diff --git a/src/views/inventory/InventoryView.scss b/src/views/inventory/InventoryView.scss index c9552f6f..83248603 100644 --- a/src/views/inventory/InventoryView.scss +++ b/src/views/inventory/InventoryView.scss @@ -2,6 +2,18 @@ width: 475px; // height: 300px; // max-height: 300px; + + .content-area { + height: 243.5px; + max-height: 243.5px; + } + + .empty-image { + background: url('../../assets/images/inventory/empty.png'); + width: 129px; + height: 181px; + } } + @import './views/InventoryViews'; diff --git a/src/views/inventory/InventoryView.tsx b/src/views/inventory/InventoryView.tsx index fdf2c722..3d8de3ca 100644 --- a/src/views/inventory/InventoryView.tsx +++ b/src/views/inventory/InventoryView.tsx @@ -11,9 +11,15 @@ import { LocalizeText } from '../../utils/LocalizeText'; import { InventoryContextProvider } from './context/InventoryContext'; import { InventoryMessageHandler } from './InventoryMessageHandler'; import { InventoryTabs, InventoryViewProps } from './InventoryView.types'; +import { initialInventoryBadge, inventoryBadgeReducer } from './reducers/InventortBadgeReducer'; +import { initialInventoryBot, inventoryBotReducer } from './reducers/InventoryBotReducer'; import { initialInventoryFurniture, inventoryFurnitureReducer } from './reducers/InventoryFurnitureReducer'; -import { isObjectMoverRequested, setObjectMoverRequested } from './utils/FurnitureUtilities'; +import { initialInventoryPet, inventoryPetReducer } from './reducers/InventoryPetReducer'; +import { isObjectMoverRequested, setObjectMoverRequested } from './utils/InventoryUtilities'; +import { InventoryBadgeView } from './views/badge/InventoryBadgeView'; +import { InventoryBotView } from './views/bot/InventoryBotView'; import { InventoryFurnitureView } from './views/furniture/InventoryFurnitureView'; +import { InventoryPetView } from './views/pet/InventoryPetView'; export const InventoryView: FC = props => { @@ -24,6 +30,9 @@ export const InventoryView: FC = props => 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 onInventoryEvent = useCallback((event: InventoryEvent) => { @@ -94,7 +103,7 @@ export const InventoryView: FC = props => } return ( - + { isVisible &&
@@ -114,10 +123,15 @@ export const InventoryView: FC = props => ; }) } -
- { (currentTab === InventoryTabs.FURNITURE ) && } +
+ { (currentTab === InventoryTabs.FURNITURE ) && + } + { (currentTab === InventoryTabs.BOTS ) && + } + { (currentTab === InventoryTabs.PETS ) && + } + { (currentTab === InventoryTabs.BADGES ) && + }
} diff --git a/src/views/inventory/context/InventoryContext.tsx b/src/views/inventory/context/InventoryContext.tsx index 8621f150..6500fbc7 100644 --- a/src/views/inventory/context/InventoryContext.tsx +++ b/src/views/inventory/context/InventoryContext.tsx @@ -3,7 +3,13 @@ import { IInventoryContext, InventoryContextProps } from './InventoryContext.typ const InventoryContext = createContext({ furnitureState: null, - dispatchFurnitureState: null + dispatchFurnitureState: null, + botState: null, + dispatchBotState: null, + petState: null, + dispatchPetState: null, + badgeState: null, + dispatchBadgeState: null }); export const InventoryContextProvider: FC = props => diff --git a/src/views/inventory/context/InventoryContext.types.ts b/src/views/inventory/context/InventoryContext.types.ts index bad74873..7053c201 100644 --- a/src/views/inventory/context/InventoryContext.types.ts +++ b/src/views/inventory/context/InventoryContext.types.ts @@ -1,10 +1,19 @@ import { Dispatch, ProviderProps } from 'react'; +import { IInventoryBadgeAction, IInventoryBadgeState } from '../reducers/InventortBadgeReducer'; +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; } export interface InventoryContextProps extends ProviderProps diff --git a/src/views/inventory/utils/BotUtilities.ts b/src/views/inventory/utils/BotUtilities.ts new file mode 100644 index 00000000..ac8f8c78 --- /dev/null +++ b/src/views/inventory/utils/BotUtilities.ts @@ -0,0 +1,120 @@ +import { BotData, RoomObjectCategory, RoomObjectPlacementSource, RoomObjectType } from 'nitro-renderer'; +import { GetRoomEngine, GetRoomSessionManager } from '../../../api'; +import { InventoryEvent } from '../../../events'; +import { dispatchUiEvent } from '../../../hooks/events/ui/ui-event'; +import { BotItem } from './BotItem'; +import { getPlacingItemId, setObjectMoverRequested, setPlacingItemId } from './InventoryUtilities'; + +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[]): 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) + { + for(const botData of fragment) + { + if(botData.id === itemId) continue; + + removedIds.push(itemId); + } + } + + const emptyExistingSet = (existingIds.length === 0); + + for(const id of removedIds) removeBotItemById(id, set); + + for(const botData of addedDatas) + { + addSingleBotItem(botData, set, true); + } + + 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) + { + set.unshift(botItem); + } + else + { + set.push(botItem); + } + + return botItem; +} diff --git a/src/views/inventory/utils/InventoryUtilities.ts b/src/views/inventory/utils/InventoryUtilities.ts new file mode 100644 index 00000000..62fe7565 --- /dev/null +++ b/src/views/inventory/utils/InventoryUtilities.ts @@ -0,0 +1,22 @@ +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; +}