Files
heros/assets/script/game/map/HeroSelectCom.ts
2025-08-21 22:57:29 +08:00

72 lines
2.3 KiB
TypeScript

import { _decorator, Component, instantiate, Node, Prefab, UITransform, Vec3 } from 'cc';
import { oops } from 'db://oops-framework/core/Oops';
import { HCardUICom } from './HCardUICom';
import { smc } from '../common/SingletonModuleComp';
import { HeroConSet } from '../common/config/BoxSet';
const { ccclass, property } = _decorator;
@ccclass('HeroSelectCom')
export class HeroSelectCom extends Component {
slot:number=0
start() {
}
onAdded(args: any) {
// console.log("[HeroSelectCom]:onAdded",args)
this.slot=args.slot
this.update_heros()
}
protected onDisable(): void {
// console.log("[HeroSelectCom]:onDisable")
this.clear_heros()
}
update_heros(){
let heros=smc.getHasHeroUUID()
let width= heros.length*230+20
this.node.getChildByName("main").getChildByName("view").getChildByName("heros").getComponent(UITransform).setContentSize(width,320)
// console.log("[HeroPageComp]:UITransform width",this.node.getChildByName("main").getChildByName("view").getChildByName("heros").getComponent(UITransform))
for(let i=0;i<heros.length;i++){
let hero=heros[i]
// console.log("[HeroPageComp]:hero",hero)
if(hero){
this.load_hero(hero)
}
}
}
clear_heros(){
let parent=this.node.getChildByName("main").getChildByName("view").getChildByName("heros")
let children=parent.children
// console.log("[HeroPageComp]:clear_heros",children)
for(let i=0;i<children.length;i++){
children[i].destroy()
}
}
load_hero(uuid:number){
// console.log("[HeroPageComp]:load_hero",uuid)
let parent=this.node.getChildByName("main").getChildByName("view").getChildByName("heros")
let path = "game/gui/hcard"
const prefab = oops.res.get(path, Prefab);
if (!prefab) {
console.error("[Skill] 预制体加载失败:", path);
return;
}
const node = instantiate(prefab) as unknown as Node;
node.parent = parent;
let hcard = node.getComponent(HCardUICom)!;
hcard.update_data(uuid,{type:HeroConSet.SELECT,slot:this.slot})
}
update(deltaTime: number) {
}
close(){
oops.gui.removeByNode(this.node)
}
reset() {
this.node.destroy()
}
}