"use strict"; cc._RF.push(module, '400930QlzxGKIe/G/3hecD1', 'cmp.act.treasure'); // Scripts/mod/acts/treasure/cmp/cmp.act.treasure.js "use strict"; var BasePage = require("act.page.base"); var BackPackController = require("backpack_controller"); var TipsController = require("tips_controller"); var XSpine = require("nx.fx.spine"); var FID = require("bridge.function.ids"); /*** * * 探宝活动 */ cc.Class({ "extends": BasePage, properties: { nodReward: { "default": null, type: cc.Node }, nodPeriod: { "default": null, type: cc.Node, displayName: "轮次显示" }, nodMat: { "default": null, type: cc.Node, displayName: "材料显示" }, nodItem: { "default": null, type: cc.Node }, nodFocus: { "default": null, type: cc.Node }, nodChange: { "default": null, type: XSpine } }, // 初始化 build: function build(_data) { this._super(_data); var chd = this.nodReward.children; for (var i = 0; i < chd.length; i++) { var nod = chd[i]; var item = nx.gui.find(nod, "item"); var nodItem = cc.instantiate(this.nodItem); nodItem.parent = item; nx.gui.setActive(nod, "focus", false); } this.effect = nx.gui.getComponent(this.nodFocus, "", "nx.fx.spine"); this.mod.vbind(this, [["treasureInfo", this.freshTreasureInfo.bind(this)], ["treasurePeriodChange", this.freshTreasurePeriod.bind(this)]]); // this.mod.reqDailyFChargeData(); }, // 销毁 onDestroy: function onDestroy() { // 活动监听解除 if (this.mod) { this.mod.vunbind(this); } this._super(); }, onEnable: function onEnable() { this.mod.reqTreasureData(); // this.mod.freshTips(); }, freshTreasurePeriod: function freshTreasurePeriod(_data) { var _this = this; if (!_data || nx.dt.objEmpty(_data)) { return; } if (this.tween) { this.tween.stop(); } this.nodChange.load("resDB/effects/E80044/action", function (_e) { if (!_e) { _this.nodChange.action("action", false); } else { _this.nodChange.stop(); } }); var period = _data.period; var datac = nx.dt.objClone(this.mod.vget("treasureInfo")); datac.period = period; datac.reward_list = []; this.freshTreasureInfo(datac); }, freshTreasureInfo: function freshTreasureInfo(_data) { if (!_data || nx.dt.objEmpty(_data)) { return; } this.index = 0; //当前光环在哪个奖品上 this.nodFocus.position = this.nodReward.children[this.index].position; //初始化光环位置 this.delayTime = 0.3; //开始的时候延迟调用的时间(最小时间间隔) this.delayTime_max = 1.5; //最大时间间隔 this.addOrSub = false; //增加还是减少的bool值 this.loopCount = 0; //循环次数 this.circleCount = 2; //前面循环的圈数(效果圈,只为效果,和奖品无关) var setGray = function setGray(_nod, _mat) { var nod = _nod; var sp = nx.gui.getComponent(nod, "qa", cc.Sprite); var isp = nx.gui.getComponent(nod, "icon", cc.Sprite); var ssp = nx.gui.getComponent(nod, "star", cc.Sprite); var rt = nx.gui.getComponent(nod, "rt/img", cc.Sprite); var material = _mat == 1 ? cc.Material.getBuiltinMaterial('2d-gray-sprite') : cc.Material.getBuiltinMaterial('2d-sprite'); sp.setMaterial(0, material); isp.setMaterial(0, material); ssp.setMaterial(0, material); rt.setMaterial(0, material); }; var BC = BackPackController.getInstance(); var period = _data.period; this.period = period; var cfgs = gdata(this.data.config, "data_richanghuodong"); var cfg = cfgs[period]; var chd = this.nodReward.children; var mat = gdata(this.data.config, "data_constant").prize_item.val[0]; // this.have = BC.getModel().getItemNumByBid( mat ); this.have = _data.num; for (var i = 0; i < chd.length; i++) { var nod = chd[i]; var ifg = cfg[i + 1 + (period - 1) * 14]; var item = nx.gui.find(nod, "item"); var nodd = nx.gui.find(item, "award"); nx.gui.setActive(nod, "focus", false); setGray(nodd, 0); var cmp = nx.gui.getComponent(item, "award", "cmp.item.base"); if (cmp) { cmp.setData(ifg.items[0]); } } if (nx.dt.arrNEmpty(_data.reward_list)) { for (var _i = 0; _i < _data.reward_list.length; _i++) { var award = _data.reward_list[_i]; var _nod2 = nx.gui.find(chd[award.id - (period - 1) * 14 - 1]); nx.gui.setActive(_nod2, "focus", true); // nx.gui.setActive( nod, "focus", false ); if (_nod2) { var _item = nx.gui.find(_nod2, "item"); var _nodd = nx.gui.find(_item, "award"); setGray(_nodd, 1); } } } nx.tween.fadeOut(this.nodFocus, "", 0.01); nx.gui.setString(this.nodPeriod, "txt", nx.text.format("TreasurePeriod", period)); nx.gui.setString(this.nodMat, "count/txt", nx.dt.shortCount(_data.num)); var tip1 = nx.gui.getComponent(this, "panel/op/charge/tip", "nx.vb.visible"); if (tip1) { tip1.setTarget(nx.mTip, this.mod.getTipKey("rewarddd")); } // let time = Math.floor( Math.random() * this.nodReward.children.length ); // this.onDoing = false; // // this.onDoAni( time, 0 ); }, // 播放輪轉動畫 onDoAni: function onDoAni(_time, _result, _loop) { var _this2 = this; this.loopCount = _loop >= 0 ? _loop : this.loopCount; this.nodFocus.opacity = 156; this.unscheduleAllCallbacks(); this.effect.load("resDB/effects/E80043/action", function (_e) { if (!_e) { _this2.effect.action("action2", true); } else { _this2.effect.stop(); } }); this.scheduleOnce(function () { _this2.index++; //循环到最后一个值之后从0开始 if (_this2.index >= _this2.nodReward.children.length) { _this2.index = 0; } if (_result > 0) { _this2.delayTime = 0.05; _this2.onDoing = true; } //当前运行次数++ if (_this2.loopCount >= _this2.nodReward.children.length * _this2.circleCount && _result > 0) { //加速度,为最大时间间隔/空转之外需要运行的间隔(空转之外需要运行的间隔是一圈+抽奖的结果) _this2.delayTime = 0.2; } _this2.loopCount++; //总的运行次数 = 空转三圈 + 一圈缓冲 + 抽奖结果 _this2.count = _this2.nodReward.children.length * (_this2.circleCount + 1) + _time; //判断是不是运行完了 // console.log( this.loopCount + "當前的總數" + this.count + "ssss" + _result ); if (_this2.loopCount >= _this2.count && _result > 0) { //隐藏遮罩 _this2.nodFocus.position = _this2.nodReward.children[_result - 1].position; _this2.effect.load("resDB/effects/E80043/action", function (_e) { if (!_e) { _this2.effect.action("action", true); nx.audio.playSFX("audios/effects/praycell"); } else { _this2.effect.stop(); } }); _this2.tween = cc.tween(_this2.nodFocus).delay(1.5).call(function () { _this2.mod.reqGetTreasure(1); // this.mod.freshTips(); _this2.onDoing = false; }).start(); return; } else { //切换光环位置 _this2.nodFocus.position = _this2.nodReward.children[_this2.index].position; //重新调用本方法(因为schedule不能动态修改运行间隔时间) nx.audio.playSFX("audios/effects/praycell"); _this2.onDoAni(_time, _result, _this2.loopCount); } }, this.delayTime, 0); //执行次数为0,实际执行次数为1 }, onTouchTreasure: function onTouchTreasure() { var _this3 = this; if (this.have == 0) { var tip = nx.text.getKey("SummonTimesNotEnough") + "," + nx.text.getKey("GotoCharge"); nx.mbox(tip, ["Cancle", "GotoCharge"], function (_key, _box) { _box.close(); if (_key == 'GotoCharge') { nx.bridge.createPanel("WndPayment", { key: "recharge" }); } }); return; } // 正在播動畫 if (this.onDoing) { nx.tbox("TreasureDoing"); return; } this.mod.reqGetTreasure(0, function (_ret, _data) { if (!_ret) { nx.tbox(_data); return; } // 本地道具-1 nx.gui.setString(_this3.nodMat, "count/txt", nx.dt.shortCount(_this3.have - 1)); // 过程模拟 var num = -_this3.nodReward.children.length; nx.tween.fadeIn(_this3.nodFocus, "", 0.1); _this3.onDoAni(num / 3, _data.reward_id - (_this3.period - 1) * 14, 0); }); }, onTouchHelp: function onTouchHelp() { var TC = TipsController.getInstance(); if (TC) { var txt = gdata(this.data.config, "data_rule")[1]; TC.showTextPanel(txt.name, nx.text.getKey(txt.content)); } } }); cc._RF.pop();