mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 15:40:51 +01:00
Fix floor editor
This commit is contained in:
parent
ed8143f7ee
commit
6ac361443b
@ -1,8 +1,7 @@
|
|||||||
import { AvatarExpressionEnum, HabboClubLevelEnum, NitroEvent, RoomControllerLevel, RoomRotatingEffect, RoomSessionChatEvent, RoomSettingsComposer, RoomShakingEffect, RoomWidgetEnum, RoomZoomEvent, TextureUtils } from '@nitrots/nitro-renderer';
|
import { AvatarExpressionEnum, HabboClubLevelEnum, NitroEvent, RoomControllerLevel, RoomRotatingEffect, RoomSessionChatEvent, RoomSettingsComposer, RoomShakingEffect, RoomWidgetEnum, RoomZoomEvent, TextureUtils } from '@nitrots/nitro-renderer';
|
||||||
import { GetClubMemberLevel, GetConfiguration, GetNitroInstance, SendMessageComposer } from '../../..';
|
import { GetClubMemberLevel, GetConfiguration, GetNitroInstance, SendMessageComposer } from '../../..';
|
||||||
import { GetRoomEngine, GetSessionDataManager, LocalizeText, NotificationUtilities } from '../../../..';
|
import { GetRoomEngine, GetSessionDataManager, LocalizeText, NotificationUtilities } from '../../../..';
|
||||||
import { FloorplanEditorEvent } from '../../../../../events/floorplan-editor/FloorplanEditorEvent';
|
import { CreateLinkEvent } from '../../../CreateLinkEvent';
|
||||||
import { DispatchUiEvent } from '../../../../../hooks';
|
|
||||||
import { RoomWidgetFloodControlEvent, RoomWidgetUpdateEvent } from '../events';
|
import { RoomWidgetFloodControlEvent, RoomWidgetUpdateEvent } from '../events';
|
||||||
import { RoomWidgetChatMessage, RoomWidgetChatSelectAvatarMessage, RoomWidgetChatTypingMessage, RoomWidgetMessage, RoomWidgetRequestWidgetMessage } from '../messages';
|
import { RoomWidgetChatMessage, RoomWidgetChatSelectAvatarMessage, RoomWidgetChatTypingMessage, RoomWidgetMessage, RoomWidgetRequestWidgetMessage } from '../messages';
|
||||||
import { RoomWidgetHandler } from './RoomWidgetHandler';
|
import { RoomWidgetHandler } from './RoomWidgetHandler';
|
||||||
@ -158,11 +157,7 @@ export class RoomWidgetChatInputHandler extends RoomWidgetHandler
|
|||||||
return null;
|
return null;
|
||||||
case ':floor':
|
case ':floor':
|
||||||
case ':bcfloor':
|
case ':bcfloor':
|
||||||
if(this.container.roomSession.controllerLevel >= RoomControllerLevel.ROOM_OWNER)
|
if(this.container.roomSession.controllerLevel >= RoomControllerLevel.ROOM_OWNER) CreateLinkEvent('floor-editor/show');
|
||||||
{
|
|
||||||
//this.container.processWidgetMessage(new RoomWidgetRequestWidgetMessage(RoomWidgetRequestWidgetMessage.FLOOR_EDITOR));
|
|
||||||
DispatchUiEvent(new FloorplanEditorEvent(FloorplanEditorEvent.SHOW_FLOORPLAN_EDITOR));
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
case ':togglefps': {
|
case ':togglefps': {
|
||||||
|
@ -17,9 +17,6 @@ const FloorplanEditorContext = createContext<IFloorplanEditorContext>({
|
|||||||
setVisualizationSettings: null
|
setVisualizationSettings: null
|
||||||
});
|
});
|
||||||
|
|
||||||
export const FloorplanEditorContextProvider: FC<ProviderProps<IFloorplanEditorContext>> = props =>
|
export const FloorplanEditorContextProvider: FC<ProviderProps<IFloorplanEditorContext>> = props => <FloorplanEditorContext.Provider { ...props } />;
|
||||||
{
|
|
||||||
return <FloorplanEditorContext.Provider value={ props.value }>{ props.children }</FloorplanEditorContext.Provider>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const useFloorplanEditorContext = () => useContext(FloorplanEditorContext);
|
export const useFloorplanEditorContext = () => useContext(FloorplanEditorContext);
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
import { FloorHeightMapEvent, NitroPoint, RoomEngineEvent, RoomVisualizationSettingsEvent, UpdateFloorPropertiesMessageComposer } from '@nitrots/nitro-renderer';
|
import { FloorHeightMapEvent, ILinkEventTracker, NitroPoint, RoomEngineEvent, RoomVisualizationSettingsEvent, UpdateFloorPropertiesMessageComposer } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useCallback, useEffect, useState } from 'react';
|
import { FC, useCallback, useEffect, useState } from 'react';
|
||||||
import { LocalizeText, SendMessageComposer } from '../../api';
|
import { AddEventLinkTracker, LocalizeText, RemoveLinkEventTracker, SendMessageComposer } from '../../api';
|
||||||
import { Button, ButtonGroup, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common';
|
import { Button, ButtonGroup, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../common';
|
||||||
import { FloorplanEditorEvent } from '../../events';
|
import { UseMessageEventHook, UseRoomEngineEvent } from '../../hooks';
|
||||||
import { UseMessageEventHook, UseRoomEngineEvent, UseUiEvent } from '../../hooks';
|
|
||||||
import { FloorplanEditor } from './common/FloorplanEditor';
|
import { FloorplanEditor } from './common/FloorplanEditor';
|
||||||
import { IFloorplanSettings } from './common/IFloorplanSettings';
|
import { IFloorplanSettings } from './common/IFloorplanSettings';
|
||||||
import { IVisualizationSettings } from './common/IVisualizationSettings';
|
import { IVisualizationSettings } from './common/IVisualizationSettings';
|
||||||
@ -33,25 +32,27 @@ export const FloorplanEditorView: FC<{}> = props =>
|
|||||||
thicknessFloor: 1
|
thicknessFloor: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
const onFloorplanEditorEvent = useCallback((event: FloorplanEditorEvent) =>
|
const saveFloorChanges = () =>
|
||||||
{
|
{
|
||||||
switch(event.type)
|
SendMessageComposer(new UpdateFloorPropertiesMessageComposer(
|
||||||
{
|
FloorplanEditor.instance.getCurrentTilemapString(),
|
||||||
case FloorplanEditorEvent.HIDE_FLOORPLAN_EDITOR:
|
FloorplanEditor.instance.doorLocation.x,
|
||||||
setIsVisible(false);
|
FloorplanEditor.instance.doorLocation.y,
|
||||||
break;
|
visualizationSettings.entryPointDir,
|
||||||
case FloorplanEditorEvent.SHOW_FLOORPLAN_EDITOR:
|
convertNumbersForSaving(visualizationSettings.thicknessWall),
|
||||||
setIsVisible(true);
|
convertNumbersForSaving(visualizationSettings.thicknessFloor),
|
||||||
break;
|
(visualizationSettings.wallHeight - 1)
|
||||||
case FloorplanEditorEvent.TOGGLE_FLOORPLAN_EDITOR:
|
));
|
||||||
setIsVisible(prevValue => !prevValue);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}, []);
|
|
||||||
|
|
||||||
UseUiEvent(FloorplanEditorEvent.HIDE_FLOORPLAN_EDITOR, onFloorplanEditorEvent);
|
const revertChanges = () =>
|
||||||
UseUiEvent(FloorplanEditorEvent.SHOW_FLOORPLAN_EDITOR, onFloorplanEditorEvent);
|
{
|
||||||
UseUiEvent(FloorplanEditorEvent.TOGGLE_FLOORPLAN_EDITOR, onFloorplanEditorEvent);
|
setVisualizationSettings({ wallHeight: originalFloorplanSettings.wallHeight, thicknessWall: originalFloorplanSettings.thicknessWall, thicknessFloor: originalFloorplanSettings.thicknessFloor, entryPointDir: originalFloorplanSettings.entryPointDir });
|
||||||
|
|
||||||
|
FloorplanEditor.instance.doorLocation = new NitroPoint(originalFloorplanSettings.entryPoint[0], originalFloorplanSettings.entryPoint[1]);
|
||||||
|
FloorplanEditor.instance.setTilemap(originalFloorplanSettings.tilemap, originalFloorplanSettings.reservedTiles);
|
||||||
|
FloorplanEditor.instance.renderTiles();
|
||||||
|
}
|
||||||
|
|
||||||
const onRoomEngineEvent = useCallback((event: RoomEngineEvent) =>
|
const onRoomEngineEvent = useCallback((event: RoomEngineEvent) =>
|
||||||
{
|
{
|
||||||
@ -113,27 +114,35 @@ export const FloorplanEditorView: FC<{}> = props =>
|
|||||||
|
|
||||||
UseMessageEventHook(RoomVisualizationSettingsEvent, onRoomVisualizationSettingsEvent);
|
UseMessageEventHook(RoomVisualizationSettingsEvent, onRoomVisualizationSettingsEvent);
|
||||||
|
|
||||||
const saveFloorChanges = () =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
SendMessageComposer(new UpdateFloorPropertiesMessageComposer(
|
const linkTracker: ILinkEventTracker = {
|
||||||
FloorplanEditor.instance.getCurrentTilemapString(),
|
linkReceived: (url: string) =>
|
||||||
FloorplanEditor.instance.doorLocation.x,
|
|
||||||
FloorplanEditor.instance.doorLocation.y,
|
|
||||||
visualizationSettings.entryPointDir,
|
|
||||||
convertNumbersForSaving(visualizationSettings.thicknessWall),
|
|
||||||
convertNumbersForSaving(visualizationSettings.thicknessFloor),
|
|
||||||
(visualizationSettings.wallHeight - 1)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
const revertChanges = () =>
|
|
||||||
{
|
{
|
||||||
setVisualizationSettings({ wallHeight: originalFloorplanSettings.wallHeight, thicknessWall: originalFloorplanSettings.thicknessWall, thicknessFloor: originalFloorplanSettings.thicknessFloor, entryPointDir: originalFloorplanSettings.entryPointDir });
|
const parts = url.split('/');
|
||||||
|
|
||||||
FloorplanEditor.instance.doorLocation = new NitroPoint(originalFloorplanSettings.entryPoint[0], originalFloorplanSettings.entryPoint[1]);
|
if(parts.length < 2) return;
|
||||||
FloorplanEditor.instance.setTilemap(originalFloorplanSettings.tilemap, originalFloorplanSettings.reservedTiles);
|
|
||||||
FloorplanEditor.instance.renderTiles();
|
switch(parts[1])
|
||||||
|
{
|
||||||
|
case 'show':
|
||||||
|
setIsVisible(true);
|
||||||
|
return;
|
||||||
|
case 'hide':
|
||||||
|
setIsVisible(false);
|
||||||
|
return;
|
||||||
|
case 'toggle':
|
||||||
|
setIsVisible(prevValue => !prevValue);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
eventUrlPrefix: 'floor-editor/'
|
||||||
|
};
|
||||||
|
|
||||||
|
AddEventLinkTracker(linkTracker);
|
||||||
|
|
||||||
|
return () => RemoveLinkEventTracker(linkTracker);
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
|
@ -5,15 +5,9 @@ import { SendMessageComposer } from '../../../api';
|
|||||||
import { Base, Button, Column, ColumnProps, Flex, Grid } from '../../../common';
|
import { Base, Button, Column, ColumnProps, Flex, Grid } from '../../../common';
|
||||||
import { UseMessageEventHook } from '../../../hooks';
|
import { UseMessageEventHook } from '../../../hooks';
|
||||||
import { FloorplanEditor } from '../common/FloorplanEditor';
|
import { FloorplanEditor } from '../common/FloorplanEditor';
|
||||||
import { IFloorplanSettings } from '../common/IFloorplanSettings';
|
|
||||||
import { useFloorplanEditorContext } from '../FloorplanEditorContext';
|
import { useFloorplanEditorContext } from '../FloorplanEditorContext';
|
||||||
|
|
||||||
interface FloorplanCanvasViewProps extends ColumnProps
|
export const FloorplanCanvasView: FC<ColumnProps> = props =>
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export const FloorplanCanvasView: FC<FloorplanCanvasViewProps> = props =>
|
|
||||||
{
|
{
|
||||||
const { gap = 1, children = null, ...rest } = props;
|
const { gap = 1, children = null, ...rest } = props;
|
||||||
const [ occupiedTilesReceived , setOccupiedTilesReceived ] = useState(false);
|
const [ occupiedTilesReceived , setOccupiedTilesReceived ] = useState(false);
|
||||||
@ -25,21 +19,17 @@ export const FloorplanCanvasView: FC<FloorplanCanvasViewProps> = props =>
|
|||||||
{
|
{
|
||||||
const parser = event.getParser();
|
const parser = event.getParser();
|
||||||
|
|
||||||
let newFloorPlanSettings: IFloorplanSettings = null;
|
|
||||||
|
|
||||||
setOriginalFloorplanSettings(prevValue =>
|
setOriginalFloorplanSettings(prevValue =>
|
||||||
{
|
{
|
||||||
const newValue = { ...prevValue };
|
const newValue = { ...prevValue };
|
||||||
|
|
||||||
newValue.reservedTiles = parser.blockedTilesMap;
|
newValue.reservedTiles = parser.blockedTilesMap;
|
||||||
|
|
||||||
newFloorPlanSettings = newValue;
|
FloorplanEditor.instance.setTilemap(newValue.tilemap, newValue.reservedTiles);
|
||||||
|
|
||||||
return newValue;
|
return newValue;
|
||||||
});
|
});
|
||||||
|
|
||||||
FloorplanEditor.instance.setTilemap(newFloorPlanSettings.tilemap, parser.blockedTilesMap);
|
|
||||||
|
|
||||||
setOccupiedTilesReceived(true);
|
setOccupiedTilesReceived(true);
|
||||||
|
|
||||||
elementRef.current.scrollTo((FloorplanEditor.instance.view.width / 3), 0);
|
elementRef.current.scrollTo((FloorplanEditor.instance.view.width / 3), 0);
|
||||||
|
@ -4,7 +4,7 @@ import classNames from 'classnames';
|
|||||||
import { FC, useEffect, useState } from 'react';
|
import { FC, useEffect, useState } from 'react';
|
||||||
import { CreateLinkEvent, GetGroupInformation, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../api';
|
import { CreateLinkEvent, GetGroupInformation, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../api';
|
||||||
import { Button, Column, Flex, LayoutBadgeImageView, LayoutRoomThumbnailView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text, UserProfileIconView } from '../../../common';
|
import { Button, Column, Flex, LayoutBadgeImageView, LayoutRoomThumbnailView, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text, UserProfileIconView } from '../../../common';
|
||||||
import { FloorplanEditorEvent, RoomWidgetThumbnailEvent } from '../../../events';
|
import { RoomWidgetThumbnailEvent } from '../../../events';
|
||||||
import { DispatchUiEvent } from '../../../hooks';
|
import { DispatchUiEvent } from '../../../hooks';
|
||||||
import { useNavigatorContext } from '../NavigatorContext';
|
import { useNavigatorContext } from '../NavigatorContext';
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ export const NavigatorRoomInfoView: FC<NavigatorRoomInfoViewProps> = props =>
|
|||||||
SendMessageComposer(new RoomMuteComposer());
|
SendMessageComposer(new RoomMuteComposer());
|
||||||
return;
|
return;
|
||||||
case 'open_floorplan_editor':
|
case 'open_floorplan_editor':
|
||||||
DispatchUiEvent(new FloorplanEditorEvent(FloorplanEditorEvent.TOGGLE_FLOORPLAN_EDITOR));
|
CreateLinkEvent('floor-editor/toggle');
|
||||||
return;
|
return;
|
||||||
case 'close':
|
case 'close':
|
||||||
onCloseClick();
|
onCloseClick();
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
import { NitroEvent } from '@nitrots/nitro-renderer';
|
|
||||||
|
|
||||||
export class FloorplanEditorEvent extends NitroEvent
|
|
||||||
{
|
|
||||||
public static SHOW_FLOORPLAN_EDITOR: string = 'FPEE_SHOW_FLOORPLAN_EDITOR';
|
|
||||||
public static HIDE_FLOORPLAN_EDITOR: string = 'FPEE_HIDE_FLOORPLAN_EDITOR';
|
|
||||||
public static TOGGLE_FLOORPLAN_EDITOR: string = 'FPEE_TOGGLE_FLOORPLAN_EDITOR';
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
export * from './FloorplanEditorEvent';
|
|
@ -1,5 +1,4 @@
|
|||||||
export * from './catalog';
|
export * from './catalog';
|
||||||
export * from './floorplan-editor';
|
|
||||||
export * from './guide-tool';
|
export * from './guide-tool';
|
||||||
export * from './help';
|
export * from './help';
|
||||||
export * from './mod-tools';
|
export * from './mod-tools';
|
||||||
|
Loading…
Reference in New Issue
Block a user