mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 06:40:50 +01:00
started furni widget for external image
This commit is contained in:
parent
f88efac443
commit
2b69f12c88
@ -10,6 +10,7 @@ import { RoomWidgetUpdateRoomViewEvent } from './events/RoomWidgetUpdateRoomView
|
||||
import { IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler } from './handlers';
|
||||
import { FurnitureContextMenuWidgetHandler } from './handlers/FurnitureContextMenuWidgetHandler';
|
||||
import { FurnitureCustomStackHeightWidgetHandler } from './handlers/FurnitureCustomStackHeightWidgetHandler';
|
||||
import { FurnitureExternalImageWidgetHandler } from './handlers/FurnitureExternalImageWidgetHandler';
|
||||
import { RoomWidgetRoomToolsHandler } from './handlers/RoomWidgetRoomToolsHandler';
|
||||
import { RoomColorView } from './RoomColorView';
|
||||
import { RoomViewProps } from './RoomView.types';
|
||||
@ -44,6 +45,7 @@ export const RoomView: FC<RoomViewProps> = props =>
|
||||
widgetHandlerManager.registerHandler(new RoomWidgetChatHandler());
|
||||
widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler());
|
||||
widgetHandlerManager.registerHandler(new FurnitureCustomStackHeightWidgetHandler());
|
||||
widgetHandlerManager.registerHandler(new FurnitureExternalImageWidgetHandler());
|
||||
|
||||
setWidgetHandler(widgetHandlerManager);
|
||||
|
||||
|
60
src/views/room/events/RoomWidgetUpdateExternalImageEvent.ts
Normal file
60
src/views/room/events/RoomWidgetUpdateExternalImageEvent.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import { RoomWidgetUpdateEvent } from './RoomWidgetUpdateEvent';
|
||||
|
||||
export class RoomWidgetUpdateExternalImageEvent extends RoomWidgetUpdateEvent
|
||||
{
|
||||
public static UPDATE_EXTERNAL_IMAGE: string = 'RWUCSHE_UPDATE_EXTERNAL_IMAGE';
|
||||
|
||||
private _objectId: number;
|
||||
private _photoData: IPhotoData;
|
||||
|
||||
constructor(objectId: number, photoData: IPhotoData = null)
|
||||
{
|
||||
super(RoomWidgetUpdateExternalImageEvent.UPDATE_EXTERNAL_IMAGE);
|
||||
|
||||
this._objectId = objectId;
|
||||
this._photoData = photoData;
|
||||
}
|
||||
|
||||
public get objectId(): number
|
||||
{
|
||||
return this._objectId;
|
||||
}
|
||||
|
||||
public get photoData(): IPhotoData
|
||||
{
|
||||
return this._photoData;
|
||||
}
|
||||
}
|
||||
|
||||
export interface IPhotoData
|
||||
{
|
||||
/**
|
||||
* creator username
|
||||
*/
|
||||
n?: string;
|
||||
|
||||
/**
|
||||
* creator user id
|
||||
*/
|
||||
s?: number;
|
||||
|
||||
/**
|
||||
* photo unique id
|
||||
*/
|
||||
u?: number;
|
||||
|
||||
/**
|
||||
* creation timestamp
|
||||
*/
|
||||
t?: number;
|
||||
|
||||
/**
|
||||
* photo caption
|
||||
*/
|
||||
m?: string;
|
||||
|
||||
/**
|
||||
* photo image url
|
||||
*/
|
||||
w?: string;
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
import { NitroEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable, RoomWidgetEnum } from 'nitro-renderer';
|
||||
import { GetRoomEngine } from '../../../api';
|
||||
import { RoomWidgetUpdateEvent } from '../events/RoomWidgetUpdateEvent';
|
||||
import { IPhotoData, RoomWidgetUpdateExternalImageEvent } from '../events/RoomWidgetUpdateExternalImageEvent';
|
||||
import { RoomWidgetMessage } from '../messages/RoomWidgetMessage';
|
||||
import { RoomWidgetHandler } from './RoomWidgetHandler';
|
||||
|
||||
export class FurnitureExternalImageWidgetHandler extends RoomWidgetHandler
|
||||
{
|
||||
private _lastFurniId: number = -1;
|
||||
|
||||
public processEvent(event: NitroEvent): void
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case(RoomEngineTriggerWidgetEvent.OPEN_WIDGET):
|
||||
{
|
||||
const widgetEvent = (event as RoomEngineTriggerWidgetEvent);
|
||||
|
||||
const roomObject = GetRoomEngine().getRoomObject(widgetEvent.roomId, widgetEvent.objectId, widgetEvent.category);
|
||||
|
||||
if(!roomObject) return;
|
||||
|
||||
this._lastFurniId = widgetEvent.objectId;
|
||||
|
||||
const data = roomObject.model.getValue<string>(RoomObjectVariable.FURNITURE_DATA);
|
||||
|
||||
const dataObj: IPhotoData = JSON.parse(data);
|
||||
|
||||
this.container.eventDispatcher.dispatchEvent(new RoomWidgetUpdateExternalImageEvent(this._lastFurniId, dataObj));
|
||||
return;
|
||||
}
|
||||
case RoomEngineTriggerWidgetEvent.CLOSE_WIDGET:
|
||||
{
|
||||
const widgetEvent = (event as RoomEngineTriggerWidgetEvent);
|
||||
|
||||
if(widgetEvent.objectId !== this._lastFurniId) return;
|
||||
|
||||
this.container.eventDispatcher.dispatchEvent(new RoomWidgetUpdateExternalImageEvent(-1));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public processWidgetMessage(message: RoomWidgetMessage): RoomWidgetUpdateEvent
|
||||
{
|
||||
switch(message.type)
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return RoomWidgetEnum.EXTERNAL_IMAGE;
|
||||
}
|
||||
|
||||
public get eventTypes(): string[]
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public get messageTypes(): string[]
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import { FurnitureContextMenuView } from './context-menu/FurnitureContextMenuVie
|
||||
import { FurnitureCustomStackHeightView } from './custom-stack-height/FurnitureCustomStackHeightView';
|
||||
import { FurnitureDimmerView } from './dimmer/FurnitureDimmerView';
|
||||
import { FurnitureExchangeCreditView } from './exchange-credit/FurnitureExchangeCreditView';
|
||||
import { FurnitureExternalImageView } from './external-image/FurnitureExternalImageView';
|
||||
import { FurnitureFriendFurniView } from './friend-furni/FurnitureFriendFurniView';
|
||||
import { FurnitureHighScoreView } from './high-score/FurnitureHighScoreView';
|
||||
import { FurnitureManipulationMenuView } from './manipulation-menu/FurnitureManipulationMenuView';
|
||||
@ -28,6 +29,7 @@ export const FurnitureWidgetsView: FC<{}> = props =>
|
||||
<FurniturePresentView />
|
||||
<FurnitureStickieView />
|
||||
<FurnitureTrophyView />
|
||||
<FurnitureExternalImageView />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,45 @@
|
||||
import { FC, useCallback, useState } from 'react';
|
||||
import { CreateEventDispatcherHook } from '../../../../../hooks';
|
||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../../layout';
|
||||
import { useRoomContext } from '../../../context/RoomContext';
|
||||
import { IPhotoData, RoomWidgetUpdateExternalImageEvent } from '../../../events/RoomWidgetUpdateExternalImageEvent';
|
||||
|
||||
export const FurnitureExternalImageView: FC<{}> = props =>
|
||||
{
|
||||
const [ objectId, setObjectId ] = useState(-1);
|
||||
const [photoData, setPhotoData ] = useState<IPhotoData>(null);
|
||||
|
||||
const { roomSession = null, eventDispatcher = null } = useRoomContext();
|
||||
|
||||
const close = useCallback(() =>
|
||||
{
|
||||
setObjectId(-1);
|
||||
setPhotoData(null)
|
||||
}, []);
|
||||
|
||||
const onRoomWidgetUpdateExternalImageEvent = useCallback((event: RoomWidgetUpdateExternalImageEvent) =>
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case RoomWidgetUpdateExternalImageEvent.UPDATE_EXTERNAL_IMAGE: {
|
||||
setObjectId(event.objectId);
|
||||
setPhotoData(event.photoData);
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
CreateEventDispatcherHook(RoomWidgetUpdateExternalImageEvent.UPDATE_EXTERNAL_IMAGE, eventDispatcher, onRoomWidgetUpdateExternalImageEvent);
|
||||
|
||||
if(objectId === -1 || !photoData) return null;
|
||||
|
||||
return(
|
||||
<NitroCardView>
|
||||
<NitroCardHeaderView headerText={ '' } onCloseClick={ close } />
|
||||
<NitroCardContentView>
|
||||
<img src={photoData.w} alt=""/>
|
||||
{photoData.m && <div>{photoData.m}</div>}
|
||||
<div>{`${photoData.n} - ${new Date(photoData.t * 1000).toLocaleDateString()}`}</div>
|
||||
</NitroCardContentView>
|
||||
</NitroCardView>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user