Files
heros/assets/script/game/map/RewardComp.ts

60 lines
2.2 KiB
TypeScript

import { _decorator, instantiate, Label, Prefab, resources, Sprite, SpriteAtlas } 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 { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { Items } from "../common/config/Items";
import { HChipComp } from "../hero/HChipComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('RewardComp')
@ecs.register('RewardComp', false)
export class RewardComp extends CCComp {
i_uuid: number = 0;
x1: number = 0;
x10: number = 0;
/** 视图层逻辑代码分离演示 */
start() {
// var entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
// this.on(ModuleEvent.Cmd, this.onHandler, this);
}
init(uuid:number,x1:number,x10:number,parent:any,type:number=0){
if(type==0){
var icon_path = "gui/items"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = this.node.getChildByName("icon").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(Items[uuid].path);
});
}
if(type==1){
this.node.getChildByName("icon").active=false
this.node.getChildByName("hchip").active=true
let hchipcomp= this.node.getChildByName("hchip").getComponent(HChipComp)
hchipcomp.update_data(uuid,0)
}
this.node.getChildByName("x1").getComponent(Label).string = x1.toString()
this.node.getChildByName("x10").getComponent(Label).string = x10.toString()
this.node.parent = parent
}
protected onDestroy(): void {
console.log("释放奖励界面");
}
/** 全局消息逻辑处理 */
// private onHandler(event: string, args: any) {
// switch (event) {
// case ModuleEvent.Cmd:
// break;
// }
// }
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}