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

75 lines
3.3 KiB
TypeScript

import { EventTouch, Label, Node,Sprite,SpriteAtlas,_decorator, resources } 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 { UIID } from "../common/config/GameUIConfig";
import { Items } from "../common/config/Items";
import { SkillSet } from "../common/config/SkillSet";
import { HeroInfo } from "../common/config/heroSet";
import { Hero } from "../hero/Hero";
import { HChipComp } from "../hero/HChipComp";
import { ItemComp } from "./ItemComp";
const { ccclass, property } = _decorator;
/** 视图层对象 */
@ccclass('ItemInfoComp')
@ecs.register('ItemInfo', false)
export class ItemInfoComp extends CCComp {
onAdded(args: any) {
this.node.setSiblingIndex(100);
this.node.getChildByName("item").active = false;
this.node.getChildByName("skill").active = false;
this.node.getChildByName("hero").active = false;
if(args.type==0){
this.node.getChildByName("item").active = true;
this.node.getChildByName("name").getComponent(Label).string=Items[args.uuid].name
this.node.getChildByName("info").getComponent(Label).string=Items[args.uuid].info
let itemcom = this.node.getChildByName("item").getComponent(ItemComp);
itemcom.update_data(args.uuid,args.num);
}
if(args.type==1){ //技能碎片
this.node.getChildByName("skill").active = true;
this.node.getChildByName("name").getComponent(Label).string=SkillSet[args.uuid].name+" 碎片"
this.node.getChildByName("info").getComponent(Label).string="「"+SkillSet[args.uuid].name+"」碎片,用于技能升阶"
var icon_path = "game/heros/cards"
resources.load(icon_path, SpriteAtlas, (err: any, atlas) => {
const sprite = this.node.getChildByName("skill").getChildByName("skill").getChildByName("icon").getComponent(Sprite);
// console.log("update_data",atlas,sprite)
sprite.spriteFrame = atlas.getSpriteFrame(SkillSet[args.uuid].path);
});
}
if(args.type==2){ //英雄碎片
this.node.getChildByName("hero").active = true;
this.node.getChildByName("name").getComponent(Label).string=HeroInfo[args.uuid].name+" 碎片"
this.node.getChildByName("info").getComponent(Label).string="「"+HeroInfo[args.uuid].name+"」碎片,用于强化英雄,怪物掉落和开宝箱抽卡获得"
let HChip=this.node.getChildByName("hero").getComponent(HChipComp);
HChip.update_data(args.uuid)
}
}
private onTouchEnd(event: EventTouch) {
switch (event.target.name) {
case "btn":
this.reset();
break;
}
event.propagationStopped = true;
}
reset() {
oops.gui.remove(UIID.ItemInfo, false);
// // 注:模拟二次删除清理缓存
// setTimeout(() => {
// oops.gui.remove(UIID.ItemInfo);
// }, 100);
}
protected onDestroy(): void {
console.log("释放角色信息界面");
}
}