48 lines
1.8 KiB
TypeScript
48 lines
1.8 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=0){
|
|
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;
|
|
this.node.getChildByName("lv1").active = Items[uuid].lv==1;
|
|
this.node.getChildByName("lv2").active = Items[uuid].lv==2;
|
|
this.node.getChildByName("lv3").active = Items[uuid].lv==3;
|
|
this.node.getChildByName("lv4").active = Items[uuid].lv==4;
|
|
|
|
resources.load(url, SpriteAtlas, (err: any, atlas) => {
|
|
const sprite = this.node.getChildByName("icon").getComponent(Sprite);
|
|
sprite.spriteFrame = atlas.getSpriteFrame(pathName);
|
|
});
|
|
}
|
|
show_info(){
|
|
if(this.node.parent.name=="item_info") return
|
|
oops.gui.open(UIID.ItemInfo, {uuid:this.i_uuid,type:0});
|
|
}
|
|
|
|
/** 视图对象通过 ecs.Entity.remove(ModuleViewComp) 删除组件是触发组件处理自定义释放逻辑 */
|
|
reset() {
|
|
this.node.destroy();
|
|
}
|
|
} |