继续完善,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();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/hero/HeroCard.ts.meta
Normal file
9
assets/script/game/hero/HeroCard.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "d7e27567-5e31-483e-bd8e-c4efd272660c",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
37
assets/script/game/hero/HeroCardComp.ts
Normal file
37
assets/script/game/hero/HeroCardComp.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { _decorator } 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 { HeroHomeComp } from "../map/HeroHomeComp";
|
||||
|
||||
const { ccclass, property } = _decorator;
|
||||
|
||||
/** 视图层对象 */
|
||||
@ccclass('HeroCardComp')
|
||||
@ecs.register('HeroCardComp', false)
|
||||
export class HeroCardComp extends CCComp {
|
||||
@property(HeroHomeComp)
|
||||
hcc_home: HeroHomeComp = null!;
|
||||
hcc_uuid: number = 0;
|
||||
|
||||
/** 视图层逻辑代码分离演示 */
|
||||
start() {
|
||||
this.hcc_home=this.node.parent.parent.parent.parent.getComponent(HeroHomeComp);
|
||||
// console.log("hero_card hcc_home",this.hcc_home)
|
||||
|
||||
}
|
||||
show_info(){
|
||||
this.hcc_home.hero_show(this.hcc_uuid)
|
||||
}
|
||||
/** 全局消息逻辑处理 */
|
||||
// private onHandler(event: string, args: any) {
|
||||
// switch (event) {
|
||||
// case ModuleEvent.Cmd:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
||||
reset() {
|
||||
this.node.destroy();
|
||||
}
|
||||
}
|
||||
9
assets/script/game/hero/HeroCardComp.ts.meta
Normal file
9
assets/script/game/hero/HeroCardComp.ts.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "4.0.23",
|
||||
"importer": "typescript",
|
||||
"imported": true,
|
||||
"uuid": "e50aeebc-0c92-4f72-ab68-4979e639c193",
|
||||
"files": [],
|
||||
"subMetas": {},
|
||||
"userData": {}
|
||||
}
|
||||
Reference in New Issue
Block a user