Good morning all,
I have written a small snippet of code to show certain aspects of the minimap children, by controlling their alpha, when I mouseover the minimap. Further, when the mouse leaves the minimap, it starts a fadeout process that occurs relatively smoothly, 20 incremental decreases of alpha by 0.05 over 1 second. I couldn't think of a better way to code this, and everything works as intended. I am writing this to determine how to do it better.
Thank you, I'm guessing this is way over engineered and am eager to learn more about how to do this more efficiently.
Lua Code:
local fadeouttimer = 1
local subtractor = fadeouttimer/20
local fader
local function tMinimapFadeOut()
if Minimap:IsMouseOver() then --mouse reentered during fadeout, cancel the ticker, reset the timer, and set alphas back to 1
fader:Cancel()
fadeouttimer = 1
GameTimeFrame:SetAlpha(1)
TimeManagerClockButton:SetAlpha(1)
MiniMapTracking:SetAlpha(1)
MiniMapChallengeMode:SetAlpha(1)
MiniMapInstanceDifficulty:SetAlpha(1)
GuildInstanceDifficulty:SetAlpha(1)
end
fadeouttimer = fadeouttimer - subtractor
GameTimeFrame:SetAlpha(fadeouttimer or 0) -- or 0 for when the game inevitably determines that 0 is actually a tiny negative number
TimeManagerClockButton:SetAlpha(fadeouttimer or 0)
MiniMapTracking:SetAlpha(fadeouttimer or 0)
MiniMapChallengeMode:SetAlpha(fadeouttimer or 0)
MiniMapInstanceDifficulty:SetAlpha(fadeouttimer or 0)
GuildInstanceDifficulty:SetAlpha(fadeouttimer or 0)
if fadeouttimer <= 0 then --reset the fadeouttimer for next time
fader:Cancel() --failsafe to stop any previous fades that are ongoing when the mouse leaves (in case the mouse enters and then exits and then reenters)
fadeouttimer = 1
end
end
local lasttime = 0
Minimap:SetScript('OnLeave', function()
if Minimap:IsMouseOver() then return end --failsafe to ensure we don't hide with mouse still on minimap
if time() == lasttime then return end --another failsafe
lasttime = time()
fader = C_Timer.NewTicker(0.05, tMinimapFadeOut, 20) --run 20 times over 1 second (20*0.05 = 1)
end)