BOSSshouShaOBJ = Up_BaseClassOBJ:new() BOSSshouShaOBJ.__cname = "FuLiDaTingOBJ" BOSSshouShaOBJ.cfg = {} function BOSSshouShaOBJ:main(parent, data) self.cfg = data GUI:LoadExport(parent, "game/FuLiDaTing/BOSSshouShaUI") 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 BOSSshouShaOBJ:CreateTableView() -- ListView 原配置: 父=parent, 位置(-262,-197), 尺寸 528x361, 方向=1(垂直), 间距=4 -- TableView 不支持 itemsMargin,把间距叠加到 cellHei 中(30 + 4) -- num=13:可视区 361/34 ≈ 10.6,加上下缓冲 self.tableView = GUI:TableView_Create(self._parent, "TableView", -262, -197, 528, 361, 1, 522, 34, 13) 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(未击杀置顶,同档内按 idx 升序) function BOSSshouShaOBJ:buildDataList() local cfg = self.cfg or {} local notKilled, killed = {}, {} for i, v in pairs(cfg) do local player = hk.getkeycount("GLOBAL(STR_BOSS击杀)", i) or "未击杀" local item = { idx = i, v = v, player = player } if player == "未击杀" then table.insert(notKilled, item) else table.insert(killed, item) end end local function byIdx(a, b) return tonumber(a.idx) < tonumber(b.idx) end table.sort(notKilled, byIdx) table.sort(killed, byIdx) self.dataList = {} for _, it in ipairs(notKilled) do table.insert(self.dataList, it) end for _, it in ipairs(killed) do table.insert(self.dataList, it) end end function BOSSshouShaOBJ:updata() self:buildDataList() if self.tableView then GUI:TableView_reloadData(self.tableView) end end --击杀状态变化:重新排序并保持滚动位置 function BOSSshouShaOBJ:setsort() self:buildDataList() if self.tableView then GUI:TableView_reloadDataEx(self.tableView) end end --在 TableView cell 父节点内构建一行 UI function BOSSshouShaOBJ:buildCell(cellParent, item) -- TableView 是虚拟化加载,cellParent 会被复用,必须先清空旧子节点 GUI:removeAllChildren(cellParent) local i = item.idx local v = item.v local player = item.player local list_bg = GUI:Image_Create(cellParent, "list_bg_", 0, 0, "res/custom/01/6/0.png") local item_name = GUI:Text_Create(list_bg, "item_name_" .. i, 60, 15, 16, "#ff0000", v.name) GUI:setAnchorPoint(item_name, 0.50, 0.50) local gives = {} for _, give in ipairs(v.gives or {}) do table.insert(gives, string.format("%sx%d", give[1], give[2])) end local list_give = GUI:Text_Create(list_bg, "list_give_" .. i, 178, 15, 16, "#00ff00", table.concat(gives, "、")) GUI:setAnchorPoint(list_give, 0.50, 0.50) local list_map = GUI:Text_Create(list_bg, "list_map_" .. i, 328, 15, 16, "#00ff00", v.map) GUI:setAnchorPoint(list_map, 0.50, 0.50) local list_Player = GUI:Text_Create(list_bg, "list_Player_" .. i, 470, 15, 16, "#00ff00", player) GUI:setAnchorPoint(list_Player, 0.50, 0.50) GUI:Text_enableOutline(list_Player, "#000000", 2) GUI:Text_setTextColor(list_Player, player == "未击杀" and "#ff0000" or "#00ff00") return list_bg end function BOSSshouShaOBJ:EventBind() local function BOSSshouShaOBJ_Var_Change(data) if GUI:Win_IsNotNull(self._parent) then if data.key == "GLOBAL(STR_BOSS击杀)" then self:setsort() return end end end SL:RegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname, BOSSshouShaOBJ_Var_Change) --关闭窗口 SL:RegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname .. "mrcz", function(widgetName) self:OnClose(widgetName) end) end --关闭窗口 function BOSSshouShaOBJ:OnClose(widgetName) if widgetName == self.__cname then self:UnRegisterEvent() end end function BOSSshouShaOBJ:UnRegisterEvent() SL:UnRegisterLUAEvent(LUA_EVENT_SERVER_VALUE_CHANGE, self.__cname) SL:UnRegisterLUAEvent(LUA_EVENT_CLOSEWIN, self.__cname) end return BOSSshouShaOBJ