mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-02-18 09:52:37 +01:00
Listening new states for the respects count
This commit is contained in:
parent
a9a03648d5
commit
058088b789
@ -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, GetSessionDataManager, LocalizeText, SendMessageComposer } from '../../../../../api';
|
||||||
import { useRoom } from '../../../../../hooks';
|
import { usePets, useRoom } 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';
|
||||||
@ -21,8 +21,14 @@ 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 [ respectsLeft, setRespectsLeft ] = useState(0);
|
|
||||||
const { roomSession = null } = useRoom();
|
const { roomSession = null } = useRoom();
|
||||||
|
const { petRespect, changePetRespect } = usePets();
|
||||||
|
|
||||||
|
useEffect(() =>
|
||||||
|
{
|
||||||
|
changePetRespect(avatarInfo.respectsPetLeft);
|
||||||
|
|
||||||
|
}, [ avatarInfo ]);
|
||||||
|
|
||||||
const canGiveHandItem = useMemo(() =>
|
const canGiveHandItem = useMemo(() =>
|
||||||
{
|
{
|
||||||
@ -49,18 +55,18 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
switch(name)
|
switch(name)
|
||||||
{
|
{
|
||||||
case 'respect':
|
case 'respect':
|
||||||
let newRespectsLeft = 0;
|
let newRespectsLeftChange = 0;
|
||||||
|
|
||||||
setRespectsLeft(prevValue =>
|
changePetRespect(prevValue =>
|
||||||
{
|
{
|
||||||
newRespectsLeft = (prevValue - 1);
|
newRespectsLeftChange = (prevValue - 1);
|
||||||
|
|
||||||
return newRespectsLeft;
|
return newRespectsLeftChange;
|
||||||
});
|
});
|
||||||
|
|
||||||
GetSessionDataManager().givePetRespect(avatarInfo.id);
|
GetSessionDataManager().givePetRespect(avatarInfo.id);
|
||||||
|
|
||||||
if(newRespectsLeft > 0) hideMenu = false;
|
if(newRespectsLeftChange > 0) hideMenu = false;
|
||||||
break;
|
break;
|
||||||
case 'treat':
|
case 'treat':
|
||||||
SendMessageComposer(new PetRespectComposer(avatarInfo.id));
|
SendMessageComposer(new PetRespectComposer(avatarInfo.id));
|
||||||
@ -132,7 +138,8 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
return MODE_NORMAL;
|
return MODE_NORMAL;
|
||||||
});
|
});
|
||||||
|
|
||||||
setRespectsLeft(avatarInfo.respectsPetLeft);
|
changePetRespect(avatarInfo.respectsPetLeft);
|
||||||
|
|
||||||
}, [ avatarInfo ]);
|
}, [ avatarInfo ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -142,9 +149,9 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
</ContextMenuHeaderView>
|
</ContextMenuHeaderView>
|
||||||
{ (mode === MODE_NORMAL) &&
|
{ (mode === MODE_NORMAL) &&
|
||||||
<>
|
<>
|
||||||
{ (respectsLeft > 0) &&
|
{ (petRespect > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
<ContextMenuListItemView onClick={ event => processAction('train') }>
|
<ContextMenuListItemView onClick={ event => processAction('train') }>
|
||||||
{ LocalizeText('infostand.button.train') }
|
{ LocalizeText('infostand.button.train') }
|
||||||
@ -170,9 +177,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>
|
||||||
{ (respectsLeft > 0) &&
|
{ (petRespect > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
<ContextMenuListItemView onClick={ event => processAction('train') }>
|
<ContextMenuListItemView onClick={ event => processAction('train') }>
|
||||||
{ LocalizeText('infostand.button.train') }
|
{ LocalizeText('infostand.button.train') }
|
||||||
@ -189,9 +196,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>
|
||||||
{ (respectsLeft > 0) &&
|
{ (petRespect > 0) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
<ContextMenuListItemView onClick={ event => processAction('respect') }>
|
||||||
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ respectsLeft.toString() ]) }
|
{ LocalizeText('infostand.button.petrespect', [ 'count' ], [ petRespect.toString() ]) }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
</> }
|
</> }
|
||||||
{ (mode === MODE_MONSTER_PLANT) &&
|
{ (mode === MODE_MONSTER_PLANT) &&
|
||||||
@ -209,7 +216,7 @@ export const AvatarInfoWidgetOwnPetView: FC<AvatarInfoWidgetOwnPetViewProps> = p
|
|||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
{ !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) &&
|
{ !avatarInfo.dead && ((avatarInfo.energy / avatarInfo.maximumEnergy) < 0.98) &&
|
||||||
<ContextMenuListItemView onClick={ event => processAction('treat') }>
|
<ContextMenuListItemView onClick={ event => processAction('treat') }>
|
||||||
{ LocalizeText('infostand.button.treat') }
|
{ LocalizeText('infostand.button.pettreat') }
|
||||||
</ContextMenuListItemView> }
|
</ContextMenuListItemView> }
|
||||||
{ !avatarInfo.dead && (avatarInfo.level === avatarInfo.maximumLevel) && avatarInfo.breedable &&
|
{ !avatarInfo.dead && (avatarInfo.level === avatarInfo.maximumLevel) && avatarInfo.breedable &&
|
||||||
<>
|
<>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user