More inventory changes

This commit is contained in:
Bill 2022-04-01 16:12:46 -04:00
parent cf47ff8f23
commit cf5c46213a
15 changed files with 447 additions and 439 deletions

View File

@ -1,28 +1,26 @@
import { LocalizeText, NotificationUtilities } from '..'; import { LocalizeText, NotificationUtilities } from '..';
import { TradingNotificationType } from './TradingNotificationType'; import { TradingNotificationType } from './TradingNotificationType';
export const TradingNotificationMessage = (type: number) => export const TradingNotificationMessage = (type: number, otherUsername: string = '') =>
{ {
switch(type) switch(type)
{ {
case TradingNotificationType.ALERT_SCAM: case TradingNotificationType.ALERT_SCAM:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.other_not_offering'), null, null, null, LocalizeText('inventory.trading.notification.title')); NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.other_not_offering'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return; return;
case TradingNotificationType.ALERT_OTHER_CANCELLED: case TradingNotificationType.HOTEL_TRADING_DISABLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.closed'), null, null, null, LocalizeText('inventory.trading.notification.title')); case TradingNotificationType.YOU_NOT_ALLOWED:
return; case TradingNotificationType.THEY_NOT_ALLOWED:
case TradingNotificationType.ALERT_ALREADY_OPEN: case TradingNotificationType.ROOM_DISABLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.already_open'), null, null, null, LocalizeText('inventory.trading.notification.title')); case TradingNotificationType.YOU_OPEN:
return; case TradingNotificationType.THEY_OPEN:
case TradingNotificationType.ALERT_OTHER_DISABLED: NotificationUtilities.simpleAlert(LocalizeText(`inventory.trading.openfail.${ type }`, [ 'otherusername' ], [ otherUsername ]), null, null, null, LocalizeText('inventory.trading.openfail.title'));
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.others_account_disabled'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return; return;
case TradingNotificationType.ERROR_WHILE_COMMIT: case TradingNotificationType.ERROR_WHILE_COMMIT:
NotificationUtilities.simpleAlert(`${ LocalizeText('inventory.trading.notification.caption') }, ${ LocalizeText('inventory.trading.notification.commiterror.info') }`, null, null, null, LocalizeText('inventory.trading.notification.title')); NotificationUtilities.simpleAlert(`${ LocalizeText('inventory.trading.notification.caption') }, ${ LocalizeText('inventory.trading.notification.commiterror.info') }`, null, null, null, LocalizeText('inventory.trading.notification.title'));
return; return;
case TradingNotificationType.YOU_NOT_ALLOWED: case TradingNotificationType.THEY_CANCELLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.own_account_disabled'), null, null, null, LocalizeText('inventory.trading.notification.title')); NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.closed'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return; return;
} }
} }

View File

@ -1,9 +1,12 @@
export class TradingNotificationType export class TradingNotificationType
{ {
public static ALERT_SCAM: number = 0; public static ALERT_SCAM: number = 0;
public static ALERT_OTHER_CANCELLED: number = 1; public static HOTEL_TRADING_DISABLED = 1;
public static ALERT_ALREADY_OPEN: number = 2; public static YOU_NOT_ALLOWED: number = 2;
public static ALERT_OTHER_DISABLED: number = 3; public static THEY_NOT_ALLOWED: number = 4;
public static ERROR_WHILE_COMMIT: number = 4; public static ROOM_DISABLED: number = 6;
public static YOU_NOT_ALLOWED: number = 5; public static YOU_OPEN: number = 7;
public static THEY_OPEN: number = 8;
public static ERROR_WHILE_COMMIT: number = 9;
public static THEY_CANCELLED: number = 10;
} }

View File

@ -16,8 +16,8 @@ interface InventoryFurnitureViewProps
export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props => export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
{ {
const { roomSession = null, roomPreviewer = null } = props; const { roomSession = null, roomPreviewer = null } = props;
const { groupItems = [], selectedItem = null, selectItem = null } = useInventoryFurni(); const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>([]);
const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>(groupItems); const { groupItems = [], selectedItem = null, selectItem = null, activate = null, deactivate = null } = useInventoryFurni();
const { getCount = null, resetCategory = null } = useInventoryUnseenTracker(); const { getCount = null, resetCategory = null } = useInventoryUnseenTracker();
useEffect(() => useEffect(() =>
@ -86,6 +86,13 @@ export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
} }
}, [ groupItems, getCount, resetCategory ]); }, [ groupItems, getCount, resetCategory ]);
useEffect(() =>
{
const id = activate();
return () => deactivate(id);
}, [ activate, deactivate ]);
if(!groupItems || !groupItems.length) return <InventoryCategoryEmptyView title={ LocalizeText('inventory.empty.title') } desc={ LocalizeText('inventory.empty.desc') } />; if(!groupItems || !groupItems.length) return <InventoryCategoryEmptyView title={ LocalizeText('inventory.empty.title') } desc={ LocalizeText('inventory.empty.desc') } />;
const InventoryFurnitureItemView: FC<{ groupItem: GroupItem }> = props => const InventoryFurnitureItemView: FC<{ groupItem: GroupItem }> = props =>

View File

@ -258,17 +258,10 @@ export const useInventoryFurni = () =>
const { setIsVisible, ...rest } = useBetween(useInventoryFurniState); const { setIsVisible, ...rest } = useBetween(useInventoryFurniState);
const { isVisible = false, activate = null, deactivate = null } = useSharedVisibility(); const { isVisible = false, activate = null, deactivate = null } = useSharedVisibility();
useEffect(() =>
{
const id = activate();
return () => deactivate(id);
}, [ activate, deactivate ]);
useEffect(() => useEffect(() =>
{ {
setIsVisible(isVisible); setIsVisible(isVisible);
}, [ isVisible, setIsVisible ]); }, [ isVisible, setIsVisible ]);
return { ...rest }; return { activate, deactivate, ...rest };
} }

View File

@ -1,5 +1,5 @@
import { AdvancedMap, TradingAcceptComposer, TradingAcceptEvent, TradingCancelComposer, TradingCloseComposer, TradingCloseEvent, TradingCloseParser, TradingCompletedEvent, TradingConfirmationComposer, TradingConfirmationEvent, TradingListItemEvent, TradingListItemRemoveComposer, TradingNotOpenEvent, TradingOpenComposer, TradingOpenEvent, TradingOpenFailedEvent, TradingOpenFailedParser, TradingOtherNotAllowedEvent, TradingUnacceptComposer, TradingYouAreNotAllowedEvent } from '@nitrots/nitro-renderer'; import { AdvancedMap, TradingAcceptComposer, TradingAcceptEvent, TradingCancelComposer, TradingCloseComposer, TradingCloseEvent, TradingCloseParser, TradingCompletedEvent, TradingConfirmationComposer, TradingConfirmationEvent, TradingListItemEvent, TradingListItemRemoveComposer, TradingNotOpenEvent, TradingOpenComposer, TradingOpenEvent, TradingOpenFailedEvent, TradingOtherNotAllowedEvent, TradingUnacceptComposer, TradingYouAreNotAllowedEvent } from '@nitrots/nitro-renderer';
import { useCallback, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { useBetween } from 'use-between'; import { useBetween } from 'use-between';
import { useInventoryFurni } from '.'; import { useInventoryFurni } from '.';
import { BatchUpdates, UseMessageEventHook } from '..'; import { BatchUpdates, UseMessageEventHook } from '..';
@ -13,7 +13,7 @@ const useInventoryTradeState = () =>
const [ ownUser, setOwnUser ] = useState<TradeUserData>(null); const [ ownUser, setOwnUser ] = useState<TradeUserData>(null);
const [ otherUser, setOtherUser ] = useState<TradeUserData>(null); const [ otherUser, setOtherUser ] = useState<TradeUserData>(null);
const [ tradeState, setTradeState ] = useState(TradeState.TRADING_STATE_READY); const [ tradeState, setTradeState ] = useState(TradeState.TRADING_STATE_READY);
const { groupItems = [], setGroupItems = null } = useInventoryFurni(); const { groupItems = [], setGroupItems = null, activate = null, deactivate = null } = useInventoryFurni();
const isTrading = (tradeState >= TradeState.TRADING_STATE_RUNNING); const isTrading = (tradeState >= TradeState.TRADING_STATE_RUNNING);
const progressTrade = () => const progressTrade = () =>
@ -126,7 +126,7 @@ const useInventoryTradeState = () =>
{ {
if(ownUser && (parser.userID !== ownUser.userId)) if(ownUser && (parser.userID !== ownUser.userId))
{ {
TradingNotificationMessage(TradingNotificationType.ALERT_OTHER_CANCELLED); TradingNotificationMessage(TradingNotificationType.THEY_CANCELLED);
} }
} }
@ -294,9 +294,7 @@ const useInventoryTradeState = () =>
{ {
const parser = event.getParser(); const parser = event.getParser();
if((parser.reason !== TradingOpenFailedParser.REASON_YOU_ARE_ALREADY_TRADING && (parser.reason !== TradingOpenFailedParser.REASON_OTHER_USER_ALREADY_TRADING))) return; TradingNotificationMessage(parser.reason, parser.otherUserName);
TradingNotificationMessage(TradingNotificationType.ALERT_ALREADY_OPEN);
}, []); }, []);
UseMessageEventHook(TradingOpenFailedEvent, onTradingOpenFailedEvent); UseMessageEventHook(TradingOpenFailedEvent, onTradingOpenFailedEvent);
@ -305,7 +303,7 @@ const useInventoryTradeState = () =>
{ {
const parser = event.getParser(); const parser = event.getParser();
TradingNotificationMessage(TradingNotificationType.ALERT_OTHER_DISABLED); TradingNotificationMessage(TradingNotificationType.THEY_NOT_ALLOWED);
}, []); }, []);
UseMessageEventHook(TradingOtherNotAllowedEvent, onTradingOtherNotAllowedEvent); UseMessageEventHook(TradingOtherNotAllowedEvent, onTradingOtherNotAllowedEvent);
@ -319,6 +317,15 @@ const useInventoryTradeState = () =>
UseMessageEventHook(TradingYouAreNotAllowedEvent, onTradingYouAreNotAllowedEvent); UseMessageEventHook(TradingYouAreNotAllowedEvent, onTradingYouAreNotAllowedEvent);
useEffect(() =>
{
if(tradeState === TradeState.TRADING_STATE_READY) return;
const id = activate();
return () => deactivate(id);
}, [ tradeState, activate, deactivate ]);
return { ownUser, otherUser, tradeState, setTradeState, isTrading, groupItems, progressTrade, removeItem, stopTrading }; return { ownUser, otherUser, tradeState, setTradeState, isTrading, groupItems, progressTrade, removeItem, stopTrading };
} }