宠物上阵

This commit is contained in:
DESKTOP-5RP3AKU\Jisol
2023-11-16 02:44:43 +08:00
parent 391ce959cb
commit 1683ec01a0
27 changed files with 5227 additions and 187 deletions

View File

@@ -2,6 +2,9 @@ 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')
@@ -9,20 +12,76 @@ export class PlayerTacticalItem extends Component {
//阵法的Index;
index:number;
//没有宠物的节点
@property(Node)
noPet:Node;
//有宠物的节点
@property(Node)
havePet:Node;
//当前上阵的宠物
petId:number;
//初始化阵法
onInit(index:number){
this.index = index;
}
//更新信息
onUpdateView(){
PlayerTacticalData.getIns().getItem(this.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(){
app.layer.Open(GUI.IntoBattleView);
//如果没有宠物则弹出选择宠物 负责 删除宠物
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, //当前选择的阵法下标
});
}
}
}

View File

@@ -1,5 +1,7 @@
import { _decorator, Component, Node } from 'cc';
import { PlayerTacticalItem } from './PlayerTacticalItem';
import { app } from '../../../App';
import { PlayerTacticalEvent } from '../../../data/PlayerTacticalData';
const { ccclass, property } = _decorator;
/**
@@ -12,22 +14,42 @@ export class PlayerTacticalView extends Component {
//阵法子节点列表
items:PlayerTacticalItem[] = [];
// onLoad(){
onLoad(){
// //阵法
// this.items = this.node.getComponentsInChildren(PlayerTacticalItem);
// this.items.forEach((item,index) => item.onInit(index));
//阵法
this.items = this.node.getComponentsInChildren(PlayerTacticalItem);
this.items.forEach((item,index) => {
item.onInit(index); //初始化阵法下标
});
// this.onUpdateView();
this.onUpdateView();
// }
this.onEvent();
// //更新阵法显示
// onUpdateView(){
// this.items.forEach(item => {
// item.onUpdateView();
// })
// }
}
protected onDestroy(): void {
this.offEvent();
}
//添加监听
onEvent(){
app.event.on(PlayerTacticalEvent.UPDATE_TACTICAL,this.onUpdateView,this);
}
//移除监听
offEvent(){
app.event.off(PlayerTacticalEvent.UPDATE_TACTICAL,this.onUpdateView,this);
}
//更新阵法显示
onUpdateView(){
this.items.forEach(item => {
item.onUpdateView();
})
}
}