mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-19 05:46:27 +01:00
Fix badges / infostand refreshing
This commit is contained in:
parent
b57d192a82
commit
567d3fdb66
@ -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
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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<IInventoryBadgeState, IInventoryBadg
|
||||
|
||||
const composer = new SetActivatedBadgesComposer();
|
||||
|
||||
for(const badgeCode of activeBadges)
|
||||
{
|
||||
composer.addActivatedBadge(badgeCode);
|
||||
}
|
||||
for(let i = 0; i < GetConfiguration<number>('user.badges.max.slots', 5); i++) composer.addActivatedBadge(activeBadges[i] || null);
|
||||
|
||||
SendMessageComposer(composer);
|
||||
|
||||
@ -119,10 +116,7 @@ export const InventoryBadgeReducer: Reducer<IInventoryBadgeState, IInventoryBadg
|
||||
|
||||
const composer = new SetActivatedBadgesComposer();
|
||||
|
||||
for(const badgeCode of activeBadges)
|
||||
{
|
||||
composer.addActivatedBadge(badgeCode);
|
||||
}
|
||||
for(let i = 0; i < GetConfiguration<number>('user.badges.max.slots', 5); i++) composer.addActivatedBadge(activeBadges[i] || null);
|
||||
|
||||
SendMessageComposer(composer);
|
||||
|
||||
|
@ -72,7 +72,7 @@ export const InventoryBadgeView: FC<InventoryBadgeViewProps> = props =>
|
||||
return (
|
||||
<Grid>
|
||||
<Column size={ 7 } overflow="hidden">
|
||||
<AutoGrid columnCount={ 5 }>
|
||||
<AutoGrid columnCount={ 4 }>
|
||||
{ badges && (badges.length > 0) && badges.map((code, index) =>
|
||||
{
|
||||
if(activeBadges.indexOf(code) >= 0) return null;
|
||||
|
@ -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);
|
||||
|
@ -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<SetStateAction<RoomWidgetUpdateInfostandUserEvent>>;
|
||||
close: () => void;
|
||||
}
|
||||
|
||||
export const InfoStandWidgetUserView: FC<InfoStandWidgetUserViewProps> = props =>
|
||||
{
|
||||
const { userData = null, close = null } = props;
|
||||
const { eventDispatcher = null, widgetHandler = null } = useRoomContext();
|
||||
const [ badges, setBadges ] = useState<string[]>([]);
|
||||
const [ motto, setMotto ] = useState(null);
|
||||
const { userData = null, setUserData = null, close = null } = props;
|
||||
const [ motto, setMotto ] = useState<string>(null);
|
||||
const [ isEditingMotto, setIsEditingMotto ] = useState(false);
|
||||
const [ userRelationships, setUserRelationships ] = useState<RelationshipStatusInfoMessageParser>(null);
|
||||
|
||||
const [ relationships, setRelationships ] = useState<RelationshipStatusInfoMessageParser>(null);
|
||||
const { eventDispatcher = null, widgetHandler = null } = useRoomContext();
|
||||
const maxBadgeCount = GetConfiguration<number>('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<InfoStandWidgetUserViewProps> = 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<InfoStandWidgetUserViewProps> = props =
|
||||
{
|
||||
BatchUpdates(() =>
|
||||
{
|
||||
setBadges(userData.badges);
|
||||
setIsEditingMotto(false);
|
||||
setMotto(userData.motto);
|
||||
});
|
||||
@ -80,8 +123,12 @@ export const InfoStandWidgetUserView: FC<InfoStandWidgetUserViewProps> = props =
|
||||
|
||||
return () =>
|
||||
{
|
||||
setBadges([]);
|
||||
setUserRelationships(null);
|
||||
BatchUpdates(() =>
|
||||
{
|
||||
setIsEditingMotto(false);
|
||||
setMotto(null);
|
||||
setRelationships(null);
|
||||
});
|
||||
}
|
||||
}, [ userData ]);
|
||||
|
||||
@ -108,7 +155,7 @@ export const InfoStandWidgetUserView: FC<InfoStandWidgetUserViewProps> = props =
|
||||
<Column grow gap={ 0 }>
|
||||
<Flex gap={ 1 }>
|
||||
<Base className="badge-image">
|
||||
{ badges[0] && <LayoutBadgeImageView badgeCode={ badges[0] } showInfo={ true } /> }
|
||||
{ userData.badges[0] && <LayoutBadgeImageView badgeCode={ userData.badges[0] } showInfo={ true } /> }
|
||||
</Base>
|
||||
<Base pointer={ ( userData.groupId > 0) } className="badge-image" onClick={ event => GetGroupInformation(userData.groupId) }>
|
||||
{ userData.groupId > 0 &&
|
||||
@ -117,18 +164,18 @@ export const InfoStandWidgetUserView: FC<InfoStandWidgetUserViewProps> = props =
|
||||
</Flex>
|
||||
<Flex gap={ 1 }>
|
||||
<Base className="badge-image">
|
||||
{ badges[1] && <LayoutBadgeImageView badgeCode={ badges[1] } showInfo={ true } /> }
|
||||
{ userData.badges[1] && <LayoutBadgeImageView badgeCode={ userData.badges[1] } showInfo={ true } /> }
|
||||
</Base>
|
||||
<Base className="badge-image">
|
||||
{ badges[2] && <LayoutBadgeImageView badgeCode={ badges[2] } showInfo={ true } /> }
|
||||
{ userData.badges[2] && <LayoutBadgeImageView badgeCode={ userData.badges[2] } showInfo={ true } /> }
|
||||
</Base>
|
||||
</Flex>
|
||||
<Flex gap={ 1 }>
|
||||
<Base className="badge-image">
|
||||
{ badges[3] && <LayoutBadgeImageView badgeCode={ badges[3] } showInfo={ true } /> }
|
||||
{ userData.badges[3] && <LayoutBadgeImageView badgeCode={ userData.badges[3] } showInfo={ true } /> }
|
||||
</Base>
|
||||
<Base className="badge-image">
|
||||
{ badges[4] && <LayoutBadgeImageView badgeCode={ badges[4] } showInfo={ true } /> }
|
||||
{ userData.badges[4] && <LayoutBadgeImageView badgeCode={ userData.badges[4] } showInfo={ true } /> }
|
||||
</Base>
|
||||
</Flex>
|
||||
</Column>
|
||||
@ -167,7 +214,7 @@ export const InfoStandWidgetUserView: FC<InfoStandWidgetUserViewProps> = props =
|
||||
</> }
|
||||
</Column>
|
||||
<Column gap={ 1 }>
|
||||
<InfoStandWidgetUserRelationshipsView relationships={ userRelationships } />
|
||||
<InfoStandWidgetUserRelationshipsView relationships={ relationships } />
|
||||
</Column>
|
||||
</Column>
|
||||
</Column>
|
||||
|
@ -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 <InfoStandWidgetFurniView furniData={ (infoStandEvent as RoomWidgetUpdateInfostandFurniEvent) } close={ closeInfostand } />;
|
||||
case RoomWidgetUpdateInfostandUserEvent.OWN_USER:
|
||||
case RoomWidgetUpdateInfostandUserEvent.PEER:
|
||||
return <InfoStandWidgetUserView userData={ (infoStandEvent as RoomWidgetUpdateInfostandUserEvent) } close={ closeInfostand } />;
|
||||
return <InfoStandWidgetUserView userData={ (infoStandEvent as RoomWidgetUpdateInfostandUserEvent) } setUserData={ setInfoStandEvent} close={ closeInfostand } />;
|
||||
case RoomWidgetUpdateInfostandUserEvent.BOT:
|
||||
return <InfoStandWidgetBotView botData={ (infoStandEvent as RoomWidgetUpdateInfostandUserEvent) } close={ closeInfostand } />;
|
||||
case RoomWidgetUpdateInfostandRentableBotEvent.RENTABLE_BOT:
|
||||
|
Loading…
Reference in New Issue
Block a user