Files
wow-Heimdall/Modules/MinimapTagger.lua
2025-01-09 12:18:04 +01:00

166 lines
5.3 KiB
Lua

local addonname, shared = ...
---@cast shared HeimdallShared
---@cast addonname string
local ModuleName = "MinimapTagger"
---@diagnostic disable-next-line: missing-fields
shared.MinimapTagger = {}
function shared.MinimapTagger.Init()
---@param x number
---@param y number
---@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
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Minimap size: %d", ModuleName, maxSize))
end
local iconSize = maxSize * 0.05
x, y = x / 100, y / 100
-- Could do with how... I have no idea, but this seems more accurate than without
--x, y = x - 0.01, y - 0.01
local offsetx, offsety = w * x, h * y
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert position: %d, %d", ModuleName, x, y))
print(string.format("[%s] Alert offset: %d, %d", ModuleName, offsetx, offsety))
end
frame:Hide()
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))
end
frame:SetScript("OnShow", function(self)
self:SetAlpha(1)
self.custom.busy = true
self.custom.progress = 0
self:SetScript("OnUpdate", function(self, elapsed)
self.custom.progress = self.custom.progress + elapsed
local progress = self.custom.progress / Heimdall_Data.config.minimapTagger.ttl
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert progress%%: %f", ModuleName, progress))
print(string.format("[%s] Alert progress: %f", ModuleName, self.custom.progress))
print(string.format("[%s] Alert ttl: %f", ModuleName, Heimdall_Data.config.minimapTagger.ttl))
end
self:SetAlpha(1 - progress)
if progress >= 1 then
self:Hide()
self.custom.busy = false
self:SetScript("OnUpdate", nil)
end
end)
end)
frame:Show()
end
---@type Frame[]
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 then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Alert frame pool is full and could not get frame", ModuleName))
end
return
end
PlantFrame(x, y, frame)
end
---@type Frame[]
local tagFramePool = {}
local tagFramePoolMaxSize = 20
for i = 1, tagFramePoolMaxSize 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\\Aura11")
table.insert(tagFramePool, frame)
end
---@param x number
---@param y number
local function PlantTag(x, y)
local frame = nil
for _, tagFrame in ipairs(tagFramePool) do
if not tagFrame.custom.busy then
frame = tagFrame
break
end
end
if not frame then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] Tag frame pool is full and could not get frame", ModuleName))
end
return
end
PlantFrame(x, y, frame)
end
local pauseUntil = 0
local frame = CreateFrame("Frame")
frame:RegisterEvent("WORLD_MAP_UPDATE")
frame:SetScript("OnEvent", function(self, event, addon)
if pauseUntil > GetTime() then return end
pauseUntil = GetTime() + 1
if not BattlefieldMinimap then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] BattlefieldMinimap not found", ModuleName))
end
return
end
if not Heimdall_Data.config.minimapTagger.enabled then
if Heimdall_Data.config.minimapTagger.debug then
print(string.format("[%s] MinimapTagger is disabled", ModuleName))
end
return
end
--local scale = Heimdall_Data.config.minimapTagger.scale
local scale = 4
BattlefieldMinimap:SetScale(scale)
BattlefieldMinimap:SetMovable(true)
BattlefieldMinimap:EnableMouse(true)
BattlefieldMinimap:RegisterForDrag("LeftButton")
BattlefieldMinimap:SetScript("OnDragStart", function(self) self:StartMoving() end)
BattlefieldMinimap:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
BattlefieldMinimapBackground:Hide()
BattlefieldMinimapCloseButton:Hide()
BattlefieldMinimapCorner:Hide()
BattlefieldMinimap:HookScript("OnHide", function(self)
for _, alertFrame in ipairs(alertFramePool) do
alertFrame:Hide()
alertFrame.custom.busy = false
end
end)
end)
print("[Heimdall] MinimapTagger loaded")
end
SlashCmdList["HEIMDALL_MINIMAPTAGGER"] = function(args)
shared.MinimapTagger.Init()
end
SLASH_HEIMDALL_MINIMAPTAGGER1 = "/mf"