Files

304 lines
7.2 KiB
JavaScript
Raw Permalink Normal View History

2026-05-24 10:21:26 +08:00
"use strict";
cc._RF.push(module, '2bfa3Sr+nZLLpd5wnuFDy3N', 'cmp.bag.wnd');
// Scripts/mod/backpack/cmps/cmp.bag.wnd.js
"use strict";
/******************************************************************
*
* 背包
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var FxTogs = require("nx.fx.togs");
var FxSVC = require("nx.fx.sv.expand");
var ItemDesc = require("cmp.item.detail");
var BackPackConst = require("backpack_const");
var BackPackController = require("backpack_controller");
var BBC = BackPackConst.Bag_Code;
var BTT = BackPackConst.item_sub_type;
// 排序类型
var SortType = cc.Enum({
Quality: 0,
// 品质
Type: 1,
// 类型
Power: 2 // 战力
});
// 标签页对应关系
var TabPage = [{
key: "EQUIPS",
tab: BTT.EQUIPS,
"goto": 1
}, {
key: "PROPS",
tab: BTT.PROPS,
"goto": 0
}, {
key: "HERO",
tab: BTT.HERO,
"goto": 2
}, {
key: "SPECIAL",
tab: BTT.SPECIAL,
"goto": 3
}, {
key: "HOLYEQUIPMENT",
tab: BTT.HOLYEQUIPMENT,
"goto": 4
}, {
key: "ELFIN",
tab: BTT.ELFIN,
"goto": 5
}];
// 各类型排序支持
var BagTypeSorts = [[0],
// 其他
[0, 1, 2],
// 装备
[0, 1],
// 道具
[0],
// 英雄碎片
[0],
// 特殊
[0, 1],
// 神装
[0] // 精灵
];
cc.Class({
"extends": BridgeWindow,
properties: {
togMenu: {
"default": null,
type: FxTogs
},
svcList: {
"default": null,
type: FxSVC
},
itemDesc: {
"default": null,
type: ItemDesc,
displayName: "道具详情"
},
nodFliter: {
"default": null,
type: cc.Node
},
nodBagNum: {
"default": null,
type: cc.Node
}
},
onLoad: function onLoad() {
// 事件监听
this.bindGEvent(EventId.ADD_GOODS, this.onUpdateGoods.bind(this));
this.bindGEvent(EventId.DELETE_GOODS, this.onUpdateGoods.bind(this));
this.bindGEvent(EventId.MODIFY_GOODS_NUM, this.onUpdateGoods.bind(this));
// 排序关闭
nx.gui.setActive(this.nodFliter, "popup", false);
// Tog监听
this.togMenu.posTog = this.onTogMenu.bind(this);
nx.gui.setActive(this.nodBagNum, "");
},
// 重载:参数打开
onOpenConfigs: function onOpenConfigs(_params) {
var _this = this;
if (_params.fromOther) {
var from = _params.fromOther;
var tab = from;
var _goto = 0;
var tabs = 0;
TabPage.forEach(function (_tab) {
if (tab == _tab.tab) {
_goto = _tab["goto"];
tabs = _tab.tab;
}
});
this.togMenu.togTo(_goto);
this.activeMenu(tabs);
} else {
this.togMenu.togTo(0);
this.scheduleOnce(function () {
_this.activeMenu(BTT.PROPS);
}, 0.01);
}
},
onDestroy: function onDestroy() {},
// 重载:关闭前
onPreClosed: function onPreClosed() {
this.svcList.rebuild([]);
},
// 更新
onUpdateGoods: function onUpdateGoods(_bagCode, _itemList) {
// 不处理: 参数无效
if (_bagCode != BBC.BACKPACK && _bagCode != BBC.EQUIPS) {
return;
}
// 不处理: 列表为空
if (nx.dt.objEmpty(_itemList)) {
return;
}
// 不处理: 非装备类型显示
if ((this.curType == BTT.EQUIPS || this.curType == BTT.HOLYEQUIPMENT) && _bagCode != BBC.EQUIPS) {
return;
}
// 不处理: 非装备类型显示
if (this.curType != BTT.EQUIPS && this.curType != BTT.HOLYEQUIPMENT && _bagCode == BBC.EQUIPS) {
return;
}
// 当前页有改变
var upd = false;
for (var k in _itemList) {
var tm = _itemList[k];
if (tm && tm.sub_type == this.curType) {
upd = true;
break;
}
}
// 强刷
if (upd) {
this.freshItemList();
}
},
// 背包更新
freshItemList: function freshItemList() {
var _this2 = this;
var model = BackPackController.getInstance().getModel();
var list = model.getAllBackPackArray(this.curType);
var focus = !nx.dt.arrEmpty(this.svcList.focusList) ? this.svcList.focusList[0] : 0;
var cnt1 = Object.keys(model.item_list[1] || {}).length;
var cnt2 = Object.keys(model.item_list[3] || {}).length;
var dataNum = cnt1 + cnt2;
nx.gui.setString(this.nodBagNum, "num", dataNum + "");
if (nx.dt.arrEmpty(list)) {
this.svcList.rebuild([]);
this.svcList.cleanFocus();
this.itemDesc.setData();
return;
}
// 排序
switch (this.curST) {
case SortType.Type:
{
var compare = Utils.tableUpperSorter(["sub_type", "type", "base_id"]);
list.sort(compare);
}
break;
case SortType.Power:
{
var _compare = Utils.tableUpperSorter(["all_score", "base_id"]);
list.sort(_compare);
}
break;
default:
{}
break;
}
this.svcList.rebuild(list);
var show = list[0];
var showIdx = 0;
if (this.curType == BTT.HOLYEQUIPMENT) {
showIdx = nx.dt.objEmpty(list[focus]) ? 0 : focus;
show = nx.dt.objEmpty(list[focus]) ? list[0] : list[focus];
}
// 设置默认
this.scheduleOnce(function () {
_this2.svcList.cleanFocus();
_this2.svcList.addFocus(showIdx);
_this2.itemDesc.setData(show, "bag");
}, 0.1);
},
// 激活菜单
activeMenu: function activeMenu(_bagCode) {
if (this.curType == _bagCode) {
return;
}
this.curType = _bagCode;
var scv = nx.gui.getComponent(this.svcList.bindSCV, "", cc.ScrollView);
if (scv) {
scv.scrollToTop(0.001);
}
this.changeSort(SortType.Quality, true);
},
// 背包切换
onTogMenu: function onTogMenu(_index) {
var tab = 0;
TabPage.forEach(function (_tab) {
if (_index == _tab["goto"]) {
tab = _tab.tab;
}
});
this.activeMenu(tab);
},
// 选中切换
onFocusChanged: function onFocusChanged(_item) {
// 空
if (nx.dt.objEmpty(_item) || nx.dt.objEmpty(_item.mdata)) {
return;
}
// 聚焦
this.svcList.cleanFocus();
this.svcList.addFocus(_item.index);
this.itemDesc.setData(_item.mdata, "bag");
nx.audio.playSFX("audios/effects/touchitem");
// 介绍
if (this.nodInfos) {
this.nodInfos.setItem(_item.mdata);
}
},
// 打开排序列表
onOpenSortList: function onOpenSortList() {
// 排序选项
var ts = BagTypeSorts[this.curType];
if (nx.dt.arrEmpty(ts) || ts.length <= 1) {
return;
}
for (var i = 0; i < 3; ++i) {
var node = nx.gui.find(this.nodFliter, "popup/list/t" + i);
node.active = nx.dt.arrMember(ts, i);
}
nx.gui.setActive(this.nodFliter, "popup", true);
},
// 关闭排序列表
onCloseSortList: function onCloseSortList() {
nx.gui.setActive(this.nodFliter, "popup", false);
},
// 选择排序方式
onSelectSortType: function onSelectSortType(_st) {
nx.debug("SORT:" + _st);
nx.gui.setActive(this.nodFliter, "popup", false);
this.changeSort(parseInt(_st) || SortType.Quality);
},
// 更改排序方式
changeSort: function changeSort(_type, _force) {
if (_force === void 0) {
_force = false;
}
if (!_force && this.curST == _type) {
return;
}
this.curST = _type;
nx.gui.setString(this.nodFliter, "cur/txt", nx.text.getKey("SortName" + _type));
this.freshItemList();
}
});
cc._RF.pop();