This commit is contained in:
Bill 2022-07-23 21:15:24 -04:00
parent 0c03fa6d4f
commit 51db1f3aa3
9 changed files with 94 additions and 82 deletions

View File

@ -12,15 +12,15 @@ interface AvatarInfoWidgetOwnPetViewProps
close: () => void;
}
const _Str_2906: number = 0;
const _Str_5818: number = 1;
const _Str_5938: number = 2;
const _Str_10946: number = 3;
const MODE_NORMAL: number = 0;
const MODE_SADDLED_UP: number = 1;
const MODE_RIDING: number = 2;
const MODE_MONSTER_PLANT: number = 3;
export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = props =>
{
const { avatarInfo = null, close = null } = props;
const [ mode, setMode ] = useState(_Str_2906);
const [ mode, setMode ] = useState(MODE_NORMAL);
const [ respectsLeft, setRespectsLeft ] = useState(0);
const { roomSession = null } = useRoom();
@ -90,7 +90,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
roomSession.removePetSaddle(avatarInfo.id);
break;
case 'breed':
if(mode === _Str_2906)
if(mode === MODE_NORMAL)
{
// _local_7 = RoomWidgetPetCommandMessage._Str_16282;
// _local_8 = ("pet.command." + _local_7);
@ -98,7 +98,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
// _local_4 = new RoomWidgetPetCommandMessage(RoomWidgetPetCommandMessage.RWPCM_PET_COMMAND, this._Str_594.id, ((this._Str_594.name + " ") + _local_9));
}
else if(mode === _Str_10946)
else if(mode === MODE_MONSTER_PLANT)
{
// messageType = RoomWidgetUserActionMessage.REQUEST_BREED_PET;
}
@ -125,11 +125,11 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
{
setMode(prevValue =>
{
if(avatarInfo.petType === PetType.MONSTERPLANT) return _Str_10946;
else if(avatarInfo.saddle && !avatarInfo.rider) return _Str_5818;
else if(avatarInfo.rider) return _Str_5938;
if(avatarInfo.petType === PetType.MONSTERPLANT) return MODE_MONSTER_PLANT;
else if(avatarInfo.saddle && !avatarInfo.rider) return MODE_SADDLED_UP;
else if(avatarInfo.rider) return MODE_RIDING;
return _Str_2906;
return MODE_NORMAL;
});
setRespectsLeft(avatarInfo.respectsPetLeft);
@ -140,7 +140,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
<ContextMenuHeaderView>
{ avatarInfo.name }
</ContextMenuHeaderView>
{ (mode === _Str_2906) &&
{ (mode === MODE_NORMAL) &&
<>
{ (respectsLeft > 0) &&
<ContextMenuListItemView onClick={ event => processAction('respect') }>
@ -161,7 +161,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
{ LocalizeText('infostand.button.breed') }
</ContextMenuListItemView> }
</> }
{ (mode === _Str_5818) &&
{ (mode === MODE_SADDLED_UP) &&
<>
<ContextMenuListItemView onClick={ event => processAction('mount') }>
{ LocalizeText('infostand.button.mount') }
@ -184,7 +184,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
{ LocalizeText('infostand.button.saddleoff') }
</ContextMenuListItemView>
</> }
{ (mode === _Str_5938) &&
{ (mode === MODE_RIDING) &&
<>
<ContextMenuListItemView onClick={ event => processAction('dismount') }>
{ LocalizeText('infostand.button.dismount') }
@ -194,7 +194,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) }
</ContextMenuListItemView> }
</> }
{ (mode === _Str_10946) &&
{ (mode === MODE_MONSTER_PLANT) &&
<>
<ContextMenuListItemView onClick={ event => processAction('pick_up') }>
{ LocalizeText('infostand.button.pickup') }

View File

@ -12,15 +12,15 @@ interface AvatarInfoWidgetPetViewProps
close: () => void;
}
const _Str_2906: number = 0;
const _Str_5818: number = 1;
const _Str_5938: number = 2;
const _Str_13388: number = 3;
const MODE_NORMAL: number = 0;
const MODE_SADDLED_UP: number = 1;
const MODE_RIDING: number = 2;
const MODE_MONSTER_PLANT: number = 3;
export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =>
{
const { avatarInfo = null, close = null } = props;
const [ mode, setMode ] = useState(_Str_2906);
const [ mode, setMode ] = useState(MODE_NORMAL);
const [ respectsLeft, setRespectsLeft ] = useState(0);
const { roomSession = null } = useRoom();
@ -92,11 +92,11 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
{
setMode(prevValue =>
{
if(avatarInfo.petType === PetType.MONSTERPLANT) return _Str_13388;
else if(avatarInfo.saddle && !avatarInfo.rider) return _Str_5818;
else if(avatarInfo.rider) return _Str_5938;
if(avatarInfo.petType === PetType.MONSTERPLANT) return MODE_MONSTER_PLANT;
else if(avatarInfo.saddle && !avatarInfo.rider) return MODE_SADDLED_UP;
else if(avatarInfo.rider) return MODE_RIDING;
return _Str_2906;
return MODE_NORMAL;
});
setRespectsLeft(avatarInfo.respectsPetLeft);
@ -107,11 +107,11 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
<ContextMenuHeaderView>
{ avatarInfo.name }
</ContextMenuHeaderView>
{ (mode === _Str_2906) && (respectsLeft > 0) &&
{ (mode === MODE_NORMAL) && (respectsLeft > 0) &&
<ContextMenuListItemView onClick={ event => processAction('respect') }>
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) }
</ContextMenuListItemView> }
{ (mode === _Str_5818) &&
{ (mode === MODE_SADDLED_UP) &&
<>
{ !!avatarInfo.publiclyRideable &&
<ContextMenuListItemView onClick={ event => processAction('mount') }>
@ -122,7 +122,7 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) }
</ContextMenuListItemView> }
</> }
{ (mode === _Str_5938) &&
{ (mode === MODE_RIDING) &&
<>
<ContextMenuListItemView onClick={ event => processAction('dismount') }>
{ LocalizeText('infostand.button.dismount') }
@ -132,7 +132,7 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) }
</ContextMenuListItemView> }
</> }
{ (mode === _Str_13388) && !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) &&
{ (mode === MODE_MONSTER_PLANT) && !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) &&
<ContextMenuListItemView onClick={ event => processAction('treat') }>
{ LocalizeText('infostand.button.treat') }
</ContextMenuListItemView> }

View File

@ -1,18 +1,17 @@
import { RoomChatSettings } from '@nitrots/nitro-renderer';
import { FC, useEffect, useMemo, useRef, useState } from 'react';
import { ChatBubbleMessage } from '../../../../api';
import { ChatBubbleMessage, GetRoomEngine } from '../../../../api';
interface ChatWidgetMessageViewProps
{
chat: ChatBubbleMessage;
makeRoom: (chat: ChatBubbleMessage) => void;
onChatClicked: (chat: ChatBubbleMessage) => void;
bubbleWidth?: number;
}
export const ChatWidgetMessageView: FC<ChatWidgetMessageViewProps> = props =>
{
const { chat = null, makeRoom = null, onChatClicked = null, bubbleWidth = RoomChatSettings.CHAT_BUBBLE_WIDTH_NORMAL } = props;
const { chat = null, makeRoom = null, bubbleWidth = RoomChatSettings.CHAT_BUBBLE_WIDTH_NORMAL } = props;
const [ isVisible, setIsVisible ] = useState(false);
const elementRef = useRef<HTMLDivElement>();
@ -70,7 +69,7 @@ export const ChatWidgetMessageView: FC<ChatWidgetMessageViewProps> = props =>
useEffect(() => setIsVisible(chat.visible), [ chat.visible ]);
return (
<div ref={ elementRef } className={ `bubble-container ${ isVisible ? 'visible' : 'invisible' }` } onClick={ event => onChatClicked(chat) }>
<div ref={ elementRef } className={ `bubble-container ${ isVisible ? 'visible' : 'invisible' }` } onClick={ event => GetRoomEngine().setSelectedAvatar(chat.roomId, chat.senderId) }>
{ (chat.styleId === 0) &&
<div className="user-container-bg" style={ { backgroundColor: chat.color } } /> }
<div className={ `chat-bubble bubble-${ chat.styleId } type-${ chat.type }` } style={ { maxWidth: getBubbleWidth } }>

View File

@ -1,6 +1,6 @@
import { IWorkerEventTracker, RoomChatSettings } from '@nitrots/nitro-renderer';
import { FC, useCallback, useEffect, useRef, useState } from 'react';
import { AddWorkerEventTracker, ChatBubbleMessage, DoChatsOverlap, GetConfiguration, GetRoomEngine, RemoveWorkerEventTracker, SendWorkerEvent } from '../../../../api';
import { FC, useEffect, useRef, useState } from 'react';
import { AddWorkerEventTracker, ChatBubbleMessage, DoChatsOverlap, GetConfiguration, RemoveWorkerEventTracker, SendWorkerEvent } from '../../../../api';
import { useChatWidget } from '../../../../hooks';
import { ChatWidgetMessageView } from './ChatWidgetMessageView';
@ -12,7 +12,7 @@ export const ChatWidgetView: FC<{}> = props =>
const { chatMessages = [], setChatMessages = null, chatSettings = null, getScrollSpeed = 6000, removeHiddenChats = null, moveAllChatsUp = null } = useChatWidget();
const elementRef = useRef<HTMLDivElement>();
const checkOverlappingChats = useCallback((chat: ChatBubbleMessage, moved: number, tempChats: ChatBubbleMessage[]) =>
const checkOverlappingChats = (chat: ChatBubbleMessage, moved: number, tempChats: ChatBubbleMessage[]) =>
{
const totalChats = chatMessages.length;
@ -37,9 +37,9 @@ export const ChatWidgetView: FC<{}> = props =>
checkOverlappingChats(collides, amount, tempChats);
}
}
}, [ chatMessages ]);
}
const makeRoom = useCallback((chat: ChatBubbleMessage) =>
const makeRoom = (chat: ChatBubbleMessage) =>
{
if(chatSettings.mode === RoomChatSettings.CHAT_MODE_FREE_FLOW)
{
@ -68,19 +68,11 @@ export const ChatWidgetView: FC<{}> = props =>
removeHiddenChats();
}
}
}, [ chatSettings, chatMessages, removeHiddenChats, checkOverlappingChats ]);
const onChatClicked = useCallback((chat: ChatBubbleMessage) =>
{
//widgetHandler.processWidgetMessage(new RoomWidgetRoomObjectMessage(RoomWidgetRoomObjectMessage.GET_OBJECT_INFO, chat.senderId, chat.senderCategory));
GetRoomEngine().setSelectedAvatar(chat.roomId, chat.senderId);
//widgetHandler.processWidgetMessage(new RoomWidgetChatSelectAvatarMessage(RoomWidgetChatSelectAvatarMessage.MESSAGE_SELECT_AVATAR, chat.senderId, chat.username, chat.roomId));
}, []);
}
useEffect(() =>
{
const resize = (event: UIEvent) =>
const resize = (event: UIEvent = null) =>
{
if(!elementRef || !elementRef.current) return;
@ -102,7 +94,7 @@ export const ChatWidgetView: FC<{}> = props =>
window.addEventListener('resize', resize);
resize(null);
resize();
return () =>
{
@ -146,7 +138,7 @@ export const ChatWidgetView: FC<{}> = props =>
return (
<div ref={ elementRef } className="nitro-chat-widget">
{ chatMessages.map(chat => <ChatWidgetMessageView key={ chat.id } chat={ chat } makeRoom={ makeRoom } onChatClicked={ onChatClicked } bubbleWidth={ chatSettings.weight } />) }
{ chatMessages.map(chat => <ChatWidgetMessageView key={ chat.id } chat={ chat } makeRoom={ makeRoom } bubbleWidth={ chatSettings.weight } />) }
</div>
);
}

View File

@ -1,4 +1,4 @@
import { FC, useCallback, useEffect, useRef, useState } from 'react';
import { FC, useEffect, useRef, useState } from 'react';
import { GetNitroInstance, GetRoomObjectBounds, GetRoomSession } from '../../../../api';
import { Base, BaseProps } from '../../../../common';
@ -15,30 +15,30 @@ export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
const [ pos, setPos ] = useState<{ x: number, y: number }>({ x: -1, y: -1 });
const elementRef = useRef<HTMLDivElement>();
const getObjectLocation = useCallback(() =>
{
const roomSession = GetRoomSession();
const objectBounds = GetRoomObjectBounds(roomSession.roomId, objectId, category, 1);
return objectBounds;
}, [ objectId, category ]);
const updatePosition = useCallback(() =>
{
const bounds = getObjectLocation();
if(!bounds || !elementRef.current) return;
setPos({
x: Math.round(((bounds.left + (bounds.width / 2)) - (elementRef.current.offsetWidth / 2))),
y: Math.round((bounds.top - elementRef.current.offsetHeight) + 10)
});
}, [ getObjectLocation ]);
useEffect(() =>
{
let remove = false;
const getObjectLocation = () =>
{
const roomSession = GetRoomSession();
const objectBounds = GetRoomObjectBounds(roomSession.roomId, objectId, category, 1);
return objectBounds;
}
const updatePosition = () =>
{
const bounds = getObjectLocation();
if(!bounds || !elementRef.current) return;
setPos({
x: Math.round(((bounds.left + (bounds.width / 2)) - (elementRef.current.offsetWidth / 2))),
y: Math.round((bounds.top - elementRef.current.offsetHeight) + 10)
});
}
if(noFollow)
{
updatePosition();
@ -54,7 +54,7 @@ export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
{
if(remove) GetNitroInstance().ticker.remove(updatePosition);
}
}, [ updatePosition, noFollow ]);
}, [ objectId, category, noFollow ]);
return <Base innerRef={ elementRef } position={ position } visible={ (pos.x + (elementRef.current ? elementRef.current.offsetWidth : 0)) > -1 } className="object-location" style={ { left: pos.x, top: pos.y } } { ...rest } />;
}

View File

@ -1,6 +1,6 @@
import { GetGuestRoomResultEvent, RateFlatMessageComposer } from '@nitrots/nitro-renderer';
import classNames from 'classnames';
import { FC, useCallback, useEffect, useState } from 'react';
import { FC, useEffect, useState } from 'react';
import { CreateLinkEvent, GetRoomEngine, LocalizeText, SendMessageComposer } from '../../../../api';
import { Base, Column, Flex, Text, TransitionAnimation, TransitionAnimationTypes } from '../../../../common';
import { useMessageEvent, useRoom, useSharedNavigatorData } from '../../../../hooks';
@ -11,7 +11,6 @@ export const RoomToolsWidgetView: FC<{}> = props =>
const [ roomName, setRoomName ] = useState<string>(null);
const [ roomOwner, setRoomOwner ] = useState<string>(null);
const [ roomTags, setRoomTags ] = useState<string[]>(null);
const [ roomInfoDisplay, setRoomInfoDisplay ] = useState<boolean>(false);
const [ isOpen, setIsOpen ] = useState<boolean>(false);
const [ navigatorData, setNavigatorData ] = useSharedNavigatorData();
const { roomSession = null } = useRoom();
@ -48,7 +47,7 @@ export const RoomToolsWidgetView: FC<{}> = props =>
}
}
const onGetGuestRoomResultEvent = useCallback((event: GetGuestRoomResultEvent) =>
useMessageEvent<GetGuestRoomResultEvent>(GetGuestRoomResultEvent, event =>
{
const parser = event.getParser();
@ -57,9 +56,7 @@ export const RoomToolsWidgetView: FC<{}> = props =>
if(roomName !== parser.data.roomName) setRoomName(parser.data.roomName);
if(roomOwner !== parser.data.ownerName) setRoomOwner(parser.data.ownerName);
if(roomTags !== parser.data.tags) setRoomTags(parser.data.tags);
}, [ roomSession, roomName, roomOwner, roomTags ]);
useMessageEvent(GetGuestRoomResultEvent, onGetGuestRoomResultEvent);
});
useEffect(() =>
{

View File

@ -1,10 +1,12 @@
import { IEventDispatcher, NitroEvent } from '@nitrots/nitro-renderer';
import { useEffect } from 'react';
export const useEventDispatcher = <T extends NitroEvent>(type: string | string[], eventDispatcher: IEventDispatcher, handler: (event: T) => void) =>
export const useEventDispatcher = <T extends NitroEvent>(type: string | string[], eventDispatcher: IEventDispatcher, handler: (event: T) => void, enabled: boolean = true) =>
{
useEffect(() =>
{
if(!enabled) return;
if(Array.isArray(type))
{
type.map(name => eventDispatcher.addEventListener(name, handler));
@ -25,5 +27,5 @@ export const useEventDispatcher = <T extends NitroEvent>(type: string | string[]
eventDispatcher.removeEventListener(type, handler);
}
}
}, [ type, eventDispatcher, handler ]);
}, [ type, eventDispatcher, enabled, handler ]);
}

View File

@ -2,4 +2,4 @@ import { NitroEvent } from '@nitrots/nitro-renderer';
import { UI_EVENT_DISPATCHER } from '../../api';
import { useEventDispatcher } from './useEventDispatcher';
export const useUiEvent = <T extends NitroEvent>(type: string | string[], handler: (event: T) => void) => useEventDispatcher<T>(type, UI_EVENT_DISPATCHER, handler);
export const useUiEvent = <T extends NitroEvent>(type: string | string[], handler: (event: T) => void, enabled: boolean = true) => useEventDispatcher<T>(type, UI_EVENT_DISPATCHER, handler, enabled);

View File

@ -1,5 +1,5 @@
import { ConditionDefinition, Triggerable, TriggerDefinition, UpdateActionMessageComposer, UpdateConditionMessageComposer, UpdateTriggerMessageComposer, WiredActionDefinition, WiredFurniActionEvent, WiredFurniConditionEvent, WiredFurniTriggerEvent } from '@nitrots/nitro-renderer';
import { useState } from 'react';
import { ConditionDefinition, Triggerable, TriggerDefinition, UpdateActionMessageComposer, UpdateConditionMessageComposer, UpdateTriggerMessageComposer, WiredActionDefinition, WiredFurniActionEvent, WiredFurniConditionEvent, WiredFurniTriggerEvent, WiredSaveSuccessEvent } from '@nitrots/nitro-renderer';
import { useEffect, useState } from 'react';
import { useBetween } from 'use-between';
import { IsOwnerOfFloorFurniture, LocalizeText, NotificationUtilities, SendMessageComposer, WiredSelectionVisualizer } from '../../api';
import { WiredSelectObjectEvent } from '../../events';
@ -50,6 +50,8 @@ const useWiredState = () =>
useUiEvent<WiredSelectObjectEvent>(WiredSelectObjectEvent.SELECT_OBJECT, event =>
{
if(!trigger) return;
const furniId = event.objectId;
if(furniId <= 0) return;
@ -78,6 +80,13 @@ const useWiredState = () =>
});
}, !!trigger);
useMessageEvent<WiredSaveSuccessEvent>(WiredSaveSuccessEvent, event =>
{
const parser = event.getParser();
setTrigger(null);
});
useMessageEvent<WiredFurniActionEvent>(WiredFurniActionEvent, event =>
{
const parser = event.getParser();
@ -99,6 +108,19 @@ const useWiredState = () =>
setTrigger(parser.definition);
});
useEffect(() =>
{
if(!trigger) return;
return () =>
{
setIntParams([]);
setStringParam('');
setFurniIds([]);
setActionDelay(0);
}
}, [ trigger ]);
return { trigger, setTrigger, intParams, setIntParams, stringParam, setStringParam, furniIds, setFurniIds, actionDelay, setActionDelay, saveWired };
}