148 lines
4.3 KiB
TypeScript
Raw Normal View History

2023-11-26 03:06:23 +08:00
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';
2023-11-27 02:10:42 +08:00
import PlayerPetData, { PlayerPetEvent } from '../../data/PlayerPetData';
2023-11-26 03:06:23 +08:00
import { API, PlayerPetOV } from '../../consts/API';
import { PetOV, PlayerPetOVSelect } from '../VO/PetOV';
import { Label } from 'cc';
import { app, TD } from '../../App';
2023-11-27 02:10:42 +08:00
import JProgressBar from '../../../../extensions/ngame/assets/ngame/util/components/Progress/JProgressBar';
2024-01-18 03:19:43 +08:00
import { Slider } from 'cc';
import ResourceData, { ResourceType } from '../../data/ResourceData';
import { GUI } from '../UIConfig';
import { PetPreviewWindow } from '../Consts/Pet/info/PetPreviewWindow';
2023-11-26 03:06:23 +08:00
const { ccclass, property } = _decorator;
@ccclass('PetUpStarView')
export class PetUpStarView extends JNLayerBase {
@property(Label)
petNameLabel:Label; //宠物名称
@property(Label)
petStar:Label; //宠物星级
@property(Label)
petStarExp:Label; //宠物星级经验
2023-11-27 02:10:42 +08:00
@property(JProgressBar)
petExpProgress:JProgressBar; //宠物经验条
@property(JProgressBar)
viewPetExpProgress:JProgressBar; //预览宠物经验条
2023-11-26 03:06:23 +08:00
2024-01-18 03:19:43 +08:00
@property(PetPreviewWindow)
petPreview:PetPreviewWindow; //宠物显示窗口
@property(Slider)
slider:Slider; //滑块
@property(Label)
qsLabel:Label; //魂数量
//消耗数量
_consume:number = 0;
get consume(){
return Math.min(ResourceData.getIns().getValue(ResourceType.Q1S),this._consume);
}
set consume(value:number){
let max = ResourceData.getIns().getValue(ResourceType.Q1S);
this._consume = value;
//修正
this.slider.progress = this.consume / max;
this.qsLabel.string = `${ResourceData.getIns().getValue(ResourceType.Q1S) - this.consume}`
}
2023-12-28 02:56:34 +08:00
2023-11-26 03:06:23 +08:00
data:PlayerPetOV;
onJNLoad(data: PlayerPetOV): void {
super.onJNLoad(data);
this.data = data;
this.onUpdateView();
2023-11-27 02:10:42 +08:00
//监听
app.event.on(PlayerPetEvent.UPDATE_INFO,this.onUpdateInfo,this); //刷新宠物信息
}
onJNClose(): void {
//取消监听
app.event.off(PlayerPetEvent.UPDATE_INFO,this.onUpdateInfo,this); //刷新宠物信息
2023-11-26 03:06:23 +08:00
}
//刷新页面
onUpdateView(){
2024-01-18 03:19:43 +08:00
//显示选中宠物
this.petPreview.bind(this.data);
2023-11-26 03:06:23 +08:00
this.onUpdateInfo();
}
//刷新信息
onUpdateInfo(){
//显示宠物名称
this.petNameLabel.string = TD.TbGRole.get(this.data.petTbId).roleName;
this.petStar.string = `当前星级: ${this.data.petStar}`;
2023-11-27 02:10:42 +08:00
let upStarExp = TD.TbGRoleUpStar.get(this.data.petStar + 1).merge;
this.petStarExp.string = `升级进度: ${upStarExp} / ${this.data.petStarExp}`;
2023-11-27 02:22:24 +08:00
this.petExpProgress.value = this.data.petStar + (this.data.petStarExp / upStarExp);
2023-11-26 03:06:23 +08:00
2024-01-18 03:19:43 +08:00
this.qsLabel.string = `${ResourceData.getIns().getValue(ResourceType.Q1S) - this.consume}`
2023-11-27 02:10:42 +08:00
}
//更新预览进度条
onUpdatePreview(){
let upStarExp;
2024-01-18 03:19:43 +08:00
let petStarExp = this.data.petStarExp + this.consume;
2023-11-27 02:10:42 +08:00
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}`;
//预览进度
2023-11-27 02:22:24 +08:00
this.viewPetExpProgress.value = petStar + (petStarExp / upStarExp);
2024-01-18 03:19:43 +08:00
this.qsLabel.string = `${ResourceData.getIns().getValue(ResourceType.Q1S) - this.consume}`
2023-11-27 02:10:42 +08:00
2023-11-26 03:06:23 +08:00
}
2024-01-18 03:19:43 +08:00
//滑动滑块
onSliderMove(slider: Slider){
let max = ResourceData.getIns().getValue(ResourceType.Q1S);
if(!max){
this.consume = 0;
return;
2023-11-26 03:06:23 +08:00
}
2024-01-18 03:19:43 +08:00
this.consume = Math.ceil(max * slider.progress);
this.onUpdatePreview();
2023-11-26 03:06:23 +08:00
}
2024-01-18 03:19:43 +08:00
//选择全部
onClickAll(){
2023-11-26 03:06:23 +08:00
}
//点击合成
async onClickUp(){
2023-12-28 02:56:34 +08:00
2024-01-18 03:19:43 +08:00
if(!this.consume){
app.layer.Open(GUI.Tips,{text:"拖拽进行升星吧~"})
2023-11-26 03:06:23 +08:00
return;
}
2024-01-18 03:19:43 +08:00
await API.PetUpStar(this.data.petId,this.consume);
this.consume = 0;
2023-12-28 02:56:34 +08:00
}
2023-11-26 03:06:23 +08:00
}