240 lines
8.6 KiB
Lua
240 lines
8.6 KiB
Lua
LeiChongJiangLiOBJ = Up_BaseClassOBJ:new()
|
||
|
||
LeiChongJiangLiOBJ.__cname = "FuLiDaTingOBJ"
|
||
|
||
LeiChongJiangLiOBJ.cfg = {}
|
||
|
||
function LeiChongJiangLiOBJ:main(parent, data)
|
||
self.cfg = data
|
||
GUI:LoadExport(parent, "game/FuLiDaTing/LeiChongJiangLiUI")
|
||
|
||
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 LeiChongJiangLiOBJ:CreateTableView()
|
||
-- ListView 原配置: 父=c_bg_img, 位置(12,50), 尺寸 524x225, 方向=1(垂直), 间距=6
|
||
-- TableView 不支持 itemsMargin,把间距叠加到 cellHei 中(68 + 6)
|
||
-- num=5:可视区约 3 个 cell,留上下缓冲,复用池设为 5
|
||
self.tableView = GUI:TableView_Create(self.ui.c_bg_img, "TableView", 12, 15, 524, 312, 1, 524, 74, 5)
|
||
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 LeiChongJiangLiOBJ:buildDataList()
|
||
local cfg = self.cfg or {}
|
||
local Vardata = hk.getkeytbl("HUMAN(STR_累充奖励)")
|
||
local totalRecharge = tonumber(SL:Get_MONEY(10) or 0)
|
||
local canGet, normal, done = {}, {}, {}
|
||
for i, v in ipairs(cfg) do
|
||
local open = Vardata and (Vardata[i] or 0) or 0
|
||
local item = { idx = i, open = open, v = v }
|
||
if open > 0 then
|
||
table.insert(done, item)
|
||
elseif totalRecharge >= v.price 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 LeiChongJiangLiOBJ:updata()
|
||
local totalRecharge = tonumber(SL:Get_MONEY(10) or 0)
|
||
GUI:Text_setString(self.ui.Text_Recharge, string.format("累计充值:%d元", totalRecharge))
|
||
|
||
self:buildDataList()
|
||
if self.tableView then
|
||
GUI:TableView_reloadData(self.tableView)
|
||
end
|
||
end
|
||
|
||
--领取状态变化后:刷新 open 状态并把已领取的项移到末尾
|
||
function LeiChongJiangLiOBJ:setsort()
|
||
if not self.dataList then
|
||
return
|
||
end
|
||
local Vardata = hk.getkeytbl("HUMAN(STR_累充奖励)")
|
||
local totalRecharge = tonumber(SL:Get_MONEY(10) or 0)
|
||
-- 同步 open 状态
|
||
for _, item in ipairs(self.dataList) do
|
||
item.open = Vardata and (Vardata[item.idx] or 0) or 0
|
||
end
|
||
-- 三档排序:可领取置顶 → 普通居中 → 已领取置底
|
||
local canGet, normal, done = {}, {}, {}
|
||
for _, item in ipairs(self.dataList) do
|
||
if item.open > 0 then
|
||
table.insert(done, item)
|
||
elseif totalRecharge >= item.v.price 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
|
||
if self.tableView then
|
||
GUI:TableView_reloadDataEx(self.tableView)
|
||
end
|
||
end
|
||
|
||
--在 TableView cell 父节点内构建一行 UI
|
||
function LeiChongJiangLiOBJ:buildCell(cellParent, item)
|
||
-- TableView 是虚拟化加载,cellParent 会被复用,必须先清空旧子节点
|
||
GUI:removeAllChildren(cellParent)
|
||
|
||
local i = item.idx
|
||
local v = item.v
|
||
local open = item.open
|
||
|
||
-- y=3 让 cell 上下各留 3 像素(cellHei=74, 内容高=68)
|
||
local list_bg = GUI:Image_Create(cellParent, "list_bg_", 0, 3, "res/custom/01/7/list.png")
|
||
|
||
-- 档位条件文字
|
||
local list_check_text = GUI:Text_Create(list_bg, "list_check_text", 100, 36, 16, "#00ff00", string.format("累充%d元", v.price))
|
||
GUI:setAnchorPoint(list_check_text, 0.50, 0.50)
|
||
GUI:Text_enableOutline(list_check_text, "#000000", 2)
|
||
|
||
-- 奖励物品展示
|
||
local list_gives_Layout = GUI:Layout_Create(list_bg, "list_gives_Layout", 170, 0, 195, 68, false)
|
||
|
||
for gives_id, give_info in ipairs(v.gives or {}) do
|
||
local list_give_bg = GUI:Image_Create(list_gives_Layout, "list_give_bg_" .. gives_id, 0, 0, "res/custom/02/9.png")
|
||
GUI:Win_SetParam(list_give_bg, gives_id)
|
||
|
||
local list_give_item = GUI:ItemShow_Create(list_give_bg, "list_give_item_" .. gives_id, 29.00, 29.00, { index = SL:GetMetaValue("ITEM_INDEX_BY_NAME", give_info[1]), count = give_info[2], bgVisible = false, look = true })
|
||
GUI:setAnchorPoint(list_give_item, 0.50, 0.50)
|
||
end
|
||
|
||
GUI:UserUILayout(list_gives_Layout, {
|
||
dir = 2,
|
||
addDir = 2,
|
||
interval = 1,
|
||
gap = { x = 1 },
|
||
sortfunc = function(lists)
|
||
table.sort(lists, function(a, b)
|
||
return GUI:Win_GetParam(a) > GUI:Win_GetParam(b)
|
||
end)
|
||
end
|
||
})
|
||
|
||
if open > 0 then
|
||
local list_open_img = GUI:Image_Create(list_bg, "list_open_img", 470, 34, "res/custom/Label/mark_yilingqu1.png")
|
||
GUI:setScale(list_open_img, 0.8)
|
||
GUI:setAnchorPoint(list_open_img, 0.50, 0.50)
|
||
else
|
||
local totalRecharge = tonumber(SL:Get_MONEY(10) or 0)
|
||
local list_btn = GUI:Button_Create(list_bg, "list_btn", 470, 34, totalRecharge >= v.price and "res/custom/01/3/5.png" or "res/custom/01/3/5.png")
|
||
GUI:Button_loadTexturePressed(list_btn, "res/custom/01/3/6.png")
|
||
GUI:setAnchorPoint(list_btn, 0.50, 0.50)
|
||
GUI:setTouchEnabled(list_btn, totalRecharge >= v.price)
|
||
GUI:addOnClickEvent(list_btn, function()
|
||
ssrMessage:SubLink(LeiChongJiangLiOBJ.__cname .. "_lcjl", { id = i })
|
||
end)
|
||
|
||
---* 红点
|
||
if totalRecharge >= v.price then
|
||
RedDotMgr.attachDot(list_btn, { x = 45, y = 28 })
|
||
end
|
||
end
|
||
return list_bg
|
||
end
|
||
|
||
function LeiChongJiangLiOBJ:EventBind()
|
||
-- 监听变量变化:领取状态 → 排序 / 充值金额 → 刷新展示
|
||
local function LeiChongJiangLiOBJ_Var_Change(data)
|
||
if GUI:Win_IsNotNull(self._parent) then
|
||
if data.key == "HUMAN(STR_累充奖励)" then
|
||
self:setsort()
|
||
return
|
||
end
|
||
if data.key == "HUMAN(INT_累计充值金额)" then
|
||
self:updata()
|
||
return
|
||
end
|
||
end
|
||
end
|
||
SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname, LeiChongJiangLiOBJ_Var_Change)
|
||
|
||
--关闭窗口
|
||
SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname .. "lcjl", function(widgetName)
|
||
self:OnClose(widgetName)
|
||
end)
|
||
end
|
||
|
||
--关闭窗口
|
||
function LeiChongJiangLiOBJ:OnClose(widgetName)
|
||
if widgetName == self.__cname then
|
||
self:UnRegisterEvent()
|
||
end
|
||
end
|
||
|
||
function LeiChongJiangLiOBJ:UnRegisterEvent()
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname)
|
||
SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname .. "lcjl")
|
||
end
|
||
|
||
|
||
--注册到全局红点系统:有可领取的累充档位 → 福利按钮 8 + 顶部福利图标都亮
|
||
if RedDotMgr and RedDotMgr.register then
|
||
RedDotMgr:register("FuLi_LeiChongJiangLi", {
|
||
owner = "FuLiDaTingOBJ",
|
||
parent = "TopIcon_FuLi",
|
||
target = function()
|
||
return FuLiDaTingOBJ and FuLiDaTingOBJ.ui and FuLiDaTingOBJ.ui.class_btn_8
|
||
end,
|
||
offset = { x = 105, y = 35 },
|
||
watchKeys = { "HUMAN(INT_累计充值金额)", "HUMAN(STR_累充奖励)" },
|
||
check = function()
|
||
local cfg = FuLiDaTingOBJ and FuLiDaTingOBJ.cfg and FuLiDaTingOBJ.cfg[8]
|
||
if not cfg then
|
||
return false
|
||
end
|
||
local totalRecharge = tonumber(SL:Get_MONEY(10) or 0)
|
||
local Var = hk.getkeytbl("HUMAN(STR_累充奖励)")
|
||
for i, v in ipairs(cfg) do
|
||
if totalRecharge >= v.price and not (Var and Var[i]) then
|
||
return true
|
||
end
|
||
end
|
||
return false
|
||
end,
|
||
})
|
||
end
|
||
|
||
|
||
|
||
return LeiChongJiangLiOBJ
|