Files
heros/assets/script/game/map/HCardUICom.ts
2025-08-25 17:28:02 +08:00

111 lines
4.9 KiB
TypeScript

import { _decorator, Animation, AnimationClip, Component, Label, Node, resources } from 'cc';
import { HeroInfo, HType } from '../common/config/heroSet';
import { smc } from '../common/SingletonModuleComp';
import { oops } from 'db://oops-framework/core/Oops';
import { UIID } from '../common/config/GameUIConfig';
import { GameSet, HeroConSet, QualitySet } from '../common/config/BoxSet';
import { HttpReturn } from 'db://oops-framework/libs/network/HttpRequest';
import { GameEvent } from '../common/config/GameEvent';
import { ecs } from 'db://oops-framework/libs/ecs/ECS';
import { CCComp } from 'db://oops-framework/module/common/CCComp';
import { finishCurrGuide, startGuide } from '../common/config/Guide';
const { ccclass, property } = _decorator;
@ccclass('HCardUICom')
@ecs.register('HCardUICom', false)
export class HCardUICom extends CCComp {
h_uuid:number=0
type:number=0
slot:number=0
start() {
// console.log("[HCardUICom]:start")
}
protected onLoad(): void {
this.on(GameEvent.UpdateHero,this.to_update_hero,this)
this.on(GameEvent.HeroUnlock,this.to_update_hero,this)
this.on(GameEvent.HeroLvUp,this.to_update_hero,this)
}
update(deltaTime: number) {
}
to_update_hero(event:any,args:any){
if(args.uuid==this.h_uuid){
console.log("[HCardUICom]:是我诶:",HeroInfo[args.uuid].name+args.uuid,this.h_uuid)
this.update_data(this.h_uuid,{type:this.type})
}
}
update_data(uuid:number,args:any){
this.type=args.type
if(args.slot) this.slot=args.slot
console.log("[HCardUICom]:update_data",uuid,this.type,this.slot,args,this.node)
this.h_uuid=uuid
this.node.getChildByName("in_fight").active=this.check_in_fight()
let hero_data = HeroInfo[uuid]
let hero= this.node.getChildByName("hero")
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
let lv=smc.heros[uuid]?.lv??0
this.node.getChildByName("luck").active=lv==0
this.node.getChildByName("lv").getChildByName("num").getComponent(Label).string=lv > 0 ? lv.toString() : ""
this.node.getChildByName("lv").active=lv > 0
// this.node.getChildByName("slv").getChildByName("lv1").active=smc.heros[uuid].slv>=1
// this.node.getChildByName("slv").getChildByName("lv2").active=smc.heros[uuid].slv>=2
// this.node.getChildByName("slv").getChildByName("lv3").active=smc.heros[uuid].slv>=3
// this.node.getChildByName("slv").getChildByName("lv4").active=smc.heros[uuid].slv>=4
// this.node.getChildByName("slv").getChildByName("lv5").active=smc.heros[uuid].slv>=5
this.node.getChildByName("g").active=hero_data.quality==QualitySet.GREEN
this.node.getChildByName("gg").active=hero_data.quality==QualitySet.GREEN
this.node.getChildByName("b").active=hero_data.quality==QualitySet.BLUE
this.node.getChildByName("bg").active=hero_data.quality==QualitySet.BLUE
this.node.getChildByName("p").active=hero_data.quality==QualitySet.PURPLE
this.node.getChildByName("pg").active=hero_data.quality==QualitySet.PURPLE
this.node.getChildByName("y").active=hero_data.quality==QualitySet.ORANGE
this.node.getChildByName("yg").active=hero_data.quality==QualitySet.ORANGE
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
}
do_click(){
switch(this.type){
case HeroConSet.INFO:
oops.gui.open(UIID.HeroInfo,this.h_uuid)
break
case HeroConSet.SELECT:
finishCurrGuide(9)
startGuide(10)
if(oops.gui.has(UIID.HeroSelect)) {
this.check_in_slot()
smc.setFightHero(this.slot,this.h_uuid,true)
oops.message.dispatchEvent(GameEvent.UpdateFightHero)
oops.gui.remove(UIID.HeroSelect)
}
break
}
}
check_in_slot(){ //如果英雄在出战位,则移除久的出战位
let heros=smc.fight_heros
for(let i=0;i<GameSet.HERO_NUM;i++){
if(heros[i]==this.h_uuid) {
smc.setFightHero(i,0,true)
}
}
}
check_in_fight(){
let heros=smc.fight_heros
for(let i=0;i<GameSet.HERO_NUM;i++){
if(heros[i]==this.h_uuid) return true
}
return false
}
reset() {
this.node.destroy()
}
}