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 { TradingNotificationType } from './TradingNotificationType';
export const TradingNotificationMessage = (type: number) =>
export const TradingNotificationMessage = (type: number, otherUsername: string = '') =>
{
switch(type)
{
case TradingNotificationType.ALERT_SCAM:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.other_not_offering'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return;
case TradingNotificationType.ALERT_OTHER_CANCELLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.closed'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return;
case TradingNotificationType.ALERT_ALREADY_OPEN:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.already_open'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return;
case TradingNotificationType.ALERT_OTHER_DISABLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.others_account_disabled'), null, null, null, LocalizeText('inventory.trading.notification.title'));
case TradingNotificationType.HOTEL_TRADING_DISABLED:
case TradingNotificationType.YOU_NOT_ALLOWED:
case TradingNotificationType.THEY_NOT_ALLOWED:
case TradingNotificationType.ROOM_DISABLED:
case TradingNotificationType.YOU_OPEN:
case TradingNotificationType.THEY_OPEN:
NotificationUtilities.simpleAlert(LocalizeText(`inventory.trading.openfail.${ type }`, [ 'otherusername' ], [ otherUsername ]), null, null, null, LocalizeText('inventory.trading.openfail.title'));
return;
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'));
return;
case TradingNotificationType.YOU_NOT_ALLOWED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.warning.own_account_disabled'), null, null, null, LocalizeText('inventory.trading.notification.title'));
case TradingNotificationType.THEY_CANCELLED:
NotificationUtilities.simpleAlert(LocalizeText('inventory.trading.info.closed'), null, null, null, LocalizeText('inventory.trading.notification.title'));
return;
}
}

View File

@ -1,9 +1,12 @@
export class TradingNotificationType
{
public static ALERT_SCAM: number = 0;
public static ALERT_OTHER_CANCELLED: number = 1;
public static ALERT_ALREADY_OPEN: number = 2;
public static ALERT_OTHER_DISABLED: number = 3;
public static ERROR_WHILE_COMMIT: number = 4;
public static YOU_NOT_ALLOWED: number = 5;
public static HOTEL_TRADING_DISABLED = 1;
public static YOU_NOT_ALLOWED: number = 2;
public static THEY_NOT_ALLOWED: number = 4;
public static ROOM_DISABLED: number = 6;
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 =>
{
const { roomSession = null, roomPreviewer = null } = props;
const { groupItems = [], selectedItem = null, selectItem = null } = useInventoryFurni();
const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>(groupItems);
const [ filteredGroupItems, setFilteredGroupItems ] = useState<GroupItem[]>([]);
const { groupItems = [], selectedItem = null, selectItem = null, activate = null, deactivate = null } = useInventoryFurni();
const { getCount = null, resetCategory = null } = useInventoryUnseenTracker();
useEffect(() =>
@ -86,6 +86,13 @@ export const InventoryFurnitureView: FC<InventoryFurnitureViewProps> = props =>
}
}, [ 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') } />;
const InventoryFurnitureItemView: FC<{ groupItem: GroupItem }> = props =>

View File

@ -258,17 +258,10 @@ export const useInventoryFurni = () =>
const { setIsVisible, ...rest } = useBetween(useInventoryFurniState);
const { isVisible = false, activate = null, deactivate = null } = useSharedVisibility();
useEffect(() =>
{
const id = activate();
return () => deactivate(id);
}, [ activate, deactivate ]);
useEffect(() =>
{
setIsVisible(isVisible);
}, [ 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 { useCallback, useState } from 'react';
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, useEffect, useState } from 'react';
import { useBetween } from 'use-between';
import { useInventoryFurni } from '.';
import { BatchUpdates, UseMessageEventHook } from '..';
@ -13,7 +13,7 @@ const useInventoryTradeState = () =>
const [ ownUser, setOwnUser ] = useState<TradeUserData>(null);
const [ otherUser, setOtherUser ] = useState<TradeUserData>(null);
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 progressTrade = () =>
@ -126,7 +126,7 @@ const useInventoryTradeState = () =>
{
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();
if((parser.reason !== TradingOpenFailedParser.REASON_YOU_ARE_ALREADY_TRADING && (parser.reason !== TradingOpenFailedParser.REASON_OTHER_USER_ALREADY_TRADING))) return;
TradingNotificationMessage(TradingNotificationType.ALERT_ALREADY_OPEN);
TradingNotificationMessage(parser.reason, parser.otherUserName);
}, []);
UseMessageEventHook(TradingOpenFailedEvent, onTradingOpenFailedEvent);
@ -305,7 +303,7 @@ const useInventoryTradeState = () =>
{
const parser = event.getParser();
TradingNotificationMessage(TradingNotificationType.ALERT_OTHER_DISABLED);
TradingNotificationMessage(TradingNotificationType.THEY_NOT_ALLOWED);
}, []);
UseMessageEventHook(TradingOtherNotAllowedEvent, onTradingOtherNotAllowedEvent);
@ -319,6 +317,15 @@ const useInventoryTradeState = () =>
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 };
}