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

306 lines
8.7 KiB
JavaScript

/******************************************************************
*
* 派遣选择界面
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const FxTogs = require( "nx.fx.togs" );
const ModLibrary = require( "library.mod" );
cc.Class( {
extends: BridgeWindow,
properties: {
togMain: { default: null, type: FxTogs },
togSub: { default: null, type: FxTogs },
nodPhotos: { default: null, type: cc.Node },
nodDesc: { default: null, type: cc.Node },
nodTasks: { default: null, type: cc.Node },
nodPicture: { default: null, type: cc.Node },
},
// 重载:参数打开
onOpenConfigs: function( _params ) {
this.library = ModLibrary.getInstance();
this.buildTogMain();
// // 参数判定
// if( nx.dt.objEmpty( _params ) ||
// nx.dt.objEmpty( _params.config ) ) {
// nx.error( "派遣选择界面参数为空!" );
// this.scheduleOnce( () => {
// this.close();
// }, 0.01 );
// return;
// }
// this.order = _params;
// this.config = _params.config;
// this.selects = [];
// // 基础刷新
// this.freshBase();
// Tog监听
this.curTog = -1;
this.togMain.posTog = this.onTogMain.bind( this );
this.togSub.posTog = this.onTogSub.bind( this );
nx.lw = this;
},
// 重载:关闭前
onPreClosed: function() {
},
// -------------------------------------------------------------
// 大类相关
// -------------------------------------------------------------
// 大类重建
buildTogMain: function() {
const tags = this.library.tags;
for( let tag in tags ) {
let ifo = tags[ tag ];
let id = parseInt( tag );
let name = nx.text.getKey( ifo.name );
let node = this.togMain.togs[ id - 1 ];
node.idTag = id;
nx.gui.setString( node, "on/txt", name );
nx.gui.setString( node, "off/txt", name );
let tip = nx.gui.getComponent( node, "off/tip", "nx.vb.visible" );
tip.setTarget( nx.mTip, `home.library.tag${ tag }`, );
}
// 默认
this.togMain.togTo( 0 );
this.onTogMain( 0 );
},
// 大类切换
onTogMain: function( _index ) {
let idx = parseInt( _index ) || 0;
nx.debug( `大类切换:${ this.curTog } -> ${ idx }` );
let tag = this.togMain.togs[ idx ].idTag;
let info = this.library.tags[ tag ];
if( !info ) {
return;
}
// 小类重建
this.buildTogSub( tag, info.subs );
},
// -------------------------------------------------------------
// 小类相关
// -------------------------------------------------------------
// 小类重建
buildTogSub: function( _tag, _subs ) {
if( nx.dt.arrEmpty( _subs ) ) {
this.togSub.node.active = false;
return;
}
this.togSub.node.active = true;
for( let i = 0; i < this.togSub.togs.length; ++i ) {
let tog = this.togSub.togs[ i ];
let sub = _subs[ i ];
if( !sub ) {
tog.active = false;
continue;
}
tog.active = true;
tog.idTag = sub.id;
let name = nx.text.getKey( sub.name );
nx.gui.setString( tog, "on/txt", name );
nx.gui.setString( tog, "off/txt", name );
let tip = nx.gui.getComponent( tog, "off/tip", "nx.vb.visible" );
tip.setTarget( nx.mTip, `home.library.tag${ _tag }.${ sub.id }`, );
}
// 默认
this.togSub.togTo( 0 );
this.onTogSub( 0 );
},
// 小类切换
onTogSub: function( _index ) {
let idx = parseInt( _index ) || 0;
nx.debug( `小类切换:${ idx }` );
// 更新页面
let gid = this.togSub.togs[ idx ].idTag;
this.showGroup( gid );
},
// -------------------------------------------------------------
// 页面展示
// -------------------------------------------------------------
// 显示指定组别
showGroup: function( _gid ) {
let gp = this.library.groups[ _gid ];
if( !gp ) {
nx.error( `无效组别:${ _gid }` );
return;
}
// 收集页
if( nx.dt.arrNEmpty( gp.partners ) ) {
this.showTaskPage( gp );
return;
}
// 描述页
if( nx.dt.arrNEmpty( gp.content ) ) {
this.showDescPage( gp );
return;
}
nx.error( `未处理组别:${ _gid }` );
},
// 展示收集页
showTaskPage: function( _infos ) {
this.nodDesc.active = false;
this.nodPicture.active = false;
this.nodPhotos.active = true;
this.nodTasks.active = true;
// 排序
let partners = _infos.partners;
partners.sort( ( a, b ) => {
if( a.statu == b.statu ) { return -1; };
if( a.statu == 1 ) { return -1; }
if( b.statu == 1 ) { return 1; }
if( a.statu == 0 ) { return -1; }
if( b.statu == 0 ) { return 1; }
return -1;
} );
// 照片墙
let chds = this.nodPhotos.children;
nx.gui.gocChildren( this.nodPhotos, "", partners.length, chds[ 0 ] );
for( let i = 0; i < partners.length; ++i ) {
let pt = partners[ i ];
let node = chds[ i ];
let path = cc.path.join( "prefab/home/library/photos", pt.photo_name );
let mat = cc.Material.getBuiltinMaterial( ( pt.statu == 0 ) ? '2d-gray-sprite' : '2d-sprite' );
let sp = nx.gui.setSpriteFrame( node, "", path );
if( sp ) {
sp.setMaterial( 0, mat );
}
node.x = pt.pos[ 0 ];
node.y = pt.pos[ 1 ];
node.partner = pt;
nx.tween.fadeIn( node, "", 0.1 );
}
// 总奖励
let header = nx.gui.getComponent( this.nodTasks, "head", "cmp.library.task.header" );
if( header ) {
header.rebuild( _infos );
}
// 子奖励
let lst = nx.gui.find( this.nodTasks, "task/view/content" );
nx.gui.gocChildren( lst, "", partners.length, lst.children[ 0 ] );
for( let i = 0; i < partners.length; ++i ) {
let pt = partners[ i ];
let node = lst.children[ i ];
let item = nx.gui.getComponent( node, "", "cmp.library.task.item" );
item.rebuild( pt, _infos );
}
},
// 展示描述页
showDescPage: function( _infos ) {
this.nodPhotos.active = false;
this.nodTasks.active = false;
this.nodDesc.active = true;
this.nodPicture.active = true;
// 内容
let node = nx.gui.find( this.nodDesc, "view/content" );
let chds = node.children;
nx.gui.gocChildren( node, "", _infos.content.length, chds[ 0 ] );
for( let i = 0; i < _infos.content.length; ++i ) {
let item = chds[ i ];
let txt = nx.text.getKey( _infos.content[ i ] );
let arr = txt.split( "#" );
nx.gui.setString( item, "head/txt", arr[ 0 ] );
nx.gui.setString( item, "desc", arr[ 1 ] );
nx.tween.fadeIn( item, "", 0.1 );
}
let layout = nx.gui.getComponent( node, "", cc.Layout );
if( layout ) {
layout.updateLayout();
}
let scv = nx.gui.getComponent( this.nodDesc, "", cc.ScrollView );
if( scv ) {
scv.scrollToTop( 0 );
}
// 图片
let path = cc.path.join( "prefab/home/library/photos", _infos.photo );
nx.gui.setSpriteFrame( this.nodPicture, "img", path );
},
// 点击照片
onTouchPhoto: function( _node ) {
let partner = _node ? _node.parent.partner : null;
if( !partner ) {
return;
}
let self = this;
let fresh = function() {
let lst = nx.gui.find( self.nodTasks, "task/view/content" );
for( let i = 0; i < lst.children.length; ++i ) {
let node = lst.children[ i ];
let cmp = nx.gui.getComponent( node, "", "cmp.library.task.item" );
if( cmp && partner ) {
cmp.updateState( cmp.partner.statu );
}
}
}
nx.bridge.createPanel( "WndLibraryPartner", {
bid: partner.id,
auto: false,
cbClose: () => {
fresh();
}
} );
},
} );