150 lines
3.6 KiB
JavaScript
150 lines
3.6 KiB
JavaScript
/******************************************************************
|
|
*
|
|
* 家园主题列表
|
|
*
|
|
******************************************************************/
|
|
|
|
const BridgeComponent = require( "bridge.component" );
|
|
const HomeMod = require( "home.mod" );
|
|
|
|
// 临时状态
|
|
const TmState = cc.Enum( {
|
|
Locked: 0, // 未解锁
|
|
Have: 1, // 已获得
|
|
Use: 2, // 已摆放
|
|
} );
|
|
|
|
cc.Class( {
|
|
|
|
extends: BridgeComponent,
|
|
|
|
properties: {
|
|
|
|
lstTheme: { default: null, type: cc.Node },
|
|
},
|
|
|
|
// 显示
|
|
onEnable: function() {
|
|
|
|
// 保存当前主题
|
|
this.look_id = nx.bridge.vget( "HomeTheme" );
|
|
|
|
// 列表重建
|
|
if( nx.dt.arrEmpty( this.themes ) ) {
|
|
|
|
this.themes = [];
|
|
const DATA = game.configs.homeland_data.data_theme_data;
|
|
for( let id in DATA ) {
|
|
let tm = nx.dt.objClone( DATA[id] );
|
|
tm.state = TmState.Locked;
|
|
this.themes.push( tm );
|
|
}
|
|
|
|
const chds = this.lstTheme.children;
|
|
nx.gui.gocChildren( this.lstTheme, "", this.themes.length, chds[0] );
|
|
|
|
}
|
|
|
|
// 视图绑定
|
|
nx.bridge.vbind( this, [
|
|
[ "HomeTheme", this.onHomeThemeChanged.bind( this ) ],
|
|
] );
|
|
|
|
},
|
|
|
|
// 关闭
|
|
onDisable: function() {
|
|
|
|
// 视图监听解除
|
|
nx.bridge.vunbind( this );
|
|
|
|
},
|
|
|
|
// 加载场景
|
|
onHomeThemeChanged: function( _id, _old, _init ) {
|
|
|
|
// 更新列表
|
|
this.updateList( _init );
|
|
},
|
|
|
|
// 更新列表
|
|
updateList: function( _sort ) {
|
|
|
|
// 状态更新
|
|
let curId = nx.bridge.vget( "HomeTheme" );
|
|
let haves = nx.bridge.vget( "HomeThemeList" );
|
|
for( let i = 0; i < this.themes.length; ++i ) {
|
|
|
|
let tm = this.themes[i];
|
|
if( tm.theme_id == curId ) {
|
|
tm.state = TmState.Use;
|
|
}
|
|
else if( nx.dt.arrMember( haves, null, ( _m ) => {
|
|
return _m && ( _m.look_id == tm.theme_id );
|
|
} ) ) {
|
|
tm.state = TmState.Have;
|
|
}
|
|
else {
|
|
tm.state = TmState.Locked;
|
|
}
|
|
this.themes[i] = tm;
|
|
}
|
|
|
|
// 状态排序
|
|
if( _sort ) {
|
|
this.themes.sort( ( _a, _b ) => {
|
|
return _b.state - _a.state;
|
|
} );
|
|
}
|
|
|
|
let chds = this.lstTheme.children;
|
|
for( let i = 0; i < this.themes.length; ++i ) {
|
|
let item = nx.gui.getComponent( chds[i], "", "cmp.home.theme.item" );
|
|
if( item ) {
|
|
item.setData( this.themes[i] );
|
|
}
|
|
}
|
|
|
|
},
|
|
|
|
// 主题保存
|
|
onTouchSave: function() {
|
|
|
|
let mod = HomeMod.getInstance();
|
|
|
|
// 没有改变
|
|
let id = nx.bridge.vget( "HomeTheme" );
|
|
if( this.look_id == id ) {
|
|
mod.togHomeEdit();
|
|
return;
|
|
}
|
|
|
|
// 保存提示
|
|
nx.mbox( "HomeThemeSaveAsk", ['cancel', 'confirm'], ( _key, _box ) => {
|
|
_box.close();
|
|
if( _key == 'confirm' ) {
|
|
mod.reqChangeTheme( id, ( _ret, _data ) => {
|
|
if( !_ret ) {
|
|
nx.tbox( _data );
|
|
return;
|
|
}
|
|
mod.togHomeEdit();
|
|
} );
|
|
}
|
|
} );
|
|
},
|
|
|
|
// 撤销返回
|
|
onTouchCancel: function() {
|
|
|
|
// 主题还原
|
|
let id = nx.bridge.vget( "HomeTheme" );
|
|
if( this.look_id > 0 && id != this.look_id ) {
|
|
nx.bridge.vset( "HomeTheme", this.look_id );
|
|
}
|
|
|
|
HomeMod.getInstance().togHomeEdit();
|
|
},
|
|
|
|
} );
|