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

56 lines
2.0 KiB
TypeScript

import { _decorator, CCInteger, Label, 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 { Items } from "../common/config/Items";
import { oops } from "../../../../extensions/oops-plugin-framework/assets/core/Oops";
import { UIID } from "../common/config/GameUIConfig";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('ItemComp')
@ecs.register('ItemComp', false)
export class ItemComp extends CCComp {
i_uuid:number = 0;
num:number = 0;
start() {
//todo 设定icon 显示
}
update_data(uuid:number,num:number){
this.i_uuid=uuid;
this.num=num;
this.node.getChildByName("num").getComponent(Label).string = num.toString();
if(num==0){
this.node.getChildByName("num").getComponent(Label).string ="";
}
let url = "gui/items";
let pathName= Items[uuid].path;
switch(Items[uuid].lv){
case 1:
this.node.getChildByName("lv1").active = true;
break;
case 2:
this.node.getChildByName("lv2").active = true;
break;
case 3:
this.node.getChildByName("lv3").active = true;
break;
case 4:
this.node.getChildByName("lv4").active = true;
break;
}
resources.load(url, SpriteAtlas, (err: any, atlas) => {
const sprite = this.node.getChildByName("icon").getComponent(Sprite);
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
});
}
show_info(){
oops.gui.open(UIID.ItemInfo, {uuid:this.i_uuid,type:0});
}
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
reset() {
this.node.destroy();
}
}