Files
fc/dev/project/library/imports/6e/6ee7c704-0f38-44a0-8cb9-4c5d958364a0.js
2026-05-24 10:21:26 +08:00

143 lines
3.3 KiB
JavaScript

"use strict";
cc._RF.push(module, '6ee7ccEDzhEoIy5TF2Vg2Sg', 'cmp.item.select.wnd');
// Scripts/mod/backpack/cmps/cmp.item.select.wnd.js
"use strict";
/******************************************************************
*
* 道具选择界面
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var FxSVC = require("nx.fx.sv.expand");
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 {
* items: 列表,
* 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;
// 空
var empty = nx.dt.arrEmpty(this.params.items);
nx.gui.setActive(this.nodRoot, "empty", empty);
nx.gui.setActive(this.nodRoot, "panel", !empty);
if (empty) {
return;
}
// 重建
this.svcList.rebuild(this.params.items);
// 已选中
var selects = this.params.selects || [];
var _loop = function _loop() {
var tm = _this.params.items[i];
if (tm && nx.dt.arrMember(selects, null, function (_p) {
return _p.id == tm.id;
})) {
_this.svcList.addFocus(i);
}
};
for (var i = 0; i < this.params.items.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);
},
// 选中切换
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.items[_idx]);
});
// 返回
nx.dt.fnInvoke(this.cb, ret);
}
});
cc._RF.pop();