Files
fc/dev/project/assets/Scripts/mod/acts/push/cmp.personal.push.wnd.js
T
2026-05-23 22:10:14 +08:00

217 lines
5.7 KiB
JavaScript

/******************************************************************
*
* 个人推送界面
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const 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() {
this.cur = 0;
this.ids = [];
this.gifts = {};
// 菜单初始化
this.menu.children.forEach( _item => {
nx.gui.setActive( _item, "on", false );
nx.gui.setActive( _item, "off", true );
} );
},
// 展示
onEnable: function() {
// 视图绑定
nx.bridge.vbind( this, [
[ "PPushGifts", this.onFreshGifts.bind( this ) ],
] );
// 开关
let 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() {
// 视图监听解除
nx.bridge.vunbind( this );
},
// 礼包刷新
onFreshGifts: function( _list ) {
// 空隐藏
if( nx.dt.arrEmpty( _list ) ) {
this.close();
return;
}
// 没有改变
let arr = [];
_list.forEach( _t => {
arr.push( _t.gift_id );
} );
if( this.ids.toString() == arr.toString() ) {
return;
}
// 刷新
this.ids = arr;
this.gifts = {};
const DATA = game.configs.personal_push_data.data_gift_info;
_list.forEach( _t => {
let cfg = DATA[_t.gift_id];
if( !cfg ) {
nx.error( `$Push:无效礼包:${_t.gift_id}` );
return;
}
let DATA2 = game.configs.personal_push_data.data_gift_layout_info[cfg.layout];
let detail = DATA2 ? DATA2[cfg.gift_id] : null;
if( !detail ) {
nx.error( `$Push:无效礼包:${cfg.gift_id}` );
return;
}
let 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() {
if( nx.dt.arrEmpty( this.ids ) ) {
return;
}
let chds = this.menu.children;
nx.gui.gocChildren( this.menu, "", this.ids.length, chds[0] );
for( let i = 0; i < this.ids.length; ++i ) {
let id = this.ids[i];
let tm = this.gifts[id];
let 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 );
}
// 初始聚焦
let gift = this.gifts[this.cur];
if( !gift ) {
let news = nx.bridge.vget( "PPushNews" );
if( news && news.length > 0 ) {
let id = news[0].new_gift_id;
gift = this.gifts[id];
}
if( !gift ) {
gift = this.gifts[this.ids[0]];
}
}
this.togGift( gift );
},
// 点击切换
onTouchMenu: function( _item ) {
if( _item && _item.parent && _item.parent.gift ) {
console.log( _item.parent.gift.gift_id );
this.togGift( _item.parent.gift );
}
},
// 切换礼包
togGift: function( _gift ) {
if( !_gift ) {
return;
}
// 菜单切换
this.menu.children.forEach( _item => {
let 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( _gift ) {
let name = "p" + _gift.fab;
let node = nx.gui.find( this.pages, name );
if( !_gift || !node ) {
return;
}
this.pages.children.forEach( _page => {
_page.active = ( _page.name == name );
} );
let cmp = node.getComponent( 'cmp.personal.push.page' );
cmp.rebuild( _gift );
},
// ================================================
// 其他
// ================================================
// 对话框显隐开关
onTogWords: function() {
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 );
},
} );