bayuMIR/client/dev/GUILayout/game/FuLiDaTing/ZBHuiShouOBJ.lua

207 lines
7.3 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ZBHuiShouOBJ = Up_BaseClassOBJ:new()
ZBHuiShouOBJ.__cname = "FuLiDaTingOBJ"
ZBHuiShouOBJ.cfg = {}
function ZBHuiShouOBJ:main(parent, data)
self.cfg = data
GUI:LoadExport(parent, "game/FuLiDaTing/ZBHuiShouUI")
self._parent = parent
self.ui = GUI:ui_delegate(parent)
if not self.ui then
return false
end
-- 隐藏导出的 ListView使用 TableView 替代
GUI:setVisible(self.ui.ListView, false)
self.dataList = {}
self:CreateTableView()
---* 绑定事件
self:EventBind()
self:updata()
end
--创建 TableView与导出的 ListView 同位置同尺寸)
function ZBHuiShouOBJ:CreateTableView()
-- ListView 原配置: 父=parent, 位置(-262,-199), 尺寸 528x363, 方向=1(垂直), 间距=4
-- TableView 不支持 itemsMargin把间距叠加到 cellHei 中68 + 4
-- num=7可视区 363/72 ≈ 5加上下缓冲
self.tableView = GUI:TableView_Create(self._parent, "TableView", -262, -199, 528, 363, 1, 528, 72, 7)
GUI:setAnchorPoint(self.tableView, 0.00, 0.00)
GUI:TableView_setTableViewCellsNumHandler(self.tableView, function()
return self.dataList and #self.dataList or 0
end)
GUI:TableView_setCellCreateEvent(self.tableView, function(cellParent, idx)
local realIdx = (tonumber(idx) or 0)
local item = self.dataList[realIdx]
if not item then
return
end
self:buildCell(cellParent, item)
end)
end
--根据 cfg、回收计数、背包中是否拥有该装备构建 dataList
--三档排序:可回收(未达上限 + 背包有,带红点)置顶 → 普通未达档(背包没但还能回收)居中 → 已达上限置底
function ZBHuiShouOBJ:buildDataList()
local cfg = self.cfg or {}
local canGet, normal, done = {}, {}, {}
for i, v in ipairs(cfg) do
local num = hk.getkeycount("GLOBAL(STR_福利回收)", i) or 0
local bag_num = tonumber(SL:Get_ITEM_COUNT(v.name)) or 0
local item = { idx = i, v = v, num = num, bag_num = bag_num }
if num >= (v.num or 0) then
table.insert(done, item)
elseif bag_num > 0 then
table.insert(canGet, item)
else
table.insert(normal, item)
end
end
self.dataList = {}
for _, it in ipairs(canGet) do table.insert(self.dataList, it) end
for _, it in ipairs(normal) do table.insert(self.dataList, it) end
for _, it in ipairs(done) do table.insert(self.dataList, it) end
end
function ZBHuiShouOBJ:updata()
self:buildDataList()
if self.tableView and GUI:Win_IsNotNull(self.tableView) then
GUI:TableView_reloadData(self.tableView)
end
end
--回收计数变化:重新排序并保持滚动位置
function ZBHuiShouOBJ:setsort()
self:buildDataList()
if self.tableView and GUI:Win_IsNotNull(self.tableView) then
GUI:TableView_reloadDataEx(self.tableView)
end
end
--在 TableView cell 父节点内构建一行 UI
function ZBHuiShouOBJ:buildCell(cellParent, item)
-- TableView 是虚拟化加载cellParent 会被复用,必须先清空旧子节点
GUI:removeAllChildren(cellParent)
local i = item.idx
local v = item.v
local num = item.num
local list_bg = GUI:Image_Create(cellParent, "list_bg_", 0, 0, "res/custom/02/14.png")
local item_show = GUI:ItemShow_Create(list_bg, "item_" .. i, 46.00, 36.00, { index = SL:GetMetaValue("ITEM_INDEX_BY_NAME", v.name), count = 1, bgVisible = false, look = true })
GUI:setAnchorPoint(item_show, 0.50, 0.50)
local give_str = {}
for _, gives in ipairs(v.gives) do
table.insert(give_str, string.format("%sx%d", gives[1], gives[2]))
end
local gives_Text = GUI:Text_Create(list_bg, "gives_Text_" .. i, 216, 34, 16, "#00ff00", table.concat(give_str, ", "))
GUI:setAnchorPoint(gives_Text, 0.50, 0.50)
local xiangou_Text = GUI:Text_Create(list_bg, "xiangou_Text_" .. i, 334, 34, 16, "#00ff00", string.format("%d/%d", num, v.num))
GUI:setAnchorPoint(xiangou_Text, 0.50, 0.50)
GUI:Text_enableOutline(xiangou_Text, "#000000", 2)
GUI:Text_setTextColor(xiangou_Text, num >= v.num and "#ff0000" or "#00ff00")
if num >= v.num then
local list_open_img = GUI:Image_Create(list_bg, "list_open_img", 470, 34, "res/custom/Label/3.png")
GUI:setScale(list_open_img, 0.2)
GUI:setAnchorPoint(list_open_img, 0.50, 0.50)
else
local list_btn = GUI:Button_Create(list_bg, "list_btn", 470, 34, "res/custom/02/20.png")
GUI:Button_loadTexturePressed(list_btn, "res/custom/02/21.png")
GUI:setAnchorPoint(list_btn, 0.50, 0.50)
GUI:addOnClickEvent(list_btn, function()
ssrMessage:SubLink(MeiriXianGouOBJ.__cname .. "_recycle", { id = i })
end)
--背包中拥有该装备:回收按钮加红点
if (item.bag_num or 0) > 0 then
RedDotMgr.attachDot(list_btn, { x = 45, y = 28 })
end
end
return list_bg
end
function ZBHuiShouOBJ:EventBind()
local function ZBHuiShouOBJ_Var_Change(data)
if GUI:Win_IsNotNull(self._parent) and self.tableView and GUI:Win_IsNotNull(self.tableView) then
if data.key == "GLOBAL(STR_福利回收)" then
self:setsort()
return
end
end
end
SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname, ZBHuiShouOBJ_Var_Change)
--背包变化也要重排(能回收的装备变多/减少影响红点与三档排序)
SL:RegisterLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, self.__cname, function()
if GUI:Win_IsNotNull(self._parent) and self.tableView and GUI:Win_IsNotNull(self.tableView) then
self:setsort()
end
end)
--关闭窗口
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname .. "mrcz", function(widgetName)
self:OnClose(widgetName)
end)
end
--关闭窗口
function ZBHuiShouOBJ:OnClose(widgetName)
if widgetName == self.__cname then
self:UnRegisterEvent()
end
end
function ZBHuiShouOBJ:UnRegisterEvent()
SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname)
SL:UnRegisterLUAEvent(LUA_EVENT_BAG_ITEM_CHANGE, self.__cname)
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname .. "mrcz")
self.tableView = nil
end
function ZBHuiShouOBJ:OnPageHide()
self:UnRegisterEvent()
end
--注册到全局红点系统:任意装备未达回收上限 → 福利按钮 4 + 顶部福利图标都亮
if RedDotMgr and RedDotMgr.register then
RedDotMgr:register("FuLi_ZBHuiShou", {
owner = "FuLiDaTingOBJ",
parent = "TopIcon_FuLi",
target = function()
return FuLiDaTingOBJ and FuLiDaTingOBJ.ui and FuLiDaTingOBJ.ui.class_btn_4
end,
offset = { x = 105, y = 35 },
watchKeys = { "GLOBAL(STR_福利回收)" },
watchBag = true,
check = function()
local cfg = FuLiDaTingOBJ and FuLiDaTingOBJ.cfg and FuLiDaTingOBJ.cfg[4]
if not cfg then
return false
end
for i, v in ipairs(cfg) do
local num = hk.getkeycount("GLOBAL(STR_福利回收)", i) or 0
local bag_item_num = tonumber(SL:Get_ITEM_COUNT(v.name)) or 0
if num < (v.num or 0) and bag_item_num > 0 then
return true
end
end
return false
end,
})
end
return ZBHuiShouOBJ