Quantcast
WoWInterface - View Single Post - Optimizing a fade out
View Single Post
09-25-18, 08:24 AM   #4
Terenna
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
I was able to dry code the following:

Lua Code:
  1. local fadeouttable = {}
  2. table.insert(fadeouttable, GameTimeFrame)
  3. table.insert(fadeouttable, TimeManagerClockButton)
  4. table.insert(fadeouttable, MiniMapTracking)
  5. table.insert(fadeouttable, MiniMapChallengeMode)
  6. table.insert(fadeouttable, MiniMapInstanceDifficulty)
  7. table.insert(fadeouttable, GuildInstanceDifficulty)
  8.  
  9. local function CreateFrameFadeAnimation(frame)
  10.     if frame.fader then return end
  11.     local animFrame = CreateFrame('frame', nil, frame)
  12.     animFrame.__owner = frame
  13.     frame.fader = animFrame:CreateAnimationGroup()
  14.     frame.fader.__owner = frame
  15.     frame.fader.__animFrame = animFrame
  16.     frame.fader.direction = nil
  17.     frame.fader.setToFinalAlpha = false
  18.     frame.fader.anim = frame.fader:CreateAnimation('Alpha')
  19.     --frame.fader:HookScript("OnFinished", FaderOnFinished)
  20.     --frame.fader:HookScript("OnUpdate", FaderOnUpdate)
  21.  end
  22.  
  23. local function tMinimapFadeOut(frame)
  24.     if frame.fader.direction == 'out' then return end
  25.     frame.fader:Pause()
  26.     frame.fader.anim:SetFromAlpha(1)
  27.     frame.fader.anim:SetToAlpha(0)
  28.     frame.fader.anim:SetDuration(1)
  29.     frame.fader.anim:SetSmoothing('OUT')
  30.     frame.fader.anim:SetStartDelay(1)
  31.     frame.fader.finAlpha = 0
  32.     frame.fader.direction = 'out'
  33.     frame.fader:Play()
  34. end
  35.  
  36. local lasttime
  37. Minimap:SetScript('OnLeave', function()
  38.     if Minimap:IsMouseOver() then return end --failsafe to ensure we don't hide with mouse still on minimap
  39.     if time() == lasttime then return end --another failsafe
  40.     lasttime = time()
  41.  
  42.     for k, v in pairs(fadeouttable) do
  43.         tMinimapFadeOut(v)
  44.     end
  45. end)
  46.  
  47. Minimap:SetScript('OnEnter', function()
  48.     for k, v in pairs(fadeouttable) do
  49.         v.fader:Pause()
  50.         v:SetAlpha(1)
  51.     end
  52. end)

Of note, I didn't understand why you need the onupdate and the onfinished functions. Why is that, exactly?

Last edited by Terenna : 09-25-18 at 08:26 AM.
  Reply With Quote