198 lines
5.2 KiB
JavaScript
198 lines
5.2 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '594e40sUVtMpK/neDUec/Sx', 'cmp.personal.push.wnd');
|
|
// Scripts/mod/acts/push/cmp.personal.push.wnd.js
|
|
|
|
"use strict";
|
|
|
|
/******************************************************************
|
|
*
|
|
* 个人推送界面
|
|
*
|
|
******************************************************************/
|
|
|
|
var BridgeWindow = require("bridge.window");
|
|
var PPushMod = require("personal.push.mod");
|
|
cc.Class({
|
|
"extends": BridgeWindow,
|
|
properties: {
|
|
menu: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
pages: {
|
|
"default": null,
|
|
type: cc.Node
|
|
},
|
|
togWords: {
|
|
"default": null,
|
|
type: cc.Node
|
|
}
|
|
},
|
|
// 载入
|
|
onLoad: function onLoad() {
|
|
this.cur = 0;
|
|
this.ids = [];
|
|
this.gifts = {};
|
|
|
|
// 菜单初始化
|
|
this.menu.children.forEach(function (_item) {
|
|
nx.gui.setActive(_item, "on", false);
|
|
nx.gui.setActive(_item, "off", true);
|
|
});
|
|
},
|
|
// 展示
|
|
onEnable: function onEnable() {
|
|
// 视图绑定
|
|
nx.bridge.vbind(this, [["PPushGifts", this.onFreshGifts.bind(this)]]);
|
|
|
|
// 开关
|
|
var tmp = nx.storage.getNumber("PPHideTip", 0);
|
|
this.showTip = tmp == 1;
|
|
nx.gui.setActive(this.togWords, "ck/on", this.showTip);
|
|
nx.gui.setActive(this.togWords, "ck/off", !this.showTip);
|
|
},
|
|
// 销毁
|
|
onDisable: function onDisable() {
|
|
// 视图监听解除
|
|
nx.bridge.vunbind(this);
|
|
},
|
|
// 礼包刷新
|
|
onFreshGifts: function onFreshGifts(_list) {
|
|
var _this = this;
|
|
// 空隐藏
|
|
if (nx.dt.arrEmpty(_list)) {
|
|
this.close();
|
|
return;
|
|
}
|
|
|
|
// 没有改变
|
|
var arr = [];
|
|
_list.forEach(function (_t) {
|
|
arr.push(_t.gift_id);
|
|
});
|
|
if (this.ids.toString() == arr.toString()) {
|
|
return;
|
|
}
|
|
|
|
// 刷新
|
|
this.ids = arr;
|
|
this.gifts = {};
|
|
var DATA = game.configs.personal_push_data.data_gift_info;
|
|
_list.forEach(function (_t) {
|
|
var cfg = DATA[_t.gift_id];
|
|
if (!cfg) {
|
|
nx.error("$Push:\u65E0\u6548\u793C\u5305:" + _t.gift_id);
|
|
return;
|
|
}
|
|
var DATA2 = game.configs.personal_push_data.data_gift_layout_info[cfg.layout];
|
|
var detail = DATA2 ? DATA2[cfg.gift_id] : null;
|
|
if (!detail) {
|
|
nx.error("$Push:\u65E0\u6548\u793C\u5305:" + cfg.gift_id);
|
|
return;
|
|
}
|
|
var tmp = nx.dt.objClone(_t);
|
|
tmp.fab = cfg.layout;
|
|
tmp.price = cfg.money;
|
|
tmp.icon = cc.path.join("resDB/models/" + cfg.face_id + "/play/pkicon");
|
|
tmp.bg = detail.bg;
|
|
tmp.hover = detail.content_img;
|
|
tmp.model = detail.res_id;
|
|
tmp.action = detail.action;
|
|
tmp.desc1 = detail.desc || "";
|
|
tmp.desc2 = detail.name;
|
|
tmp.name = cfg.name;
|
|
_this.gifts[_t.gift_id] = tmp;
|
|
});
|
|
this.menu.active = true;
|
|
this.pages.active = true;
|
|
this.reMenu();
|
|
},
|
|
// ================================================
|
|
// 礼包相关
|
|
// ================================================
|
|
|
|
// 礼包重建
|
|
reMenu: function reMenu() {
|
|
if (nx.dt.arrEmpty(this.ids)) {
|
|
return;
|
|
}
|
|
var chds = this.menu.children;
|
|
nx.gui.gocChildren(this.menu, "", this.ids.length, chds[0]);
|
|
for (var i = 0; i < this.ids.length; ++i) {
|
|
var id = this.ids[i];
|
|
var tm = this.gifts[id];
|
|
var node = chds[i];
|
|
node.gift = tm;
|
|
nx.gui.setString(node, "on/txt", tm.name);
|
|
nx.gui.setString(node, "off/txt", tm.name);
|
|
nx.gui.setSpriteFrame(node, "role", tm.icon);
|
|
}
|
|
|
|
// 初始聚焦
|
|
var gift = this.gifts[this.cur];
|
|
if (!gift) {
|
|
var news = nx.bridge.vget("PPushNews");
|
|
if (news && news.length > 0) {
|
|
var _id = news[0].new_gift_id;
|
|
gift = this.gifts[_id];
|
|
}
|
|
if (!gift) {
|
|
gift = this.gifts[this.ids[0]];
|
|
}
|
|
}
|
|
this.togGift(gift);
|
|
},
|
|
// 点击切换
|
|
onTouchMenu: function onTouchMenu(_item) {
|
|
if (_item && _item.parent && _item.parent.gift) {
|
|
console.log(_item.parent.gift.gift_id);
|
|
this.togGift(_item.parent.gift);
|
|
}
|
|
},
|
|
// 切换礼包
|
|
togGift: function togGift(_gift) {
|
|
if (!_gift) {
|
|
return;
|
|
}
|
|
|
|
// 菜单切换
|
|
this.menu.children.forEach(function (_item) {
|
|
var info = _item.gift || {};
|
|
nx.gui.setActive(_item, "on", info.gift_id == _gift.gift_id);
|
|
nx.gui.setActive(_item, "off", info.gift_id != _gift.gift_id);
|
|
});
|
|
|
|
// 展示切换
|
|
this.showPage(_gift);
|
|
},
|
|
// ================================================
|
|
// 页面相关
|
|
// ================================================
|
|
|
|
// 页面展示
|
|
showPage: function showPage(_gift) {
|
|
var name = "p" + _gift.fab;
|
|
var node = nx.gui.find(this.pages, name);
|
|
if (!_gift || !node) {
|
|
return;
|
|
}
|
|
this.pages.children.forEach(function (_page) {
|
|
_page.active = _page.name == name;
|
|
});
|
|
var cmp = node.getComponent('cmp.personal.push.page');
|
|
cmp.rebuild(_gift);
|
|
},
|
|
// ================================================
|
|
// 其他
|
|
// ================================================
|
|
|
|
// 对话框显隐开关
|
|
onTogWords: function onTogWords() {
|
|
this.showTip = !this.showTip;
|
|
nx.storage.set("PPHideTip", this.showTip ? 1 : 0);
|
|
nx.gui.setActive(this.togWords, "ck/on", this.showTip);
|
|
nx.gui.setActive(this.togWords, "ck/off", !this.showTip);
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |