Files
fc/dev/project/library/imports/71/712ea709-8004-4929-91c5-f6237ca4083d.js
2026-05-24 10:21:26 +08:00

213 lines
6.1 KiB
JavaScript

"use strict";
cc._RF.push(module, '712eacJgARJKZHF9iN8pAg9', 'cmp.partner.select.wnd');
// Scripts/mod/partner/cmps/cmp.partner.select.wnd.js
"use strict";
/******************************************************************
*
* 伙伴选择界面
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var FxSVC = require("nx.fx.sv.expand");
var BackPackConst = require("backpack_const");
cc.Class({
"extends": BridgeWindow,
properties: {
nodRoot: {
"default": null,
type: cc.Node
},
svcList: {
"default": null,
type: FxSVC
},
nodCount: {
"default": null,
type: cc.Node
}
},
// 重载:参数打开
onOpenConfigs: function onOpenConfigs(_params) {
/**
* params {
* partners: 列表,
* count: 选择上限,
* selects: 已选择,
* fnSelector: 选择验证(默认空)
* fixed: 是否固定选择上限数(默认false)
* flag: 特殊标记 }
*/
// 参数判定
this.params = _params.params;
this.cb = _params.cb || [];
// 重建
this.rebuild();
},
// 重载:关闭前
onPreClosed: function onPreClosed() {
this.svcList.rebuild([]);
},
// 重建
rebuild: function rebuild() {
var _this = this;
if (this.params.flag) {
var path = cc.path.join("coms/images", "star" + this.params.flag.star);
var color = BackPackConst.quality_color(this.params.flag.star);
var cur = nx.gui.find(this.nodRoot, "star/type").color;
cur.fromHEX(color);
nx.gui.find(this.nodRoot, "star/type").color = cur;
nx.gui.setSpriteFrame(this.nodRoot, "star/star", path);
nx.gui.setString(this.nodRoot, "star/type", nx.text.getKey(this.params.flag.type));
}
nx.gui.setActive(this.nodRoot, "star", this.params.flag);
// 空
var empty = nx.dt.arrEmpty(this.params.partners);
nx.gui.setActive(this.nodRoot, "empty", empty);
nx.gui.setActive(this.nodRoot, "panel", !empty);
if (empty) {
nx.gui.setString(this.nodRoot, "star/count", 0 + "/" + this.params.count);
nx.gui.setActive(this.nodRoot, "star/count", empty);
return;
}
// 重建
this.svcList.rebuild(this.params.partners);
var num = 0;
// 已选中
var selects = this.params.selects || [];
var _loop = function _loop() {
var partner = _this.params.partners[i];
if (partner && nx.dt.arrMember(selects, null, function (_p) {
return _p.partner_id == partner.partner_id;
})) {
num++;
if (num <= selects.length) {
_this.svcList.addFocus(i);
}
}
};
for (var i = 0; i < this.params.partners.length; ++i) {
_loop();
}
// 数量更新
this.freshCount();
},
// 数量更新
freshCount: function freshCount() {
var key = "";
var total = this.params.count;
if (total > 1) {
var cnt = this.svcList.focusList.length;
key = cnt + "/" + total;
}
nx.gui.setString(this.nodCount, "", key);
nx.gui.setString(this.nodRoot, "star/count", this.svcList.focusList.length + "/" + total);
nx.gui.setActive(this.nodRoot, "star/count", nx.dt.strEmpty(key));
},
// 选中切换
onFocusChanged: function onFocusChanged(_item) {
// 空
if (nx.dt.objEmpty(_item) || nx.dt.objEmpty(_item.mdata)) {
return;
}
// 取消选中
if (this.svcList.isFocus(_item.index)) {
this.svcList.removeFocus(_item.index);
this.freshCount();
return;
}
// 选择验证
if (nx.dt.fnGood(this.params.fnSelector) && !this.params.fnSelector(this, _item.mdata)) {
return;
}
// 是不是单选
var single = this.params.count == 1;
if (single) {
this.svcList.cleanFocus();
this.svcList.addFocus(_item.index);
this.freshCount();
return;
}
// 选中添加
if (this.svcList.focusList.length < this.params.count) {
this.svcList.addFocus(_item.index);
this.freshCount();
return;
}
},
// 点击确认
onTouchConfirm: function onTouchConfirm() {
var _this2 = this;
// 统计所选
var ret = [];
this.svcList.focusList.forEach(function (_idx) {
ret.push(_this2.params.partners[_idx]);
});
// 返回
nx.dt.fnInvoke(this.cb, ret);
}
// // 根据Flag筛选伙伴列表
// fliterPartners: function( _flag ) {
// this.params.partners = [];
// let model = HeroController.getInstance().getModel();
// // 根据Flag确认不同的筛选方式
// // 0:升星标准参数 1:重生单选 2:复活单选
// switch( _flag ) {
// // 2:复活单选
// case 2: {
// let conds = {};
// let config = gconfig( "partner_data", "data_partner_const", "reborn_condition" );
// if( config && config.val ) {
// for( let i in config.val ) {
// let v = config.val[ i ];
// if( conds[ v[ 1 ] ] == null ) {
// conds[ v[ 1 ] ] = {}
// }
// conds[ v[ 1 ] ][ v[ 2 ] ] = true
// }
// }
// let all = model.getHeroList() || []
// for( let k in all ) {
// let partner = all[ k ];
// if( !conds[ partner.bid ] || !conds[ partner.bid ][ partner.star ] ) {
// continue;
// }
// // 非排除英雄
// // if( nx.dt.arrMember( this.excludes, null, ( _m ) => {
// // return _m.partner_id == partner_id;
// // } ) ) {
// // continue;
// // };
// this.params.partners.push( partner );
// }
// } break;
// // 0:升星标准参数
// default: {
// } break;
// };
// // 排序
// let sort_func = Utils.tableLowerSorter( [ "camp_type", "star", "bid" ] )
// this.params.partners.sort( sort_func );
// },
});
cc._RF.pop();