Refactor frame creation a little
This commit is contained in:
@@ -6,19 +6,10 @@ local ModuleName = "MinimapTagger"
|
|||||||
---@diagnostic disable-next-line: missing-fields
|
---@diagnostic disable-next-line: missing-fields
|
||||||
shared.MinimapTagger = {}
|
shared.MinimapTagger = {}
|
||||||
function shared.MinimapTagger.Init()
|
function shared.MinimapTagger.Init()
|
||||||
local alertFramePool = {}
|
|
||||||
local alertFramePoolMaxSize = 20
|
|
||||||
---@param x number
|
---@param x number
|
||||||
---@param y number
|
---@param y number
|
||||||
local function PlantAlert(x, y)
|
---@param frame Frame
|
||||||
local frame = nil
|
local function PlantFrame(x, y, frame)
|
||||||
for _, alertFrame in ipairs(alertFramePool) do
|
|
||||||
if not alertFrame.custom.busy then
|
|
||||||
frame = alertFrame
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local w, h = BattlefieldMinimap:GetSize()
|
local w, h = BattlefieldMinimap:GetSize()
|
||||||
w, h = w * BattlefieldMinimap:GetEffectiveScale(), h * BattlefieldMinimap:GetEffectiveScale()
|
w, h = w * BattlefieldMinimap:GetEffectiveScale(), h * BattlefieldMinimap:GetEffectiveScale()
|
||||||
local maxSize = w > h and w or h
|
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 position: %d, %d", ModuleName, x, y))
|
||||||
print(string.format("[%s] Alert offset: %d, %d", ModuleName, offsetx, offsety))
|
print(string.format("[%s] Alert offset: %d, %d", ModuleName, offsetx, offsety))
|
||||||
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
|
|
||||||
|
|
||||||
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)
|
frame:SetPoint("CENTER", BattlefieldMinimap, "TOPLEFT", offsetx, -offsety)
|
||||||
if Heimdall_Data.config.minimapTagger.debug then
|
if Heimdall_Data.config.minimapTagger.debug then
|
||||||
print(string.format("[%s] Alert frame created, OnUpdate hooked", ModuleName))
|
print(string.format("[%s] Alert frame created, OnUpdate hooked", ModuleName))
|
||||||
@@ -89,6 +58,35 @@ function shared.MinimapTagger.Init()
|
|||||||
frame:Show()
|
frame:Show()
|
||||||
end
|
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")
|
local frame = CreateFrame("Frame")
|
||||||
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
||||||
frame:SetScript("OnEvent", function(self, event, addon)
|
frame:SetScript("OnEvent", function(self, event, addon)
|
||||||
|
|||||||
Reference in New Issue
Block a user