2023-11-15 18:38:00 +08:00
|
|
|
import { _decorator, Component, Node } from 'cc';
|
|
|
|
import PlayerTacticalData from '../../../data/PlayerTacticalData';
|
|
|
|
import { app } from '../../../App';
|
|
|
|
import { GUI } from '../../UIConfig';
|
2023-11-16 02:44:43 +08:00
|
|
|
import { sp } from 'cc';
|
|
|
|
import { UIPetAnim } from '../../../consts/GData';
|
|
|
|
import PlayerPetData from '../../../data/PlayerPetData';
|
2023-11-16 19:10:19 +08:00
|
|
|
import { Vec3 } from 'cc';
|
|
|
|
import { NodeEventType } from 'cc';
|
|
|
|
import { EventTouch } from 'cc';
|
|
|
|
import JNodeDrag from '../../../../../extensions/ngame/assets/ngame/util/components/JNodeDrag';
|
2023-11-28 19:20:11 +08:00
|
|
|
import { PetIcon } from '../Pet/PetIcon';
|
2023-11-15 18:38:00 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
@ccclass('PlayerTacticalItem')
|
|
|
|
export class PlayerTacticalItem extends Component {
|
|
|
|
|
|
|
|
//阵法的Index;
|
|
|
|
index:number;
|
2023-11-16 02:44:43 +08:00
|
|
|
|
|
|
|
//没有宠物的节点
|
|
|
|
@property(Node)
|
|
|
|
noPet:Node;
|
|
|
|
|
|
|
|
//有宠物的节点
|
|
|
|
@property(Node)
|
|
|
|
havePet:Node;
|
|
|
|
|
2023-11-28 19:20:11 +08:00
|
|
|
//宠物节点
|
|
|
|
@property(PetIcon)
|
|
|
|
petIcon:PetIcon;
|
|
|
|
|
2023-11-16 19:10:19 +08:00
|
|
|
//拖拽
|
|
|
|
@property(JNodeDrag)
|
|
|
|
drag:JNodeDrag;
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
//当前上阵的宠物
|
|
|
|
petId:number;
|
2023-11-16 19:10:19 +08:00
|
|
|
|
|
|
|
//初始位置
|
|
|
|
initPos:Vec3;
|
2023-11-15 18:38:00 +08:00
|
|
|
|
|
|
|
//初始化阵法
|
|
|
|
onInit(index:number){
|
|
|
|
this.index = index;
|
2023-11-16 19:10:19 +08:00
|
|
|
this.initPos = this.node.position;
|
2023-11-15 18:38:00 +08:00
|
|
|
}
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
protected start(): void {
|
|
|
|
this.onUpdateView();
|
|
|
|
}
|
|
|
|
|
2023-11-15 18:38:00 +08:00
|
|
|
//更新信息
|
|
|
|
onUpdateView(){
|
2023-11-16 02:44:43 +08:00
|
|
|
|
|
|
|
//获取阵法下的宠物
|
|
|
|
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 info = PlayerPetData.getIns().petIdQueryPetInfo(this.petId);
|
2023-11-28 19:20:11 +08:00
|
|
|
this.petIcon.set(info);
|
|
|
|
|
2023-11-15 18:38:00 +08:00
|
|
|
}
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
//打开选择阵法宠物
|
2023-11-15 18:38:00 +08:00
|
|
|
onClick(){
|
2023-11-16 19:10:19 +08:00
|
|
|
|
|
|
|
//如果拖拽了则不生效点击事件
|
|
|
|
if(this.drag.isMove) return;
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
//如果没有宠物则弹出选择宠物 负责 删除宠物
|
|
|
|
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, //当前选择的阵法下标
|
|
|
|
});
|
|
|
|
}
|
2023-11-15 18:38:00 +08:00
|
|
|
}
|
2023-11-16 19:10:19 +08:00
|
|
|
|
|
|
|
//交换阵法
|
|
|
|
onExchange(item:PlayerTacticalItem){
|
|
|
|
let rootIndex = this.index;
|
|
|
|
this.index = item.index;
|
|
|
|
item.index = rootIndex;
|
|
|
|
|
|
|
|
//更新拖拽位置
|
|
|
|
let rootOriginal = this.drag.original;
|
|
|
|
this.drag.onUpdateOriginal(item.drag.original);
|
|
|
|
item.drag.onUpdateOriginal(rootOriginal);
|
|
|
|
}
|
|
|
|
|
|
|
|
addMoveEvent(fun:Function){
|
|
|
|
this.drag.addMoveEvent((e) => {
|
|
|
|
fun(this,e);
|
|
|
|
});
|
|
|
|
}
|
2023-11-17 02:57:46 +08:00
|
|
|
|
|
|
|
addMoveEndEvent(fun:Function){
|
|
|
|
this.drag.addMoveEndEvent((e) => {
|
|
|
|
fun(this,e);
|
|
|
|
});
|
|
|
|
}
|
2023-11-15 18:38:00 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|