309 lines
9.8 KiB
JavaScript
309 lines
9.8 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '0d18asU4atLC4xNlGuv7lOK', 'cmp.act.custom.page');
|
|
// Scripts/mod/acts/sevencustomization/cmp/cmp.act.custom.page.js
|
|
|
|
"use strict";
|
|
|
|
/******************************************************************
|
|
*
|
|
* 定制页面
|
|
*
|
|
******************************************************************/
|
|
var mod = require("act.sevencustom.mod");
|
|
var ActPopup = require("act.popup.base");
|
|
var Payment = require("payment.mod");
|
|
var TipsController = require("tips_controller");
|
|
cc.Class({
|
|
"extends": ActPopup,
|
|
properties: {
|
|
nodContent: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
nodCost: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
preItem: {
|
|
"default": null,
|
|
type: cc.Prefab
|
|
},
|
|
nodTime: {
|
|
"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 cfgs = gdata(this.mod.data.config, "data_optional_cfg");
|
|
var rewards = gdata(this.mod.data.config, "data_optional_reward");
|
|
var charge = game.configs.charge_data.data_charge_data;
|
|
var chd = this.nodCost.children;
|
|
var itemnod = this.nodContent.children[0];
|
|
this.first = [];
|
|
this.second = [];
|
|
for (var i in cfgs) {
|
|
var cfg = cfgs[i];
|
|
var price = cfg.charge_id > 0 ? Payment.getInstance().fmtPrice(charge[cfg.charge_id].val) : nx.text.getKey("Free");
|
|
var nod = chd[cfg.id - 1];
|
|
var reward = rewards[i];
|
|
var len = Object.keys(reward).length;
|
|
var rewardnod = nx.gui.find(itemnod, "reward").children[cfg.id - 1];
|
|
rewardnod.children.forEach(function (_nod) {
|
|
nx.gui.setActive(_nod, "", false);
|
|
});
|
|
for (var u = 0; u < len; u++) {
|
|
var rnod = rewardnod.children[u];
|
|
nx.gui.setActive(rnod, "", true);
|
|
nx.gui.setActive(rnod, "change", false);
|
|
nx.gui.setActive(rnod, "cannot", false);
|
|
nx.gui.setActive(rnod, "focus", false);
|
|
nx.gui.setActive(rnod, "get", false);
|
|
nx.gui.setActive(rnod, "canget", false);
|
|
}
|
|
for (var j in reward) {
|
|
var item = reward[j];
|
|
if (j == 1) {
|
|
item.forEach(function (_item) {
|
|
_this.first.push(_item[0]);
|
|
});
|
|
} else {
|
|
if (j == 2) {
|
|
item.forEach(function (_item) {
|
|
_this.second.push(_item[0]);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
// if( u == 0 ){
|
|
|
|
// this.first.push( )
|
|
// }
|
|
nx.gui.setString(nod, "txt", price);
|
|
nx.gui.setActive(nod, "focus", false);
|
|
}
|
|
var days = gdata(this.mod.data.config, "data_const").act_days.val;
|
|
nx.gui.gocChildren(this.nodContent, "", days);
|
|
var nods = this.nodContent.children;
|
|
for (var n = 0; n < nods.length; n++) {
|
|
var _nod2 = nods[n];
|
|
nx.gui.setActive(_nod2, "empty", false);
|
|
nx.gui.setString(_nod2, "day", "0" + (n + 1));
|
|
}
|
|
// 视图监听
|
|
this.mod.vbind(this, [["sevenCustom", this.freshDayReward.bind(this)]]);
|
|
this.mod.reqOptionalGiftData();
|
|
// // this.mod.reqBaseData();
|
|
// nx.debug( "$ActPage onEnable");
|
|
// 获取指定主题信息
|
|
},
|
|
|
|
onEnable: function onEnable() {
|
|
this.unscheduleAllCallbacks();
|
|
},
|
|
// 销毁
|
|
onDestroy: function onDestroy() {
|
|
// 活动监听解除
|
|
if (this.mod) {
|
|
this.mod.vunbind(this);
|
|
}
|
|
delete this.mod;
|
|
this._super();
|
|
},
|
|
// 倒计时
|
|
updateDate: function updateDate() {
|
|
var txt = nx.bridge.time.cdSimple(this.mod.data.end_time > 0 ? this.mod.data.end_time : 0);
|
|
txt = nx.text.getKey(txt || "已结束");
|
|
nx.gui.setString(this.nodTime, "time", txt);
|
|
},
|
|
freshDayReward: function freshDayReward(_cdata) {
|
|
var _this2 = this;
|
|
if (!_cdata || !this.nodContent) {
|
|
return;
|
|
}
|
|
var time = new Date();
|
|
var left = this.mod.data.end_time > 0 ? this.mod.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"));
|
|
});
|
|
this.custominfo = _cdata;
|
|
var chd = this.nodContent.children;
|
|
var payed = _cdata.data_list;
|
|
var lchd = this.nodCost.children;
|
|
// let reward = _cdata.data_list;
|
|
for (var p = 0; p < payed.length; p++) {
|
|
var nod = lchd[p];
|
|
nx.gui.setActive(nod, "focus", false);
|
|
nx.gui.setActive(nod, "normal", true);
|
|
var cmp = nx.gui.getComponent(nod, "", cc.Button);
|
|
if (cmp) {
|
|
cmp.interactable = this.custominfo.data_list[p].is_activate == 0 && p != 0;
|
|
nx.gui.setOutlineColor(nod, "txt", this.custominfo.data_list[p].is_activate == 0 && p != 0 ? new cc.color("#b85833") : cc.Color.BLACK);
|
|
}
|
|
}
|
|
for (var c = 0; c < chd.length; c++) {
|
|
var _nod3 = chd[c];
|
|
var _cmp = _nod3.getComponent("cmp.act.custom.item");
|
|
nx.gui.setActive(_nod3, "day", c <= _cdata.day - 1);
|
|
if (c <= _cdata.day - 1) {
|
|
_cmp.freshInfo({
|
|
active: true,
|
|
day: c,
|
|
config: this.mod.data.config,
|
|
rewards: payed
|
|
});
|
|
} else {
|
|
_cmp.freshInfo({
|
|
active: false,
|
|
day: c,
|
|
config: this.mod.data.config,
|
|
rewards: payed
|
|
});
|
|
}
|
|
}
|
|
this.setRewardInfo(payed);
|
|
this.freshTip(_cdata);
|
|
this.setBuyTimes();
|
|
},
|
|
setRewardInfo: function setRewardInfo(_rewards) {
|
|
var _this3 = this;
|
|
var self = this;
|
|
var rewards = _rewards;
|
|
var _loop = function _loop(r) {
|
|
var reward = rewards[r].reward_list;
|
|
if (nx.dt.arrNEmpty(reward)) {
|
|
reward.forEach(function (_r) {
|
|
var nod = self.nodContent.children[_r.day - 1];
|
|
var status = _r.status;
|
|
var rnod = nx.gui.find(nod, "reward").children[r];
|
|
for (var n = 0; n < rnod.children.length; n++) {
|
|
var pnod = rnod.children[n];
|
|
var count = 0;
|
|
// nx.gui.setActive( pnod, "change", false );
|
|
var nodParent = nx.gui.find(pnod, "item");
|
|
if (pnod.active) {
|
|
// _r.item_list.sort( ( a, b ) => {
|
|
// return a.item_id - b.item_id;
|
|
// } )
|
|
var _rewards2 = [];
|
|
var data = _r.item_list[pnod.touchId - 1];
|
|
if (data) {
|
|
var _nod4 = cc.instantiate(self.preItem);
|
|
|
|
// nod.getComponent( "cmp.item.base" ).setDate( data );
|
|
var show = {
|
|
bid: data.item_id,
|
|
num: data.num
|
|
};
|
|
_rewards2.push(show);
|
|
// nod.name = "item";
|
|
// nod.setParent( nodParent );
|
|
var cmp = nx.gui.getComponent(nodParent, "", "cmp.common.itemlayout");
|
|
if (cmp) {
|
|
// cmp.tipSelf = false;
|
|
cmp.rebuild(_rewards2);
|
|
}
|
|
nx.gui.setActive(pnod, "tip", false);
|
|
}
|
|
} //
|
|
nx.gui.setActive(pnod, "change", nodParent.children.length > 0 && status == 0);
|
|
nx.gui.setActive(pnod, "focus", false);
|
|
nx.gui.setActive(pnod, "canget", rewards[r].is_activate == 1 && _r.day <= _this3.custominfo.day && nodParent.children.length > 0 && status == 1);
|
|
nx.gui.setActive(pnod, "cannot", status == 3);
|
|
nx.gui.setActive(pnod, "get", status == 2);
|
|
}
|
|
var touch = nx.gui.getComponent(rnod, "", cc.Button);
|
|
if (touch) {
|
|
if (status) {
|
|
touch.interactable = status == 1 && rewards[r].is_activate == 1;
|
|
} else {
|
|
touch.interactable = false;
|
|
}
|
|
}
|
|
// rnod.children.forEach( _nod =>{
|
|
|
|
// } )
|
|
});
|
|
}
|
|
};
|
|
for (var r = 0; r < rewards.length; r++) {
|
|
_loop(r);
|
|
}
|
|
},
|
|
setBuyTimes: function setBuyTimes() {
|
|
var buyinfo = this.custominfo.data_list;
|
|
buyinfo.forEach(function (_nod) {
|
|
if (_nod.is_activate == 1) {}
|
|
});
|
|
},
|
|
freshTip: function freshTip(_data) {
|
|
var count = 0;
|
|
var self = this;
|
|
var day = _data.day;
|
|
var list = _data.data_list;
|
|
var nod = self.nodContent.children[_data.day - 1];
|
|
list.forEach(function (_item) {
|
|
if (_item.cate == 1) {
|
|
if (!_item.reward_list[day - 1]) {
|
|
count++;
|
|
}
|
|
}
|
|
});
|
|
var nods = nx.gui.find(nod, "reward/free").children;
|
|
nods.forEach(function (_nod) {
|
|
if (_nod.active) {
|
|
nx.gui.setActive(_nod, "tip", count++);
|
|
}
|
|
});
|
|
// nx.gui.setActive( nods, "reward/free" )
|
|
// this.openTip( "reward", count > 0 );
|
|
},
|
|
|
|
onTouchBuy: function onTouchBuy(_idx) {
|
|
var buyinfo = this.custominfo.data_list;
|
|
var count = 0;
|
|
var buy = [];
|
|
buyinfo.forEach(function (_nod) {
|
|
if (_nod.is_activate == 1 && _idx == _nod.cate) {
|
|
count++;
|
|
}
|
|
if (_idx == _nod.cate) {
|
|
buy = _nod.reward_list;
|
|
}
|
|
});
|
|
if (count > 0) {
|
|
nx.tbox("CustomBuyTip");
|
|
return;
|
|
}
|
|
if (buy.length < this.nodContent.children.length) {
|
|
nx.tbox("ActSevenCustom");
|
|
return;
|
|
}
|
|
var cfgs = gdata(this.mod.data.config, "data_optional_cfg");
|
|
if (cfgs[_idx].charge_id > 0) {
|
|
var msg = "pay " + cfgs[_idx].charge_id;
|
|
Payment.getInstance().reqPayment(cfgs[_idx].charge_id);
|
|
}
|
|
},
|
|
onTouchHelp: function onTouchHelp() {
|
|
var TC = TipsController.getInstance();
|
|
var explain = gdata(this.mod.data.config, "data_desc")[1];
|
|
TC.showTextPanel(explain.name, explain.desc);
|
|
}
|
|
});
|
|
/**{"day":5,"data_list":[
|
|
* {"cate":1,"is_activate":1,"reward_list":[{"day":5,"status":0,"item_list":[{"item_id":11403,"num":1}]},{"day":2,"status":0,"item_list":[{"item_id":11403,"num":1}]}]},
|
|
* {"cate":2,"is_activate":0,"reward_list":[]},
|
|
* {"cate":3,"is_activate":0,"reward_list":[]},
|
|
* {"cate":4,"is_activate":0,"reward_list":[]}]}
|
|
|
|
/***/
|
|
|
|
cc._RF.pop(); |