Files

166 lines
7.6 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Octo Minimap Buttons (owner 2026-11-24): a single round button on the minimap rim that collects the
-- minimap buttons of addons into one panel. Drag it with the left mouse button to slide it along the rim,
-- like the day/night (game time) icon. Only addon frames are moved; Blizzard minimap widgets stay untouched.
local ADDON = ...
local DB
local BLIZZARD = {
MinimapBackdrop = true, MinimapZoomIn = true, MinimapZoomOut = true, MiniMapTracking = true,
MiniMapTrackingFrame = true, MiniMapMailFrame = true, MiniMapBattlefieldFrame = true, GameTimeFrame = true,
TimeManagerClockButton = true, MiniMapWorldMapButton = true, MinimapToggleButton = true, MiniMapLFGFrame = true,
QueueStatusMinimapButton = true, AddonCompartmentFrame = true, MinimapCompassTexture = true,
MiniMapInstanceDifficulty = true, ExpansionLandingPageMinimapButton = true, MinimapCluster = true,
}
local collected, order = {}, {}
local placing = false
-- The rim button ---------------------------------------------------------------------------------
local button = CreateFrame("Button", "OctoMinimapButtonsButton", Minimap)
button:SetSize(31, 31)
button:SetFrameStrata("MEDIUM")
button:SetFrameLevel(Minimap:GetFrameLevel() + 9)
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:RegisterForDrag("LeftButton")
local icon = button:CreateTexture(nil, "BACKGROUND")
icon:SetSize(20, 20)
icon:SetPoint("TOPLEFT", 7, -5)
icon:SetTexture("Interface\\Icons\\INV_Misc_Bag_10_Blue")
local border = button:CreateTexture(nil, "OVERLAY")
border:SetSize(53, 53)
border:SetPoint("TOPLEFT")
border:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
button:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
local function place()
local a = math.rad(DB and DB.angle or 200)
local r = Minimap:GetWidth() / 2 + 8
button:ClearAllPoints()
button:SetPoint("CENTER", Minimap, "CENTER", math.cos(a) * r, math.sin(a) * r)
end
local function follow()
local mx, my = Minimap:GetCenter()
local cx, cy = GetCursorPosition()
local s = Minimap:GetEffectiveScale()
DB.angle = math.deg(math.atan2(cy / s - my, cx / s - mx)) % 360
place()
end
button:SetScript("OnDragStart", function(self) self:SetScript("OnUpdate", follow) end)
button:SetScript("OnDragStop", function(self) self:SetScript("OnUpdate", nil); place() end)
-- The panel -----------------------------------------------------------------------------------------
local panel = CreateFrame("Frame", "OctoMinimapButtonsPanel", UIParent, "BackdropTemplate")
panel:SetFrameStrata("DIALOG")
panel:SetClampedToScreen(true)
panel:SetBackdrop({ bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16, insets = { left = 4, right = 4, top = 4, bottom = 4 } })
panel:SetBackdropColor(0, 0, 0, 0.85)
panel:Hide()
local empty = panel:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
empty:SetPoint("CENTER")
empty:SetText("No addon minimap buttons")
local SIZE, PAD, PER_ROW = 32, 4, 5
local function layout()
placing = true
local n = #order
local cols = math.max(1, math.min(PER_ROW, n))
local rows = math.max(1, math.ceil(n / PER_ROW))
panel:SetSize(cols * (SIZE + PAD) + PAD + 8, rows * (SIZE + PAD) + PAD + 8)
empty:SetShown(n == 0)
if n == 0 then panel:SetSize(170, 34) end
for i, f in ipairs(order) do
f:ClearAllPoints()
f:SetPoint("TOPLEFT", panel, "TOPLEFT", 4 + PAD + ((i - 1) % PER_ROW) * (SIZE + PAD), -4 - PAD - math.floor((i - 1) / PER_ROW) * (SIZE + PAD))
end
placing = false
end
local function anchorPanel()
panel:ClearAllPoints()
local bx = button:GetCenter()
local mx = Minimap:GetCenter()
if bx and mx and bx < mx then panel:SetPoint("TOPRIGHT", button, "BOTTOMLEFT", 8, 4)
else panel:SetPoint("TOPLEFT", button, "BOTTOMRIGHT", -8, 4) end
end
-- Collecting ---------------------------------------------------------------------------------------
local function isAddonButton(f)
if not f or f == button or f:IsForbidden() or f:IsProtected() then return false end
local name = f:GetName()
if not name or BLIZZARD[name] or collected[f] then return false end
if not f:IsObjectType("Button") and not f:IsObjectType("Frame") then return false end
if not f:IsMouseEnabled() then return false end
local w, h = f:GetSize()
if not w or w < 14 or w > 48 or h < 14 or h > 48 then return false end
-- Map pins (gathering/quest markers) are children of Minimap too; addon buttons sit on the rim.
local x, y = f:GetCenter(); local mx, my = Minimap:GetCenter()
if not (x and mx) then return name:find("[Mm]inimap") ~= nil end
local d = math.sqrt((x - mx) ^ 2 + (y - my) ^ 2)
return d >= Minimap:GetWidth() / 2 - 20 or name:find("[Mm]ini[Mm]ap[Bb]utton") ~= nil or name:find("^LibDBIcon") ~= nil
end
local function collect()
if DB and DB.off then return end
local changed
for _, parent in ipairs({ Minimap, MinimapBackdrop }) do
if parent then
for _, f in ipairs({ parent:GetChildren() }) do
if isAddonButton(f) then
collected[f] = true; order[#order + 1] = f; changed = true
f:SetParent(panel)
f:SetFrameStrata("DIALOG")
f:SetScale(1)
-- Addons re-anchor their own button on drag / login; keep it in the panel.
hooksecurefunc(f, "SetPoint", function(self)
if collected[self] and not placing and self:GetParent() == panel then layout() end
end)
if f.RegisterForDrag then f:RegisterForDrag() end
end
end
end
end
if changed then
table.sort(order, function(a, b) return (a:GetName() or "") < (b:GetName() or "") end)
layout()
end
end
local function release()
for _, f in ipairs(order) do f:SetParent(Minimap); f:SetFrameStrata("MEDIUM") end
wipe(collected); wipe(order); layout(); panel:Hide()
print("|cff33ff99Octo Minimap Buttons|r: buttons returned to the minimap; /reload to arrange them.")
end
button:SetScript("OnClick", function(self, mouse)
if mouse == "RightButton" then
DB.off = not DB.off
if DB.off then release() else collect(); print("|cff33ff99Octo Minimap Buttons|r: gathering addon buttons.") end
return
end
collect()
if panel:IsShown() then panel:Hide() else anchorPanel(); panel:Show() end
end)
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText("Addon buttons", 1, 1, 1)
GameTooltip:AddLine("Left-click: show / hide", nil, nil, nil, true)
GameTooltip:AddLine("Drag: move along the minimap", nil, nil, nil, true)
GameTooltip:AddLine("Right-click: " .. ((DB and DB.off) and "gather buttons again" or "put buttons back on the minimap"), nil, nil, nil, true)
GameTooltip:Show()
end)
button:SetScript("OnLeave", GameTooltip_Hide)
local events = CreateFrame("Frame")
events:RegisterEvent("ADDON_LOADED")
events:RegisterEvent("PLAYER_ENTERING_WORLD")
events:SetScript("OnEvent", function(_, event, name)
if event == "ADDON_LOADED" then
if name == ADDON then
OctoMinimapButtonsDB = OctoMinimapButtonsDB or {}
DB = OctoMinimapButtonsDB
place()
end
return
end
-- Late-created buttons (LibDBIcon, addons that wait for login data) are picked up by the rescans.
collect(); C_Timer.After(2, collect); C_Timer.After(10, collect)
end)