mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-22 22:30:52 +01:00
RoomDimmer updates
This commit is contained in:
parent
0a615dffb6
commit
ecc6f26ae9
35
src/api/nitro/room/widgets/events/RoomDimmerPreset.ts
Normal file
35
src/api/nitro/room/widgets/events/RoomDimmerPreset.ts
Normal file
@ -0,0 +1,35 @@
|
||||
export class RoomDimmerPreset
|
||||
{
|
||||
private _id: number = 0;
|
||||
private _type: number = 0;
|
||||
private _color: number = 0;
|
||||
private _intensity: number = 0;
|
||||
|
||||
constructor(id: number, type: number, color: number, intensity: number)
|
||||
{
|
||||
this._id = id;
|
||||
this._type = type;
|
||||
this._color = color;
|
||||
this._intensity = intensity;
|
||||
}
|
||||
|
||||
public get id(): number
|
||||
{
|
||||
return this._id;
|
||||
}
|
||||
|
||||
public get type(): number
|
||||
{
|
||||
return this._type;
|
||||
}
|
||||
|
||||
public get color(): number
|
||||
{
|
||||
return this._color;
|
||||
}
|
||||
|
||||
public get _Str_4272(): number
|
||||
{
|
||||
return this._intensity;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
import { RoomWidgetUpdateEvent } from './RoomWidgetUpdateEvent';
|
||||
|
||||
export class RoomWidgetDimmerStateUpdateEvent extends RoomWidgetUpdateEvent
|
||||
{
|
||||
public static DIMMER_STATE: string = 'RWDSUE_DIMMER_STATE';
|
||||
|
||||
private _state: number;
|
||||
private _presetId: number;
|
||||
private _effectId: number;
|
||||
private _color: number;
|
||||
private _brightness: number;
|
||||
|
||||
constructor(state: number, presetId: number, effectId: number, color: number, brightness: number)
|
||||
{
|
||||
super(RoomWidgetDimmerStateUpdateEvent.DIMMER_STATE);
|
||||
|
||||
this._state = state;
|
||||
this._presetId = presetId;
|
||||
this._effectId = effectId;
|
||||
this._color = color;
|
||||
this._brightness = brightness;
|
||||
}
|
||||
|
||||
public get state(): number
|
||||
{
|
||||
return this._state;
|
||||
}
|
||||
|
||||
public get presetId(): number
|
||||
{
|
||||
return this._presetId;
|
||||
}
|
||||
|
||||
public get effectId(): number
|
||||
{
|
||||
return this._effectId;
|
||||
}
|
||||
|
||||
public get color(): number
|
||||
{
|
||||
return this._color;
|
||||
}
|
||||
|
||||
public get brightness(): number
|
||||
{
|
||||
return this._brightness;
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
import { RoomDimmerPreset } from './RoomDimmerPreset';
|
||||
import { RoomWidgetUpdateEvent } from './RoomWidgetUpdateEvent';
|
||||
|
||||
export class RoomWidgetDimmerUpdateEvent extends RoomWidgetUpdateEvent
|
||||
{
|
||||
public static PRESETS: string = 'RWDUE_PRESETS';
|
||||
public static HIDE: string = 'RWDUE_HIDE';
|
||||
|
||||
private _selectedPresetId: number = 0;
|
||||
private _presets: RoomDimmerPreset[];
|
||||
|
||||
constructor(type: string)
|
||||
{
|
||||
super(type);
|
||||
|
||||
this._presets = [];
|
||||
}
|
||||
|
||||
public get presetCount(): number
|
||||
{
|
||||
return this._presets.length;
|
||||
}
|
||||
|
||||
public get presets(): RoomDimmerPreset[]
|
||||
{
|
||||
return this._presets;
|
||||
}
|
||||
|
||||
public get selectedPresetId(): number
|
||||
{
|
||||
return this._selectedPresetId;
|
||||
}
|
||||
|
||||
public set selectedPresetId(k: number)
|
||||
{
|
||||
this._selectedPresetId = k;
|
||||
}
|
||||
|
||||
public setPresetValues(id: number, type: number, color: number, intensity: number):void
|
||||
{
|
||||
const preset = new RoomDimmerPreset(id, type, color, intensity);
|
||||
|
||||
this._presets[(id - 1)] = preset;
|
||||
}
|
||||
|
||||
public getPresetNumber(id: number): RoomDimmerPreset
|
||||
{
|
||||
return this._presets[id];
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ export * from './IPhotoData';
|
||||
export * from './RoomObjectItem';
|
||||
export * from './RoomWidgetAvatarInfoEvent';
|
||||
export * from './RoomWidgetChooserContentEvent';
|
||||
export * from './RoomWidgetDimmerUpdateEvent';
|
||||
export * from './RoomWidgetDoorbellEvent';
|
||||
export * from './RoomWidgetFloodControlEvent';
|
||||
export * from './RoomWidgetObjectNameEvent';
|
||||
|
@ -0,0 +1,111 @@
|
||||
import { NitroEvent, RoomControllerLevel, RoomEngineDimmerStateEvent, RoomEngineTriggerWidgetEvent, RoomSessionDimmerPresetsEvent, RoomWidgetEnum } from '@nitrots/nitro-renderer';
|
||||
import { GetRoomEngine } from '../..';
|
||||
import { GetSessionDataManager } from '../../..';
|
||||
import { RoomWidgetDimmerUpdateEvent, RoomWidgetUpdateEvent } from '../events';
|
||||
import { RoomWidgetDimmerStateUpdateEvent } from '../events/RoomWidgetDimmerStateUpdateEvent';
|
||||
import { RoomWidgetDimmerChangeStateMessage, RoomWidgetDimmerPreviewMessage, RoomWidgetFurniToWidgetMessage, RoomWidgetMessage } from '../messages';
|
||||
import { RoomWidgetDimmerSavePresetMessage } from '../messages/RoomWidgetDimmerSavePresetMessage';
|
||||
import { RoomWidgetHandler } from './RoomWidgetHandler';
|
||||
|
||||
export class FurnitureDimmerWidgetHandler extends RoomWidgetHandler
|
||||
{
|
||||
public processEvent(event: NitroEvent): void
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case RoomSessionDimmerPresetsEvent.ROOM_DIMMER_PRESETS: {
|
||||
const presetsEvent = (event as RoomSessionDimmerPresetsEvent);
|
||||
const updateEvent = new RoomWidgetDimmerUpdateEvent(RoomWidgetDimmerUpdateEvent.PRESETS);
|
||||
|
||||
updateEvent.selectedPresetId = presetsEvent.selectedPresetId;
|
||||
|
||||
let i = 0;
|
||||
|
||||
while(i < presetsEvent.presetCount)
|
||||
{
|
||||
const preset = presetsEvent.getPreset(i);
|
||||
|
||||
if(preset) updateEvent.setPresetValues(preset.id, preset.type, preset.color, preset.light);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
this.container.eventDispatcher.dispatchEvent(updateEvent);
|
||||
return;
|
||||
}
|
||||
case RoomEngineDimmerStateEvent.ROOM_COLOR: {
|
||||
const stateEvent = (event as RoomEngineDimmerStateEvent);
|
||||
|
||||
this.container.eventDispatcher.dispatchEvent(new RoomWidgetDimmerStateUpdateEvent(stateEvent.state, stateEvent.presetId, stateEvent.effectId, stateEvent.color, stateEvent.brightness));
|
||||
return;
|
||||
}
|
||||
case RoomEngineTriggerWidgetEvent.REMOVE_DIMMER: {
|
||||
this.container.eventDispatcher.dispatchEvent(new RoomWidgetDimmerUpdateEvent(RoomWidgetDimmerUpdateEvent.HIDE));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public processWidgetMessage(message: RoomWidgetMessage): RoomWidgetUpdateEvent
|
||||
{
|
||||
switch(message.type)
|
||||
{
|
||||
case RoomWidgetFurniToWidgetMessage.REQUEST_DIMMER: {
|
||||
if(this.canOpenWidget()) this.container.roomSession.requestMoodlightSettings();
|
||||
break;
|
||||
}
|
||||
case RoomWidgetDimmerSavePresetMessage.SAVE_PRESET: {
|
||||
if(this.canOpenWidget())
|
||||
{
|
||||
const savePresetMessage = (message as RoomWidgetDimmerSavePresetMessage);
|
||||
this.container.roomSession.updateMoodlightData(savePresetMessage.presetNumber, savePresetMessage.effectTypeId, savePresetMessage.color, savePresetMessage.brightness, savePresetMessage.apply);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case RoomWidgetDimmerChangeStateMessage.CHANGE_STATE: {
|
||||
if(this.canOpenWidget()) this.container.roomSession.toggleMoodlightState();
|
||||
break;
|
||||
}
|
||||
case RoomWidgetDimmerPreviewMessage.PREVIEW_DIMMER_PRESET: {
|
||||
const roomId = this.container.roomSession.roomId;
|
||||
const previewMessage = (message as RoomWidgetDimmerPreviewMessage);
|
||||
|
||||
if(!previewMessage || !GetRoomEngine()) return null;
|
||||
|
||||
GetRoomEngine().updateObjectRoomColor(roomId, previewMessage.color, previewMessage.brightness, previewMessage.bgOnly);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private canOpenWidget(): boolean
|
||||
{
|
||||
return (this.container.roomSession.isRoomOwner || (this.container.roomSession.controllerLevel >= RoomControllerLevel.GUEST) || GetSessionDataManager().isModerator);
|
||||
}
|
||||
|
||||
public get type(): string
|
||||
{
|
||||
return RoomWidgetEnum.ROOM_DIMMER;
|
||||
}
|
||||
|
||||
public get eventTypes(): string[]
|
||||
{
|
||||
return [
|
||||
RoomSessionDimmerPresetsEvent.ROOM_DIMMER_PRESETS,
|
||||
RoomEngineDimmerStateEvent.ROOM_COLOR,
|
||||
RoomEngineTriggerWidgetEvent.REMOVE_DIMMER
|
||||
];
|
||||
}
|
||||
|
||||
public get messageTypes(): string[]
|
||||
{
|
||||
return [
|
||||
RoomWidgetFurniToWidgetMessage.REQUEST_DIMMER,
|
||||
RoomWidgetDimmerSavePresetMessage.SAVE_PRESET,
|
||||
RoomWidgetDimmerChangeStateMessage.CHANGE_STATE,
|
||||
RoomWidgetDimmerPreviewMessage.PREVIEW_DIMMER_PRESET
|
||||
];
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@ export * from './DoorbellWidgetHandler';
|
||||
export * from './FurniChooserWidgetHandler';
|
||||
export * from './FurnitureContextMenuWidgetHandler';
|
||||
export * from './FurnitureCustomStackHeightWidgetHandler';
|
||||
export * from './FurnitureDimmerWidgetHandler';
|
||||
export * from './FurnitureExternalImageWidgetHandler';
|
||||
export * from './FurniturePresentWidgetHandler';
|
||||
export * from './IRoomWidgetHandler';
|
||||
|
@ -0,0 +1,11 @@
|
||||
import { RoomWidgetMessage } from './RoomWidgetMessage';
|
||||
|
||||
export class RoomWidgetDimmerChangeStateMessage extends RoomWidgetMessage
|
||||
{
|
||||
public static CHANGE_STATE: string = 'RWCDSM_CHANGE_STATE';
|
||||
|
||||
constructor()
|
||||
{
|
||||
super(RoomWidgetDimmerChangeStateMessage.CHANGE_STATE);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
import { RoomWidgetMessage } from './RoomWidgetMessage';
|
||||
|
||||
export class RoomWidgetDimmerPreviewMessage extends RoomWidgetMessage
|
||||
{
|
||||
public static PREVIEW_DIMMER_PRESET: string = 'RWDPM_PREVIEW_DIMMER_PRESET';
|
||||
|
||||
private _color: number;
|
||||
private _brightness: number;
|
||||
private _bgOnly: boolean;
|
||||
|
||||
constructor(color: number, brightness: number, bgOnly: boolean)
|
||||
{
|
||||
super(RoomWidgetDimmerPreviewMessage.PREVIEW_DIMMER_PRESET);
|
||||
|
||||
this._color = color;
|
||||
this._brightness = brightness;
|
||||
this._bgOnly = bgOnly;
|
||||
}
|
||||
|
||||
public get color(): number
|
||||
{
|
||||
return this._color;
|
||||
}
|
||||
|
||||
public get brightness(): number
|
||||
{
|
||||
return this._brightness;
|
||||
}
|
||||
|
||||
public get bgOnly(): boolean
|
||||
{
|
||||
return this._bgOnly;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
import { RoomWidgetMessage } from './RoomWidgetMessage';
|
||||
|
||||
export class RoomWidgetDimmerSavePresetMessage extends RoomWidgetMessage
|
||||
{
|
||||
public static SAVE_PRESET: string = 'RWSDPM_SAVE_PRESET';
|
||||
|
||||
private _presetNumber: number;
|
||||
private _effectTypeId: number;
|
||||
private _color: number;
|
||||
private _brightness: number;
|
||||
private _apply: boolean;
|
||||
|
||||
constructor(presetNumber: number, effectTypeId: number, color: number, brightness: number, apply: boolean)
|
||||
{
|
||||
super(RoomWidgetDimmerSavePresetMessage.SAVE_PRESET);
|
||||
|
||||
this._presetNumber = presetNumber;
|
||||
this._effectTypeId = effectTypeId;
|
||||
this._color = color;
|
||||
this._brightness = brightness;
|
||||
this._apply = apply;
|
||||
}
|
||||
|
||||
public get presetNumber(): number
|
||||
{
|
||||
return this._presetNumber;
|
||||
}
|
||||
|
||||
public get effectTypeId(): number
|
||||
{
|
||||
return this._effectTypeId;
|
||||
}
|
||||
|
||||
public get color(): number
|
||||
{
|
||||
return this._color;
|
||||
}
|
||||
|
||||
public get brightness(): number
|
||||
{
|
||||
return this._brightness;
|
||||
}
|
||||
|
||||
public get apply(): boolean
|
||||
{
|
||||
return this._apply;
|
||||
}
|
||||
}
|
@ -5,6 +5,9 @@ export * from './RoomWidgetChatMessage';
|
||||
export * from './RoomWidgetChatSelectAvatarMessage';
|
||||
export * from './RoomWidgetChatTypingMessage';
|
||||
export * from './RoomWidgetDanceMessage';
|
||||
export * from './RoomWidgetDimmerChangeStateMessage';
|
||||
export * from './RoomWidgetDimmerPreviewMessage';
|
||||
export * from './RoomWidgetDimmerSavePresetMessage';
|
||||
export * from './RoomWidgetFurniActionMessage';
|
||||
export * from './RoomWidgetFurniToWidgetMessage';
|
||||
export * from './RoomWidgetLetUserInMessage';
|
||||
|
BIN
src/assets/images/room-widgets/dimmer-widget/dimmer_banner.png
Normal file
BIN
src/assets/images/room-widgets/dimmer-widget/dimmer_banner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
@ -1,6 +1,6 @@
|
||||
import { EventDispatcher, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
||||
import { FC, useEffect, useRef, useState } from 'react';
|
||||
import { DispatchMouseEvent, DispatchTouchEvent, DoorbellWidgetHandler, FurniChooserWidgetHandler, FurnitureContextMenuWidgetHandler, FurnitureCustomStackHeightWidgetHandler, FurnitureExternalImageWidgetHandler, FurniturePresentWidgetHandler, GetNitroInstance, GetRoomEngine, InitializeRoomInstanceRenderingCanvas, IRoomWidgetHandlerManager, RoomWidgetAvatarInfoHandler, RoomWidgetChatHandler, RoomWidgetChatInputHandler, RoomWidgetHandlerManager, RoomWidgetInfostandHandler, RoomWidgetRoomToolsHandler, RoomWidgetUpdateRoomViewEvent, UserChooserWidgetHandler } from '../../api';
|
||||
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 { RoomContextProvider } from './context/RoomContext';
|
||||
import { RoomColorView } from './RoomColorView';
|
||||
import { RoomViewProps } from './RoomView.types';
|
||||
@ -42,6 +42,7 @@ export const RoomView: FC<RoomViewProps> = props =>
|
||||
widgetHandlerManager.registerHandler(new FurnitureCustomStackHeightWidgetHandler());
|
||||
widgetHandlerManager.registerHandler(new FurnitureExternalImageWidgetHandler());
|
||||
widgetHandlerManager.registerHandler(new FurniturePresentWidgetHandler());
|
||||
widgetHandlerManager.registerHandler(new FurnitureDimmerWidgetHandler());
|
||||
|
||||
setWidgetHandler(widgetHandlerManager);
|
||||
|
||||
|
@ -1,3 +1,9 @@
|
||||
.nitro-dimmer {
|
||||
width: 300px;
|
||||
|
||||
.dimmer-banner {
|
||||
width: 56px;
|
||||
height: 79px;
|
||||
background: url(../../../../../assets/images/room-widgets/dimmer-widget/dimmer_banner.png) center no-repeat;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
import { NitroEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable } from '@nitrots/nitro-renderer';
|
||||
import { FC, useCallback, useState } from 'react';
|
||||
import { LocalizeText } from '../../../../../api';
|
||||
import { GetRoomEngine, LocalizeText, RoomWidgetDimmerUpdateEvent, RoomWidgetRoomObjectUpdateEvent } from '../../../../../api';
|
||||
import { RoomWidgetDimmerStateUpdateEvent } from '../../../../../api/nitro/room/widgets/events/RoomWidgetDimmerStateUpdateEvent';
|
||||
import { RoomWidgetDimmerChangeStateMessage } from '../../../../../api/nitro/room/widgets/messages/RoomWidgetDimmerChangeStateMessage';
|
||||
import { CreateEventDispatcherHook, useRoomEngineEvent } from '../../../../../hooks';
|
||||
import { NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../../layout';
|
||||
import { useRoomContext } from '../../../context/RoomContext';
|
||||
import { FurnitureDimmerData } from './FurnitureDimmerData';
|
||||
@ -9,72 +13,78 @@ export const FurnitureDimmerView: FC<{}> = props =>
|
||||
const { eventDispatcher = null, widgetHandler = null } = useRoomContext();
|
||||
const [ dimmerData, setDimmerData ] = useState<FurnitureDimmerData>(null);
|
||||
|
||||
// const onNitroEvent = useCallback((event: NitroEvent) =>
|
||||
// {
|
||||
// switch(event.type)
|
||||
// {
|
||||
// case RoomEngineTriggerWidgetEvent.REQUEST_DIMMER: {
|
||||
// const widgetEvent = (event as RoomEngineTriggerWidgetEvent);
|
||||
|
||||
// const roomObject = GetRoomEngine().getRoomObject(widgetEvent.roomId, widgetEvent.objectId, widgetEvent.category);
|
||||
|
||||
// if(!roomObject) return;
|
||||
|
||||
// const data = roomObject.model.getValue<string[]>(RoomObjectVariable.FURNITURE_DATA);
|
||||
|
||||
// console.log('data', data);
|
||||
const onNitroEvent = useCallback((event: NitroEvent) =>
|
||||
{
|
||||
switch(event.type)
|
||||
{
|
||||
case RoomEngineTriggerWidgetEvent.REQUEST_DIMMER: {
|
||||
const widgetEvent = (event as RoomEngineTriggerWidgetEvent);
|
||||
console.log(widgetEvent);
|
||||
|
||||
// setDimmerData(new FurnitureDimmerData(widgetEvent.objectId, widgetEvent.category, false));
|
||||
// return;
|
||||
// }
|
||||
// case RoomWidgetRoomObjectUpdateEvent.FURNI_REMOVED: {
|
||||
// const widgetEvent = (event as RoomWidgetRoomObjectUpdateEvent);
|
||||
const roomObject = GetRoomEngine().getRoomObject(widgetEvent.roomId, widgetEvent.objectId, widgetEvent.category);
|
||||
|
||||
if(!roomObject) return;
|
||||
|
||||
// setDimmerData(prevState =>
|
||||
// {
|
||||
// if(!prevState || (widgetEvent.id !== prevState.objectId) || (widgetEvent.category !== prevState.category)) return prevState;
|
||||
const data = roomObject.model.getValue<string[]>(RoomObjectVariable.FURNITURE_DATA);
|
||||
|
||||
setDimmerData(new FurnitureDimmerData(widgetEvent.objectId, widgetEvent.category, false));
|
||||
return;
|
||||
}
|
||||
case RoomWidgetRoomObjectUpdateEvent.FURNI_REMOVED: {
|
||||
const widgetEvent = (event as RoomWidgetRoomObjectUpdateEvent);
|
||||
|
||||
// return null;
|
||||
// });
|
||||
// return;
|
||||
// }
|
||||
// case RoomWidgetDimmerUpdateEvent.RWDUE_PRESETS: {
|
||||
// const widgetEvent = (event as RoomWidgetDimmerUpdateEvent);
|
||||
setDimmerData(prevState =>
|
||||
{
|
||||
if(!prevState || (widgetEvent.id !== prevState.objectId) || (widgetEvent.category !== prevState.category)) return prevState;
|
||||
|
||||
// console.log(widgetEvent);
|
||||
// return;
|
||||
// }
|
||||
// case RoomWidgetDimmerStateUpdateEvent.RWDSUE_DIMMER_STATE: {
|
||||
// const widgetEvent = (event as RoomWidgetDimmerStateUpdateEvent);
|
||||
return null;
|
||||
});
|
||||
return;
|
||||
}
|
||||
case RoomWidgetDimmerUpdateEvent.PRESETS: {
|
||||
const widgetEvent = (event as RoomWidgetDimmerUpdateEvent);
|
||||
|
||||
// console.log(widgetEvent);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// }, []);
|
||||
console.log(widgetEvent);
|
||||
return;
|
||||
}
|
||||
case RoomWidgetDimmerStateUpdateEvent.DIMMER_STATE: {
|
||||
const widgetEvent = (event as RoomWidgetDimmerStateUpdateEvent);
|
||||
|
||||
// useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_DIMMER, onNitroEvent);
|
||||
// CreateEventDispatcherHook(RoomWidgetRoomObjectUpdateEvent.FURNI_REMOVED, props.events, onNitroEvent);
|
||||
// CreateEventDispatcherHook(RoomWidgetDimmerUpdateEvent.RWDUE_PRESETS, props.events, onNitroEvent);
|
||||
// CreateEventDispatcherHook(RoomWidgetDimmerStateUpdateEvent.RWDSUE_DIMMER_STATE, props.events, onNitroEvent);
|
||||
console.log(widgetEvent);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
useRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_DIMMER, onNitroEvent);
|
||||
CreateEventDispatcherHook(RoomWidgetRoomObjectUpdateEvent.FURNI_REMOVED, eventDispatcher, onNitroEvent);
|
||||
CreateEventDispatcherHook(RoomWidgetDimmerUpdateEvent.PRESETS, eventDispatcher, onNitroEvent);
|
||||
CreateEventDispatcherHook(RoomWidgetDimmerStateUpdateEvent.DIMMER_STATE, eventDispatcher, onNitroEvent);
|
||||
|
||||
const processAction = useCallback((type: string, value: string = null) =>
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case 'toggle_state':
|
||||
widgetHandler.processWidgetMessage(new RoomWidgetDimmerChangeStateMessage());
|
||||
return;
|
||||
case 'close':
|
||||
setDimmerData(null);
|
||||
return;
|
||||
}
|
||||
}, []);
|
||||
}, [ widgetHandler ]);
|
||||
|
||||
if(!dimmerData) return null;
|
||||
|
||||
return (
|
||||
<NitroCardView className="nitro-dimmer">
|
||||
<NitroCardHeaderView headerText={ LocalizeText('widget.dimmer.title') } onCloseClick={ event => processAction('close') } />
|
||||
<NitroCardView className="nitro-dimmer" simple={ true }>
|
||||
<NitroCardHeaderView headerText={ LocalizeText('widget.dimmer.title') } onCloseClick={ () => processAction('close') } />
|
||||
<NitroCardContentView>
|
||||
|
||||
{ !dimmerData.active && <div className="d-flex flex-column gap-2 align-items-center">
|
||||
<div className="dimmer-banner"></div>
|
||||
<div className="bg-muted rounded p-1 text-center text-black">{ LocalizeText('widget.dimmer.info.off') }</div>
|
||||
<button className="btn-success btn w-100" onClick={ () => processAction('toggle_state') }>{ LocalizeText('widget.dimmer.button.on') }</button>
|
||||
</div> }
|
||||
</NitroCardContentView>
|
||||
</NitroCardView>
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user