From 567d3fdb663542bc77316d208500b1bd1c89413a Mon Sep 17 00:00:00 2001 From: Bill Date: Mon, 21 Mar 2022 02:10:36 -0400 Subject: [PATCH] Fix badges / infostand refreshing --- .../handlers/RoomWidgetInfostandHandler.ts | 49 ++-------- .../reducers/InventoryBadgeReducer.tsx | 12 +-- .../views/badge/InventoryBadgeView.tsx | 2 +- .../room/widgets/RoomWidgetsView.tsx | 3 +- .../infostand/InfoStandWidgetUserView.tsx | 93 ++++++++++++++----- .../widgets/infostand/InfoStandWidgetView.tsx | 3 +- 6 files changed, 86 insertions(+), 76 deletions(-) diff --git a/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts b/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts index 5641e6e7..ed22e5f6 100644 --- a/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts +++ b/src/api/nitro/room/widgets/handlers/RoomWidgetInfostandHandler.ts @@ -1,4 +1,4 @@ -import { IFurnitureData, NitroEvent, ObjectDataFactory, PetFigureData, PetRespectComposer, PetSupplementComposer, PetType, RoomControllerLevel, RoomModerationSettings, RoomObjectCategory, RoomObjectOperationType, RoomObjectType, RoomObjectVariable, RoomSessionPetInfoUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent, RoomTradingLevelEnum, RoomUnitDropHandItemComposer, RoomUnitGiveHandItemComposer, RoomUnitGiveHandItemPetComposer, RoomUserData, RoomWidgetEnum, RoomWidgetEnumItemExtradataParameter, Vector3d } from '@nitrots/nitro-renderer'; +import { IFurnitureData, NitroEvent, ObjectDataFactory, PetFigureData, PetRespectComposer, PetSupplementComposer, PetType, RoomControllerLevel, RoomModerationSettings, RoomObjectCategory, RoomObjectOperationType, RoomObjectType, RoomObjectVariable, RoomSessionFavoriteGroupUpdateEvent, RoomSessionPetInfoUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent, RoomTradingLevelEnum, RoomUnitDropHandItemComposer, RoomUnitGiveHandItemComposer, RoomUnitGiveHandItemPetComposer, RoomUserData, RoomWidgetEnum, RoomWidgetEnumItemExtradataParameter, Vector3d } from '@nitrots/nitro-renderer'; import { SendMessageComposer } from '../../..'; import { GetNitroInstance, GetRoomEngine, GetSessionDataManager, IsOwnerOfFurniture } from '../../../..'; import { FriendsHelper } from '../../../../../components/friends/common/FriendsHelper'; @@ -23,7 +23,10 @@ export class RoomWidgetInfostandHandler extends RoomWidgetHandler this.container.eventDispatcher.dispatchEvent(event); return; case RoomSessionUserFigureUpdateEvent.USER_FIGURE: - this.processRoomSessionUserFigureUpdateEvent((event as RoomSessionUserFigureUpdateEvent)); + this.container.eventDispatcher.dispatchEvent(event); + return; + case RoomSessionFavoriteGroupUpdateEvent.FAVOURITE_GROUP_UPDATE: + this.container.eventDispatcher.dispatchEvent(event); return; } } @@ -528,7 +531,7 @@ export class RoomWidgetInfostandHandler extends RoomWidgetHandler // this._Str_16287(_local_12, _local_13); } - event.groupId = parseInt(userData.guildId); + event.groupId = userData.groupId; event.groupBadgeId = GetSessionDataManager().getGroupBadge(event.groupId); event.groupName = userData.groupName; event.badges = this.container.roomSession.userDataManager.getUserBadges(userData.webID); @@ -662,17 +665,6 @@ export class RoomWidgetInfostandHandler extends RoomWidgetHandler this.container.eventDispatcher.dispatchEvent(infostandEvent); } - private processRoomSessionUserFigureUpdateEvent(event: RoomSessionUserFigureUpdateEvent): void - { - const userData = this.container.roomSession.userDataManager.getUserDataByIndex(event.userId); - - if(!userData) return; - - // update active infostand figure - // update motto - // update activity points - } - private checkGuildSetting(event: RoomWidgetUpdateInfostandUserEvent): boolean { if(event.isGuildRoom) return (event.roomControllerLevel >= RoomControllerLevel.GUILD_ADMIN); @@ -743,32 +735,6 @@ export class RoomWidgetInfostandHandler extends RoomWidgetHandler return (flag && (event.roomControllerLevel < RoomControllerLevel.ROOM_OWNER)); } - private getPetType(figure: string): number - { - return this.getPetFigurePart(figure, 0); - } - - private getPetBreed(figure: string): number - { - return this.getPetFigurePart(figure, 1); - } - - private getPetColor(figure: string): number - { - return this.getPetFigurePart(figure, 2); - } - - private getPetFigurePart(figure: string, index: number): number - { - if(!figure || !figure.length) return -1; - - const parts = figure.split(' '); - - if(parts.length > 0) return parseInt(parts[index]); - - return -1; - } - public get type(): string { return RoomWidgetEnum.INFOSTAND; @@ -779,7 +745,8 @@ export class RoomWidgetInfostandHandler extends RoomWidgetHandler return [ RoomSessionPetInfoUpdateEvent.PET_INFO, RoomSessionUserBadgesEvent.RSUBE_BADGES, - RoomSessionUserFigureUpdateEvent.USER_FIGURE + RoomSessionUserFigureUpdateEvent.USER_FIGURE, + RoomSessionFavoriteGroupUpdateEvent.FAVOURITE_GROUP_UPDATE ]; } diff --git a/src/components/inventory/reducers/InventoryBadgeReducer.tsx b/src/components/inventory/reducers/InventoryBadgeReducer.tsx index b8de1d72..9589baeb 100644 --- a/src/components/inventory/reducers/InventoryBadgeReducer.tsx +++ b/src/components/inventory/reducers/InventoryBadgeReducer.tsx @@ -1,6 +1,6 @@ import { SetActivatedBadgesComposer } from '@nitrots/nitro-renderer'; import { Reducer } from 'react'; -import { SendMessageComposer } from '../../../api'; +import { GetConfiguration, SendMessageComposer } from '../../../api'; export interface IInventoryBadgeState { @@ -97,10 +97,7 @@ export const InventoryBadgeReducer: Reducer('user.badges.max.slots', 5); i++) composer.addActivatedBadge(activeBadges[i] || null); SendMessageComposer(composer); @@ -119,10 +116,7 @@ export const InventoryBadgeReducer: Reducer('user.badges.max.slots', 5); i++) composer.addActivatedBadge(activeBadges[i] || null); SendMessageComposer(composer); diff --git a/src/components/inventory/views/badge/InventoryBadgeView.tsx b/src/components/inventory/views/badge/InventoryBadgeView.tsx index 8bf4f873..8471d39d 100644 --- a/src/components/inventory/views/badge/InventoryBadgeView.tsx +++ b/src/components/inventory/views/badge/InventoryBadgeView.tsx @@ -72,7 +72,7 @@ export const InventoryBadgeView: FC = props => return ( - + { badges && (badges.length > 0) && badges.map((code, index) => { if(activeBadges.indexOf(code) >= 0) return null; diff --git a/src/components/room/widgets/RoomWidgetsView.tsx b/src/components/room/widgets/RoomWidgetsView.tsx index c8bea4a2..55bdeaad 100644 --- a/src/components/room/widgets/RoomWidgetsView.tsx +++ b/src/components/room/widgets/RoomWidgetsView.tsx @@ -1,4 +1,4 @@ -import { RoomEngineEvent, RoomEngineObjectEvent, RoomEngineRoomAdEvent, RoomEngineTriggerWidgetEvent, RoomEngineUseProductEvent, RoomId, RoomObjectCategory, RoomObjectOperationType, RoomObjectVariable, RoomSessionChatEvent, RoomSessionDanceEvent, RoomSessionDimmerPresetsEvent, RoomSessionDoorbellEvent, RoomSessionErrorMessageEvent, RoomSessionEvent, RoomSessionFriendRequestEvent, RoomSessionPetInfoUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionPollEvent, RoomSessionPresentEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent, RoomSessionWordQuizEvent, RoomZoomEvent } from '@nitrots/nitro-renderer'; +import { RoomEngineEvent, RoomEngineObjectEvent, RoomEngineRoomAdEvent, RoomEngineTriggerWidgetEvent, RoomEngineUseProductEvent, RoomId, RoomObjectCategory, RoomObjectOperationType, RoomObjectVariable, RoomSessionChatEvent, RoomSessionDanceEvent, RoomSessionDimmerPresetsEvent, RoomSessionDoorbellEvent, RoomSessionErrorMessageEvent, RoomSessionEvent, RoomSessionFavoriteGroupUpdateEvent, RoomSessionFriendRequestEvent, RoomSessionPetInfoUpdateEvent, RoomSessionPetStatusUpdateEvent, RoomSessionPollEvent, RoomSessionPresentEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent, RoomSessionWordQuizEvent, RoomZoomEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback } from 'react'; import { CanManipulateFurniture, GetRoomEngine, GetSessionDataManager, IsFurnitureSelectionDisabled, LocalizeText, NotificationAlertType, NotificationUtilities, ProcessRoomObjectOperation, RoomWidgetFurniToWidgetMessage, RoomWidgetUpdateRoomEngineEvent, RoomWidgetUpdateRoomObjectEvent } from '../../../api'; import { FriendRequestEvent } from '../../../events'; @@ -263,6 +263,7 @@ export const RoomWidgetsView: FC<{}> = props => UseRoomSessionManagerEvent(RoomSessionDanceEvent.RSDE_DANCE, onRoomSessionEvent); UseRoomSessionManagerEvent(RoomSessionUserBadgesEvent.RSUBE_BADGES, onRoomSessionEvent); UseRoomSessionManagerEvent(RoomSessionUserFigureUpdateEvent.USER_FIGURE, onRoomSessionEvent); + UseRoomSessionManagerEvent(RoomSessionFavoriteGroupUpdateEvent.FAVOURITE_GROUP_UPDATE, onRoomSessionEvent); UseRoomSessionManagerEvent(RoomSessionPetStatusUpdateEvent.PET_STATUS_UPDATE, onRoomSessionEvent); UseRoomSessionManagerEvent(RoomSessionDoorbellEvent.DOORBELL, onRoomSessionEvent); UseRoomSessionManagerEvent(RoomSessionDoorbellEvent.RSDE_REJECTED, onRoomSessionEvent); diff --git a/src/components/room/widgets/infostand/InfoStandWidgetUserView.tsx b/src/components/room/widgets/infostand/InfoStandWidgetUserView.tsx index a39d2f5b..60b97b31 100644 --- a/src/components/room/widgets/infostand/InfoStandWidgetUserView.tsx +++ b/src/components/room/widgets/infostand/InfoStandWidgetUserView.tsx @@ -1,7 +1,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { RelationshipStatusInfoEvent, RelationshipStatusInfoMessageParser, RoomSessionUserBadgesEvent, UserRelationshipsComposer } from '@nitrots/nitro-renderer'; -import { FC, FocusEvent, KeyboardEvent, useCallback, useEffect, useState } from 'react'; -import { GetConfiguration, GetGroupInformation, LocalizeText, RoomWidgetChangeMottoMessage, RoomWidgetUpdateInfostandUserEvent, SendMessageComposer } from '../../../../api'; +import { RelationshipStatusInfoEvent, RelationshipStatusInfoMessageParser, RoomSessionFavoriteGroupUpdateEvent, RoomSessionUserBadgesEvent, RoomSessionUserFigureUpdateEvent, UserRelationshipsComposer } from '@nitrots/nitro-renderer'; +import { Dispatch, FC, FocusEvent, KeyboardEvent, SetStateAction, useCallback, useEffect, useState } from 'react'; +import { CloneObject, GetConfiguration, GetGroupInformation, GetSessionDataManager, LocalizeText, RoomWidgetChangeMottoMessage, RoomWidgetUpdateInfostandUserEvent, SendMessageComposer } from '../../../../api'; import { Base, Column, Flex, LayoutAvatarImageView, LayoutBadgeImageView, Text, UserProfileIconView } from '../../../../common'; import { BatchUpdates, UseEventDispatcherHook, UseMessageEventHook } from '../../../../hooks'; import { useRoomContext } from '../../RoomContext'; @@ -10,23 +10,22 @@ import { InfoStandWidgetUserRelationshipsView } from './InfoStandWidgetUserRelat interface InfoStandWidgetUserViewProps { userData: RoomWidgetUpdateInfostandUserEvent; + setUserData: Dispatch>; close: () => void; } export const InfoStandWidgetUserView: FC = props => { - const { userData = null, close = null } = props; - const { eventDispatcher = null, widgetHandler = null } = useRoomContext(); - const [ badges, setBadges ] = useState([]); - const [ motto, setMotto ] = useState(null); + const { userData = null, setUserData = null, close = null } = props; + const [ motto, setMotto ] = useState(null); const [ isEditingMotto, setIsEditingMotto ] = useState(false); - const [ userRelationships, setUserRelationships ] = useState(null); - + const [ relationships, setRelationships ] = useState(null); + const { eventDispatcher = null, widgetHandler = null } = useRoomContext(); const maxBadgeCount = GetConfiguration('user.badges.max.slots', 5); const saveMotto = (motto: string) => { - if(motto.length > 38) return; + if(!isEditingMotto || (motto.length > 38)) return; widgetHandler.processWidgetMessage(new RoomWidgetChangeMottoMessage(motto)); @@ -51,18 +50,63 @@ export const InfoStandWidgetUserView: FC = props = { if(!userData || (userData.webID !== event.userId)) return; - setBadges(event.badges); - }, [ userData ]); + setUserData(prevValue => + { + const newValue = CloneObject(prevValue); + + newValue.badges = event.badges; + + return newValue; + }); + }, [ userData, setUserData ]); UseEventDispatcherHook(RoomSessionUserBadgesEvent.RSUBE_BADGES, eventDispatcher, onRoomSessionUserBadgesEvent); + const onRoomSessionUserFigureUpdateEvent = useCallback((event: RoomSessionUserFigureUpdateEvent) => + { + if(!userData || (userData.roomIndex !== event.roomIndex)) return; + + setUserData(prevValue => + { + const newValue = CloneObject(prevValue); + + newValue.figure = event.figure; + newValue.motto = event.customInfo; + newValue.achievementScore = event.activityPoints; + + return newValue; + }); + }, [ userData, setUserData ]); + + UseEventDispatcherHook(RoomSessionUserFigureUpdateEvent.USER_FIGURE, eventDispatcher, onRoomSessionUserFigureUpdateEvent); + + const onRoomSessionFavoriteGroupUpdateEvent = useCallback((event: RoomSessionFavoriteGroupUpdateEvent) => + { + if(!userData || (userData.roomIndex !== event.roomIndex)) return; + + setUserData(prevValue => + { + const newValue = CloneObject(prevValue); + + const clearGroup = ((event.status === -1) || (event.habboGroupId <= 0)); + + newValue.groupId = clearGroup ? -1 : event.habboGroupId; + newValue.groupName = clearGroup ? null : event.habboGroupName + newValue.groupBadgeId = clearGroup ? null : GetSessionDataManager().getGroupBadge(event.habboGroupId); + + return newValue; + }); + }, [ userData, setUserData ]); + + UseEventDispatcherHook(RoomSessionFavoriteGroupUpdateEvent.FAVOURITE_GROUP_UPDATE, eventDispatcher, onRoomSessionFavoriteGroupUpdateEvent); + const onUserRelationshipsEvent = useCallback((event: RelationshipStatusInfoEvent) => { const parser = event.getParser(); if(!userData || (userData.webID !== parser.userId)) return; - - setUserRelationships(parser); + + setRelationships(parser); }, [ userData ]); UseMessageEventHook(RelationshipStatusInfoEvent, onUserRelationshipsEvent); @@ -71,7 +115,6 @@ export const InfoStandWidgetUserView: FC = props = { BatchUpdates(() => { - setBadges(userData.badges); setIsEditingMotto(false); setMotto(userData.motto); }); @@ -80,8 +123,12 @@ export const InfoStandWidgetUserView: FC = props = return () => { - setBadges([]); - setUserRelationships(null); + BatchUpdates(() => + { + setIsEditingMotto(false); + setMotto(null); + setRelationships(null); + }); } }, [ userData ]); @@ -108,7 +155,7 @@ export const InfoStandWidgetUserView: FC = props = - { badges[0] && } + { userData.badges[0] && } 0) } className="badge-image" onClick={ event => GetGroupInformation(userData.groupId) }> { userData.groupId > 0 && @@ -117,18 +164,18 @@ export const InfoStandWidgetUserView: FC = props = - { badges[1] && } + { userData.badges[1] && } - { badges[2] && } + { userData.badges[2] && } - { badges[3] && } + { userData.badges[3] && } - { badges[4] && } + { userData.badges[4] && } @@ -167,7 +214,7 @@ export const InfoStandWidgetUserView: FC = props = } - + diff --git a/src/components/room/widgets/infostand/InfoStandWidgetView.tsx b/src/components/room/widgets/infostand/InfoStandWidgetView.tsx index fae40a4e..b8122eb8 100644 --- a/src/components/room/widgets/infostand/InfoStandWidgetView.tsx +++ b/src/components/room/widgets/infostand/InfoStandWidgetView.tsx @@ -91,6 +91,7 @@ export const InfoStandWidgetView: FC<{}> = props => UseEventDispatcherHook(RoomWidgetUpdateInfostandUserEvent.BOT, eventDispatcher, onRoomWidgetUpdateEvent); UseEventDispatcherHook(RoomWidgetUpdateInfostandRentableBotEvent.RENTABLE_BOT, eventDispatcher, onRoomWidgetUpdateEvent); UseEventDispatcherHook(RoomWidgetUpdateInfostandPetEvent.PET_INFO, eventDispatcher, onRoomWidgetUpdateEvent); + UseEventDispatcherHook(RoomWidgetUpdateInfostandPetEvent.PET_INFO, eventDispatcher, onRoomWidgetUpdateEvent); const getInfostandView = useCallback(() => { @@ -102,7 +103,7 @@ export const InfoStandWidgetView: FC<{}> = props => return ; case RoomWidgetUpdateInfostandUserEvent.OWN_USER: case RoomWidgetUpdateInfostandUserEvent.PEER: - return ; + return ; case RoomWidgetUpdateInfostandUserEvent.BOT: return ; case RoomWidgetUpdateInfostandRentableBotEvent.RENTABLE_BOT: