ChengZhangJiJinOBJ = Up_BaseClassOBJ:new() ChengZhangJiJinOBJ.__cname = "FuLiDaTingOBJ" ChengZhangJiJinOBJ.cfg = {} function ChengZhangJiJinOBJ:main(parent, data) self.cfg = data GUI:LoadExport(parent, "game/FuLiDaTing/ChengZhangJiJinUI") 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 ChengZhangJiJinOBJ:CreateTableView() -- ListView 原配置: 父=c_bg_img, 位置(12,17), 尺寸 524x264, 方向=1(垂直), 间距=6 -- TableView 不支持 itemsMargin,把间距叠加到 cellHei 中(68 + 6) -- num=5:可视区约 3.5 个 cell,留上下缓冲,复用池设为 5 self.tableView = GUI:TableView_Create(self.ui.c_bg_img, "TableView", 12, 17, 524, 264, 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 ChengZhangJiJinOBJ:buildDataList() local cfg = self.cfg or {} local Vardata = hk.getkeytbl("HUMAN(STR_成长基金)") local canGet, normal, done = {}, {}, {} for i, v in ipairs(cfg) do if i > 1 then 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 hk.checkcontion(v.check) then table.insert(canGet, item) else table.insert(normal, item) end 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 ChengZhangJiJinOBJ:updata() local cfg = self.cfg self.drop = cfg[1].gives self:setDropShow(1, 10) local tequan_open = tonumber(SL:Get_SERVER_VALUE("{8}")) or 0 if tequan_open > 0 then GUI:setTouchEnabled(self.ui.up_btn, false) GUI:setVisible(self.ui.open_img, true) else GUI:setVisible(self.ui.open_img, false) GUI:setTouchEnabled(self.ui.up_btn, true) GUI:addOnClickEvent(self.ui.up_btn, function() ssrMessage:SubLink("FuLiDaTingOBJ_czjjbuy") -- SL:RequestPay(-1, 13, 288, 13) end) ---* 红点 if tonumber(SL:Get_MONEY(2) or 0) >= 2880 then RedDotMgr.attachDot(self.ui.up_btn, { x = 120, y = 40 }) end end self:buildDataList() if self.tableView then GUI:TableView_reloadData(self.tableView) end end --领取状态变化:刷新 open 状态并把已领取的项移到末尾 function ChengZhangJiJinOBJ:setsort() if not self.dataList then return end local Vardata = hk.getkeytbl("HUMAN(STR_成长基金)") -- 同步 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 hk.checkcontion(item.v.check) 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 -- 领取后排序变化时使用 reloadDataEx 保持滚动位置 GUI:TableView_reloadDataEx(self.tableView) end end --在 TableView cell 父节点内构建一行 UI function ChengZhangJiJinOBJ:buildCell(cellParent, item) -- TableView 是虚拟化加载,cellParent 会被复用,必须先清空旧子节点 GUI:removeAllChildren(cellParent) local i = item.idx local v = item.v local open = item.open local bg_id = string.find(v.check[1][1], "等级", 1, true) ~= nil and "res/custom/01/3/7.png" or "res/custom/01/3/3.png" -- y=3 让 cell 上下各留 3 像素(cellHei=74, 内容高=68) local list_bg = GUI:Image_Create(cellParent, "list_bg_", 0, 3, bg_id) local check_text = string.find(v.check[1][1], "等级", 1, true) ~= nil and v.check[1][2] or v.check[1][3] local list_check_text = GUI:Text_Create(list_bg, "list_check_text", 100, 36, 16, "#00ff00", check_text) 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 list_btn = GUI:Button_Create(list_bg, "list_btn", 470, 34, "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:addOnClickEvent(list_btn, function() ssrMessage:SubLink(MeiriXianGouOBJ.__cname .. "_czjj", { id = i }) end) ---* 红点 if tonumber(SL:GetMetaValue("SERVER_VALUE", "{8}") or 0) > 0 and hk.checkcontion(v.check) then RedDotMgr.attachDot(list_btn, { x = 45, y = 25 }) end end return list_bg end function ChengZhangJiJinOBJ:EventBind() local function ChengZhangJiJinOBJ_Var_Change(data) if GUI:Win_IsNotNull(self._parent) then if data.key == "{8}" then self:updata() return end if data.key == "HUMAN(STR_成长基金)" then self:setsort() return end end end SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname, ChengZhangJiJinOBJ_Var_Change) --关闭窗口 SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname .. "mrcz", function(widgetName) self:OnClose(widgetName) end) end --关闭窗口 function ChengZhangJiJinOBJ:OnClose(widgetName) if widgetName == self.__cname then self:UnRegisterEvent() end end function ChengZhangJiJinOBJ:UnRegisterEvent() SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname) SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname) end --注册到全局红点系统:成长基金有未领取档位 → 福利按钮 7 + 顶部福利图标(TopIcon_5)都亮 if RedDotMgr and RedDotMgr.register then RedDotMgr:register("FuLi_ChengZhangJiJin", { owner = "FuLiDaTingOBJ", parent = "TopIcon_FuLi", target = function() return FuLiDaTingOBJ and FuLiDaTingOBJ.ui and FuLiDaTingOBJ.ui.class_btn_7 end, offset = { x = 105, y = 35 }, watchKeys = { "{8}", "HUMAN(STR_成长基金)" }, watchLevel = true, check = function() if tonumber(SL:GetMetaValue("SERVER_VALUE", "{8}") or 0) == 0 then return false end if SL:Get_RELEVEL() <= 3 then return false end local cfg = FuLiDaTingOBJ and FuLiDaTingOBJ.cfg and FuLiDaTingOBJ.cfg[7] if not cfg then return false end local Var = hk.getkeytbl("HUMAN(STR_成长基金)") for i, v in ipairs(cfg) do if i > 1 and hk.checkcontion(v.check) and not (Var and Var[i]) then return true end end return false end, }) end return ChengZhangJiJinOBJ