From c950ab68a7773c6fe42fdf827df363ed1c8fc931 Mon Sep 17 00:00:00 2001 From: Bill Date: Sun, 13 Jun 2021 04:13:46 -0400 Subject: [PATCH] Update widgets --- .../avatar-info/AvatarInfoWidgetView.tsx | 138 +++++++++--------- .../views/name/AvatarInfoWidgetNameView.tsx | 15 ++ .../name/AvatarInfoWidgetNameView.types.ts | 6 + .../FurnitureManipulationMenuView.tsx | 2 +- 4 files changed, 93 insertions(+), 68 deletions(-) create mode 100644 src/views/room/widgets/avatar-info/views/name/AvatarInfoWidgetNameView.tsx create mode 100644 src/views/room/widgets/avatar-info/views/name/AvatarInfoWidgetNameView.types.ts diff --git a/src/views/room/widgets/avatar-info/AvatarInfoWidgetView.tsx b/src/views/room/widgets/avatar-info/AvatarInfoWidgetView.tsx index 41fb84ce..22689633 100644 --- a/src/views/room/widgets/avatar-info/AvatarInfoWidgetView.tsx +++ b/src/views/room/widgets/avatar-info/AvatarInfoWidgetView.tsx @@ -1,91 +1,95 @@ -import { IFurnitureData, RoomObjectCategory, RoomObjectVariable } from 'nitro-renderer'; -import { FC, useCallback } from 'react'; -import { GetRoomEngine, GetRoomSession, GetSessionDataManager } from '../../../../api'; +import { RoomObjectCategory } from 'nitro-renderer'; +import { FC, useCallback, useState } from 'react'; import { CreateEventDispatcherHook } from '../../../../hooks/events/event-dispatcher.base'; -import { RoomObjectNameEvent, RoomWidgetRoomObjectUpdateEvent } from '../events'; +import { RoomWidgetRoomEngineUpdateEvent, RoomWidgetRoomObjectUpdateEvent } from '../events'; import { AvatarInfoWidgetViewProps } from './AvatarInfoWidgetView.types'; +import { GetRoomObjectNameData } from './utils/GetRoomObjectNameData'; +import { RoomObjectNameData } from './utils/RoomObjectNameData'; +import { AvatarInfoWidgetNameView } from './views/name/AvatarInfoWidgetNameView'; export const AvatarInfoWidgetView: FC = props => { const { events = null } = props; - - const processObjectName = useCallback((roomId: number, objectId: number, category: number) => - { - let id = -1; - let name: string = null; - let type = 0; - let roomIndex = 0; - - switch(category) - { - case RoomObjectCategory.FLOOR: - case RoomObjectCategory.WALL: - const roomObject = GetRoomEngine().getRoomObject(roomId, id, category); - - if(!roomObject) return; - - if(roomObject.type.indexOf('poster') === 0) - { - name = ('${poster_' + parseInt(roomObject.type.replace('poster', '')) + '_name}'); - roomIndex = roomObject.id; - } - else - { - let furniData: IFurnitureData = null; - - const typeId = roomObject.model.getValue(RoomObjectVariable.FURNITURE_TYPE_ID); - - if(category === RoomObjectCategory.FLOOR) - { - furniData = GetSessionDataManager().getFloorItemData(typeId); - } - - else if(category === RoomObjectCategory.WALL) - { - furniData = GetSessionDataManager().getWallItemData(typeId); - } - - if(!furniData) return; - - id = furniData.id; - name = furniData.name; - roomIndex = roomObject.id; - } - break; - case RoomObjectCategory.UNIT: - const userData = GetRoomSession().userDataManager.getUserDataByIndex(id); - - if(!userData) return; - - id = userData.webID; - name = userData.name; - type = userData.type; - roomIndex = userData.roomIndex; - break; - } - - if(!name) return; - - events.dispatchEvent(new RoomObjectNameEvent(id, category, name, type, roomIndex)); - }, [ events ]); + const [ names, setNames ] = useState([]); + const [ isGameMode, setGameMode ] = useState(false); const onRoomWidgetRoomObjectUpdateEvent = useCallback((event: RoomWidgetRoomObjectUpdateEvent) => { switch(event.type) { + case RoomWidgetRoomObjectUpdateEvent.OBJECT_SELECTED: { + return; + } + case RoomWidgetRoomObjectUpdateEvent.OBJECT_DESELECTED: { + return; + } case RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OVER: { - processObjectName(event.roomId, event.id, event.category); + if(isGameMode) return; + + if(event.category !== RoomObjectCategory.UNIT) return; + + const nameData = GetRoomObjectNameData(event.roomId, event.id, event.category); + + if(nameData) + { + setNames(prevValue => + { + const existing = prevValue.filter(value => + { + if(value.objectId === nameData.id) return null; + + return value; + }); + + return [ ...existing, new RoomObjectNameData(nameData.objectId, nameData.category, nameData.id, nameData.name, nameData.type) ] + }); + } return; } case RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OUT: { - console.log('out'); + if(isGameMode) return; + + setNames(prevValue => + { + return prevValue.filter(value => + { + if(value.objectId === event.id) return null; + + return value; + }); + }); return; } } + }, [ isGameMode ]); + + const onRoomWidgetRoomEngineUpdateEvent = useCallback((event: RoomWidgetRoomEngineUpdateEvent) => + { + switch(event.type) + { + case RoomWidgetRoomEngineUpdateEvent.RWREUE_NORMAL_MODE: + setGameMode(false); + break; + case RoomWidgetRoomEngineUpdateEvent.RWREUE_GAME_MODE: + setGameMode(true); + break; + } }, []); + CreateEventDispatcherHook(RoomWidgetRoomObjectUpdateEvent.OBJECT_SELECTED, events, onRoomWidgetRoomObjectUpdateEvent); + CreateEventDispatcherHook(RoomWidgetRoomObjectUpdateEvent.OBJECT_DESELECTED, events, onRoomWidgetRoomObjectUpdateEvent); CreateEventDispatcherHook(RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OVER, events, onRoomWidgetRoomObjectUpdateEvent); CreateEventDispatcherHook(RoomWidgetRoomObjectUpdateEvent.OBJECT_ROLL_OUT, events, onRoomWidgetRoomObjectUpdateEvent); - return null; + CreateEventDispatcherHook(RoomWidgetRoomEngineUpdateEvent.RWREUE_NORMAL_MODE, events, onRoomWidgetRoomEngineUpdateEvent); + CreateEventDispatcherHook(RoomWidgetRoomEngineUpdateEvent.RWREUE_GAME_MODE, events, onRoomWidgetRoomEngineUpdateEvent); + + return ( + <> + { names && (names.length > 0) && names.map((data, index) => + { + return + }) } + + ) } diff --git a/src/views/room/widgets/avatar-info/views/name/AvatarInfoWidgetNameView.tsx b/src/views/room/widgets/avatar-info/views/name/AvatarInfoWidgetNameView.tsx new file mode 100644 index 00000000..0dfcfd4a --- /dev/null +++ b/src/views/room/widgets/avatar-info/views/name/AvatarInfoWidgetNameView.tsx @@ -0,0 +1,15 @@ +import { FC } from 'react'; +import { ObjectLocationView } from '../../../object-location/ObjectLocationView'; +import { AvatarInfoWidgetNameViewProps } from './AvatarInfoWidgetNameView.types'; + +export const AvatarInfoWidgetNameView: FC = props => +{ + const { nameData = null } = props; + const { objectId = -1, category = -1, id = -1, name = '', type = '' } = nameData; + + return ( + + { name } + + ); +} diff --git a/src/views/room/widgets/avatar-info/views/name/AvatarInfoWidgetNameView.types.ts b/src/views/room/widgets/avatar-info/views/name/AvatarInfoWidgetNameView.types.ts new file mode 100644 index 00000000..7cf34445 --- /dev/null +++ b/src/views/room/widgets/avatar-info/views/name/AvatarInfoWidgetNameView.types.ts @@ -0,0 +1,6 @@ +import { RoomObjectNameData } from '../../utils/RoomObjectNameData'; + +export interface AvatarInfoWidgetNameViewProps +{ + nameData: RoomObjectNameData; +} diff --git a/src/views/room/widgets/furniture/manipulation-menu/FurnitureManipulationMenuView.tsx b/src/views/room/widgets/furniture/manipulation-menu/FurnitureManipulationMenuView.tsx index bd4475d2..1b1d447a 100644 --- a/src/views/room/widgets/furniture/manipulation-menu/FurnitureManipulationMenuView.tsx +++ b/src/views/room/widgets/furniture/manipulation-menu/FurnitureManipulationMenuView.tsx @@ -57,7 +57,7 @@ export const FurnitureManipulationMenuView: FC +