refactor(gui): 首页 英雄选择信息更新 初步 完成
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { _decorator, Animation, AnimationClip, Component, Label, Node, resources, Sprite, SpriteFrame } from 'cc';
|
||||
import { oops } from 'db://oops-framework/core/Oops';
|
||||
import { UIID } from '../common/config/GameUIConfig';
|
||||
import { getHeroList, getHeroStatsByLevel, getUpgradeResources, HeroInfo, HType, unlockHeroCost } from '../common/config/heroSet';
|
||||
import { getHeroList, getHeroStatsByLevel, getUpgradeResources, HeroInfo, HType, HTypeName, unlockHeroCost } from '../common/config/heroSet';
|
||||
import { smc } from '../common/SingletonModuleComp';
|
||||
import { GameEvent } from '../common/config/GameEvent';
|
||||
import { NumberFormatter } from '../common/config/BoxSet';
|
||||
@@ -12,13 +12,19 @@ const { ccclass, property } = _decorator;
|
||||
@ccclass('HInfoComp')
|
||||
export class HInfoComp extends Component {
|
||||
h_uuid:number=0
|
||||
name_node:any=null
|
||||
type_node:any=null
|
||||
ap_node:any=null
|
||||
hp_node:any=null
|
||||
def_node:any=null
|
||||
start() {
|
||||
|
||||
}
|
||||
onAdded(args: any) {
|
||||
console.log("[HInfoComp]:onAdded",this.node)
|
||||
this.update_data(args)
|
||||
startGuide(5)
|
||||
this.name_node=this.node.getChildByName("hero").getChildByName("hname").getChildByName("name")
|
||||
this.type_node=this.node.getChildByName("hero").getChildByName("hname").getChildByName("type")
|
||||
this.ap_node=this.node.getChildByName("info").getChildByName("base").getChildByName("ap").getChildByName("num")
|
||||
this.hp_node=this.node.getChildByName("info").getChildByName("base").getChildByName("hp").getChildByName("num")
|
||||
this.def_node=this.node.getChildByName("info").getChildByName("base").getChildByName("def").getChildByName("num")
|
||||
this.h_uuid=smc.fight_heros[0]
|
||||
this.update_data(this.h_uuid)
|
||||
}
|
||||
update(deltaTime: number) {
|
||||
|
||||
@@ -27,102 +33,16 @@ export class HInfoComp extends Component {
|
||||
this.h_uuid=uuid
|
||||
let hero_data = HeroInfo[uuid]
|
||||
console.log("[HInfoComp]:update_data",uuid,hero_data,this.node)
|
||||
let lv=smc.heros[uuid]?.lv??1
|
||||
this.name_node.getComponent(Label).string=hero_data.name
|
||||
this.type_node.getComponent(Label).string=HTypeName[hero_data.type]
|
||||
this.ap_node.getComponent(Label).string=hero_data.ap.toString()
|
||||
this.hp_node.getComponent(Label).string=hero_data.hp.toString()
|
||||
this.def_node.getComponent(Label).string=hero_data.def.toString()
|
||||
let anm_path=hero_data.path
|
||||
resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => {
|
||||
this.node.getChildByName("hero").getComponent(Animation).addClip(clip);
|
||||
this.node.getChildByName("hero").getComponent(Animation).play("idle");
|
||||
});
|
||||
this.node.getChildByName("name").getComponent(Label).string=hero_data.name
|
||||
this.node.getChildByName("lv").getChildByName("num").getComponent(Label).string=lv.toString()
|
||||
this.node.getChildByName("skills").getChildByName("sk2").getChildByName("lock").active= lv <5
|
||||
this.node.getChildByName("skills").getChildByName("sk3").getChildByName("lock").active= lv <10
|
||||
this.node.getChildByName("skills").getChildByName("sk4").getChildByName("lock").active= lv <15
|
||||
this.node.getChildByName("skills").getChildByName("sk5").getChildByName("lock").active= lv <20
|
||||
let {hp,ap,def}=getHeroStatsByLevel(uuid,lv)
|
||||
this.node.getChildByName("info").getChildByName("hp").getChildByName("num").getComponent(Label).string=hp.toString()
|
||||
this.node.getChildByName("info").getChildByName("ap").getChildByName("num").getComponent(Label).string=ap.toString()
|
||||
this.node.getChildByName("info").getChildByName("def").getChildByName("num").getComponent(Label).string=def.toString()
|
||||
let {experience,gold}=getUpgradeResources(lv)
|
||||
this.updata_need(experience,gold)
|
||||
this.node.getChildByName("upBtn").active=smc.data.exp>=experience&&smc.data.gold>=gold
|
||||
this.node.getChildByName("type").getChildByName("w").active=hero_data.type==HType.warrior
|
||||
this.node.getChildByName("type").getChildByName("r").active=hero_data.type==HType.remote
|
||||
this.node.getChildByName("type").getChildByName("m").active=hero_data.type==HType.mage
|
||||
this.show_lock(smc.heros[uuid]?.lv??0)
|
||||
}
|
||||
updata_need(experience:number,gold:number){
|
||||
let need_node=this.node.getChildByName("upNeed").getChildByName("need")
|
||||
need_node.getChildByName("exp").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(experience)
|
||||
need_node.getChildByName("gold").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(gold)
|
||||
need_node.getChildByName("exp").getChildByName("has").getComponent(Label).string=NumberFormatter.formatNumber(smc.data.exp)
|
||||
need_node.getChildByName("gold").getChildByName("has").getComponent(Label).string=NumberFormatter.formatNumber(smc.data.gold)
|
||||
}
|
||||
show_lock(lv:number){
|
||||
|
||||
if(lv==0){
|
||||
console.log("[HInfoComp]:show_lock lv==0",this.node)
|
||||
finishCurrGuide(3)
|
||||
startGuide(4)
|
||||
}
|
||||
this.node.getChildByName("upBtn").active=lv > 0
|
||||
this.node.getChildByName("upNeed").active=lv > 0
|
||||
this.node.getChildByName("lock").active=lv == 0
|
||||
this.node.getChildByName("unLock").active=lv == 0
|
||||
let need_item=unlockHeroCost[HeroInfo[this.h_uuid].quality]
|
||||
// console.log("[HInfoComp]:show_lock item:item_uuid:hero_uuid:hero_data",Items[need_item.i_uuid],need_item.i_uuid,this.h_uuid,HeroInfo[this.h_uuid])
|
||||
|
||||
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("has").getComponent(Label).string=smc.items[need_item.i_uuid]??0
|
||||
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("need").getComponent(Label).string=NumberFormatter.formatNumber(need_item.num)
|
||||
let path="gui/items/"+Items[need_item.i_uuid].path
|
||||
resources.load(path,SpriteFrame, (err, clip) => {
|
||||
this.node.getChildByName("unLockNeed").getChildByName("need").getChildByName("icon").getComponent(Sprite).spriteFrame=clip
|
||||
});
|
||||
this.node.getChildByName("unLockNeed").active=lv == 0
|
||||
}
|
||||
uplockhero(){
|
||||
let need_item=unlockHeroCost[HeroInfo[this.h_uuid].quality]
|
||||
if(!smc.items[need_item.i_uuid]||smc.items[need_item.i_uuid]<need_item.num){
|
||||
oops.gui.toast("["+Items[need_item.i_uuid].name+"]数量不足")
|
||||
return
|
||||
}
|
||||
if(!smc.spendItem(need_item.i_uuid,need_item.num)){
|
||||
smc.error()
|
||||
return
|
||||
}
|
||||
if(!smc.addHero(this.h_uuid)){
|
||||
smc.addItem(need_item.i_uuid,need_item.num,false)
|
||||
oops.gui.toast("英雄< "+HeroInfo[this.h_uuid].name+" >招募失败")
|
||||
return
|
||||
}
|
||||
oops.gui.toast("英雄< "+HeroInfo[this.h_uuid].name+" >招募成功")
|
||||
finishCurrGuide(4)
|
||||
startGuide(5)
|
||||
this.update_data(this.h_uuid)
|
||||
oops.message.dispatchEvent(GameEvent.HeroUnlock, {uuid:this.h_uuid})
|
||||
}
|
||||
uplevel(){
|
||||
let lv=smc.heros[this.h_uuid].lv
|
||||
let {experience,gold}=getUpgradeResources(lv)
|
||||
if(smc.data.exp<experience||smc.data.gold<gold){
|
||||
oops.gui.toast("经验或金币不足")
|
||||
return
|
||||
}
|
||||
if(!smc.spendGameProperty({exp:experience,gold:gold},false)){
|
||||
smc.error()
|
||||
return
|
||||
}
|
||||
if(!smc.levelUpHero(this.h_uuid)){
|
||||
smc.addExp(experience,false)
|
||||
smc.addGold(gold,false)
|
||||
smc.error()
|
||||
return
|
||||
}
|
||||
this.update_data(this.h_uuid)
|
||||
finishCurrGuide(5)
|
||||
startGuide(6)
|
||||
oops.gui.toast(`英雄< ${HeroInfo[this.h_uuid].name} >升级成功`)
|
||||
oops.message.dispatchEvent(GameEvent.HeroLvUp, {uuid:this.h_uuid})
|
||||
}
|
||||
next_hero(){
|
||||
let heros=getHeroList()
|
||||
|
||||
Reference in New Issue
Block a user