mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-30 08:50:51 +01:00
Update exchange
This commit is contained in:
parent
915d05adb1
commit
393d40ff41
@ -0,0 +1,34 @@
|
|||||||
|
import { RoomWidgetUpdateEvent } from './RoomWidgetUpdateEvent';
|
||||||
|
|
||||||
|
export class RoomWidgetUpdateCreditFurniEvent extends RoomWidgetUpdateEvent
|
||||||
|
{
|
||||||
|
public static CREDIT_FURNI_UPDATE: string = 'RWUCFE_CREDIT_FURNI_UPDATE';
|
||||||
|
|
||||||
|
private _objectId: number;
|
||||||
|
private _value: number;
|
||||||
|
private _furniType: string;
|
||||||
|
|
||||||
|
constructor(type: string, objectId: number, value: number, furniType: string)
|
||||||
|
{
|
||||||
|
super(type);
|
||||||
|
|
||||||
|
this._objectId = objectId;
|
||||||
|
this._value = value;
|
||||||
|
this._furniType = furniType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get objectId(): number
|
||||||
|
{
|
||||||
|
return this._objectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get value(): number
|
||||||
|
{
|
||||||
|
return this._value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get furniType(): string
|
||||||
|
{
|
||||||
|
return this._furniType;
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ export * from './RoomWidgetRoomObjectUpdateEvent';
|
|||||||
export * from './RoomWidgetUpdateBackgroundColorPreviewEvent';
|
export * from './RoomWidgetUpdateBackgroundColorPreviewEvent';
|
||||||
export * from './RoomWidgetUpdateChatEvent';
|
export * from './RoomWidgetUpdateChatEvent';
|
||||||
export * from './RoomWidgetUpdateChatInputContentEvent';
|
export * from './RoomWidgetUpdateChatInputContentEvent';
|
||||||
|
export * from './RoomWidgetUpdateCreditFurniEvent';
|
||||||
export * from './RoomWidgetUpdateCustomStackHeightEvent';
|
export * from './RoomWidgetUpdateCustomStackHeightEvent';
|
||||||
export * from './RoomWidgetUpdateDanceStatusEvent';
|
export * from './RoomWidgetUpdateDanceStatusEvent';
|
||||||
export * from './RoomWidgetUpdateDimmerEvent';
|
export * from './RoomWidgetUpdateDimmerEvent';
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
import { FurnitureExchangeComposer, NitroEvent, RoomObjectVariable, RoomWidgetEnum } from '@nitrots/nitro-renderer';
|
||||||
|
import { RoomWidgetCreditFurniRedeemMessage, RoomWidgetUpdateCreditFurniEvent, RoomWidgetUpdateEvent } from '..';
|
||||||
|
import { GetRoomEngine } from '../..';
|
||||||
|
import { IsOwnerOfFurniture } from '../../..';
|
||||||
|
import { RoomWidgetFurniToWidgetMessage, RoomWidgetMessage } from '../messages';
|
||||||
|
import { RoomWidgetHandler } from './RoomWidgetHandler';
|
||||||
|
|
||||||
|
export class FurnitureCreditWidgetHandler extends RoomWidgetHandler
|
||||||
|
{
|
||||||
|
public processEvent(event: NitroEvent): void
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
public processWidgetMessage(message: RoomWidgetMessage): RoomWidgetUpdateEvent
|
||||||
|
{
|
||||||
|
switch(message.type)
|
||||||
|
{
|
||||||
|
case RoomWidgetFurniToWidgetMessage.REQUEST_CREDITFURNI: {
|
||||||
|
const creditMessage = (message as RoomWidgetFurniToWidgetMessage);
|
||||||
|
|
||||||
|
const roomObject = GetRoomEngine().getRoomObject(creditMessage.roomId, creditMessage.objectId, creditMessage.category);
|
||||||
|
|
||||||
|
if(!roomObject || !IsOwnerOfFurniture(roomObject)) return;
|
||||||
|
|
||||||
|
this.container.eventDispatcher.dispatchEvent(new RoomWidgetUpdateCreditFurniEvent(RoomWidgetUpdateCreditFurniEvent.CREDIT_FURNI_UPDATE, creditMessage.objectId, roomObject.model.getValue<number>(RoomObjectVariable.FURNITURE_CREDIT_VALUE), (roomObject.model.getValue<string>(RoomObjectVariable.FURNITURE_TYPE_ID) + '_' + creditMessage.type + '_' + creditMessage.objectId)));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case RoomWidgetCreditFurniRedeemMessage.REDEEM: {
|
||||||
|
const redeemMessage = (message as RoomWidgetCreditFurniRedeemMessage);
|
||||||
|
|
||||||
|
this.container.roomSession.connection.send(new FurnitureExchangeComposer(redeemMessage.objectId));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get type(): string
|
||||||
|
{
|
||||||
|
return RoomWidgetEnum.FURNI_CREDIT_WIDGET;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get eventTypes(): string[]
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public get messageTypes(): string[]
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
RoomWidgetFurniToWidgetMessage.REQUEST_CREDITFURNI,
|
||||||
|
RoomWidgetCreditFurniRedeemMessage.REDEEM
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
export * from './DoorbellWidgetHandler';
|
export * from './DoorbellWidgetHandler';
|
||||||
export * from './FurniChooserWidgetHandler';
|
export * from './FurniChooserWidgetHandler';
|
||||||
export * from './FurnitureContextMenuWidgetHandler';
|
export * from './FurnitureContextMenuWidgetHandler';
|
||||||
|
export * from './FurnitureCreditWidgetHandler';
|
||||||
export * from './FurnitureCustomStackHeightWidgetHandler';
|
export * from './FurnitureCustomStackHeightWidgetHandler';
|
||||||
export * from './FurnitureDimmerWidgetHandler';
|
export * from './FurnitureDimmerWidgetHandler';
|
||||||
export * from './FurnitureExternalImageWidgetHandler';
|
export * from './FurnitureExternalImageWidgetHandler';
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
import { RoomWidgetMessage } from './RoomWidgetMessage';
|
||||||
|
|
||||||
|
export class RoomWidgetCreditFurniRedeemMessage extends RoomWidgetMessage
|
||||||
|
{
|
||||||
|
public static REDEEM: string = 'RWCFRM_REDEEM';
|
||||||
|
|
||||||
|
private _objectId: number;
|
||||||
|
|
||||||
|
constructor(type: string, objectId: number)
|
||||||
|
{
|
||||||
|
super(type);
|
||||||
|
|
||||||
|
this._objectId = objectId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get objectId(): number
|
||||||
|
{
|
||||||
|
return this._objectId;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ export * from './RoomWidgetChangePostureMessage';
|
|||||||
export * from './RoomWidgetChatMessage';
|
export * from './RoomWidgetChatMessage';
|
||||||
export * from './RoomWidgetChatSelectAvatarMessage';
|
export * from './RoomWidgetChatSelectAvatarMessage';
|
||||||
export * from './RoomWidgetChatTypingMessage';
|
export * from './RoomWidgetChatTypingMessage';
|
||||||
|
export * from './RoomWidgetCreditFurniRedeemMessage';
|
||||||
export * from './RoomWidgetDanceMessage';
|
export * from './RoomWidgetDanceMessage';
|
||||||
export * from './RoomWidgetDimmerChangeStateMessage';
|
export * from './RoomWidgetDimmerChangeStateMessage';
|
||||||
export * from './RoomWidgetDimmerPreviewMessage';
|
export * from './RoomWidgetDimmerPreviewMessage';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { EventDispatcher, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
import { EventDispatcher, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useEffect, useRef, useState } from 'react';
|
import { FC, useEffect, useRef, useState } from 'react';
|
||||||
import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureDimmerWidgetHandler, FurnitureExternalImageWidgetHandler, FurniturePresentWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler } from '../../api';
|
import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCreditWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureDimmerWidgetHandler, FurnitureExternalImageWidgetHandler, FurniturePresentWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler } from '../../api';
|
||||||
import { RoomContextProvider } from './context/RoomContext';
|
import { RoomContextProvider } from './context/RoomContext';
|
||||||
import { RoomColorView } from './RoomColorView';
|
import { RoomColorView } from './RoomColorView';
|
||||||
import { RoomViewProps } from './RoomView.types';
|
import { RoomViewProps } from './RoomView.types';
|
||||||
@ -39,6 +39,7 @@ export const RoomView: FC<RoomViewProps> = props =>
|
|||||||
|
|
||||||
widgetHandlerManager.registerHandler(new FurniChooserWidgetHandler());
|
widgetHandlerManager.registerHandler(new FurniChooserWidgetHandler());
|
||||||
widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler());
|
widgetHandlerManager.registerHandler(new FurnitureContextMenuWidgetHandler());
|
||||||
|
widgetHandlerManager.registerHandler(new FurnitureCreditWidgetHandler());
|
||||||
widgetHandlerManager.registerHandler(new FurnitureCustomStackHeightWidgetHandler());
|
widgetHandlerManager.registerHandler(new FurnitureCustomStackHeightWidgetHandler());
|
||||||
widgetHandlerManager.registerHandler(new FurnitureExternalImageWidgetHandler());
|
widgetHandlerManager.registerHandler(new FurnitureExternalImageWidgetHandler());
|
||||||
widgetHandlerManager.registerHandler(new FurniturePresentWidgetHandler());
|
widgetHandlerManager.registerHandler(new FurniturePresentWidgetHandler());
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
export class FurnitureExchangeCreditData
|
|
||||||
{
|
|
||||||
constructor(
|
|
||||||
public objectId: number,
|
|
||||||
public category: number,
|
|
||||||
public value: number) {}
|
|
||||||
}
|
|
@ -1,73 +1,51 @@
|
|||||||
import { FurnitureExchangeComposer, NitroEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable } from '@nitrots/nitro-renderer';
|
|
||||||
import { FC, useCallback, useState } from 'react';
|
import { FC, useCallback, useState } from 'react';
|
||||||
import { GetRoomEngine, GetRoomSession, IsOwnerOfFurniture, LocalizeText, RoomWidgetRoomObjectUpdateEvent } from '../../../../../api';
|
import { LocalizeText, RoomWidgetCreditFurniRedeemMessage, RoomWidgetUpdateCreditFurniEvent } from '../../../../../api';
|
||||||
|
import { BatchUpdates } from '../../../../../hooks';
|
||||||
import { CreateEventDispatcherHook } from '../../../../../hooks/events/event-dispatcher.base';
|
import { CreateEventDispatcherHook } from '../../../../../hooks/events/event-dispatcher.base';
|
||||||
import { useRoomEngineEvent } from '../../../../../hooks/events/nitro/room/room-engine-event';
|
|
||||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../../layout';
|
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../../layout';
|
||||||
import { useRoomContext } from '../../../context/RoomContext';
|
import { useRoomContext } from '../../../context/RoomContext';
|
||||||
import { FurnitureExchangeCreditData } from './FurnitureExchangeCreditData';
|
|
||||||
|
|
||||||
export const FurnitureExchangeCreditView: FC<{}> = props =>
|
export const FurnitureExchangeCreditView: FC<{}> = props =>
|
||||||
{
|
{
|
||||||
|
const [ objectId, setObjectId ] = useState(-1);
|
||||||
|
const [ value, setValue ] = useState(0);
|
||||||
const { eventDispatcher = null, widgetHandler = null } = useRoomContext();
|
const { eventDispatcher = null, widgetHandler = null } = useRoomContext();
|
||||||
const [ exchangeCreditData, setExchangeCreditData ] = useState<FurnitureExchangeCreditData>(null);
|
|
||||||
|
|
||||||
const onNitroEvent = useCallback((event: NitroEvent) =>
|
const onRoomWidgetUpdateCreditFurniEvent = useCallback((event: RoomWidgetUpdateCreditFurniEvent) =>
|
||||||
{
|
{
|
||||||
switch(event.type)
|
setObjectId(event.objectId);
|
||||||
{
|
setValue(event.value);
|
||||||
case RoomEngineTriggerWidgetEvent.REQUEST_CREDITFURNI: {
|
|
||||||
const widgetEvent = (event as RoomEngineTriggerWidgetEvent);
|
|
||||||
|
|
||||||
const roomObject = GetRoomEngine().getRoomObject(widgetEvent.roomId, widgetEvent.objectId, widgetEvent.category);
|
|
||||||
|
|
||||||
if(!roomObject || !IsOwnerOfFurniture(roomObject)) return;
|
|
||||||
|
|
||||||
const value = roomObject.model.getValue<number>(RoomObjectVariable.FURNITURE_CREDIT_VALUE);
|
|
||||||
|
|
||||||
setExchangeCreditData(new FurnitureExchangeCreditData(widgetEvent.objectId, widgetEvent.category, value));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
case RoomWidgetRoomObjectUpdateEvent.FURNI_REMOVED: {
|
|
||||||
const widgetEvent = (event as RoomWidgetRoomObjectUpdateEvent);
|
|
||||||
|
|
||||||
setExchangeCreditData(prevState =>
|
|
||||||
{
|
|
||||||
if(!prevState || (widgetEvent.id !== prevState.objectId) || (widgetEvent.category !== prevState.category)) return prevState;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_CREDITFURNI, onNitroEvent);
|
CreateEventDispatcherHook(RoomWidgetUpdateCreditFurniEvent.CREDIT_FURNI_UPDATE, eventDispatcher, onRoomWidgetUpdateCreditFurniEvent);
|
||||||
CreateEventDispatcherHook(RoomWidgetRoomObjectUpdateEvent.FURNI_REMOVED, eventDispatcher, onNitroEvent);
|
|
||||||
|
|
||||||
const processAction = useCallback((type: string, value: string = null) =>
|
const processAction = useCallback((type: string, value: string = null) =>
|
||||||
{
|
{
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case 'close':
|
case 'close':
|
||||||
setExchangeCreditData(null);
|
BatchUpdates(() =>
|
||||||
|
{
|
||||||
|
setObjectId(-1);
|
||||||
|
setValue(0);
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
case 'redeem':
|
case 'redeem':
|
||||||
if(!exchangeCreditData) return null;
|
widgetHandler.processWidgetMessage(new RoomWidgetCreditFurniRedeemMessage(RoomWidgetCreditFurniRedeemMessage.REDEEM, objectId));
|
||||||
|
|
||||||
GetRoomSession().connection.send(new FurnitureExchangeComposer(exchangeCreditData.objectId));
|
processAction('close');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, [exchangeCreditData]);
|
}, [ widgetHandler, objectId ]);
|
||||||
|
|
||||||
if(!exchangeCreditData) return null;
|
if(objectId === -1) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NitroCardView className="nitro-exchange-credit" simple={ true }>
|
<NitroCardView className="nitro-exchange-credit" simple={ true }>
|
||||||
<NitroCardHeaderView headerText={ LocalizeText('catalog.redeem.dialog.title') } onCloseClick={ event => processAction('close') } />
|
<NitroCardHeaderView headerText={ LocalizeText('catalog.redeem.dialog.title') } onCloseClick={ event => processAction('close') } />
|
||||||
<NitroCardContentView>
|
<NitroCardContentView>
|
||||||
<div className="text-black mb-2">
|
<div className="text-black mb-2">
|
||||||
{ LocalizeText('widgets.furniture.credit.redeem.value', [ 'value' ], [ exchangeCreditData.value.toString() ]) }
|
{ LocalizeText('widgets.furniture.credit.redeem.value', [ 'value' ], [ value.toString() ]) }
|
||||||
</div>
|
</div>
|
||||||
<button className="btn btn-success w-100" onClick={ event => processAction('redeem') }>{ LocalizeText('catalog.redeem.dialog.button.exchange') }</button>
|
<button className="btn btn-success w-100" onClick={ event => processAction('redeem') }>{ LocalizeText('catalog.redeem.dialog.button.exchange') }</button>
|
||||||
</NitroCardContentView>
|
</NitroCardContentView>
|
||||||
|
Loading…
Reference in New Issue
Block a user