"use strict"; cc._RF.push(module, '15a05aTiNlBi6ijzweNawka', 'cmp.act.blind.box'); // Scripts/mod/acts/blindBox/cmp/cmp.act.blind.box.js "use strict"; /****************************************************************** * * 开盲盒 * ******************************************************************/ var ActPage = require("act.page.base"); var NxSpine = require("nx.fx.spine"); var ItemLayout = require("cmp.item.layout"); var TipsController = require("tips_controller"); var BridgeItemBinder = require("bridge.binder.item.icon.count"); var BKC = require("backpack_controller"); cc.Class({ "extends": ActPage, properties: { nodBG: { "default": null, type: cc.Node }, spRole: { "default": null, type: NxSpine }, spMini: { "default": null, type: NxSpine }, spBox: { "default": null, type: NxSpine }, nodGifts: { "default": null, type: cc.Node }, nodAd: { "default": null, type: cc.Node }, nodGround: { "default": null, type: cc.Node }, nodDate: { "default": null, type: cc.Node }, nodOps: { "default": null, type: cc.Node }, nodCombine: { "default": null, type: cc.Node }, nodBars: { "default": null, type: cc.Node }, nodCoin: { "default": null, type: BridgeItemBinder }, nodFrags: { "default": null, type: BridgeItemBinder }, nodRewards: { "default": null, type: ItemLayout } }, // 初始化 build: function build(_data) { this._super(_data); // 依赖缺失 if (!this.mod || nx.dt.objEmpty(this.data)) { return; } // 基本信息 this.configs = this.mod.queryConfigs(this.data.camp_id); this.freshBasic(); }, // 显示 onEnable: function onEnable() { // 操作锁定 nx.gui.setActive(this.nodOps, "on", true); nx.gui.setActive(this.nodOps, "off", false); // 盲盒动画 this.spBox.action("action", true); this.mod.freshTips(); // 刷新活动日期 this.freshDate(); }, // 关闭 onDisable: function onDisable() { if (this.voiceHandle) { nx.audio.stopSFX(this.voiceHandle); this.voiceHandle = null; } }, // ------------------------------------------------------------ // 基础相关 // ------------------------------------------------------------ // 基本信息 freshBasic: function freshBasic() { var _this = this; // 置空 if (!this.configs) { nx.gui.setActive(this, "right", false); return; } nx.gui.setActive(this, "right", true); // 背景 var path = cc.path.join("prefab/acts/blindBox/themes", this.configs.theme, "bg"); nx.gui.setSpriteFrame(this.nodBG, "", path); // 展台 path = cc.path.join("prefab/acts/blindBox/themes", this.configs.theme, "ground"); nx.gui.setSpriteFrame(this.nodGround, "", path); // Mini台 path = cc.path.join("prefab/acts/blindBox/themes", this.configs.theme, "tai"); nx.gui.setSpriteFrame(this.spMini, "tai", path); // 广告图 var key = this.configs.partner_id + "_" + this.configs.skin_id; path = cc.path.join("locals/{lang}/images/blindbox", key, "ad"); nx.gui.setSpriteFrame(this.nodAd, "", nx.res.fmtPath(path)); // 皮肤展示 this.partnerRes = ""; var SKIN = game.configs.partner_skin_data.data_skin_info[this.configs.skin_id]; if (SKIN) { var bsp = PathTool.getSpinePath(SKIN.res_id, "show", false); this.spRole.play(bsp, this.configs.drama, null, true); var msp = PathTool.getSpinePath(SKIN.res_id, SKIN.res_id, false); this.spMini.play(msp, "stand2", null, true); this.partnerRes = SKIN.res_id; } // 奖励面板 path = cc.path.join("locals/{lang}/images/blindbox", key, "panel"); nx.gui.setSpriteFrame(this.nodGifts, "", nx.res.fmtPath(path)); // 大奖展示 var snode = nx.gui.find(this.nodGifts, "sp"); if (snode) { var rewards = this.configs.big_reward; for (var i = 0; i < snode.children.length; ++i) { var cmp = nx.gui.getComponent(snode.children[i], "", "cmp.item.base"); if (cmp) cmp.setData(rewards[i][0], rewards[i][1]); } } // 小奖展示 var mnode = nx.gui.find(this.nodGifts, "items"); if (mnode) { var _rewards = this.configs.good_gift; for (var _i = 0; _i < mnode.children.length; ++_i) { var _cmp = nx.gui.getComponent(mnode.children[_i], "", "cmp.item.base"); if (_cmp) { _cmp.setData(_rewards[_i][0], _rewards[_i][1]); if (_rewards[_i][1] == "?") { nx.gui.setString(_cmp, "count", "?"); } } } } // 必出奖励 this.nodRewards.rebuild(this.configs.must_reward); // 跳过动画 this.setSkipAnim(false); // 盲盒动画 path = cc.path.join("locals/{lang}/images/blindbox", key, "box/action"); this.spBox.play(path, "action", null, true); // 道具绑定 this.nodCoin.setID(this.configs.item_id); // 碎片绑定 var frags = this.configs.skin_debris_id; nx.gui.setString(this.nodFrags, "total", frags[1]); this.nodFrags.setID(frags[0], function () { _this.freshCombine(); }); // 红点绑定 var tip1 = nx.gui.getComponent(this.nodOps, "on/once/tip", "nx.vb.visible"); if (tip1) { tip1.setTarget(nx.mTip, this.mod.getTipKey("once")); } var tip2 = nx.gui.getComponent(this.nodOps, "on/ten/tip", "nx.vb.visible"); if (tip2) { tip2.setTarget(nx.mTip, this.mod.getTipKey("ten")); } // 操作刷新 this.freshOps(); }, // 刷新活动日期 freshDate: function freshDate() { var time = nx.bridge.time.toNeedTime(this.data.end_time); nx.gui.setString(this.nodDate, "txt", time); }, // ------------------------------------------------------------ // 抽奖相关 // ------------------------------------------------------------ // 操作刷新 freshOps: function freshOps() { // 按钮设置 var autoOp = function autoOp(_node, _draw) { var tinfo = gitemdata(_draw[0]); if (!tinfo) { nx.error("$BlindBox:\u9053\u5177\u65E0\u6548! " + _draw[0]); return; } nx.bridge.setIcon(_node, "btn/list/icon", tinfo.icon); nx.gui.setString(_node, "btn/list/num", _draw[1]); }; // 操作刷新 autoOp(nx.gui.find(this.nodOps, "on/once"), this.configs.loss_item_once[0]); autoOp(nx.gui.find(this.nodOps, "off/once"), this.configs.loss_item_once[0]); autoOp(nx.gui.find(this.nodOps, "on/ten"), this.configs.loss_item_ten[0]); autoOp(nx.gui.find(this.nodOps, "off/ten"), this.configs.loss_item_ten[0]); }, // 抽奖 doRaffle: function doRaffle(_once) { var _this2 = this; // 操作锁定 nx.gui.setActive(this.nodOps, "on", false); nx.gui.setActive(this.nodOps, "off", true); // 抽取 var self = this; var raffle = function raffle() { self.mod.reqRaffle(_once, function (_ret, _data, _code) { nx.gui.setActive(self.nodOps, "on", true); nx.gui.setActive(self.nodOps, "off", false); // 道具不足 if (!_ret && _code == 101) { self.onTouchCoin(); } }); }; // 跳过动画 if (this.skipAnim) { return raffle(); } // 动画播放 var anim = function anim(_key) { self.spBox.action(_key || "action2", false, function (_event) { if (_event == "reward") { raffle(); return; } if (_event == "complete") { self.spBox.action("action", null, true); return; } }); // 開啟音效 var path = cc.path.join("prefab/acts/blindBox/audios", "open"); nx.audio.playSFX(path, false); }; // 执行长流程 this.mod.reqPreRaffle(_once, function (_ret, _data, _code) { // 失败 if (!_ret) { nx.gui.setActive(self.nodOps, "on", true); nx.gui.setActive(self.nodOps, "off", false); // 道具不足 if (_code == 101) { _this2.onTouchCoin(); } return; } // 盲盒动画 anim(_data.is_notice == 0 ? "action2" : "action3"); }); }, // 点击招募 onTouchOnce: function onTouchOnce() { this.doRaffle(true); }, // 点击招募 onTouchTen: function onTouchTen() { this.doRaffle(false); }, // ------------------------------------------------------------ // 合成相关 // ------------------------------------------------------------ // 合成刷新 freshCombine: function freshCombine() {}, // 点击合成 onTouchCombine: function onTouchCombine() { var frags = this.configs.skin_debris_id; BKC.getInstance().reqSkinCombine(frags[0], function (_ret, _data) {}); }, // ------------------------------------------------------------ // 动画相关 // ------------------------------------------------------------ // 动画切换 setSkipAnim: function setSkipAnim(_skip) { this.skipAnim = !!_skip; nx.gui.setActive(this.nodBars, "skip/ck/on", this.skipAnim); nx.gui.setActive(this.nodBars, "skip/ck/off", !this.skipAnim); }, // 动画切换 onTouchSkip: function onTouchSkip() { this.setSkipAnim(!this.skipAnim); }, // 点击动画 onTouchSpine: function onTouchSpine() { var _this3 = this; if (nx.dt.strEmpty(this.partnerRes)) { return; } if (this.voiceHandle) { nx.audio.stopSFX(this.voiceHandle); this.voiceHandle = null; } var path = cc.path.join("resDB/models", this.partnerRes, this.configs.voice); nx.audio.playVoice(path, function (_err, _id) { if (!_err) { _this3.voiceHandle = _id; } }); }, // ------------------------------------------------------------ // 其他 // ------------------------------------------------------------ // 点击道具 onTouchCoin: function onTouchCoin() { if (this.actRoot && this.configs) { this.actRoot.jumpToMenu(this.configs.shop_source_id); } }, // 点击规则 onTouchRule: function onTouchRule() { var rule = this.mod ? this.mod.queryRule() : ""; if (nx.dt.strNEmpty(rule)) { var TC = TipsController.getInstance(); TC.showTextPanel("tip", rule); } } }); cc._RF.pop();