/****************************************************************** * * 礼包选择界面(多种类批量选择) * ******************************************************************/ const BridgeWindow = require("bridge.window"); const FxSVC = require("nx.fx.sv.expand"); const BackPackController = require("backpack_controller"); cc.Class({ extends: BridgeWindow, properties: { svcList: { default: null, type: FxSVC, }, numInput:{ default:null, type:cc.EditBox } }, onLoad(){ this.select_num = 1; this.numInput.string = 1; }, setInputNum(edit){ let num = Number(edit.string); this.select_num = 0; if(typeof num != "number"){ return nx.tbox("InputNoNumTip"); } if(num <= 0){ return nx.tbox("InputNumPosive"); } this.select_num = num; //最大數量鎖定 if(this.item.quantity < this.select_num){ this.select_num = this.item.quantity; } }, //直接添加最大數量 onAddMax(){ if(!this.item)return; this.select_num = this.item.quantity; this.numInput.string = this.select_num; }, // 重载:参数打开 onOpenConfigs: function (_params) { this.item = _params; // 拆包 let gifts = []; let inside = game.configs.gift_data.data_choose_gift[this.item.base_id]; if (inside) { // 单选多选(暂留) for (let i in inside) { let t = inside[i]; if (t && nx.dt.numPositive(t.bid, false)) { gifts.push({ id: t.bid, num: t.num, sort_id: t.sort_id }); } } } // 重建 gifts.sort(Utils.tableLowerSorter(["sort_id"])); this.rebuild(gifts); }, // 重建 rebuild: function (_items) { this.giftList = _items || []; nx.gui.setActive(this.svcList, "empty", nx.dt.arrEmpty(this.giftList)); this.svcList.rebuild(this.giftList); // 设置默认 this.scheduleOnce(() => { this.svcList.cleanFocus(); this.svcList.addFocus(0); }, 0.05); }, // 选中切换 onFocusChanged: function (_item) { // 空 if (nx.dt.objEmpty(_item) || nx.dt.objEmpty(_item.mdata)) { return; } // 聚焦 this.svcList.cleanFocus(); this.svcList.addFocus(_item.index); }, // 点击确认 onTouchConfirm: function () { if(!this.select_num || this.select_num == null || this.select_num <= 0)return; let arg = []; this.giftid; let quantity = this.select_num; for (let index = 0; index < this.giftList.length; index++) { //获取当前选中的礼包id if (this.svcList.isFocus(index)) { this.giftid = index; arg.push({ name: 1, value: this.giftList[this.giftid].id, str: "" }); let sort_id = -1; sort_id = this.giftList[this.giftid].sort_id; if (sort_id >= 0) { arg.push({ name: 2, value: sort_id, str: "" }) } } } let BagC = BackPackController.getInstance(); BagC.sender10515(this.item.id, quantity, arg); this.close(); }, });