From d6e5e7941f44d37a46c03ce75efed6c30ae817d0 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sun, 26 Jan 2025 22:20:04 +0100 Subject: [PATCH] Fix inviter kick buttons --- Modules/Inviter.lua | 94 ++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 40 deletions(-) diff --git a/Modules/Inviter.lua b/Modules/Inviter.lua index e0d77ac..73ba81d 100644 --- a/Modules/Inviter.lua +++ b/Modules/Inviter.lua @@ -64,50 +64,61 @@ function shared.Inviter.Init() end ---@param name string - ---Kicking people or othwerise people leaving will fuck up the buttons - ---We should make them reactive to GROUP_ROSTER_UPDATE - ---But that is currently not trivial and would require some work - ---Since I'm the only one currently using this - I don't care where the buttons are - local function OverlayKickButtonElvUI(name) - if Heimdall_Data.config.inviter.debug then - print(string.format("[%s] OverlayKickButtonElvUI", ModuleName)) - shared.dumpTable(Heimdall_Data.config.inviter) - end + ---@return Frame? + local function FindPlayerRaidFrame(name) for group = 1, 8 do for player = 1, 5 do local button = _G[string.format("ElvUF_RaidGroup%dUnitButton%d", group, player)] if Heimdall_Data.config.inviter.debug then - print(string.format("[%s] button = %s", ModuleName, button)) + print(string.format("[%s] button = %s", ModuleName, tostring(button))) end local unitName = button and button.unit and UnitName(button.unit) if Heimdall_Data.config.inviter.debug then - print(string.format("[%s] unitName = %s", ModuleName, unitName)) + print(string.format("[%s] unitName = %s", ModuleName, tostring(unitName))) end if unitName == name then if Heimdall_Data.config.inviter.debug then print(string.format("[%s] unitName == name", ModuleName)) end - local overlayButton = framePool[button.unit] or - CreateFrame("Button", - string.format("HeimdallKickButton%s", button.unit, button, "SecureActionButtonTemplate")) - framePool[button.unit] = overlayButton + return button + end + end + end + return nil + end - overlayButton:SetSize(button.UNIT_WIDTH / 2, button.UNIT_HEIGHT / 2) - overlayButton:SetPoint("CENTER", button, "CENTER", 0, 0) - overlayButton:SetNormalTexture("Interface\\Buttons\\UI-GroupLoot-KickIcon") - overlayButton:SetHighlightTexture("Interface\\Buttons\\UI-GroupLoot-KickIcon") - overlayButton:SetPushedTexture("Interface\\Buttons\\UI-GroupLoot-KickIcon") - overlayButton:SetDisabledTexture("Interface\\Buttons\\UI-GroupLoot-KickIcon") - overlayButton:SetAlpha(0.5) - overlayButton:Show() - overlayButton:SetScript("OnClick", function() - UninviteUnit(name) - overlayButton:Hide() - end) - -- button:SetAttribute("type", "macro") - -- button:SetAttribute("macrotext", "/kick " .. unit) - return + local framePool = {} + local playerButtons = {} + setmetatable(playerButtons, { __mode = "kv" }) + ---@param players string[] + local function OverlayKickButtons(players) + for _, frame in pairs(framePool) do + frame:Hide() + end + for _, name in pairs(players) do + local frame = FindPlayerRaidFrame(name) + if frame then + playerButtons[name] = frame + local button = framePool[frame.unit] or CreateFrame("Button", + string.format("HeimdallKickButton%s", frame.unit, frame, "SecureActionButtonTemplate")) + framePool[frame.unit] = button + + button:SetSize(frame.UNIT_WIDTH / 2, frame.UNIT_HEIGHT / 2) + button:SetPoint("CENTER", frame, "CENTER", 0, 0) + button:SetNormalTexture("Interface\\Buttons\\UI-GroupLoot-KickIcon") + button:SetHighlightTexture("Interface\\Buttons\\UI-GroupLoot-KickIcon") + button:SetPushedTexture("Interface\\Buttons\\UI-GroupLoot-KickIcon") + button:SetDisabledTexture("Interface\\Buttons\\UI-GroupLoot-KickIcon") + button:SetAlpha(0.5) + button:Show() + button:SetScript("OnClick", function() + UninviteUnit(name) + button:Hide() + end) + else + if Heimdall_Data.config.inviter.debug then + print(string.format("[%s] Frame for player %s not found", ModuleName, name)) end end end @@ -138,18 +149,21 @@ function shared.Inviter.Init() end end end + local afkPlayers = {} for name, time in pairs(groupMembers) do - if time < now - Heimdall_Data.config.inviter.afkThreshold then - print(string.format("Kicking %s for being offline", name)) - -- Blyat this is protected... - -- UninviteUnit(name) - OverlayKickButtonElvUI(name) - end if not UnitInParty(name) then print(string.format("%s no longer in party", name)) groupMembers[name] = nil + else + if time < now - Heimdall_Data.config.inviter.afkThreshold then + print(string.format("Kicking %s for being offline", name)) + afkPlayers[#afkPlayers + 1] = name + -- Blyat this is protected... + -- UninviteUnit(name) + end end end + OverlayKickButtons(afkPlayers) end local function Tick() CleanGroups() @@ -181,10 +195,10 @@ function shared.Inviter.Init() local inviterChannelFrame = CreateFrame("Frame") inviterChannelFrame:RegisterEvent("CHAT_MSG_CHANNEL") inviterChannelFrame:SetScript("OnEvent", function(self, event, msg, sender, ...) - -- if Heimdall_Data.config.inviter.debug then - -- print(string.format("[%s] Chat message received: %s", ModuleName, msg)) - -- shared.dumpTable(Heimdall_Data.config.inviter) - -- end + --if Heimdall_Data.config.inviter.debug then + -- print(string.format("[%s] Chat message received: %s", ModuleName, msg)) + -- shared.dumpTable(Heimdall_Data.config.inviter) + --end if not Heimdall_Data.config.inviter.enabled then return end local channelId = select(6, ...) local _, channelname = GetChannelName(channelId)