From 34c52c69eb4e145f9873c18ffb80f620673ab271 Mon Sep 17 00:00:00 2001 From: duckietm Date: Mon, 15 Jul 2024 08:29:05 +0200 Subject: [PATCH] :up Add area hider --- public/renderer-config.json | 8 +- .../views/editor/CameraWidgetEditorView.tsx | 2 +- .../furniture/FurnitureAreaHideView.tsx | 58 ++++++++++++ .../furniture/FurnitureWidgetsView.tsx | 6 +- src/hooks/rooms/widgets/furniture/index.ts | 1 + .../furniture/useFurnitureAreaHideWidget.ts | 93 +++++++++++++++++++ 6 files changed, 161 insertions(+), 7 deletions(-) create mode 100644 src/components/room/widgets/furniture/FurnitureAreaHideView.tsx create mode 100644 src/hooks/rooms/widgets/furniture/useFurnitureAreaHideWidget.ts diff --git a/public/renderer-config.json b/public/renderer-config.json index 50e07fb..88dd98f 100644 --- a/public/renderer-config.json +++ b/public/renderer-config.json @@ -27,11 +27,11 @@ "furni.rotation.bounce.steps": 20, "furni.rotation.bounce.height": 0.0625, "enable.avatar.arrow": false, - "system.log.debug": false, - "system.log.warn": false, - "system.log.error": false, + "system.log.debug": true, + "system.log.warn": true, + "system.log.error": true, "system.log.events": false, - "system.log.packets": false, + "system.log.packets": true, "system.fps.animation": 24, "system.fps.max": 60, "system.pong.manually": true, diff --git a/src/components/camera/views/editor/CameraWidgetEditorView.tsx b/src/components/camera/views/editor/CameraWidgetEditorView.tsx index 6341768..383bd8f 100644 --- a/src/components/camera/views/editor/CameraWidgetEditorView.tsx +++ b/src/components/camera/views/editor/CameraWidgetEditorView.tsx @@ -240,4 +240,4 @@ export const CameraWidgetEditorView: FC = props => ); -} +} \ No newline at end of file diff --git a/src/components/room/widgets/furniture/FurnitureAreaHideView.tsx b/src/components/room/widgets/furniture/FurnitureAreaHideView.tsx new file mode 100644 index 0000000..8b7bd82 --- /dev/null +++ b/src/components/room/widgets/furniture/FurnitureAreaHideView.tsx @@ -0,0 +1,58 @@ +import { GetRoomEngine } from '@nitrots/nitro-renderer'; +import { FC } from 'react'; +import { LocalizeText } from '../../../../api'; +import { Button, Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView, Text } from '../../../../common'; +import { useFurnitureAreaHideWidget } from '../../../../hooks'; + +export const FurnitureAreaHideView: FC<{}> = props => +{ + const { objectId = -1, isOn, setIsOn, wallItems, setWallItems, inverted, setInverted, invisibility, setInvisibility, onClose = null } = useFurnitureAreaHideWidget(); + + if(objectId === -1) return null; + + return ( + + + + + + { LocalizeText('wiredfurni.params.area_selection') } + { LocalizeText('wiredfurni.params.area_selection.info') } + + + + + + + + { LocalizeText('widget.areahide.options') } + + setWallItems(event.target.checked ? true : false) } /> + { LocalizeText('widget.areahide.options.wallitems') } + + + setInverted(event.target.checked ? true : false) } /> + + { LocalizeText('widget.areahide.options.invert') } + { LocalizeText('widget.areahide.options.invert.info') } + + + + setInvisibility(event.target.checked ? true : false) } /> + + { LocalizeText('widget.areahide.options.invisibility') } + { LocalizeText('widget.areahide.options.invisibility.info') } + + + + + + + ); +}; \ No newline at end of file diff --git a/src/components/room/widgets/furniture/FurnitureWidgetsView.tsx b/src/components/room/widgets/furniture/FurnitureWidgetsView.tsx index d0e4066..a237a49 100644 --- a/src/components/room/widgets/furniture/FurnitureWidgetsView.tsx +++ b/src/components/room/widgets/furniture/FurnitureWidgetsView.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { Base } from '../../../../common'; -import { FurnitureContextMenuView } from './context-menu/FurnitureContextMenuView'; +import { FurnitureAreaHideView } from './FurnitureAreaHideView'; import { FurnitureBackgroundColorView } from './FurnitureBackgroundColorView'; import { FurnitureBadgeDisplayView } from './FurnitureBadgeDisplayView'; import { FurnitureCraftingView } from './FurnitureCraftingView'; @@ -18,6 +18,7 @@ import { FurnitureStackHeightView } from './FurnitureStackHeightView'; import { FurnitureStickieView } from './FurnitureStickieView'; import { FurnitureTrophyView } from './FurnitureTrophyView'; import { FurnitureYoutubeDisplayView } from './FurnitureYoutubeDisplayView'; +import { FurnitureContextMenuView } from './context-menu/FurnitureContextMenuView'; import { FurniturePlaylistEditorWidgetView } from './playlist-editor/FurniturePlaylistEditorWidgetView'; export const FurnitureWidgetsView: FC<{}> = props => @@ -43,6 +44,7 @@ export const FurnitureWidgetsView: FC<{}> = props => + ); -} +}; \ No newline at end of file diff --git a/src/hooks/rooms/widgets/furniture/index.ts b/src/hooks/rooms/widgets/furniture/index.ts index 37fa573..d9eccba 100644 --- a/src/hooks/rooms/widgets/furniture/index.ts +++ b/src/hooks/rooms/widgets/furniture/index.ts @@ -1,3 +1,4 @@ +export * from './useFurnitureAreaHideWidget'; export * from './useFurnitureBackgroundColorWidget'; export * from './useFurnitureBadgeDisplayWidget'; export * from './useFurnitureContextMenuWidget'; diff --git a/src/hooks/rooms/widgets/furniture/useFurnitureAreaHideWidget.ts b/src/hooks/rooms/widgets/furniture/useFurnitureAreaHideWidget.ts new file mode 100644 index 0000000..a454401 --- /dev/null +++ b/src/hooks/rooms/widgets/furniture/useFurnitureAreaHideWidget.ts @@ -0,0 +1,93 @@ +import { GetRoomEngine, RoomAreaSelectionManager, RoomEngineAreaHideStateEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable } from '@nitrots/nitro-renderer'; +import { useEffect, useState } from 'react'; +import { CanManipulateFurniture } from '../../../../api'; +import { useNitroEvent } from '../../../events'; +import { useRoom } from '../../useRoom'; + +const useFurnitureAreaHideWidgetState = () => +{ + const [ objectId, setObjectId ] = useState(-1); + const [ category, setCategory ] = useState(-1); + const [ isOn, setIsOn ] = useState(false); + const [ rootX, setRootX ] = useState(0); + const [ rootY, setRootY ] = useState(0); + const [ width, setWidth ] = useState(0); + const [ length, setLength ] = useState(0); + const [ invisibility, setInvisibility ] = useState(false); + const [ wallItems, setWallItems ] = useState(false); + const [ inverted, setInverted ] = useState(false); + const { roomSession = null } = useRoom(); + + const onClose = () => + { + setObjectId(-1); + setCategory(-1); + setIsOn(false); + setRootX(0); + setRootY(0); + setWidth(0); + setLength(0); + setInvisibility(false); + setWallItems(false); + setInverted(false); + + GetRoomEngine().areaSelectionManager.deactivate(); + }; + + useNitroEvent(RoomEngineTriggerWidgetEvent.REQUEST_AREA_HIDE, event => + { + if(!CanManipulateFurniture(roomSession, event.objectId, event.category)) return; + + setObjectId(event.objectId); + setCategory(event.category); + + const roomObject = GetRoomEngine().getRoomObject(event.roomId, event.objectId, event.category); + + const model = roomObject.model; + + setIsOn(roomObject.getState(0) === 1); + setRootX(model.getValue(RoomObjectVariable.FURNITURE_AREA_HIDE_ROOT_X) ?? 0); + setRootY(model.getValue(RoomObjectVariable.FURNITURE_AREA_HIDE_ROOT_Y) ?? 0); + setWidth(model.getValue(RoomObjectVariable.FURNITURE_AREA_HIDE_WIDTH) ?? 0); + setLength(model.getValue(RoomObjectVariable.FURNITURE_AREA_HIDE_LENGTH) ?? 0); + setInvisibility(model.getValue(RoomObjectVariable.FURNITURE_AREA_HIDE_INVISIBILITY) === 1); + setWallItems(model.getValue(RoomObjectVariable.FURNITURE_AREA_HIDE_WALL_ITEMS) === 1); + setInverted(model.getValue(RoomObjectVariable.FURNITURE_AREA_HIDE_INVERT) === 1); + }); + + useNitroEvent(RoomEngineAreaHideStateEvent.UPDATE_STATE_AREA_HIDE, event => + { + setObjectId(event.objectId); + setCategory(event.category); + setIsOn(event.isOn); + }); + + useEffect(() => + { + if(objectId === -1) return; + + if(!isOn) + { + const callback = (rootX: number, rootY: number, width: number, height: number) => + { + setRootX(rootX); + setRootY(rootY); + setWidth(width); + setLength(height); + }; + + if(GetRoomEngine().areaSelectionManager.activate(callback, RoomAreaSelectionManager.HIGHLIGHT_DARKEN)) + { + GetRoomEngine().areaSelectionManager.setHighlight(rootX, rootY, width, length); + } + } + else + { + GetRoomEngine().areaSelectionManager.deactivate(); + } + }, [ objectId, isOn, rootX, rootY, width, length ]); + + return { objectId, category, isOn, setIsOn, rootX, setRootX, rootY, setRootY, width, setWidth, length, setLength, invisibility, setInvisibility, wallItems, setWallItems, inverted, setInverted, onClose }; +}; + +export const useFurnitureAreaHideWidget = useFurnitureAreaHideWidgetState; \ No newline at end of file