mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
宠物上阵
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
import { _decorator, Component, Node } from 'cc';
|
||||
import JNLayerBase from '../../../../extensions/ngame/assets/ngame/ui/base/JNLayerBase';
|
||||
import { Prefab } from 'cc';
|
||||
import PlayerPetData from '../../data/PlayerPetData';
|
||||
import JNScrollView from '../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollView';
|
||||
import { PetIconItem } from '../Consts/Pet/PetIconItem';
|
||||
import { NodeEventType } from 'cc';
|
||||
import { sp } from 'cc';
|
||||
import { app } from '../../App';
|
||||
import { PlayerPetOV } from '../../consts/API';
|
||||
import { UIPetAnim } from '../../consts/GData';
|
||||
import { GUI } from '../UIConfig';
|
||||
import PlayerTacticalData from '../../data/PlayerTacticalData';
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
//上阵页面
|
||||
@@ -7,6 +18,95 @@ const { ccclass, property } = _decorator;
|
||||
export class IntoBattleView extends JNLayerBase {
|
||||
|
||||
|
||||
@property(JNScrollView)
|
||||
views:JNScrollView; //宠物列表
|
||||
|
||||
@property(Prefab)
|
||||
petIconPrefab; //宠物Icon预制体
|
||||
|
||||
@property(sp.Skeleton)
|
||||
spine:sp.Skeleton; //当前选中的宠物
|
||||
|
||||
//宠物数据
|
||||
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();
|
||||
this.views.refreshData(this.pets);
|
||||
|
||||
//向子节点添加点击事件
|
||||
this.views.addItemEvent(NodeEventType.TOUCH_START,this.onClickItem.bind(this));
|
||||
|
||||
}
|
||||
|
||||
//刷新选中
|
||||
onUpdateSelect(){
|
||||
|
||||
//默认都不选中
|
||||
this.views.getItems<PetIconItem>().forEach(item => {
|
||||
item.isSelect = false;
|
||||
item.onUpdateSelect();
|
||||
})
|
||||
|
||||
//设置选中
|
||||
if(this.index != -1){
|
||||
let current = this.views.getItems<PetIconItem>()[this.index]
|
||||
current.isSelect = true;
|
||||
current.onUpdateSelect();
|
||||
}
|
||||
|
||||
//显示选中宠物
|
||||
this.spine.skeletonData = app.battleRes.roleSpine[this.pets[this.index].petTbId];
|
||||
this.spine.setAnimation(0,UIPetAnim.std,true);
|
||||
|
||||
}
|
||||
|
||||
//点击Item
|
||||
onClickItem(index:number){
|
||||
|
||||
//设置当前选中
|
||||
this.index = index;
|
||||
//刷新
|
||||
this.onUpdateSelect();
|
||||
|
||||
}
|
||||
|
||||
//点击上阵
|
||||
async onClickTactical(){
|
||||
|
||||
if(this.index < 0){
|
||||
app.layer.Open(GUI.Tips,{text:"请选择要上阵的宠物."})
|
||||
return;
|
||||
}
|
||||
|
||||
//修改上阵信息
|
||||
await PlayerTacticalData.getIns().UpdateIndexTactical(this.index,this.pets[this.index].petId);
|
||||
|
||||
//上阵完 关闭页面
|
||||
app.layer.CloseNode(this.node);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user