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

365 lines
9.7 KiB
JavaScript

/******************************************************************
*
* 秘书组
*
******************************************************************/
const BridgeWindow = require( "bridge.window" );
const FxTogs = require( "nx.fx.togs" );
const FxSVC = require( "nx.fx.sv.expand" );
const Clerk = require( "partner.clerk.mod" );
const TipsController = require( "tips_controller" );
const RoleController = require( "role_controller" );
const HeroConst = require( "hero_const" );
const HeroControl = require( "hero_controller" );
const HCT = HeroConst.CampType;
cc.Class( {
extends: BridgeWindow,
properties: {
pageGroup: { default: null, type: cc.Node },
pageSelect: { default: null, type: cc.Node },
togCamp: { default: null, type: FxTogs },
svcList: { default: null, type: FxSVC },
nodCount: { default: null, type: cc.Node },
},
// 加载
onLoad: function() {
this.skins = {};
this.selects = [];
// 视图监听
this.vbind( [
[ "clerkList", this.onFreshGroup.bind( this ) ]
] );
// 获取秘书组信息
Clerk.getInstance().reqFetch();
// 切换秘书页
this.showGroupPage();
},
// 销毁
onDestroy: function() {
// 视图监听释放
this.vunbind();
},
// ============================================================
// 秘书页
// ============================================================
// 切换秘书页
showGroupPage: function() {
this.pageGroup.active = true;
this.pageSelect.active = false;
},
// 重置
onFreshGroup: function( _clerks, _old, _init ) {
if( _init ) {
return;
}
const conds = game.configs.secretary_data.data_secretary_info;
const role = RoleController.getInstance().getRoleVo();
// 单设
let count = 0, max = 0;
let reset = function( _node, _data, _rank ) {
// 未解锁
let rank = _rank || 1;
let limit = conds[ rank ] || 0;
let locked = ( role.lev < limit );
if( locked ) {
nx.gui.setActive( _node, "empty", false );
nx.gui.setActive( _node, "normal", false );
nx.gui.setActive( _node, "locked", true );
nx.gui.setString( _node, "locked/txt", nx.text.format( "UnLockedLevel", limit ) );
return;
}
// 解锁数量
++max;
// 空缺
if( nx.dt.objEmpty( _data ) ) {
nx.gui.setActive( _node, "empty", true );
nx.gui.setActive( _node, "normal", false );
nx.gui.setActive( _node, "locked", false );
return;
}
// 秘书验证
let args = _data.resource_id.split( "_" );
let key = args[ 0 ] + "_" + args[ 1 ];
let clerk = gdata( "partner_data", "data_partner_star", key );
if( !clerk ) {
nx.error( "秘书无效!", _data.resource_id );
nx.gui.setActive( _node, "empty", true );
nx.gui.setActive( _node, "normal", false );
nx.gui.setActive( _node, "locked", false );
return;
}
++count;
// 有角色
nx.gui.setActive( _node, "empty", false );
nx.gui.setActive( _node, "locked", false );
let node = nx.gui.setActive( _node, "normal", true );
let cfgs = game.configs.partner_data.data_partner_base[ clerk.bid ];
// 阵营标记
let camp = cfgs ? cfgs.camp_type : HCT.eWater;
let path = cc.path.join( "coms/images", "camps" + camp );
nx.gui.setSpriteFrame( node, "head/camp", path );
// 阵营背景
path = cc.path.join( "coms/camps", "bg" + camp );
nx.gui.setSpriteFrame( node, "bg", path );
// 阵营边框
path = cc.path.join( "coms/camps", "frame" + camp );
nx.gui.setSpriteFrame( node, "frame", path );
// 角色
let info = nx.bridge.partner.parseShowInfo( ...args );
nx.gui.setSpriteFrame( node, "mask/img", info.img_half_nor, ( _ret ) => {
if( !_ret ) {
nx.gui.setSpriteFrame( node, "mask/img", "resDB/empty/half_show2" );
}
} );
};
// 遍历填充
let chds = this.pageGroup.children;
for( let i = 0; i < chds.length; ++i ) {
reset( chds[ i ], _clerks ? _clerks[ i ] : null, i + 1 );
}
this.cntSelect = count;
this.maxSelect = max;
},
// 批量重选
reselectOnce: function() {
this.showSelectPage();
},
// 点击更换
onTouchChange: function( _rank ) {
this.reselectOnce();
},
// 点击添加
onTouchAdd: function( _rank ) {
this.reselectOnce();
},
// 点击帮助
onTouchHelp: function() {
const txt = game.configs.secretary_data.data_secretary_const.secretary_rule.des;
if( nx.dt.strNEmpty( txt ) ) {
const TC = TipsController.getInstance();
TC.showTextPanel( "tip", txt );
}
},
// ============================================================
// 选择页
// ============================================================
// 切换选择页
showSelectPage: function() {
this.pageGroup.active = false;
this.pageSelect.active = true;
// 初始选择
this.selects = [];
let arr = nx.bridge.vget( "clerkList" ) || [];
arr.forEach( _t => {
this.selects.push( _t.resource_id );
} );
// 初始化
if( !nx.dt.fnGood( this.togCamp.posTog ) ) {
this.togCamp.posTog = this.onTogCamp.bind( this );
this.togCamp.togTo( 0 );
this.scheduleOnce( () => {
this.onTogCamp( HCT.eNone );
}, 0.01 );
}
},
// 整体刷新
freshClerks: function() {
// 获取当前秘书列表
let clerks = this.skins[ this.curCamp ];
if( !clerks ) {
// 筛选当前阵营所有不同的皮肤资源
clerks = [];
let records = {};
let HC = HeroControl.getInstance();
let partners = HC.getModel().getHeroListByCamp( this.curCamp );
partners.sort( ( _a, _b ) => {
return _a.star - _b.star;
} );
for( let i in partners ) {
let pt = partners[ i ];
if( !pt ) {
continue;
}
let key = pt.bid + "_" + pt.star + "_" + pt.use_skin;
let cfg = nx.bridge.partner.getShowInfo( pt );
if( !cfg || records[ cfg.resid ] ) {
continue;
}
records[ cfg.resid ] = cfg;
clerks.push( { key: key, partner: pt, cfg: cfg } );
}
this.skins[ this.curCamp ] = clerks;
}
// 排序
clerks.sort( ( _a, _b ) => {
let ain = nx.dt.arrMember( this.selects, _a.key );
let bin = nx.dt.arrMember( this.selects, _b.key );
if( ain != bin ) {
return ain ? -1 : 1;
}
if( _a.cfg.star != _b.cfg.star ) {
return _a.cfg.bid - _b.cfg.bid;
}
return _b.cfg.star - _a.cfg.star;
} );
// 列表重置
nx.gui.setActive( this.svcList, "empty", nx.dt.arrEmpty( clerks ) );
this.svcList.rebuild( clerks );
// 当前选中统计
for( let k in clerks ) {
let ck = clerks[ k ];
if( nx.dt.arrMember( this.selects, ck.key ) ) {
this.svcList.addFocus( k );
}
}
// 刷新选择数量
this.freshCount();
},
// 刷新选择数量
freshCount: function() {
let txt = this.selects.length + "/" + this.maxSelect;
nx.gui.setString( this.nodCount, "txt", txt );
},
// 点击取消
onTouchCancel: function() {
this.showGroupPage();
},
// 点击确认
onTouchConfirm: function() {
let args = [];
for( let i = 0; i < this.selects.length; ++i ) {
args.push( { resource_id: this.selects[i] } );
}
nx.bridge.clerks.reqModify( args, () => {
this.showGroupPage();
} );
},
// 阵营切换
onTogCamp: function( _index ) {
let idx = parseInt( _index ) || 0;
if( this.curCamp == idx ) {
return;
}
nx.debug( `[Hero]阵营切换:${ this.curCamp } -> ${ idx }` );
this.curCamp = idx;
// 整体刷新
this.freshClerks();
},
// 选中切换
onFocusChanged: function( _item ) {
// 空
if( nx.dt.objEmpty( _item ) ||
nx.dt.objEmpty( _item.mdata ) ) {
return;
}
// 取消聚焦
if( this.svcList.isFocus( _item.index ) ) {
this.svcList.removeFocus( _item.index );
nx.dt.arrDelete( this.selects, ( _t ) => {
return _item.mdata.key == _t;
} );
this.freshCount();
return;
}
// 超限
if( this.selects.length >= this.maxSelect ) {
return;
}
// 聚焦
this.svcList.addFocus( _item.index );
this.selects.push( _item.mdata.key );
this.freshCount();
},
close: function() {
this._super();
nx.bridge.createPanel( "WndPersonal" );
},
} );