"use strict"; cc._RF.push(module, '0b263wf9QdAF7aat4qh9Qbs', 'cmp.act.starskypray.shop'); // Scripts/mod/acts/starskyprayer/cmp/cmp.act.starskypray.shop.js "use strict"; var BridgeWindow = require("bridge.window"); var NxSpine = require("nx.fx.spine"); var Mod = require("act.starskyprayer.mod"); var Payment = require("payment.mod"); var TDefine = require("trace.define"); var TTT = TDefine.TraceType; cc.Class({ "extends": BridgeWindow, //30019 properties: { spRole: { "default": null, type: NxSpine }, nodList: { "default": null, type: cc.Node } }, onLoad: function onLoad() { var _this = this; this.mod = Mod.getInstance(); // 无效 if (!this.mod) { return; } this.spRole.load("resDB/models/H30019/show", function (_e) { if (!_e) { _this.spRole.action("action1", true); } else { _this.spRole.stop(); } }); this.cfg = gdata(this.mod.data.config, "data_shop_info"); var count = Object.keys(this.cfg).length; this.buyInfos = []; nx.gui.gocChildren(this.nodList, "", count); for (var i in this.cfg) { var dataitem = this.cfg[i]; var nod = this.nodList.children[dataitem.id - 1]; var reward = nx.dt.objClone(dataitem.reward); nx.gui.find(nod, "buy").payType = dataitem.pay_type; nx.gui.find(nod, "buy").payInfo = dataitem.charge_id; nx.gui.setActive(nod, "buy/cost/icon", dataitem.pay_type == 2); if (dataitem.pay_type == 2) { nx.bridge.setIconS(nod, "buy/cost/icon", "3"); } nx.gui.setString(nod, "buy/cost/price", dataitem.pay_type == 2 ? dataitem.price : Payment.getInstance().fmtPrice(dataitem.price)); var first = []; this.buyInfos.push(dataitem); first.push(reward.shift()); var nodd = nx.gui.find(nod, "itemlist").children; var nodf = nodd[0]; var nods = nodd[1]; this.setGray(nod, 0); nx.gui.setActive(nodf, "", nx.dt.arrNEmpty(first)); nx.gui.setActive(nods, "", nx.dt.arrNEmpty(reward)); nx.gui.setActive(nod, "left", false); var cmpf = nx.gui.getComponent(nodf, "", "cmp.common.itemlayout"); if (cmpf) { cmpf.rebuild(first); } if (reward && nx.dt.arrNEmpty(reward)) { var cmpt = nx.gui.getComponent(nods, "", "cmp.common.itemlayout"); if (cmpt) { cmpt.rebuild(reward); } } } // 埋点 if (nx.mTrace) { nx.mTrace.trace(TTT.actCampOpened, this.mod.data.camp_id, 0); } // 活动监听 this.mod.vbind(this, [["starPrayShopData", this.freshInfo.bind(this)]]); }, // 销毁 onDestroy: function onDestroy() { // 活动监听解除 if (this.mod) { this.mod.vunbind(this); } delete this.mod; this._super(); }, onEnable: function onEnable() { this.mod.reqStarGiftInfo(); }, freshInfo: function freshInfo(_data) { if (!_data || !_data.ids) { return; } var info = _data.ids; // this.buyInfos = info; var chd = this.nodList.children; for (var i = 0; i < info.length; i++) { var data = info[i]; var nod = chd[data.id - 1]; nx.gui.setString(nod, "left/count", data.buy_num); if (data.buy_num == 0) { this.setGray(nod, 1); } nx.gui.setActive(nod, "left", true); } /***{"ids":[ * {"id":1,"buy_num":2}, * {"id":2,"buy_num":2}, * {"id":3,"buy_num":2}, * {"id":4,"buy_num":3}, * {"id":5,"buy_num":5}, * {"id":6,"buy_num":5} * ]} * */ }, onTouchBuy: function onTouchBuy(_btn) { var type = _btn.payType; var info = _btn.payInfo; if (type == 2) { var buynum = 0; this.buyInfos.forEach(function (_info) { if (_info.pay_type == type) { buynum = _info.buy_num; } }); if (buynum == 0) { nx.tbox(); return; } this.mod.reqBuyUseDia(); return; } Payment.getInstance().reqPayment(info); }, setGray: function setGray(_nod, _mat) { var nod = _nod; var sp = nx.gui.getComponent(nod, "buy/bg", cc.Sprite); var ssp = nx.gui.getComponent(nod, "buy/cost/icon", cc.Sprite); var material = _mat == 1 ? cc.Material.getBuiltinMaterial('2d-gray-sprite') : cc.Material.getBuiltinMaterial('2d-sprite'); nx.gui.setOutlineColor(nod, "buy/cost/price", _mat == 0 ? new cc.color("#b85833") : cc.Color.BLACK); var cmp = nx.gui.getComponent(nod, "buy", cc.Button); if (cmp) { cmp.interactable = _mat == 0; } sp.setMaterial(0, material); ssp.setMaterial(0, material); }, close: function close() { this.mod.reqBaseData(); this._super(); } }); cc._RF.pop();