From da1b0c508d41c97dc9c4b717091ec87eb5c38fbd Mon Sep 17 00:00:00 2001 From: Bill Date: Wed, 30 Mar 2022 10:19:09 -0400 Subject: [PATCH] Completely redo inventory state --- src/api/index.ts | 1 + .../common => api/inventory}/FurniCategory.ts | 0 .../common => api/inventory}/FurnitureItem.ts | 4 +- .../common => api/inventory}/GroupItem.ts | 2 +- src/api/inventory/IBadgeItem.ts | 5 + src/api/inventory/IBotItem.ts | 6 + .../inventory}/IFurnitureItem.ts | 0 src/api/inventory/IPetItem.ts | 6 + src/api/inventory/InventoryUtilities.ts | 116 ++++++ .../common => api/inventory}/TradeState.ts | 0 .../common => api/inventory}/TradeUserData.ts | 0 .../inventory}/TradingNotificationMessage.ts | 2 +- .../inventory}/TradingNotificationType.ts | 0 src/api/inventory/index.ts | 13 + .../inventory}/unseen/IUnseenItemTracker.ts | 0 .../inventory}/unseen/UnseenItemCategory.ts | 0 src/api/inventory/unseen/index.ts | 2 + .../handlers/RoomWidgetAvatarInfoHandler.ts | 2 +- .../marketplace/MarketplacePostOfferView.tsx | 3 +- .../CatalogBadgeSelectorWidgetView.tsx | 30 +- src/components/inventory/InventoryContext.tsx | 39 -- .../inventory/InventoryMessageHandler.tsx | 386 ------------------ src/components/inventory/InventoryView.tsx | 235 +++++------ src/components/inventory/common/BadgeItem.ts | 26 -- src/components/inventory/common/BotItem.ts | 45 -- .../inventory/common/BotUtilities.ts | 131 ------ .../inventory/common/FurnitureUtilities.ts | 350 ---------------- .../inventory/common/InventoryUtilities.ts | 22 - src/components/inventory/common/PetItem.ts | 45 -- .../inventory/common/PetUtilities.ts | 150 ------- .../common/unseen/UnseenItemTracker.ts | 146 ------- .../reducers/InventoryBadgeReducer.tsx | 128 ------ .../reducers/InventoryBotReducer.tsx | 88 ---- .../reducers/InventoryFurnitureReducer.tsx | 273 ------------- .../reducers/InventoryPetReducer.tsx | 88 ---- .../inventory/views/InventoryBadgeView.tsx | 75 ++++ .../inventory/views/InventoryBotView.tsx | 116 ++++++ .../InventoryCategoryEmptyView.tsx | 4 +- .../InventoryFurnitureSearchView.tsx | 6 +- .../views/InventoryFurnitureView.tsx | 161 ++++++++ .../inventory/views/InventoryPetView.tsx | 115 ++++++ .../views/{trade => }/InventoryTradeView.tsx | 133 ++---- .../views/badge/InventoryBadgeItemView.tsx | 34 -- .../views/badge/InventoryBadgeView.tsx | 102 ----- .../views/bot/InventoryBotItemView.tsx | 56 --- .../inventory/views/bot/InventoryBotView.tsx | 94 ----- .../furniture/InventoryFurnitureItemView.tsx | 54 --- .../furniture/InventoryFurnitureView.tsx | 139 ------- .../views/pet/InventoryPetItemView.tsx | 56 --- .../inventory/views/pet/InventoryPetView.tsx | 93 ----- src/components/mod-tools/ModToolsView.tsx | 5 +- .../AvatarInfoUseProductConfirmView.tsx | 3 +- .../avatar-info/AvatarInfoUseProductView.tsx | 3 +- .../MonsterPlantSeedConfirmView.tsx | 3 +- .../PurchasableClothingConfirmView.tsx | 3 +- src/components/toolbar/ToolbarView.tsx | 17 +- .../CatalogPostMarketplaceOfferEvent.ts | 2 +- .../inventory/InventoryBadgesRequestEvent.ts | 6 - .../inventory/InventoryBadgesUpdatedEvent.ts | 20 - .../inventory/InventoryTradeStartEvent.ts | 2 +- .../inventory/UnseenItemTrackerUpdateEvent.ts | 20 - src/events/inventory/index.ts | 3 - src/hooks/index.ts | 2 + .../inventory/common/FurnitureUtilities.ts | 182 +++++++++ src/hooks/inventory/common/PetUtilities.ts | 102 +++++ .../inventory/common/TradingUtilities.ts | 38 +- src/hooks/inventory/common/index.ts | 3 + src/hooks/inventory/index.ts | 7 + .../inventory/useSharedInventoryBadges.ts | 148 +++++++ src/hooks/inventory/useSharedInventoryBots.ts | 172 ++++++++ .../inventory/useSharedInventoryFurni.ts | 264 ++++++++++++ src/hooks/inventory/useSharedInventoryPets.ts | 125 ++++++ .../inventory/useSharedInventoryTrade.ts | 293 +++++++++++++ .../useSharedInventoryUnseenTracker.ts | 143 +++++++ src/hooks/useSharedVisibility.ts | 44 ++ 75 files changed, 2277 insertions(+), 2915 deletions(-) rename src/{components/inventory/common => api/inventory}/FurniCategory.ts (100%) rename src/{components/inventory/common => api/inventory}/FurnitureItem.ts (98%) rename src/{components/inventory/common => api/inventory}/GroupItem.ts (99%) create mode 100644 src/api/inventory/IBadgeItem.ts create mode 100644 src/api/inventory/IBotItem.ts rename src/{components/inventory/common => api/inventory}/IFurnitureItem.ts (100%) create mode 100644 src/api/inventory/IPetItem.ts create mode 100644 src/api/inventory/InventoryUtilities.ts rename src/{components/inventory/common => api/inventory}/TradeState.ts (100%) rename src/{components/inventory/common => api/inventory}/TradeUserData.ts (100%) rename src/{components/inventory/common => api/inventory}/TradingNotificationMessage.ts (96%) rename src/{components/inventory/common => api/inventory}/TradingNotificationType.ts (100%) create mode 100644 src/api/inventory/index.ts rename src/{components/inventory/common => api/inventory}/unseen/IUnseenItemTracker.ts (100%) rename src/{components/inventory/common => api/inventory}/unseen/UnseenItemCategory.ts (100%) create mode 100644 src/api/inventory/unseen/index.ts delete mode 100644 src/components/inventory/InventoryContext.tsx delete mode 100644 src/components/inventory/InventoryMessageHandler.tsx delete mode 100644 src/components/inventory/common/BadgeItem.ts delete mode 100644 src/components/inventory/common/BotItem.ts delete mode 100644 src/components/inventory/common/BotUtilities.ts delete mode 100644 src/components/inventory/common/FurnitureUtilities.ts delete mode 100644 src/components/inventory/common/InventoryUtilities.ts delete mode 100644 src/components/inventory/common/PetItem.ts delete mode 100644 src/components/inventory/common/PetUtilities.ts delete mode 100644 src/components/inventory/common/unseen/UnseenItemTracker.ts delete mode 100644 src/components/inventory/reducers/InventoryBadgeReducer.tsx delete mode 100644 src/components/inventory/reducers/InventoryBotReducer.tsx delete mode 100644 src/components/inventory/reducers/InventoryFurnitureReducer.tsx delete mode 100644 src/components/inventory/reducers/InventoryPetReducer.tsx create mode 100644 src/components/inventory/views/InventoryBadgeView.tsx create mode 100644 src/components/inventory/views/InventoryBotView.tsx rename src/components/inventory/views/{category-empty => }/InventoryCategoryEmptyView.tsx (82%) rename src/components/inventory/views/{furniture => }/InventoryFurnitureSearchView.tsx (88%) create mode 100644 src/components/inventory/views/InventoryFurnitureView.tsx create mode 100644 src/components/inventory/views/InventoryPetView.tsx rename src/components/inventory/views/{trade => }/InventoryTradeView.tsx (64%) delete mode 100644 src/components/inventory/views/badge/InventoryBadgeItemView.tsx delete mode 100644 src/components/inventory/views/badge/InventoryBadgeView.tsx delete mode 100644 src/components/inventory/views/bot/InventoryBotItemView.tsx delete mode 100644 src/components/inventory/views/bot/InventoryBotView.tsx delete mode 100644 src/components/inventory/views/furniture/InventoryFurnitureItemView.tsx delete mode 100644 src/components/inventory/views/furniture/InventoryFurnitureView.tsx delete mode 100644 src/components/inventory/views/pet/InventoryPetItemView.tsx delete mode 100644 src/components/inventory/views/pet/InventoryPetView.tsx delete mode 100644 src/events/inventory/InventoryBadgesRequestEvent.ts delete mode 100644 src/events/inventory/InventoryBadgesUpdatedEvent.ts delete mode 100644 src/events/inventory/UnseenItemTrackerUpdateEvent.ts create mode 100644 src/hooks/inventory/common/FurnitureUtilities.ts create mode 100644 src/hooks/inventory/common/PetUtilities.ts rename src/{components => hooks}/inventory/common/TradingUtilities.ts (53%) create mode 100644 src/hooks/inventory/common/index.ts create mode 100644 src/hooks/inventory/index.ts create mode 100644 src/hooks/inventory/useSharedInventoryBadges.ts create mode 100644 src/hooks/inventory/useSharedInventoryBots.ts create mode 100644 src/hooks/inventory/useSharedInventoryFurni.ts create mode 100644 src/hooks/inventory/useSharedInventoryPets.ts create mode 100644 src/hooks/inventory/useSharedInventoryTrade.ts create mode 100644 src/hooks/inventory/useSharedInventoryUnseenTracker.ts create mode 100644 src/hooks/useSharedVisibility.ts diff --git a/src/api/index.ts b/src/api/index.ts index 9ec673e9..302f2131 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -6,6 +6,7 @@ export * from './friends'; export * from './GetRendererVersion'; export * from './GetUIVersion'; export * from './groups'; +export * from './inventory'; export * from './navigator'; export * from './nitro'; export * from './nitro/avatar'; diff --git a/src/components/inventory/common/FurniCategory.ts b/src/api/inventory/FurniCategory.ts similarity index 100% rename from src/components/inventory/common/FurniCategory.ts rename to src/api/inventory/FurniCategory.ts diff --git a/src/components/inventory/common/FurnitureItem.ts b/src/api/inventory/FurnitureItem.ts similarity index 98% rename from src/components/inventory/common/FurnitureItem.ts rename to src/api/inventory/FurnitureItem.ts index 0cf0d457..009591a3 100644 --- a/src/components/inventory/common/FurnitureItem.ts +++ b/src/api/inventory/FurnitureItem.ts @@ -1,6 +1,6 @@ import { IFurnitureItemData, IObjectData } from '@nitrots/nitro-renderer'; -import { GetNitroInstance } from '../../../api'; -import { IFurnitureItem } from './IFurnitureItem'; +import { IFurnitureItem } from '.'; +import { GetNitroInstance } from '..'; export class FurnitureItem implements IFurnitureItem { diff --git a/src/components/inventory/common/GroupItem.ts b/src/api/inventory/GroupItem.ts similarity index 99% rename from src/components/inventory/common/GroupItem.ts rename to src/api/inventory/GroupItem.ts index 2b3598a4..d229200e 100644 --- a/src/components/inventory/common/GroupItem.ts +++ b/src/api/inventory/GroupItem.ts @@ -1,5 +1,5 @@ import { IObjectData, IRoomEngine } from '@nitrots/nitro-renderer'; -import { LocalizeText } from '../../../api'; +import { LocalizeText } from '..'; import { FurniCategory } from './FurniCategory'; import { FurnitureItem } from './FurnitureItem'; import { IFurnitureItem } from './IFurnitureItem'; diff --git a/src/api/inventory/IBadgeItem.ts b/src/api/inventory/IBadgeItem.ts new file mode 100644 index 00000000..ec983767 --- /dev/null +++ b/src/api/inventory/IBadgeItem.ts @@ -0,0 +1,5 @@ +export interface IBadgeItem +{ + id: number; + badgeCode: string; +} diff --git a/src/api/inventory/IBotItem.ts b/src/api/inventory/IBotItem.ts new file mode 100644 index 00000000..0a370ba6 --- /dev/null +++ b/src/api/inventory/IBotItem.ts @@ -0,0 +1,6 @@ +import { BotData } from '@nitrots/nitro-renderer'; + +export interface IBotItem +{ + botData: BotData; +} diff --git a/src/components/inventory/common/IFurnitureItem.ts b/src/api/inventory/IFurnitureItem.ts similarity index 100% rename from src/components/inventory/common/IFurnitureItem.ts rename to src/api/inventory/IFurnitureItem.ts diff --git a/src/api/inventory/IPetItem.ts b/src/api/inventory/IPetItem.ts new file mode 100644 index 00000000..910d5dff --- /dev/null +++ b/src/api/inventory/IPetItem.ts @@ -0,0 +1,6 @@ +import { PetData } from '@nitrots/nitro-renderer'; + +export interface IPetItem +{ + petData: PetData; +} diff --git a/src/api/inventory/InventoryUtilities.ts b/src/api/inventory/InventoryUtilities.ts new file mode 100644 index 00000000..2dae7d84 --- /dev/null +++ b/src/api/inventory/InventoryUtilities.ts @@ -0,0 +1,116 @@ +import { FurniturePlacePaintComposer, RoomObjectCategory, RoomObjectPlacementSource, RoomObjectType } from '@nitrots/nitro-renderer'; +import { FurniCategory, GroupItem } from '.'; +import { CreateLinkEvent, GetRoomEngine, GetRoomSessionManager, SendMessageComposer } from '..'; +import { IBotItem } from './IBotItem'; +import { IPetItem } from './IPetItem'; + +let objectMoverRequested = false; +let itemIdInPlacing = -1; + +export const isObjectMoverRequested = () => objectMoverRequested; + +export const setObjectMoverRequested = (flag: boolean) => objectMoverRequested = flag; + +export const getPlacingItemId = () => itemIdInPlacing; + +export const setPlacingItemId = (id: number) => (itemIdInPlacing = id); + +export const cancelRoomObjectPlacement = () => +{ + if(getPlacingItemId() === -1) return; + + GetRoomEngine().cancelRoomObjectPlacement(); + + setPlacingItemId(-1); + setObjectMoverRequested(false); +} + +export const attemptPetPlacement = (petItem: IPetItem, flag: boolean = false) => +{ + const petData = petItem.petData; + + if(!petData) return false; + + const session = GetRoomSessionManager().getSession(1); + + if(!session) return false; + + if(!session.isRoomOwner && !session.allowPets) return false; + + CreateLinkEvent('inventory/hide'); + + if(GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, -(petData.id), RoomObjectCategory.UNIT, RoomObjectType.PET, petData.figureData.figuredata)) + { + setPlacingItemId(petData.id); + setObjectMoverRequested(true); + } + + return true; +} + +export const attemptItemPlacement = (groupItem: GroupItem, flag: boolean = false) => +{ + if(!groupItem || !groupItem.getUnlockedCount()) return false; + + const item = groupItem.getLastItem(); + + if(!item) return false; + + if((item.category === FurniCategory.FLOOR) || (item.category === FurniCategory.WALL_PAPER) || (item.category === FurniCategory.LANDSCAPE)) + { + if(flag) return false; + + SendMessageComposer(new FurniturePlacePaintComposer(item.id)); + + return false; + } + else + { + CreateLinkEvent('inventory/hide'); + + let category = 0; + let isMoving = false; + + if(item.isWallItem) category = RoomObjectCategory.WALL; + else category = RoomObjectCategory.FLOOR; + + if((item.category === FurniCategory.POSTER)) // or external image from furnidata + { + isMoving = GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, item.id, category, item.type, item.stuffData.getLegacyString()); + } + else + { + isMoving = GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, item.id, category, item.type, item.extra.toString(), item.stuffData); + } + + if(isMoving) + { + setPlacingItemId(item.ref); + setObjectMoverRequested(true); + } + } + + return true; +} + + +export const attemptBotPlacement = (botItem: IBotItem, flag: boolean = false) => +{ + const botData = botItem.botData; + + if(!botData) return false; + + const session = GetRoomSessionManager().getSession(1); + + if(!session || !session.isRoomOwner) return false; + + CreateLinkEvent('inventory/hide'); + + if(GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, -(botData.id), RoomObjectCategory.UNIT, RoomObjectType.RENTABLE_BOT, botData.figure)) + { + setPlacingItemId(botData.id); + setObjectMoverRequested(true); + } + + return true; +} diff --git a/src/components/inventory/common/TradeState.ts b/src/api/inventory/TradeState.ts similarity index 100% rename from src/components/inventory/common/TradeState.ts rename to src/api/inventory/TradeState.ts diff --git a/src/components/inventory/common/TradeUserData.ts b/src/api/inventory/TradeUserData.ts similarity index 100% rename from src/components/inventory/common/TradeUserData.ts rename to src/api/inventory/TradeUserData.ts diff --git a/src/components/inventory/common/TradingNotificationMessage.ts b/src/api/inventory/TradingNotificationMessage.ts similarity index 96% rename from src/components/inventory/common/TradingNotificationMessage.ts rename to src/api/inventory/TradingNotificationMessage.ts index 4931fd5c..8ccbed1a 100644 --- a/src/components/inventory/common/TradingNotificationMessage.ts +++ b/src/api/inventory/TradingNotificationMessage.ts @@ -1,4 +1,4 @@ -import { LocalizeText, NotificationUtilities } from '../../../api'; +import { LocalizeText, NotificationUtilities } from '..'; import { TradingNotificationType } from './TradingNotificationType'; export const TradingNotificationMessage = (type: number) => diff --git a/src/components/inventory/common/TradingNotificationType.ts b/src/api/inventory/TradingNotificationType.ts similarity index 100% rename from src/components/inventory/common/TradingNotificationType.ts rename to src/api/inventory/TradingNotificationType.ts diff --git a/src/api/inventory/index.ts b/src/api/inventory/index.ts new file mode 100644 index 00000000..31b6dfad --- /dev/null +++ b/src/api/inventory/index.ts @@ -0,0 +1,13 @@ +export * from './FurniCategory'; +export * from './FurnitureItem'; +export * from './GroupItem'; +export * from './IBadgeItem'; +export * from './IBotItem'; +export * from './IFurnitureItem'; +export * from './InventoryUtilities'; +export * from './IPetItem'; +export * from './TradeState'; +export * from './TradeUserData'; +export * from './TradingNotificationMessage'; +export * from './TradingNotificationType'; +export * from './unseen'; diff --git a/src/components/inventory/common/unseen/IUnseenItemTracker.ts b/src/api/inventory/unseen/IUnseenItemTracker.ts similarity index 100% rename from src/components/inventory/common/unseen/IUnseenItemTracker.ts rename to src/api/inventory/unseen/IUnseenItemTracker.ts diff --git a/src/components/inventory/common/unseen/UnseenItemCategory.ts b/src/api/inventory/unseen/UnseenItemCategory.ts similarity index 100% rename from src/components/inventory/common/unseen/UnseenItemCategory.ts rename to src/api/inventory/unseen/UnseenItemCategory.ts diff --git a/src/api/inventory/unseen/index.ts b/src/api/inventory/unseen/index.ts new file mode 100644 index 00000000..31936cbd --- /dev/null +++ b/src/api/inventory/unseen/index.ts @@ -0,0 +1,2 @@ +export * from './IUnseenItemTracker'; +export * from './UnseenItemCategory'; diff --git a/src/api/nitro/room/widgets/handlers/RoomWidgetAvatarInfoHandler.ts b/src/api/nitro/room/widgets/handlers/RoomWidgetAvatarInfoHandler.ts index 5ec47a95..5731ad1d 100644 --- a/src/api/nitro/room/widgets/handlers/RoomWidgetAvatarInfoHandler.ts +++ b/src/api/nitro/room/widgets/handlers/RoomWidgetAvatarInfoHandler.ts @@ -2,7 +2,7 @@ import { NitroEvent, RoomEngineUseProductEvent, RoomObjectCategory, RoomObjectTy import { SendMessageComposer } from '../../..'; import { GetRoomEngine, GetSessionDataManager, IsOwnerOfFurniture } from '../../../..'; import { MessengerFriend } from '../../../../../components/friends/common/MessengerFriend'; -import { FurniCategory } from '../../../../../components/inventory/common/FurniCategory'; +import { FurniCategory } from '../../../../inventory/FurniCategory'; import { RoomWidgetAvatarInfoEvent, RoomWidgetUpdateDanceStatusEvent, RoomWidgetUpdateEvent, RoomWidgetUpdateUserDataEvent, RoomWidgetUseProductBubbleEvent, UseProductItem } from '../events'; import { RoomWidgetAvatarExpressionMessage, RoomWidgetChangePostureMessage, RoomWidgetDanceMessage, RoomWidgetMessage, RoomWidgetRoomObjectMessage, RoomWidgetUseProductMessage, RoomWidgetUserActionMessage } from '../messages'; import { RoomWidgetHandler } from './RoomWidgetHandler'; diff --git a/src/components/catalog/views/page/layout/marketplace/MarketplacePostOfferView.tsx b/src/components/catalog/views/page/layout/marketplace/MarketplacePostOfferView.tsx index 1e6475e7..4c0b8104 100644 --- a/src/components/catalog/views/page/layout/marketplace/MarketplacePostOfferView.tsx +++ b/src/components/catalog/views/page/layout/marketplace/MarketplacePostOfferView.tsx @@ -1,10 +1,9 @@ import { GetMarketplaceConfigurationMessageComposer, MakeOfferMessageComposer, MarketplaceConfigurationEvent } from '@nitrots/nitro-renderer'; import { FC, useCallback, useEffect, useState } from 'react'; -import { LocalizeText, NotificationUtilities, SendMessageComposer } from '../../../../../../api'; +import { FurnitureItem, LocalizeText, NotificationUtilities, SendMessageComposer } from '../../../../../../api'; import { Base, Button, Column, Grid, LayoutFurniImageView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../../../common'; import { CatalogPostMarketplaceOfferEvent } from '../../../../../../events'; import { UseMessageEventHook, UseUiEvent } from '../../../../../../hooks'; -import { FurnitureItem } from '../../../../../inventory/common/FurnitureItem'; import { useCatalogContext } from '../../../../CatalogContext'; import { ProductTypeEnum } from '../../../../common/ProductTypeEnum'; diff --git a/src/components/catalog/views/page/widgets/CatalogBadgeSelectorWidgetView.tsx b/src/components/catalog/views/page/widgets/CatalogBadgeSelectorWidgetView.tsx index fb32c1b2..47b589e5 100644 --- a/src/components/catalog/views/page/widgets/CatalogBadgeSelectorWidgetView.tsx +++ b/src/components/catalog/views/page/widgets/CatalogBadgeSelectorWidgetView.tsx @@ -1,8 +1,8 @@ import { StringDataType } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useMemo, useState } from 'react'; +import { FC, useEffect, useMemo, useState } from 'react'; +import { IBadgeItem } from '../../../../../api'; import { AutoGrid, AutoGridProps, LayoutBadgeImageView, LayoutGridItem } from '../../../../../common'; -import { InventoryBadgesRequestEvent, InventoryBadgesUpdatedEvent } from '../../../../../events'; -import { DispatchUiEvent, UseUiEvent } from '../../../../../hooks'; +import { useSharedInventoryBadges } from '../../../../../hooks'; import { useCatalogContext } from '../../../CatalogContext'; const EXCLUDED_BADGE_CODES: string[] = []; @@ -15,16 +15,9 @@ interface CatalogBadgeSelectorWidgetViewProps extends AutoGridProps export const CatalogBadgeSelectorWidgetView: FC = props => { const { columnCount = 5, ...rest } = props; - const [ badges, setBadges ] = useState([]); - const [ currentBadge, setCurrentBadge ] = useState(null); + const [ currentBadge, setCurrentBadge ] = useState(null); const { currentOffer = null, setPurchaseOptions = null } = useCatalogContext(); - - const onInventoryBadgesUpdatedEvent = useCallback((event: InventoryBadgesUpdatedEvent) => - { - setBadges(event.badges); - }, []); - - UseUiEvent(InventoryBadgesUpdatedEvent.BADGES_UPDATED, onInventoryBadgesUpdatedEvent); + const { badges = [] } = useSharedInventoryBadges(); const previewStuffData = useMemo(() => { @@ -32,7 +25,7 @@ export const CatalogBadgeSelectorWidgetView: FC - { - DispatchUiEvent(new InventoryBadgesRequestEvent(InventoryBadgesRequestEvent.REQUEST_BADGES)); - }, []); - return ( - { badges && (badges.length > 0) && badges.map((code, index) => + { badges && (badges.length > 0) && badges.map((badge, index) => { return ( - setCurrentBadge(code) }> - + setCurrentBadge(badge) }> + ); }) } diff --git a/src/components/inventory/InventoryContext.tsx b/src/components/inventory/InventoryContext.tsx deleted file mode 100644 index b30e81bc..00000000 --- a/src/components/inventory/InventoryContext.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { createContext, Dispatch, FC, ProviderProps, useContext } from 'react'; -import { IUnseenItemTracker } from './common/unseen/IUnseenItemTracker'; -import { IInventoryBadgeAction, IInventoryBadgeState } from './reducers/InventoryBadgeReducer'; -import { IInventoryBotAction, IInventoryBotState } from './reducers/InventoryBotReducer'; -import { IInventoryFurnitureAction, IInventoryFurnitureState } from './reducers/InventoryFurnitureReducer'; -import { IInventoryPetAction, IInventoryPetState } from './reducers/InventoryPetReducer'; - -export interface IInventoryContext -{ - furnitureState: IInventoryFurnitureState; - dispatchFurnitureState: Dispatch; - botState: IInventoryBotState; - dispatchBotState: Dispatch; - petState: IInventoryPetState; - dispatchPetState: Dispatch; - badgeState: IInventoryBadgeState; - dispatchBadgeState: Dispatch; - unseenTracker: IUnseenItemTracker; -} - - -const InventoryContext = createContext({ - furnitureState: null, - dispatchFurnitureState: null, - botState: null, - dispatchBotState: null, - petState: null, - dispatchPetState: null, - badgeState: null, - dispatchBadgeState: null, - unseenTracker: null -}); - -export const InventoryContextProvider: FC> = props => -{ - return { props.children } -} - -export const useInventoryContext = () => useContext(InventoryContext); diff --git a/src/components/inventory/InventoryMessageHandler.tsx b/src/components/inventory/InventoryMessageHandler.tsx deleted file mode 100644 index 5b5e72b5..00000000 --- a/src/components/inventory/InventoryMessageHandler.tsx +++ /dev/null @@ -1,386 +0,0 @@ -import { AdvancedMap, BadgePointLimitsEvent, BadgeReceivedEvent, BadgesEvent, BotAddedToInventoryEvent, BotInventoryMessageEvent, BotRemovedFromInventoryEvent, FurnitureListAddOrUpdateEvent, FurnitureListEvent, FurnitureListInvalidateEvent, FurnitureListItemParser, FurnitureListRemovedEvent, FurniturePostItPlacedEvent, PetAddedToInventoryEvent, PetData, PetInventoryEvent, PetRemovedFromInventory, RequestBadgesComposer, TradingAcceptEvent, TradingCloseEvent, TradingCloseParser, TradingCompletedEvent, TradingConfirmationEvent, TradingListItemEvent, TradingNotOpenEvent, TradingOpenEvent, TradingOpenFailedEvent, TradingOpenFailedParser, TradingOtherNotAllowedEvent, TradingYouAreNotAllowedEvent, UnseenItemsEvent } from '@nitrots/nitro-renderer'; -import { FC, useCallback } from 'react'; -import { GetLocalization, GetRoomSession, GetSessionDataManager, SendMessageComposer } from '../../api'; -import { InventoryBadgesRequestEvent, InventoryBadgesUpdatedEvent } from '../../events'; -import { DispatchUiEvent, UseMessageEventHook, UseUiEvent } from '../../hooks'; -import { mergeFurniFragments } from './common/FurnitureUtilities'; -import { mergePetFragments } from './common/PetUtilities'; -import { TradeState } from './common/TradeState'; -import { TradeUserData } from './common/TradeUserData'; -import { TradingNotificationMessage } from './common/TradingNotificationMessage'; -import { TradingNotificationType } from './common/TradingNotificationType'; -import { useInventoryContext } from './InventoryContext'; -import { InventoryBadgeActions } from './reducers/InventoryBadgeReducer'; -import { InventoryBotActions } from './reducers/InventoryBotReducer'; -import { InventoryFurnitureActions } from './reducers/InventoryFurnitureReducer'; -import { InventoryPetActions } from './reducers/InventoryPetReducer'; - -let furniMsgFragments: Map[] = null; -let petMsgFragments: Map[] = null; - -export const InventoryMessageHandler: FC<{}> = props => -{ - const { dispatchFurnitureState = null, dispatchBotState = null, dispatchPetState = null, badgeState = null, dispatchBadgeState = null, unseenTracker = null, furnitureState = null } = useInventoryContext(); - - const onFurnitureListAddOrUpdateEvent = useCallback((event: FurnitureListAddOrUpdateEvent) => - { - const parser = event.getParser(); - - dispatchFurnitureState({ - type: InventoryFurnitureActions.ADD_OR_UPDATE_FURNITURE, - payload: { - parsers: parser.items - } - }); - }, [ dispatchFurnitureState ]); - - const onFurnitureListEvent = useCallback((event: FurnitureListEvent) => - { - const parser = event.getParser(); - - if(!furniMsgFragments) furniMsgFragments = new Array(parser.totalFragments); - - const fragment = mergeFurniFragments(parser.fragment, parser.totalFragments, parser.fragmentNumber, furniMsgFragments); - - if(!fragment) return; - - dispatchFurnitureState({ - type: InventoryFurnitureActions.PROCESS_FRAGMENT, - payload: { fragment, unseenTracker } - }); - - furniMsgFragments = null; - }, [ unseenTracker, dispatchFurnitureState ]); - - const onFurnitureListInvalidateEvent = useCallback((event: FurnitureListInvalidateEvent) => - { - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_NEEDS_UPDATE, - payload: { - flag: true - } - }); - }, [ dispatchFurnitureState ]); - - const onFurnitureListRemovedEvent = useCallback((event: FurnitureListRemovedEvent) => - { - const parser = event.getParser(); - - dispatchFurnitureState({ - type: InventoryFurnitureActions.REMOVE_FURNITURE, - payload: { - itemId: parser.itemId - } - }); - }, [ dispatchFurnitureState ]); - - const onFurniturePostItPlacedEvent = useCallback((event: FurniturePostItPlacedEvent) => - { - - }, []); - - const onBotInventoryMessageEvent = useCallback((event: BotInventoryMessageEvent) => - { - const parser = event.getParser(); - - const fragment = Array.from(parser.items.values()); - - dispatchBotState({ - type: InventoryBotActions.PROCESS_FRAGMENT, - payload: { fragment, unseenTracker } - }); - }, [ dispatchBotState, unseenTracker ]); - - const onBotAddedToInventoryEvent = useCallback((event: BotAddedToInventoryEvent) => - { - const parser = event.getParser(); - - dispatchBotState({ - type: InventoryBotActions.ADD_BOT, - payload: { - botData: parser.item - } - }); - }, [ dispatchBotState ]); - - const onBotRemovedFromInventoryEvent = useCallback((event: BotRemovedFromInventoryEvent) => - { - const parser = event.getParser(); - - dispatchBotState({ - type: InventoryBotActions.REMOVE_BOT, - payload: { - botId: parser.itemId - } - }); - }, [ dispatchBotState ]); - - const onPetInventoryEvent = useCallback((event: PetInventoryEvent) => - { - const parser = event.getParser(); - - if(!petMsgFragments) petMsgFragments = new Array(parser.totalFragments); - - const fragment = mergePetFragments(parser.fragment, parser.totalFragments, parser.fragmentNumber, petMsgFragments); - - if(!fragment) return; - - dispatchPetState({ - type: InventoryPetActions.PROCESS_FRAGMENT, - payload: { fragment, unseenTracker } - }); - }, [ dispatchPetState, unseenTracker ]); - - const onPetAddedToInventoryEvent = useCallback((event: PetAddedToInventoryEvent) => - { - const parser = event.getParser(); - - dispatchPetState({ - type: InventoryPetActions.ADD_PET, - payload: { - petData: parser.pet - } - }); - }, [ dispatchPetState ]); - - const onPetRemovedFromInventory = useCallback((event: PetRemovedFromInventory) => - { - const parser = event.getParser(); - - dispatchPetState({ - type: InventoryPetActions.REMOVE_PET, - payload: { - petId: parser.petId - } - }); - }, [ dispatchPetState ]); - - const onBadgesEvent = useCallback((event: BadgesEvent) => - { - const parser = event.getParser(); - - dispatchBadgeState({ - type: InventoryBadgeActions.SET_BADGES, - payload: { - badgeCodes: parser.getAllBadgeCodes(), - activeBadgeCodes: parser.getActiveBadgeCodes() - } - }); - }, [ dispatchBadgeState ]); - - const onBadgeReceivedEvent = useCallback((event: BadgeReceivedEvent) => - { - const parser = event.getParser(); - - dispatchBadgeState({ - type: InventoryBadgeActions.ADD_BADGE, - payload: { - badgeCode: parser.badgeCode - } - }); - }, [ dispatchBadgeState ]); - - const onTradingAcceptEvent = useCallback((event: TradingAcceptEvent) => - { - const parser = event.getParser(); - - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_TRADE_ACCEPTANCE, - payload: { - userId: parser.userID, - flag: parser.userAccepts - } - }); - }, [ dispatchFurnitureState ]); - - const onTradingCloseEvent = useCallback((event: TradingCloseEvent) => - { - const parser = event.getParser(); - - if(parser.reason === TradingCloseParser.ERROR_WHILE_COMMIT) - { - TradingNotificationMessage(TradingNotificationType.ERROR_WHILE_COMMIT); - } - else - { - if(parser.userID !== (furnitureState && furnitureState.tradeData.ownUser.userId)) - { - TradingNotificationMessage(TradingNotificationType.ALERT_OTHER_CANCELLED); - } - } - - dispatchFurnitureState({ - type: InventoryFurnitureActions.CLOSE_TRADE, - payload: {} - }); - }, [ furnitureState, dispatchFurnitureState ]); - - const onTradingCompletedEvent = useCallback((event: TradingCompletedEvent) => - { - const parser = event.getParser(); - - dispatchFurnitureState({ - type: InventoryFurnitureActions.CLOSE_TRADE, - payload: {} - }); - }, [ dispatchFurnitureState ]); - - const onTradingConfirmationEvent = useCallback((event: TradingConfirmationEvent) => - { - const parser = event.getParser(); - - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_TRADE_STATE, - payload: { - tradeState: TradeState.TRADING_STATE_COUNTDOWN - } - }); - }, [ dispatchFurnitureState ]); - - const onTradingListItemEvent = useCallback((event: TradingListItemEvent) => - { - const parser = event.getParser(); - - dispatchFurnitureState({ - type: InventoryFurnitureActions.UPDATE_TRADE, - payload: { - tradeParser: event.getParser() - } - }); - }, [ dispatchFurnitureState ]); - - const onTradingNotOpenEvent = useCallback((event: TradingNotOpenEvent) => - { - const parser = event.getParser(); - - console.log(parser); - }, []); - - const onTradingOpenEvent = useCallback((event: TradingOpenEvent) => - { - const parser = event.getParser(); - - const ownUser = new TradeUserData(); - const otherUser = new TradeUserData(); - - ownUser.userItems = new AdvancedMap(); - otherUser.userItems = new AdvancedMap(); - - const userDataOne = GetRoomSession().userDataManager.getUserData(parser.userID); - const userDataTwo = GetRoomSession().userDataManager.getUserData(parser.otherUserID); - - if(userDataOne.webID === GetSessionDataManager().userId) - { - ownUser.userId = userDataOne.webID; - ownUser.userName = userDataOne.name; - ownUser.canTrade = parser.userCanTrade; - - otherUser.userId = userDataTwo.webID; - otherUser.userName = userDataTwo.name; - otherUser.canTrade = parser.otherUserCanTrade; - } - - else if(userDataTwo.webID === GetSessionDataManager().userId) - { - ownUser.userId = userDataTwo.webID; - ownUser.userName = userDataTwo.name; - ownUser.canTrade = parser.otherUserCanTrade; - - otherUser.userId = userDataOne.webID; - otherUser.userName = userDataOne.name; - otherUser.canTrade = parser.userCanTrade; - } - - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_TRADE_DATA, - payload: { - ownTradeUser: ownUser, - otherTradeUser: otherUser - } - }); - }, [ dispatchFurnitureState ]); - - const onTradingOpenFailedEvent = useCallback((event: TradingOpenFailedEvent) => - { - const parser = event.getParser(); - - if((parser.reason !== TradingOpenFailedParser.REASON_YOU_ARE_ALREADY_TRADING && (parser.reason !== TradingOpenFailedParser.REASON_OTHER_USER_ALREADY_TRADING))) return; - - TradingNotificationMessage(TradingNotificationType.ALERT_ALREADY_OPEN); - }, []); - - const onTradingOtherNotAllowedEvent = useCallback((event: TradingOtherNotAllowedEvent) => - { - const parser = event.getParser(); - - TradingNotificationMessage(TradingNotificationType.ALERT_OTHER_DISABLED); - }, []); - - const onTradingYouAreNotAllowedEvent = useCallback((event: TradingYouAreNotAllowedEvent) => - { - const parser = event.getParser(); - - TradingNotificationMessage(TradingNotificationType.YOU_NOT_ALLOWED); - }, []); - - const onUnseenItemsEvent = useCallback((event: UnseenItemsEvent) => - { - const parser = event.getParser(); - - for(const category of parser.categories) - { - const itemIds = parser.getItemsByCategory(category); - - unseenTracker.addItems(category, itemIds); - } - }, [ unseenTracker ]); - - const onBadgePointLimitsEvent = useCallback((event: BadgePointLimitsEvent) => - { - const parser = event.getParser(); - - for(const data of parser.data) GetLocalization().setBadgePointLimit(data.badgeId, data.limit); - }, []); - - UseMessageEventHook(FurnitureListAddOrUpdateEvent, onFurnitureListAddOrUpdateEvent); - UseMessageEventHook(FurnitureListEvent, onFurnitureListEvent); - UseMessageEventHook(FurnitureListInvalidateEvent, onFurnitureListInvalidateEvent); - UseMessageEventHook(FurnitureListRemovedEvent, onFurnitureListRemovedEvent); - UseMessageEventHook(FurniturePostItPlacedEvent, onFurniturePostItPlacedEvent); - UseMessageEventHook(BotInventoryMessageEvent, onBotInventoryMessageEvent); - UseMessageEventHook(BotRemovedFromInventoryEvent, onBotRemovedFromInventoryEvent); - UseMessageEventHook(BotAddedToInventoryEvent, onBotAddedToInventoryEvent); - UseMessageEventHook(PetInventoryEvent, onPetInventoryEvent); - UseMessageEventHook(PetRemovedFromInventory, onPetRemovedFromInventory); - UseMessageEventHook(PetAddedToInventoryEvent, onPetAddedToInventoryEvent); - UseMessageEventHook(BadgesEvent, onBadgesEvent); - UseMessageEventHook(BadgeReceivedEvent, onBadgeReceivedEvent); - UseMessageEventHook(TradingAcceptEvent, onTradingAcceptEvent); - UseMessageEventHook(TradingCloseEvent, onTradingCloseEvent); - UseMessageEventHook(TradingCompletedEvent, onTradingCompletedEvent); - UseMessageEventHook(TradingConfirmationEvent, onTradingConfirmationEvent); - UseMessageEventHook(TradingListItemEvent, onTradingListItemEvent); - UseMessageEventHook(TradingNotOpenEvent, onTradingNotOpenEvent); - UseMessageEventHook(TradingOpenEvent, onTradingOpenEvent); - UseMessageEventHook(TradingOpenFailedEvent, onTradingOpenFailedEvent); - UseMessageEventHook(TradingOtherNotAllowedEvent, onTradingOtherNotAllowedEvent); - UseMessageEventHook(TradingYouAreNotAllowedEvent, onTradingYouAreNotAllowedEvent); - UseMessageEventHook(UnseenItemsEvent, onUnseenItemsEvent); - UseMessageEventHook(BadgePointLimitsEvent, onBadgePointLimitsEvent); - - const onInventoryBadgesRequestEvent = useCallback((event: InventoryBadgesRequestEvent) => - { - if(badgeState.needsBadgeUpdate) - { - SendMessageComposer(new RequestBadgesComposer()); - - return; - } - - DispatchUiEvent(new InventoryBadgesUpdatedEvent(InventoryBadgesUpdatedEvent.BADGES_UPDATED, badgeState.badges)); - }, [ badgeState ]) - - UseUiEvent(InventoryBadgesRequestEvent.REQUEST_BADGES, onInventoryBadgesRequestEvent); - - return null; -} diff --git a/src/components/inventory/InventoryView.tsx b/src/components/inventory/InventoryView.tsx index 6a8ca1df..fd862598 100644 --- a/src/components/inventory/InventoryView.tsx +++ b/src/components/inventory/InventoryView.tsx @@ -1,25 +1,15 @@ -import { IRoomSession, RoomEngineObjectEvent, RoomEngineObjectPlacedEvent, RoomPreviewer, RoomSessionEvent, TradingCancelComposer, TradingCloseComposer, TradingOpenComposer } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useEffect, useReducer, useState } from 'react'; -import { GetRoomEngine, LocalizeText, SendMessageComposer } from '../../api'; +import { BadgePointLimitsEvent, ILinkEventTracker, IRoomSession, RoomEngineObjectEvent, RoomEngineObjectPlacedEvent, RoomPreviewer, RoomSessionEvent, TradingOpenComposer } from '@nitrots/nitro-renderer'; +import { FC, useCallback, useEffect, useState } from 'react'; +import { AddEventLinkTracker, GetLocalization, GetRoomEngine, LocalizeText, RemoveLinkEventTracker, SendMessageComposer, UnseenItemCategory } from '../../api'; +import { isObjectMoverRequested, setObjectMoverRequested } from '../../api/inventory/InventoryUtilities'; import { NitroCardContentView, NitroCardHeaderView, NitroCardTabsItemView, NitroCardTabsView, NitroCardView } from '../../common'; -import { InventoryBadgesUpdatedEvent, InventoryEvent, InventoryTradeRequestEvent } from '../../events'; -import { DispatchUiEvent, UseRoomEngineEvent, UseRoomSessionManagerEvent, UseUiEvent } from '../../hooks'; -import { isObjectMoverRequested, setObjectMoverRequested } from './common/InventoryUtilities'; -import { TradeState } from './common/TradeState'; -import { IUnseenItemTracker } from './common/unseen/IUnseenItemTracker'; -import { UnseenItemCategory } from './common/unseen/UnseenItemCategory'; -import { UnseenItemTracker } from './common/unseen/UnseenItemTracker'; -import { InventoryContextProvider } from './InventoryContext'; -import { InventoryMessageHandler } from './InventoryMessageHandler'; -import { initialInventoryBadge, InventoryBadgeReducer } from './reducers/InventoryBadgeReducer'; -import { initialInventoryBot, InventoryBotReducer } from './reducers/InventoryBotReducer'; -import { initialInventoryFurniture, InventoryFurnitureReducer } from './reducers/InventoryFurnitureReducer'; -import { initialInventoryPet, InventoryPetReducer } from './reducers/InventoryPetReducer'; -import { InventoryBadgeView } from './views/badge/InventoryBadgeView'; -import { InventoryBotView } from './views/bot/InventoryBotView'; -import { InventoryFurnitureView } from './views/furniture/InventoryFurnitureView'; -import { InventoryPetView } from './views/pet/InventoryPetView'; -import { InventoryTradeView } from './views/trade/InventoryTradeView'; +import { InventoryTradeRequestEvent } from '../../events'; +import { UseMessageEventHook, UseRoomEngineEvent, UseRoomSessionManagerEvent, useSharedInventoryUnseenTracker, UseUiEvent } from '../../hooks'; +import { InventoryBadgeView } from './views/InventoryBadgeView'; +import { InventoryBotView } from './views/InventoryBotView'; +import { InventoryFurnitureView } from './views/InventoryFurnitureView'; +import { InventoryPetView } from './views/InventoryPetView'; +import { InventoryTradeView } from './views/InventoryTradeView'; const TAB_FURNITURE: string = 'inventory.furni'; const TAB_BOTS: string = 'inventory.bots'; @@ -34,66 +24,40 @@ export const InventoryView: FC<{}> = props => const [ currentTab, setCurrentTab ] = useState(TABS[0]); const [ roomSession, setRoomSession ] = useState(null); const [ roomPreviewer, setRoomPreviewer ] = useState(null); - const [ furnitureState, dispatchFurnitureState ] = useReducer(InventoryFurnitureReducer, initialInventoryFurniture); - const [ botState, dispatchBotState ] = useReducer(InventoryBotReducer, initialInventoryBot); - const [ petState, dispatchPetState ] = useReducer(InventoryPetReducer, initialInventoryPet); - const [ badgeState, dispatchBadgeState ] = useReducer(InventoryBadgeReducer, initialInventoryBadge); - const [ unseenTracker ] = useState(new UnseenItemTracker()); + const { getCount = null, resetCategory = null } = useSharedInventoryUnseenTracker(); const close = useCallback(() => { - if(furnitureState.tradeData) - { - switch(furnitureState.tradeData.state) - { - case TradeState.TRADING_STATE_RUNNING: - SendMessageComposer(new TradingCloseComposer()); - return; - default: - SendMessageComposer(new TradingCancelComposer()); - return; - } - } + // close the trade + // if(furnitureState.tradeData) + // { + // switch(furnitureState.tradeData.state) + // { + // case TradeState.TRADING_STATE_RUNNING: + // SendMessageComposer(new TradingCloseComposer()); + // return; + // default: + // SendMessageComposer(new TradingCancelComposer()); + // return; + // } + // } setIsVisible(false); - }, [ furnitureState.tradeData ]); + }, []); - const onInventoryEvent = useCallback((event: InventoryEvent) => + const onInventoryTradeRequestEvent = useCallback((event: InventoryTradeRequestEvent) => { switch(event.type) { - case InventoryEvent.SHOW_INVENTORY: - if(isVisible) return; - - setIsVisible(true); - return; - case InventoryEvent.HIDE_INVENTORY: - if(!isVisible) return; - - close(); - return; - case InventoryEvent.TOGGLE_INVENTORY: - if(!isVisible) - { - setIsVisible(true); - } - else - { - close(); - } - return; case InventoryTradeRequestEvent.REQUEST_TRADE: { const tradeEvent = (event as InventoryTradeRequestEvent); SendMessageComposer(new TradingOpenComposer(tradeEvent.objectId)); } } - }, [ isVisible, close ]); + }, []); - UseUiEvent(InventoryEvent.SHOW_INVENTORY, onInventoryEvent); - UseUiEvent(InventoryEvent.HIDE_INVENTORY, onInventoryEvent); - UseUiEvent(InventoryEvent.TOGGLE_INVENTORY, onInventoryEvent); - UseUiEvent(InventoryTradeRequestEvent.REQUEST_TRADE, onInventoryEvent); + UseUiEvent(InventoryTradeRequestEvent.REQUEST_TRADE, onInventoryTradeRequestEvent); const onRoomEngineObjectPlacedEvent = useCallback((event: RoomEngineObjectPlacedEvent) => { @@ -123,44 +87,44 @@ export const InventoryView: FC<{}> = props => UseRoomSessionManagerEvent(RoomSessionEvent.CREATED, onRoomSessionEvent); UseRoomSessionManagerEvent(RoomSessionEvent.ENDED, onRoomSessionEvent); - const resetTrackerForTab = useCallback((name: string) => + const onBadgePointLimitsEvent = useCallback((event: BadgePointLimitsEvent) => { - const tabIndex = TABS.indexOf(name); + const parser = event.getParser(); - if(tabIndex === -1) return; + for(const data of parser.data) GetLocalization().setBadgePointLimit(data.badgeId, data.limit); + }, []); - const unseenCategory = UNSEEN_CATEGORIES[tabIndex]; - - if(unseenCategory === -1) return; - - const count = unseenTracker.getCount(unseenCategory); - - if(!count) return; - - unseenTracker.resetCategory(unseenCategory); - - switch(unseenCategory) - { - case UnseenItemCategory.FURNI: - for(const groupItem of furnitureState.groupItems) groupItem.hasUnseenItems = false; - - return; - } - }, [ furnitureState.groupItems, unseenTracker ]); - - const switchTab = (prevTab: string, nextTab: string) => - { - if(nextTab) setCurrentTab(nextTab); - - resetTrackerForTab(prevTab); - } + UseMessageEventHook(BadgePointLimitsEvent, onBadgePointLimitsEvent); useEffect(() => { - if(isVisible) return; + const linkTracker: ILinkEventTracker = { + linkReceived: (url: string) => + { + const parts = url.split('/'); - if(currentTab) resetTrackerForTab(currentTab); - }, [ currentTab, isVisible, resetTrackerForTab ]); + if(parts.length < 2) return; + + switch(parts[1]) + { + case 'show': + setIsVisible(true); + return; + case 'hide': + setIsVisible(false); + return; + case 'toggle': + setIsVisible(prevValue => !prevValue); + return; + } + }, + eventUrlPrefix: 'inventory/' + }; + + AddEventLinkTracker(linkTracker); + + return () => RemoveLinkEventTracker(linkTracker); + }, []); useEffect(() => { @@ -181,53 +145,46 @@ export const InventoryView: FC<{}> = props => { if(!isVisible) { - if(furnitureState.tradeData) setIsVisible(true); + // if trading show it } - }, [ furnitureState.tradeData, isVisible ]); + }, [ isVisible ]); - useEffect(() => - { - if(!badgeState.badges) return; - - DispatchUiEvent(new InventoryBadgesUpdatedEvent(InventoryBadgesUpdatedEvent.BADGES_UPDATED, badgeState.badges)); - }, [ badgeState.badges ]); + const isTrading = false; + + if(!isVisible) return null; return ( - - - { isVisible && - - - { !furnitureState.tradeData && - <> - - { TABS.map((name, index) => - { - const unseenCount = unseenTracker.getCount(UNSEEN_CATEGORIES[index]); + + + { !isTrading && + <> + + { TABS.map((name, index) => + { + const unseenCount = getCount(UNSEEN_CATEGORIES[index]); - return ( - switchTab(currentTab, name) } count={ unseenCount }> - { LocalizeText(name) } - - ); - }) } - - - { (currentTab === TAB_FURNITURE ) && - } - { (currentTab === TAB_BOTS ) && - } - { (currentTab === TAB_PETS ) && - } - { (currentTab === TAB_BADGES ) && - } - - } - { furnitureState.tradeData && - - - } - } - + return ( + setCurrentTab(name) } count={ unseenCount }> + { LocalizeText(name) } + + ); + }) } + + + { (currentTab === TAB_FURNITURE ) && + } + { (currentTab === TAB_BOTS ) && + } + { (currentTab === TAB_PETS ) && + } + { (currentTab === TAB_BADGES ) && + } + + } + { isTrading && + + + } + ); } diff --git a/src/components/inventory/common/BadgeItem.ts b/src/components/inventory/common/BadgeItem.ts deleted file mode 100644 index 159a87d5..00000000 --- a/src/components/inventory/common/BadgeItem.ts +++ /dev/null @@ -1,26 +0,0 @@ -export class BadgeItem -{ - private _code: string; - private _isUnseen: boolean; - - constructor(code: string) - { - this._code = code; - this._isUnseen = false; - } - - public get code(): string - { - return this._code; - } - - public get isUnseen(): boolean - { - return this._isUnseen; - } - - public set isUnseen(flag: boolean) - { - this._isUnseen = flag; - } -} diff --git a/src/components/inventory/common/BotItem.ts b/src/components/inventory/common/BotItem.ts deleted file mode 100644 index 34a8ba58..00000000 --- a/src/components/inventory/common/BotItem.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { BotData } from '@nitrots/nitro-renderer'; - -export class BotItem -{ - private _botData: BotData; - private _selected: boolean; - private _isUnseen: boolean; - - constructor(botData: BotData) - { - this._botData = botData; - this._selected = false; - this._isUnseen = false; - } - - public get id(): number - { - return this._botData.id; - } - - public get botData(): BotData - { - return this._botData; - } - - public get selected(): boolean - { - return this._selected; - } - - public set selected(flag: boolean) - { - this._selected = flag; - } - - public get isUnseen(): boolean - { - return this._isUnseen; - } - - public set isUnseen(flag: boolean) - { - this._isUnseen = flag; - } -} diff --git a/src/components/inventory/common/BotUtilities.ts b/src/components/inventory/common/BotUtilities.ts deleted file mode 100644 index 590c0e66..00000000 --- a/src/components/inventory/common/BotUtilities.ts +++ /dev/null @@ -1,131 +0,0 @@ -import { BotData, RoomObjectCategory, RoomObjectPlacementSource, RoomObjectType } from '@nitrots/nitro-renderer'; -import { GetRoomEngine, GetRoomSessionManager } from '../../../api'; -import { InventoryEvent } from '../../../events'; -import { DispatchUiEvent } from '../../../hooks'; -import { BotItem } from './BotItem'; -import { getPlacingItemId, setObjectMoverRequested, setPlacingItemId } from './InventoryUtilities'; -import { IUnseenItemTracker } from './unseen/IUnseenItemTracker'; -import { UnseenItemCategory } from './unseen/UnseenItemCategory'; - -export function cancelRoomObjectPlacement(): void -{ - if(getPlacingItemId() === -1) return; - - GetRoomEngine().cancelRoomObjectPlacement(); - - setPlacingItemId(-1); - setObjectMoverRequested(false); -} - -export function attemptBotPlacement(botItem: BotItem, flag: boolean = false): boolean -{ - const botData = botItem.botData; - - if(!botData) return false; - - const session = GetRoomSessionManager().getSession(1); - - if(!session || !session.isRoomOwner) return false; - - DispatchUiEvent(new InventoryEvent(InventoryEvent.HIDE_INVENTORY)); - - if(GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, -(botData.id), RoomObjectCategory.UNIT, RoomObjectType.RENTABLE_BOT, botData.figure)) - { - setPlacingItemId(botData.id); - setObjectMoverRequested(true); - } - - return true; -} - -function getAllItemIds(botItems: BotItem[]): number[] -{ - const itemIds: number[] = []; - - for(const botItem of botItems) itemIds.push(botItem.id); - - return itemIds; -} - -export function processBotFragment(set: BotItem[], fragment: BotData[], unseenTracker: IUnseenItemTracker): BotItem[] -{ - const existingIds = getAllItemIds(set); - const addedDatas: BotData[] = []; - const removedIds: number[] = []; - - for(const botData of fragment) (existingIds.indexOf(botData.id) === -1) && addedDatas.push(botData); - - for(const itemId of existingIds) - { - let remove = true; - - for(const botData of fragment) - { - if(botData.id === itemId) - { - remove = false; - - break; - } - } - - if(remove) removedIds.push(itemId); - } - - const emptyExistingSet = (existingIds.length === 0); - - for(const id of removedIds) removeBotItemById(id, set); - - for(const botData of addedDatas) - { - addSingleBotItem(botData, set, unseenTracker.isUnseen(UnseenItemCategory.BOT, botData.id)); - } - - return set; -} - -export function removeBotItemById(id: number, set: BotItem[]): BotItem -{ - let index = 0; - - while(index < set.length) - { - const botItem = set[index]; - - if(botItem && (botItem.id === id)) - { - if(getPlacingItemId() === botItem.id) - { - cancelRoomObjectPlacement(); - - setTimeout(() => DispatchUiEvent(new InventoryEvent(InventoryEvent.SHOW_INVENTORY)), 1); - } - - set.splice(index, 1); - - return botItem; - } - - index++; - } - - return null; -} - -export function addSingleBotItem(botData: BotData, set: BotItem[], unseen: boolean = true): BotItem -{ - const botItem = new BotItem(botData); - - if(unseen) - { - botItem.isUnseen = true; - - set.unshift(botItem); - } - else - { - set.push(botItem); - } - - return botItem; -} diff --git a/src/components/inventory/common/FurnitureUtilities.ts b/src/components/inventory/common/FurnitureUtilities.ts deleted file mode 100644 index 15bbe5e8..00000000 --- a/src/components/inventory/common/FurnitureUtilities.ts +++ /dev/null @@ -1,350 +0,0 @@ -import { FurnitureListItemParser, FurniturePlacePaintComposer, IObjectData, RoomObjectCategory, RoomObjectPlacementSource } from '@nitrots/nitro-renderer'; -import { GetRoomEngine, SendMessageComposer } from '../../../api'; -import { CatalogPostMarketplaceOfferEvent, InventoryEvent } from '../../../events'; -import { DispatchUiEvent } from '../../../hooks'; -import { FurniCategory } from './FurniCategory'; -import { FurnitureItem } from './FurnitureItem'; -import { GroupItem } from './GroupItem'; -import { getPlacingItemId, setObjectMoverRequested, setPlacingItemId } from './InventoryUtilities'; -import { IUnseenItemTracker } from './unseen/IUnseenItemTracker'; -import { UnseenItemCategory } from './unseen/UnseenItemCategory'; - -export function attemptItemPlacement(groupItem: GroupItem, flag: boolean = false): boolean -{ - if(!groupItem || !groupItem.getUnlockedCount()) return false; - - const item = groupItem.getLastItem(); - - if(!item) return false; - - if((item.category === FurniCategory.FLOOR) || (item.category === FurniCategory.WALL_PAPER) || (item.category === FurniCategory.LANDSCAPE)) - { - if(flag) return false; - - SendMessageComposer(new FurniturePlacePaintComposer(item.id)); - - return false; - } - else - { - DispatchUiEvent(new InventoryEvent(InventoryEvent.HIDE_INVENTORY)); - - let category = 0; - let isMoving = false; - - if(item.isWallItem) category = RoomObjectCategory.WALL; - else category = RoomObjectCategory.FLOOR; - - if((item.category === FurniCategory.POSTER)) // or external image from furnidata - { - isMoving = GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, item.id, category, item.type, item.stuffData.getLegacyString()); - } - else - { - isMoving = GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, item.id, category, item.type, item.extra.toString(), item.stuffData); - } - - if(isMoving) - { - setPlacingItemId(item.ref); - setObjectMoverRequested(true); - } - } - - return true; -} - -export function attemptPlaceMarketplaceOffer(groupItem: GroupItem): boolean -{ - const item = groupItem.getLastItem(); - - if(!item) return false; - - if(!item.sellable) return false; - - DispatchUiEvent(new CatalogPostMarketplaceOfferEvent(item)); -} - -function cancelRoomObjectPlacement(): void -{ - if(getPlacingItemId() === -1) return; - - GetRoomEngine().cancelRoomObjectPlacement(); - - setPlacingItemId(-1); - setObjectMoverRequested(false); -} - -export function getGroupItemForFurnitureId(set: GroupItem[], id: number): GroupItem -{ - for(const groupItem of set) - { - if(groupItem.getItemById(id)) return groupItem; - } - - return null; -} - -export function mergeFurniFragments(fragment: Map, totalFragments: number, fragmentNumber: number, fragments: Map[]) -{ - if(totalFragments === 1) return fragment; - - fragments[fragmentNumber] = fragment; - - for(const frag of fragments) - { - if(!frag) return null; - } - - const merged: Map = new Map(); - - for(const frag of fragments) - { - for(const [ key, value ] of frag) merged.set(key, value); - - frag.clear(); - } - - fragments = null; - - return merged; -} - -function getAllItemIds(groupItems: GroupItem[]): number[] -{ - const itemIds: number[] = []; - - for(const groupItem of groupItems) - { - let totalCount = groupItem.getTotalCount(); - - if(groupItem.category === FurniCategory.POST_IT) totalCount = 1; - - let i = 0; - - while(i < totalCount) - { - itemIds.push(groupItem.getItemByIndex(i).id); - - i++; - } - } - - return itemIds; -} - -export function processFurniFragment(set: GroupItem[], fragment: Map, unseenTracker: IUnseenItemTracker): GroupItem[] -{ - const existingIds = getAllItemIds(set); - const addedIds: number[] = []; - const removedIds: number[] = []; - - for(const key of fragment.keys()) (existingIds.indexOf(key) === -1) && addedIds.push(key); - - for(const itemId of existingIds) (!fragment.get(itemId)) && removedIds.push(itemId); - - const emptyExistingSet = (existingIds.length === 0); - - for(const id of removedIds) removeFurniItemById(id, set); - - for(const id of addedIds) - { - const parser = fragment.get(id); - - if(!parser) continue; - - const item = new FurnitureItem(parser); - - addFurnitureItem(set, item, unseenTracker.isUnseen(UnseenItemCategory.FURNI, id)); - } - - return set; -} - -export function removeFurniItemById(id: number, set: GroupItem[]): GroupItem -{ - let index = 0; - - while(index < set.length) - { - const group = set[index]; - const item = group.remove(id); - - if(item) - { - if(getPlacingItemId() === item.ref) - { - cancelRoomObjectPlacement(); - - if(!attemptItemPlacement(group)) - { - setTimeout(() => DispatchUiEvent(new InventoryEvent(InventoryEvent.SHOW_INVENTORY)), 1); - } - } - - if(group.getTotalCount() <= 0) - { - set.splice(index, 1); - - group.dispose(); - } - - return group; - } - - index++; - } - - return null; -} - -export function addFurnitureItem(set: GroupItem[], item: FurnitureItem, unseen: boolean): void -{ - if(!item.isGroupable) - { - addSingleFurnitureItem(set, item, unseen); - } - else - { - addGroupableFurnitureItem(set, item, unseen); - } -} - -function addSingleFurnitureItem(set: GroupItem[], item: FurnitureItem, unseen: boolean): GroupItem -{ - const groupItems: GroupItem[] = []; - - for(const groupItem of set) - { - if(groupItem.type === item.type) groupItems.push(groupItem); - } - - for(const groupItem of groupItems) - { - if(groupItem.getItemById(item.id)) return groupItem; - } - - const groupItem = createGroupItem(item.type, item.category, item.stuffData, item.extra); - - groupItem.push(item); - - if(unseen) - { - groupItem.hasUnseenItems = true; - - set.unshift(groupItem); - } - else - { - set.push(groupItem); - } - - return groupItem; -} - -function addGroupableFurnitureItem(set: GroupItem[], item: FurnitureItem, unseen: boolean): GroupItem -{ - let existingGroup: GroupItem = null; - - for(const groupItem of set) - { - if((groupItem.type === item.type) && (groupItem.isWallItem === item.isWallItem) && groupItem.isGroupable) - { - if(item.category === FurniCategory.POSTER) - { - if(groupItem.stuffData.getLegacyString() === item.stuffData.getLegacyString()) - { - existingGroup = groupItem; - - break; - } - } - - else if(item.category === FurniCategory.GUILD_FURNI) - { - if(item.stuffData.compare(groupItem.stuffData)) - { - existingGroup = groupItem; - - break; - } - } - - else - { - existingGroup = groupItem; - - break; - } - } - } - - if(existingGroup) - { - existingGroup.push(item); - - if(unseen) - { - existingGroup.hasUnseenItems = true; - - const index = set.indexOf(existingGroup); - - if(index >= 0) set.splice(index, 1); - - set.unshift(existingGroup); - } - - return existingGroup; - } - - existingGroup = createGroupItem(item.type, item.category, item.stuffData, item.extra); - - existingGroup.push(item); - - if(unseen) - { - existingGroup.hasUnseenItems = true; - - set.unshift(existingGroup); - } - else - { - set.push(existingGroup); - } - - return existingGroup; -} - -export function createGroupItem(type: number, category: number, stuffData: IObjectData, extra: number = NaN): GroupItem -{ - // const iconImage: HTMLImageElement = null; - - if(category === FurniCategory.WALL_PAPER) - { - // const icon = this._windowManager.assets.getAssetByName("inventory_furni_icon_wallpaper"); - // if (icon != null) - // { - // iconImage = (icon.content as BitmapData).clone(); - // } - } - - else if(category === FurniCategory.FLOOR) - { - // const icon = this._windowManager.assets.getAssetByName("inventory_furni_icon_floor"); - // if (icon != null) - // { - // iconImage = (icon.content as BitmapData).clone(); - // } - } - - else if(category === FurniCategory.LANDSCAPE) - { - // const icon = this._windowManager.assets.getAssetByName("inventory_furni_icon_landscape"); - // if (icon != null) - // { - // iconImage = (icon.content as BitmapData).clone(); - // } - } - - return new GroupItem(type, category, GetRoomEngine(), stuffData, extra); -} diff --git a/src/components/inventory/common/InventoryUtilities.ts b/src/components/inventory/common/InventoryUtilities.ts deleted file mode 100644 index 62fe7565..00000000 --- a/src/components/inventory/common/InventoryUtilities.ts +++ /dev/null @@ -1,22 +0,0 @@ -let objectMoverRequested = false; -let itemIdInPlacing = -1; - -export function isObjectMoverRequested(): boolean -{ - return objectMoverRequested; -} - -export function setObjectMoverRequested(flag: boolean) -{ - objectMoverRequested = flag; -} - -export function getPlacingItemId(): number -{ - return itemIdInPlacing; -} - -export function setPlacingItemId(id: number) -{ - itemIdInPlacing = id; -} diff --git a/src/components/inventory/common/PetItem.ts b/src/components/inventory/common/PetItem.ts deleted file mode 100644 index 070b85b4..00000000 --- a/src/components/inventory/common/PetItem.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { PetData } from '@nitrots/nitro-renderer'; - -export class PetItem -{ - private _petData: PetData; - private _selected: boolean; - private _isUnseen: boolean; - - constructor(petData: PetData) - { - this._petData = petData; - this._selected = false; - this._isUnseen = false; - } - - public get id(): number - { - return this._petData.id; - } - - public get petData(): PetData - { - return this._petData; - } - - public get selected(): boolean - { - return this._selected; - } - - public set selected(flag: boolean) - { - this._selected = flag; - } - - public get isUnseen(): boolean - { - return this._isUnseen; - } - - public set isUnseen(flag: boolean) - { - this._isUnseen = flag; - } -} diff --git a/src/components/inventory/common/PetUtilities.ts b/src/components/inventory/common/PetUtilities.ts deleted file mode 100644 index 02f5c096..00000000 --- a/src/components/inventory/common/PetUtilities.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { PetData, RoomObjectCategory, RoomObjectPlacementSource, RoomObjectType } from '@nitrots/nitro-renderer'; -import { GetRoomEngine, GetRoomSessionManager } from '../../../api'; -import { InventoryEvent } from '../../../events'; -import { DispatchUiEvent } from '../../../hooks'; -import { getPlacingItemId, setObjectMoverRequested, setPlacingItemId } from './InventoryUtilities'; -import { PetItem } from './PetItem'; -import { IUnseenItemTracker } from './unseen/IUnseenItemTracker'; -import { UnseenItemCategory } from './unseen/UnseenItemCategory'; - -export function cancelRoomObjectPlacement(): void -{ - if(getPlacingItemId() === -1) return; - - GetRoomEngine().cancelRoomObjectPlacement(); - - setPlacingItemId(-1); - setObjectMoverRequested(false); -} - -export function attemptPetPlacement(petItem: PetItem, flag: boolean = false): boolean -{ - const petData = petItem.petData; - - if(!petData) return false; - - const session = GetRoomSessionManager().getSession(1); - - if(!session) return false; - - if(!session.isRoomOwner) - { - if(!session.allowPets) return false; - } - - DispatchUiEvent(new InventoryEvent(InventoryEvent.HIDE_INVENTORY)); - - if(GetRoomEngine().processRoomObjectPlacement(RoomObjectPlacementSource.INVENTORY, -(petData.id), RoomObjectCategory.UNIT, RoomObjectType.PET, petData.figureData.figuredata)) - { - setPlacingItemId(petData.id); - setObjectMoverRequested(true); - } - - return true; -} - -export function mergePetFragments(fragment: Map, totalFragments: number, fragmentNumber: number, fragments: Map[]) -{ - if(totalFragments === 1) return fragment; - - fragments[fragmentNumber] = fragment; - - for(const frag of fragments) - { - if(!frag) return null; - } - - const merged: Map = new Map(); - - for(const frag of fragments) - { - for(const [ key, value ] of frag) merged.set(key, value); - - frag.clear(); - } - - fragments = null; - - return merged; -} - -function getAllItemIds(petItems: PetItem[]): number[] -{ - const itemIds: number[] = []; - - for(const petItem of petItems) itemIds.push(petItem.id); - - return itemIds; -} - -export function processPetFragment(set: PetItem[], fragment: Map, unseenTracker: IUnseenItemTracker): PetItem[] -{ - const existingIds = getAllItemIds(set); - const addedIds: number[] = []; - const removedIds: number[] = []; - - for(const key of fragment.keys()) (existingIds.indexOf(key) === -1) && addedIds.push(key); - - for(const itemId of existingIds) (!fragment.get(itemId)) && removedIds.push(itemId); - - const emptyExistingSet = (existingIds.length === 0); - - for(const id of removedIds) removePetItemById(id, set); - - for(const id of addedIds) - { - const parser = fragment.get(id); - - if(!parser) continue; - - addSinglePetItem(parser, set, unseenTracker.isUnseen(UnseenItemCategory.PET, parser.id)); - } - - return set; -} - -export function removePetItemById(id: number, set: PetItem[]): PetItem -{ - let index = 0; - - while(index < set.length) - { - const petItem = set[index]; - - if(petItem && (petItem.id === id)) - { - if(getPlacingItemId() === petItem.id) - { - cancelRoomObjectPlacement(); - - setTimeout(() => DispatchUiEvent(new InventoryEvent(InventoryEvent.SHOW_INVENTORY)), 1); - } - - set.splice(index, 1); - - return petItem; - } - - index++; - } - - return null; -} - -export function addSinglePetItem(petData: PetData, set: PetItem[], unseen: boolean = true): PetItem -{ - const petItem = new PetItem(petData); - - if(unseen) - { - petItem.isUnseen = true; - - set.unshift(petItem); - } - else - { - set.push(petItem); - } - - return petItem; -} diff --git a/src/components/inventory/common/unseen/UnseenItemTracker.ts b/src/components/inventory/common/unseen/UnseenItemTracker.ts deleted file mode 100644 index 660d5ba8..00000000 --- a/src/components/inventory/common/unseen/UnseenItemTracker.ts +++ /dev/null @@ -1,146 +0,0 @@ -import { UnseenResetCategoryComposer, UnseenResetItemsComposer } from '@nitrots/nitro-renderer'; -import { SendMessageComposer } from '../../../../api'; -import { UnseenItemTrackerUpdateEvent } from '../../../../events'; -import { DispatchUiEvent } from '../../../../hooks'; -import { IUnseenItemTracker } from './IUnseenItemTracker'; - -export class UnseenItemTracker implements IUnseenItemTracker -{ - private _unseenItems: Map = new Map(); - - public dispose(): void - { - this._unseenItems.clear(); - } - - public resetCategory(category: number): boolean - { - if(!this.getCount(category)) return false; - - this._unseenItems.delete(category); - - this.dispatchUpdateEvent(); - - this.sendResetCategoryMessage(category); - - return true; - } - - public resetItems(category: number, itemIds: number[]): boolean - { - if(!this.getCount(category)) return false; - - const existing = this._unseenItems.get(category); - - for(const itemId of itemIds) - { - existing.splice(existing.indexOf(itemId), 1); - } - - this.dispatchUpdateEvent(); - - this.sendResetItemsMessage(category, itemIds); - - return true; - } - - public resetCategoryIfEmpty(category: number): boolean - { - if(this.getCount(category)) return false; - - this._unseenItems.delete(category); - - this.dispatchUpdateEvent(); - - this.sendResetCategoryMessage(category); - - return true; - } - - public isUnseen(category: number, itemId: number): boolean - { - if(!this._unseenItems.get(category)) return false; - - const items = this._unseenItems.get(category); - - return (items.indexOf(itemId) >= 0); - } - - public removeUnseen(category: number, itemId: number): boolean - { - if(!this._unseenItems.get(category)) return false; - - const items = this._unseenItems.get(category); - const index = items.indexOf(itemId); - - if(index === -1) return false; - - items.splice(index, 1); - - this.dispatchUpdateEvent(); - - return true; - } - - public getIds(category: number): number[] - { - if(!this._unseenItems) return []; - - return this._unseenItems.get(category); - } - - public getCount(category: number): number - { - if(!this._unseenItems.get(category)) return 0; - - return this._unseenItems.get(category).length; - } - - public getFullCount(): number - { - let count = 0; - - for(const key of this._unseenItems.keys()) - { - count += this.getCount(key); - } - - return count; - } - - public addItems(category: number, itemIds: number[]): void - { - if(!itemIds) return; - - let unseenItems = this._unseenItems.get(category); - - if(!unseenItems) - { - unseenItems = []; - - this._unseenItems.set(category, unseenItems); - } - - for(const itemId of itemIds) - { - if(unseenItems.indexOf(itemId) === -1) unseenItems.push(itemId); - } - - this.dispatchUpdateEvent(); - } - - private dispatchUpdateEvent(): void - { - DispatchUiEvent(new UnseenItemTrackerUpdateEvent(this.getFullCount())); - } - - private sendResetCategoryMessage(category: number): void - { - SendMessageComposer(new UnseenResetCategoryComposer(category)); - } - - private sendResetItemsMessage(category: number, itemIds: number[]): void - { - SendMessageComposer(new UnseenResetItemsComposer(category, ...itemIds)); - } -} diff --git a/src/components/inventory/reducers/InventoryBadgeReducer.tsx b/src/components/inventory/reducers/InventoryBadgeReducer.tsx deleted file mode 100644 index 9589baeb..00000000 --- a/src/components/inventory/reducers/InventoryBadgeReducer.tsx +++ /dev/null @@ -1,128 +0,0 @@ -import { SetActivatedBadgesComposer } from '@nitrots/nitro-renderer'; -import { Reducer } from 'react'; -import { GetConfiguration, SendMessageComposer } from '../../../api'; - -export interface IInventoryBadgeState -{ - needsBadgeUpdate: boolean; - badge: string; - badges: string[]; - activeBadges: string[]; -} - -export interface IInventoryBadgeAction -{ - type: string; - payload: { - flag?: boolean; - badgeCode?: string; - badgeCodes?: string[]; - activeBadgeCodes?: string[]; - } -} - -export class InventoryBadgeActions -{ - public static SET_NEEDS_UPDATE: string = 'IBA_SET_NEEDS_UPDATE'; - public static SET_BADGE: string = 'IBA_SET_BADGE'; - public static SET_BADGES: string = 'IBA_SET_BADGES'; - public static ADD_BADGE: string = 'IBA_ADD_BADGE'; - public static ADD_ACTIVE_BADGE: string = 'IBA_ADD_ACTIVE_BADGE'; - public static REMOVE_ACTIVE_BADGE: string = 'IBA_REMOVE_ACTIVE_BADGE'; -} - -export const initialInventoryBadge: IInventoryBadgeState = { - needsBadgeUpdate: true, - badge: null, - badges: [], - activeBadges: [] -} - -export const InventoryBadgeReducer: Reducer = (state, action) => -{ - switch(action.type) - { - case InventoryBadgeActions.SET_NEEDS_UPDATE: - return { ...state, needsBadgeUpdate: (action.payload.flag || false) }; - case InventoryBadgeActions.SET_BADGE: { - let badge = (action.payload.badgeCode || state.badge || null); - - let index = 0; - - if(badge) - { - const foundIndex = state.badges.indexOf(badge); - - if(foundIndex > -1) index = foundIndex; - } - - badge = (state.badges[index] || null); - - return { ...state, badge }; - } - case InventoryBadgeActions.SET_BADGES: { - const badges: string[] = []; - const activeBadges: string[] = []; - - const badgeCodes = action.payload.badgeCodes; - const activeBadgeCodes = action.payload.activeBadgeCodes; - - for(const badgeCode of badgeCodes) - { - const wearingIndex = activeBadgeCodes.indexOf(badgeCode); - - badges.push(badgeCode); - - if(wearingIndex >= 0) activeBadges.push(badgeCode); - } - - return { ...state, badges, activeBadges }; - } - case InventoryBadgeActions.ADD_BADGE: { - const badges = [ ...state.badges ]; - const badge = (action.payload.badgeCode); - - if(badges.indexOf(badge) === -1) badges.push(badge); - - return { ...state, badges }; - } - case InventoryBadgeActions.ADD_ACTIVE_BADGE: { - const badgeCode = action.payload.badgeCode; - - if(state.activeBadges.indexOf(badgeCode) >= 0) return state; - - const activeBadges = [ ...state.activeBadges ]; - - activeBadges.push(badgeCode); - - const composer = new SetActivatedBadgesComposer(); - - for(let i = 0; i < GetConfiguration('user.badges.max.slots', 5); i++) composer.addActivatedBadge(activeBadges[i] || null); - - SendMessageComposer(composer); - - return { ...state, activeBadges }; - } - case InventoryBadgeActions.REMOVE_ACTIVE_BADGE: { - const badgeCode = action.payload.badgeCode; - - const index = state.activeBadges.indexOf(badgeCode); - - if(index === -1) return state; - - const activeBadges = [ ...state.activeBadges ]; - - activeBadges.splice(index, 1); - - const composer = new SetActivatedBadgesComposer(); - - for(let i = 0; i < GetConfiguration('user.badges.max.slots', 5); i++) composer.addActivatedBadge(activeBadges[i] || null); - - SendMessageComposer(composer); - - return { ...state, activeBadges }; - } - default: - return state; - } -} diff --git a/src/components/inventory/reducers/InventoryBotReducer.tsx b/src/components/inventory/reducers/InventoryBotReducer.tsx deleted file mode 100644 index b94eea81..00000000 --- a/src/components/inventory/reducers/InventoryBotReducer.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import { BotData } from '@nitrots/nitro-renderer'; -import { Reducer } from 'react'; -import { BotItem } from '../common/BotItem'; -import { addSingleBotItem, processBotFragment, removeBotItemById } from '../common/BotUtilities'; -import { IUnseenItemTracker } from '../common/unseen/IUnseenItemTracker'; - -export interface IInventoryBotState -{ - needsBotUpdate: boolean; - botItem: BotItem; - botItems: BotItem[]; -} - -export interface IInventoryBotAction -{ - type: string; - payload: { - flag?: boolean; - botItem?: BotItem; - botId?: number; - botData?: BotData; - fragment?: BotData[]; - unseenTracker?: IUnseenItemTracker; - } -} - -export class InventoryBotActions -{ - public static SET_NEEDS_UPDATE: string = 'IBA_SET_NEEDS_UPDATE'; - public static SET_BOT_ITEM: string = 'IBA_SET_BOT_ITEM'; - public static PROCESS_FRAGMENT: string = 'IBA_PROCESS_FRAGMENT'; - public static ADD_BOT: string = 'IBA_ADD_BOT'; - public static REMOVE_BOT: string = 'IBA_REMOVE_BOT'; -} - -export const initialInventoryBot: IInventoryBotState = { - needsBotUpdate: true, - botItem: null, - botItems: [] -} - -export const InventoryBotReducer: Reducer = (state, action) => -{ - switch(action.type) - { - case InventoryBotActions.SET_NEEDS_UPDATE: - return { ...state, needsBotUpdate: (action.payload.flag || false) }; - case InventoryBotActions.SET_BOT_ITEM: { - let botItem = (action.payload.botItem || state.botItem || null); - - let index = 0; - - if(botItem) - { - const foundIndex = state.botItems.indexOf(botItem); - - if(foundIndex > -1) index = foundIndex; - } - - botItem = (state.botItems[index] || null); - - return { ...state, botItem }; - } - case InventoryBotActions.PROCESS_FRAGMENT: { - const botItems = [ ...state.botItems ]; - - processBotFragment(botItems, action.payload.fragment, (action.payload.unseenTracker || null)); - - return { ...state, botItems }; - } - case InventoryBotActions.ADD_BOT: { - const botItems = [ ...state.botItems ]; - - addSingleBotItem(action.payload.botData, botItems, true); - - return { ...state, botItems }; - } - case InventoryBotActions.REMOVE_BOT: { - const botItems = [ ...state.botItems ]; - - removeBotItemById(action.payload.botId, botItems); - - return { ...state, botItems }; - } - default: - return state; - } -} diff --git a/src/components/inventory/reducers/InventoryFurnitureReducer.tsx b/src/components/inventory/reducers/InventoryFurnitureReducer.tsx deleted file mode 100644 index 20d991f2..00000000 --- a/src/components/inventory/reducers/InventoryFurnitureReducer.tsx +++ /dev/null @@ -1,273 +0,0 @@ -import { AdvancedMap, FurnitureListItemParser, TradingListItemParser } from '@nitrots/nitro-renderer'; -import { Reducer } from 'react'; -import { FurnitureItem } from '../common/FurnitureItem'; -import { addFurnitureItem, processFurniFragment, removeFurniItemById } from '../common/FurnitureUtilities'; -import { GroupItem } from '../common/GroupItem'; -import { TradeState } from '../common/TradeState'; -import { TradeUserData } from '../common/TradeUserData'; -import { parseTradeItems } from '../common/TradingUtilities'; -import { IUnseenItemTracker } from '../common/unseen/IUnseenItemTracker'; - -export interface IInventoryFurnitureState -{ - needsFurniUpdate: boolean; - groupItem: GroupItem; - groupItems: GroupItem[]; - tradeData: { - ownUser: TradeUserData; - otherUser: TradeUserData; - state: number; - } -} - -export interface IInventoryFurnitureAction -{ - type: string; - payload: { - flag?: boolean; - groupItem?: GroupItem; - parsers?: FurnitureListItemParser[]; - itemId?: number; - fragment?: Map; - ownTradeUser?: TradeUserData; - otherTradeUser?: TradeUserData; - tradeState?: number; - userId?: number; - tradeParser?: TradingListItemParser; - unseenTracker?: IUnseenItemTracker; - } -} - -export class InventoryFurnitureActions -{ - public static SET_NEEDS_UPDATE: string = 'IFA_SET_NEEDS_UPDATE'; - public static SET_GROUP_ITEM: string = 'IFA_SET_GROUP_ITEM'; - public static PROCESS_FRAGMENT: string = 'IFA_PROCESS_FRAGMENT'; - public static ADD_OR_UPDATE_FURNITURE: string = 'IFA_ADD_OR_UPDATE_FURNITURE'; - public static REMOVE_FURNITURE: string = 'IFA_REMOVE_FURNITURE'; - public static SET_TRADE_DATA: string = 'IFA_SET_TRADE_DATA'; - public static SET_TRADE_STATE: string = 'IFA_SET_TRADE_STATE'; - public static SET_TRADE_ACCEPTANCE: string = 'FA_SET_TRADE_ACCEPTANCE'; - public static CLOSE_TRADE: string = 'IFA_CLOSE_STRING'; - public static UPDATE_TRADE: string = 'IFA_UPDATE_TRADE'; -} - -export const initialInventoryFurniture: IInventoryFurnitureState = { - needsFurniUpdate: true, - groupItem: null, - groupItems: [], - tradeData: null -} - -export const InventoryFurnitureReducer: Reducer = (state, action) => -{ - switch(action.type) - { - case InventoryFurnitureActions.SET_NEEDS_UPDATE: - return { ...state, needsFurniUpdate: (action.payload.flag || false) }; - case InventoryFurnitureActions.SET_GROUP_ITEM: { - let groupItem = (action.payload.groupItem || state.groupItem || null); - - let index = 0; - - if(groupItem) - { - const foundIndex = state.groupItems.indexOf(groupItem); - - if(foundIndex > -1) index = foundIndex; - } - - groupItem = (state.groupItems[index] || null); - - return { ...state, groupItem }; - } - case InventoryFurnitureActions.PROCESS_FRAGMENT: { - const groupItems = [ ...state.groupItems ]; - - processFurniFragment(groupItems, (action.payload.fragment || null), (action.payload.unseenTracker || null)); - - return { ...state, groupItems }; - } - case InventoryFurnitureActions.ADD_OR_UPDATE_FURNITURE: { - const groupItems = [ ...state.groupItems ]; - - for(const item of action.payload.parsers) - { - let i = 0; - let groupItem: GroupItem = null; - - while(i < groupItems.length) - { - const group = groupItems[i]; - - let j = 0; - - while(j < group.items.length) - { - const furniture = group.items[j]; - - if(furniture.id === item.itemId) - { - furniture.update(item); - - const newFurniture = [ ...group.items ]; - - newFurniture[j] = furniture; - - group.items = newFurniture; - - groupItem = group; - - break; - } - - j++ - } - - if(groupItem) break; - - i++; - } - - if(groupItem) - { - groupItem.hasUnseenItems = true; - - groupItems[i] = Object.create(groupItem); - } - else - { - const furniture = new FurnitureItem(item); - - addFurnitureItem(groupItems, furniture, true); - } - } - - return { ...state, groupItems }; - } - case InventoryFurnitureActions.REMOVE_FURNITURE: { - const groupItems = [ ...state.groupItems ]; - - removeFurniItemById(action.payload.itemId, groupItems); - - return { ...state, groupItems }; - } - case InventoryFurnitureActions.SET_TRADE_DATA: { - const tradeData = { ...state.tradeData }; - - tradeData.ownUser = (action.payload.ownTradeUser || null); - tradeData.otherUser = (action.payload.otherTradeUser || null); - tradeData.state = TradeState.TRADING_STATE_RUNNING; - - return { ...state, tradeData }; - } - case InventoryFurnitureActions.SET_TRADE_STATE: { - const tradeData = { ...state.tradeData }; - - tradeData.state = (action.payload.tradeState || TradeState.TRADING_STATE_RUNNING); - - return { ...state, tradeData }; - } - case InventoryFurnitureActions.SET_TRADE_ACCEPTANCE: { - const tradeData = { ...state.tradeData }; - - const userId = (action.payload.userId || -1); - - if(tradeData.ownUser.userId === userId) - { - const ownUserData = Object.assign({}, tradeData.ownUser); - - ownUserData.accepts = (action.payload.flag || false); - - tradeData.ownUser = ownUserData; - } - - else if(tradeData.otherUser.userId === userId) - { - const otherUserData = Object.assign({}, tradeData.otherUser); - - otherUserData.accepts = (action.payload.flag || false); - - tradeData.otherUser = otherUserData; - } - - return { ...state, tradeData }; - } - case InventoryFurnitureActions.CLOSE_TRADE: { - const tradeData = null; - - return { ...state, tradeData }; - } - case InventoryFurnitureActions.UPDATE_TRADE: { - const tradeData = { ...state.tradeData }; - const groupItems = [ ...state.groupItems ]; - - const parser = (action.payload.tradeParser || null); - - if(parser) - { - const firstUserItems: AdvancedMap = new AdvancedMap(); - const secondUserItems: AdvancedMap = new AdvancedMap(); - - parseTradeItems(parser.firstUserItemArray, firstUserItems); - parseTradeItems(parser.secondUserItemArray, secondUserItems); - - const ownUserData = Object.assign({}, tradeData.ownUser); - const otherUserData = Object.assign({}, tradeData.otherUser); - - if(tradeData.ownUser.userId === parser.firstUserID) - { - ownUserData.creditsCount = parser.firstUserNumCredits; - ownUserData.itemCount = parser.firstUserNumItems; - ownUserData.items = firstUserItems; - } - - else if(tradeData.ownUser.userId === parser.secondUserID) - { - ownUserData.creditsCount = parser.secondUserNumCredits; - ownUserData.itemCount = parser.secondUserNumItems; - ownUserData.items = secondUserItems; - } - - if(tradeData.otherUser.userId === parser.firstUserID) - { - otherUserData.creditsCount = parser.firstUserNumCredits; - otherUserData.itemCount = parser.firstUserNumItems; - otherUserData.items = firstUserItems; - } - - else if(tradeData.otherUser.userId === parser.secondUserID) - { - otherUserData.creditsCount = parser.secondUserNumCredits; - otherUserData.itemCount = parser.secondUserNumItems; - otherUserData.items = secondUserItems; - } - - tradeData.ownUser = ownUserData; - tradeData.otherUser = otherUserData; - - const tradeIds: number[] = []; - - for(const groupItem of ownUserData.items.getValues()) - { - let i = 0; - - while(i < groupItem.getTotalCount()) - { - const item = groupItem.getItemByIndex(i); - - if(item) tradeIds.push(item.ref); - - i++; - } - } - - for(const groupItem of groupItems) groupItem.lockItemIds(tradeIds); - } - - return { ...state, groupItems, tradeData }; - } - default: - return state; - } -} diff --git a/src/components/inventory/reducers/InventoryPetReducer.tsx b/src/components/inventory/reducers/InventoryPetReducer.tsx deleted file mode 100644 index 14679510..00000000 --- a/src/components/inventory/reducers/InventoryPetReducer.tsx +++ /dev/null @@ -1,88 +0,0 @@ -import { PetData } from '@nitrots/nitro-renderer'; -import { Reducer } from 'react'; -import { PetItem } from '../common/PetItem'; -import { addSinglePetItem, processPetFragment, removePetItemById } from '../common/PetUtilities'; -import { IUnseenItemTracker } from '../common/unseen/IUnseenItemTracker'; - -export interface IInventoryPetState -{ - needsPetUpdate: boolean; - petItem: PetItem; - petItems: PetItem[]; -} - -export interface IInventoryPetAction -{ - type: string; - payload: { - flag?: boolean; - petItem?: PetItem; - petId?: number; - petData?: PetData; - fragment?: Map; - unseenTracker?: IUnseenItemTracker; - } -} - -export class InventoryPetActions -{ - public static SET_NEEDS_UPDATE: string = 'IPA_SET_NEEDS_UPDATE'; - public static SET_PET_ITEM: string = 'IPA_SET_PET_ITEM'; - public static PROCESS_FRAGMENT: string = 'IPA_PROCESS_FRAGMENT'; - public static ADD_PET: string = 'IPA_ADD_PET'; - public static REMOVE_PET: string = 'IPA_REMOVE_PET'; -} - -export const initialInventoryPet: IInventoryPetState = { - needsPetUpdate: true, - petItem: null, - petItems: [] -} - -export const InventoryPetReducer: Reducer = (state, action) => -{ - switch(action.type) - { - case InventoryPetActions.SET_NEEDS_UPDATE: - return { ...state, needsPetUpdate: (action.payload.flag || false) }; - case InventoryPetActions.SET_PET_ITEM: { - let petItem = (action.payload.petItem || state.petItem || null); - - let index = 0; - - if(petItem) - { - const foundIndex = state.petItems.indexOf(petItem); - - if(foundIndex > -1) index = foundIndex; - } - - petItem = (state.petItems[index] || null); - - return { ...state, petItem }; - } - case InventoryPetActions.PROCESS_FRAGMENT: { - const petItems = [ ...state.petItems ]; - - processPetFragment(petItems, (action.payload.fragment || null), (action.payload.unseenTracker || null)); - - return { ...state, petItems }; - } - case InventoryPetActions.ADD_PET: { - const petItems = [ ...state.petItems ]; - - addSinglePetItem(action.payload.petData, petItems, true); - - return { ...state, petItems }; - } - case InventoryPetActions.REMOVE_PET: { - const petItems = [ ...state.petItems ]; - - removePetItemById(action.payload.petId, petItems); - - return { ...state, petItems }; - } - default: - return state; - } -} diff --git a/src/components/inventory/views/InventoryBadgeView.tsx b/src/components/inventory/views/InventoryBadgeView.tsx new file mode 100644 index 00000000..a5ba05f1 --- /dev/null +++ b/src/components/inventory/views/InventoryBadgeView.tsx @@ -0,0 +1,75 @@ +import { FC, useEffect } from 'react'; +import { IBadgeItem, LocalizeBadgeName, LocalizeText, UnseenItemCategory } from '../../../api'; +import { AutoGrid, Button, Column, Flex, Grid, LayoutBadgeImageView, LayoutGridItem, Text } from '../../../common'; +import { useSharedInventoryBadges, useSharedInventoryUnseenTracker } from '../../../hooks'; + +export const InventoryBadgeView: FC<{}> = props => +{ + const { badges = [], activeBadges = [], selectedBadge = null, isWearingBadge = null, canWearBadges = null, toggleBadge = null, selectBadge = null } = useSharedInventoryBadges(); + const { getCount = null, resetCategory = null, isUnseen = null, removeUnseen = null } = useSharedInventoryUnseenTracker(); + + useEffect(() => + { + if(!badges || !badges.length) return; + + return () => + { + const count = getCount(UnseenItemCategory.BADGE); + + if(!count) return; + + resetCategory(UnseenItemCategory.BADGE); + } + }, [ badges, getCount, resetCategory ]); + + const InventoryBadgeItemView: FC<{ badge: IBadgeItem }> = props => + { + const { badge = null, children = null, ...rest } = props; + const unseen = isUnseen(UnseenItemCategory.BADGE, badge.id); + + const select = () => + { + selectBadge(badge); + + if(unseen) removeUnseen(UnseenItemCategory.BADGE, badge.id); + } + + return ( + + + { children } + + ); + } + + return ( + + + + { badges && (badges.length > 0) && badges.map((badge, index) => + { + if(activeBadges.indexOf(badge) >= 0) return null; + + return + }) } + + + + + { LocalizeText('inventory.badges.activebadges') } + + { activeBadges && (activeBadges.length > 0) && activeBadges.map((badge, index) => ) } + + + { !!selectedBadge && + + + + { LocalizeBadgeName(selectedBadge.badgeCode) } + + + } + + + ); +} diff --git a/src/components/inventory/views/InventoryBotView.tsx b/src/components/inventory/views/InventoryBotView.tsx new file mode 100644 index 00000000..7d3905fb --- /dev/null +++ b/src/components/inventory/views/InventoryBotView.tsx @@ -0,0 +1,116 @@ +import { IRoomSession, MouseEventType, RoomObjectVariable, RoomPreviewer } from '@nitrots/nitro-renderer'; +import { FC, MouseEvent, useEffect, useState } from 'react'; +import { attemptBotPlacement, GetRoomEngine, IBotItem, LocalizeText, UnseenItemCategory } from '../../../api'; +import { AutoGrid, Button, Column, Grid, LayoutAvatarImageView, LayoutGridItem, LayoutRoomPreviewerView, Text } from '../../../common'; +import { useSharedInventoryBots, useSharedInventoryUnseenTracker } from '../../../hooks'; +import { InventoryCategoryEmptyView } from './InventoryCategoryEmptyView'; + +interface InventoryBotViewProps +{ + roomSession: IRoomSession; + roomPreviewer: RoomPreviewer; +} + +export const InventoryBotView: FC = props => +{ + const { roomSession = null, roomPreviewer = null } = props; + const { botItems = [], selectedBot = null, selectBot = null } = useSharedInventoryBots(); + const { getCount = null, resetCategory = null, isUnseen = null, removeUnseen = null } = useSharedInventoryUnseenTracker(); + + useEffect(() => + { + if(!botItems || !botItems.length) return; + + return () => + { + const count = getCount(UnseenItemCategory.BOT); + + if(!count) return; + + resetCategory(UnseenItemCategory.BOT); + } + }, [ botItems, getCount, resetCategory ]); + + useEffect(() => + { + if(!selectedBot || !roomPreviewer) return; + + const botData = selectedBot.botData; + + const roomEngine = GetRoomEngine(); + + let wallType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_WALL_TYPE); + let floorType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_FLOOR_TYPE); + let landscapeType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_LANDSCAPE_TYPE); + + wallType = (wallType && wallType.length) ? wallType : '101'; + floorType = (floorType && floorType.length) ? floorType : '101'; + landscapeType = (landscapeType && landscapeType.length) ? landscapeType : '1.1'; + + roomPreviewer.reset(false); + roomPreviewer.updateRoomWallsAndFloorVisibility(true, true); + roomPreviewer.updateObjectRoom(floorType, wallType, landscapeType); + roomPreviewer.addAvatarIntoRoom(botData.figure, 0); + }, [ roomPreviewer, selectedBot ]); + + if(!botItems || !botItems.length) return ; + + const InventoryBotItemView: FC<{ botItem: IBotItem }> = props => + { + const { botItem = null } = props; + const [ isMouseDown, setMouseDown ] = useState(false); + const isActive = (botItem === selectedBot); + const unseen = isUnseen(UnseenItemCategory.BOT, botItem.botData.id); + + const onMouseEvent = (event: MouseEvent) => + { + switch(event.type) + { + case MouseEventType.MOUSE_DOWN: + selectBot(botItem); + + if(unseen) removeUnseen(UnseenItemCategory.BOT, botItem.botData.id); + + setMouseDown(true); + return; + case MouseEventType.MOUSE_UP: + setMouseDown(false); + return; + case MouseEventType.ROLL_OUT: + if(!isMouseDown || !isActive) return; + + attemptBotPlacement(botItem); + return; + } + } + + return ( + + + + ); + } + + return ( + + + + { botItems && (botItems.length > 0) && botItems.map(item => ) } + + + + + + + { selectedBot && + + { selectedBot.botData.name } + { !!roomSession && + } + } + + + ); +} diff --git a/src/components/inventory/views/category-empty/InventoryCategoryEmptyView.tsx b/src/components/inventory/views/InventoryCategoryEmptyView.tsx similarity index 82% rename from src/components/inventory/views/category-empty/InventoryCategoryEmptyView.tsx rename to src/components/inventory/views/InventoryCategoryEmptyView.tsx index 8460d97e..635aca1a 100644 --- a/src/components/inventory/views/category-empty/InventoryCategoryEmptyView.tsx +++ b/src/components/inventory/views/InventoryCategoryEmptyView.tsx @@ -1,7 +1,5 @@ import { FC } from 'react'; -import { Column } from '../../../../common/Column'; -import { Grid, GridProps } from '../../../../common/Grid'; -import { Text } from '../../../../common/Text'; +import { Column, Grid, GridProps, Text } from '../../../common'; export interface InventoryCategoryEmptyViewProps extends GridProps { diff --git a/src/components/inventory/views/furniture/InventoryFurnitureSearchView.tsx b/src/components/inventory/views/InventoryFurnitureSearchView.tsx similarity index 88% rename from src/components/inventory/views/furniture/InventoryFurnitureSearchView.tsx rename to src/components/inventory/views/InventoryFurnitureSearchView.tsx index 11705f0e..b36e4b9e 100644 --- a/src/components/inventory/views/furniture/InventoryFurnitureSearchView.tsx +++ b/src/components/inventory/views/InventoryFurnitureSearchView.tsx @@ -1,9 +1,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'; -import { LocalizeText } from '../../../../api'; -import { Button } from '../../../../common/Button'; -import { Flex } from '../../../../common/Flex'; -import { GroupItem } from '../../common/GroupItem'; +import { GroupItem, LocalizeText } from '../../../api'; +import { Button, Flex } from '../../../common'; export interface InventoryFurnitureSearchViewProps { diff --git a/src/components/inventory/views/InventoryFurnitureView.tsx b/src/components/inventory/views/InventoryFurnitureView.tsx new file mode 100644 index 00000000..d6c1a689 --- /dev/null +++ b/src/components/inventory/views/InventoryFurnitureView.tsx @@ -0,0 +1,161 @@ +import { IRoomSession, MouseEventType, RoomObjectVariable, RoomPreviewer, Vector3d } from '@nitrots/nitro-renderer'; +import { FC, MouseEvent, useEffect, useState } from 'react'; +import { attemptItemPlacement, FurniCategory, GetRoomEngine, GetSessionDataManager, GroupItem, LocalizeText, UnseenItemCategory } from '../../../api'; +import { AutoGrid, Button, Column, Grid, LayoutGridItem, LayoutLimitedEditionCompactPlateView, LayoutRarityLevelView, LayoutRoomPreviewerView, Text } from '../../../common'; +import { useSharedInventoryFurni, useSharedInventoryUnseenTracker } from '../../../hooks'; +import { attemptPlaceMarketplaceOffer } from '../../../hooks/inventory/common'; +import { InventoryCategoryEmptyView } from './InventoryCategoryEmptyView'; +import { InventoryFurnitureSearchView } from './InventoryFurnitureSearchView'; + +interface InventoryFurnitureViewProps +{ + roomSession: IRoomSession; + roomPreviewer: RoomPreviewer; +} + +export const InventoryFurnitureView: FC = props => +{ + const { roomSession = null, roomPreviewer = null } = props; + const { groupItems = [], selectedItem = null, selectItem = null } = useSharedInventoryFurni(); + const [ filteredGroupItems, setFilteredGroupItems ] = useState(groupItems); + const { getCount = null, resetCategory = null } = useSharedInventoryUnseenTracker(); + + useEffect(() => + { + if(!selectedItem || !roomPreviewer) return; + + const furnitureItem = selectedItem.getLastItem(); + + if(!furnitureItem) return; + + const roomEngine = GetRoomEngine(); + + let wallType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_WALL_TYPE); + let floorType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_FLOOR_TYPE); + let landscapeType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_LANDSCAPE_TYPE); + + wallType = (wallType && wallType.length) ? wallType : '101'; + floorType = (floorType && floorType.length) ? floorType : '101'; + landscapeType = (landscapeType && landscapeType.length) ? landscapeType : '1.1'; + + roomPreviewer.reset(false); + roomPreviewer.updateObjectRoom(floorType, wallType, landscapeType); + roomPreviewer.updateRoomWallsAndFloorVisibility(true, true); + + if((furnitureItem.category === FurniCategory.WALL_PAPER) || (furnitureItem.category === FurniCategory.FLOOR) || (furnitureItem.category === FurniCategory.LANDSCAPE)) + { + floorType = ((furnitureItem.category === FurniCategory.FLOOR) ? selectedItem.stuffData.getLegacyString() : floorType); + wallType = ((furnitureItem.category === FurniCategory.WALL_PAPER) ? selectedItem.stuffData.getLegacyString() : wallType); + landscapeType = ((furnitureItem.category === FurniCategory.LANDSCAPE) ? selectedItem.stuffData.getLegacyString() : landscapeType); + + roomPreviewer.updateObjectRoom(floorType, wallType, landscapeType); + + if(furnitureItem.category === FurniCategory.LANDSCAPE) + { + const data = GetSessionDataManager().getWallItemDataByName('noob_window_double'); + + if(data) roomPreviewer.addWallItemIntoRoom(data.id, new Vector3d(90, 0, 0), data.customParams); + } + } + else + { + if(selectedItem.isWallItem) + { + roomPreviewer.addWallItemIntoRoom(selectedItem.type, new Vector3d(90), furnitureItem.stuffData.getLegacyString()); + } + else + { + roomPreviewer.addFurnitureIntoRoom(selectedItem.type, new Vector3d(90), selectedItem.stuffData, (furnitureItem.extra.toString())); + } + } + }, [ roomPreviewer, selectedItem ]); + + useEffect(() => + { + if(!groupItems || !groupItems.length) return; + + return () => + { + const count = getCount(UnseenItemCategory.FURNI); + + if(!count) return; + + resetCategory(UnseenItemCategory.FURNI); + + for(const groupItem of groupItems) groupItem.hasUnseenItems = false; + } + }, [ groupItems, getCount, resetCategory ]); + + if(!groupItems || !groupItems.length) return ; + + const InventoryFurnitureItemView: FC<{ groupItem: GroupItem }> = props => + { + const { groupItem = null } = props; + const [ isMouseDown, setMouseDown ] = useState(false); + const isActive = (groupItem === selectedItem); + + const onMouseEvent = (event: MouseEvent) => + { + switch(event.type) + { + case MouseEventType.MOUSE_DOWN: + selectItem(groupItem); + setMouseDown(true); + return; + case MouseEventType.MOUSE_UP: + setMouseDown(false); + return; + case MouseEventType.ROLL_OUT: + if(!isMouseDown || !isActive) return; + + attemptItemPlacement(groupItem); + return; + } + } + + useEffect(() => + { + if(!isActive) return; + + groupItem.hasUnseenItems = false; + }, [ isActive, groupItem ]); + + const count = groupItem.getUnlockedCount(); + + return ; + } + + return ( + + + + + { filteredGroupItems && (filteredGroupItems.length > 0) && filteredGroupItems.map((item, index) => ) } + + + + + + { selectedItem && selectedItem.stuffData.isUnique && + } + { (selectedItem && selectedItem.stuffData.rarityLevel > -1) && + } + + { selectedItem && + + { selectedItem.name } + + { !!roomSession && + } + { (selectedItem && selectedItem.isSellable) && + } + + } + + + ); +} diff --git a/src/components/inventory/views/InventoryPetView.tsx b/src/components/inventory/views/InventoryPetView.tsx new file mode 100644 index 00000000..7bd264d1 --- /dev/null +++ b/src/components/inventory/views/InventoryPetView.tsx @@ -0,0 +1,115 @@ +import { IRoomSession, MouseEventType, RoomObjectVariable, RoomPreviewer } from '@nitrots/nitro-renderer'; +import { FC, MouseEvent, useEffect, useState } from 'react'; +import { attemptPetPlacement, GetRoomEngine, IPetItem, LocalizeText, UnseenItemCategory } from '../../../api'; +import { AutoGrid, Button, Column, Grid, LayoutGridItem, LayoutPetImageView, LayoutRoomPreviewerView, Text } from '../../../common'; +import { useSharedInventoryPets, useSharedInventoryUnseenTracker } from '../../../hooks'; +import { InventoryCategoryEmptyView } from './InventoryCategoryEmptyView'; + +interface InventoryPetViewProps +{ + roomSession: IRoomSession; + roomPreviewer: RoomPreviewer; +} + +export const InventoryPetView: FC = props => +{ + const { roomSession = null, roomPreviewer = null } = props; + const { petItems = null, selectedPet = null, selectPet = null } = useSharedInventoryPets(); + const { getCount = null, resetCategory = null, isUnseen = null, removeUnseen = null } = useSharedInventoryUnseenTracker(); + + useEffect(() => + { + if(!petItems || !petItems.length) return; + + return () => + { + const count = getCount(UnseenItemCategory.PET); + + if(!count) return; + + resetCategory(UnseenItemCategory.PET); + } + }, [ petItems, getCount, resetCategory ]); + + useEffect(() => + { + if(!selectedPet || !roomPreviewer) return; + + const petData = selectedPet.petData; + const roomEngine = GetRoomEngine(); + + let wallType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_WALL_TYPE); + let floorType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_FLOOR_TYPE); + let landscapeType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_LANDSCAPE_TYPE); + + wallType = (wallType && wallType.length) ? wallType : '101'; + floorType = (floorType && floorType.length) ? floorType : '101'; + landscapeType = (landscapeType && landscapeType.length) ? landscapeType : '1.1'; + + roomPreviewer.reset(false); + roomPreviewer.updateRoomWallsAndFloorVisibility(true, true); + roomPreviewer.updateObjectRoom(floorType, wallType, landscapeType); + roomPreviewer.addPetIntoRoom(petData.figureString); + }, [ roomPreviewer, selectedPet ]); + + if(!petItems || !petItems.length) return ; + + const InventoryPetItemView: FC<{ petItem: IPetItem }> = props => + { + const { petItem = null } = props; + const [ isMouseDown, setMouseDown ] = useState(false); + const isActive = (petItem === selectedPet); + const unseen = isUnseen(UnseenItemCategory.PET, petItem.petData.id); + + const onMouseEvent = (event: MouseEvent) => + { + switch(event.type) + { + case MouseEventType.MOUSE_DOWN: + selectPet(petItem); + + if(unseen) removeUnseen(UnseenItemCategory.PET, petItem.petData.id); + + setMouseDown(true); + return; + case MouseEventType.MOUSE_UP: + setMouseDown(false); + return; + case MouseEventType.ROLL_OUT: + if(!isMouseDown || !isActive) return; + + attemptPetPlacement(petItem); + return; + } + } + + return ( + + + + ); + } + + return ( + + + + { petItems && (petItems.length > 0) && petItems.map(item => ) } + + + + + + + { selectedPet && selectedPet.petData && + + { selectedPet.petData.name } + { !!roomSession && + } + } + + + ); +} diff --git a/src/components/inventory/views/trade/InventoryTradeView.tsx b/src/components/inventory/views/InventoryTradeView.tsx similarity index 64% rename from src/components/inventory/views/trade/InventoryTradeView.tsx rename to src/components/inventory/views/InventoryTradeView.tsx index 1b52dfd1..a36e0731 100644 --- a/src/components/inventory/views/trade/InventoryTradeView.tsx +++ b/src/components/inventory/views/InventoryTradeView.tsx @@ -1,18 +1,13 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { FurnitureListComposer, IObjectData, TradingAcceptComposer, TradingConfirmationComposer, TradingListAddItemComposer, TradingListAddItemsComposer, TradingListItemRemoveComposer, TradingUnacceptComposer } from '@nitrots/nitro-renderer'; +import { IObjectData, TradingListAddItemComposer, TradingListAddItemsComposer } from '@nitrots/nitro-renderer'; import { FC, useEffect, useState } from 'react'; -import { LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer } from '../../../../api'; -import { AutoGrid, Base, Button, Column, Flex, Grid, LayoutGridItem, Text } from '../../../../common'; -import { FurniCategory } from '../../common/FurniCategory'; -import { GroupItem } from '../../common/GroupItem'; -import { IFurnitureItem } from '../../common/IFurnitureItem'; -import { TradeState } from '../../common/TradeState'; -import { _Str_16998 } from '../../common/TradingUtilities'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryFurnitureActions } from '../../reducers/InventoryFurnitureReducer'; -import { InventoryFurnitureSearchView } from '../furniture/InventoryFurnitureSearchView'; +import { FurniCategory, GroupItem, IFurnitureItem, LocalizeText, NotificationAlertType, NotificationUtilities, SendMessageComposer, TradeState } from '../../../api'; +import { AutoGrid, Base, Button, Column, Flex, Grid, LayoutGridItem, Text } from '../../../common'; +import { useSharedInventoryTrade } from '../../../hooks'; +import { getGuildFurniType } from '../../../hooks/inventory/common/TradingUtilities'; +import { InventoryFurnitureSearchView } from './InventoryFurnitureSearchView'; -export interface InventoryTradeViewProps +interface InventoryTradeViewProps { cancelTrade: () => void; } @@ -27,14 +22,13 @@ export const InventoryTradeView: FC = props => const [ otherGroupItem, setOtherGroupItem ] = useState(null); const [ filteredGroupItems, setFilteredGroupItems ] = useState(null); const [ countdownTick, setCountdownTick ] = useState(3); - const { furnitureState = null, dispatchFurnitureState = null } = useInventoryContext(); - const { needsFurniUpdate = false, groupItems = [], tradeData = null } = furnitureState; + const { ownUser = null, otherUser = null, groupItems = [], tradeState = TradeState.TRADING_STATE_READY, progressTrade = null, removeItem = null, setTradeState = null } = useSharedInventoryTrade(); const canTradeItem = (isWallItem: boolean, spriteId: number, category: number, groupable: boolean, stuffData: IObjectData) => { - if(!tradeData || !tradeData.ownUser || tradeData.ownUser.accepts || !tradeData.ownUser.items) return false; + if(!ownUser || ownUser.accepts || !ownUser.items) return false; - if(tradeData.ownUser.items.length < MAX_ITEMS_TO_TRADE) return true; + if(ownUser.items.length < MAX_ITEMS_TO_TRADE) return true; if(!groupable) return false; @@ -48,7 +42,7 @@ export const InventoryTradeView: FC = props => { if(category === FurniCategory.GUILD_FURNI) { - type = _Str_16998(spriteId, stuffData); + type = getGuildFurniType(spriteId, stuffData); } else { @@ -56,12 +50,12 @@ export const InventoryTradeView: FC = props => } } - return !!tradeData.ownUser.items.getValue(type); + return !!ownUser.items.getValue(type); } const attemptItemOffer = (count: number) => { - if(!tradeData || !groupItem) return; + if(!groupItem) return; const tradeItems = groupItem.getTradeItems(count); @@ -77,7 +71,7 @@ export const InventoryTradeView: FC = props => if(!coreItem) coreItem = item; } - const ownItemCount = tradeData.ownUser.items.length; + const ownItemCount = ownUser.items.length; if((ownItemCount + itemIds.length) <= 1500) { @@ -116,74 +110,17 @@ export const InventoryTradeView: FC = props => } } - const removeItem = (group: GroupItem) => - { - const item = group.getLastItem(); - - if(!item) return; - - SendMessageComposer(new TradingListItemRemoveComposer(item.id)); - } - - const progressTrade = () => - { - switch(tradeData.state) - { - case TradeState.TRADING_STATE_RUNNING: - if(!tradeData.otherUser.itemCount && !tradeData.ownUser.accepts) - { - NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.other_not_offering'), null, null, null); - } - - if(tradeData.ownUser.accepts) - { - SendMessageComposer(new TradingUnacceptComposer()); - } - else - { - SendMessageComposer(new TradingAcceptComposer()); - } - return; - case TradeState.TRADING_STATE_CONFIRMING: - SendMessageComposer(new TradingConfirmationComposer()); - - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_TRADE_STATE, - payload: { - tradeState: TradeState.TRADING_STATE_CONFIRMED - } - }); - return; - } - } - const getLockIcon = (accepts: boolean) => { const iconName = accepts ? 'lock' : 'unlock'; const textColor = accepts ? 'success' : 'danger'; return - }; + } useEffect(() => { - if(needsFurniUpdate) - { - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_NEEDS_UPDATE, - payload: { - flag: false - } - }); - - SendMessageComposer(new FurnitureListComposer()); - } - - }, [ needsFurniUpdate, groupItems, dispatchFurnitureState ]); - - useEffect(() => - { - if(!tradeData || (tradeData.state !== TradeState.TRADING_STATE_COUNTDOWN)) return; + if(tradeState !== TradeState.TRADING_STATE_COUNTDOWN) return; setCountdownTick(3); @@ -195,12 +132,7 @@ export const InventoryTradeView: FC = props => if(newValue === 0) { - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_TRADE_STATE, - payload: { - tradeState: TradeState.TRADING_STATE_CONFIRMING - } - }); + setTradeState(TradeState.TRADING_STATE_CONFIRMING); clearInterval(interval); } @@ -209,11 +141,8 @@ export const InventoryTradeView: FC = props => }); }, 1000); - return () => - { - clearInterval(interval); - } - }, [ tradeData, dispatchFurnitureState ]); + return () => clearInterval(interval); + }, [ tradeState, setTradeState ]); return ( @@ -245,12 +174,12 @@ export const InventoryTradeView: FC = props => { LocalizeText('inventory.trading.you') } { LocalizeText('inventory.trading.areoffering') }: - { getLockIcon(tradeData.ownUser.accepts) } + { getLockIcon(ownUser.accepts) } { Array.from(Array(MAX_ITEMS_TO_TRADE), (e, i) => { - const item = (tradeData.ownUser.items.getWithIndex(i) || null); + const item = (ownUser.items.getWithIndex(i) || null); if(!item) return ; @@ -270,13 +199,13 @@ export const InventoryTradeView: FC = props => - { tradeData.otherUser.userName } { LocalizeText('inventory.trading.isoffering') }: - { getLockIcon(tradeData.otherUser.accepts) } + { otherUser.userName } { LocalizeText('inventory.trading.isoffering') }: + { getLockIcon(otherUser.accepts) } { Array.from(Array(MAX_ITEMS_TO_TRADE), (e, i) => { - const item = (tradeData.otherUser.items.getWithIndex(i) || null); + const item = (otherUser.items.getWithIndex(i) || null); if(!item) return ; @@ -290,15 +219,15 @@ export const InventoryTradeView: FC = props => - { (tradeData.state === TradeState.TRADING_STATE_READY) && - } - { (tradeData.state === TradeState.TRADING_STATE_RUNNING) && - } - { (tradeData.state === TradeState.TRADING_STATE_COUNTDOWN) && + { (tradeState === TradeState.TRADING_STATE_READY) && + } + { (tradeState === TradeState.TRADING_STATE_RUNNING) && + } + { (tradeState === TradeState.TRADING_STATE_COUNTDOWN) && } - { (tradeData.state === TradeState.TRADING_STATE_CONFIRMING) && + { (tradeState === TradeState.TRADING_STATE_CONFIRMING) && } - { (tradeData.state === TradeState.TRADING_STATE_CONFIRMED) && + { (tradeState === TradeState.TRADING_STATE_CONFIRMED) && } diff --git a/src/components/inventory/views/badge/InventoryBadgeItemView.tsx b/src/components/inventory/views/badge/InventoryBadgeItemView.tsx deleted file mode 100644 index d9b5427b..00000000 --- a/src/components/inventory/views/badge/InventoryBadgeItemView.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { MouseEventType } from '@nitrots/nitro-renderer'; -import { FC, MouseEvent } from 'react'; -import { LayoutBadgeImageView, LayoutGridItem } from '../../../../common'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryBadgeActions } from '../../reducers/InventoryBadgeReducer'; - -export interface InventoryBadgeItemViewProps -{ - badgeCode: string; -} - -export const InventoryBadgeItemView: FC = props => -{ - const { badgeCode = null } = props; - const { badgeState = null, dispatchBadgeState = null } = useInventoryContext(); - - const onMouseEvent = (event: MouseEvent) => - { - switch(event.type) - { - case MouseEventType.MOUSE_DOWN: - dispatchBadgeState({ - type: InventoryBadgeActions.SET_BADGE, - payload: { badgeCode } - }); - } - } - - return ( - - - - ); -} diff --git a/src/components/inventory/views/badge/InventoryBadgeView.tsx b/src/components/inventory/views/badge/InventoryBadgeView.tsx deleted file mode 100644 index b000e874..00000000 --- a/src/components/inventory/views/badge/InventoryBadgeView.tsx +++ /dev/null @@ -1,102 +0,0 @@ -import { RequestBadgesComposer } from '@nitrots/nitro-renderer'; -import { FC, useEffect } from 'react'; -import { GetConfiguration, LocalizeBadgeName, LocalizeText, SendMessageComposer } from '../../../../api'; -import { AutoGrid, Button, Column, Flex, Grid, LayoutBadgeImageView, Text } from '../../../../common'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryBadgeActions } from '../../reducers/InventoryBadgeReducer'; -import { InventoryBadgeItemView } from './InventoryBadgeItemView'; - -export interface InventoryBadgeViewProps -{ -} - -export const InventoryBadgeView: FC = props => -{ - const { badgeState = null, dispatchBadgeState = null } = useInventoryContext(); - const { needsBadgeUpdate = false, badge = null, badges = [], activeBadges = [] } = badgeState; - - const maxBadgeCount = GetConfiguration('user.badges.max.slots', 5); - - const isWearingBadge = (badgeCode: string) => (activeBadges.indexOf(badgeCode) >= 0); - const canWearBadges = () => (activeBadges.length < maxBadgeCount); - - const toggleBadge = () => - { - if(isWearingBadge(badge)) - { - dispatchBadgeState({ - type: InventoryBadgeActions.REMOVE_ACTIVE_BADGE, - payload: { - badgeCode: badge - } - }); - } - else - { - if(!canWearBadges()) return; - - dispatchBadgeState({ - type: InventoryBadgeActions.ADD_ACTIVE_BADGE, - payload: { - badgeCode: badge - } - }); - } - } - - useEffect(() => - { - if(needsBadgeUpdate) - { - dispatchBadgeState({ - type: InventoryBadgeActions.SET_NEEDS_UPDATE, - payload: { - flag: false - } - }); - - SendMessageComposer(new RequestBadgesComposer()); - } - else - { - dispatchBadgeState({ - type: InventoryBadgeActions.SET_BADGE, - payload: { - badgeCode: null - } - }); - } - - }, [ needsBadgeUpdate, badges, dispatchBadgeState ]); - - return ( - - - - { badges && (badges.length > 0) && badges.map((code, index) => - { - if(activeBadges.indexOf(code) >= 0) return null; - - return - }) } - - - - - { LocalizeText('inventory.badges.activebadges') } - - { activeBadges && (activeBadges.length > 0) && activeBadges.map((code, index) => ) } - - - { badge && (badge.length > 0) && - - - - { LocalizeBadgeName(badge) } - - - } - - - ); -} diff --git a/src/components/inventory/views/bot/InventoryBotItemView.tsx b/src/components/inventory/views/bot/InventoryBotItemView.tsx deleted file mode 100644 index f91840cb..00000000 --- a/src/components/inventory/views/bot/InventoryBotItemView.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { MouseEventType } from '@nitrots/nitro-renderer'; -import { FC, MouseEvent, useEffect, useState } from 'react'; -import { LayoutAvatarImageView, LayoutGridItem } from '../../../../common'; -import { BotItem } from '../../common/BotItem'; -import { attemptBotPlacement } from '../../common/BotUtilities'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryBotActions } from '../../reducers/InventoryBotReducer'; - -export interface InventoryBotItemViewProps -{ - botItem: BotItem; -} - -export const InventoryBotItemView: FC = props => -{ - const { botItem } = props; - const [ isMouseDown, setMouseDown ] = useState(false); - const { botState = null, dispatchBotState = null } = useInventoryContext(); - const isActive = (botState.botItem === botItem); - - const onMouseEvent = (event: MouseEvent) => - { - switch(event.type) - { - case MouseEventType.MOUSE_DOWN: - dispatchBotState({ - type: InventoryBotActions.SET_BOT_ITEM, - payload: { botItem } - }); - - setMouseDown(true); - return; - case MouseEventType.MOUSE_UP: - setMouseDown(false); - return; - case MouseEventType.ROLL_OUT: - if(!isMouseDown || !isActive) return; - - attemptBotPlacement(botItem); - return; - } - } - - useEffect(() => - { - if(!isActive) return; - - botItem.isUnseen = false; - }, [ isActive, botItem ]); - - return ( - - - - ); -} diff --git a/src/components/inventory/views/bot/InventoryBotView.tsx b/src/components/inventory/views/bot/InventoryBotView.tsx deleted file mode 100644 index 063c02fb..00000000 --- a/src/components/inventory/views/bot/InventoryBotView.tsx +++ /dev/null @@ -1,94 +0,0 @@ -import { GetBotInventoryComposer, IRoomSession, RoomObjectVariable, RoomPreviewer } from '@nitrots/nitro-renderer'; -import { FC, useEffect } from 'react'; -import { GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api'; -import { AutoGrid, Button, Column, Grid, LayoutRoomPreviewerView, Text } from '../../../../common'; -import { attemptBotPlacement } from '../../common/BotUtilities'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryBotActions } from '../../reducers/InventoryBotReducer'; -import { InventoryCategoryEmptyView } from '../category-empty/InventoryCategoryEmptyView'; -import { InventoryBotItemView } from './InventoryBotItemView'; - -export interface InventoryBotViewProps -{ - roomSession: IRoomSession; - roomPreviewer: RoomPreviewer; -} - -export const InventoryBotView: FC = props => -{ - const { roomSession = null, roomPreviewer = null } = props; - const { botState = null, dispatchBotState = null } = useInventoryContext(); - const { needsBotUpdate = false, botItem = null, botItems = [] } = botState; - - useEffect(() => - { - if(needsBotUpdate) - { - dispatchBotState({ - type: InventoryBotActions.SET_NEEDS_UPDATE, - payload: { - flag: false - } - }); - - SendMessageComposer(new GetBotInventoryComposer()); - } - else - { - dispatchBotState({ - type: InventoryBotActions.SET_BOT_ITEM, - payload: { - botItem: null - } - }); - } - - }, [ needsBotUpdate, botItems, dispatchBotState ]); - - useEffect(() => - { - if(!botItem || !roomPreviewer) return; - - const botData = botItem.botData; - - const roomEngine = GetRoomEngine(); - - let wallType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_WALL_TYPE); - let floorType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_FLOOR_TYPE); - let landscapeType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_LANDSCAPE_TYPE); - - wallType = (wallType && wallType.length) ? wallType : '101'; - floorType = (floorType && floorType.length) ? floorType : '101'; - landscapeType = (landscapeType && landscapeType.length) ? landscapeType : '1.1'; - - roomPreviewer.reset(false); - roomPreviewer.updateRoomWallsAndFloorVisibility(true, true); - roomPreviewer.updateObjectRoom(floorType, wallType, landscapeType); - roomPreviewer.addAvatarIntoRoom(botData.figure, 0); - }, [ roomPreviewer, botItem ]); - - if(!botItems || !botItems.length) return ; - - return ( - - - - { botItems && (botItems.length > 0) && botItems.map(item => ) } - - - - - - - { botItem && - - { botItem.botData.name } - { !!roomSession && - } - } - - - ); -} diff --git a/src/components/inventory/views/furniture/InventoryFurnitureItemView.tsx b/src/components/inventory/views/furniture/InventoryFurnitureItemView.tsx deleted file mode 100644 index 0d25ce86..00000000 --- a/src/components/inventory/views/furniture/InventoryFurnitureItemView.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { MouseEventType } from '@nitrots/nitro-renderer'; -import { FC, MouseEvent, useEffect, useState } from 'react'; -import { LayoutGridItem } from '../../../../common/layout/LayoutGridItem'; -import { attemptItemPlacement } from '../../common/FurnitureUtilities'; -import { GroupItem } from '../../common/GroupItem'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryFurnitureActions } from '../../reducers/InventoryFurnitureReducer'; - -export interface InventoryFurnitureItemViewProps -{ - groupItem: GroupItem; -} - -export const InventoryFurnitureItemView: FC = props => -{ - const { groupItem } = props; - const [ isMouseDown, setMouseDown ] = useState(false); - const { furnitureState, dispatchFurnitureState } = useInventoryContext(); - const isActive = (furnitureState.groupItem === groupItem); - - const onMouseEvent = (event: MouseEvent) => - { - switch(event.type) - { - case MouseEventType.MOUSE_DOWN: - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_GROUP_ITEM, - payload: { groupItem } - }); - - setMouseDown(true); - return; - case MouseEventType.MOUSE_UP: - setMouseDown(false); - return; - case MouseEventType.ROLL_OUT: - if(!isMouseDown || !isActive) return; - - attemptItemPlacement(groupItem); - return; - } - } - - useEffect(() => - { - if(!isActive) return; - - groupItem.hasUnseenItems = false; - }, [ isActive, groupItem ]); - - const count = groupItem.getUnlockedCount(); - - return ; -} diff --git a/src/components/inventory/views/furniture/InventoryFurnitureView.tsx b/src/components/inventory/views/furniture/InventoryFurnitureView.tsx deleted file mode 100644 index e8886c54..00000000 --- a/src/components/inventory/views/furniture/InventoryFurnitureView.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import { FurnitureListComposer, IRoomSession, RoomObjectVariable, RoomPreviewer, Vector3d } from '@nitrots/nitro-renderer'; -import { FC, useEffect, useState } from 'react'; -import { GetRoomEngine, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../../api'; -import { AutoGrid, Button, Column, Grid, LayoutLimitedEditionCompactPlateView, LayoutRarityLevelView, LayoutRoomPreviewerView, Text } from '../../../../common'; -import { FurniCategory } from '../../common/FurniCategory'; -import { attemptItemPlacement, attemptPlaceMarketplaceOffer } from '../../common/FurnitureUtilities'; -import { GroupItem } from '../../common/GroupItem'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryFurnitureActions } from '../../reducers/InventoryFurnitureReducer'; -import { InventoryCategoryEmptyView } from '../category-empty/InventoryCategoryEmptyView'; -import { InventoryFurnitureItemView } from './InventoryFurnitureItemView'; -import { InventoryFurnitureSearchView } from './InventoryFurnitureSearchView'; - -export interface InventoryFurnitureViewProps -{ - roomSession: IRoomSession; - roomPreviewer: RoomPreviewer; -} - -export const InventoryFurnitureView: FC = props => -{ - const { roomSession = null, roomPreviewer = null } = props; - const { furnitureState = null, dispatchFurnitureState = null, unseenTracker = null } = useInventoryContext(); - const { needsFurniUpdate = false, groupItem = null, groupItems = [] } = furnitureState; - const [ filteredGroupItems, setFilteredGroupItems ] = useState(groupItems); - - useEffect(() => - { - if(needsFurniUpdate) - { - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_NEEDS_UPDATE, - payload: { - flag: false - } - }); - - SendMessageComposer(new FurnitureListComposer()); - } - else - { - setFilteredGroupItems(groupItems); - - dispatchFurnitureState({ - type: InventoryFurnitureActions.SET_GROUP_ITEM, - payload: { - groupItem: null - } - }); - } - - }, [ needsFurniUpdate, groupItems, dispatchFurnitureState ]); - - useEffect(() => - { - if(!groupItem || !roomPreviewer) return; - - const furnitureItem = groupItem.getLastItem(); - - if(!furnitureItem) return; - - const roomEngine = GetRoomEngine(); - - let wallType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_WALL_TYPE); - let floorType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_FLOOR_TYPE); - let landscapeType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_LANDSCAPE_TYPE); - - wallType = (wallType && wallType.length) ? wallType : '101'; - floorType = (floorType && floorType.length) ? floorType : '101'; - landscapeType = (landscapeType && landscapeType.length) ? landscapeType : '1.1'; - - roomPreviewer.reset(false); - roomPreviewer.updateObjectRoom(floorType, wallType, landscapeType); - roomPreviewer.updateRoomWallsAndFloorVisibility(true, true); - - if((furnitureItem.category === FurniCategory.WALL_PAPER) || (furnitureItem.category === FurniCategory.FLOOR) || (furnitureItem.category === FurniCategory.LANDSCAPE)) - { - floorType = ((furnitureItem.category === FurniCategory.FLOOR) ? groupItem.stuffData.getLegacyString() : floorType); - wallType = ((furnitureItem.category === FurniCategory.WALL_PAPER) ? groupItem.stuffData.getLegacyString() : wallType); - landscapeType = ((furnitureItem.category === FurniCategory.LANDSCAPE) ? groupItem.stuffData.getLegacyString() : landscapeType); - - roomPreviewer.updateObjectRoom(floorType, wallType, landscapeType); - - if(furnitureItem.category === FurniCategory.LANDSCAPE) - { - const data = GetSessionDataManager().getWallItemDataByName('noob_window_double'); - - if(data) roomPreviewer.addWallItemIntoRoom(data.id, new Vector3d(90, 0, 0), data.customParams); - } - } - else - { - if(groupItem.isWallItem) - { - roomPreviewer.addWallItemIntoRoom(groupItem.type, new Vector3d(90), furnitureItem.stuffData.getLegacyString()); - } - else - { - roomPreviewer.addFurnitureIntoRoom(groupItem.type, new Vector3d(90), groupItem.stuffData, (furnitureItem.extra.toString())); - } - } - }, [ roomPreviewer, groupItem ]); - - if(!groupItems || !groupItems.length) return ; - - return ( - - - - - { filteredGroupItems && (filteredGroupItems.length > 0) && filteredGroupItems.map((item, index) => ) } - - - - - - { groupItem && groupItem.stuffData.isUnique && - } - { (groupItem && groupItem.stuffData.rarityLevel > -1) && - } - - { groupItem && - - { groupItem.name } - - { !!roomSession && - } - { (groupItem && groupItem.isSellable) && - } - - } - - - ); -} diff --git a/src/components/inventory/views/pet/InventoryPetItemView.tsx b/src/components/inventory/views/pet/InventoryPetItemView.tsx deleted file mode 100644 index 6e6ecb2a..00000000 --- a/src/components/inventory/views/pet/InventoryPetItemView.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { MouseEventType } from '@nitrots/nitro-renderer'; -import { FC, MouseEvent, useEffect, useState } from 'react'; -import { LayoutGridItem, LayoutPetImageView } from '../../../../common'; -import { PetItem } from '../../common/PetItem'; -import { attemptPetPlacement } from '../../common/PetUtilities'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryPetActions } from '../../reducers/InventoryPetReducer'; - -export interface InventoryPetItemViewProps -{ - petItem: PetItem; -} - -export const InventoryPetItemView: FC = props => -{ - const { petItem } = props; - const [ isMouseDown, setMouseDown ] = useState(false); - const { petState = null, dispatchPetState = null } = useInventoryContext(); - const isActive = (petState.petItem === petItem); - - const onMouseEvent = (event: MouseEvent) => - { - switch(event.type) - { - case MouseEventType.MOUSE_DOWN: - dispatchPetState({ - type: InventoryPetActions.SET_PET_ITEM, - payload: { petItem } - }); - - setMouseDown(true); - return; - case MouseEventType.MOUSE_UP: - setMouseDown(false); - return; - case MouseEventType.ROLL_OUT: - if(!isMouseDown || !isActive) return; - - attemptPetPlacement(petItem); - return; - } - } - - useEffect(() => - { - if(!isActive) return; - - petItem.isUnseen = false; - }, [ isActive, petItem ]); - - return ( - - - - ); -} diff --git a/src/components/inventory/views/pet/InventoryPetView.tsx b/src/components/inventory/views/pet/InventoryPetView.tsx deleted file mode 100644 index d7b84250..00000000 --- a/src/components/inventory/views/pet/InventoryPetView.tsx +++ /dev/null @@ -1,93 +0,0 @@ -import { IRoomSession, RequestPetsComposer, RoomObjectVariable, RoomPreviewer } from '@nitrots/nitro-renderer'; -import { FC, useEffect } from 'react'; -import { GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api'; -import { AutoGrid, Button, Column, Grid, LayoutRoomPreviewerView, Text } from '../../../../common'; -import { attemptPetPlacement } from '../../common/PetUtilities'; -import { useInventoryContext } from '../../InventoryContext'; -import { InventoryPetActions } from '../../reducers/InventoryPetReducer'; -import { InventoryCategoryEmptyView } from '../category-empty/InventoryCategoryEmptyView'; -import { InventoryPetItemView } from './InventoryPetItemView'; - -export interface InventoryPetViewProps -{ - roomSession: IRoomSession; - roomPreviewer: RoomPreviewer; -} - -export const InventoryPetView: FC = props => -{ - const { roomSession = null, roomPreviewer = null } = props; - const { petState = null, dispatchPetState = null } = useInventoryContext(); - const { needsPetUpdate = false, petItem = null, petItems = [] } = petState; - - useEffect(() => - { - if(needsPetUpdate) - { - dispatchPetState({ - type: InventoryPetActions.SET_NEEDS_UPDATE, - payload: { - flag: false - } - }); - - SendMessageComposer(new RequestPetsComposer()); - } - else - { - dispatchPetState({ - type: InventoryPetActions.SET_PET_ITEM, - payload: { - petItem: null - } - }); - } - - }, [ needsPetUpdate, petItems, dispatchPetState ]); - - useEffect(() => - { - if(!petItem || !roomPreviewer) return; - - const petData = petItem.petData; - const roomEngine = GetRoomEngine(); - - let wallType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_WALL_TYPE); - let floorType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_FLOOR_TYPE); - let landscapeType = roomEngine.getRoomInstanceVariable(roomEngine.activeRoomId, RoomObjectVariable.ROOM_LANDSCAPE_TYPE); - - wallType = (wallType && wallType.length) ? wallType : '101'; - floorType = (floorType && floorType.length) ? floorType : '101'; - landscapeType = (landscapeType && landscapeType.length) ? landscapeType : '1.1'; - - roomPreviewer.reset(false); - roomPreviewer.updateRoomWallsAndFloorVisibility(true, true); - roomPreviewer.updateObjectRoom(floorType, wallType, landscapeType); - roomPreviewer.addPetIntoRoom(petData.figureString); - }, [ roomPreviewer, petItem ]); - - if(!petItems || !petItems.length) return ; - - return ( - - - - { petItems && (petItems.length > 0) && petItems.map(item => ) } - - - - - - - { petItem && - - { petItem.petData.name } - { !!roomSession && - } - } - - - ); -} diff --git a/src/components/mod-tools/ModToolsView.tsx b/src/components/mod-tools/ModToolsView.tsx index a7b3c173..022cc2bc 100644 --- a/src/components/mod-tools/ModToolsView.tsx +++ b/src/components/mod-tools/ModToolsView.tsx @@ -1,5 +1,5 @@ import { RoomEngineObjectEvent, RoomObjectCategory, RoomObjectType } from '@nitrots/nitro-renderer'; -import { FC, useCallback, useReducer, useState } from 'react'; +import { FC, useCallback, useReducer, useRef, useState } from 'react'; import { GetRoomSession } from '../../api'; import { Base, Button, DraggableWindowPosition, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common'; import { ModToolsEvent, ModToolsOpenRoomChatlogEvent, ModToolsOpenRoomInfoEvent, ModToolsOpenUserInfoEvent } from '../../events'; @@ -21,6 +21,7 @@ export const ModToolsView: FC<{}> = props => const [ isTicketsVisible, setIsTicketsVisible ] = useState(false); const [ modToolsState, dispatchModToolsState ] = useReducer(ModToolsReducer, initialModTools); const { currentRoomId = null, openRooms = null, openRoomChatlogs = null, openUserChatlogs = null, openUserInfo = null } = modToolsState; + const elementRef = useRef(null); const onModToolsEvent = useCallback((event: ModToolsEvent) => { @@ -190,7 +191,7 @@ export const ModToolsView: FC<{}> = props => -