142 lines
4.8 KiB
Lua
142 lines
4.8 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()
|
|
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
|
|
|
|
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
|
|
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: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
|
|
|
|
local frame = CreateFrame("Frame")
|
|
frame:RegisterEvent("PLAYER_ENTERING_WORLD")
|
|
frame:SetScript("OnEvent", function(self, event, addon)
|
|
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("OnShow", function(self)
|
|
for i = 1, 10 do
|
|
local x = math.random()
|
|
local y = math.random()
|
|
PlantAlert(x * 100, y * 100)
|
|
end
|
|
end)
|
|
BattlefieldMinimap:HookScript("OnHide", function(self)
|
|
for _, alertFrame in ipairs(alertFramePool) do
|
|
alertFrame:Hide()
|
|
alertFrame.custom.busy = false
|
|
end
|
|
end)
|
|
BattlefieldMinimap:Hide()
|
|
BattlefieldMinimap:Show()
|
|
end)
|
|
|
|
print("[Heimdall] MinimapTagger loaded")
|
|
end
|
|
|
|
SlashCmdList["HEIMDALL_MINIMAPTAGGER"] = function(args)
|
|
shared.MinimapTagger.Init()
|
|
end
|
|
SLASH_HEIMDALL_MINIMAPTAGGER1 = "/mf"
|