started furni widget for external image

This commit is contained in:
Dank074 2021-08-03 18:30:16 -05:00
parent f88efac443
commit 2b69f12c88
5 changed files with 177 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import { RoomWidgetUpdateRoomViewEvent } from './events/RoomWidgetUpdateRoomView
import { IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler } from './handlers'; import { IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler } from './handlers';
import { FurnitureContextMenuWidgetHandler } from './handlers/FurnitureContextMenuWidgetHandler'; import { FurnitureContextMenuWidgetHandler } from './handlers/FurnitureContextMenuWidgetHandler';
import { FurnitureCustomStackHeightWidgetHandler } from './handlers/FurnitureCustomStackHeightWidgetHandler'; import { FurnitureCustomStackHeightWidgetHandler } from './handlers/FurnitureCustomStackHeightWidgetHandler';
import { FurnitureExternalImageWidgetHandler } from './handlers/FurnitureExternalImageWidgetHandler';
import { RoomWidgetRoomToolsHandler } from './handlers/RoomWidgetRoomToolsHandler'; import { RoomWidgetRoomToolsHandler } from './handlers/RoomWidgetRoomToolsHandler';
import { RoomColorView } from './RoomColorView'; import { RoomColorView } from './RoomColorView';
import { RoomViewProps } from './RoomView.types'; import { RoomViewProps } from './RoomView.types';
@ -44,6 +45,7 @@ export const RoomView: FC<RoomViewProps> = props =>
widgetHandlerManager.registerHandler(new RoomWidgetChatHandler()); widgetHandlerManager.registerHandler(new RoomWidgetChatHandler());
widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler());
widgetHandlerManager.registerHandler(new FurnitureCustomStackHeightWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureCustomStackHeightWidgetHandler());
widgetHandlerManager.registerHandler(new FurnitureExternalImageWidgetHandler());
setWidgetHandler(widgetHandlerManager); setWidgetHandler(widgetHandlerManager);

View 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;
}

View File

@ -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 [];
}
}

View File

@ -4,6 +4,7 @@ import { FurnitureContextMenuView } from './context-menu/FurnitureContextMenuVie
import { FurnitureCustomStackHeightView } from './custom-stack-height/FurnitureCustomStackHeightView'; import { FurnitureCustomStackHeightView } from './custom-stack-height/FurnitureCustomStackHeightView';
import { FurnitureDimmerView } from './dimmer/FurnitureDimmerView'; import { FurnitureDimmerView } from './dimmer/FurnitureDimmerView';
import { FurnitureExchangeCreditView } from './exchange-credit/FurnitureExchangeCreditView'; import { FurnitureExchangeCreditView } from './exchange-credit/FurnitureExchangeCreditView';
import { FurnitureExternalImageView } from './external-image/FurnitureExternalImageView';
import { FurnitureFriendFurniView } from './friend-furni/FurnitureFriendFurniView'; import { FurnitureFriendFurniView } from './friend-furni/FurnitureFriendFurniView';
import { FurnitureHighScoreView } from './high-score/FurnitureHighScoreView'; import { FurnitureHighScoreView } from './high-score/FurnitureHighScoreView';
import { FurnitureManipulationMenuView } from './manipulation-menu/FurnitureManipulationMenuView'; import { FurnitureManipulationMenuView } from './manipulation-menu/FurnitureManipulationMenuView';
@ -28,6 +29,7 @@ export const FurnitureWidgetsView: FC<{}> = props =>
<FurniturePresentView /> <FurniturePresentView />
<FurnitureStickieView /> <FurnitureStickieView />
<FurnitureTrophyView /> <FurnitureTrophyView />
<FurnitureExternalImageView />
</div> </div>
); );
} }

View File

@ -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>
);
}