"use strict"; cc._RF.push(module, 'd71e0d//r5HUpNBNXdz0jt5', 'cmp.bag.gift.choose.more'); // Scripts/mod/backpack/cmps/cmp.bag.gift.choose.more.js "use strict"; /****************************************************************** * * 礼包选择界面(多种类批量选择) * ******************************************************************/ var BridgeWindow = require("bridge.window"); var FxSVC = require("nx.fx.sv.expand"); var BackPackController = require("backpack_controller"); cc.Class({ "extends": BridgeWindow, properties: { svcList: { "default": null, type: FxSVC }, numInput: { "default": null, type: cc.EditBox } }, onLoad: function onLoad() { this.select_num = 1; this.numInput.string = 1; }, setInputNum: function setInputNum(edit) { var 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: function onAddMax() { if (!this.item) return; this.select_num = this.item.quantity; this.numInput.string = this.select_num; }, // 重载:参数打开 onOpenConfigs: function onOpenConfigs(_params) { this.item = _params; // 拆包 var gifts = []; var inside = game.configs.gift_data.data_choose_gift[this.item.base_id]; if (inside) { // 单选多选(暂留) for (var i in inside) { var 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 rebuild(_items) { var _this = this; this.giftList = _items || []; nx.gui.setActive(this.svcList, "empty", nx.dt.arrEmpty(this.giftList)); this.svcList.rebuild(this.giftList); // 设置默认 this.scheduleOnce(function () { _this.svcList.cleanFocus(); _this.svcList.addFocus(0); }, 0.05); }, // 选中切换 onFocusChanged: function onFocusChanged(_item) { // 空 if (nx.dt.objEmpty(_item) || nx.dt.objEmpty(_item.mdata)) { return; } // 聚焦 this.svcList.cleanFocus(); this.svcList.addFocus(_item.index); }, // 点击确认 onTouchConfirm: function onTouchConfirm() { if (!this.select_num || this.select_num == null || this.select_num <= 0) return; var arg = []; this.giftid; var quantity = this.select_num; for (var 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: "" }); var sort_id = -1; sort_id = this.giftList[this.giftid].sort_id; if (sort_id >= 0) { arg.push({ name: 2, value: sort_id, str: "" }); } } } var BagC = BackPackController.getInstance(); BagC.sender10515(this.item.id, quantity, arg); this.close(); } }); cc._RF.pop();