"use strict"; cc._RF.push(module, 'cf1bbEpnzJGf4P5NUJo3BcE', 'cmp.act.firstcharge.wnd'); // Scripts/mod/acts/firstcharge/cmp/cmp.act.firstcharge.wnd.js "use strict"; var BasePage = require("act.page.base"); var NxTogs = require("nx.fx.togs"); var NxSpine = require("nx.fx.spine"); var PathTool = require("pathtool"); var Payment = require("payment.mod"); var RoleController = require("role_controller"); cc.Class({ "extends": BasePage, properties: { list: { "default": null, type: cc.Node }, nodCharge: { "default": null, type: cc.Node }, nodNormalCharge: { "default": null, type: cc.Node }, video: { "default": null, type: cc.VideoPlayer }, nodCtl: { "default": null, type: cc.Node }, nodRole: { "default": null, type: NxSpine }, nodTitle: { "default": null, type: cc.Node }, nodMenus: { "default": null, type: NxTogs }, nodRightDesc: { "default": null, type: cc.Node } }, // 初始化 build: function build(_data) { this._super(_data); this.charge = 0; this.normalCharge = 0; // this.default = 0; // 无效 if (!this.mod) { return; } var ccfg = gdata(this.data.config, "data_constant").spine_charge.val; // nx.gui.setActive( this, "op/btn_buy", false ); // nx.gui.setActive( this.video.node.parent, "", false ); this.charge_data = gdata(this.data.config, "data_new_first_charge_data3"); //game.configs.charge_data.data_new_first_charge_data3; var fids = []; this.fidsss = []; for (var i in this.charge_data) { var fid = this.charge_data[i]; if (!nx.dt.arrMember(fids, fid.fid)) { fids.push(fid.fid); this.fidsss.push({ fid: fid.fid, cost: fid.desc1, price: fid.desc2, model: fid.desc3, desc: fid.desc, leftdesc: fid.desc5, rightdesc: fid.desc4 }); } } this.fidsss.sort(Utils.tableLowerSorter(["fid"])); // fids.sort( ); this.select_index = 1; //fid // this.togs.posTog = this.onTogMenu.bind( this ); // this.togs.togTo( 0 ); // 活动监听 this.mod.vbind(this, [["firstCharge", this.freshInfos.bind(this)]]); nx.gui.gocChildren(this.nodMenus, "", fids.length); var chd = this.nodMenus.node.children; for (var c = 0; c < chd.length; c++) { var nod = chd[c]; var info = this.fidsss[c]; nx.gui.setString(nod, "on/txt", info.desc); nx.gui.setString(nod, "off/txt", info.desc); } // nx.gui.gocChildren( this.nodMenus, "", fids.length ); this.nodMenus.posTog = this.onTogMenu.bind(this); this.nodMenus.togTo(0); this.onTogMenu(0); var firstop = true; // let open = nx.storage.get( "openvideovol" + role.rid ); // if( open ){ // firstop = open == 1; // } // this.video.volume = firstop ? 0 : 1; // this.nodCtl.getComponent( cc.Toggle ).isChecked = firstop; // let desc = firstop ? nx.text.getKey( "ActSeeVideoDefaultTips" ) : nx.text.getKey( "ActSeeVideoOpenTips" ) ; // nx.gui.setString( this.nodCtl, "tips", desc ); this.mod.reqFirstData(); // this.setMainInfo(); }, // 销毁 onDestroy: function onDestroy() { // nx.gui.setActive( this, "op/btn_buy", false ); // nx.gui.setActive( this.video, "", false ); // 活动监听解除 if (this.mod) { this.mod.vunbind(this); } this._super(); }, onEnable: function onEnable() {}, freshInfos: function freshInfos(_data) { if (nx.dt.arrEmpty(_data) || !_data) return; nx.gui.hideAllChildren(this.nodCharge, "cost"); var rewards = []; var count = 0; for (var i = 0; i < _data.length; i++) { var gift = _data[i]; var cfgc = this.charge_data[gift.id]; var award_status = _data[i].status; if (cfgc.fid == this.select) { if (award_status == 1 || award_status == 2) { count++; } rewards.push({ cfg: cfgc, status: award_status }); this.charge = cfgc.desc2; this.normalCharge = cfgc.desc1; } } // 请求信息 var price = Payment.getInstance().transPrice(this.charge); var normalPrice = Payment.getInstance().transPrice(this.normalCharge); var path = "cost/" + "num" + price; nx.gui.setString(this.nodCharge, path, price); nx.gui.setActive(this.nodCharge, path, true); nx.gui.setString(this.nodNormalCharge, "", normalPrice); rewards.sort(function (a, b) { return a.cfg.day - b.cfg.day; }); nx.gui.setString(this, "op/btn_buy/txt", count > 0 ? nx.text.getKey("Charged") : nx.text.getKey("Buy")); var cmp = nx.gui.getComponent(this, "op/btn_buy", cc.Button); if (cmp) { cmp.interactable = count == 0; } // nx.gui.setActive( this.video, "", true ); // nx.tween.fadeIn( this, "op/btn_buy", 0.5 ); nx.tween.fadeIn(this, "op/btn_buy", 0.3); this.refreshItems(rewards); // nx.gui.setActive( this.btnBuy, "", is_buy ); }, refreshItems: function refreshItems(cur_list) { nx.gui.gocChildren(this.list, "", cur_list.length); for (var i = 0; i < this.list.children.length; i++) { var nod = this.list.children[i]; var cmp = nx.gui.getComponent(nod, "", "cmp.act.firstcharge.item"); if (cmp) { cmp.rebind(i, cur_list[i], this.mod); } } }, onClickBuy: function onClickBuy() { var charge_id = null; for (var i in this.charge_data) { if (this.charge_data[i].fid == this.select) { charge_id = this.charge_data[i].need_exp; break; } } if (charge_id == null) return; Payment.getInstance().reqPayment(charge_id); }, onTouchVideo: function onTouchVideo() { this.video.play(); }, onTouchVolCtl: function onTouchVolCtl(_nod) { var role = RoleController.getInstance().getRoleVo(); var nod = _nod; var select = nod.getComponent(cc.Toggle).isChecked; var desc = select ? nx.text.getKey("ActSeeVideoDefaultTips") : nx.text.getKey("ActSeeVideoOpenTips"); nx.gui.setString(nod, "tips", desc); this.video.volume = select ? 0 : 1; nx.storage.set("openvideovol" + role.rid, select ? 1 : 0); }, onTogMenu: function onTogMenu(_idx) { var _this = this; var cfg = this.fidsss[_idx]; this.select = parseInt(_idx) + 1; var dataa = this.mod.vget("firstCharge"); var model = cfg.model; this.nodRole.load("resDB/models/" + model + "/show", function (_e) { if (!_e) { _this.nodRole.action("action1", true); } else { _this.nodRole.stop(); } }); var uipath = cc.path.join("locals/{lang}/images/acts", cfg.rightdesc); nx.gui.setSpriteFrame(this.nodRightDesc, "", nx.res.fmtPath(uipath)); if (nx.dt.strNEmpty(cfg.leftdesc)) { var _uipath = cc.path.join("locals/{lang}/images/acts", cfg.leftdesc); nx.gui.setSpriteFrame(this.nodTitle, "", nx.res.fmtPath(_uipath)); } else { nx.gui.setSpriteFrame(this.nodTitle, "", null); } this.freshInfos(dataa); } }); cc._RF.pop();