"use strict"; cc._RF.push(module, '44ce3HoFO5HFqLJ405Yy+Dd', 'cmp.act.starskypray.wnd'); // Scripts/mod/acts/starskyprayer/cmp/cmp.act.starskypray.wnd.js "use strict"; var BridgeWindow = require("bridge.window"); var NxSpine = require("nx.fx.spine"); var Mod = require("act.starskyprayer.mod"); var ItemBase = require("cmp.item.base"); var themeMod = require("acts.mod"); var BackPackController = require("backpack_controller"); var FID = require("bridge.function.ids"); var TipsController = require("tips_controller"); var ActPopup = require("act.popup.base"); var NormalLen = 56; var TotalLen = 156; cc.Class({ "extends": ActPopup, properties: { spRole: { "default": null, type: NxSpine }, nodRewards: { "default": null, type: cc.Node }, nodShows: { "default": null, type: cc.Node }, nodRewardsR: { "default": null, type: cc.Node }, nodRight: { "default": null, type: cc.Node }, nodShop: { "default": null, type: NxSpine }, nodTimes: { "default": null, type: cc.Node }, nodEndTimes: { "default": null, type: cc.Node }, nodJump: { "default": null, type: cc.Toggle } // E90901 }, // 初始化 onOpenConfigs: function onOpenConfigs(_params) { var _this = this; this._super(_params); this.mod = Mod.getInstance(); // 无效 if (!this.mod) { this.delayClose(); return; } this.spRole.load("resDB/models/H30102/H30102", function (_e) { if (!_e) { _this.spRole.action("stand2", true); } else { _this.spRole.stop(); } }); this.nodShop.load("resDB/effects/E90901/action", function (_e) { if (!_e) { _this.nodShop.action("action", true); } else { _this.nodShop.stop(); } }); var rewards = gdata(this.mod.data.config, "data_reach_reward"); this.periods_num = gdata(this.mod.data.config, "data_const").periods_num; this.diamond_times = gdata(this.mod.data.config, "data_const").diamond_times.val; this.cfg = gdata(this.mod.data.config, "data_base_info")[this.periods_num.val]; var reachs = []; for (var i in rewards) { var reward = rewards[i]; reachs.push(reward); } this.reaches = reachs; var time = new Date(); var showtime = this.mod.data.end_time - time / 1000; nx.gui.setCdTxt(this.nodEndTimes, "left/time", showtime); this.showRewards = reachs; var chd = this.nodRewards.children; for (var r = 0; r < reachs.length; r++) { var reach = reachs[r]; var nod = chd[r]; var cmp = nx.gui.getComponent(nod, "box", "cmp.common.itemlayout"); if (cmp) { cmp.rebuild(reach.reward); } nx.gui.find(nod, "can/get").zIndex = reach.id; nx.gui.setString(nod, "point", reach.num); nx.gui.setActive(nod, "boxopen", false); } this.onShowRewards(); // 活动监听 this.mod.vbind(this, [["starPrayData", this.freshInfo.bind(this)]]); nx.gui.hideAllChildren(this.nodShows, "", false); // this.setProg(); this.mod.reqBaseData(); }, onEnable: function onEnable() {}, // 销毁 onDestroy: function onDestroy() { // 活动监听解除 if (this.mod) { this.mod.vunbind(this); } delete this.mod; this._super(); }, /** {"free_end_time":0,"draw_times":0,"gold_times":20,"luck_num":0,"ids":[],"log_info":[]}*/ freshInfo: function freshInfo(_data) { if (_data) { var luck_num = _data.luck_num; var free_time = _data.free_end_time; var left = this.diamond_times - _data.gold_times; this.leftDia = left; // this.records = _data.log_info; nx.gui.setString(this.nodTimes, "txt", _data.draw_times); nx.gui.setString(this.nodEndTimes, "times/num", left); nx.gui.setString(this.nodEndTimes, "times/all", this.diamond_times); this.nodJump.isChecked = _data.is_skip == 1; this.skip = _data.is_skip == 1; this.setProg(luck_num); var time = new Date(); var showtime = free_time - time / 1000; var nodd = nx.gui.find(this.nodRight, "ops/once/time"); nx.gui.setCdTxt(nodd, "ttime", showtime); this.dealOp(free_time); this.dealReachRewards(_data.ids); this.index = -1; //当前光环在哪个奖品上 // 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; //前面循环的圈数(效果圈,只为效果,和奖品无关) } }, onShowRewards: function onShowRewards() { var rewards = gdata(this.mod.data.config, "data_reward_info")[this.periods_num.val]; var chd = this.nodRewardsR.children; for (var i in rewards) { var reward = rewards[i]; var id = reward.point; var nod = chd[id - 1]; // { bid, num } var shows = { bid: reward.item_id, num: reward.num, info: reward.id }; var cmp = nx.gui.getComponent(nod, "item", ItemBase); if (cmp) { cmp.setData(shows); } var level = 0; switch (reward.level_name) { case "A": { level = 2; } ; break; case "B": { level = 3; } ; break; case "S": { level = 4; } ; break; } var ico = "prefab/acts/starskyprayer/ui/starskyprayer_0" + level; nx.gui.setSpriteFrame(nod, "icor", ico); nx.gui.setActive(nod, "focus", false); } }, setProg: function setProg(_num) { // 右上角 幸運值 相關顯示 var nod = nx.gui.find(this.nodRight, "luck/mask"); if (nod) { nod.height = NormalLen + parseInt((TotalLen - NormalLen) * _num * 0.012); } var lucknod = nx.gui.find(this.nodRight, "luck/score/txt"); nx.gui.setString(lucknod, "", _num); }, dealReachRewards: function dealReachRewards(_reds) { // ids":[{"id":7,"status":0},{"id":6,"status":0},{"id":5,"status":0},{"id":4,"status":0},{"id":3,"status":0},{"id":2,"status":0},{"id":1,"status":2}] var ids = _reds; var chd = this.nodRewards.children; for (var i = 0; i < ids.length; i++) { var dataa = ids[i]; var nod = chd[dataa.id - 1]; nx.gui.setActive(nod, "can", dataa.status == 1); nx.gui.setActive(nod, "boxopen", dataa.status == 2); // nx.gui.setActive( nod, "box", dataa.status == 1 || dataa.status == 0 ); nx.gui.setActive(nod, "box", true); } }, // 處理 操作以及材料顯示 dealOp: function dealOp(_time) { if (!this.cfg) { return; } this.useFree = false; this.useItemF = false; this.useItemT = false; this.useDiaT = false; this.useDiaF = false; var free = _time == 0; var mat = this.cfg.loss_item_once[0][0]; var other = this.cfg.loss_goal_once[0][0]; var needmatf = this.cfg.loss_item_once[0][1]; var needmatt = this.cfg.loss_item_ten[0][1]; var needmatdf = this.cfg.loss_goal_once[0][1]; var needmatdt = this.cfg.loss_goal_ten[0][1]; var model = BackPackController.getInstance().getModel(); var have = model.getItemNumByBid(mat); this.havemat = have; this.needMatT = needmatt; this.needMatF = needmatf; this.name = gitemdata(mat); var haveDia = model.getItemNumByBid(other); this.haveDia = haveDia; this.needMatDT = needmatdt; this.needMatDF = needmatdf; nx.gui.setString(this.nodRight, "have/num", have); nx.bridge.setIconS(this.nodRight, "have/icon", mat); var once = nx.gui.find(this.nodRight, "ops/once"); var ten = nx.gui.find(this.nodRight, "ops/ten"); nx.gui.setActive(once, "free", free); nx.gui.setActive(once, "mat", !free); nx.gui.setActive(once, "time", !free); this.useFree = free; var self = this; var dealUseDia = function dealUseDia() { if (haveDia >= needmatdt) { if (self.useItemT) { self.useDiaT = false; self.useItemF = true; self.useDiaF = false; } else { if (self.useItemF) { self.useDiaF = false; self.useDiaT = true; } else { self.useDiaF = true; self.useDiaT = true; } } } else { if (haveDia >= needmatdf) { if (self.useItemF) { self.useDiaF = false; self.useDiaT = false; } else { self.useDiaF = true; self.useDiaT = false; } } else { self.useDiaF = false; self.useDiaT = false; } } }; // 当拥有的材料数量不小于10个时 if (have >= needmatt) { nx.bridge.setIconS(once, "mat/icon", mat); nx.bridge.setIconS(ten, "mat/icon", mat); nx.gui.setString(once, "mat/neednum", "X" + needmatf); nx.gui.setString(ten, "mat/neednum", "X" + needmatt); this.useItemF = true; this.useItemT = true; this.useDiaF = false; this.useDiaT = false; // dealUseDia(); } else { // 当材料可以 1抽 if (have >= needmatf) { nx.bridge.setIconS(once, "mat/icon", mat); nx.bridge.setIconS(ten, "mat/icon", this.leftDia == this.diamond_times ? mat : other); nx.gui.setString(once, "mat/neednum", "X" + needmatf); nx.gui.setString(ten, "mat/neednum", "X" + (this.leftDia == this.diamond_times ? needmatt : needmatdt)); this.useItemF = true; this.useItemT = false; dealUseDia(); this.useDiaF = false; } else { if (this.leftDia == this.diamond_times) { nx.bridge.setIconS(once, "mat/icon", mat); nx.bridge.setIconS(ten, "mat/icon", mat); nx.gui.setString(once, "mat/neednum", "X" + needmatf); nx.gui.setString(ten, "mat/neednum", "X" + needmatt); } else { nx.bridge.setIconS(once, "mat/icon", other); nx.bridge.setIconS(ten, "mat/icon", other); nx.gui.setString(once, "mat/neednum", "X" + needmatdf); nx.gui.setString(ten, "mat/neednum", "X" + needmatdt); } dealUseDia(); } } }, // 顯示 達成獎勵相關 onTouchShow: function onTouchShow(_idx) { var id = parseInt(_idx); for (var i = 0; i < this.nodShows.children.length; i++) { var nod = this.nodShows.children[i]; if (i != id - 1) { nx.gui.setActive(nod, "", false); } } // nx.gui.hideAllChildren( this.nodShows, "", false ); var snod = this.nodShows.children[id - 1]; var cmp = nx.gui.getComponent(snod, "bg/award", "cmp.common.itemlayout"); var rewards = this.showRewards[id - 1]; if (cmp) { cmp.rebuild(rewards.reward); } var show = snod.active; nx.gui.setActive(snod, "", !show); }, // 打開 記錄 onTouchRecord: function onTouchRecord() { this.mod.reqStarPrayRecord(function (_ret, _data) { if (!_ret) { return; } nx.bridge.createPanel("WndActStarSkyPrayRecords", _data); }); }, // onTouchShop: function onTouchShop() { var shopInfo = gdata(this.mod.data.config, "data_shop_info"); nx.bridge.createPanel("WndActStarSkyPrayShop", shopInfo); }, // 播放輪轉動畫 onDoAni: function onDoAni(_time, _result, _loop, _usetype) { var _this2 = this; var result = _result[0]; if (this.tween) { this.tween.stop(); } this.loopCount = _loop >= 0 ? _loop : this.loopCount; this.usetype = _usetype; // this.nodFocus.opacity = 156; var num = 0; for (var i = 0; i < this.nodRewardsR.children.length; i++) { var nod = this.nodRewardsR.children[i]; var cmp = nx.gui.getComponent(nod, "item", ItemBase); if (cmp) { if (cmp.mdata.info == result.id) { // nx.gui.setActive( nod, "focus", true ); num = i; } } } var all = num + 3 * this.nodRewardsR.children.length; this.unscheduleAllCallbacks(); var self = this; this.scheduleOnce(function () { _this2.index++; //循环到最后一个值之后从0开始 if (_this2.index >= _this2.nodRewardsR.children.length) { _this2.index = 0; } if (_this2.loopCount > 0) { _this2.delayTime = 0.05; _this2.onDoing = true; } //当前运行次数++ if (_this2.loopCount >= _this2.nodRewardsR.children.length * _this2.circleCount && _result > 0) { //加速度,为最大时间间隔/空转之外需要运行的间隔(空转之外需要运行的间隔是一圈+抽奖的结果) _this2.delayTime = 0.20; } _this2.loopCount++; if (_this2.loopCount > all) { _this2.loopCount = all; } //总的运行次数 = 空转三圈 + 一圈缓冲 + 抽奖结果 _this2.count = _this2.nodRewardsR.children.length * (_this2.circleCount + 1) + _time; //判断是不是运行完了 if (_this2.loopCount >= all && result.id > 0) { for (var _i = 0; _i < _this2.nodRewardsR.children.length; _i++) { var _nod = _this2.nodRewardsR.children[_i]; var _cmp = nx.gui.getComponent(_nod, "item", ItemBase); if (_cmp) { if (_cmp.mdata.info == result.id) { nx.gui.setActive(_nod, "focus", true); _nod = _nod; } else { nx.gui.setActive(_nod, "focus", false); } } // nx.gui.setActive( nod, "focus", false ); } //隐藏遮罩 _this2.tween = cc.tween(_this2.node) // .delay( 0.3 ) // .call( ()=>{ // } ) .delay(0.5).call(function () { var nowresult = _result.shift(); if (!nowresult || nx.dt.arrEmpty(_result)) { var dataa = { group_id: self.periods_num.val, type: self.usetype, id: 0 }; self.mod.reqGetStarPrayRewardData(dataa); self.onDoing = false; for (var _i2 = 0; _i2 < _this2.nodRewardsR.children.length; _i2++) { var _nod2 = _this2.nodRewardsR.children[_i2]; var _cmp2 = nx.gui.getComponent(_nod2, "item", ItemBase); if (_cmp2) { nx.gui.setActive(_nod2, "focus", false); } } return; } for (var _i3 = 0; _i3 < _this2.nodRewardsR.children.length; _i3++) { var _nod3 = _this2.nodRewardsR.children[_i3]; var _cmp3 = nx.gui.getComponent(_nod3, "item", ItemBase); if (_cmp3) { nx.gui.setActive(_nod3, "focus", false); } } _this2.onDoAni(_time, _result, 0, self.usetype); _this2.onDoing = false; }).start(); return; } else { //切换光环位置 for (var _i4 = 0; _i4 < _this2.nodRewardsR.children.length; _i4++) { var _nod4 = _this2.nodRewardsR.children[_i4]; nx.gui.setActive(_nod4, "focus", false); } nx.gui.setActive(_this2.nodRewardsR.children[_this2.index], "focus", true); //重新调用本方法(因为schedule不能动态修改运行间隔时间) _this2.onDoAni(_time, _result, _this2.loopCount, self.usetype); } }, this.delayTime, 0); //执行次数为0,实际执行次数为1 }, onTouchPray: function onTouchPray(_idx) { var _this3 = this; var self = this; var times = parseInt(_idx); // if( this.havemat > ) // if( this.useFree ) if (times == 1) { if (!this.useFree) { if (this.havemat < this.needMatF) { if (this.haveDia >= this.needMatDF) { if (this.leftDia + times > this.diamond_times) { var name = this.name ? this.name.name : ""; var _str = nx.text.format("ActStarPrayBuyTip", name); nx.mbox(_str, ['cancel', 'Buy'], function (_key, _box) { _box.close(); if (_key == "Buy") { // this.reqSummon( _args.type, _times, _args ); // self.close(); nx.bridge.createPanel("WndActStarSkyPrayShop"); } }); // nx.tbox( "PrayDiaTimesLimit" ); return; } } } else {} } } else { if (this.havemat < this.needMatT) { if (this.haveDia >= this.needMatDT) { if (this.leftDia + times > this.diamond_times) { var _name = this.name ? this.name.name : ""; var _str2 = nx.text.format("ActStarPrayBuyTip", _name); nx.mbox(_str2, ['cancel', 'Buy'], function (_key, _box) { _box.close(); if (_key == "Buy") { // this.reqSummon( _args.type, _times, _args ); // self.close(); nx.bridge.createPanel("WndActStarSkyPrayShop"); } }); // nx.tbox( "PrayDiaTimesLimit" ); return; } } } } var str = nx.text.format("elfin_hatch_unlock_6", nx.text.getKey("Dia")); var usetype = 0; // 正在播動畫 if (this.onDoing) { nx.tbox("PrayDiaDoing"); return; } this.unscheduleAllCallbacks(); if (times == 1) { // 1 free 3 钻石 4 道具 if (this.useFree) { usetype = 1; } else { if (this.useItemF) { usetype = 4; } else { if (this.useDiaF) { usetype = 3; } else { nx.mbox(str, ['cancel', 'GotoCharge'], function (_key, _box) { _box.close(); if (_key == "GotoCharge") { // this.reqSummon( _args.type, _times, _args ); self.close(); nx.bridge.jumper.jump2Window(FID.Charge); } }); return; } } } } else { if (this.useItemT) { usetype = 4; } else { if (this.useDiaT) { usetype = 3; } else { nx.mbox(str, ['cancel', 'GotoCharge'], function (_key, _box) { _box.close(); if (_key == "GotoCharge") { // this.reqSummon( _args.type, _times, _args ); self.close(); nx.bridge.jumper.jump2Window(FID.Charge); } }); return; } } } var dataa = { group_id: this.periods_num.val, times: times }; this.mod.reqGetStarPray(dataa, function (_ret, _data) { // console.log( "當前的返回相關" + JSON.stringify( _data ) ); if (!_ret) { nx.tbox(_data); return; } // {"flag":1,"msg":"","item_id":[{"id":102}]} // 本地道具-1 // nx.gui.setString( this.nodMat, "count/txt", nx.dt.shortCount( this.have - 1 ) ); // 过程模拟 var num = -_this3.nodRewardsR.children.length; // nx.tween.fadeIn( this.nodFocus,"", 0.1 ); var self = _this3; _this3.finalResult = _data.item_id; if (_this3.skip || times == 10) { var _dataa = { group_id: self.periods_num.val, type: usetype, id: 0 }; self.onDoing = false; self.mod.reqGetStarPrayRewardData(_dataa); return; } // this.schedule( dealPlay, _data.item_id.length, cc.macro.REPEAT_FOREVER ); _this3.onDoAni(num / 3, _data.item_id, 0, usetype); // dealPlay(); }); }, onTouchGetReach: function onTouchGetReach(_btn) { this.mod.reqGetStarReachReward(_btn.zIndex); }, onTouchJump: function onTouchJump() { var jump = this.nodJump.isChecked; // this.mod.reqGetStarReachReward( _btn.zIndex ); this.mod.reqSetStatus(jump); }, onTouchHelp: function onTouchHelp() { var explain = gdata(this.mod.data.config, "data_explain")[1]; var prob = gdata(this.mod.data.config, "data_prob_info"); var probs = []; for (var i in prob) { var pro = prob[i]; probs.push(pro); } var ruleinfo = { desc: explain.desc, prob: probs, mod: this.mod }; nx.bridge.createPanel("WndActStarSkyPrayRule", ruleinfo); } }); cc._RF.pop();