256 lines
7.2 KiB
JavaScript
256 lines
7.2 KiB
JavaScript
|
|
/******************************************************************
|
||
|
|
*
|
||
|
|
* 主題入口樣式1
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
const BridgeWindow = require( "bridge.window" );
|
||
|
|
const NxSpine = require( "nx.fx.spine" );
|
||
|
|
const TDefine = require( "trace.define" );
|
||
|
|
const TTT = TDefine.TraceType;
|
||
|
|
|
||
|
|
cc.Class( {
|
||
|
|
|
||
|
|
extends: BridgeWindow,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
|
||
|
|
nodMenu: { default: null, type: cc.Node },
|
||
|
|
spBG: { default: null, type: NxSpine },
|
||
|
|
spSlots: { default: null, type: NxSpine },
|
||
|
|
imgLogo: { default: null, type: cc.Node },
|
||
|
|
nodClose: { default: null, type: cc.Node },
|
||
|
|
nodDate: { default: null, type: cc.Node },
|
||
|
|
lstEntries: { default: [], type: cc.Node },
|
||
|
|
},
|
||
|
|
|
||
|
|
// 载入
|
||
|
|
onLoad: function() {
|
||
|
|
|
||
|
|
nx.gui.setActive( this.imgLogo, "", false );
|
||
|
|
nx.gui.setActive( this.nodClose, "", false );
|
||
|
|
nx.gui.setActive( this.nodMenu, "", false );
|
||
|
|
nx.gui.setActive( this.nodDate, "", false );
|
||
|
|
nx.gui.setActive( this.spBG, "", false );
|
||
|
|
nx.gui.setActive( this.spSlots, "", false );
|
||
|
|
this.lstEntries.forEach( _entry => {
|
||
|
|
nx.gui.setActive( this.nodDate, "", false );
|
||
|
|
} );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 重载:参数打开
|
||
|
|
onOpenConfigs: function( _params ) {
|
||
|
|
|
||
|
|
// 信息构建
|
||
|
|
this.buildData( _params );
|
||
|
|
|
||
|
|
// 背景动画
|
||
|
|
this.doStart();
|
||
|
|
|
||
|
|
// 埋点
|
||
|
|
if( nx.mTrace ) {
|
||
|
|
nx.mTrace.trace( TTT.actThemeOpened, _params.theme_id );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 信息构建
|
||
|
|
buildData: function( _params ) {
|
||
|
|
|
||
|
|
// 无效参数
|
||
|
|
if( nx.dt.objEmpty( _params ) ||
|
||
|
|
!nx.dt.numPositive( _params.theme_id, false ) ||
|
||
|
|
nx.dt.arrEmpty( _params.theme_holiday_list ) ) {
|
||
|
|
this.delayClose();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.theme = _params;
|
||
|
|
|
||
|
|
// 活动统计
|
||
|
|
this.acts = {};
|
||
|
|
_params.theme_holiday_list.forEach( _item => {
|
||
|
|
|
||
|
|
this.acts[ _item.cate ] = this.acts[ _item.cate ] || {
|
||
|
|
name: nx.text.getKey( _item.cate_name ),
|
||
|
|
list: []
|
||
|
|
};
|
||
|
|
|
||
|
|
this.acts[ _item.cate ].list.push( _item );
|
||
|
|
} );
|
||
|
|
|
||
|
|
// 活动日期
|
||
|
|
let secs = this.theme.end_time - client.socket.getTime();
|
||
|
|
if( nx.dt.numPositive( secs, false ) ) {
|
||
|
|
nx.gui.setColor( this.nodDate, "txt", cc.color().fromHEX( "#05F515" ) );
|
||
|
|
nx.gui.setCdTxt( this.nodDate, "txt", secs );
|
||
|
|
} else {
|
||
|
|
nx.gui.setString( this.nodDate, "txt", nx.text.getKey( "已过期" ) );
|
||
|
|
nx.gui.setColor( this.nodDate, "txt", cc.Color.RED );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 背景动画
|
||
|
|
doStart: function() {
|
||
|
|
|
||
|
|
let self = this;
|
||
|
|
let show = function() {
|
||
|
|
nx.gui.setActive( self.imgLogo, "", true );
|
||
|
|
nx.gui.setActive( self.nodClose, "", true );
|
||
|
|
nx.gui.setActive( self.nodDate, "", true );
|
||
|
|
self.buildMenu();
|
||
|
|
};
|
||
|
|
|
||
|
|
nx.gui.setActive( this.spBG, "", true );
|
||
|
|
this.spBG.action( "show", false, ( _event ) => {
|
||
|
|
nx.debug( `%doStart:${ _event }` );
|
||
|
|
// 菜单展示
|
||
|
|
if( _event == "done" ) {
|
||
|
|
show();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 完毕
|
||
|
|
if( _event == "complete" ) {
|
||
|
|
this.spBG.action( "loop", true );
|
||
|
|
}
|
||
|
|
} );
|
||
|
|
},
|
||
|
|
|
||
|
|
// -------------------------------------------------------
|
||
|
|
// 菜单相关
|
||
|
|
// -------------------------------------------------------
|
||
|
|
|
||
|
|
// 菜单重建
|
||
|
|
buildMenu: function() {
|
||
|
|
|
||
|
|
nx.gui.setActive( this.nodMenu, "", true );
|
||
|
|
|
||
|
|
let keys = Object.keys( this.acts );
|
||
|
|
let chds = this.nodMenu.children;
|
||
|
|
for( let i = 0; i < chds.length; ++i ) {
|
||
|
|
|
||
|
|
let tog = chds[ i ];
|
||
|
|
let ifo = this.acts[ keys[ i ] ];
|
||
|
|
if( !ifo ) {
|
||
|
|
tog.active = false;
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
tog.active = true;
|
||
|
|
nx.gui.setString( tog, "on/txt", ifo.name );
|
||
|
|
nx.gui.setString( tog, "off/txt", ifo.name );
|
||
|
|
|
||
|
|
let tip = nx.gui.getComponent( tog, "off/tip", "nx.vb.visible" );
|
||
|
|
if( tip ) {
|
||
|
|
tip.setTarget( nx.mTip, `acts.${ this.theme.theme_id }.${ keys[ i ] }` );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
this.onTouchMenu( keys[ 0 ] );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 菜单切换
|
||
|
|
onTouchMenu: function( _index ) {
|
||
|
|
|
||
|
|
let key = `tog${ _index }`;
|
||
|
|
this.nodMenu.children.forEach( _tog => {
|
||
|
|
nx.gui.setActive( _tog, "off", _tog.name != key );
|
||
|
|
nx.gui.setActive( _tog, "on", _tog.name == key );
|
||
|
|
} );
|
||
|
|
|
||
|
|
this.showPage( _index );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 页动画展示
|
||
|
|
showPage: function( _index ) {
|
||
|
|
|
||
|
|
// 入口重建&隐藏
|
||
|
|
this.lstEntries.forEach( _entry => {
|
||
|
|
_entry.active = false;
|
||
|
|
} );
|
||
|
|
|
||
|
|
// 活动重建
|
||
|
|
let index = parseInt( _index );
|
||
|
|
let acts = this.acts[ index ];
|
||
|
|
if( !acts || nx.dt.arrEmpty( acts.list ) ) {
|
||
|
|
nx.error( `$ThemeEntry:活动无效!${ _index }` );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 排序
|
||
|
|
// acts.list.sort( ( _a, _b ) => {
|
||
|
|
// return _a.sort - _b.sort;
|
||
|
|
// } );
|
||
|
|
|
||
|
|
// 活动重建
|
||
|
|
this.lstEntries.forEach( _node => {
|
||
|
|
_node.ainfo = null;
|
||
|
|
_node.active = false;
|
||
|
|
nx.gui.setString( _node, "txt", "" );
|
||
|
|
} );
|
||
|
|
|
||
|
|
for( let i = 0; i < acts.list.length; ++i ) {
|
||
|
|
|
||
|
|
let info = acts.list[ i ];
|
||
|
|
let node = this.lstEntries[info.sort-1];
|
||
|
|
if( !node ) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
node.ainfo = info;
|
||
|
|
node.active = true;
|
||
|
|
nx.gui.setString( node, "txt", nx.text.getKey( info.name ) );
|
||
|
|
|
||
|
|
let tip = nx.gui.getComponent( node, "tip", "nx.vb.visible" );
|
||
|
|
if( tip ) {
|
||
|
|
tip.setTarget( nx.mTip, `acts.${ this.theme.theme_id }.${ info.cate }.${ info.camp_id }` );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
nx.gui.setActive( this.spSlots, "", true );
|
||
|
|
this.spSlots.action( `show${ index }`, false, ( _event ) => {
|
||
|
|
|
||
|
|
// 显示入口
|
||
|
|
if( _event == "done" ) {
|
||
|
|
this.lstEntries.forEach( _entry => {
|
||
|
|
_entry.active = !!_entry.ainfo;
|
||
|
|
} );
|
||
|
|
}
|
||
|
|
|
||
|
|
// 完成
|
||
|
|
if( _event == "complete" ) {
|
||
|
|
this.spSlots.action( `loop${ index }`, true );
|
||
|
|
}
|
||
|
|
} );
|
||
|
|
},
|
||
|
|
|
||
|
|
// -------------------------------------------------------
|
||
|
|
// 入口相关
|
||
|
|
// -------------------------------------------------------
|
||
|
|
|
||
|
|
// 点击入口
|
||
|
|
onTouchEntry: function( _item ) {
|
||
|
|
|
||
|
|
|
||
|
|
let entry = _item ? _item.parent.ainfo : null;
|
||
|
|
if( nx.dt.objEmpty( entry ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
let time = new Date();
|
||
|
|
let showtime = entry.end_time - ( time / 1000 );
|
||
|
|
if( nx.dt.objEmpty( entry ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if( showtime < 0 ){
|
||
|
|
nx.tbox( "StepUpDone" );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
nx.debug( `$ThemeEntry:活动点击!${ entry.name }` );
|
||
|
|
nx.bridge.jumper.jump2Window( entry.source, {
|
||
|
|
theme: this.theme,
|
||
|
|
entry: entry } );
|
||
|
|
this.close();
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|