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 { smc } from '../common/SingletonModuleComp'; import { GameEvent } from '../common/config/GameEvent'; import { NumberFormatter } from '../common/config/BoxSet'; import { Items } from '../common/config/Items'; import { finishCurrGuide, GuideConfig, startGuide } from '../common/config/Guide'; const { ccclass, property } = _decorator; @ccclass('HInfoComp') export class HInfoComp extends Component { h_uuid:number=0 start() { } onAdded(args: any) { console.log("[HInfoComp]:onAdded",this.node) this.update_data(args) startGuide(5) } update(deltaTime: number) { } update_data(uuid:number){ 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 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("list2").getChildByName("lock").active= lv <5 this.node.getChildByName("skills").getChildByName("list3").getChildByName("lock").active= lv <10 this.node.getChildByName("skills").getChildByName("list4").getChildByName("lock").active= lv <15 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]招募失败") 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升级成功`) oops.message.dispatchEvent(GameEvent.HeroLvUp, {uuid:this.h_uuid}) } next_hero(){ let heros=getHeroList() let index = heros.indexOf(this.h_uuid); index++ if(index==heros.length) index=0 let nextHero = heros[index]; this.update_data(nextHero) } prev_hero(){ let heros=getHeroList() let index = heros.indexOf(this.h_uuid); index-- if(index==-1) index=heros.length-1 let prevHero = heros[index]; this.update_data(prevHero) } close(){ finishCurrGuide(6) startGuide(7) oops.gui.removeByNode(this.node) } reset() { this.node.destroy() } }