diff --git a/src/api/nitro/room/widgets/events/RoomWidgetUpdatePresentDataEvent.ts b/src/api/nitro/room/widgets/events/RoomWidgetUpdatePresentDataEvent.ts new file mode 100644 index 00000000..4a4567b3 --- /dev/null +++ b/src/api/nitro/room/widgets/events/RoomWidgetUpdatePresentDataEvent.ts @@ -0,0 +1,116 @@ +import { RoomWidgetUpdateEvent } from './RoomWidgetUpdateEvent'; + +export class RoomWidgetUpdatePresentDataEvent extends RoomWidgetUpdateEvent +{ + public static PACKAGEINFO: string = 'RWUPDE_PACKAGEINFO'; + public static CONTENTS: string = 'RWUPDE_CONTENTS'; + public static CONTENTS_CLUB: string = 'RWUPDE_CONTENTS_CLUB'; + public static CONTENTS_FLOOR: string = 'RWUPDE_CONTENTS_FLOOR'; + public static CONTENTS_LANDSCAPE: string = 'RWUPDE_CONTENTS_LANDSCAPE'; + public static CONTENTS_WALLPAPER: string = 'RWUPDE_CONTENTS_WALLPAPER'; + public static CONTENTS_IMAGE: string = 'RWUPDE_CONTENTS_IMAGE'; + + private _objectId: number = -1; + private _classId: number = 0; + private _itemType: string = ''; + private _giftMessage: string = ''; + private _imageUrl: string = null; + private _isController: boolean; + private _purchaserName: string; + private _purchaserFigure: string; + private _placedItemId: number = -1; + private _placedItemType: string = ''; + private _placedInRoom: boolean; + + constructor(type: string, objectId: number, giftMessage: string, isOwnerOfFurniture: boolean = false, imageUrl: string = null, purchaserName: string = null, purchaserFigure: string = null) + { + super(type); + + this._objectId = objectId; + this._giftMessage = giftMessage; + this._imageUrl = imageUrl; + this._isController = isOwnerOfFurniture; + this._purchaserName = purchaserName; + this._purchaserFigure = purchaserFigure; + } + + public get objectId(): number + { + return this._objectId; + } + + public get classId(): number + { + return this._classId; + } + + public set classId(classId: number) + { + this._classId = classId; + } + + public get itemType(): string + { + return this._itemType; + } + + public set itemType(type: string) + { + this._itemType = type; + } + + public get giftMessage(): string + { + return this._giftMessage; + } + + public get imageUrl(): string + { + return this._imageUrl; + } + + public get isController(): boolean + { + return this._isController; + } + + public get purchaserName(): string + { + return this._purchaserName; + } + + public get purchaserFigure(): string + { + return this._purchaserFigure; + } + + public get placedItemId(): number + { + return this._placedItemId; + } + + public set placedItemId(itemId: number) + { + this._placedItemId = itemId; + } + + public get placedInRoom(): boolean + { + return this._placedInRoom; + } + + public set placedInRoom(flag: boolean) + { + this._placedInRoom = flag; + } + + public get placedItemType(): string + { + return this._placedItemType; + } + + public set placedItemType(type: string) + { + this._placedItemType = type; + } +} diff --git a/src/api/nitro/room/widgets/events/index.ts b/src/api/nitro/room/widgets/events/index.ts index cdb95870..4b4810d0 100644 --- a/src/api/nitro/room/widgets/events/index.ts +++ b/src/api/nitro/room/widgets/events/index.ts @@ -19,6 +19,7 @@ export * from './RoomWidgetUpdateInfostandFurniEvent'; export * from './RoomWidgetUpdateInfostandPetEvent'; export * from './RoomWidgetUpdateInfostandRentableBotEvent'; export * from './RoomWidgetUpdateInfostandUserEvent'; +export * from './RoomWidgetUpdatePresentDataEvent'; export * from './RoomWidgetUpdateRentableBotChatEvent'; export * from './RoomWidgetUpdateRoomViewEvent'; export * from './RoomWidgetUpdateSongEvent'; diff --git a/src/api/nitro/room/widgets/handlers/FurniturePresentWidgetHandler.ts b/src/api/nitro/room/widgets/handlers/FurniturePresentWidgetHandler.ts new file mode 100644 index 00000000..745ed868 --- /dev/null +++ b/src/api/nitro/room/widgets/handlers/FurniturePresentWidgetHandler.ts @@ -0,0 +1,223 @@ +import { IFurnitureData, IGetImageListener, NitroEvent, NitroRenderTexture, PetFigureData, RoomObjectCategory, RoomObjectVariable, RoomSessionPresentEvent, RoomWidgetEnum, TextureUtils, Vector3d } from '@nitrots/nitro-renderer'; +import { GetSessionDataManager, IsOwnerOfFurniture } from '../../..'; +import { GetRoomEngine, LocalizeText } from '../../../..'; +import { ProductTypeEnum } from '../../../../../views/catalog/common/ProductTypeEnum'; +import { RoomWidgetUpdateEvent, RoomWidgetUpdatePresentDataEvent } from '../events'; +import { RoomWidgetFurniToWidgetMessage, RoomWidgetPresentOpenMessage } from '../messages'; +import { RoomWidgetMessage } from '../messages/RoomWidgetMessage'; +import { RoomWidgetHandler } from './RoomWidgetHandler'; + +export class FurniturePresentWidgetHandler extends RoomWidgetHandler implements IGetImageListener +{ + private static FLOOR: string = 'floor'; + private static WALLPAPER: string = 'wallpaper'; + private static LANDSCAPE: string = 'landscape'; + private static POSTER: string = 'poster'; + + private _lastFurniId: number = -1; + private _name: string = null; + + public processEvent(event: NitroEvent): void + { + switch(event.type) + { + case RoomSessionPresentEvent.RSPE_PRESENT_OPENED: { + const presentEvent = (event as RoomSessionPresentEvent); + + let furniData: IFurnitureData = null; + + if(presentEvent.itemType === ProductTypeEnum.FLOOR) + { + furniData = GetSessionDataManager().getFloorItemData(presentEvent.classId); + } + else if(presentEvent.itemType === ProductTypeEnum.WALL) + { + furniData = GetSessionDataManager().getWallItemData(presentEvent.classId); + } + + let isOwnerOfFurni = false; + + if(presentEvent.placedInRoom) + { + const roomObject = GetRoomEngine().getRoomObject(this.container.roomSession.roomId, presentEvent.placedItemId, RoomObjectCategory.FLOOR); + + if(roomObject) isOwnerOfFurni = IsOwnerOfFurniture(roomObject); + } + + let giftImage: string = null; + let dataUpdateEvent: RoomWidgetUpdatePresentDataEvent = null; + + switch(presentEvent.itemType) + { + case ProductTypeEnum.WALL: { + if(furniData) + { + switch(furniData.className) + { + case FurniturePresentWidgetHandler.FLOOR: + dataUpdateEvent = new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.CONTENTS_FLOOR, 0, LocalizeText('inventory.furni.item.floor.name'), isOwnerOfFurni); + break; + case FurniturePresentWidgetHandler.LANDSCAPE: + dataUpdateEvent = new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.CONTENTS_LANDSCAPE, 0, LocalizeText('inventory.furni.item.landscape.name'), isOwnerOfFurni); + break; + case FurniturePresentWidgetHandler.WALLPAPER: + dataUpdateEvent = new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.CONTENTS_WALLPAPER, 0, LocalizeText('inventory.furni.item.wallpaper.name'), isOwnerOfFurni); + break; + case FurniturePresentWidgetHandler.POSTER: { + const productCode = presentEvent.productCode; + + let extras: string = null; + + if(productCode.indexOf('poster') === 0) extras = productCode.replace('poster', ''); + + giftImage = GetRoomEngine().getFurnitureWallIconUrl(presentEvent.classId, extras); + + const productData = GetSessionDataManager().getProductData(productCode); + + if(productData) this._name = productData.name; + else if(furniData) this._name = furniData.name; + + dataUpdateEvent = new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.CONTENTS, 0, this._name, isOwnerOfFurni, giftImage); + + break; + } + default: { + giftImage = GetRoomEngine().getFurnitureWallIconUrl(presentEvent.classId); + + if(furniData) this._name = furniData.name; + + dataUpdateEvent = new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.CONTENTS, 0, this._name, isOwnerOfFurni, giftImage); + break; + } + } + } + + break; + } + case ProductTypeEnum.HABBO_CLUB: + dataUpdateEvent = new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.CONTENTS_CLUB, 0, LocalizeText('widget.furni.present.hc'), false); + break; + default: { + if(presentEvent.placedItemType === ProductTypeEnum.PET) + { + const petfigureString = presentEvent.petFigureString; + + if(petfigureString && petfigureString.length) + { + const petFigureData = new PetFigureData(petfigureString); + + const petImage = GetRoomEngine().getRoomObjectPetImage(petFigureData.typeId, petFigureData.paletteId, petFigureData.color, new Vector3d(90), 64, this, true, 0, petFigureData.customParts); + + if(petImage) giftImage = petImage.getImage().src; + } + } + + if(!giftImage) + { + const furniImage = GetRoomEngine().getFurnitureFloorImage(presentEvent.classId, new Vector3d(90), 64, this); + + if(furniImage) giftImage = furniImage.getImage().src; + } + + const productData = GetSessionDataManager().getProductData(presentEvent.productCode); + + if(productData) this._name = productData.name; + else this._name = furniData.name; + + if(giftImage) dataUpdateEvent = new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.CONTENTS, 0, this._name, isOwnerOfFurni, giftImage); + + break; + } + } + + if(dataUpdateEvent) + { + dataUpdateEvent.classId = presentEvent.classId; + dataUpdateEvent.itemType = presentEvent.itemType; + dataUpdateEvent.placedItemId = presentEvent.placedItemId; + dataUpdateEvent.placedInRoom = presentEvent.placedInRoom; + dataUpdateEvent.placedItemType = presentEvent.placedItemType; + + this.container.eventDispatcher.dispatchEvent(dataUpdateEvent); + } + + return; + } + } + } + + public processWidgetMessage(message: RoomWidgetMessage): RoomWidgetUpdateEvent + { + switch(message.type) + { + case RoomWidgetFurniToWidgetMessage.REQUEST_PRESENT: { + const widgetMessage = (message as RoomWidgetFurniToWidgetMessage); + + const roomObject = GetRoomEngine().getRoomObject(widgetMessage.roomId, widgetMessage.objectId, widgetMessage.category); + + if(!roomObject) return null; + + this._lastFurniId = widgetMessage.objectId; + + const giftMessage = (roomObject.model.getValue(RoomObjectVariable.FURNITURE_DATA) || ''); + const purchaserName = roomObject.model.getValue(RoomObjectVariable.FURNITURE_PURCHASER_NAME); + const purchaserFigure = roomObject.model.getValue(RoomObjectVariable.FURNITURE_PURCHASER_FIGURE); + const typeId = roomObject.model.getValue(RoomObjectVariable.FURNITURE_TYPE_ID); + const extras = roomObject.model.getValue(RoomObjectVariable.FURNITURE_EXTRAS); + const giftImage = GetRoomEngine().getFurnitureFloorImage(typeId, new Vector3d(180), 64, null, 0, extras); + + this.container.eventDispatcher.dispatchEvent(new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.PACKAGEINFO, widgetMessage.objectId, giftMessage, IsOwnerOfFurniture(roomObject), giftImage.getImage().src, purchaserName, purchaserFigure)); + + break; + } + case RoomWidgetPresentOpenMessage.OPEN_PRESENT: { + const openMessage = (message as RoomWidgetPresentOpenMessage); + + if(openMessage.objectId !== this._lastFurniId) return null; + + this.container.roomSession.openGift(openMessage.objectId); + + GetRoomEngine().changeObjectModelData(GetRoomEngine().activeRoomId, openMessage.objectId, RoomObjectCategory.FLOOR, RoomObjectVariable.FURNITURE_DISABLE_PICKING_ANIMATION, 1); + + break; + } + } + + return null; + } + + public imageReady(id: number, texture: NitroRenderTexture, image: HTMLImageElement = null): void + { + let imageUrl: string = null; + + if(image) imageUrl = image.src; + else if(texture) imageUrl = TextureUtils.generateImageUrl(texture); + + this.container.eventDispatcher.dispatchEvent(new RoomWidgetUpdatePresentDataEvent(RoomWidgetUpdatePresentDataEvent.CONTENTS_IMAGE, 0, this._name, false, imageUrl)); + } + + public imageFailed(id: number): void + { + + } + + public get type(): string + { + return RoomWidgetEnum.FURNI_PRESENT_WIDGET; + } + + public get eventTypes(): string[] + { + return [ + RoomSessionPresentEvent.RSPE_PRESENT_OPENED + ]; + } + + public get messageTypes(): string[] + { + return [ + RoomWidgetFurniToWidgetMessage.REQUEST_PRESENT, + RoomWidgetPresentOpenMessage.OPEN_PRESENT + ]; + } +} diff --git a/src/api/nitro/room/widgets/handlers/RoomWidgetChatInputHandler.ts b/src/api/nitro/room/widgets/handlers/RoomWidgetChatInputHandler.ts index 8daf7bc0..81f5411d 100644 --- a/src/api/nitro/room/widgets/handlers/RoomWidgetChatInputHandler.ts +++ b/src/api/nitro/room/widgets/handlers/RoomWidgetChatInputHandler.ts @@ -1,4 +1,5 @@ import { AvatarExpressionEnum, HabboClubLevelEnum, NitroEvent, RoomControllerLevel, RoomSessionChatEvent, RoomSettingsComposer, RoomWidgetEnum, RoomZoomEvent, TextureUtils } from '@nitrots/nitro-renderer'; +import { GetConfiguration, GetNitroInstance } from '../../..'; import { GetRoomEngine, GetSessionDataManager } from '../../../..'; import { SendMessageHook } from '../../../../../hooks/messages'; import { RoomWidgetFloodControlEvent, RoomWidgetUpdateEvent } from '../events'; @@ -146,6 +147,12 @@ export class RoomWidgetChatInputHandler extends RoomWidgetHandler } return null; + case ':togglefps': { + if(GetNitroInstance().ticker.maxFPS > 0) GetNitroInstance().ticker.maxFPS = 0; + else GetNitroInstance().ticker.maxFPS = GetConfiguration('system.animation.fps'); + + return null; + } case ':client': case ':nitro': case ':billsonnn': diff --git a/src/api/nitro/room/widgets/handlers/index.ts b/src/api/nitro/room/widgets/handlers/index.ts index d787e68c..500115e7 100644 --- a/src/api/nitro/room/widgets/handlers/index.ts +++ b/src/api/nitro/room/widgets/handlers/index.ts @@ -3,6 +3,7 @@ export * from './FurniChooserWidgetHandler'; export * from './FurnitureContextMenuWidgetHandler'; export * from './FurnitureCustomStackHeightWidgetHandler'; export * from './FurnitureExternalImageWidgetHandler'; +export * from './FurniturePresentWidgetHandler'; export * from './IRoomWidgetHandler'; export * from './IRoomWidgetHandlerManager'; export * from './RoomWidgetAvatarInfoHandler'; diff --git a/src/api/nitro/room/widgets/messages/RoomWidgetPresentOpenMessage.ts b/src/api/nitro/room/widgets/messages/RoomWidgetPresentOpenMessage.ts new file mode 100644 index 00000000..20f34f49 --- /dev/null +++ b/src/api/nitro/room/widgets/messages/RoomWidgetPresentOpenMessage.ts @@ -0,0 +1,20 @@ +import { RoomWidgetMessage } from './RoomWidgetMessage'; + +export class RoomWidgetPresentOpenMessage extends RoomWidgetMessage +{ + public static OPEN_PRESENT: string = 'RWPOM_OPEN_PRESENT'; + + private _objectId: number; + + constructor(type: string, objectId: number) + { + super(type); + + this._objectId = objectId; + } + + public get objectId(): number + { + return this._objectId; + } +} diff --git a/src/api/nitro/room/widgets/messages/index.ts b/src/api/nitro/room/widgets/messages/index.ts index 732e5665..2cfcba12 100644 --- a/src/api/nitro/room/widgets/messages/index.ts +++ b/src/api/nitro/room/widgets/messages/index.ts @@ -9,6 +9,7 @@ export * from './RoomWidgetFurniActionMessage'; export * from './RoomWidgetFurniToWidgetMessage'; export * from './RoomWidgetLetUserInMessage'; export * from './RoomWidgetMessage'; +export * from './RoomWidgetPresentOpenMessage'; export * from './RoomWidgetRequestWidgetMessage'; export * from './RoomWidgetRoomObjectMessage'; export * from './RoomWidgetUseProductMessage'; diff --git a/src/views/room/RoomView.tsx b/src/views/room/RoomView.tsx index 882d7a76..c1e18a1f 100644 --- a/src/views/room/RoomView.tsx +++ b/src/views/room/RoomView.tsx @@ -1,6 +1,6 @@ import { EventDispatcher, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer'; import { FC, useEffect, useRef, useState } from 'react'; -import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureExternalImageWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler } from '../../api'; +import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureExternalImageWidgetHandler, FurniturePresentWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler } from '../../api'; import { RoomContextProvider } from './context/RoomContext'; import { RoomColorView } from './RoomColorView'; import { RoomViewProps } from './RoomView.types'; @@ -34,12 +34,14 @@ export const RoomView: FC = props => widgetHandlerManager.registerHandler(new RoomWidgetRoomToolsHandler()); widgetHandlerManager.registerHandler(new RoomWidgetChatInputHandler()); widgetHandlerManager.registerHandler(new RoomWidgetChatHandler()); + widgetHandlerManager.registerHandler(new UserChooserWidgetHandler()); + widgetHandlerManager.registerHandler(new DoorbellWidgetHandler()); + + widgetHandlerManager.registerHandler(new FurniChooserWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureCustomStackHeightWidgetHandler()); widgetHandlerManager.registerHandler(new FurnitureExternalImageWidgetHandler()); - widgetHandlerManager.registerHandler(new FurniChooserWidgetHandler()); - widgetHandlerManager.registerHandler(new UserChooserWidgetHandler()); - widgetHandlerManager.registerHandler(new DoorbellWidgetHandler()); + widgetHandlerManager.registerHandler(new FurniturePresentWidgetHandler()); setWidgetHandler(widgetHandlerManager); diff --git a/src/views/room/widgets/RoomWidgetsView.tsx b/src/views/room/widgets/RoomWidgetsView.tsx index b1f3b102..2b5dee4e 100644 --- a/src/views/room/widgets/RoomWidgetsView.tsx +++ b/src/views/room/widgets/RoomWidgetsView.tsx @@ -1,6 +1,6 @@ import { RoomEngineDimmerStateEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomEngineTriggerWidgetEvent, RoomEngineUseProductEvent, RoomId, RoomObjectCategory, RoomObjectOperationType, RoomSessionChatEvent, RoomSessionDanceEvent, RoomSessionDimmerPresetsEvent, RoomSessionDoorbellEvent, RoomSessionErrorMessageEvent, RoomSessionEvent, RoomSessionFriendRequestEvent, RoomSessionPetInfoUpdateEvent, RoomSessionPresentEvent, RoomSessionUserBadgesEvent, RoomZoomEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback } from 'react'; -import { CanManipulateFurniture, GetRoomEngine, IsFurnitureSelectionDisabled, LocalizeText, ProcessRoomObjectOperation, RoomWidgetRoomEngineUpdateEvent, RoomWidgetRoomObjectUpdateEvent } from '../../../api'; +import { CanManipulateFurniture, GetRoomEngine, IsFurnitureSelectionDisabled, LocalizeText, ProcessRoomObjectOperation, RoomWidgetFurniToWidgetMessage, RoomWidgetRoomEngineUpdateEvent, RoomWidgetRoomObjectUpdateEvent } from '../../../api'; import { useRoomEngineEvent, useRoomSessionManagerEvent } from '../../../hooks/events'; import { useRoomContext } from '../context/RoomContext'; import { AvatarInfoWidgetView } from './avatar-info/AvatarInfoWidgetView'; @@ -118,6 +118,9 @@ export const RoomWidgetsView: FC = props => case RoomEngineObjectEvent.MOUSE_LEAVE: updateEvent = new RoomWidgetRoomObjectUpdateEvent(RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OUT, objectId, category, event.roomId); break; + case RoomEngineTriggerWidgetEvent.REQUEST_PRESENT: + widgetHandler.processWidgetMessage(new RoomWidgetFurniToWidgetMessage(RoomWidgetFurniToWidgetMessage.REQUEST_PRESENT, objectId, category, event.roomId)); + break; case RoomEngineUseProductEvent.USE_PRODUCT_FROM_INVENTORY: case RoomEngineUseProductEvent.USE_PRODUCT_FROM_ROOM: case RoomEngineTriggerWidgetEvent.OPEN_WIDGET: @@ -146,10 +149,11 @@ export const RoomWidgetsView: FC = props => useRoomEngineEvent(RoomEngineObjectEvent.REQUEST_MANIPULATION, onRoomEngineObjectEvent); useRoomEngineEvent(RoomEngineObjectEvent.MOUSE_ENTER, onRoomEngineObjectEvent); useRoomEngineEvent(RoomEngineObjectEvent.MOUSE_LEAVE, onRoomEngineObjectEvent); - useRoomEngineEvent(RoomEngineUseProductEvent.USE_PRODUCT_FROM_INVENTORY, onRoomEngineObjectEvent); - useRoomEngineEvent(RoomEngineUseProductEvent.USE_PRODUCT_FROM_ROOM, onRoomEngineObjectEvent); useRoomEngineEvent(RoomEngineTriggerWidgetEvent.OPEN_WIDGET, onRoomEngineObjectEvent); useRoomEngineEvent(RoomEngineTriggerWidgetEvent.CLOSE_WIDGET, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_PRESENT, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineUseProductEvent.USE_PRODUCT_FROM_INVENTORY, onRoomEngineObjectEvent); + useRoomEngineEvent(RoomEngineUseProductEvent.USE_PRODUCT_FROM_ROOM, onRoomEngineObjectEvent); const onRoomSessionEvent = useCallback((event: RoomSessionEvent) => { diff --git a/src/views/room/widgets/furniture/FurnitureWidgetsView.tsx b/src/views/room/widgets/furniture/FurnitureWidgetsView.tsx index b37b0a8d..2d152199 100644 --- a/src/views/room/widgets/furniture/FurnitureWidgetsView.tsx +++ b/src/views/room/widgets/furniture/FurnitureWidgetsView.tsx @@ -7,10 +7,10 @@ import { FurnitureDimmerView } from './dimmer/FurnitureDimmerView'; import { FurnitureExchangeCreditView } from './exchange-credit/FurnitureExchangeCreditView'; import { FurnitureExternalImageView } from './external-image/FurnitureExternalImageView'; import { FurnitureFriendFurniView } from './friend-furni/FurnitureFriendFurniView'; +import { FurnitureGiftOpeningView } from './gift-opening/FurnitureGiftOpeningView'; import { FurnitureHighScoreView } from './high-score/FurnitureHighScoreView'; import { FurnitureManipulationMenuView } from './manipulation-menu/FurnitureManipulationMenuView'; import { FurnitureMannequinView } from './mannequin/FurnitureMannequinView'; -import { FurniturePresentView } from './present/FurniturePresentView'; import { FurnitureStickieView } from './stickie/FurnitureStickieView'; import { FurnitureTrophyView } from './trophy/FurnitureTrophyView'; @@ -23,11 +23,11 @@ export const FurnitureWidgetsView: FC<{}> = props => + - diff --git a/src/views/room/widgets/furniture/present/FurniturePresentView.scss b/src/views/room/widgets/furniture/gift-opening/FurnitureGiftOpeningView.scss similarity index 100% rename from src/views/room/widgets/furniture/present/FurniturePresentView.scss rename to src/views/room/widgets/furniture/gift-opening/FurnitureGiftOpeningView.scss diff --git a/src/views/room/widgets/furniture/gift-opening/FurnitureGiftOpeningView.tsx b/src/views/room/widgets/furniture/gift-opening/FurnitureGiftOpeningView.tsx new file mode 100644 index 00000000..8af7befb --- /dev/null +++ b/src/views/room/widgets/furniture/gift-opening/FurnitureGiftOpeningView.tsx @@ -0,0 +1,137 @@ +import { FC, useCallback, useState } from 'react'; +import { LocalizeText, RoomWidgetRoomObjectUpdateEvent, RoomWidgetUpdatePresentDataEvent } from '../../../../../api'; +import { CreateEventDispatcherHook } from '../../../../../hooks/events/event-dispatcher.base'; +import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../../layout'; +import { useRoomContext } from '../../../context/RoomContext'; + +export const FurnitureGiftOpeningView: FC<{}> = props => +{ + const { eventDispatcher = null, widgetHandler = null } = useRoomContext(); + const [ objectId, setObjectId ] = useState(-1); + const [ classId, setClassId ] = useState(-1); + const [ itemType, setItemType ] = useState(null); + const [ text, setText ] = useState(null); + const [ isOwnerOfFurniture, setIsOwnerOfFurniture ] = useState(false); + const [ senderName, setSenderName ] = useState(null); + const [ senderFigure, setSenderFigure ] = useState(null); + const [ placedItemId, setPlacedItemId ] = useState(-1); + const [ placedItemType, setPlacedItemType ] = useState(null); + const [ placedInRoom, setPlacedInRoom ] = useState(false); + const [ imageUrl, setImageUrl ] = useState(null); + const [ openRequested, setOpenRequested ] = useState(false); + + const clearGift = useCallback(() => + { + if(!openRequested) setObjectId(-1); + + setText(null); + setIsOwnerOfFurniture(false); + }, [ openRequested ]); + + const getGiftImageUrl = useCallback((name: string) => + { + return ''; + }, []); + + const onRoomWidgetUpdatePresentDataEvent = useCallback((event: RoomWidgetUpdatePresentDataEvent) => + { + switch(event.type) + { + case RoomWidgetUpdatePresentDataEvent.PACKAGEINFO: { + setOpenRequested(false); + setObjectId(event.objectId); + setText(event.giftMessage); + setIsOwnerOfFurniture(event.isController); + setSenderName(event.purchaserName); + setSenderFigure(event.purchaserFigure); + setImageUrl(event.imageUrl); + return; + } + case RoomWidgetUpdatePresentDataEvent.CONTENTS_FLOOR: + case RoomWidgetUpdatePresentDataEvent.CONTENTS_LANDSCAPE: + case RoomWidgetUpdatePresentDataEvent.CONTENTS_WALLPAPER: { + setObjectId(event.objectId); + setClassId(event.classId); + setItemType(event.itemType); + setText(event.giftMessage); + setIsOwnerOfFurniture(event.isController); + setPlacedItemId(event.placedItemId); + setPlacedItemType(event.placedItemType); + setPlacedInRoom(event.placedInRoom); + + let imageType: string = null; + + if(event.type === RoomWidgetUpdatePresentDataEvent.CONTENTS_FLOOR) imageType = 'packagecard_icon_floor'; + else if(event.type === RoomWidgetUpdatePresentDataEvent.CONTENTS_LANDSCAPE) imageType = 'packagecard_icon_landscape'; + else if(event.type === RoomWidgetUpdatePresentDataEvent.CONTENTS_WALLPAPER) imageType = 'packagecard_icon_wallpaper'; + + setImageUrl(getGiftImageUrl(imageType)); + return; + } + case RoomWidgetUpdatePresentDataEvent.CONTENTS_CLUB: { + setObjectId(event.objectId); + setClassId(event.classId); + setItemType(event.itemType); + setText(event.giftMessage); + setIsOwnerOfFurniture(event.isController); + setImageUrl(getGiftImageUrl('packagecard_icon_hc')); + return; + } + case RoomWidgetUpdatePresentDataEvent.CONTENTS: { + if(!openRequested) return; + + setObjectId(event.objectId); + setClassId(event.classId); + setItemType(event.itemType); + setText(event.giftMessage); + setIsOwnerOfFurniture(event.isController); + setPlacedItemId(event.placedItemId); + setPlacedItemType(event.placedItemType); + setPlacedInRoom(event.placedInRoom); + + return; + } + case RoomWidgetUpdatePresentDataEvent.CONTENTS_IMAGE: { + if(!openRequested) return; + + setImageUrl(event.imageUrl); + } + } + }, [ openRequested, getGiftImageUrl ]); + + CreateEventDispatcherHook(RoomWidgetUpdatePresentDataEvent.PACKAGEINFO, eventDispatcher, onRoomWidgetUpdatePresentDataEvent); + CreateEventDispatcherHook(RoomWidgetUpdatePresentDataEvent.CONTENTS, eventDispatcher, onRoomWidgetUpdatePresentDataEvent); + CreateEventDispatcherHook(RoomWidgetUpdatePresentDataEvent.CONTENTS_FLOOR, eventDispatcher, onRoomWidgetUpdatePresentDataEvent); + CreateEventDispatcherHook(RoomWidgetUpdatePresentDataEvent.CONTENTS_LANDSCAPE, eventDispatcher, onRoomWidgetUpdatePresentDataEvent); + CreateEventDispatcherHook(RoomWidgetUpdatePresentDataEvent.CONTENTS_WALLPAPER, eventDispatcher, onRoomWidgetUpdatePresentDataEvent); + CreateEventDispatcherHook(RoomWidgetUpdatePresentDataEvent.CONTENTS_CLUB, eventDispatcher, onRoomWidgetUpdatePresentDataEvent); + CreateEventDispatcherHook(RoomWidgetUpdatePresentDataEvent.CONTENTS_IMAGE, eventDispatcher, onRoomWidgetUpdatePresentDataEvent); + + const onRoomWidgetRoomObjectUpdateEvent = useCallback((event: RoomWidgetRoomObjectUpdateEvent) => + { + if(event.id === objectId) clearGift(); + + if(event.id === placedItemId) + { + if(placedInRoom) setPlacedInRoom(false); + } + }, [ objectId, placedItemId, placedInRoom, clearGift ]); + + CreateEventDispatcherHook(RoomWidgetRoomObjectUpdateEvent.FURNI_REMOVED, eventDispatcher, onRoomWidgetRoomObjectUpdateEvent); + + const close = useCallback(() => + { + setObjectId(-1); + }, []); + + if(objectId === -1) return null; + + return ( + + + + plz + + + ); +} diff --git a/src/views/room/widgets/furniture/present/FurniturePresentView.tsx b/src/views/room/widgets/furniture/present/FurniturePresentView.tsx deleted file mode 100644 index 3516185a..00000000 --- a/src/views/room/widgets/furniture/present/FurniturePresentView.tsx +++ /dev/null @@ -1,18 +0,0 @@ -import { NitroEvent, RoomEngineTriggerWidgetEvent } from '@nitrots/nitro-renderer'; -import { FC } from 'react'; -import { useRoomEngineEvent } from '../../../../../hooks/events/nitro/room/room-engine-event'; -import { useRoomContext } from '../../../context/RoomContext'; - -export const FurniturePresentView: FC<{}> = props => -{ - const { eventDispatcher = null, widgetHandler = null } = useRoomContext(); - - const onNitroEvent = (event: NitroEvent) => - { - console.log(event); - }; - - useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_PRESENT, onNitroEvent); - - return null; -}