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

99 lines
2.3 KiB
JavaScript

/****
* 合成面板
*/
const ItemBase = require("cmp.item.base");
const BridgeWindow = require("bridge.window");
const SliderProgress = require("cmp.slider.prog.selector");
const BackPackController = require("backpack_controller");
cc.Class({
extends: BridgeWindow,
properties: {
cmpItem: {
default: null,
type: ItemBase,
},
cmpCounter: {
default: null,
type: SliderProgress,
},
nodResult: {
default: null,
type: cc.Node,
},
},
// 重载:参数打开
onOpenConfigs: function (_params) {
this.item = _params[0];
this.config = this.item ? this.item.config : null;
this.bagCode = _params[1] || 1;
if (!this.item || !this.config) {
nx.error("[Merge]合成失败,参数无效!");
return;
}
// 重建
this.rebuild();
},
// 重建
rebuild: function () {
// 道具信息
this.cmpItem.setData(this.item);
// 数量范围&&默认
let Bag = BackPackController.getInstance().getModel();
let count = Bag.getPackItemNumByBid(this.bagCode, this.config.id);
let needCount = gdata("partner_data", "data_get_compound_info", this.config.id).num;
let canMergeCount = Math.floor(parseInt(count / needCount));
this.canMerge = count >= needCount ? true : false;
if (!this.canMerge) {
this.cmpCounter.build(0, 0, 0, 0);
} else {
// 设置滚动条
this.cmpCounter.build(1, canMergeCount, canMergeCount, (_count) => {
this.changeCount(_count);
});
}
this.cmpItem.setCount(0);
},
// 数量改变
changeCount: function (_count) {
if (this.cur == _count ||
!nx.dt.numPositive(_count, false)) {
return;
}
this.cur = _count;
},
// 点击合成按钮
onTouchSell: function () {
let BagC = BackPackController.getInstance();
if (!this.canMerge) {
nx.tbox("insufficent amount!");
this.cmpCounter.build(0, 0, 0, 0);
return;
}
BagC.sender11008(this.config.id, this.cur);
BagC.openItemMergePanel(false);
},
});