"use strict"; cc._RF.push(module, 'aebe4BXlvJLtrVpqBBjzQxg', 'cmp.item.base'); // Scripts/mod/backpack/cmps/cmp.item.base.js "use strict"; var SVCItem = require("nx.fx.sv.expand.item"); var BackPackConst = require("backpack_const"); var TipsController = require("tips_controller"); var NXSpine = require("nx.fx.spine"); var _require = require("bridge.utils.item"), data2Icon = _require.data2Icon; var BIST = BackPackConst.item_sub_type; cc.Class({ "extends": SVCItem, properties: { nodBG: { "default": null, type: cc.Sprite, displayName: "品质" }, nodIcon: { "default": null, type: cc.Node, displayName: "图标" }, nodCount: { "default": null, type: cc.Label, displayName: "数量" }, ignoreOne: { "default": true, displayName: "忽略单个" }, shortCount: { "default": false, displayName: "数量简化显示" }, lenName: { "default": 0, displayName: "名字长度(字节)" }, nodName: { "default": null, type: cc.Label, displayName: "名字" }, nodType: { "default": null, type: cc.Label, displayName: "类型" }, nodDesc: { "default": null, type: cc.RichText, displayName: "描述" }, nodStar: { "default": null, type: cc.Node, displayName: "星级" }, imgLT: { "default": null, type: cc.Sprite, displayName: "左上角标" }, imgRT: { "default": null, type: cc.Sprite, displayName: "右上角标" }, nodFocus: { "default": null, type: cc.Sprite, displayName: "聚焦框" }, spRare: { "default": null, type: NXSpine }, tipSelf: { "default": true, displayName: "点击提示" }, mutexStarCount: { "default": true, displayName: "星量互斥" } }, // 显示 onEnable: function onEnable() { this.openTip(this.tipSelf); }, // 数据重置 rebind: function rebind(_idx, _data, _key) { this._super(_idx, _data, _key); // 刷新 this.setData(_data); }, // 聚焦获得 onFocus: function onFocus() { if (this.nodFocus && nx.dt.objNEmpty(this.info)) { this.nodFocus.node.active = true; } }, // 聚焦失去 outFocus: function outFocus() { if (this.nodFocus) { this.nodFocus.node.active = false; } }, // 置空 setEmpty: function setEmpty() { this.outFocus(); this.setQuality(-1); this.setIcon(0); this.setName(""); this.setDescribe(""); this.setStars(0); this.freshLT(); this.freshRT(); this.setRareEft(0); nx.gui.setString(this.nodCount, "", ""); }, // 重置 setData: function setData(_data, _count) { this.mdata = _data; // 统一道具信息格式 this.info = _data ? data2Icon(_data) : null; if (!this.info) { this.mdata = {}; this.setEmpty(); return; } // 数量 if (nx.dt.numGood(_count)) { this.info.count = _count; } // 刷新 this.freshAll(); }, // 重置(不定参覆盖) setDataEx: function setDataEx(_data, _params) { this.mdata = _data; // 统一道具信息格式 this.info = data2Icon(_data); if (!this.info) { this.mdata = {}; this.setEmpty(); return; } // 不定参覆盖 if (nx.dt.objNEmpty(_params)) { Object.assign(this.info, _params); } // 刷新 this.freshAll(); }, //----------结构 // {bid:xxxx,num:xxxx,config:object} // 刷新 freshAll: function freshAll() { // 置空 if (nx.dt.objEmpty(this.info)) { this.setEmpty(); return; } // 基本信息 this.setQuality(this.info.quality); this.setIcon(this.info.icon); this.setName(this.info.name); this.setDescribe(this.info.desc); this.setRareEft(this.info.mark); // 星级/数量是否互斥 if (!this.mutexStarCount) { this.setCount(this.info.count); this.setStars(this.info.stars || this.info.eqm_jie); } else { if (this.ignoreOne && this.info.count <= 1) { this.setCount(0); this.setStars(this.info.stars || this.info.eqm_jie); } else { this.setCount(this.info.count); this.setStars(0); } } // 角标 this.freshLT(); this.freshRT(); }, setRareEft: function setRareEft(_play) { var _this = this; if (!this.spRare) return; if (_play == 0) { this.spRare.stop(); } else if (_play == 1) { var res_path = PathTool.getSpinePath("E80048", null, false); this.spRare.load(res_path, function (_e) { if (!_e) { _this.spRare.action("action", true); } else { _this.spRare.stop(); } }); } }, // 单设:品质 setQuality: function setQuality(_qa) { if (this.nodBG) { var qa = null; if (nx.dt.numPositive(_qa)) { var _show = _qa < BackPackConst.quality.golden ? _qa : BackPackConst.quality.red; qa = cc.path.join("coms/images", "bg_qa" + _show); } nx.gui.setSpriteFrame(this.nodBG, "", qa); if (!qa) { nx.gui.getComponent(this.nodBG, "", cc.Sprite).curKey = ""; } } if (this.nodName) { var color = BackPackConst.quality_color(_qa); var cur = this.nodName.node.color; cur.fromHEX(color); this.nodName.node.color = cur; } }, // 单设:图标 setIcon: function setIcon(_icon) { if (!this.nodIcon) { return; } // 置空 var icon = _icon + ""; if (nx.dt.strEmpty(icon) || icon == "0") { nx.gui.setActive(this.nodIcon, "", false); return; } nx.gui.setActive(this.nodIcon, "", true); // 图标设置 nx.bridge.setIcon(this.nodIcon, "", _icon); }, // 单设:数量 setCount: function setCount(_count) { if (!this.nodCount) { return; } var count = parseInt(_count) || 0; if (this.ignoreOne && count <= 1) { this.nodCount.string = ""; return; } if (this.shortCount) { count = nx.dt.shortCount(count); } this.nodCount.string = "" + count; }, // 单设:名字 setName: function setName(_name) { if (!this.nodName) { return; } var txt = nx.text.getKey(_name); if (this.lenName > 0) { txt = nx.dt.strCut(txt, this.lenName); } this.nodName.string = txt; }, // 单设:描述 setDescribe: function setDescribe(_desc) { if (!this.nodDesc) { return; } this.nodDesc.string = nx.text.getKey(_desc); }, // 单设:星级 setStars: function setStars(_stars) { if (!this.nodStar) { return; } if (!nx.dt.numPositive(_stars, false)) { nx.gui.setSpriteFrame(this.nodStar, "", null); return; } var path = cc.path.join("coms/images", "star" + _stars); nx.gui.setSpriteFrame(this.nodStar, "", path); }, // 设置阵营 setCamp: function setCamp(_camp) { if (!this.imgLT) { return; } var sf = cc.path.join("coms/images/camps" + _camp); nx.gui.setSpriteFrame(this.imgLT, "", sf); }, // 左上角标更新 freshLT: function freshLT() { if (!this.imgLT) { return; } var sf = null; // 区别处理 if (nx.dt.objNEmpty(this.info)) { // 伙伴阵营 if (nx.dt.numPositive(this.info.camp_type, false)) { this.setCamp(this.info.camp_type); return; } // 神装类型 if (!sf && BackPackConst.checkIsHolyEquipment(this.info.type)) { if (nx.dt.numPositive(this.info.eqm_set, false)) { var lv = Math.floor(this.info.eqm_set / 100); sf = cc.path.join("coms/images/eqm_set" + lv); } } // 精灵等级 if (!sf && this.info.type == BackPackConst.item_type.ELFIN) { var sfg = gdata("sprite_data", "data_elfin_data", this.info.item_id); if (sfg.skill) { var data = gskilldata('data_get_skill', sfg.skill); sf = cc.path.join("coms/images/ico_lv" + data.level); } } } nx.gui.setSpriteFrame(this.imgLT, "", sf); }, // 右上角标更新 freshRT: function freshRT() { if (!this.imgRT) { return; } // 区别处理 var sf = null; var ssf = ""; if (nx.dt.objNEmpty(this.info)) { // 碎片展示 if (!sf && this.info.type == BackPackConst.item_type.PARTNER_DEBRIS) { sf = cc.path.join("coms/images", "ico_frag"); } ; // 神装评价 if (!sf && BackPackConst.checkIsHolyEquipment(this.info.type)) { if (this.info.eqm_jie >= 0) { var eq = this.info.eqm_jie >= BackPackConst.quality.purple ? BackPackConst.quality.purple : this.info.eqm_jie; sf = cc.path.join("coms/images/eqm_jie" + (eq + 1)); } } if (this.info.type == BackPackConst.item_type.ProductsGift) { ssf = this.info.desc_client; } ; //雇佣兵 // if ( !sf && (this.mdata.is_employ || (this.mdata.is_flag == 1)) ) { // sf = cc.path.join( "coms/images/assist" ); // } } nx.gui.setString(this.imgRT.node.parent, "time/txt", ssf); nx.gui.setSpriteFrame(this.imgRT, "", sf); nx.gui.setActive(this.imgRT.node.parent, "time", nx.dt.strNEmpty(ssf)); }, // 开启详情跳转 openTip: function openTip(_open) { this.tipSelf = !!_open; var btn = nx.gui.getComponent(this, "bg", "nx.fx.button"); if (btn) { btn.lock(!this.tipSelf); } }, // 点击 onTouchTip: function onTouchTip() { var TC = TipsController.getInstance(); if (TC && this.info) { TC.showItemTips(this.info); } } }); cc._RF.pop();