2023-11-15 18:38:00 +08:00
|
|
|
import { _decorator, Component, Node } from 'cc';
|
|
|
|
import JNLayerBase from '../../../../extensions/ngame/assets/ngame/ui/base/JNLayerBase';
|
2023-11-16 02:44:43 +08:00
|
|
|
import { Prefab } from 'cc';
|
|
|
|
import PlayerPetData from '../../data/PlayerPetData';
|
|
|
|
import JNScrollView from '../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollView';
|
|
|
|
import { NodeEventType } from 'cc';
|
|
|
|
import { sp } from 'cc';
|
|
|
|
import { app } from '../../App';
|
2023-11-28 02:13:05 +08:00
|
|
|
import { API, PlayerPetOV } from '../../consts/API';
|
2023-11-16 02:44:43 +08:00
|
|
|
import { UIPetAnim } from '../../consts/GData';
|
|
|
|
import { GUI } from '../UIConfig';
|
|
|
|
import PlayerTacticalData from '../../data/PlayerTacticalData';
|
2023-11-26 03:06:23 +08:00
|
|
|
import { PetIconSelectScroll } from '../Consts/Pet/PetIconSelectScroll';
|
2023-11-28 02:13:05 +08:00
|
|
|
import { PetPreviewWindow } from '../Consts/Pet/info/PetPreviewWindow';
|
2024-01-04 18:58:21 +08:00
|
|
|
import { Label } from 'cc';
|
2023-11-15 18:38:00 +08:00
|
|
|
const { ccclass, property } = _decorator;
|
|
|
|
|
|
|
|
//上阵页面
|
|
|
|
@ccclass('IntoBattleView')
|
|
|
|
export class IntoBattleView extends JNLayerBase {
|
|
|
|
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
@property(JNScrollView)
|
|
|
|
views:JNScrollView; //宠物列表
|
|
|
|
|
2023-11-28 02:13:05 +08:00
|
|
|
@property(PetPreviewWindow)
|
|
|
|
petPreview:PetPreviewWindow; //宠物显示窗口
|
2023-11-16 02:44:43 +08:00
|
|
|
|
2024-01-04 18:58:21 +08:00
|
|
|
@property(Label)
|
|
|
|
tacticalLabel:Label;//上阵文本
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
//宠物数据
|
|
|
|
pets:PlayerPetOV[] = [];
|
|
|
|
|
|
|
|
//当前选中
|
|
|
|
index:number = -1;
|
|
|
|
|
|
|
|
tIndex:number = -1; //阵法下标
|
|
|
|
|
|
|
|
onJNLoad(data: {index}): void {
|
|
|
|
|
|
|
|
super.onJNLoad();
|
|
|
|
|
|
|
|
//获取传入的下标
|
|
|
|
this.tIndex = data.index;
|
|
|
|
|
|
|
|
console.log("你选择的是",this.tIndex);
|
|
|
|
|
|
|
|
this.onUpdateView();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//刷新页面
|
|
|
|
onUpdateView(){
|
|
|
|
|
|
|
|
//获取所有玩家宠物
|
|
|
|
this.pets = PlayerPetData.getIns().getData();
|
2024-01-04 18:58:21 +08:00
|
|
|
|
|
|
|
//获取当前阵法下标是否存在宠物
|
|
|
|
let petId = PlayerTacticalData.getIns().getItem(this.tIndex);
|
|
|
|
if(petId){
|
|
|
|
//如果存在则默认选中
|
|
|
|
this.index = this.pets.indexOf(PlayerPetData.getIns().petIdQueryPetInfo(petId));
|
|
|
|
}
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
this.views.refreshData(this.pets);
|
|
|
|
|
2023-11-16 19:10:19 +08:00
|
|
|
//设置不可选中
|
2023-11-26 03:06:23 +08:00
|
|
|
this.views.getItems<PetIconSelectScroll>().forEach(item => {
|
2023-11-16 19:10:19 +08:00
|
|
|
if(PlayerTacticalData.getIns().getTacticalInfo().indexOf(item.data.petId) != -1)
|
2023-11-17 18:29:39 +08:00
|
|
|
item.select.isNoSelect = true; //如果在阵法里则不可选中
|
2023-11-16 19:10:19 +08:00
|
|
|
})
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
//向子节点添加点击事件
|
|
|
|
this.views.addItemEvent(NodeEventType.TOUCH_START,this.onClickItem.bind(this));
|
|
|
|
|
2023-11-16 19:10:19 +08:00
|
|
|
this.onUpdateSelect();
|
|
|
|
|
2023-11-16 02:44:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//刷新选中
|
|
|
|
onUpdateSelect(){
|
|
|
|
|
|
|
|
//默认都不选中
|
2023-11-26 03:06:23 +08:00
|
|
|
this.views.getItems<PetIconSelectScroll>().forEach(item => {
|
2023-11-17 18:29:39 +08:00
|
|
|
item.select.isSelect = false;
|
2023-11-16 02:44:43 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
//设置选中
|
|
|
|
if(this.index != -1){
|
2023-11-26 03:06:23 +08:00
|
|
|
let current = this.views.getItems<PetIconSelectScroll>()[this.index]
|
2023-11-17 18:29:39 +08:00
|
|
|
current.select.isSelect = true;
|
2023-11-16 02:44:43 +08:00
|
|
|
|
2023-11-16 19:10:19 +08:00
|
|
|
//显示选中宠物
|
2023-11-28 02:13:05 +08:00
|
|
|
this.petPreview.bind(this.pets[this.index]);
|
2023-11-16 19:10:19 +08:00
|
|
|
}
|
2023-11-16 02:44:43 +08:00
|
|
|
|
2024-01-04 18:58:21 +08:00
|
|
|
this.onUpdateTactical();
|
|
|
|
}
|
|
|
|
|
|
|
|
//刷新上阵
|
|
|
|
onUpdateTactical(){
|
|
|
|
//获取当前阵法下标是否存在宠物
|
|
|
|
let petId = PlayerTacticalData.getIns().getItem(this.tIndex);
|
|
|
|
this.tacticalLabel.string = `${petId ? "下阵" : "上阵"}`
|
2023-11-16 02:44:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//点击Item
|
|
|
|
onClickItem(index:number){
|
|
|
|
|
|
|
|
//设置当前选中
|
|
|
|
this.index = index;
|
|
|
|
//刷新
|
|
|
|
this.onUpdateSelect();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//点击上阵
|
|
|
|
async onClickTactical(){
|
|
|
|
|
|
|
|
if(this.index < 0){
|
|
|
|
app.layer.Open(GUI.Tips,{text:"请选择要上阵的宠物."})
|
|
|
|
return;
|
|
|
|
}
|
2024-01-04 18:58:21 +08:00
|
|
|
//获取当前阵法下标是否存在宠物
|
|
|
|
let petId = PlayerTacticalData.getIns().getItem(this.tIndex);
|
|
|
|
|
|
|
|
if(petId) {
|
|
|
|
//下阵
|
|
|
|
await PlayerTacticalData.getIns().UpdateIndexTactical(this.tIndex,0);
|
|
|
|
app.layer.Open(GUI.Tips,{text:"下阵成功"});
|
|
|
|
//上阵完 关闭页面
|
|
|
|
app.layer.CloseNode(this.node);
|
2023-11-26 03:06:23 +08:00
|
|
|
return;
|
|
|
|
}
|
2023-11-16 02:44:43 +08:00
|
|
|
|
|
|
|
//修改上阵信息
|
2023-11-16 19:10:19 +08:00
|
|
|
await PlayerTacticalData.getIns().UpdateIndexTactical(this.tIndex,this.pets[this.index].petId);
|
2024-01-04 18:58:21 +08:00
|
|
|
app.layer.Open(GUI.Tips,{text:"上阵成功"});
|
2023-11-16 02:44:43 +08:00
|
|
|
|
|
|
|
//上阵完 关闭页面
|
|
|
|
app.layer.CloseNode(this.node);
|
|
|
|
|
|
|
|
}
|
2023-11-15 18:38:00 +08:00
|
|
|
|
2023-11-26 03:06:23 +08:00
|
|
|
//点击升星页面
|
|
|
|
async onClickUpStar(){
|
|
|
|
|
|
|
|
if(this.index < 0){
|
|
|
|
app.layer.Open(GUI.Tips,{text:"请选择宠物."})
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
app.layer.Open(GUI.PetUpStarView,this.pets[this.index]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-11-28 02:13:05 +08:00
|
|
|
//点击升级
|
|
|
|
async onClickUpLevel(){
|
|
|
|
if(this.index < 0){
|
|
|
|
app.layer.Open(GUI.Tips,{text:"请选择宠物."})
|
|
|
|
return;
|
|
|
|
}
|
2023-12-28 02:56:34 +08:00
|
|
|
await API.PetUpLevel(this.pets[this.index].petId)
|
2023-11-28 02:13:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-11-15 18:38:00 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|