201 lines
6.3 KiB
JavaScript
201 lines
6.3 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '9ee21rhj95EqokYQKphEWXr', 'act.mysteryshop.wnd');
|
|
// Scripts/mod/acts/mysteryshop/act.mysteryshop.wnd.js
|
|
|
|
"use strict";
|
|
|
|
var ActPopup = require("act.popup.base");
|
|
var mod = require("act.mysteryshop.mod");
|
|
var FxTogs = require("nx.fx.togs");
|
|
var Payment = require("payment.mod");
|
|
var RoleController = require("role_controller");
|
|
var TDefine = require("trace.define");
|
|
var TTT = TDefine.TraceType;
|
|
cc.Class({
|
|
"extends": ActPopup,
|
|
properties: {
|
|
nodGifts: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodMenu: {
|
|
"default": null,
|
|
type: FxTogs
|
|
},
|
|
nodOp: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodLimit: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodTime: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodCost: {
|
|
"default": null,
|
|
type: cc.Node
|
|
}
|
|
},
|
|
onOpenConfigs: function onOpenConfigs(_params) {
|
|
var _this = this;
|
|
this._super(_params);
|
|
this.mod = mod.getInstance();
|
|
if (!this.mod) {
|
|
this.delayClose();
|
|
return;
|
|
}
|
|
var needgo = nx.dt.objNEmpty(_params) ? _params.id : _params;
|
|
var toggo = 0;
|
|
this.cfgs = gdata(this.mod.data.config, "data_daily_gift_data");
|
|
var count = Object.keys(this.cfgs).length;
|
|
this.cfgss = [];
|
|
nx.gui.gocChildren(this.nodMenu.node, "", count);
|
|
this.nodMenu.rebuildTogs();
|
|
this.nodMenu._freshTogShow();
|
|
var chd = this.nodMenu.node.children;
|
|
var _loop = function _loop() {
|
|
var info = _this.cfgs[i];
|
|
var nod = chd[info.id - 1];
|
|
var showid = info.id % 2 == 0 ? 2 : 1;
|
|
// let path = cc.path.join( "prefab/acts/mysteryshop/ui/btn_0" + showid );
|
|
nx.gui.setString(nod, "on/txt", info.name);
|
|
// nx.gui.setSpriteFrame( nod, "on/dbg", path );
|
|
// nx.gui.setSpriteFrame( nod, "off/bg", path );
|
|
nx.gui.setString(nod, "off/txt", info.name);
|
|
// nx.gui.setOutlineColor( nod, "off/txt", info.id % 2 == 0 ? new cc.color( "#236491" ) : new cc.color( "#B85833" ) )
|
|
|
|
var reward = info.reward;
|
|
if (nx.dt.objNEmpty(_params)) {
|
|
if (needgo && info.id == needgo) {
|
|
toggo = info.id - 1;
|
|
}
|
|
} else {
|
|
if (nx.dt.arrNEmpty(reward)) {
|
|
reward.forEach(function (_reward) {
|
|
if (needgo && _reward[0] == needgo) {
|
|
toggo = info.id - 1;
|
|
}
|
|
});
|
|
}
|
|
}
|
|
_this.cfgss.push(info);
|
|
};
|
|
for (var i in this.cfgs) {
|
|
_loop();
|
|
}
|
|
|
|
// Tog监听
|
|
this.nodMenu.posTog = this.onTogMenu.bind(this);
|
|
this.nodMenu.togTo(toggo);
|
|
this.onTogMenu(toggo);
|
|
this.mod.vbind(this, [["mysteryshop", this.freshInfo.bind(this)]]);
|
|
this.mod.reqMysteryChargeData();
|
|
},
|
|
onEnable: function onEnable() {},
|
|
onDestroy: function onDestroy() {
|
|
// 活动监听解除
|
|
if (this.mod) {
|
|
this.mod.vunbind(this);
|
|
}
|
|
delete this.mod;
|
|
this._super();
|
|
},
|
|
freshInfo: function freshInfo(_data) {
|
|
var _this2 = this;
|
|
this.gifts = _data.first_gift;
|
|
var limit = this.cfgss[this.doid];
|
|
var show = 0;
|
|
for (var i = 0; i < this.gifts.length; i++) {
|
|
var _info2 = this.gifts[i];
|
|
if (_info2.id - 1 == this.doid) {
|
|
show = _info2.count;
|
|
nx.gui.setString(this.nodLimit, "count", nx.text.format("BuyLimit", limit.limit_count - _info2.count, limit.limit_count));
|
|
nx.gui.setString(this.nodCost, "num", nx.text.getKey("act_limit_buy1") + Payment.getInstance().fmtPrice(limit.old_price));
|
|
}
|
|
}
|
|
var time = new Date();
|
|
var left = _data.end_time > 0 ? _data.end_time - time / 1000 : 0.1;
|
|
nx.gui.setCdTxt(this.nodTime, "time", left, function () {
|
|
nx.gui.setString(_this2.nodTime, "time", nx.text.getKey("lab_planesafk_main_have_over"));
|
|
});
|
|
var info = {
|
|
count: show,
|
|
total: limit.limit_count,
|
|
vip: limit.limit_vip,
|
|
price: limit.old_price
|
|
};
|
|
this.dealLimit(info);
|
|
|
|
// [21053]:{"first_gift":[{"id":1,"count":1}],"end_time":1705420800}
|
|
},
|
|
|
|
// 等级切换
|
|
onTogMenu: function onTogMenu(_index) {
|
|
var id = parseInt(_index);
|
|
var cfg = this.cfgss[id];
|
|
this.doid = id;
|
|
nx.gui.gocChildren(this.nodGifts, "", cfg.reward.length);
|
|
var chd = this.nodGifts.children;
|
|
for (var i = 0; i < chd.length; i++) {
|
|
var reward = cfg.reward[i];
|
|
var nod = chd[i];
|
|
var cmp = nx.gui.getComponent(nod, "item", "cmp.item.base");
|
|
if (cmp) {
|
|
cmp.setData(reward);
|
|
}
|
|
}
|
|
var show = 0;
|
|
this.nodOp.chargeid = cfg.charge_id;
|
|
if (this.gifts && nx.dt.arrNEmpty(this.gifts)) {
|
|
for (var d = 0; d < this.gifts.length; d++) {
|
|
var _info3 = this.gifts[d];
|
|
if (_info3.id == id + 1) {
|
|
show = _info3.count;
|
|
}
|
|
}
|
|
}
|
|
var info = {
|
|
count: show,
|
|
total: cfg.limit_count,
|
|
vip: cfg.limit_vip,
|
|
price: cfg.old_price
|
|
};
|
|
|
|
// 埋点
|
|
if (nx.mTrace) {
|
|
nx.mTrace.trace(TTT.actCampOpened, this.mod.data.camp_id, id);
|
|
}
|
|
nx.gui.setString(this.nodLimit, "count", nx.text.format("BuyLimit", cfg.limit_count - show, cfg.limit_count));
|
|
nx.gui.setString(this.nodLimit, "vip", nx.text.format("tips_vipBuy", cfg.limit_vip));
|
|
nx.gui.setActive(this.nodLimit, "vip", cfg.limit_vip > 0);
|
|
nx.gui.setString(this.nodOp, "price", Payment.getInstance().fmtPrice(cfg.val));
|
|
nx.gui.setString(this.nodCost, "num", nx.text.getKey("act_limit_buy1") + Payment.getInstance().fmtPrice(cfg.old_price));
|
|
this.dealLimit(info);
|
|
},
|
|
dealLimit: function dealLimit(_info) {
|
|
var needs = _info;
|
|
var role = RoleController.getInstance().getRoleVo();
|
|
var cmp = nx.gui.getComponent(this.nodOp, "", cc.Button);
|
|
if (cmp) {
|
|
if (needs.vip > 0) {
|
|
cmp.interactable = role.vip_lev >= needs.vip && needs.total - needs.count > 0;
|
|
nx.gui.setOutlineColor(this.nodOp, "price", role.vip_lev >= needs.vip && needs.total - needs.count > 0 ? new cc.color("#b85833") : cc.Color.BLACK);
|
|
} else {
|
|
cmp.interactable = needs.count > 0 ? 0 < needs.total - needs.count : true;
|
|
if (needs.count > 0) {
|
|
nx.gui.setOutlineColor(this.nodOp, "price", needs.total - needs.count > 0 ? new cc.color("#b85833") : cc.Color.BLACK);
|
|
} else {
|
|
nx.gui.setOutlineColor(this.nodOp, "price", new cc.color("#b85833"));
|
|
}
|
|
}
|
|
}
|
|
},
|
|
onTouchBuy: function onTouchBuy(_btn) {
|
|
Payment.getInstance().reqPayment(_btn.chargeid);
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |