mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 14:40:50 +01:00
Exchange Credit Widget and fix Trophy title
This commit is contained in:
parent
f01eb065f3
commit
c55c0c1ee2
@ -1,3 +1,4 @@
|
|||||||
|
import { FurnitureExchangeCreditView } from './exchange-credit/FurnitureExchangeCreditView';
|
||||||
import { FurnitureWidgetsViewProps } from './FurnitureWidgetsView.types';
|
import { FurnitureWidgetsViewProps } from './FurnitureWidgetsView.types';
|
||||||
import { FurnitureHighScoreView } from './high-score/FurnitureHighScoreView';
|
import { FurnitureHighScoreView } from './high-score/FurnitureHighScoreView';
|
||||||
import { FurnitureManipulationMenuView } from './manipulation-menu/FurnitureManipulationMenuView';
|
import { FurnitureManipulationMenuView } from './manipulation-menu/FurnitureManipulationMenuView';
|
||||||
@ -12,6 +13,7 @@ export function FurnitureWidgetsView(props: FurnitureWidgetsViewProps): JSX.Elem
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="position-absolute nitro-room-widgets t-0 l-0">
|
<div className="position-absolute nitro-room-widgets t-0 l-0">
|
||||||
|
<FurnitureExchangeCreditView events={ events } />
|
||||||
<FurnitureHighScoreView events={ events } />
|
<FurnitureHighScoreView events={ events } />
|
||||||
<FurnitureManipulationMenuView events={ events } />
|
<FurnitureManipulationMenuView events={ events } />
|
||||||
<FurnitureMannequinView events={ events } />
|
<FurnitureMannequinView events={ events } />
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
export class FurnitureExchangeCreditData
|
||||||
|
{
|
||||||
|
constructor(
|
||||||
|
public objectId: number,
|
||||||
|
public category: number,
|
||||||
|
public value: number) {}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
import { FurnitureExchangeComposer, NitroEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable } from 'nitro-renderer';
|
||||||
|
import { FC, useCallback, useState } from 'react';
|
||||||
|
import { GetRoomEngine, GetRoomSession } from '../../../../../api';
|
||||||
|
import { CreateEventDispatcherHook } from '../../../../../hooks/events/event-dispatcher.base';
|
||||||
|
import { useRoomEngineEvent } from '../../../../../hooks/events/nitro/room/room-engine-event';
|
||||||
|
import { NitroCardContentView, NitroCardHeaderView } from '../../../../../layout';
|
||||||
|
import { NitroCardView } from '../../../../../layout/card/NitroCardView';
|
||||||
|
import { LocalizeText } from '../../../../../utils/LocalizeText';
|
||||||
|
import { RoomWidgetRoomObjectUpdateEvent } from '../../events';
|
||||||
|
import { FurnitureExchangeCreditData } from './FurnitureExchangeCreditData';
|
||||||
|
import { FurnitureExchangeCreditProps } from './FurnitureExchangeCreditView.types';
|
||||||
|
|
||||||
|
export const FurnitureExchangeCreditView: FC<FurnitureExchangeCreditProps> = props =>
|
||||||
|
{
|
||||||
|
const [ exchangeCreditData, setExchangeCreditData ] = useState<FurnitureExchangeCreditData>(null);
|
||||||
|
|
||||||
|
const onNitroEvent = useCallback((event: NitroEvent) =>
|
||||||
|
{
|
||||||
|
switch(event.type)
|
||||||
|
{
|
||||||
|
case RoomEngineTriggerWidgetEvent.REQUEST_CREDITFURNI: {
|
||||||
|
const widgetEvent = (event as RoomEngineTriggerWidgetEvent);
|
||||||
|
|
||||||
|
const roomObject = GetRoomEngine().getRoomObject(widgetEvent.roomId, widgetEvent.objectId, widgetEvent.category);
|
||||||
|
|
||||||
|
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(RoomWidgetRoomObjectUpdateEvent.FURNI_REMOVED, props.events, onNitroEvent);
|
||||||
|
|
||||||
|
const processAction = useCallback((type: string, value: string = null) =>
|
||||||
|
{
|
||||||
|
switch(type)
|
||||||
|
{
|
||||||
|
case 'close':
|
||||||
|
setExchangeCreditData(null);
|
||||||
|
return;
|
||||||
|
case 'redeem':
|
||||||
|
if(!exchangeCreditData) return null;
|
||||||
|
|
||||||
|
GetRoomSession().connection.send(new FurnitureExchangeComposer(exchangeCreditData.objectId));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if(!exchangeCreditData) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<NitroCardView className="nitro-friend-list">
|
||||||
|
<NitroCardHeaderView headerText={ LocalizeText('catalog.redeem.dialog.title') } onCloseClick={ event => processAction('close') } />
|
||||||
|
<NitroCardContentView>
|
||||||
|
<div className="text-black mb-2">
|
||||||
|
{ LocalizeText('widgets.furniture.credit.redeem.value', [ 'value' ], [ exchangeCreditData.value.toString() ]) }
|
||||||
|
</div>
|
||||||
|
<button className="btn btn-success w-100" onClick={ event => processAction('redeem') }>{ LocalizeText('catalog.redeem.dialog.button.exchange') }</button>
|
||||||
|
</NitroCardContentView>
|
||||||
|
</NitroCardView>
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
import { FurnitureWidgetProps } from '../FurnitureWidget.types';
|
||||||
|
|
||||||
|
export interface FurnitureExchangeCreditProps extends FurnitureWidgetProps
|
||||||
|
{}
|
@ -4,6 +4,7 @@ import { GetRoomEngine } from '../../../../../api';
|
|||||||
import { DraggableWindow } from '../../../../../hooks/draggable-window/DraggableWindow';
|
import { DraggableWindow } from '../../../../../hooks/draggable-window/DraggableWindow';
|
||||||
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 { useRoomEngineEvent } from '../../../../../hooks/events/nitro/room/room-engine-event';
|
||||||
|
import { LocalizeText } from '../../../../../utils/LocalizeText';
|
||||||
import { RoomWidgetRoomObjectUpdateEvent } from '../../events';
|
import { RoomWidgetRoomObjectUpdateEvent } from '../../events';
|
||||||
import { FurnitureTrophyData } from './FurnitureTrophyData';
|
import { FurnitureTrophyData } from './FurnitureTrophyData';
|
||||||
import { FurnitureTrophyViewProps } from './FurnitureTrophyView.types';
|
import { FurnitureTrophyViewProps } from './FurnitureTrophyView.types';
|
||||||
@ -74,7 +75,7 @@ export const FurnitureTrophyView: FC<FurnitureTrophyViewProps> = props =>
|
|||||||
<div className="trophy-header drag-handler">
|
<div className="trophy-header drag-handler">
|
||||||
<div className="float-end trophy-close" onClick={ event => processAction('close') }></div>
|
<div className="float-end trophy-close" onClick={ event => processAction('close') }></div>
|
||||||
<div className="trophy-title fw-bold text-center">
|
<div className="trophy-title fw-bold text-center">
|
||||||
Trophy
|
{ LocalizeText('widget.furni.trophy.title') }
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="trophy-content">
|
<div className="trophy-content">
|
||||||
|
Loading…
Reference in New Issue
Block a user