import ItemUtil from "../core/ItemUtil"; import SKDataUtil from "../gear_2.3.4/util/SKDataUtil"; import TransformationUtil from "../transformation/TransformationUtil"; const { ccclass, property } = cc._decorator; @ccclass export default class BagItem extends cc.Component { @property(cc.Sprite) item_icon: cc.Sprite = null; @property(cc.Prefab) item_detail: cc.Prefab = null; @property(cc.Node) item_bg: cc.Node = null; @property(cc.Label) item_count: cc.Label = null; @property(cc.Node) item_selected: cc.Node = null @property(cc.SpriteFrame) lockIcon: cc.SpriteFrame = null; @property(cc.Sprite) transformationType: cc.Sprite = null; @property(cc.Sprite) transformationChange: cc.Sprite = null; canSelect: Boolean = true; public itemInfo: any; onLoad() { if (this.item_selected) { this.item_selected.active = false; } } loadInfo(info: any) { if (info.canSelect == !1) { this.canSelect = info.canSelect; if (info.lock == !0) { this.item_icon.spriteFrame = this.lockIcon; this.item_count.string = ""; this.item_bg.getComponent(cc.Sprite).spriteFrame = null; this.item_bg.getChildByName("frame").getComponent(cc.Sprite).spriteFrame = null; this.item_bg.active = true; } return } let data = ItemUtil.getItemData(info.itemid); if (data == null) { this.item_icon.spriteFrame = ItemUtil.getItemIcon("1000"); this.item_count.string = ""; return; } this.itemInfo = data; this.itemInfo.count = info.count; this.item_bg.active = true; if (this.item_count) { let text = SKDataUtil.transform(info.count); this.item_count.string = text; } this.item_icon.spriteFrame = ItemUtil.getItemIconBy(data); if (data.type == 15) { if (data.level == 1003) { // 橘色 var typeArr = ["9CC2C05E", "44D85091", "4988966A"]//強 抗 物 this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[data.attrType - 1]); if (TransformationUtil.Instance.getCardsInfo(data.id).cardstate == 0) this.transformationChange.spriteFrame = null else this.transformationChange.spriteFrame = ItemUtil.getItemIcon("743CB1F3") } else if (data.level == 1002) { // 紫色 var typeArr = ["A1519957", "7844A6C6", "A71F8CC7"]//強 抗 物 this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[data.attrType - 1]); this.transformationChange.spriteFrame = null } else if (data.level == 1001) { // 藍色 var typeArr = ["905A9C64", "56878EC7", "CD606498"]//強 抗 物 this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[data.attrType - 1]); if (TransformationUtil.Instance.getCardsInfo(data.id).cardstate == 0) this.transformationChange.spriteFrame = null else this.transformationChange.spriteFrame = ItemUtil.getItemIcon("4FF0E3B9") } else if (data.level == 1000) { // 綠色 var typeArr = ["ECAE61A5", "6A45551C", "71EA9A95"]//強 抗 物 this.transformationType.spriteFrame = ItemUtil.getItemIcon(typeArr[data.attrType - 1]); if (TransformationUtil.Instance.getCardsInfo(data.id).cardstate == 0) this.transformationChange.spriteFrame = null else this.transformationChange.spriteFrame = ItemUtil.getItemIcon("CE379C20") } else { return } this.transformationType.node.active = true; this.transformationChange.node.active = true; } } selected() { if (this.canSelect && this.item_selected) { this.item_selected.active = true; } if (this.itemInfo != null && this.item_detail != null) { let canvas = cc.find('Canvas'); if (canvas.getChildByName('BagItemDetail') == null) { let detail = cc.instantiate(this.item_detail); detail.parent = canvas; detail.name = 'BagItemDetail'; detail.getComponent('BagItemDetail').loadInfo(this.itemInfo); let bagLayer = cc.find('MainUI/BagPanel', canvas); if (bagLayer != null) { detail.getComponent('BagItemDetail').showOperation(); } } } }; unSelected() { if (this.item_selected) { this.item_selected.active = false; } }; hideCount() { if (this.item_count) { this.item_count.node.active = false; } }; getItemid(): number { if (this.itemInfo) { this.itemInfo.itemid; } return 0; }; setItemCount(count: number) { this.itemInfo.count = count; this.item_count.string = `${count}`; }; rmSelectedNode() { if (this.item_selected) { this.item_selected.destroy(); } }; getItemInfo() { return this.itemInfo } }