diff --git a/src/components/avatar-editor/AvatarEditorView.tsx b/src/components/avatar-editor/AvatarEditorView.tsx index 44fc15c6..10ba06f5 100644 --- a/src/components/avatar-editor/AvatarEditorView.tsx +++ b/src/components/avatar-editor/AvatarEditorView.tsx @@ -1,15 +1,13 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { AvatarEditorFigureCategory, FigureSetIdsMessageEvent, GetWardrobeMessageComposer, IAvatarFigureContainer, UserFigureComposer, UserWardrobePageEvent } from '@nitrots/nitro-renderer'; +import { AvatarEditorFigureCategory, FigureSetIdsMessageEvent, GetWardrobeMessageComposer, IAvatarFigureContainer, ILinkEventTracker, UserFigureComposer, UserWardrobePageEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useMemo, useState } from 'react'; -import { GetAvatarRenderManager, GetClubMemberLevel, GetConfiguration, GetSessionDataManager, LocalizeText } from '../../api'; +import { AddEventLinkTracker, GetAvatarRenderManager, GetClubMemberLevel, GetConfiguration, GetSessionDataManager, LocalizeText, RemoveLinkEventTracker } from '../../api'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; import { Button } from '../../common/Button'; import { ButtonGroup } from '../../common/ButtonGroup'; import { Column } from '../../common/Column'; import { Grid } from '../../common/Grid'; -import { AvatarEditorEvent } from '../../events/avatar-editor'; import { CreateMessageHook, SendMessageHook } from '../../hooks'; -import { useUiEvent } from '../../hooks/events/ui/ui-event'; import { AvatarEditorAction } from './common/AvatarEditorAction'; import { AvatarEditorUtilities } from './common/AvatarEditorUtilities'; import { BodyModel } from './common/BodyModel'; @@ -44,34 +42,6 @@ export const AvatarEditorView: FC<{}> = props => const maxWardrobeSlots = useMemo(() => GetConfiguration('avatar.wardrobe.max.slots', 10), []); - const onAvatarEditorEvent = useCallback((event: AvatarEditorEvent) => - { - switch(event.type) - { - case AvatarEditorEvent.SHOW_EDITOR: - setIsVisible(true); - setNeedsReset(true); - return; - case AvatarEditorEvent.HIDE_EDITOR: - setIsVisible(false); - return; - case AvatarEditorEvent.TOGGLE_EDITOR: - setIsVisible(prevValue => - { - const flag = !prevValue; - - if(flag) setNeedsReset(true); - - return flag; - }); - return; - } - }, []); - - useUiEvent(AvatarEditorEvent.SHOW_EDITOR, onAvatarEditorEvent); - useUiEvent(AvatarEditorEvent.HIDE_EDITOR, onAvatarEditorEvent); - useUiEvent(AvatarEditorEvent.TOGGLE_EDITOR, onAvatarEditorEvent); - const onFigureSetIdsMessageEvent = useCallback((event: FigureSetIdsMessageEvent) => { const parser = event.getParser(); @@ -195,6 +165,45 @@ export const AvatarEditorView: FC<{}> = props => setFigureData(figures.get(gender)); }, [ figures ]); + const linkReceived = useCallback((url: string) => + { + const parts = url.split('/'); + + if(parts.length < 2) return; + + switch(parts[1]) + { + case 'show': + setIsVisible(true); + return; + case 'hide': + setIsVisible(false); + return; + case 'toggle': + setIsVisible(prevValue => + { + const flag = !prevValue; + + if(flag) setNeedsReset(true); + + return flag; + }); + return; + } + }, []); + + useEffect(() => + { + const linkTracker: ILinkEventTracker = { + linkReceived, + eventUrlPrefix: 'avatar-editor/' + }; + + AddEventLinkTracker(linkTracker); + + return () => RemoveLinkEventTracker(linkTracker); + }, [ linkReceived ]); + useEffect(() => { setSavedFigures(new Array(maxWardrobeSlots)); diff --git a/src/components/camera/CameraWidgetView.tsx b/src/components/camera/CameraWidgetView.tsx index dc2115e3..4fb09627 100644 --- a/src/components/camera/CameraWidgetView.tsx +++ b/src/components/camera/CameraWidgetView.tsx @@ -1,10 +1,8 @@ -import { InitCameraMessageEvent, IRoomCameraWidgetEffect, RequestCameraConfigurationComposer, RoomCameraWidgetManagerEvent, RoomSessionEvent } from '@nitrots/nitro-renderer'; +import { ILinkEventTracker, InitCameraMessageEvent, IRoomCameraWidgetEffect, RequestCameraConfigurationComposer, RoomCameraWidgetManagerEvent, RoomSessionEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { GetRoomCameraWidgetManager } from '../../api'; -import { RoomWidgetCameraEvent } from '../../events/camera/RoomWidgetCameraEvent'; +import { AddEventLinkTracker, GetRoomCameraWidgetManager, RemoveLinkEventTracker } from '../../api'; import { useRoomSessionManagerEvent } from '../../hooks'; import { useCameraEvent } from '../../hooks/events/nitro/camera/camera-event'; -import { useUiEvent } from '../../hooks/events/ui/ui-event'; import { CreateMessageHook, SendMessageHook } from '../../hooks/messages/message-event'; import { CameraWidgetContextProvider } from './CameraWidgetContext'; import { CameraPicture } from './common/CameraPicture'; @@ -27,30 +25,6 @@ export const CameraWidgetView: FC<{}> = props => const [ base64Url, setSavedPictureUrl ] = useState(null); const [ price, setPrice ] = useState<{ credits: number, duckets: number, publishDucketPrice: number }>(null); - const onNitroEvent = useCallback((event: RoomWidgetCameraEvent) => - { - switch(event.type) - { - case RoomWidgetCameraEvent.SHOW_CAMERA: - setMode(MODE_CAPTURE); - return; - case RoomWidgetCameraEvent.HIDE_CAMERA: - setMode(MODE_NONE); - return; - case RoomWidgetCameraEvent.TOGGLE_CAMERA: - setMode(prevValue => - { - if(!prevValue) return MODE_CAPTURE; - else return MODE_NONE; - }); - return; - } - }, []); - - useUiEvent(RoomWidgetCameraEvent.SHOW_CAMERA, onNitroEvent); - useUiEvent(RoomWidgetCameraEvent.HIDE_CAMERA, onNitroEvent); - useUiEvent(RoomWidgetCameraEvent.TOGGLE_CAMERA, onNitroEvent); - const onRoomCameraWidgetManagerEvent = useCallback((event: RoomCameraWidgetManagerEvent) => { setAvailableEffects(Array.from(GetRoomCameraWidgetManager().effects.values())) @@ -118,6 +92,42 @@ export const CameraWidgetView: FC<{}> = props => setMode(MODE_CHECKOUT); }, []); + const linkReceived = useCallback((url: string) => + { + const parts = url.split('/'); + + if(parts.length < 2) return; + + switch(parts[1]) + { + case 'show': + setMode(MODE_CAPTURE); + return; + case 'hide': + setMode(MODE_NONE); + return; + case 'toggle': + setMode(prevValue => + { + if(!prevValue) return MODE_CAPTURE; + else return MODE_NONE; + }); + return; + } + }, []); + + useEffect(() => + { + const linkTracker: ILinkEventTracker = { + linkReceived, + eventUrlPrefix: 'camera/' + }; + + AddEventLinkTracker(linkTracker); + + return () => RemoveLinkEventTracker(linkTracker); + }, [ linkReceived ]); + if(mode === MODE_NONE) return null; return ( diff --git a/src/components/toolbar/ToolbarView.tsx b/src/components/toolbar/ToolbarView.tsx index 30c6ab7e..5f9200c3 100644 --- a/src/components/toolbar/ToolbarView.tsx +++ b/src/components/toolbar/ToolbarView.tsx @@ -3,7 +3,7 @@ import { FC, useCallback, useState } from 'react'; import { CreateLinkEvent, GetRoomSession, GetRoomSessionManager, GetSessionDataManager, GetUserProfile, GoToDesktop, OpenMessengerChat } from '../../api'; import { Base, Flex, TransitionAnimationTypes } from '../../common'; import { TransitionAnimation } from '../../common/transitions/TransitionAnimation'; -import { AvatarEditorEvent, FriendsEvent, FriendsMessengerIconEvent, FriendsRequestCountEvent, GuideToolEvent, InventoryEvent, NavigatorEvent, RoomWidgetCameraEvent } from '../../events'; +import { FriendsEvent, FriendsMessengerIconEvent, FriendsRequestCountEvent, GuideToolEvent, InventoryEvent, NavigatorEvent } from '../../events'; import { AchievementsUIEvent, AchievementsUIUnseenCountEvent } from '../../events/achievements'; import { UnseenItemTrackerUpdateEvent } from '../../events/inventory/UnseenItemTrackerUpdateEvent'; import { ModToolsEvent } from '../../events/mod-tools/ModToolsEvent'; @@ -155,10 +155,10 @@ export const ToolbarView: FC = props => dispatchUiEvent(new FriendsEvent(FriendsEvent.TOGGLE_FRIEND_LIST)); return; case ToolbarViewItems.CAMERA_ITEM: - dispatchUiEvent(new RoomWidgetCameraEvent(RoomWidgetCameraEvent.TOGGLE_CAMERA)); + CreateLinkEvent('camera/toggle'); return; case ToolbarViewItems.CLOTHING_ITEM: - dispatchUiEvent(new AvatarEditorEvent(AvatarEditorEvent.TOGGLE_EDITOR)); + CreateLinkEvent('avatar-editor/toggle'); setMeExpanded(false); return; case ToolbarViewItems.MOD_TOOLS_ITEM: diff --git a/src/events/avatar-editor/AvatarEditorEvent.ts b/src/events/avatar-editor/AvatarEditorEvent.ts deleted file mode 100644 index fdde2f19..00000000 --- a/src/events/avatar-editor/AvatarEditorEvent.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class AvatarEditorEvent extends NitroEvent -{ - public static SHOW_EDITOR: string = 'AEE_SHOW_EDITOR'; - public static HIDE_EDITOR: string = 'AEE_HIDE_EDITOR'; - public static TOGGLE_EDITOR: string = 'AEE_TOGGLE_EDITOR'; -} diff --git a/src/events/avatar-editor/index.ts b/src/events/avatar-editor/index.ts deleted file mode 100644 index 79313d2b..00000000 --- a/src/events/avatar-editor/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './AvatarEditorEvent'; diff --git a/src/events/camera/RoomWidgetCameraEvent.ts b/src/events/camera/RoomWidgetCameraEvent.ts deleted file mode 100644 index 8423d087..00000000 --- a/src/events/camera/RoomWidgetCameraEvent.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { NitroEvent } from '@nitrots/nitro-renderer'; - -export class RoomWidgetCameraEvent extends NitroEvent -{ - public static SHOW_CAMERA: string = 'NE_SHOW_CAMERA'; - public static HIDE_CAMERA: string = 'NE_HIDE_CAMERA'; - public static TOGGLE_CAMERA: string = 'NE_TOGGLE_CAMERA'; -} diff --git a/src/events/camera/index.ts b/src/events/camera/index.ts deleted file mode 100644 index a04e80d0..00000000 --- a/src/events/camera/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './RoomWidgetCameraEvent'; diff --git a/src/events/index.ts b/src/events/index.ts index f8c3cddd..8a7625ea 100644 --- a/src/events/index.ts +++ b/src/events/index.ts @@ -1,6 +1,4 @@ export * from './achievements'; -export * from './avatar-editor'; -export * from './camera'; export * from './catalog'; export * from './floorplan-editor'; export * from './friends'; diff --git a/src/views/room/widgets/avatar-info/AvatarInfoWidgetOwnAvatarView.tsx b/src/views/room/widgets/avatar-info/AvatarInfoWidgetOwnAvatarView.tsx index 5c40631f..f2422488 100644 --- a/src/views/room/widgets/avatar-info/AvatarInfoWidgetOwnAvatarView.tsx +++ b/src/views/room/widgets/avatar-info/AvatarInfoWidgetOwnAvatarView.tsx @@ -1,9 +1,8 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { AvatarAction, AvatarExpressionEnum, RoomControllerLevel, RoomObjectCategory } from '@nitrots/nitro-renderer'; import { FC, useCallback, useMemo, useState } from 'react'; -import { GetCanStandUp, GetCanUseExpression, GetOwnPosture, GetUserProfile, HasHabboClub, HasHabboVip, IsRidingHorse, LocalizeText, RoomWidgetAvatarExpressionMessage, RoomWidgetChangePostureMessage, RoomWidgetDanceMessage, RoomWidgetMessage, RoomWidgetUpdateDecorateModeEvent, RoomWidgetUpdateInfostandUserEvent, RoomWidgetUserActionMessage } from '../../../../api'; +import { CreateLinkEvent, GetCanStandUp, GetCanUseExpression, GetOwnPosture, GetUserProfile, HasHabboClub, HasHabboVip, IsRidingHorse, LocalizeText, RoomWidgetAvatarExpressionMessage, RoomWidgetChangePostureMessage, RoomWidgetDanceMessage, RoomWidgetMessage, RoomWidgetUpdateDecorateModeEvent, RoomWidgetUpdateInfostandUserEvent, RoomWidgetUserActionMessage } from '../../../../api'; import { Flex } from '../../../../common'; -import { AvatarEditorEvent } from '../../../../events'; import { HelpNameChangeEvent } from '../../../../events/help/HelpNameChangeEvent'; import { dispatchUiEvent } from '../../../../hooks'; import { CurrencyIcon } from '../../../shared/currency-icon/CurrencyIcon'; @@ -55,7 +54,7 @@ export const AvatarInfoWidgetOwnAvatarView: FC