mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
简单的升星
This commit is contained in:
114
JisolGameCocos/assets/script/ui/Pet/PetUpStarView.ts
Normal file
114
JisolGameCocos/assets/script/ui/Pet/PetUpStarView.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
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:"合成成功"});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "f8ba437e-6ea7-43f3-8214-2b98fe19202a",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
Reference in New Issue
Block a user