import { _decorator,Button,color,EventHandler,EventTouch,instantiate,Label,NodeEventType,Prefab,ProgressBar,resources,Sprite,SpriteAtlas,tween,UITransform,v3 } from "cc"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp"; import { HeroInfo, HeroList } from "../common/config/heroSet"; import { HeroCard } from "../hero/HeroCard"; import { smc } from "../common/SingletonModuleComp"; import { UIID } from "../common/config/GameUIConfig"; import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops"; import { Items } from "../common/config/Items"; import { SkillSet } from "../common/config/SkillSet"; import { LvUp, SlvUp, UpGold } from "../common/config/RoleSet"; import { HChipComp } from "../hero/HChipComp"; const { ccclass, property } = _decorator; /** 视图层对象 */ @ccclass('HeroHomeComp') @ecs.register('HeroHome', false) export class HeroHomeComp extends CCComp { h_uuid:number=0 role:any=null hero:any=null protected onLoad(): void { } start() { // this.load_talents() console.log("hero_home start") // this.h_uuid=5001 // this.hero_show(this.h_uuid) this.loads() this.node.getChildByName("show").active=false } loads(){ let hc:number =HeroList.length let parent= this.node.getChildByName("heros").getChildByName("view").getChildByName("content") parent.getComponent(UITransform).setContentSize(720,Math.ceil(HeroList.length/5)*180) console.log("parent",parent) for (let i = 0; i < hc; i++) { if (HeroInfo[HeroList[i]].quality==3) { let hcc =ecs.getEntity(HeroCard) hcc.load(HeroList[i],parent) } } for (let i = 0; i < hc; i++) { if (HeroInfo[HeroList[i]].quality==2) { let hcc =ecs.getEntity(HeroCard) hcc.load(HeroList[i],parent) } } for (let i = 0; i < hc; i++) { if (HeroInfo[HeroList[i]].quality==1) { let hcc =ecs.getEntity(HeroCard) hcc.load(HeroList[i],parent) } } } hero_show(uuid:number) { this.node.getChildByName("show").active=true this.h_uuid=uuid this.role=smc.heros[uuid] this.hero=HeroInfo[uuid] console.log("hero_show",uuid) let skill1 = SkillSet[this.hero.sk1[0]] let skill2 = SkillSet[this.hero.sk2[0]] var sk_path = "game/skills/skill_icon" var icon_path = "game/heros/herois" this.node.getChildByName("show").getChildByName("name").getChildByName("value").getComponent(Label).string=this.hero.name resources.load(icon_path, SpriteAtlas, (err: any, atlas) => { const sprite = this.node.getChildByName("show").getChildByName("hero").getChildByName("icon").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(this.hero.path); }); resources.load(sk_path, SpriteAtlas, (err: any, atlas) => { const sprite = this.node.getChildByName("show").getChildByName("bottom").getChildByName("sk").getChildByName("skicon").getChildByName("Mask").getChildByName("icon").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(skill1.path); }); this.node.getChildByName("show").getChildByName("bottom").getChildByName("sk").getChildByName("name").getComponent(Label).string = skill1.name; this.node.getChildByName("show").getChildByName("bottom").getChildByName("sk").getChildByName("info").getComponent(Label).string = skill1.info; resources.load(sk_path, SpriteAtlas, (err: any, atlas) => { const sprite = this.node.getChildByName("show").getChildByName("bottom").getChildByName("sk2").getChildByName("skicon").getChildByName("Mask").getChildByName("icon").getComponent(Sprite); sprite.spriteFrame = atlas.getSpriteFrame(skill2.path); }); this.node.getChildByName("show").getChildByName("bottom").getChildByName("sk2").getChildByName("name").getComponent(Label).string = skill2.name; this.node.getChildByName("show").getChildByName("bottom").getChildByName("sk2").getChildByName("info").getComponent(Label).string = skill2.info; // tal.getChildByName("slv1").getChildByName("val").getComponent(Label).string = this.hero.tals[0] // tal.getChildByName("slv2").getChildByName("val").getComponent(Label).string = this.hero.tals[1] // tal.getChildByName("slv3").getChildByName("val").getComponent(Label).string = this.hero.tals[2] // tal.getChildByName("slv4").getChildByName("val").getComponent(Label).string = this.hero.tals[3] // tal.getChildByName("slv5").getChildByName("val").getComponent(Label).string = this.hero.tals[4] this.update_data() } update_data(){ let slv_node=this.node.getChildByName("show").getChildByName("name").getChildByName("slv"); let lvup=this.node.getChildByName("show").getChildByName("lvup"); let slvup=this.node.getChildByName("show").getChildByName("slvup"); let attr = this.node.getChildByName("show").getChildByName("attr"); let attr2 = this.node.getChildByName("show").getChildByName("attr2").getChildByName("other"); this.node.getChildByName("show").getChildByName("name").getChildByName("lv").getComponent(Label).string = this.role.lv.toString()+"级"; slv_node.getChildByName("slv").getComponent(Label).string = this.role.slv.toString(); this.node.getChildByName("show").getChildByName("name").getChildByName("quality").getChildByName("q1").active = this.hero.quality == 1; this.node.getChildByName("show").getChildByName("name").getChildByName("quality").getChildByName("q2").active = this.hero.quality == 2; this.node.getChildByName("show").getChildByName("name").getChildByName("quality").getChildByName("q3").active = this.hero.quality == 3; this.node.getChildByName("show").getChildByName("name").getChildByName("quality").getChildByName("k1").active = this.hero.kind == 1; this.node.getChildByName("show").getChildByName("name").getChildByName("quality").getChildByName("k2").active = this.hero.kind == 2; this.node.getChildByName("show").getChildByName("name").getChildByName("quality").getChildByName("k3").active = this.hero.kind == 3; let lvneed=(this.hero.lvexp*this.role.lv) // lvup.getChildByName("gold").getChildByName("need").getComponent(Label).string = (UpGold.LvUp*this.role.lv).toString() lvup.getChildByName("item").getChildByName("btn").getChildByName("need").getComponent(Label).string = lvneed.toString() lvup.getChildByName("item").getChildByName("btn").getChildByName("num").getComponent(Label).string = smc.vmdata.exp.num.toString() if( smc.vmdata.exp.num>=lvneed) { lvup.getChildByName("item").getChildByName("btn").getChildByName("num").getComponent(Label).color = color(0,255,0); }else{ lvup.getChildByName("item").getChildByName("btn").getChildByName("num").getComponent(Label).color = color(255,0,0); } // lvup.getChildByName("item").getChildByName("btn").getChildByName("bar").getComponent(ProgressBar).progress = smc.vmdata.exp.num/lvneed lvup.getChildByName("info").getChildByName("ap").getComponent(Label).string = "+"+this.hero.ap_up lvup.getChildByName("info").getChildByName("def").getComponent(Label).string = "+"+this.hero.def_up lvup.getChildByName("info").getChildByName("hp").getComponent(Label).string = "+"+this.hero.hp_up // lvup.getChildByName("item").getChildByName("btn").getChildByName("bar").getComponent(ProgressBar).progress = smc.vmdata.exp.num/((LvUp[0]+this.hero.lvexp)*this.role.lv) // slvup.getChildByName("gold").getChildByName("btn").getChildByName("need").getComponent(Label).string = (UpGold.SlvUp*(this.role.slv+1)).toString() let slvneed=HeroInfo[this.h_uuid].slvexp*this.role.slv let slvnum=smc.heros[this.h_uuid].num if( slvnum>=slvneed) { slvup.getChildByName("cost").getChildByName("btn").getChildByName("num").getComponent(Label).color = color(0,255,0); }else{ slvup.getChildByName("cost").getChildByName("btn").getChildByName("num").getComponent(Label).color = color(255,0,0); } slvup.getChildByName("cost").getChildByName("btn").getChildByName("need").getComponent(Label).string = slvneed.toString() slvup.getChildByName("cost").getChildByName("btn").getChildByName("num").getComponent(Label).string = slvnum.toString() // slvup.getChildByName("cost").getChildByName("btn").getChildByName("bar").getComponent(ProgressBar).progress = smc.heros[this.h_uuid].num/((SlvUp[this.role.slv]-HeroInfo[this.h_uuid].slvexp)*(1+this.role.slv)) let hchipcomp= slvup.getChildByName("cost").getChildByName("btn").getChildByName("hchip").getComponent(HChipComp) hchipcomp.update_data(this.h_uuid,0) slvup.getChildByName("info").getChildByName("ap").getComponent(Label).string = "+"+this.hero.sap_up+"%" slvup.getChildByName("info").getChildByName("def").getComponent(Label).string = "+"+this.hero.sdef_up+"%" slvup.getChildByName("info").getChildByName("hp").getComponent(Label).string = "+"+this.hero.shp_up+"%" // if( this.role.slv==5) { // slvup.getChildByName("btned").active=true // }else{ // slvup.getChildByName("btned").active=false // }; if( this.role.slv==0) { this.node.getChildByName("show").getChildByName("call").getChildByName("Node").getChildByName("cost").getChildByName("need").getComponent(Label).string = ((SlvUp[this.role.slv]-HeroInfo[this.h_uuid].slvexp)*(1+this.role.slv)).toString() this.node.getChildByName("show").getChildByName("call").getChildByName("Node").getChildByName("cost").getChildByName("num").getComponent(Label).string = smc.heros[this.h_uuid].num.toString() this.node.getChildByName("show").getChildByName("call").getChildByName("Node").getChildByName("cost").getChildByName("bar").getComponent(ProgressBar).progress = smc.heros[this.h_uuid].num/((SlvUp[this.role.slv]-HeroInfo[this.h_uuid].slvexp)*(1+this.role.slv)) let hchipcomp= this.node.getChildByName("show").getChildByName("call").getChildByName("Node").getChildByName("cost").getChildByName("hchip").getComponent(HChipComp) hchipcomp.update_data(this.h_uuid,0) this.node.getChildByName("show").getChildByName("call").active=true }else{ this.node.getChildByName("show").getChildByName("call").active=false }; attr.getChildByName("ap").getChildByName("val").getComponent(Label).string = ((this.hero.ap+this.hero.ap_up* this.role.lv)*(1+this.hero.sap_up/100*this.role.slv)).toFixed(0).toString() attr.getChildByName("hp").getChildByName("val").getComponent(Label).string = ((this.hero.hp+this.hero.hp_up* this.role.lv)*(1+this.hero.shp_up/100*this.role.slv)).toFixed(0).toString() attr.getChildByName("def").getChildByName("val").getComponent(Label).string = ((this.hero.ap+this.hero.ap_up* this.role.lv)*(1+this.hero.sdef_up/100*this.role.slv)).toFixed(0).toString() attr.getChildByName("acd").getChildByName("val").getComponent(Label).string = this.hero.a_cd attr.getChildByName("speed").getChildByName("val").getComponent(Label).string = this.hero.speed attr.getChildByName("dis").getChildByName("val").getComponent(Label).string = this.hero.dis attr2.getChildByName("crit").getChildByName("val").getComponent(Label).string = this.hero.crit+"%" attr2.getChildByName("ca").getChildByName("val").getComponent(Label).string = (150+this.hero.crit_add).toString()+"%" attr2.getChildByName("ucr").getChildByName("val").getComponent(Label).string = this.hero.ucr+"%" attr2.getChildByName("dod").getChildByName("val").getComponent(Label).string = this.hero.dodge+"%" attr2.getChildByName("aexp").getChildByName("val").getComponent(Label).string = this.hero.aexp attr2.getChildByName("uaexp").getChildByName("val").getComponent(Label).string = this.hero.uaexp attr2.getChildByName("cexp").getChildByName("val").getComponent(Label).string = this.hero.cexp attr2.getChildByName("doexp").getChildByName("val").getComponent(Label).string = this.hero.doexp attr2.getChildByName("dexp").getChildByName("val").getComponent(Label).string = this.hero.dexp oops.message.dispatchEvent("hero_card_update_info",{uuid:this.h_uuid}) } lv_selcet(e:any,val:any){ let active = this.node.getChildByName("show").getChildByName("menu").getChildByName("active") tween(active).to(0.1,{position:v3(val,0)}).start() let hero = this.node.getChildByName("show").getChildByName("hero") let attr = this.node.getChildByName("show").getChildByName("attr") let attr2 = this.node.getChildByName("show").getChildByName("attr2") let info = this.node.getChildByName("show").getChildByName("info") let lvup = this.node.getChildByName("show").getChildByName("lvup") let sk = this.node.getChildByName("show").getChildByName("bottom").getChildByName("sk") let slvup = this.node.getChildByName("show").getChildByName("slvup") if(val < 0){ tween(hero).to(0.2,{position:v3(0,hero.position.y)}).start() tween(attr).to(0.2,{position:v3(0,attr.position.y)}).start() tween(attr2).to(0.2,{position:v3(0,attr2.position.y)}).start() tween(lvup).to(0.2,{position:v3(0,lvup.position.y)}).start() tween(sk).to(0.2,{position:v3(1000,sk.position.y)}).start() tween(slvup).to(0.2,{position:v3(1000,slvup.position.y)}).start() }else{ tween(hero).to(0.2,{position:v3(-1000,hero.position.y)}).start() tween(attr).to(0.2,{position:v3(-1000,attr.position.y)}).start() tween(attr2).to(0.2,{position:v3(-1000,attr2.position.y)}).start() tween(lvup).to(0.2,{position:v3(-1000,lvup.position.y)}).start() tween(sk).to(0.2,{position:v3(0,sk.position.y)}).start() tween(slvup).to(0.2,{position:v3(0,slvup.position.y)}).start() } } lv_up(){ if(smc.vmdata.exp.num < ((this.hero.lvexp)*this.role.lv)){ oops.gui.toast("资源不足,升级失败"); return } smc.vmdata.exp.num -= ((this.hero.lvexp)*this.role.lv) this.role.lv++ this.update_data() } slv_up(){ if(this.role.slv>=5){ oops.gui.toast("已经满星,升阶失败"); return } if(smc.heros[this.h_uuid].num < (HeroInfo[this.h_uuid].slvexp*this.role.slv)){ oops.gui.toast("资源不足,升阶失败"); return } smc.heros[this.h_uuid].num -= (HeroInfo[this.h_uuid].slvexp*this.role.slv) this.role.slv++ this.update_data() } item_show(e:any,val:any){ oops.gui.open(UIID.ItemInfo, {uuid:val,type:0}); } close_show(){ this.node.getChildByName("show").active=false } reset() { this.node.destroy(); } }