From f6f22b2961208692cc7e85780e655c87e231de3f Mon Sep 17 00:00:00 2001 From: Bill Date: Thu, 5 Jan 2023 13:21:27 -0500 Subject: [PATCH] Fix pet training window --- .../room/widgets/RoomWidgetsView.tsx | 2 -- .../AvatarInfoPetTrainingPanelView.tsx} | 31 ++++++++++--------- .../avatar-info/AvatarInfoWidgetView.tsx | 2 ++ .../rooms/widgets/useAvatarInfoWidget.ts | 7 ++--- 4 files changed, 20 insertions(+), 22 deletions(-) rename src/components/room/widgets/{pet-training/PetTrainingPanelWidgetView.tsx => avatar-info/AvatarInfoPetTrainingPanelView.tsx} (63%) diff --git a/src/components/room/widgets/RoomWidgetsView.tsx b/src/components/room/widgets/RoomWidgetsView.tsx index 59e9cfbf..8f1bd8a6 100644 --- a/src/components/room/widgets/RoomWidgetsView.tsx +++ b/src/components/room/widgets/RoomWidgetsView.tsx @@ -10,7 +10,6 @@ import { UserChooserWidgetView } from './choosers/UserChooserWidgetView'; import { DoorbellWidgetView } from './doorbell/DoorbellWidgetView'; import { FriendRequestWidgetView } from './friend-request/FriendRequestWidgetView'; import { FurnitureWidgetsView } from './furniture/FurnitureWidgetsView'; -import { PetTrainingPanelWidgetView } from './pet-training/PetTrainingPanelWidgetView'; import { RoomFilterWordsWidgetView } from './room-filter-words/RoomFilterWordsWidgetView'; import { RoomThumbnailWidgetView } from './room-thumbnail/RoomThumbnailWidgetView'; import { RoomToolsWidgetView } from './room-tools/RoomToolsWidgetView'; @@ -166,7 +165,6 @@ export const RoomWidgetsView: FC<{}> = props => - ); } diff --git a/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx b/src/components/room/widgets/avatar-info/AvatarInfoPetTrainingPanelView.tsx similarity index 63% rename from src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx rename to src/components/room/widgets/avatar-info/AvatarInfoPetTrainingPanelView.tsx index 22d95cc0..8e2e566c 100644 --- a/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx +++ b/src/components/room/widgets/avatar-info/AvatarInfoPetTrainingPanelView.tsx @@ -1,26 +1,27 @@ -import { DesktopViewEvent, PetTrainingPanelMessageEvent } from '@nitrots/nitro-renderer'; -import { FC } from 'react'; -import { AvatarInfoPet, LocalizeText } from '../../../../api'; +import { IRoomUserData, PetTrainingMessageParser, PetTrainingPanelMessageEvent } from '@nitrots/nitro-renderer'; +import { FC, useState } from 'react'; +import { LocalizeText } from '../../../../api'; import { Button, Column, Flex, Grid, LayoutPetImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; -import { useAvatarInfoWidget, useMessageEvent, useRoom, useSessionInfo } from '../../../../hooks'; +import { useMessageEvent, useRoom, useSessionInfo } from '../../../../hooks'; -export const PetTrainingPanelWidgetView: FC<{}> = props => +export const AvatarInfoPetTrainingPanelView: FC<{}> = props => { - const { avatarInfo = null, petTrainInformation = null, setPetTrainInformation = null } = useAvatarInfoWidget(); + const [ petData, setPetData ] = useState(null); + const [ petTrainInformation, setPetTrainInformation ] = useState(null); const { chatStyleId = 0 } = useSessionInfo(); const { roomSession = null } = useRoom(); - useMessageEvent(DesktopViewEvent, event => - { - setPetTrainInformation(null); - }); - useMessageEvent(PetTrainingPanelMessageEvent, event => { const parser = event.getParser(); if (!parser) return; + const roomPetData = roomSession.userDataManager.getPetData(parser.petId); + + if(!roomPetData) return; + + setPetData(roomPetData); setPetTrainInformation(parser); }); @@ -31,7 +32,7 @@ export const PetTrainingPanelWidgetView: FC<{}> = props => roomSession?.sendChatMessage(`${ petName } ${ commandName }`, chatStyleId); } - if(!petTrainInformation) return null; + if(!petData || !petTrainInformation) return null; return ( @@ -40,15 +41,15 @@ export const PetTrainingPanelWidgetView: FC<{}> = props => - + - { (avatarInfo as AvatarInfoPet)?.name } + { petData.name } { (petTrainInformation.commands && petTrainInformation.commands.length > 0) && petTrainInformation.commands.map((command, index) => - + ) } diff --git a/src/components/room/widgets/avatar-info/AvatarInfoWidgetView.tsx b/src/components/room/widgets/avatar-info/AvatarInfoWidgetView.tsx index f70c2b0a..5a0acf1d 100644 --- a/src/components/room/widgets/avatar-info/AvatarInfoWidgetView.tsx +++ b/src/components/room/widgets/avatar-info/AvatarInfoWidgetView.tsx @@ -3,6 +3,7 @@ import { FC, useState } from 'react'; import { AvatarInfoFurni, AvatarInfoPet, AvatarInfoRentableBot, AvatarInfoUser, GetConfiguration, GetSessionDataManager, RoomWidgetUpdateRentableBotChatEvent } from '../../../../api'; import { Column } from '../../../../common'; import { useAvatarInfoWidget, useRoom, useRoomEngineEvent, useRoomSessionManagerEvent, useUiEvent } from '../../../../hooks'; +import { AvatarInfoPetTrainingPanelView } from './AvatarInfoPetTrainingPanelView'; import { AvatarInfoRentableBotChatView } from './AvatarInfoRentableBotChatView'; import { AvatarInfoUseProductConfirmView } from './AvatarInfoUseProductConfirmView'; import { AvatarInfoUseProductView } from './AvatarInfoUseProductView'; @@ -132,6 +133,7 @@ export const AvatarInfoWidgetView: FC<{}> = props => }) } { rentableBotChatEvent && setRentableBotChatEvent(null) }/> } { confirmingProduct && updateConfirmingProduct(null) } /> } + ) } diff --git a/src/hooks/rooms/widgets/useAvatarInfoWidget.ts b/src/hooks/rooms/widgets/useAvatarInfoWidget.ts index afe46658..9545362a 100644 --- a/src/hooks/rooms/widgets/useAvatarInfoWidget.ts +++ b/src/hooks/rooms/widgets/useAvatarInfoWidget.ts @@ -1,4 +1,4 @@ -import { PetTrainingMessageParser, RoomEngineObjectEvent, RoomEngineUseProductEvent, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomSessionPetInfoUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionUserDataUpdateEvent } from '@nitrots/nitro-renderer'; +import { RoomEngineObjectEvent, RoomEngineUseProductEvent, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomSessionPetInfoUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionUserDataUpdateEvent } from '@nitrots/nitro-renderer'; import { useEffect, useState } from 'react'; import { AvatarInfoFurni, AvatarInfoName, AvatarInfoPet, AvatarInfoRentableBot, AvatarInfoUser, AvatarInfoUtilities, CanManipulateFurniture, FurniCategory, GetRoomEngine, GetSessionDataManager, IAvatarInfo, IsOwnerOfFurniture, RoomWidgetUpdateRoomObjectEvent, UseProductItem } from '../../../api'; import { useRoomEngineEvent, useRoomSessionManagerEvent, useUiEvent } from '../../events'; @@ -14,7 +14,6 @@ const useAvatarInfoWidgetState = () => const [ nameBubbles, setNameBubbles ] = useState([]); const [ productBubbles, setProductBubbles ] = useState([]); const [ confirmingProduct, setConfirmingProduct ] = useState(null); - const [ petTrainInformation, setPetTrainInformation ] = useState(null); const [ pendingPetId, setPendingPetId ] = useState(-1); const [ isDecorating, setIsDecorating ] = useState(false); const { friends = [] } = useFriends(); @@ -66,7 +65,6 @@ const useAvatarInfoWidgetState = () => const getObjectInfo = (objectId: number, category: number) => { let info: IAvatarInfo = null; - setPetTrainInformation(null); switch(category) { @@ -274,7 +272,6 @@ const useAvatarInfoWidgetState = () => useObjectDeselectedEvent(event => { setAvatarInfo(null); - setPetTrainInformation(null); setProductBubbles([]); }); @@ -352,7 +349,7 @@ const useAvatarInfoWidgetState = () => roomSession.isDecorating = isDecorating; }, [ roomSession, isDecorating ]); - return { avatarInfo, setAvatarInfo, activeNameBubble, setActiveNameBubble, nameBubbles, productBubbles, confirmingProduct, petTrainInformation, setPetTrainInformation, isDecorating, setIsDecorating, removeNameBubble, removeProductBubble, updateConfirmingProduct, getObjectName }; + return { avatarInfo, setAvatarInfo, activeNameBubble, setActiveNameBubble, nameBubbles, productBubbles, confirmingProduct, isDecorating, setIsDecorating, removeNameBubble, removeProductBubble, updateConfirmingProduct, getObjectName }; } export const useAvatarInfoWidget = useAvatarInfoWidgetState;