From 3d413ac5bad9ae7fb1507affb02b73c1f4508563 Mon Sep 17 00:00:00 2001 From: oobjectt Date: Tue, 20 Dec 2022 00:48:22 +0100 Subject: [PATCH 1/3] New panel for pet training --- .../room/widgets/RoomWidgetsView.tsx | 4 +- .../infostand/InfoStandWidgetPetView.tsx | 4 +- .../menu/AvatarInfoWidgetOwnPetView.tsx | 2 +- .../PetTrainingPanelWidgetView.tsx | 56 +++++++++++++++++++ .../rooms/widgets/useAvatarInfoWidget.ts | 7 ++- 5 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx diff --git a/src/components/room/widgets/RoomWidgetsView.tsx b/src/components/room/widgets/RoomWidgetsView.tsx index 83cbb190..ee3ee54f 100644 --- a/src/components/room/widgets/RoomWidgetsView.tsx +++ b/src/components/room/widgets/RoomWidgetsView.tsx @@ -10,6 +10,7 @@ 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 { RoomThumbnailWidgetView } from './room-thumbnail/RoomThumbnailWidgetView'; import { RoomToolsWidgetView } from './room-tools/RoomToolsWidgetView'; import { WordQuizWidgetView } from './word-quiz/WordQuizWidgetView'; @@ -75,7 +76,7 @@ export const RoomWidgetsView: FC<{}> = props => } if(!updateEvent) return; - + let dispatchEvent = true; if(RoomId.isRoomPreviewerId(updateEvent.roomId)) return; @@ -163,6 +164,7 @@ export const RoomWidgetsView: FC<{}> = props => + ); } diff --git a/src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx b/src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx index a590b785..91bb06f8 100644 --- a/src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx +++ b/src/components/room/widgets/avatar-info/infostand/InfoStandWidgetPetView.tsx @@ -28,7 +28,7 @@ export const InfoStandWidgetPetView: FC = props => useEffect(() => { if((avatarInfo.petType !== PetType.MONSTERPLANT) || avatarInfo.dead) return; - + const interval = setInterval(() => { setRemainingGrowTime(prevValue => (prevValue - 1)); @@ -57,7 +57,7 @@ export const InfoStandWidgetPetView: FC = props => CreateLinkEvent('catalog/open/' + GetConfiguration('catalog.links')['pets.buy_saddle']); break; case 'train': - // not coded + roomSession?.requestPetCommands(avatarInfo.id); break; case 'treat': SendMessageComposer(new PetRespectComposer(avatarInfo.id)); diff --git a/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx b/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx index af889c12..cdd4bba4 100644 --- a/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx +++ b/src/components/room/widgets/avatar-info/menu/AvatarInfoWidgetOwnPetView.tsx @@ -60,7 +60,7 @@ export const AvatarInfoWidgetOwnPetView: FC = p SendMessageComposer(new RoomUnitGiveHandItemPetComposer(avatarInfo.id)); break; case 'train': - //this.widget._Str_23877(); + roomSession.requestPetCommands(avatarInfo.id); break; case 'pick_up': roomSession.pickupPet(avatarInfo.id); diff --git a/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx b/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx new file mode 100644 index 00000000..08d8da71 --- /dev/null +++ b/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx @@ -0,0 +1,56 @@ +import { DesktopViewEvent, PetTrainingPanelMessageEvent } from '@nitrots/nitro-renderer'; +import { FC } from 'react'; +import { AvatarInfoPet, LocalizeText } from '../../../../api'; +import { Button, Column, Flex, Grid, LayoutPetImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; +import { useAvatarInfoWidget, useMessageEvent } from '../../../../hooks'; + +export const PetTrainingPanelWidgetView: FC<{}> = props => +{ + const { avatarInfo = null, petTrainInformation = null, setTrainPetInformation = null } = useAvatarInfoWidget(); + + useMessageEvent(DesktopViewEvent, event => + { + setTrainPetInformation(null); + }); + + useMessageEvent(PetTrainingPanelMessageEvent, event => + { + const parser = event.getParser(); + + if (!parser) return; + + setTrainPetInformation(parser); + }); + + const processPetAction = (petId: number, type: string) => + { + if (!petId || !type) return; + + // packet for pet actions + } + + if(!petTrainInformation) return null; + + return ( + + setTrainPetInformation(null) } /> + + + + + + + { (avatarInfo as AvatarInfoPet)?.name } + + + + { + (petTrainInformation.commands && petTrainInformation.commands.length > 0) && petTrainInformation.commands.map((command, index) => + + ) + } + + + + ); +}; diff --git a/src/hooks/rooms/widgets/useAvatarInfoWidget.ts b/src/hooks/rooms/widgets/useAvatarInfoWidget.ts index 9545362a..aacf50e5 100644 --- a/src/hooks/rooms/widgets/useAvatarInfoWidget.ts +++ b/src/hooks/rooms/widgets/useAvatarInfoWidget.ts @@ -1,4 +1,4 @@ -import { RoomEngineObjectEvent, RoomEngineUseProductEvent, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomSessionPetInfoUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionUserDataUpdateEvent } from '@nitrots/nitro-renderer'; +import { PetTrainingMessageParser, 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,6 +14,7 @@ const useAvatarInfoWidgetState = () => const [ nameBubbles, setNameBubbles ] = useState([]); const [ productBubbles, setProductBubbles ] = useState([]); const [ confirmingProduct, setConfirmingProduct ] = useState(null); + const [ petTrainInformation, setTrainPetInformation ] = useState(null); const [ pendingPetId, setPendingPetId ] = useState(-1); const [ isDecorating, setIsDecorating ] = useState(false); const { friends = [] } = useFriends(); @@ -65,6 +66,7 @@ const useAvatarInfoWidgetState = () => const getObjectInfo = (objectId: number, category: number) => { let info: IAvatarInfo = null; + setTrainPetInformation(null); switch(category) { @@ -272,6 +274,7 @@ const useAvatarInfoWidgetState = () => useObjectDeselectedEvent(event => { setAvatarInfo(null); + setTrainPetInformation(null); setProductBubbles([]); }); @@ -349,7 +352,7 @@ const useAvatarInfoWidgetState = () => roomSession.isDecorating = isDecorating; }, [ roomSession, isDecorating ]); - return { avatarInfo, setAvatarInfo, activeNameBubble, setActiveNameBubble, nameBubbles, productBubbles, confirmingProduct, isDecorating, setIsDecorating, removeNameBubble, removeProductBubble, updateConfirmingProduct, getObjectName }; + return { avatarInfo, setAvatarInfo, activeNameBubble, setActiveNameBubble, nameBubbles, productBubbles, confirmingProduct, petTrainInformation, setTrainPetInformation, isDecorating, setIsDecorating, removeNameBubble, removeProductBubble, updateConfirmingProduct, getObjectName }; } export const useAvatarInfoWidget = useAvatarInfoWidgetState; From 2b80b15fdab32ef5536a5f119cf2a4e108922304 Mon Sep 17 00:00:00 2001 From: oobjectt Date: Tue, 20 Dec 2022 21:59:19 +0100 Subject: [PATCH 2/3] Changing details --- .../pet-training/PetTrainingPanelWidgetView.tsx | 12 ++++++------ src/hooks/rooms/widgets/useAvatarInfoWidget.ts | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx b/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx index 08d8da71..170f2332 100644 --- a/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx +++ b/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx @@ -6,11 +6,11 @@ import { useAvatarInfoWidget, useMessageEvent } from '../../../../hooks'; export const PetTrainingPanelWidgetView: FC<{}> = props => { - const { avatarInfo = null, petTrainInformation = null, setTrainPetInformation = null } = useAvatarInfoWidget(); + const { avatarInfo = null, petTrainInformation = null, setPetTrainInformation = null } = useAvatarInfoWidget(); useMessageEvent(DesktopViewEvent, event => { - setTrainPetInformation(null); + setPetTrainInformation(null); }); useMessageEvent(PetTrainingPanelMessageEvent, event => @@ -19,7 +19,7 @@ export const PetTrainingPanelWidgetView: FC<{}> = props => if (!parser) return; - setTrainPetInformation(parser); + setPetTrainInformation(parser); }); const processPetAction = (petId: number, type: string) => @@ -33,20 +33,20 @@ export const PetTrainingPanelWidgetView: FC<{}> = props => return ( - setTrainPetInformation(null) } /> + setPetTrainInformation(null) } /> - { (avatarInfo as AvatarInfoPet)?.name } + { (avatarInfo as AvatarInfoPet)?.name } { (petTrainInformation.commands && petTrainInformation.commands.length > 0) && petTrainInformation.commands.map((command, index) => - + ) } diff --git a/src/hooks/rooms/widgets/useAvatarInfoWidget.ts b/src/hooks/rooms/widgets/useAvatarInfoWidget.ts index aacf50e5..afe46658 100644 --- a/src/hooks/rooms/widgets/useAvatarInfoWidget.ts +++ b/src/hooks/rooms/widgets/useAvatarInfoWidget.ts @@ -14,7 +14,7 @@ const useAvatarInfoWidgetState = () => const [ nameBubbles, setNameBubbles ] = useState([]); const [ productBubbles, setProductBubbles ] = useState([]); const [ confirmingProduct, setConfirmingProduct ] = useState(null); - const [ petTrainInformation, setTrainPetInformation ] = useState(null); + const [ petTrainInformation, setPetTrainInformation ] = useState(null); const [ pendingPetId, setPendingPetId ] = useState(-1); const [ isDecorating, setIsDecorating ] = useState(false); const { friends = [] } = useFriends(); @@ -66,7 +66,7 @@ const useAvatarInfoWidgetState = () => const getObjectInfo = (objectId: number, category: number) => { let info: IAvatarInfo = null; - setTrainPetInformation(null); + setPetTrainInformation(null); switch(category) { @@ -274,7 +274,7 @@ const useAvatarInfoWidgetState = () => useObjectDeselectedEvent(event => { setAvatarInfo(null); - setTrainPetInformation(null); + setPetTrainInformation(null); setProductBubbles([]); }); @@ -352,7 +352,7 @@ const useAvatarInfoWidgetState = () => roomSession.isDecorating = isDecorating; }, [ roomSession, isDecorating ]); - return { avatarInfo, setAvatarInfo, activeNameBubble, setActiveNameBubble, nameBubbles, productBubbles, confirmingProduct, petTrainInformation, setTrainPetInformation, isDecorating, setIsDecorating, removeNameBubble, removeProductBubble, updateConfirmingProduct, getObjectName }; + return { avatarInfo, setAvatarInfo, activeNameBubble, setActiveNameBubble, nameBubbles, productBubbles, confirmingProduct, petTrainInformation, setPetTrainInformation, isDecorating, setIsDecorating, removeNameBubble, removeProductBubble, updateConfirmingProduct, getObjectName }; } export const useAvatarInfoWidget = useAvatarInfoWidgetState; From 88823300af59a962db578e478b4dd2af00df5566 Mon Sep 17 00:00:00 2001 From: oobjectt Date: Tue, 20 Dec 2022 23:55:05 +0100 Subject: [PATCH 3/3] Added action for pet commands --- .../pet-training/PetTrainingPanelWidgetView.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx b/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx index 170f2332..22d95cc0 100644 --- a/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx +++ b/src/components/room/widgets/pet-training/PetTrainingPanelWidgetView.tsx @@ -2,11 +2,13 @@ import { DesktopViewEvent, PetTrainingPanelMessageEvent } from '@nitrots/nitro-r import { FC } from 'react'; import { AvatarInfoPet, LocalizeText } from '../../../../api'; import { Button, Column, Flex, Grid, LayoutPetImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; -import { useAvatarInfoWidget, useMessageEvent } from '../../../../hooks'; +import { useAvatarInfoWidget, useMessageEvent, useRoom, useSessionInfo } from '../../../../hooks'; export const PetTrainingPanelWidgetView: FC<{}> = props => { const { avatarInfo = null, petTrainInformation = null, setPetTrainInformation = null } = useAvatarInfoWidget(); + const { chatStyleId = 0 } = useSessionInfo(); + const { roomSession = null } = useRoom(); useMessageEvent(DesktopViewEvent, event => { @@ -22,11 +24,11 @@ export const PetTrainingPanelWidgetView: FC<{}> = props => setPetTrainInformation(parser); }); - const processPetAction = (petId: number, type: string) => + const processPetAction = (petName: string, commandName: string) => { - if (!petId || !type) return; + if (!petName || !commandName) return; - // packet for pet actions + roomSession?.sendChatMessage(`${ petName } ${ commandName }`, chatStyleId); } if(!petTrainInformation) return null; @@ -46,7 +48,7 @@ export const PetTrainingPanelWidgetView: FC<{}> = props => { (petTrainInformation.commands && petTrainInformation.commands.length > 0) && petTrainInformation.commands.map((command, index) => - + ) }