From 51db1f3aa32faea2e36da6758fda8123cb803e54 Mon Sep 17 00:00:00 2001 From: Bill Date: Sat, 23 Jul 2022 21:15:24 -0400 Subject: [PATCH] Changes --- .../menu/AvatarInfoWidgetOwnPetView.tsx | 30 ++++++------- .../menu/AvatarInfoWidgetPetView.tsx | 26 +++++------ .../widgets/chat/ChatWidgetMessageView.tsx | 7 ++- .../room/widgets/chat/ChatWidgetView.tsx | 26 ++++------- .../object-location/ObjectLocationView.tsx | 44 +++++++++---------- .../room-tools/RoomToolsWidgetView.tsx | 9 ++-- src/hooks/events/useEventDispatcher.tsx | 6 ++- src/hooks/events/useUiEvent.tsx | 2 +- src/hooks/wired/useWired.ts | 26 ++++++++++- 9 files changed, 94 insertions(+), 82 deletions(-) diff --git a/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx b/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx index 5c390eda..e69ce62a 100644 --- a/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx +++ b/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx @@ -12,15 +12,15 @@ interface AvatarInfoWidgetOwnPetViewProps close: () => void; } -const _Str_2906: number = 0; -const _Str_5818: number = 1; -const _Str_5938: number = 2; -const _Str_10946: number = 3; +const MODE_NORMAL: number = 0; +const MODE_SADDLED_UP: number = 1; +const MODE_RIDING: number = 2; +const MODE_MONSTER_PLANT: number = 3; export const AvatarInfoWidgetOwnPetView: FC = props => { const { avatarInfo = null, close = null } = props; - const [ mode, setMode ] = useState(_Str_2906); + const [ mode, setMode ] = useState(MODE_NORMAL); const [ respectsLeft, setRespectsLeft ] = useState(0); const { roomSession = null } = useRoom(); @@ -90,7 +90,7 @@ export const AvatarInfoWidgetOwnPetView: FC = p roomSession.removePetSaddle(avatarInfo.id); break; case 'breed': - if(mode === _Str_2906) + if(mode === MODE_NORMAL) { // _local_7 = RoomWidgetPetCommandMessage._Str_16282; // _local_8 = ("pet.command." + _local_7); @@ -98,7 +98,7 @@ export const AvatarInfoWidgetOwnPetView: FC = p // _local_4 = new RoomWidgetPetCommandMessage(RoomWidgetPetCommandMessage.RWPCM_PET_COMMAND, this._Str_594.id, ((this._Str_594.name + " ") + _local_9)); } - else if(mode === _Str_10946) + else if(mode === MODE_MONSTER_PLANT) { // messageType = RoomWidgetUserActionMessage.REQUEST_BREED_PET; } @@ -125,11 +125,11 @@ export const AvatarInfoWidgetOwnPetView: FC = p { setMode(prevValue => { - if(avatarInfo.petType === PetType.MONSTERPLANT) return _Str_10946; - else if(avatarInfo.saddle && !avatarInfo.rider) return _Str_5818; - else if(avatarInfo.rider) return _Str_5938; + if(avatarInfo.petType === PetType.MONSTERPLANT) return MODE_MONSTER_PLANT; + else if(avatarInfo.saddle && !avatarInfo.rider) return MODE_SADDLED_UP; + else if(avatarInfo.rider) return MODE_RIDING; - return _Str_2906; + return MODE_NORMAL; }); setRespectsLeft(avatarInfo.respectsPetLeft); @@ -140,7 +140,7 @@ export const AvatarInfoWidgetOwnPetView: FC = p { avatarInfo.name } - { (mode === _Str_2906) && + { (mode === MODE_NORMAL) && <> { (respectsLeft > 0) && processAction('respect') }> @@ -161,7 +161,7 @@ export const AvatarInfoWidgetOwnPetView: FC = p { LocalizeText('infostand.button.breed') } } } - { (mode === _Str_5818) && + { (mode === MODE_SADDLED_UP) && <> processAction('mount') }> { LocalizeText('infostand.button.mount') } @@ -184,7 +184,7 @@ export const AvatarInfoWidgetOwnPetView: FC = p { LocalizeText('infostand.button.saddleoff') } } - { (mode === _Str_5938) && + { (mode === MODE_RIDING) && <> processAction('dismount') }> { LocalizeText('infostand.button.dismount') } @@ -194,7 +194,7 @@ export const AvatarInfoWidgetOwnPetView: FC = p { LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) } } } - { (mode === _Str_10946) && + { (mode === MODE_MONSTER_PLANT) && <> processAction('pick_up') }> { LocalizeText('infostand.button.pickup') } diff --git a/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetPetView.tsx b/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetPetView.tsx index 2107e216..08fd69cf 100644 --- a/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetPetView.tsx +++ b/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetPetView.tsx @@ -12,15 +12,15 @@ interface AvatarInfoWidgetPetViewProps close: () => void; } -const _Str_2906: number = 0; -const _Str_5818: number = 1; -const _Str_5938: number = 2; -const _Str_13388: number = 3; +const MODE_NORMAL: number = 0; +const MODE_SADDLED_UP: number = 1; +const MODE_RIDING: number = 2; +const MODE_MONSTER_PLANT: number = 3; export const AvatarInfoWidgetPetView: FC = props => { const { avatarInfo = null, close = null } = props; - const [ mode, setMode ] = useState(_Str_2906); + const [ mode, setMode ] = useState(MODE_NORMAL); const [ respectsLeft, setRespectsLeft ] = useState(0); const { roomSession = null } = useRoom(); @@ -92,11 +92,11 @@ export const AvatarInfoWidgetPetView: FC = props = { setMode(prevValue => { - if(avatarInfo.petType === PetType.MONSTERPLANT) return _Str_13388; - else if(avatarInfo.saddle && !avatarInfo.rider) return _Str_5818; - else if(avatarInfo.rider) return _Str_5938; + if(avatarInfo.petType === PetType.MONSTERPLANT) return MODE_MONSTER_PLANT; + else if(avatarInfo.saddle && !avatarInfo.rider) return MODE_SADDLED_UP; + else if(avatarInfo.rider) return MODE_RIDING; - return _Str_2906; + return MODE_NORMAL; }); setRespectsLeft(avatarInfo.respectsPetLeft); @@ -107,11 +107,11 @@ export const AvatarInfoWidgetPetView: FC = props = { avatarInfo.name } - { (mode === _Str_2906) && (respectsLeft > 0) && + { (mode === MODE_NORMAL) && (respectsLeft > 0) && processAction('respect') }> { LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) } } - { (mode === _Str_5818) && + { (mode === MODE_SADDLED_UP) && <> { !!avatarInfo.publiclyRideable && processAction('mount') }> @@ -122,7 +122,7 @@ export const AvatarInfoWidgetPetView: FC = props = { LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) } } } - { (mode === _Str_5938) && + { (mode === MODE_RIDING) && <> processAction('dismount') }> { LocalizeText('infostand.button.dismount') } @@ -132,7 +132,7 @@ export const AvatarInfoWidgetPetView: FC = props = { LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) } } } - { (mode === _Str_13388) && !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) && + { (mode === MODE_MONSTER_PLANT) && !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) && processAction('treat') }> { LocalizeText('infostand.button.treat') } } diff --git a/src/components/room/widgets/chat/ChatWidgetMessageView.tsx b/src/components/room/widgets/chat/ChatWidgetMessageView.tsx index fd117cef..98891e94 100644 --- a/src/components/room/widgets/chat/ChatWidgetMessageView.tsx +++ b/src/components/room/widgets/chat/ChatWidgetMessageView.tsx @@ -1,18 +1,17 @@ import { RoomChatSettings } from '@nitrots/nitro-renderer'; import { FC, useEffect, useMemo, useRef, useState } from 'react'; -import { ChatBubbleMessage } from '../../../../api'; +import { ChatBubbleMessage, GetRoomEngine } from '../../../../api'; interface ChatWidgetMessageViewProps { chat: ChatBubbleMessage; makeRoom: (chat: ChatBubbleMessage) => void; - onChatClicked: (chat: ChatBubbleMessage) => void; bubbleWidth?: number; } export const ChatWidgetMessageView: FC = props => { - const { chat = null, makeRoom = null, onChatClicked = null, bubbleWidth = RoomChatSettings.CHAT_BUBBLE_WIDTH_NORMAL } = props; + const { chat = null, makeRoom = null, bubbleWidth = RoomChatSettings.CHAT_BUBBLE_WIDTH_NORMAL } = props; const [ isVisible, setIsVisible ] = useState(false); const elementRef = useRef(); @@ -70,7 +69,7 @@ export const ChatWidgetMessageView: FC = props => useEffect(() => setIsVisible(chat.visible), [ chat.visible ]); return ( -
onChatClicked(chat) }> +
GetRoomEngine().setSelectedAvatar(chat.roomId, chat.senderId) }> { (chat.styleId === 0) &&
}
diff --git a/src/components/room/widgets/chat/ChatWidgetView.tsx b/src/components/room/widgets/chat/ChatWidgetView.tsx index bb98df31..4a28746b 100644 --- a/src/components/room/widgets/chat/ChatWidgetView.tsx +++ b/src/components/room/widgets/chat/ChatWidgetView.tsx @@ -1,6 +1,6 @@ import { IWorkerEventTracker, RoomChatSettings } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useRef, useState } from 'react'; -import { AddWorkerEventTracker, ChatBubbleMessage, DoChatsOverlap, GetConfiguration, GetRoomEngine, RemoveWorkerEventTracker, SendWorkerEvent } from '../../../../api'; +import { FC, useEffect, useRef, useState } from 'react'; +import { AddWorkerEventTracker, ChatBubbleMessage, DoChatsOverlap, GetConfiguration, RemoveWorkerEventTracker, SendWorkerEvent } from '../../../../api'; import { useChatWidget } from '../../../../hooks'; import { ChatWidgetMessageView } from './ChatWidgetMessageView'; @@ -12,7 +12,7 @@ export const ChatWidgetView: FC<{}> = props => const { chatMessages = [], setChatMessages = null, chatSettings = null, getScrollSpeed = 6000, removeHiddenChats = null, moveAllChatsUp = null } = useChatWidget(); const elementRef = useRef(); - const checkOverlappingChats = useCallback((chat: ChatBubbleMessage, moved: number, tempChats: ChatBubbleMessage[]) => + const checkOverlappingChats = (chat: ChatBubbleMessage, moved: number, tempChats: ChatBubbleMessage[]) => { const totalChats = chatMessages.length; @@ -37,9 +37,9 @@ export const ChatWidgetView: FC<{}> = props => checkOverlappingChats(collides, amount, tempChats); } } - }, [ chatMessages ]); + } - const makeRoom = useCallback((chat: ChatBubbleMessage) => + const makeRoom = (chat: ChatBubbleMessage) => { if(chatSettings.mode === RoomChatSettings.CHAT_MODE_FREE_FLOW) { @@ -68,19 +68,11 @@ export const ChatWidgetView: FC<{}> = props => removeHiddenChats(); } } - }, [ chatSettings, chatMessages, removeHiddenChats, checkOverlappingChats ]); - - const onChatClicked = useCallback((chat: ChatBubbleMessage) => - { - //widgetHandler.processWidgetMessage(new RoomWidgetRoomObjectMessage(RoomWidgetRoomObjectMessage.GET_OBJECT_INFO, chat.senderId, chat.senderCategory)); - - GetRoomEngine().setSelectedAvatar(chat.roomId, chat.senderId); - //widgetHandler.processWidgetMessage(new RoomWidgetChatSelectAvatarMessage(RoomWidgetChatSelectAvatarMessage.MESSAGE_SELECT_AVATAR, chat.senderId, chat.username, chat.roomId)); - }, []); + } useEffect(() => { - const resize = (event: UIEvent) => + const resize = (event: UIEvent = null) => { if(!elementRef || !elementRef.current) return; @@ -102,7 +94,7 @@ export const ChatWidgetView: FC<{}> = props => window.addEventListener('resize', resize); - resize(null); + resize(); return () => { @@ -146,7 +138,7 @@ export const ChatWidgetView: FC<{}> = props => return (
- { chatMessages.map(chat => ) } + { chatMessages.map(chat => ) }
); } diff --git a/src/components/room/widgets/object-location/ObjectLocationView.tsx b/src/components/room/widgets/object-location/ObjectLocationView.tsx index b4dd23ca..acd21fb1 100644 --- a/src/components/room/widgets/object-location/ObjectLocationView.tsx +++ b/src/components/room/widgets/object-location/ObjectLocationView.tsx @@ -1,4 +1,4 @@ -import { FC, useCallback, useEffect, useRef, useState } from 'react'; +import { FC, useEffect, useRef, useState } from 'react'; import { GetNitroInstance, GetRoomObjectBounds, GetRoomSession } from '../../../../api'; import { Base, BaseProps } from '../../../../common'; @@ -15,30 +15,30 @@ export const ObjectLocationView: FC = props => const [ pos, setPos ] = useState<{ x: number, y: number }>({ x: -1, y: -1 }); const elementRef = useRef(); - const getObjectLocation = useCallback(() => - { - const roomSession = GetRoomSession(); - const objectBounds = GetRoomObjectBounds(roomSession.roomId, objectId, category, 1); - - return objectBounds; - }, [ objectId, category ]); - - const updatePosition = useCallback(() => - { - const bounds = getObjectLocation(); - - if(!bounds || !elementRef.current) return; - - setPos({ - x: Math.round(((bounds.left + (bounds.width / 2)) - (elementRef.current.offsetWidth / 2))), - y: Math.round((bounds.top - elementRef.current.offsetHeight) + 10) - }); - }, [ getObjectLocation ]); - useEffect(() => { let remove = false; + const getObjectLocation = () => + { + const roomSession = GetRoomSession(); + const objectBounds = GetRoomObjectBounds(roomSession.roomId, objectId, category, 1); + + return objectBounds; + } + + const updatePosition = () => + { + const bounds = getObjectLocation(); + + if(!bounds || !elementRef.current) return; + + setPos({ + x: Math.round(((bounds.left + (bounds.width / 2)) - (elementRef.current.offsetWidth / 2))), + y: Math.round((bounds.top - elementRef.current.offsetHeight) + 10) + }); + } + if(noFollow) { updatePosition(); @@ -54,7 +54,7 @@ export const ObjectLocationView: FC = props => { if(remove) GetNitroInstance().ticker.remove(updatePosition); } - }, [ updatePosition, noFollow ]); + }, [ objectId, category, noFollow ]); return -1 } className="object-location" style={ { left: pos.x, top: pos.y } } { ...rest } />; } diff --git a/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx b/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx index 53d1731f..588b9523 100644 --- a/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx +++ b/src/components/room/widgets/room-tools/RoomToolsWidgetView.tsx @@ -1,6 +1,6 @@ import { GetGuestRoomResultEvent, RateFlatMessageComposer } from '@nitrots/nitro-renderer'; import classNames from 'classnames'; -import { FC, useCallback, useEffect, useState } from 'react'; +import { FC, useEffect, useState } from 'react'; import { CreateLinkEvent, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api'; import { Base, Column, Flex, Text, TransitionAnimation, TransitionAnimationTypes } from '../../../../common'; import { useMessageEvent, useRoom, useSharedNavigatorData } from '../../../../hooks'; @@ -11,7 +11,6 @@ export const RoomToolsWidgetView: FC<{}> = props => const [ roomName, setRoomName ] = useState(null); const [ roomOwner, setRoomOwner ] = useState(null); const [ roomTags, setRoomTags ] = useState(null); - const [ roomInfoDisplay, setRoomInfoDisplay ] = useState(false); const [ isOpen, setIsOpen ] = useState(false); const [ navigatorData, setNavigatorData ] = useSharedNavigatorData(); const { roomSession = null } = useRoom(); @@ -48,7 +47,7 @@ export const RoomToolsWidgetView: FC<{}> = props => } } - const onGetGuestRoomResultEvent = useCallback((event: GetGuestRoomResultEvent) => + useMessageEvent(GetGuestRoomResultEvent, event => { const parser = event.getParser(); @@ -57,9 +56,7 @@ export const RoomToolsWidgetView: FC<{}> = props => if(roomName !== parser.data.roomName) setRoomName(parser.data.roomName); if(roomOwner !== parser.data.ownerName) setRoomOwner(parser.data.ownerName); if(roomTags !== parser.data.tags) setRoomTags(parser.data.tags); - }, [ roomSession, roomName, roomOwner, roomTags ]); - - useMessageEvent(GetGuestRoomResultEvent, onGetGuestRoomResultEvent); + }); useEffect(() => { diff --git a/src/hooks/events/useEventDispatcher.tsx b/src/hooks/events/useEventDispatcher.tsx index f109c5f0..60555f2e 100644 --- a/src/hooks/events/useEventDispatcher.tsx +++ b/src/hooks/events/useEventDispatcher.tsx @@ -1,10 +1,12 @@ import { IEventDispatcher, NitroEvent } from '@nitrots/nitro-renderer'; import { useEffect } from 'react'; -export const useEventDispatcher = (type: string | string[], eventDispatcher: IEventDispatcher, handler: (event: T) => void) => +export const useEventDispatcher = (type: string | string[], eventDispatcher: IEventDispatcher, handler: (event: T) => void, enabled: boolean = true) => { useEffect(() => { + if(!enabled) return; + if(Array.isArray(type)) { type.map(name => eventDispatcher.addEventListener(name, handler)); @@ -25,5 +27,5 @@ export const useEventDispatcher = (type: string | string[] eventDispatcher.removeEventListener(type, handler); } } - }, [ type, eventDispatcher, handler ]); + }, [ type, eventDispatcher, enabled, handler ]); } diff --git a/src/hooks/events/useUiEvent.tsx b/src/hooks/events/useUiEvent.tsx index b77285d9..02c0aff4 100644 --- a/src/hooks/events/useUiEvent.tsx +++ b/src/hooks/events/useUiEvent.tsx @@ -2,4 +2,4 @@ import { NitroEvent } from '@nitrots/nitro-renderer'; import { UI_EVENT_DISPATCHER } from '../../api'; import { useEventDispatcher } from './useEventDispatcher'; -export const useUiEvent = (type: string | string[], handler: (event: T) => void) => useEventDispatcher(type, UI_EVENT_DISPATCHER, handler); +export const useUiEvent = (type: string | string[], handler: (event: T) => void, enabled: boolean = true) => useEventDispatcher(type, UI_EVENT_DISPATCHER, handler, enabled); diff --git a/src/hooks/wired/useWired.ts b/src/hooks/wired/useWired.ts index e4583c90..ae3e983a 100644 --- a/src/hooks/wired/useWired.ts +++ b/src/hooks/wired/useWired.ts @@ -1,5 +1,5 @@ -import { ConditionDefinition, Triggerable, TriggerDefinition, UpdateActionMessageComposer, UpdateConditionMessageComposer, UpdateTriggerMessageComposer, WiredActionDefinition, WiredFurniActionEvent, WiredFurniConditionEvent, WiredFurniTriggerEvent } from '@nitrots/nitro-renderer'; -import { useState } from 'react'; +import { ConditionDefinition, Triggerable, TriggerDefinition, UpdateActionMessageComposer, UpdateConditionMessageComposer, UpdateTriggerMessageComposer, WiredActionDefinition, WiredFurniActionEvent, WiredFurniConditionEvent, WiredFurniTriggerEvent, WiredSaveSuccessEvent } from '@nitrots/nitro-renderer'; +import { useEffect, useState } from 'react'; import { useBetween } from 'use-between'; import { IsOwnerOfFloorFurniture, LocalizeText, NotificationUtilities, SendMessageComposer, WiredSelectionVisualizer } from '../../api'; import { WiredSelectObjectEvent } from '../../events'; @@ -50,6 +50,8 @@ const useWiredState = () => useUiEvent(WiredSelectObjectEvent.SELECT_OBJECT, event => { + if(!trigger) return; + const furniId = event.objectId; if(furniId <= 0) return; @@ -78,6 +80,13 @@ const useWiredState = () => }); }, !!trigger); + useMessageEvent(WiredSaveSuccessEvent, event => + { + const parser = event.getParser(); + + setTrigger(null); + }); + useMessageEvent(WiredFurniActionEvent, event => { const parser = event.getParser(); @@ -99,6 +108,19 @@ const useWiredState = () => setTrigger(parser.definition); }); + useEffect(() => + { + if(!trigger) return; + + return () => + { + setIntParams([]); + setStringParam(''); + setFurniIds([]); + setActionDelay(0); + } + }, [ trigger ]); + return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, saveWired }; }