DESKTOP-5RP3AKU\Jisol 0da4b5e8d8 update
2023-11-27 02:22:24 +08:00

168 lines
5.3 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, { PlayerPetEvent } 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';
import { ProgressBar } from 'cc';
import JProgressBar from '../../../../extensions/ngame/assets/ngame/util/components/Progress/JProgressBar';
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; //宠物星级经验
@property(JProgressBar)
petExpProgress:JProgressBar; //宠物经验条
@property(JProgressBar)
viewPetExpProgress:JProgressBar; //预览宠物经验条
data:PlayerPetOV;
onJNLoad(data: PlayerPetOV): void {
super.onJNLoad(data);
this.data = data;
this.onUpdateView();
//监听
app.event.on(PlayerPetEvent.UPDATE_INFO,this.onUpdateInfo,this); //刷新宠物信息
app.event.on(PlayerPetEvent.UPDATE_MINUS,this.onPetMinus,this); //减少宠物
}
onJNClose(): void {
//取消监听
app.event.off(PlayerPetEvent.UPDATE_INFO,this.onUpdateInfo,this); //刷新宠物信息
app.event.off(PlayerPetEvent.UPDATE_MINUS,this.onPetMinus,this); //减少宠物
}
//刷新页面
onUpdateView(){
this.onUpdateInfo();
//当前需要升星的宠物并且未上阵 并且排除自己
let pets = PetOV.PlayerPetOVSelects(
PlayerPetData.getIns().getPetIdData(
this.data.petTbId, //同一种宠物
PlayerPetData.getIns().getNoTacticalData() //非上阵宠物
).filter(pet => pet.petId != this.data.petId) //排除自己
);
this.views.refreshData(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}`;
let upStarExp = TD.TbGRoleUpStar.get(this.data.petStar + 1).merge;
this.petStarExp.string = `升级进度: ${upStarExp} / ${this.data.petStarExp}`;
this.petExpProgress.value = this.data.petStar + (this.data.petStarExp / upStarExp);
}
//减少宠物
onPetMinus(pet:PlayerPetOV){
this.views.getItems<PetIconSelectScroll>().forEach(item => {
if(item.data.petId == pet.petId)
this.views.delData(item.data);
});
}
//刷新选择
onUpdateSelect(){
//刷新
this.views.getItems<PetIconSelectScroll>().forEach((item) => {
let data = item.data as PlayerPetOVSelect;
item.select.isSelect = data.isSelect;
})
this.onUpdatePreview();
}
//更新预览进度条
onUpdatePreview(){
//选择得到的经验
let exp = this.views.getItems<PetIconSelectScroll>().filter(item => item.select.isSelect).length;
let upStarExp;
let petStarExp = this.data.petStarExp + exp;
let petStar = this.data.petStar;
while(petStarExp >= (upStarExp = TD.TbGRoleUpStar.get(petStar + 1).merge)){
petStar++;
petStarExp = Math.floor(petStarExp - upStarExp);
}
this.petStar.string = `当前星级: ${petStar}`;
this.petStarExp.string = `升级进度: ${upStarExp} / ${petStarExp}`;
//预览进度
this.viewPetExpProgress.value = petStar + (petStarExp / upStarExp);
}
//选择全部
onClickAll(){
let pets = this.views.getData<PlayerPetOVSelect>();
//如果全部选择则全部取消
if(pets.filter(pet => pet.isSelect).length == pets.length){
pets.forEach(pet => pet.isSelect = false);
}else{
pets.forEach(pet => pet.isSelect = true);
}
this.onUpdateSelect();
}
//点击Item
onClickItem(index:number){
let pets = this.views.getData<PlayerPetOVSelect>();
pets[index].isSelect = !pets[index].isSelect;
this.onUpdateSelect();
}
//点击合成
async onClickUp(){
//获取被合成的Id
let pets = this.views.getData<PlayerPetOVSelect>().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:"合成成功"});
}
}