mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-26 15:40:51 +01:00
Move respect to the session hook
This commit is contained in:
parent
cfe35224cb
commit
3aa37f3945
@ -1,9 +1,9 @@
|
|||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
import { PetRespectComposer, PetType } from '@nitrots/nitro-renderer';
|
import { PetRespectComposer, PetType } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useEffect } from 'react';
|
import { FC } from 'react';
|
||||||
import { AvatarInfoPet, CreateLinkEvent, GetConfiguration, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../../../api';
|
import { AvatarInfoPet, CreateLinkEvent, GetConfiguration, LocalizeText, SendMessageComposer } from '../../../../../api';
|
||||||
import { Base, Button, Column, Flex, LayoutPetImageView, Text, UserProfileIconView } from '../../../../../common';
|
import { Base, Button, Column, Flex, LayoutPetImageView, Text, UserProfileIconView } from '../../../../../common';
|
||||||
import { usePets, useRoom } from '../../../../../hooks';
|
import { useRoom, useSessionInfo } from '../../../../../hooks';
|
||||||
|
|
||||||
interface InfoStandWidgetPetViewProps
|
interface InfoStandWidgetPetViewProps
|
||||||
{
|
{
|
||||||
@ -15,16 +15,10 @@ export const InfoStandWidgetPetView: FC<InfoStandWidgetPetViewProps> = props =>
|
|||||||
{
|
{
|
||||||
const { avatarInfo = null, onClose = null } = props;
|
const { avatarInfo = null, onClose = null } = props;
|
||||||
const { roomSession = null } = useRoom();
|
const { roomSession = null } = useRoom();
|
||||||
const { petRespect, changePetRespect } = usePets();
|
const { petRespectRemaining = 0, respectPet = null } = useSessionInfo();
|
||||||
|
|
||||||
if(!avatarInfo) return null;
|
if(!avatarInfo) return null;
|
||||||
|
|
||||||
useEffect(() =>
|
|
||||||
{
|
|
||||||
changePetRespect(avatarInfo.respectsPetLeft);
|
|
||||||
|
|
||||||
}, [ avatarInfo ]);
|
|
||||||
|
|
||||||
const processButtonAction = (action: string) =>
|
const processButtonAction = (action: string) =>
|
||||||
{
|
{
|
||||||
let hideMenu = true;
|
let hideMenu = true;
|
||||||
@ -34,17 +28,9 @@ export const InfoStandWidgetPetView: FC<InfoStandWidgetPetViewProps> = props =>
|
|||||||
switch (action)
|
switch (action)
|
||||||
{
|
{
|
||||||
case 'respect':
|
case 'respect':
|
||||||
let newRespectsLeftChange = 0;
|
respectPet(avatarInfo.id);
|
||||||
|
|
||||||
changePetRespect(prevValue =>
|
if((petRespectRemaining - 1) >= 1) hideMenu = false;
|
||||||
{
|
|
||||||
newRespectsLeftChange = (prevValue - 1);
|
|
||||||
|
|
||||||
return newRespectsLeftChange;
|
|
||||||
});
|
|
||||||
|
|
||||||
GetSessionDataManager().givePetRespect(avatarInfo.id);
|
|
||||||
if(newRespectsLeftChange > 0) hideMenu = false;
|
|
||||||
break;
|
break;
|
||||||
case 'buyfood':
|
case 'buyfood':
|
||||||
CreateLinkEvent('catalog/open/' + GetConfiguration('catalog.links')['pets.buy_saddle']);
|
CreateLinkEvent('catalog/open/' + GetConfiguration('catalog.links')['pets.buy_saddle']);
|
||||||
@ -66,12 +52,6 @@ export const InfoStandWidgetPetView: FC<InfoStandWidgetPetViewProps> = props =>
|
|||||||
if(hideMenu) onClose();
|
if(hideMenu) onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() =>
|
|
||||||
{
|
|
||||||
changePetRespect(avatarInfo.respectsPetLeft);
|
|
||||||
|
|
||||||
}, [ avatarInfo ]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Column gap={ 1 } alignItems="end">
|
<Column gap={ 1 } alignItems="end">
|
||||||
<Column className="nitro-infostand rounded">
|
<Column className="nitro-infostand rounded">
|
||||||
@ -140,36 +120,30 @@ export const InfoStandWidgetPetView: FC<InfoStandWidgetPetViewProps> = props =>
|
|||||||
</Column>
|
</Column>
|
||||||
</Column>
|
</Column>
|
||||||
<Flex gap={ 1 } justifyContent="end">
|
<Flex gap={ 1 } justifyContent="end">
|
||||||
{ avatarInfo.petType !== PetType.MONSTERPLANT &&
|
{ (avatarInfo.petType !== PetType.MONSTERPLANT) &&
|
||||||
<Button variant="dark" onClick={ event => processButtonAction('buyfood') }>
|
<Button variant="dark" onClick={ event => processButtonAction('buyfood') }>
|
||||||
{ LocalizeText('infostand.button.buyfood') }
|
{ LocalizeText('infostand.button.buyfood') }
|
||||||
</Button>
|
</Button> }
|
||||||
}
|
{ avatarInfo.isOwner && (avatarInfo.petType !== PetType.MONSTERPLANT) &&
|
||||||
{ avatarInfo.isOwner && avatarInfo.petType !== PetType.MONSTERPLANT &&
|
|
||||||
<Button variant="dark" onClick={ event => processButtonAction('train') }>
|
<Button variant="dark" onClick={ event => processButtonAction('train') }>
|
||||||
{ LocalizeText('infostand.button.train') }
|
{ LocalizeText('infostand.button.train') }
|
||||||
</Button>
|
</Button> }
|
||||||
}
|
|
||||||
{ !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) && avatarInfo.petType === PetType.MONSTERPLANT &&
|
{ !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) && avatarInfo.petType === PetType.MONSTERPLANT &&
|
||||||
<Button variant="dark" onClick={ event => processButtonAction('treat') }>
|
<Button variant="dark" onClick={ event => processButtonAction('treat') }>
|
||||||
{ LocalizeText('infostand.button.pettreat') }
|
{ LocalizeText('infostand.button.pettreat') }
|
||||||
</Button>
|
</Button> }
|
||||||
}
|
|
||||||
{ roomSession?.isRoomOwner && avatarInfo.petType === PetType.MONSTERPLANT &&
|
{ roomSession?.isRoomOwner && avatarInfo.petType === PetType.MONSTERPLANT &&
|
||||||
<Button variant="dark" onClick={ event => processButtonAction('compost') }>
|
<Button variant="dark" onClick={ event => processButtonAction('compost') }>
|
||||||
{ LocalizeText('infostand.button.compost') }
|
{ LocalizeText('infostand.button.compost') }
|
||||||
</Button>
|
</Button> }
|
||||||
}
|
|
||||||
{ avatarInfo.isOwner &&
|
{ avatarInfo.isOwner &&
|
||||||
<Button variant="dark" onClick={ event => processButtonAction('pick_up') }>
|
<Button variant="dark" onClick={ event => processButtonAction('pick_up') }>
|
||||||
{ LocalizeText('inventory.pets.pickup') }
|
{ LocalizeText('inventory.pets.pickup') }
|
||||||
</Button>
|
</Button> }
|
||||||
}
|
{ (petRespectRemaining > 0) && (avatarInfo.petType !== PetType.MONSTERPLANT) &&
|
||||||
{ (petRespect > 0) && avatarInfo.petType !== PetType.MONSTERPLANT &&
|
|
||||||
<Button variant="dark" onClick={ event => processButtonAction('respect') }>
|
<Button variant="dark" onClick={ event => processButtonAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespectRemaining.toString() ]) }
|
||||||
</Button>
|
</Button> }
|
||||||
}
|
|
||||||
</Flex>
|
</Flex>
|
||||||
</Column>
|
</Column>
|
||||||
);
|
);
|
||||||
|
@ -3,7 +3,7 @@ import { RoomControllerLevel, RoomObjectCategory, RoomObjectVariable, RoomUnitGi
|
|||||||
import { FC, useEffect, useMemo, useState } from 'react';
|
import { FC, useEffect, useMemo, useState } from 'react';
|
||||||
import { AvatarInfoUser, CreateLinkEvent, DispatchUiEvent, GetOwnRoomObject, GetSessionDataManager, GetUserProfile, LocalizeText, MessengerFriend, ReportType, RoomWidgetUpdateChatInputContentEvent, SendMessageComposer } from '../../../../../api';
|
import { AvatarInfoUser, CreateLinkEvent, DispatchUiEvent, GetOwnRoomObject, GetSessionDataManager, GetUserProfile, LocalizeText, MessengerFriend, ReportType, RoomWidgetUpdateChatInputContentEvent, SendMessageComposer } from '../../../../../api';
|
||||||
import { Base, Flex } from '../../../../../common';
|
import { Base, Flex } from '../../../../../common';
|
||||||
import { useFriends, useHelp, useRoom } from '../../../../../hooks';
|
import { useFriends, useHelp, useRoom, useSessionInfo } from '../../../../../hooks';
|
||||||
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';
|
||||||
@ -26,10 +26,10 @@ export const AvatarInfoWidgetAvatarView: FC<AvatarInfoWidgetAvatarViewProps> = p
|
|||||||
{
|
{
|
||||||
const { avatarInfo = null, onClose = null } = props;
|
const { avatarInfo = null, onClose = null } = props;
|
||||||
const [ mode, setMode ] = useState(MODE_NORMAL);
|
const [ mode, setMode ] = useState(MODE_NORMAL);
|
||||||
const [ respectsLeft, setRespectsLeft ] = useState(0);
|
|
||||||
const { canRequestFriend = null } = useFriends();
|
const { canRequestFriend = null } = useFriends();
|
||||||
const { report = null } = useHelp();
|
const { report = null } = useHelp();
|
||||||
const { roomSession = null } = useRoom();
|
const { roomSession = null } = useRoom();
|
||||||
|
const { userRespectRemaining = 0, respectUser = null } = useSessionInfo();
|
||||||
|
|
||||||
const isShowGiveRights = useMemo(() =>
|
const isShowGiveRights = useMemo(() =>
|
||||||
{
|
{
|
||||||
@ -113,13 +113,9 @@ export const AvatarInfoWidgetAvatarView: FC<AvatarInfoWidgetAvatarViewProps> = p
|
|||||||
setMode(MODE_RELATIONSHIP);
|
setMode(MODE_RELATIONSHIP);
|
||||||
break;
|
break;
|
||||||
case 'respect': {
|
case 'respect': {
|
||||||
let newRespectsLeft = (respectsLeft - 1);
|
respectUser(avatarInfo.webID);
|
||||||
|
|
||||||
setRespectsLeft(newRespectsLeft);
|
if((userRespectRemaining - 1) >= 1) hideMenu = false;
|
||||||
|
|
||||||
GetSessionDataManager().giveRespect(avatarInfo.webID);
|
|
||||||
|
|
||||||
if(newRespectsLeft > 0) hideMenu = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'ignore':
|
case 'ignore':
|
||||||
@ -203,7 +199,6 @@ export const AvatarInfoWidgetAvatarView: FC<AvatarInfoWidgetAvatarViewProps> = p
|
|||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
setMode(MODE_NORMAL);
|
setMode(MODE_NORMAL);
|
||||||
setRespectsLeft(avatarInfo.respectLeft);
|
|
||||||
}, [ avatarInfo ]);
|
}, [ avatarInfo ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -223,9 +218,9 @@ export const AvatarInfoWidgetAvatarView: FC<AvatarInfoWidgetAvatarViewProps> = p
|
|||||||
<ContextMenuListItemView onClick={ event => processAction('whisper') }>
|
<ContextMenuListItemView onClick={ event => processAction('whisper') }>
|
||||||
{ LocalizeText('infostand.button.whisper') }
|
{ LocalizeText('infostand.button.whisper') }
|
||||||
</ContextMenuListItemView>
|
</ContextMenuListItemView>
|
||||||
{ (respectsLeft > 0) &&
|
{ (userRespectRemaining > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.respect', [ 'count' ], [ respectsLeft.toString() ]) }
|
{ LocalizeText('infostand.button.respect', [ 'count' ], [ userRespectRemaining.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
{ !canRequestFriend(avatarInfo.webID) &&
|
{ !canRequestFriend(avatarInfo.webID) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('relationship') }>
|
<ContextMenuListItemView onClick={ event => processAction('relationship') }>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { PetRespectComposer, PetType, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomUnitGiveHandItemPetComposer } from '@nitrots/nitro-renderer';
|
import { PetRespectComposer, PetType, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomUnitGiveHandItemPetComposer } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useEffect, useMemo, useState } from 'react';
|
import { FC, useEffect, useMemo, useState } from 'react';
|
||||||
import { AvatarInfoPet, CreateLinkEvent, GetConfiguration, GetOwnRoomObject, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../../../api';
|
import { AvatarInfoPet, CreateLinkEvent, GetConfiguration, GetOwnRoomObject, LocalizeText, SendMessageComposer } from '../../../../../api';
|
||||||
import { usePets, useRoom } from '../../../../../hooks';
|
import { useRoom, useSessionInfo } from '../../../../../hooks';
|
||||||
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';
|
||||||
@ -22,13 +22,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
const { avatarInfo = null, onClose = null } = props;
|
const { avatarInfo = null, onClose = null } = props;
|
||||||
const [ mode, setMode ] = useState(MODE_NORMAL);
|
const [ mode, setMode ] = useState(MODE_NORMAL);
|
||||||
const { roomSession = null } = useRoom();
|
const { roomSession = null } = useRoom();
|
||||||
const { petRespect, changePetRespect } = usePets();
|
const { petRespectRemaining = 0, respectPet = null } = useSessionInfo();
|
||||||
|
|
||||||
useEffect(() =>
|
|
||||||
{
|
|
||||||
changePetRespect(avatarInfo.respectsPetLeft);
|
|
||||||
|
|
||||||
}, [ avatarInfo ]);
|
|
||||||
|
|
||||||
const canGiveHandItem = useMemo(() =>
|
const canGiveHandItem = useMemo(() =>
|
||||||
{
|
{
|
||||||
@ -55,18 +49,9 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
switch(name)
|
switch(name)
|
||||||
{
|
{
|
||||||
case 'respect':
|
case 'respect':
|
||||||
let newRespectsLeftChange = 0;
|
respectPet(avatarInfo.id);
|
||||||
|
|
||||||
changePetRespect(prevValue =>
|
if((petRespectRemaining - 1) >= 1) hideMenu = false;
|
||||||
{
|
|
||||||
newRespectsLeftChange = (prevValue - 1);
|
|
||||||
|
|
||||||
return newRespectsLeftChange;
|
|
||||||
});
|
|
||||||
|
|
||||||
GetSessionDataManager().givePetRespect(avatarInfo.id);
|
|
||||||
|
|
||||||
if(newRespectsLeftChange > 0) hideMenu = false;
|
|
||||||
break;
|
break;
|
||||||
case 'treat':
|
case 'treat':
|
||||||
SendMessageComposer(new PetRespectComposer(avatarInfo.id));
|
SendMessageComposer(new PetRespectComposer(avatarInfo.id));
|
||||||
@ -137,9 +122,6 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
|
|
||||||
return MODE_NORMAL;
|
return MODE_NORMAL;
|
||||||
});
|
});
|
||||||
|
|
||||||
changePetRespect(avatarInfo.respectsPetLeft);
|
|
||||||
|
|
||||||
}, [ avatarInfo ]);
|
}, [ avatarInfo ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -149,9 +131,9 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
</ContextMenuHeaderView>
|
</ContextMenuHeaderView>
|
||||||
{ (mode === MODE_NORMAL) &&
|
{ (mode === MODE_NORMAL) &&
|
||||||
<>
|
<>
|
||||||
{ (petRespect > 0) &&
|
{ (petRespectRemaining > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespectRemaining.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
<ContextMenuListItemView onClick={ event => processAction('train') }>
|
<ContextMenuListItemView onClick={ event => processAction('train') }>
|
||||||
{ LocalizeText('infostand.button.train') }
|
{ LocalizeText('infostand.button.train') }
|
||||||
@ -177,9 +159,9 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
<input type="checkbox" checked={ !!avatarInfo.publiclyRideable } readOnly={ true } />
|
<input type="checkbox" checked={ !!avatarInfo.publiclyRideable } readOnly={ true } />
|
||||||
{ LocalizeText('infostand.button.toggle_riding_permission') }
|
{ LocalizeText('infostand.button.toggle_riding_permission') }
|
||||||
</ContextMenuListItemView>
|
</ContextMenuListItemView>
|
||||||
{ (petRespect > 0) &&
|
{ (petRespectRemaining > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespectRemaining.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
<ContextMenuListItemView onClick={ event => processAction('train') }>
|
<ContextMenuListItemView onClick={ event => processAction('train') }>
|
||||||
{ LocalizeText('infostand.button.train') }
|
{ LocalizeText('infostand.button.train') }
|
||||||
@ -196,9 +178,9 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
<ContextMenuListItemView onClick={ event => processAction('dismount') }>
|
<ContextMenuListItemView onClick={ event => processAction('dismount') }>
|
||||||
{ LocalizeText('infostand.button.dismount') }
|
{ LocalizeText('infostand.button.dismount') }
|
||||||
</ContextMenuListItemView>
|
</ContextMenuListItemView>
|
||||||
{ (petRespect > 0) &&
|
{ (petRespectRemaining > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespectRemaining.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
</> }
|
</> }
|
||||||
{ (mode === MODE_MONSTER_PLANT) &&
|
{ (mode === MODE_MONSTER_PLANT) &&
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { PetRespectComposer, PetType, RoomControllerLevel, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomUnitGiveHandItemPetComposer } from '@nitrots/nitro-renderer';
|
import { PetRespectComposer, PetType, RoomControllerLevel, RoomObjectCategory, RoomObjectType, RoomObjectVariable, RoomUnitGiveHandItemPetComposer } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useEffect, useMemo, useState } from 'react';
|
import { FC, useEffect, useMemo, useState } from 'react';
|
||||||
import { AvatarInfoPet, GetOwnRoomObject, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../../../api';
|
import { AvatarInfoPet, GetOwnRoomObject, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../../../api';
|
||||||
import { usePets, useRoom } from '../../../../../hooks';
|
import { useRoom, useSessionInfo } from '../../../../../hooks';
|
||||||
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';
|
||||||
@ -22,13 +22,7 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
|||||||
const { avatarInfo = null, onClose = null } = props;
|
const { avatarInfo = null, onClose = null } = props;
|
||||||
const [ mode, setMode ] = useState(MODE_NORMAL);
|
const [ mode, setMode ] = useState(MODE_NORMAL);
|
||||||
const { roomSession = null } = useRoom();
|
const { roomSession = null } = useRoom();
|
||||||
const { petRespect, changePetRespect } = usePets();
|
const { petRespectRemaining = 0, respectPet = null } = useSessionInfo();
|
||||||
|
|
||||||
useEffect(() =>
|
|
||||||
{
|
|
||||||
changePetRespect(avatarInfo.respectsPetLeft);
|
|
||||||
|
|
||||||
}, [ avatarInfo ]);
|
|
||||||
|
|
||||||
const canPickUp = useMemo(() =>
|
const canPickUp = useMemo(() =>
|
||||||
{
|
{
|
||||||
@ -60,18 +54,9 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
|||||||
switch(name)
|
switch(name)
|
||||||
{
|
{
|
||||||
case 'respect':
|
case 'respect':
|
||||||
let newRespectsLeftChange = 0;
|
respectPet(avatarInfo.id);
|
||||||
|
|
||||||
changePetRespect(prevValue =>
|
if((petRespectRemaining - 1) >= 1) hideMenu = false;
|
||||||
{
|
|
||||||
newRespectsLeftChange = (prevValue - 1);
|
|
||||||
|
|
||||||
return newRespectsLeftChange;
|
|
||||||
});
|
|
||||||
|
|
||||||
GetSessionDataManager().givePetRespect(avatarInfo.id);
|
|
||||||
|
|
||||||
if(newRespectsLeftChange > 0) hideMenu = false;
|
|
||||||
break;
|
break;
|
||||||
case 'treat':
|
case 'treat':
|
||||||
SendMessageComposer(new PetRespectComposer(avatarInfo.id));
|
SendMessageComposer(new PetRespectComposer(avatarInfo.id));
|
||||||
@ -104,9 +89,6 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
|||||||
|
|
||||||
return MODE_NORMAL;
|
return MODE_NORMAL;
|
||||||
});
|
});
|
||||||
|
|
||||||
changePetRespect(avatarInfo.respectsPetLeft);
|
|
||||||
|
|
||||||
}, [ avatarInfo ]);
|
}, [ avatarInfo ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -114,9 +96,9 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
|||||||
<ContextMenuHeaderView>
|
<ContextMenuHeaderView>
|
||||||
{ avatarInfo.name }
|
{ avatarInfo.name }
|
||||||
</ContextMenuHeaderView>
|
</ContextMenuHeaderView>
|
||||||
{ (mode === MODE_NORMAL) && (petRespect > 0) &&
|
{ (mode === MODE_NORMAL) && (petRespectRemaining > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespectRemaining.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
{ (mode === MODE_SADDLED_UP) &&
|
{ (mode === MODE_SADDLED_UP) &&
|
||||||
<>
|
<>
|
||||||
@ -124,9 +106,9 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
|||||||
<ContextMenuListItemView onClick={ event => processAction('mount') }>
|
<ContextMenuListItemView onClick={ event => processAction('mount') }>
|
||||||
{ LocalizeText('infostand.button.mount') }
|
{ LocalizeText('infostand.button.mount') }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
{ (petRespect > 0) &&
|
{ (petRespectRemaining > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespectRemaining.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
</> }
|
</> }
|
||||||
{ (mode === MODE_RIDING) &&
|
{ (mode === MODE_RIDING) &&
|
||||||
@ -134,9 +116,9 @@ export const AvatarInfoWidgetPetView: FC<AvatarInfoWidgetPetViewProps> = props =
|
|||||||
<ContextMenuListItemView onClick={ event => processAction('dismount') }>
|
<ContextMenuListItemView onClick={ event => processAction('dismount') }>
|
||||||
{ LocalizeText('infostand.button.dismount') }
|
{ LocalizeText('infostand.button.dismount') }
|
||||||
</ContextMenuListItemView>
|
</ContextMenuListItemView>
|
||||||
{ (petRespect > 0) &&
|
{ (petRespectRemaining > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespectRemaining.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
</> }
|
</> }
|
||||||
{ (mode === MODE_MONSTER_PLANT) && !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) &&
|
{ (mode === MODE_MONSTER_PLANT) && !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) &&
|
||||||
|
@ -12,7 +12,6 @@ export * from './inventory';
|
|||||||
export * from './mod-tools';
|
export * from './mod-tools';
|
||||||
export * from './navigator';
|
export * from './navigator';
|
||||||
export * from './notification';
|
export * from './notification';
|
||||||
export * from './pets';
|
|
||||||
export * from './purse';
|
export * from './purse';
|
||||||
export * from './rooms';
|
export * from './rooms';
|
||||||
export * from './session';
|
export * from './session';
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export * from './usePets';
|
|
@ -1,16 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { useBetween } from 'use-between';
|
|
||||||
|
|
||||||
const usePetsState = () =>
|
|
||||||
{
|
|
||||||
const [ petRespect, setPetRespect ] = useState(0);
|
|
||||||
|
|
||||||
const changePetRespect = (respects: React.SetStateAction<number>) =>
|
|
||||||
{
|
|
||||||
setPetRespect(respects);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { petRespect, setPetRespect, changePetRespect };
|
|
||||||
}
|
|
||||||
|
|
||||||
export const usePets = () => useBetween(usePetsState);
|
|
@ -1,7 +1,7 @@
|
|||||||
import { FigureUpdateEvent, RoomUnitChatStyleComposer, UserInfoDataParser, UserInfoEvent, UserSettingsEvent } from '@nitrots/nitro-renderer';
|
import { FigureUpdateEvent, RoomUnitChatStyleComposer, UserInfoDataParser, UserInfoEvent, UserSettingsEvent } from '@nitrots/nitro-renderer';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useBetween } from 'use-between';
|
import { useBetween } from 'use-between';
|
||||||
import { SendMessageComposer } from '../../api';
|
import { GetSessionDataManager, SendMessageComposer } from '../../api';
|
||||||
import { useMessageEvent } from '../events';
|
import { useMessageEvent } from '../events';
|
||||||
|
|
||||||
const useSessionInfoState = () =>
|
const useSessionInfoState = () =>
|
||||||
@ -9,6 +9,8 @@ const useSessionInfoState = () =>
|
|||||||
const [ userInfo, setUserInfo ] = useState<UserInfoDataParser>(null);
|
const [ userInfo, setUserInfo ] = useState<UserInfoDataParser>(null);
|
||||||
const [ userFigure, setUserFigure ] = useState<string>(null);
|
const [ userFigure, setUserFigure ] = useState<string>(null);
|
||||||
const [ chatStyleId, setChatStyleId ] = useState<number>(0);
|
const [ chatStyleId, setChatStyleId ] = useState<number>(0);
|
||||||
|
const [ userRespectRemaining, setUserRespectRemaining ] = useState<number>(0);
|
||||||
|
const [ petRespectRemaining, setPetRespectRemaining ] = useState<number>(0);
|
||||||
|
|
||||||
const updateChatStyleId = (styleId: number) =>
|
const updateChatStyleId = (styleId: number) =>
|
||||||
{
|
{
|
||||||
@ -17,12 +19,28 @@ const useSessionInfoState = () =>
|
|||||||
SendMessageComposer(new RoomUnitChatStyleComposer(styleId));
|
SendMessageComposer(new RoomUnitChatStyleComposer(styleId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const respectUser = (userId: number) =>
|
||||||
|
{
|
||||||
|
GetSessionDataManager().giveRespect(userId);
|
||||||
|
|
||||||
|
setUserRespectRemaining(GetSessionDataManager().respectsLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
const respectPet = (petId: number) =>
|
||||||
|
{
|
||||||
|
GetSessionDataManager().givePetRespect(petId);
|
||||||
|
|
||||||
|
setPetRespectRemaining(GetSessionDataManager().respectsPetLeft);
|
||||||
|
}
|
||||||
|
|
||||||
useMessageEvent<UserInfoEvent>(UserInfoEvent, event =>
|
useMessageEvent<UserInfoEvent>(UserInfoEvent, event =>
|
||||||
{
|
{
|
||||||
const parser = event.getParser();
|
const parser = event.getParser();
|
||||||
|
|
||||||
setUserInfo(parser.userInfo);
|
setUserInfo(parser.userInfo);
|
||||||
setUserFigure(parser.userInfo.figure);
|
setUserFigure(parser.userInfo.figure);
|
||||||
|
setUserRespectRemaining(parser.userInfo.respectsRemaining);
|
||||||
|
setPetRespectRemaining(parser.userInfo.respectsPetRemaining);
|
||||||
});
|
});
|
||||||
|
|
||||||
useMessageEvent<FigureUpdateEvent>(FigureUpdateEvent, event =>
|
useMessageEvent<FigureUpdateEvent>(FigureUpdateEvent, event =>
|
||||||
@ -39,7 +57,7 @@ const useSessionInfoState = () =>
|
|||||||
setChatStyleId(parser.chatType);
|
setChatStyleId(parser.chatType);
|
||||||
});
|
});
|
||||||
|
|
||||||
return { userInfo, userFigure, chatStyleId, updateChatStyleId };
|
return { userInfo, userFigure, chatStyleId, userRespectRemaining, petRespectRemaining, respectUser, respectPet, updateChatStyleId };
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useSessionInfo = () => useBetween(useSessionInfoState);
|
export const useSessionInfo = () => useBetween(useSessionInfoState);
|
||||||
|
Loading…
Reference in New Issue
Block a user