import { _decorator, Component, Node } from 'cc'; import PlayerTacticalData from '../../../data/PlayerTacticalData'; import { app } from '../../../App'; import { GUI } from '../../UIConfig'; import { sp } from 'cc'; import { UIPetAnim } from '../../../consts/GData'; import PlayerPetData from '../../../data/PlayerPetData'; const { ccclass, property } = _decorator; @ccclass('PlayerTacticalItem') export class PlayerTacticalItem extends Component { //阵法的Index; index:number; //没有宠物的节点 @property(Node) noPet:Node; //有宠物的节点 @property(Node) havePet:Node; //当前上阵的宠物 petId:number; //初始化阵法 onInit(index:number){ this.index = index; } protected start(): void { this.onUpdateView(); } //更新信息 onUpdateView(){ //获取阵法下的宠物 this.petId = PlayerTacticalData.getIns().getItem(this.index); //如果为0则没有宠物 if(this.petId){ this.havePet.active = true; this.noPet.active = false; this.onUpdatePetView(); }else{ this.noPet.active = true; this.havePet.active = false; } } //更新宠物信息 onUpdatePetView(){ let spine = this.havePet.getComponentInChildren(sp.Skeleton); //获取宠物信息 let info = PlayerPetData.getIns().petIdQueryPetInfo(this.petId); spine.skeletonData = app.battleRes.roleSpine[info.petTbId]; spine.setAnimation(0,UIPetAnim.std,true); } //打开选择阵法宠物 onClick(){ //如果没有宠物则弹出选择宠物 负责 删除宠物 if(this.petId){ //移除宠物 //提示是否移除宠物 app.layer.Open(GUI.SelectionBox,{ tigText:"是否移除宠物?", cancel:()=>{}, confirm:async ()=>{ //移除宠物 (0就是移除) await PlayerTacticalData.getIns().UpdateIndexTactical(this.index,0); } }) }else{ //选择宠物 app.layer.Open(GUI.IntoBattleView,{ index:this.index, //当前选择的阵法下标 }); } } }