mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 19:34:47 +00:00
78 lines
1.8 KiB
TypeScript
78 lines
1.8 KiB
TypeScript
import { sp } from 'cc';
|
|
import { _decorator, Component, Node } from 'cc';
|
|
import { app } from '../../../App';
|
|
import { UIPetAnim } from '../../../consts/GData';
|
|
import { v3 } from 'cc';
|
|
import { PlayerPetOV } from '../../../consts/API';
|
|
import { Label } from 'cc';
|
|
import { PlayerPetEvent } from '../../../data/PlayerPetData';
|
|
import PetEquipData from '../../../data/PetEquipData';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('PetIcon')
|
|
export class PetIcon extends Component {
|
|
|
|
@property(sp.Skeleton)
|
|
spine:sp.Skeleton;
|
|
|
|
@property(Node)
|
|
starNode:Node; //星星
|
|
|
|
@property(Label)
|
|
levelLabel:Label; //等级
|
|
|
|
|
|
info:PlayerPetOV;
|
|
|
|
onLoad(){
|
|
this.reset();
|
|
|
|
//监听
|
|
app.event.on(PlayerPetEvent.UPDATE_INFO,this.onUpdateInfo,this)
|
|
}
|
|
|
|
protected onDestroy(): void {
|
|
app.event.off(PlayerPetEvent.UPDATE_INFO,this.onUpdateInfo,this)
|
|
}
|
|
|
|
//初始化
|
|
reset(){
|
|
|
|
this.starNode.active = false;
|
|
|
|
}
|
|
|
|
//信息更新
|
|
onUpdateInfo(info:PlayerPetOV){
|
|
if(this.info && info.petId == this.info.petId){
|
|
this.onUpdateView(); //刷新页面
|
|
}
|
|
}
|
|
|
|
//刷新页面
|
|
onUpdateView(){
|
|
this.spine.skeletonData = app.battleRes.getRoleSpine(this.info.petTbId);
|
|
this.spine.setAnimation(0,UIPetAnim.std,true);
|
|
|
|
if(this.info.petStar){
|
|
this.starNode.active = true;
|
|
this.starNode.getComponentInChildren(Label).string = `${this.info.petStar}`;
|
|
}
|
|
|
|
//设置宠物等级
|
|
// this.levelLabel.string = `Lv ${PetEquipData.getIns().getForgingBenchPetLevel(this.info.petId)}`
|
|
this.levelLabel.string = `Lv ${this.info.petLevel}`
|
|
|
|
}
|
|
|
|
//设置icon
|
|
set(info:PlayerPetOV){
|
|
this.reset();
|
|
this.info = info;
|
|
this.onUpdateView();
|
|
}
|
|
|
|
}
|
|
|
|
|