DESKTOP-5RP3AKU\Jisol b33fede03e 简单的升星
2023-11-26 03:06:23 +08:00

115 lines
3.0 KiB
TypeScript

import { _decorator, Component, Node } from 'cc';
import JNLayerBase from '../../../../extensions/ngame/assets/ngame/ui/base/JNLayerBase';
import JNScrollView from '../../../../extensions/ngame/assets/ngame/util/components/scrollview/JNScrollView';
import PlayerPetData from '../../data/PlayerPetData';
import { API, PlayerPetOV } from '../../consts/API';
import { PetOV, PlayerPetOVSelect } from '../VO/PetOV';
import { PetIconSelectScroll } from '../Consts/Pet/PetIconSelectScroll';
import { NodeEventType } from 'cc';
import { Label } from 'cc';
import { app, TD } from '../../App';
import { GUI } from '../UIConfig';
const { ccclass, property } = _decorator;
@ccclass('PetUpStarView')
export class PetUpStarView extends JNLayerBase {
@property(JNScrollView)
views:JNScrollView; //宠物列表
@property(Label)
petNameLabel:Label; //宠物名称
@property(Label)
petStar:Label; //宠物星级
@property(Label)
petStarExp:Label; //宠物星级经验
//宠物数据
pets:PlayerPetOVSelect[] = [];
data:PlayerPetOV;
onJNLoad(data: PlayerPetOV): void {
super.onJNLoad(data);
this.data = data;
this.onUpdateView();
}
//刷新页面
onUpdateView(){
this.onUpdateInfo();
//获取所有玩家宠物
this.pets = PetOV.PlayerPetOVSelects(PlayerPetData.getIns().getData());
this.views.refreshData(this.pets);
//向子节点添加点击事件
this.views.addItemEvent(NodeEventType.TOUCH_START,this.onClickItem.bind(this));
this.onUpdateSelect();
}
//刷新信息
onUpdateInfo(){
//显示宠物名称
this.petNameLabel.string = TD.TbGRole.get(this.data.petTbId).roleName;
this.petStar.string = `当前星级: ${this.data.petStar}`;
this.petStarExp.string = `升级所需经验 / ${this.data.petStarExp}`;
}
//刷新选择
onUpdateSelect(){
//刷新
this.views.getItems<PetIconSelectScroll>().forEach((item) => {
let data = item.data as PlayerPetOVSelect;
item.select.isSelect = data.isSelect;
})
}
//选择全部
onClickAll(){
//如果全部选择则全部取消
if(this.pets.filter(pet => pet.isSelect).length == this.pets.length){
this.pets.forEach(pet => pet.isSelect = false);
}else{
this.pets.forEach(pet => pet.isSelect = true);
}
this.onUpdateSelect();
}
//点击Item
onClickItem(index:number){
this.pets[index].isSelect = !this.pets[index].isSelect;
this.onUpdateSelect();
}
//点击合成
async onClickUp(){
//获取被合成的Id
let pets = this.pets.filter(pet => pet.isSelect).map(pet => pet.petId);
if(pets.length <= 0){
app.layer.Open(GUI.Tips,{text:"请选择需要被合成的宠物"});
return;
}
await API.PetUpStar(this.data.petId,pets);
app.layer.Open(GUI.Tips,{text:"合成成功"});
}
}