mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
宠物升星
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
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 PlayerPetData, { PlayerPetEvent } from '../../data/PlayerPetData';
|
||||
import { API, PlayerPetOV } from '../../consts/API';
|
||||
import { PetOV, PlayerPetOVSelect } from '../VO/PetOV';
|
||||
import { PetIconSelectScroll } from '../Consts/Pet/PetIconSelectScroll';
|
||||
@@ -9,6 +9,8 @@ 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')
|
||||
@@ -23,9 +25,10 @@ export class PetUpStarView extends JNLayerBase {
|
||||
petStar:Label; //宠物星级
|
||||
@property(Label)
|
||||
petStarExp:Label; //宠物星级经验
|
||||
|
||||
//宠物数据
|
||||
pets:PlayerPetOVSelect[] = [];
|
||||
@property(JProgressBar)
|
||||
petExpProgress:JProgressBar; //宠物经验条
|
||||
@property(JProgressBar)
|
||||
viewPetExpProgress:JProgressBar; //预览宠物经验条
|
||||
|
||||
data:PlayerPetOV;
|
||||
|
||||
@@ -35,6 +38,16 @@ export class PetUpStarView extends JNLayerBase {
|
||||
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); //减少宠物
|
||||
}
|
||||
|
||||
|
||||
@@ -43,9 +56,14 @@ export class PetUpStarView extends JNLayerBase {
|
||||
|
||||
this.onUpdateInfo();
|
||||
|
||||
//获取所有玩家宠物
|
||||
this.pets = PetOV.PlayerPetOVSelects(PlayerPetData.getIns().getData());
|
||||
this.views.refreshData(this.pets);
|
||||
//当前需要升星的宠物并且未上阵 并且排除自己
|
||||
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));
|
||||
@@ -60,10 +78,21 @@ export class PetUpStarView extends JNLayerBase {
|
||||
//显示宠物名称
|
||||
this.petNameLabel.string = TD.TbGRole.get(this.data.petTbId).roleName;
|
||||
this.petStar.string = `当前星级: ${this.data.petStar} 星`;
|
||||
this.petStarExp.string = `升级所需经验 / ${this.data.petStarExp}`;
|
||||
|
||||
let upStarExp = TD.TbGRoleUpStar.get(this.data.petStar + 1).merge;
|
||||
this.petStarExp.string = `升级进度: ${upStarExp} / ${this.data.petStarExp}`;
|
||||
this.petExpProgress.value = (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(){
|
||||
|
||||
@@ -73,31 +102,55 @@ export class PetUpStarView extends JNLayerBase {
|
||||
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 = (petStarExp / upStarExp);
|
||||
|
||||
}
|
||||
|
||||
//选择全部
|
||||
onClickAll(){
|
||||
let pets = this.views.getData<PlayerPetOVSelect>();
|
||||
//如果全部选择则全部取消
|
||||
if(this.pets.filter(pet => pet.isSelect).length == this.pets.length){
|
||||
this.pets.forEach(pet => pet.isSelect = false);
|
||||
if(pets.filter(pet => pet.isSelect).length == pets.length){
|
||||
pets.forEach(pet => pet.isSelect = false);
|
||||
}else{
|
||||
this.pets.forEach(pet => pet.isSelect = true);
|
||||
pets.forEach(pet => pet.isSelect = true);
|
||||
}
|
||||
this.onUpdateSelect();
|
||||
}
|
||||
|
||||
//点击Item
|
||||
onClickItem(index:number){
|
||||
|
||||
this.pets[index].isSelect = !this.pets[index].isSelect;
|
||||
let pets = this.views.getData<PlayerPetOVSelect>();
|
||||
pets[index].isSelect = !pets[index].isSelect;
|
||||
this.onUpdateSelect();
|
||||
|
||||
}
|
||||
|
||||
//点击合成
|
||||
async onClickUp(){
|
||||
//获取被合成的Id
|
||||
let pets = this.pets.filter(pet => pet.isSelect).map(pet => pet.petId);
|
||||
let pets = this.views.getData<PlayerPetOVSelect>().filter(pet => pet.isSelect).map(pet => pet.petId);
|
||||
|
||||
if(pets.length <= 0){
|
||||
app.layer.Open(GUI.Tips,{text:"请选择需要被合成的宠物"});
|
||||
|
Reference in New Issue
Block a user