75 lines
2.5 KiB
TypeScript
75 lines
2.5 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';
|
|
import { startGuide } from '../common/config/Guide';
|
|
const { ccclass, property } = _decorator;
|
|
|
|
@ccclass('HeroSelectCom')
|
|
export class HeroSelectCom extends Component {
|
|
slot:number=0
|
|
start() {
|
|
console.log("[HeroSelectCom]:start",this.node)
|
|
}
|
|
onAdded(args: any) {
|
|
// console.log("[HeroSelectCom]:onAdded",args)
|
|
this.slot=args.slot
|
|
startGuide(9)
|
|
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,i)
|
|
}
|
|
}
|
|
}
|
|
|
|
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,index: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.name="hero"+index.toString()
|
|
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()
|
|
}
|
|
}
|
|
|
|
|