mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
feat: update room control widgets and menus
This commit is contained in:
@@ -28,7 +28,7 @@ export const AvatarInfoWidgetAvatarView: FC<AvatarInfoWidgetAvatarViewProps> = p
|
||||
const [ mode, setMode ] = useState(MODE_NORMAL);
|
||||
const { canRequestFriend = null } = useFriends();
|
||||
const { report = null } = useHelp();
|
||||
const { roomSession = null } = useRoom();
|
||||
const { roomSession = null, isHandItemBlocked = false } = useRoom();
|
||||
const { userRespectRemaining = 0, respectUser = null } = useSessionInfo();
|
||||
const { openInspectionForUser, showInspectButton } = useWiredTools();
|
||||
|
||||
@@ -49,6 +49,8 @@ export const AvatarInfoWidgetAvatarView: FC<AvatarInfoWidgetAvatarViewProps> = p
|
||||
|
||||
const canGiveHandItem = useMemo(() =>
|
||||
{
|
||||
if(isHandItemBlocked) return false;
|
||||
|
||||
let flag = false;
|
||||
|
||||
const roomObject = GetOwnRoomObject();
|
||||
@@ -61,7 +63,7 @@ export const AvatarInfoWidgetAvatarView: FC<AvatarInfoWidgetAvatarViewProps> = p
|
||||
}
|
||||
|
||||
return flag;
|
||||
}, []);
|
||||
}, [ isHandItemBlocked ]);
|
||||
|
||||
const processAction = (name: string) =>
|
||||
{
|
||||
|
||||
@@ -21,11 +21,13 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
||||
{
|
||||
const { avatarInfo = null, onClose = null } = props;
|
||||
const [ mode, setMode ] = useState(MODE_NORMAL);
|
||||
const { roomSession = null } = useRoom();
|
||||
const { roomSession = null, isHandItemBlocked = false } = useRoom();
|
||||
const { petRespectRemaining = 0, respectPet = null } = useSessionInfo();
|
||||
|
||||
const canGiveHandItem = useMemo(() =>
|
||||
{
|
||||
if(isHandItemBlocked) return false;
|
||||
|
||||
let flag = false;
|
||||
|
||||
const roomObject = GetOwnRoomObject();
|
||||
@@ -38,7 +40,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
||||
}
|
||||
|
||||
return flag;
|
||||
}, []);
|
||||
}, [ isHandItemBlocked ]);
|
||||
|
||||
const processAction = (name: string) =>
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
||||
{
|
||||
const { avatarInfo = null, onClose = null } = props;
|
||||
const [ mode, setMode ] = useState(MODE_NORMAL);
|
||||
const { roomSession = null } = useRoom();
|
||||
const { roomSession = null, isHandItemBlocked = false } = useRoom();
|
||||
const { petRespectRemaining = 0, respectPet = null } = useSessionInfo();
|
||||
|
||||
const canPickUp = useMemo(() =>
|
||||
@@ -31,6 +31,8 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
||||
|
||||
const canGiveHandItem = useMemo(() =>
|
||||
{
|
||||
if(isHandItemBlocked) return false;
|
||||
|
||||
let flag = false;
|
||||
|
||||
const roomObject = GetOwnRoomObject();
|
||||
@@ -43,7 +45,7 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
||||
}
|
||||
|
||||
return flag;
|
||||
}, []);
|
||||
}, [ isHandItemBlocked ]);
|
||||
|
||||
const processAction = (name: string) =>
|
||||
{
|
||||
|
||||
@@ -108,8 +108,15 @@ export const ContextMenuView: FC<ContextMenuViewProps> = ({
|
||||
|
||||
const update = () => {
|
||||
if (!elementRef.current) return;
|
||||
const bounds = GetRoomObjectBounds(GetRoomSession().roomId, objectId, category);
|
||||
const location = GetRoomObjectScreenLocation(GetRoomSession().roomId, objectId, category);
|
||||
const roomSession = GetRoomSession();
|
||||
|
||||
if (!roomSession) {
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
|
||||
const bounds = GetRoomObjectBounds(roomSession.roomId, objectId, category);
|
||||
const location = GetRoomObjectScreenLocation(roomSession.roomId, objectId, category);
|
||||
updatePosition(bounds, location);
|
||||
};
|
||||
|
||||
@@ -117,7 +124,7 @@ export const ContextMenuView: FC<ContextMenuViewProps> = ({
|
||||
ticker.add(update);
|
||||
|
||||
return () => ticker.remove(update);
|
||||
}, [objectId, category, updatePosition]);
|
||||
}, [objectId, category, updatePosition, onClose]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!fades) return;
|
||||
@@ -141,4 +148,4 @@ export const ContextMenuView: FC<ContextMenuViewProps> = ({
|
||||
{collapsable && <ContextMenuCaretView collapsed={isCollapsed} onClick={() => setIsCollapsed((prev) => !prev)} />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import { useFurnitureAreaHideWidget } from '../../../../hooks';
|
||||
|
||||
export const FurnitureAreaHideView: FC<{}> = props =>
|
||||
{
|
||||
const { objectId = -1, isOn, setIsOn, wallItems, setWallItems, inverted, setInverted, invisibility, setInvisibility, onClose = null } = useFurnitureAreaHideWidget();
|
||||
const { objectId = -1, isOn, wallItems, setWallItems, inverted, setInverted, invisibility, setInvisibility, saveChanges = null, onClose = null } = useFurnitureAreaHideWidget();
|
||||
|
||||
if(objectId === -1) return null;
|
||||
|
||||
@@ -49,10 +49,10 @@ export const FurnitureAreaHideView: FC<{}> = props =>
|
||||
</Column>
|
||||
</Flex>
|
||||
</Column>
|
||||
<Button fullWidth variant="primary">
|
||||
<Button fullWidth variant="primary" onClick={ saveChanges }>
|
||||
{ LocalizeText(isOn ? 'widget.dimmer.button.off' : 'widget.dimmer.button.on') }
|
||||
</Button>
|
||||
</NitroCardContentView>
|
||||
</NitroCardView>
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { FC } from 'react';
|
||||
import { FurnitureBackgroundColorView } from './FurnitureBackgroundColorView';
|
||||
import { FurnitureAreaHideView } from './FurnitureAreaHideView';
|
||||
import { FurnitureBadgeDisplayView } from './FurnitureBadgeDisplayView';
|
||||
import { FurnitureCraftingView } from './FurnitureCraftingView';
|
||||
import { FurnitureDimmerView } from './FurnitureDimmerView';
|
||||
@@ -23,6 +24,7 @@ export const FurnitureWidgetsView: FC<{}> = props =>
|
||||
{
|
||||
return (
|
||||
<>
|
||||
<FurnitureAreaHideView />
|
||||
<FurnitureBackgroundColorView />
|
||||
<FurnitureBadgeDisplayView />
|
||||
<FurnitureCraftingView />
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { ColorConverter, GetRenderer, GetRoomEngine, GetStage, IRoomSession, NitroAdjustmentFilter, NitroSprite, NitroTexture, RoomBackgroundColorEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomGeometry, RoomId, RoomObjectCategory, RoomObjectHSLColorEnabledEvent, RoomObjectOperationType, RoomSessionEvent, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
||||
import { ColorConverter, GetRenderer, GetRoomEngine, GetStage, HanditemBlockStateMessageEvent, IRoomSession, NitroAdjustmentFilter, NitroSprite, NitroTexture, RoomBackgroundColorEvent, RoomEngineEvent, RoomEngineObjectEvent, RoomGeometry, RoomId, RoomObjectCategory, RoomObjectHSLColorEnabledEvent, RoomObjectOperationType, RoomSessionEvent, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useBetween } from 'use-between';
|
||||
import { CanManipulateFurniture, DispatchUiEvent, GetRoomSession, IsFurnitureSelectionDisabled, ProcessRoomObjectOperation, RoomWidgetUpdateBackgroundColorPreviewEvent, RoomWidgetUpdateRoomObjectEvent, SetActiveRoomId, StartRoomSession } from '../../api';
|
||||
import { useNitroEvent, useUiEvent } from '../events';
|
||||
import { useMessageEvent, useNitroEvent, useUiEvent } from '../events';
|
||||
|
||||
const useRoomState = () =>
|
||||
{
|
||||
const [roomSession, setRoomSession] = useState<IRoomSession>(null);
|
||||
const [isHandItemBlocked, setIsHandItemBlocked] = useState(false);
|
||||
const [roomBackground, setRoomBackground] = useState<NitroSprite>(null);
|
||||
const [roomFilter, setRoomFilter] = useState<NitroAdjustmentFilter>(null);
|
||||
const [originalRoomBackgroundColor, setOriginalRoomBackgroundColor] = useState(0);
|
||||
@@ -91,9 +92,11 @@ const useRoomState = () =>
|
||||
case RoomEngineEvent.INITIALIZED:
|
||||
SetActiveRoomId(event.roomId);
|
||||
setRoomSession(session);
|
||||
setIsHandItemBlocked(false);
|
||||
return;
|
||||
case RoomEngineEvent.DISPOSED:
|
||||
setRoomSession(null);
|
||||
setIsHandItemBlocked(false);
|
||||
return;
|
||||
}
|
||||
});
|
||||
@@ -110,10 +113,22 @@ const useRoomState = () =>
|
||||
return;
|
||||
case RoomSessionEvent.ENDED:
|
||||
setRoomSession(null);
|
||||
setIsHandItemBlocked(false);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
useMessageEvent<HanditemBlockStateMessageEvent>(HanditemBlockStateMessageEvent, event =>
|
||||
{
|
||||
const parser = event.getParser();
|
||||
const session = (roomSession || GetRoomSession());
|
||||
|
||||
if(!parser || !session) return;
|
||||
if(parser.stateData.roomId !== session.roomId) return;
|
||||
|
||||
setIsHandItemBlocked(parser.stateData.blocked);
|
||||
});
|
||||
|
||||
useNitroEvent<RoomEngineObjectEvent>([
|
||||
RoomEngineObjectEvent.SELECTED,
|
||||
RoomEngineObjectEvent.DESELECTED,
|
||||
@@ -281,7 +296,7 @@ const useRoomState = () =>
|
||||
};
|
||||
}, [roomSession]);
|
||||
|
||||
return { roomSession };
|
||||
return { roomSession, isHandItemBlocked };
|
||||
};
|
||||
|
||||
export const useRoom = () => useBetween(useRoomState);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { GetRoomEngine, RoomAreaSelectionManager, RoomEngineAreaHideStateEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable } from '@nitrots/nitro-renderer';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { CanManipulateFurniture } from '../../../../api';
|
||||
import { FurnitureMultiStateComposer, GetRoomEngine, RoomAreaSelectionManager, RoomEngineAreaHideStateEvent, RoomEngineTriggerWidgetEvent, RoomObjectVariable, SetObjectDataMessageComposer } from '@nitrots/nitro-renderer';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { CanManipulateFurniture, SendMessageComposer } from '../../../../api';
|
||||
import { useNitroEvent } from '../../../events';
|
||||
import { useRoom } from '../../useRoom';
|
||||
|
||||
@@ -34,6 +34,27 @@ const useFurnitureAreaHideWidgetState = () =>
|
||||
GetRoomEngine().areaSelectionManager.deactivate();
|
||||
};
|
||||
|
||||
const saveChanges = useCallback(() =>
|
||||
{
|
||||
if(objectId === -1) return;
|
||||
|
||||
const data = new Map<string, string>();
|
||||
|
||||
data.set('state', isOn ? '1' : '0');
|
||||
data.set('rootX', rootX.toString());
|
||||
data.set('rootY', rootY.toString());
|
||||
data.set('width', width.toString());
|
||||
data.set('length', length.toString());
|
||||
data.set('invisibility', invisibility ? '1' : '0');
|
||||
data.set('wallItems', wallItems ? '1' : '0');
|
||||
data.set('invert', inverted ? '1' : '0');
|
||||
|
||||
SendMessageComposer(new SetObjectDataMessageComposer(objectId, data));
|
||||
SendMessageComposer(new FurnitureMultiStateComposer(objectId, isOn ? 0 : 1));
|
||||
|
||||
onClose();
|
||||
}, [ objectId, isOn, rootX, rootY, width, length, invisibility, wallItems, inverted ]);
|
||||
|
||||
useNitroEvent<RoomEngineTriggerWidgetEvent>(RoomEngineTriggerWidgetEvent.REQUEST_AREA_HIDE, event =>
|
||||
{
|
||||
if(!CanManipulateFurniture(roomSession, event.objectId, event.category)) return;
|
||||
@@ -44,20 +65,22 @@ const useFurnitureAreaHideWidgetState = () =>
|
||||
const roomObject = GetRoomEngine().getRoomObject(event.roomId, event.objectId, event.category);
|
||||
|
||||
const model = roomObject.model;
|
||||
const data = model.getValue<number[]>(RoomObjectVariable.FURNITURE_DATA) || [];
|
||||
|
||||
setIsOn(roomObject.getState(0) === 1);
|
||||
setRootX(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_ROOT_X) ?? 0);
|
||||
setRootY(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_ROOT_Y) ?? 0);
|
||||
setWidth(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_WIDTH) ?? 0);
|
||||
setLength(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_LENGTH) ?? 0);
|
||||
setInvisibility(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_INVISIBILITY) === 1);
|
||||
setWallItems(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_WALL_ITEMS) === 1);
|
||||
setInverted(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_INVERT) === 1);
|
||||
setRootX(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_ROOT_X) ?? data[1] ?? 0);
|
||||
setRootY(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_ROOT_Y) ?? data[2] ?? 0);
|
||||
setWidth(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_WIDTH) ?? data[3] ?? 0);
|
||||
setLength(model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_LENGTH) ?? data[4] ?? 0);
|
||||
setInvisibility((model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_INVISIBILITY) ?? data[5] ?? 0) === 1);
|
||||
setWallItems((model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_WALL_ITEMS) ?? data[6] ?? 0) === 1);
|
||||
setInverted((model.getValue<number>(RoomObjectVariable.FURNITURE_AREA_HIDE_INVERT) ?? data[7] ?? 0) === 1);
|
||||
});
|
||||
|
||||
useNitroEvent<RoomEngineAreaHideStateEvent>(RoomEngineAreaHideStateEvent.UPDATE_STATE_AREA_HIDE, event =>
|
||||
{
|
||||
setObjectId(event.objectId);
|
||||
if(objectId !== event.objectId) return;
|
||||
|
||||
setCategory(event.category);
|
||||
setIsOn(event.isOn);
|
||||
});
|
||||
@@ -87,7 +110,7 @@ const useFurnitureAreaHideWidgetState = () =>
|
||||
}
|
||||
}, [ 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 };
|
||||
return { objectId, category, isOn, setIsOn, rootX, setRootX, rootY, setRootY, width, setWidth, length, setLength, invisibility, setInvisibility, wallItems, setWallItems, inverted, setInverted, saveChanges, onClose };
|
||||
};
|
||||
|
||||
export const useFurnitureAreaHideWidget = useFurnitureAreaHideWidgetState;
|
||||
export const useFurnitureAreaHideWidget = useFurnitureAreaHideWidgetState;
|
||||
|
||||
Reference in New Issue
Block a user