125 lines
2.7 KiB
JavaScript
125 lines
2.7 KiB
JavaScript
|
|
/******************************************************************
|
||
|
|
*
|
||
|
|
* 更换桌面
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
const BridgeWindow = require( "bridge.window" );
|
||
|
|
const FxSVC = require( "nx.fx.sv.expand" );
|
||
|
|
const RC = require( "role_controller" );
|
||
|
|
const FxButton = require( "nx.fx.button" );
|
||
|
|
|
||
|
|
cc.Class( {
|
||
|
|
|
||
|
|
extends: BridgeWindow,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
|
||
|
|
nodBG: { default: null, type: cc.Node },
|
||
|
|
lstMenu: { default: null, type: FxSVC },
|
||
|
|
nodSwap: { default: null, type: FxButton },
|
||
|
|
},
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
// 展示
|
||
|
|
onEnable: function() {
|
||
|
|
|
||
|
|
nx.bridge.closePanel( "WndPersonal" );
|
||
|
|
RC.getInstance().reqThemeData( ( _ret, _data ) => {
|
||
|
|
|
||
|
|
if( !_ret ) {
|
||
|
|
nx.tbox( _data );
|
||
|
|
this.delayClose();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.build( _data );
|
||
|
|
|
||
|
|
} );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 构建
|
||
|
|
build: function( _data ) {
|
||
|
|
|
||
|
|
this.used = _data.id;
|
||
|
|
|
||
|
|
// 统计菜单项
|
||
|
|
this.menus = _data.list;
|
||
|
|
this.lstMenu.rebuild( this.menus );
|
||
|
|
|
||
|
|
// 寻找当前
|
||
|
|
this.cur = 0;
|
||
|
|
for( let i = 0; i < this.menus.length; ++i ) {
|
||
|
|
let item = this.menus[i];
|
||
|
|
if( item.id == _data.id ) {
|
||
|
|
this.cur = i;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
this.freshUsed();
|
||
|
|
|
||
|
|
// 默认1
|
||
|
|
this.scheduleOnce( () => {
|
||
|
|
this.onSelectMenu( { index: this.cur, mdata: this.menus[ this.cur ] } );
|
||
|
|
}, 0.1 );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 刷新当前使用
|
||
|
|
freshUsed: function() {
|
||
|
|
|
||
|
|
let chds = this.lstMenu.bindSCV.content.children;
|
||
|
|
for( let i in chds ) {
|
||
|
|
let item = chds[i].svItem;
|
||
|
|
if( item ){
|
||
|
|
item.setUsed( this.used == item.mdata.id );
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 菜单切换
|
||
|
|
onSelectMenu: function( _item ) {
|
||
|
|
|
||
|
|
// 聚焦
|
||
|
|
this.lstMenu.cleanFocus();
|
||
|
|
this.lstMenu.addFocus( _item.index );
|
||
|
|
|
||
|
|
// 设置
|
||
|
|
let path = cc.path.join( "resDB/desktop", "" + _item.mdata.id );
|
||
|
|
nx.gui.setSpriteFrame( this.nodBG, "", path );
|
||
|
|
|
||
|
|
// 刷新按钮
|
||
|
|
this.nodSwap.node.active = ( this.used != _item.mdata.id );
|
||
|
|
|
||
|
|
this.cur = _item.mdata.id;
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击更换
|
||
|
|
onTouchSwap: function() {
|
||
|
|
|
||
|
|
RC.getInstance().reqSwapTheme( this.cur, ( _ret, _data ) => {
|
||
|
|
|
||
|
|
if( !_ret ) {
|
||
|
|
nx.tbox( _data );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
this.used = this.cur;
|
||
|
|
this.nodSwap.node.active = false;
|
||
|
|
this.freshUsed();
|
||
|
|
nx.tbox( "DesktopChanged" );
|
||
|
|
|
||
|
|
} );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
close: function(){
|
||
|
|
this._super();
|
||
|
|
nx.bridge.createPanel( "WndPersonal" );
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|