mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-22 22:30:52 +01:00
Changes
This commit is contained in:
parent
5412f3d3b3
commit
fe6dd25859
17
.vscode/settings.json
vendored
17
.vscode/settings.json
vendored
@ -4,17 +4,24 @@
|
|||||||
"typescript.preferences.quoteStyle": "single",
|
"typescript.preferences.quoteStyle": "single",
|
||||||
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
|
"typescript.format.placeOpenBraceOnNewLineForControlBlocks": true,
|
||||||
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
|
"typescript.format.placeOpenBraceOnNewLineForFunctions": true,
|
||||||
|
"typescript.format.enable": false,
|
||||||
"editor.codeActionsOnSave": {
|
"editor.codeActionsOnSave": {
|
||||||
"source.fixAll": true,
|
"source.fixAll.eslint": true,
|
||||||
"source.fixAll.sortJSON": false,
|
|
||||||
"source.organizeImports": true
|
"source.organizeImports": true
|
||||||
},
|
},
|
||||||
"git.ignoreLimitWarning": true,
|
"git.ignoreLimitWarning": true,
|
||||||
"files.eol": "\n",
|
"files.eol": "\n",
|
||||||
"files.insertFinalNewline": true,
|
"files.insertFinalNewline": true,
|
||||||
"files.trimFinalNewlines": true,
|
"files.trimFinalNewlines": true,
|
||||||
"editor.wordWrap": "on",
|
"editor.wordWrap": "on",
|
||||||
"emmet.showExpandedAbbreviation": "never",
|
"emmet.showExpandedAbbreviation": "never",
|
||||||
"eslint.validate": [ "javascript", "javascriptreact", "html", "typescriptreact" ],
|
"eslint.validate": [
|
||||||
"eslint.workingDirectories": [ "./src" ]
|
"javascript",
|
||||||
|
"javascriptreact",
|
||||||
|
"html",
|
||||||
|
"typescriptreact"
|
||||||
|
],
|
||||||
|
"eslint.workingDirectories": [
|
||||||
|
"./src"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ export * from './IRoomModel';
|
|||||||
export * from './IRoomModerationSettings';
|
export * from './IRoomModerationSettings';
|
||||||
export * from './NavigatorSearchResultViewDisplayMode';
|
export * from './NavigatorSearchResultViewDisplayMode';
|
||||||
export * from './RoomInfoData';
|
export * from './RoomInfoData';
|
||||||
export * from './RoomSettingsData';
|
|
||||||
export * from './RoomSettingsUtils';
|
export * from './RoomSettingsUtils';
|
||||||
export * from './SearchFilterOptions';
|
export * from './SearchFilterOptions';
|
||||||
export * from './TryVisitRoom';
|
export * from './TryVisitRoom';
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
@import './utils';
|
@import './utils';
|
||||||
|
|
||||||
.btn-sm {
|
.btn-sm {
|
||||||
min-height: 28px;
|
min-height: 28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
|
@ -31,11 +31,9 @@ export const ContextMenuView: FC<ContextMenuViewProps> = props =>
|
|||||||
const [ opacity, setOpacity ] = useState(1);
|
const [ opacity, setOpacity ] = useState(1);
|
||||||
const [ isFading, setIsFading ] = useState(false);
|
const [ isFading, setIsFading ] = useState(false);
|
||||||
const [ fadeTime, setFadeTime ] = useState(0);
|
const [ fadeTime, setFadeTime ] = useState(0);
|
||||||
const [ isFrozen, setIsFrozen ] = useState(false);
|
const [ isCollapsed, setIsCollapsed ] = useState(COLLAPSED);
|
||||||
const elementRef = useRef<HTMLDivElement>();
|
const elementRef = useRef<HTMLDivElement>();
|
||||||
|
|
||||||
const [ collapsed, setCollapsed ] = useState(COLLAPSED);
|
|
||||||
|
|
||||||
const getOffset = useCallback((bounds: NitroRectangle) =>
|
const getOffset = useCallback((bounds: NitroRectangle) =>
|
||||||
{
|
{
|
||||||
let height = -(elementRef.current.offsetHeight);
|
let height = -(elementRef.current.offsetHeight);
|
||||||
@ -125,14 +123,14 @@ export const ContextMenuView: FC<ContextMenuViewProps> = props =>
|
|||||||
{
|
{
|
||||||
const newClassNames: string[] = [ 'nitro-context-menu' ];
|
const newClassNames: string[] = [ 'nitro-context-menu' ];
|
||||||
|
|
||||||
if (collapsed) newClassNames.push('menu-hidden');
|
if (isCollapsed) newClassNames.push('menu-hidden');
|
||||||
|
|
||||||
newClassNames.push((pos.x !== null) ? 'visible' : 'invisible');
|
newClassNames.push((pos.x !== null) ? 'visible' : 'invisible');
|
||||||
|
|
||||||
if(classNames.length) newClassNames.push(...classNames);
|
if(classNames.length) newClassNames.push(...classNames);
|
||||||
|
|
||||||
return newClassNames;
|
return newClassNames;
|
||||||
}, [ pos, classNames, collapsed ]);
|
}, [ pos, classNames, isCollapsed ]);
|
||||||
|
|
||||||
const getStyle = useMemo(() =>
|
const getStyle = useMemo(() =>
|
||||||
{
|
{
|
||||||
@ -155,20 +153,13 @@ export const ContextMenuView: FC<ContextMenuViewProps> = props =>
|
|||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
let added = false;
|
GetTicker().add(update);
|
||||||
|
|
||||||
if(!isFrozen)
|
|
||||||
{
|
|
||||||
added = true;
|
|
||||||
|
|
||||||
GetTicker().add(update);
|
|
||||||
}
|
|
||||||
|
|
||||||
return () =>
|
return () =>
|
||||||
{
|
{
|
||||||
if(added) GetTicker().remove(update);
|
GetTicker().remove(update);
|
||||||
}
|
}
|
||||||
}, [ isFrozen, update ]);
|
}, [ update ]);
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
@ -183,10 +174,13 @@ export const ContextMenuView: FC<ContextMenuViewProps> = props =>
|
|||||||
const toggleCollapse = () =>
|
const toggleCollapse = () =>
|
||||||
{
|
{
|
||||||
COLLAPSED = !COLLAPSED;
|
COLLAPSED = !COLLAPSED;
|
||||||
setCollapsed(COLLAPSED)
|
setIsCollapsed(COLLAPSED);
|
||||||
|
setOpacity(0);
|
||||||
|
|
||||||
|
console.log(opacity);
|
||||||
}
|
}
|
||||||
return <Base innerRef={ elementRef } position={ position } classNames={ getClassNames } style={ getStyle } onMouseOver={ event => setIsFrozen(true) } onMouseOut={ event => setIsFrozen(false) } { ...rest }>
|
return <Base innerRef={ elementRef } position={ position } classNames={ getClassNames } style={ getStyle } { ...rest }>
|
||||||
{ !(collapsable && COLLAPSED) && children }
|
{ !(collapsable && COLLAPSED) && children }
|
||||||
{ collapsable && <ContextMenuCaretView onClick={ () => toggleCollapse() } collapsed={ collapsed } /> }
|
{ collapsable && <ContextMenuCaretView onClick={ () => toggleCollapse() } collapsed={ isCollapsed } /> }
|
||||||
</Base>;
|
</Base>;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ export const FurnitureCustomStackHeightView: FC<{}> = props =>
|
|||||||
value={ height }
|
value={ height }
|
||||||
onChange={ event => updateHeight(event) }
|
onChange={ event => updateHeight(event) }
|
||||||
renderThumb={ (props, state) => <div { ...props }>{ state.valueNow }</div> } />
|
renderThumb={ (props, state) => <div { ...props }>{ state.valueNow }</div> } />
|
||||||
<input type="number" min={ 0 } max={ maxHeight } value={ height } onChange={ event => updateHeight(parseFloat(event.target.value)) } />
|
<input className="show-number-arrows" type="number" min={ 0 } max={ maxHeight } value={ height } onChange={ event => updateHeight(parseFloat(event.target.value)) } />
|
||||||
</Flex>
|
</Flex>
|
||||||
<Column gap={ 1 }>
|
<Column gap={ 1 }>
|
||||||
<Button onClick={ event => sendUpdate(-100) }>
|
<Button onClick={ event => sendUpdate(-100) }>
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
import { ContextMenuEnum, GroupFurniContextMenuInfoMessageEvent, GroupFurniContextMenuInfoMessageParser, RoomEngineTriggerWidgetEvent, RoomObjectCategory } from '@nitrots/nitro-renderer';
|
import { ContextMenuEnum, RoomObjectCategory } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useCallback, useState } from 'react';
|
import { FC } from 'react';
|
||||||
import { GetGroupInformation, GetRoomEngine, IsOwnerOfFurniture, LocalizeText, RoomWidgetFurniActionMessage, TryJoinGroup, TryVisitRoom } from '../../../../../api';
|
import { GetGroupInformation, LocalizeText } from '../../../../../api';
|
||||||
import { UseMessageEventHook, UseRoomEngineEvent } from '../../../../../hooks';
|
import { useFurnitureContextMenuWidget } from '../../../../../hooks';
|
||||||
import { useRoomContext } from '../../../RoomContext';
|
|
||||||
import { ContextMenuHeaderView } from '../../context-menu/ContextMenuHeaderView';
|
import { ContextMenuHeaderView } from '../../context-menu/ContextMenuHeaderView';
|
||||||
import { ContextMenuListItemView } from '../../context-menu/ContextMenuListItemView';
|
import { ContextMenuListItemView } from '../../context-menu/ContextMenuListItemView';
|
||||||
import { ContextMenuView } from '../../context-menu/ContextMenuView';
|
import { ContextMenuView } from '../../context-menu/ContextMenuView';
|
||||||
@ -17,145 +16,16 @@ const EFFECTBOX_OPEN: string = 'EFFECTBOX_OPEN';
|
|||||||
|
|
||||||
export const FurnitureContextMenuView: FC<{}> = props =>
|
export const FurnitureContextMenuView: FC<{}> = props =>
|
||||||
{
|
{
|
||||||
const [ objectId, setObjectId ] = useState(-1);
|
const { closeConfirm = null, processAction = null, objectId = -1, mode = null, confirmMode = null, confirmingObjectId = -1, groupData = null, isGroupMember = false } = useFurnitureContextMenuWidget();
|
||||||
const [ mode, setMode ] = useState<string>(null);
|
|
||||||
const [ confirmMode, setConfirmMode ] = useState<string>(null);
|
|
||||||
const [ confirmingObjectId, setConfirmingObjectId ] = useState(-1);
|
|
||||||
const [ groupData, setGroupData ] = useState<GroupFurniContextMenuInfoMessageParser>(null);
|
|
||||||
const [ isGroupMember, setIsGroupMember ] = useState(false);
|
|
||||||
const { roomSession = null, widgetHandler = null } = useRoomContext();
|
|
||||||
|
|
||||||
const close = useCallback(() =>
|
|
||||||
{
|
|
||||||
setObjectId(-1);
|
|
||||||
setGroupData(null);
|
|
||||||
setIsGroupMember(false);
|
|
||||||
setMode(null);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const closeConfirm = () =>
|
|
||||||
{
|
|
||||||
setConfirmMode(null);
|
|
||||||
setConfirmingObjectId(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const onRoomEngineTriggerWidgetEvent = useCallback((event: RoomEngineTriggerWidgetEvent) =>
|
|
||||||
{
|
|
||||||
const object = GetRoomEngine().getRoomObject(roomSession.roomId, event.objectId, event.category);
|
|
||||||
|
|
||||||
if(!object) return;
|
|
||||||
|
|
||||||
switch(event.type)
|
|
||||||
{
|
|
||||||
case RoomEngineTriggerWidgetEvent.REQUEST_MONSTERPLANT_SEED_PLANT_CONFIRMATION_DIALOG:
|
|
||||||
if(!IsOwnerOfFurniture(object)) return;
|
|
||||||
|
|
||||||
setConfirmingObjectId(object.id);
|
|
||||||
setConfirmMode(MONSTERPLANT_SEED_CONFIRMATION);
|
|
||||||
|
|
||||||
close();
|
|
||||||
return;
|
|
||||||
case RoomEngineTriggerWidgetEvent.REQUEST_EFFECTBOX_OPEN_DIALOG:
|
|
||||||
if(!IsOwnerOfFurniture(object)) return;
|
|
||||||
|
|
||||||
setConfirmingObjectId(object.id);
|
|
||||||
setConfirmMode(EFFECTBOX_OPEN);
|
|
||||||
|
|
||||||
close();
|
|
||||||
return;
|
|
||||||
case RoomEngineTriggerWidgetEvent.REQUEST_PURCHASABLE_CLOTHING_CONFIRMATION_DIALOG:
|
|
||||||
if(!IsOwnerOfFurniture(object)) return;
|
|
||||||
|
|
||||||
setConfirmingObjectId(object.id);
|
|
||||||
setConfirmMode(PURCHASABLE_CLOTHING_CONFIRMATION);
|
|
||||||
|
|
||||||
close();
|
|
||||||
return;
|
|
||||||
case RoomEngineTriggerWidgetEvent.OPEN_FURNI_CONTEXT_MENU:
|
|
||||||
|
|
||||||
setObjectId(object.id);
|
|
||||||
|
|
||||||
switch(event.contextMenu)
|
|
||||||
{
|
|
||||||
case ContextMenuEnum.FRIEND_FURNITURE:
|
|
||||||
setMode(ContextMenuEnum.FRIEND_FURNITURE);
|
|
||||||
return;
|
|
||||||
case ContextMenuEnum.MONSTERPLANT_SEED:
|
|
||||||
if(IsOwnerOfFurniture(object)) setMode(ContextMenuEnum.MONSTERPLANT_SEED);
|
|
||||||
return;
|
|
||||||
case ContextMenuEnum.MYSTERY_BOX:
|
|
||||||
return;
|
|
||||||
case ContextMenuEnum.RANDOM_TELEPORT:
|
|
||||||
setMode(ContextMenuEnum.RANDOM_TELEPORT);
|
|
||||||
return;
|
|
||||||
case ContextMenuEnum.PURCHASABLE_CLOTHING:
|
|
||||||
if(IsOwnerOfFurniture(object)) setMode(ContextMenuEnum.PURCHASABLE_CLOTHING);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
case RoomEngineTriggerWidgetEvent.CLOSE_FURNI_CONTEXT_MENU:
|
|
||||||
if(object.id === objectId) close();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}, [ roomSession, objectId, close ]);
|
|
||||||
|
|
||||||
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.OPEN_FURNI_CONTEXT_MENU, onRoomEngineTriggerWidgetEvent);
|
|
||||||
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.CLOSE_FURNI_CONTEXT_MENU, onRoomEngineTriggerWidgetEvent);
|
|
||||||
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_MONSTERPLANT_SEED_PLANT_CONFIRMATION_DIALOG, onRoomEngineTriggerWidgetEvent);
|
|
||||||
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_PURCHASABLE_CLOTHING_CONFIRMATION_DIALOG, onRoomEngineTriggerWidgetEvent);
|
|
||||||
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_EFFECTBOX_OPEN_DIALOG, onRoomEngineTriggerWidgetEvent);
|
|
||||||
|
|
||||||
const onGroupFurniContextMenuInfoMessageEvent = useCallback((event: GroupFurniContextMenuInfoMessageEvent) =>
|
|
||||||
{
|
|
||||||
const parser = event.getParser();
|
|
||||||
|
|
||||||
setObjectId(parser.objectId);
|
|
||||||
setGroupData(parser);
|
|
||||||
setIsGroupMember(parser.userIsMember);
|
|
||||||
setMode(GROUP_FURNITURE);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
UseMessageEventHook(GroupFurniContextMenuInfoMessageEvent, onGroupFurniContextMenuInfoMessageEvent);
|
|
||||||
|
|
||||||
const processAction = (name: string) =>
|
|
||||||
{
|
|
||||||
if(name)
|
|
||||||
{
|
|
||||||
switch(name)
|
|
||||||
{
|
|
||||||
case 'use_friend_furni':
|
|
||||||
roomSession.useMultistateItem(objectId);
|
|
||||||
break;
|
|
||||||
case 'use_monsterplant_seed':
|
|
||||||
setConfirmMode(MONSTERPLANT_SEED_CONFIRMATION);
|
|
||||||
setConfirmingObjectId(objectId);
|
|
||||||
break;
|
|
||||||
case 'use_random_teleport':
|
|
||||||
widgetHandler.processWidgetMessage(new RoomWidgetFurniActionMessage(RoomWidgetFurniActionMessage.USE, objectId, RoomObjectCategory.FLOOR));
|
|
||||||
break;
|
|
||||||
case 'use_purchaseable_clothing':
|
|
||||||
setConfirmMode(PURCHASABLE_CLOTHING_CONFIRMATION);
|
|
||||||
setConfirmingObjectId(objectId);
|
|
||||||
break;
|
|
||||||
case 'join_group':
|
|
||||||
TryJoinGroup(groupData.guildId);
|
|
||||||
setIsGroupMember(true);
|
|
||||||
return;
|
|
||||||
case 'go_to_group_homeroom':
|
|
||||||
if(groupData) TryVisitRoom(groupData.guildHomeRoomId);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{ (confirmMode === MONSTERPLANT_SEED_CONFIRMATION) && <MonsterPlantSeedConfirmView objectId={ confirmingObjectId } close={ closeConfirm } /> }
|
{ (confirmMode === MONSTERPLANT_SEED_CONFIRMATION) &&
|
||||||
{ (confirmMode === PURCHASABLE_CLOTHING_CONFIRMATION) && <PurchasableClothingConfirmView objectId={ confirmingObjectId } close={ closeConfirm } /> }
|
<MonsterPlantSeedConfirmView objectId={ confirmingObjectId } close={ closeConfirm } /> }
|
||||||
{ (confirmMode === EFFECTBOX_OPEN) && <EffectBoxConfirmView objectId={ confirmingObjectId } close={ closeConfirm } /> }
|
{ (confirmMode === PURCHASABLE_CLOTHING_CONFIRMATION) &&
|
||||||
|
<PurchasableClothingConfirmView objectId={ confirmingObjectId } close={ closeConfirm } /> }
|
||||||
|
{ (confirmMode === EFFECTBOX_OPEN) &&
|
||||||
|
<EffectBoxConfirmView objectId={ confirmingObjectId } close={ closeConfirm } /> }
|
||||||
{ (objectId >= 0) && mode &&
|
{ (objectId >= 0) && mode &&
|
||||||
<ContextMenuView objectId={ objectId } category={ RoomObjectCategory.FLOOR } close={ close } fades={ true }>
|
<ContextMenuView objectId={ objectId } category={ RoomObjectCategory.FLOOR } close={ close } fades={ true }>
|
||||||
{ (mode === ContextMenuEnum.FRIEND_FURNITURE) &&
|
{ (mode === ContextMenuEnum.FRIEND_FURNITURE) &&
|
||||||
@ -199,15 +69,17 @@ export const FurnitureContextMenuView: FC<{}> = props =>
|
|||||||
<ContextMenuHeaderView className="cursor-pointer text-truncate" onClick={ () => GetGroupInformation(groupData.guildId) }>
|
<ContextMenuHeaderView className="cursor-pointer text-truncate" onClick={ () => GetGroupInformation(groupData.guildId) }>
|
||||||
{ groupData.guildName }
|
{ groupData.guildName }
|
||||||
</ContextMenuHeaderView>
|
</ContextMenuHeaderView>
|
||||||
{ !isGroupMember && <ContextMenuListItemView onClick={ event => processAction('join_group') }>
|
{ !isGroupMember &&
|
||||||
{ LocalizeText('widget.furniture.button.join.group') }
|
<ContextMenuListItemView onClick={ event => processAction('join_group') }>
|
||||||
</ContextMenuListItemView> }
|
{ LocalizeText('widget.furniture.button.join.group') }
|
||||||
|
</ContextMenuListItemView> }
|
||||||
<ContextMenuListItemView onClick={ event => processAction('go_to_group_homeroom') }>
|
<ContextMenuListItemView onClick={ event => processAction('go_to_group_homeroom') }>
|
||||||
{ LocalizeText('widget.furniture.button.go.to.group.home.room') }
|
{ LocalizeText('widget.furniture.button.go.to.group.home.room') }
|
||||||
</ContextMenuListItemView>
|
</ContextMenuListItemView>
|
||||||
{ groupData.guildHasReadableForum && <ContextMenuListItemView onClick={ event => processAction('open_forum') }>
|
{ groupData.guildHasReadableForum &&
|
||||||
{ LocalizeText('widget.furniture.button.open_group_forum') }
|
<ContextMenuListItemView onClick={ event => processAction('open_forum') }>
|
||||||
</ContextMenuListItemView> }
|
{ LocalizeText('widget.furniture.button.open_group_forum') }
|
||||||
|
</ContextMenuListItemView> }
|
||||||
</> }
|
</> }
|
||||||
</ContextMenuView> }
|
</ContextMenuView> }
|
||||||
</>
|
</>
|
||||||
|
@ -17,7 +17,7 @@ export const WiredTriggerBotReachedStuffView: FC<{}> = props =>
|
|||||||
}, [ trigger ]);
|
}, [ trigger ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WiredTriggerBaseView requiresFurni={ WiredFurniType.STUFF_SELECTION_OPTION_NONE } hasSpecialInput={ true } save={ save }>
|
<WiredTriggerBaseView requiresFurni={ WiredFurniType.STUFF_SELECTION_OPTION_BY_ID_OR_BY_TYPE } hasSpecialInput={ true } save={ save }>
|
||||||
<Column gap={ 1 }>
|
<Column gap={ 1 }>
|
||||||
<Text bold>{ LocalizeText('wiredfurni.params.bot.name') }</Text>
|
<Text bold>{ LocalizeText('wiredfurni.params.bot.name') }</Text>
|
||||||
<input type="text" className="form-control form-control-sm" maxLength={ 32 } value={ botName } onChange={ event => setBotName(event.target.value) } />
|
<input type="text" className="form-control form-control-sm" maxLength={ 32 } value={ botName } onChange={ event => setBotName(event.target.value) } />
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
export * from './useFurnitureBackgroundColorWidget';
|
export * from './useFurnitureBackgroundColorWidget';
|
||||||
export * from './useFurnitureBadgeDisplayWidget';
|
export * from './useFurnitureBadgeDisplayWidget';
|
||||||
|
export * from './useFurnitureContextMenuWidget';
|
||||||
export * from './useFurnitureDimmerWidget';
|
export * from './useFurnitureDimmerWidget';
|
||||||
export * from './useFurnitureExchangeWidget';
|
export * from './useFurnitureExchangeWidget';
|
||||||
export * from './useFurnitureExternalImageWidget';
|
export * from './useFurnitureExternalImageWidget';
|
||||||
|
@ -0,0 +1,152 @@
|
|||||||
|
import { ContextMenuEnum, GroupFurniContextMenuInfoMessageEvent, GroupFurniContextMenuInfoMessageParser, RoomEngineTriggerWidgetEvent, RoomObjectCategory } from '@nitrots/nitro-renderer';
|
||||||
|
import { useCallback, useState } from 'react';
|
||||||
|
import { GetRoomEngine, IsOwnerOfFurniture, RoomWidgetFurniActionMessage, TryJoinGroup, TryVisitRoom } from '../../../../api';
|
||||||
|
import { UseRoomEngineEvent } from '../../../events';
|
||||||
|
import { UseMessageEventHook } from '../../../messages';
|
||||||
|
import { useRoom } from '../../useRoom';
|
||||||
|
|
||||||
|
const MONSTERPLANT_SEED_CONFIRMATION: string = 'MONSTERPLANT_SEED_CONFIRMATION';
|
||||||
|
const PURCHASABLE_CLOTHING_CONFIRMATION: string = 'PURCHASABLE_CLOTHING_CONFIRMATION';
|
||||||
|
const GROUP_FURNITURE: string = 'GROUP_FURNITURE';
|
||||||
|
const EFFECTBOX_OPEN: string = 'EFFECTBOX_OPEN';
|
||||||
|
|
||||||
|
const useFurnitureContextMenuWidgetState = () =>
|
||||||
|
{
|
||||||
|
const [ objectId, setObjectId ] = useState(-1);
|
||||||
|
const [ mode, setMode ] = useState<string>(null);
|
||||||
|
const [ confirmMode, setConfirmMode ] = useState<string>(null);
|
||||||
|
const [ confirmingObjectId, setConfirmingObjectId ] = useState(-1);
|
||||||
|
const [ groupData, setGroupData ] = useState<GroupFurniContextMenuInfoMessageParser>(null);
|
||||||
|
const [ isGroupMember, setIsGroupMember ] = useState(false);
|
||||||
|
const { roomSession = null, widgetHandler = null } = useRoom();
|
||||||
|
|
||||||
|
const close = useCallback(() =>
|
||||||
|
{
|
||||||
|
setObjectId(-1);
|
||||||
|
setGroupData(null);
|
||||||
|
setIsGroupMember(false);
|
||||||
|
setMode(null);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const closeConfirm = () =>
|
||||||
|
{
|
||||||
|
setConfirmMode(null);
|
||||||
|
setConfirmingObjectId(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
const processAction = (name: string) =>
|
||||||
|
{
|
||||||
|
if(name)
|
||||||
|
{
|
||||||
|
switch(name)
|
||||||
|
{
|
||||||
|
case 'use_friend_furni':
|
||||||
|
roomSession.useMultistateItem(objectId);
|
||||||
|
break;
|
||||||
|
case 'use_monsterplant_seed':
|
||||||
|
setConfirmMode(MONSTERPLANT_SEED_CONFIRMATION);
|
||||||
|
setConfirmingObjectId(objectId);
|
||||||
|
break;
|
||||||
|
case 'use_random_teleport':
|
||||||
|
widgetHandler.processWidgetMessage(new RoomWidgetFurniActionMessage(RoomWidgetFurniActionMessage.USE, objectId, RoomObjectCategory.FLOOR));
|
||||||
|
break;
|
||||||
|
case 'use_purchaseable_clothing':
|
||||||
|
setConfirmMode(PURCHASABLE_CLOTHING_CONFIRMATION);
|
||||||
|
setConfirmingObjectId(objectId);
|
||||||
|
break;
|
||||||
|
case 'join_group':
|
||||||
|
TryJoinGroup(groupData.guildId);
|
||||||
|
setIsGroupMember(true);
|
||||||
|
return;
|
||||||
|
case 'go_to_group_homeroom':
|
||||||
|
if(groupData) TryVisitRoom(groupData.guildHomeRoomId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
|
||||||
|
const onRoomEngineTriggerWidgetEvent = useCallback((event: RoomEngineTriggerWidgetEvent) =>
|
||||||
|
{
|
||||||
|
const object = GetRoomEngine().getRoomObject(roomSession.roomId, event.objectId, event.category);
|
||||||
|
|
||||||
|
if(!object) return;
|
||||||
|
|
||||||
|
switch(event.type)
|
||||||
|
{
|
||||||
|
case RoomEngineTriggerWidgetEvent.REQUEST_MONSTERPLANT_SEED_PLANT_CONFIRMATION_DIALOG:
|
||||||
|
if(!IsOwnerOfFurniture(object)) return;
|
||||||
|
|
||||||
|
setConfirmingObjectId(object.id);
|
||||||
|
setConfirmMode(MONSTERPLANT_SEED_CONFIRMATION);
|
||||||
|
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
case RoomEngineTriggerWidgetEvent.REQUEST_EFFECTBOX_OPEN_DIALOG:
|
||||||
|
if(!IsOwnerOfFurniture(object)) return;
|
||||||
|
|
||||||
|
setConfirmingObjectId(object.id);
|
||||||
|
setConfirmMode(EFFECTBOX_OPEN);
|
||||||
|
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
case RoomEngineTriggerWidgetEvent.REQUEST_PURCHASABLE_CLOTHING_CONFIRMATION_DIALOG:
|
||||||
|
if(!IsOwnerOfFurniture(object)) return;
|
||||||
|
|
||||||
|
setConfirmingObjectId(object.id);
|
||||||
|
setConfirmMode(PURCHASABLE_CLOTHING_CONFIRMATION);
|
||||||
|
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
case RoomEngineTriggerWidgetEvent.OPEN_FURNI_CONTEXT_MENU:
|
||||||
|
|
||||||
|
setObjectId(object.id);
|
||||||
|
|
||||||
|
switch(event.contextMenu)
|
||||||
|
{
|
||||||
|
case ContextMenuEnum.FRIEND_FURNITURE:
|
||||||
|
setMode(ContextMenuEnum.FRIEND_FURNITURE);
|
||||||
|
return;
|
||||||
|
case ContextMenuEnum.MONSTERPLANT_SEED:
|
||||||
|
if(IsOwnerOfFurniture(object)) setMode(ContextMenuEnum.MONSTERPLANT_SEED);
|
||||||
|
return;
|
||||||
|
case ContextMenuEnum.MYSTERY_BOX:
|
||||||
|
return;
|
||||||
|
case ContextMenuEnum.RANDOM_TELEPORT:
|
||||||
|
setMode(ContextMenuEnum.RANDOM_TELEPORT);
|
||||||
|
return;
|
||||||
|
case ContextMenuEnum.PURCHASABLE_CLOTHING:
|
||||||
|
if(IsOwnerOfFurniture(object)) setMode(ContextMenuEnum.PURCHASABLE_CLOTHING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
case RoomEngineTriggerWidgetEvent.CLOSE_FURNI_CONTEXT_MENU:
|
||||||
|
if(object.id === objectId) close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}, [ roomSession, objectId, close ]);
|
||||||
|
|
||||||
|
const onGroupFurniContextMenuInfoMessageEvent = useCallback((event: GroupFurniContextMenuInfoMessageEvent) =>
|
||||||
|
{
|
||||||
|
const parser = event.getParser();
|
||||||
|
|
||||||
|
setObjectId(parser.objectId);
|
||||||
|
setGroupData(parser);
|
||||||
|
setIsGroupMember(parser.userIsMember);
|
||||||
|
setMode(GROUP_FURNITURE);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
UseMessageEventHook(GroupFurniContextMenuInfoMessageEvent, onGroupFurniContextMenuInfoMessageEvent);
|
||||||
|
|
||||||
|
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.OPEN_FURNI_CONTEXT_MENU, onRoomEngineTriggerWidgetEvent);
|
||||||
|
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.CLOSE_FURNI_CONTEXT_MENU, onRoomEngineTriggerWidgetEvent);
|
||||||
|
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_MONSTERPLANT_SEED_PLANT_CONFIRMATION_DIALOG, onRoomEngineTriggerWidgetEvent);
|
||||||
|
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_PURCHASABLE_CLOTHING_CONFIRMATION_DIALOG, onRoomEngineTriggerWidgetEvent);
|
||||||
|
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_EFFECTBOX_OPEN_DIALOG, onRoomEngineTriggerWidgetEvent);
|
||||||
|
|
||||||
|
return { objectId, mode, confirmMode, confirmingObjectId, groupData, isGroupMember, closeConfirm, processAction };
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useFurnitureContextMenuWidget = useFurnitureContextMenuWidgetState;
|
@ -1,6 +1,6 @@
|
|||||||
import { RoomEngineTriggerWidgetEvent, RoomObjectVariable } from '@nitrots/nitro-renderer';
|
import { RoomEngineTriggerWidgetEvent, RoomObjectVariable } from '@nitrots/nitro-renderer';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { GetRoomEngine, GetRoomSession, GetSessionDataManager } from '../../../../api';
|
import { GetRoomEngine, GetRoomSession, GetSessionDataManager, IsOwnerOfFurniture } from '../../../../api';
|
||||||
import { UseRoomEngineEvent } from '../../../events';
|
import { UseRoomEngineEvent } from '../../../events';
|
||||||
import { useFurniRemovedEvent } from '../../useFurniRemovedEvent';
|
import { useFurniRemovedEvent } from '../../useFurniRemovedEvent';
|
||||||
|
|
||||||
@ -10,8 +10,7 @@ const useFurnitureStickieWidgetState = () =>
|
|||||||
const [ category, setCategory ] = useState(-1);
|
const [ category, setCategory ] = useState(-1);
|
||||||
const [ color, setColor ] = useState('0');
|
const [ color, setColor ] = useState('0');
|
||||||
const [ text, setText ] = useState('');
|
const [ text, setText ] = useState('');
|
||||||
|
const [ canModify, setCanModify ] = useState(false);
|
||||||
const canModify = (GetRoomSession().isRoomOwner || GetSessionDataManager().isModerator);
|
|
||||||
|
|
||||||
const close = useCallback(() =>
|
const close = useCallback(() =>
|
||||||
{
|
{
|
||||||
@ -19,6 +18,7 @@ const useFurnitureStickieWidgetState = () =>
|
|||||||
setCategory(-1);
|
setCategory(-1);
|
||||||
setColor('0');
|
setColor('0');
|
||||||
setText('');
|
setText('');
|
||||||
|
setCanModify(false);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const updateColor = (newColor: string) =>
|
const updateColor = (newColor: string) =>
|
||||||
@ -39,7 +39,7 @@ const useFurnitureStickieWidgetState = () =>
|
|||||||
|
|
||||||
const trash = () => GetRoomEngine().deleteRoomObject(objectId, category);
|
const trash = () => GetRoomEngine().deleteRoomObject(objectId, category);
|
||||||
|
|
||||||
const onRoomEngineTriggerWidgetEvent = useCallback((event: RoomEngineTriggerWidgetEvent) =>
|
UseRoomEngineEvent<RoomEngineTriggerWidgetEvent>(RoomEngineTriggerWidgetEvent.REQUEST_STICKIE, event =>
|
||||||
{
|
{
|
||||||
const roomObject = GetRoomEngine().getRoomObject(event.roomId, event.objectId, event.category);
|
const roomObject = GetRoomEngine().getRoomObject(event.roomId, event.objectId, event.category);
|
||||||
|
|
||||||
@ -66,9 +66,8 @@ const useFurnitureStickieWidgetState = () =>
|
|||||||
setCategory(event.category);
|
setCategory(event.category);
|
||||||
setColor(color || '0');
|
setColor(color || '0');
|
||||||
setText(text || '');
|
setText(text || '');
|
||||||
}, []);
|
setCanModify(GetRoomSession().isRoomOwner || GetSessionDataManager().isModerator || IsOwnerOfFurniture(roomObject));
|
||||||
|
});
|
||||||
UseRoomEngineEvent(RoomEngineTriggerWidgetEvent.REQUEST_STICKIE, onRoomEngineTriggerWidgetEvent);
|
|
||||||
|
|
||||||
useFurniRemovedEvent(((objectId !== -1) && (category !== -1)), event =>
|
useFurniRemovedEvent(((objectId !== -1) && (category !== -1)), event =>
|
||||||
{
|
{
|
||||||
|
5
src/hooks/rooms/widgets/useInfostandWidget.ts
Normal file
5
src/hooks/rooms/widgets/useInfostandWidget.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { useBetween } from 'use-between';
|
||||||
|
|
||||||
|
const useInfostandWidgetState = () => {};
|
||||||
|
|
||||||
|
export const useInfostandWidget = () => useBetween(useInfostandWidgetState);
|
Loading…
Reference in New Issue
Block a user