继续完善,todo herocard 点击后显示信息
This commit is contained in:
41
assets/script/game/hero/HeroCard.ts
Normal file
41
assets/script/game/hero/HeroCard.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { instantiate, Label, Prefab, resources, Sprite, SpriteAtlas } from "cc";
|
||||
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
|
||||
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
|
||||
import { HeroCardComp } from "./HeroCardComp";
|
||||
import { smc } from "../common/SingletonModuleComp";
|
||||
|
||||
/** HeroCard 模块 */
|
||||
@ecs.register(`HeroCard`)
|
||||
export class HeroCard extends ecs.Entity {
|
||||
|
||||
protected init() {
|
||||
// this.addComponents<ecs.Comp>();
|
||||
}
|
||||
load(uuid:number=101,parent:any) {
|
||||
// var path = "game/monster/"+prefab_path;
|
||||
var path = "game/gui/hero_card";
|
||||
var icon_path = "game/heros/herois"
|
||||
var prefab: Prefab = oops.res.get(path, Prefab)!;
|
||||
var node = instantiate(prefab);
|
||||
node.parent = parent;
|
||||
node.getChildByName("name").getComponent(Label).string = smc.heros[uuid].name
|
||||
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
|
||||
const sprite = node.getChildByName("Mask").getChildByName("hero").getComponent(Sprite);
|
||||
sprite.spriteFrame = atlas.getSpriteFrame(smc.heros[uuid].path);
|
||||
});
|
||||
node.getChildByName("lv").getComponent(Label).string = smc.vmdata.heros[uuid].lv.toString();
|
||||
if(smc.vmdata.heros[uuid].slv>=1) node.getChildByName("slv").getChildByName("s1").active=true;
|
||||
if(smc.vmdata.heros[uuid].slv>=2) node.getChildByName("slv").getChildByName("s2").active=true;
|
||||
if(smc.vmdata.heros[uuid].slv>=3) node.getChildByName("slv").getChildByName("s3").active=true;
|
||||
if(smc.vmdata.heros[uuid].slv>=4) node.getChildByName("slv").getChildByName("s4").active=true;
|
||||
if(smc.vmdata.heros[uuid].slv>=5) node.getChildByName("slv").getChildByName("s5").active=true;
|
||||
let hcc = node.getComponent(HeroCardComp)!;
|
||||
hcc.hcc_uuid = uuid;
|
||||
this.add(hcc);
|
||||
}
|
||||
/** 模块资源释放 */
|
||||
destroy() {
|
||||
// 注: 自定义释放逻辑,视图层实现 ecs.IComp 接口的 ecs 组件需要手动释放
|
||||
super.destroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user