import { _decorator, Animation, AnimationClip, Component, Label, Node, resources } from 'cc'; import { oops } from 'db://oops-framework/core/Oops'; import { UIID } from '../common/config/GameUIConfig'; import { getHeroList, getHeroStatsByLevel, getUpgradeResources, HeroInfo, HType } from '../common/config/heroSet'; import { smc } from '../common/SingletonModuleComp'; import { GameEvent } from '../common/config/GameEvent'; const { ccclass, property } = _decorator; @ccclass('HInfoComp') export class HInfoComp extends Component { h_uuid:number=0 start() { } onAdded(args: any) { console.log("[HInfoComp]:onAdded",args) this.update_data(args) } update(deltaTime: number) { } update_data(uuid:number){ console.log("[HInfoComp]:update_data",uuid) console.log("[HCardUICom]:update_data",uuid) this.h_uuid=uuid let hero_data = HeroInfo[uuid] let hero= this.node.getChildByName("hero") let lv=smc.heros[uuid]?.lv??1 let anm_path=hero_data.path resources.load("game/heros/hero/"+anm_path+"/idle", AnimationClip, (err, clip) => { hero.getComponent(Animation).addClip(clip); 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("luck").active= lv <5 this.node.getChildByName("skills").getChildByName("list3").getChildByName("luck").active= lv <10 this.node.getChildByName("skills").getChildByName("list4").getChildByName("luck").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) let need_node=this.node.getChildByName("upNeed").getChildByName("need") need_node.getChildByName("exp").getChildByName("need").getComponent(Label).string=experience.toString() need_node.getChildByName("gold").getChildByName("need").getComponent(Label).string=gold.toString() 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_luck(smc.heros[uuid]?.lv??0) } show_luck(lv:number){ this.node.getChildByName("upBtn").active=lv > 0 this.node.getChildByName("upNeed").active=lv > 0 this.node.getChildByName("luck").active=lv == 0 } uplevel(){ let lv=smc.heros[this.h_uuid].lv let {experience,gold}=getUpgradeResources(lv) if(smc.vmdata.data.exp<=experience||smc.vmdata.data.gold<=gold){ oops.gui.toast("经验或金币不足") return } smc.spendGameProperty({exp:experience,gold:gold},false) let result=smc.levelUpHero(this.h_uuid,experience,gold) if(!result){ smc.addExp(experience,false) smc.addGold(gold,false) oops.gui.toast("网络出错了,升级失败,请重试") return } this.update_data(this.h_uuid) oops.message.dispatchEvent(GameEvent.UpdateHero, {}) } 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(){ oops.gui.removeByNode(this.node) } }