Refactor frame creation a little

This commit is contained in:
2025-01-09 12:11:03 +01:00
parent 4b43ee86c0
commit 32543d04a0

View File

@@ -6,19 +6,10 @@ local ModuleName = "MinimapTagger"
---@diagnostic disable-next-line: missing-fields
shared.MinimapTagger = {}
function shared.MinimapTagger.Init()
local alertFramePool = {}
local alertFramePoolMaxSize = 20
---@param x number
---@param y number
local function PlantAlert(x, y)
local frame = nil
for _, alertFrame in ipairs(alertFramePool) do
if not alertFrame.custom.busy then
frame = alertFrame
break
end
end
---@param frame Frame
local function PlantFrame(x, y, frame)
local w, h = BattlefieldMinimap:GetSize()
w, h = w * BattlefieldMinimap:GetEffectiveScale(), h * BattlefieldMinimap:GetEffectiveScale()
local maxSize = w > h and w or h
@@ -35,32 +26,10 @@ function shared.MinimapTagger.Init()
print(string.format("[%s] Alert position: %d, %d", ModuleName, x, y))
print(string.format("[%s] Alert offset: %d, %d", ModuleName, offsetx, offsety))
end
if not frame and #alertFramePool >= alertFramePoolMaxSize then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert frame pool is full, skipping", ModuleName))
end
return
end
if not frame then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Creating new alert frame", ModuleName))
end
frame = CreateFrame("Frame")
frame:SetSize(iconSize, iconSize)
frame:SetFrameStrata("HIGH")
frame:SetFrameLevel(100)
frame.custom = { busy = true }
local alertFrameTexture = frame:CreateTexture(nil, "ARTWORK")
alertFrameTexture:SetAllPoints(frame)
alertFrameTexture:SetColorTexture(1, 0, 0, 0.5)
alertFrameTexture:SetTexture("Interface\\AddOns\\WeakAuras\\PowerAurasMedia\\Auras\\Aura27")
table.insert(alertFramePool, frame)
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert frame created, pool size: %d", ModuleName, #alertFramePool))
end
end
frame:SetSize(iconSize, iconSize)
frame:SetFrameStrata("HIGH")
frame:SetFrameLevel(100)
frame:SetPoint("CENTER", BattlefieldMinimap, "TOPLEFT", offsetx, -offsety)
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert frame created, OnUpdate hooked", ModuleName))
@@ -89,6 +58,35 @@ function shared.MinimapTagger.Init()
frame:Show()
end
local alertFramePool = {}
local alertFramePoolMaxSize = 20
for i = 1, alertFramePoolMaxSize do
local frame = CreateFrame("Frame")
frame.custom = { busy = false }
local texture = frame:CreateTexture(nil, "ARTWORK")
texture:SetAllPoints(frame)
texture:SetTexture("Interface\\AddOns\\WeakAuras\\PowerAurasMedia\\Auras\\Aura27")
table.insert(alertFramePool, frame)
end
---@param x number
---@param y number
local function PlantAlert(x, y)
local frame = nil
for _, alertFrame in ipairs(alertFramePool) do
if not alertFrame.custom.busy then
frame = alertFrame
break
end
end
if not frame and #alertFramePool >= alertFramePoolMaxSize then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert frame pool is full, skipping", ModuleName))
end
return
end
PlantFrame(x, y, frame)
end
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", function(self, event, addon)