Thread Tools Display Modes
02-15-15, 10:10 PM   #1
JDoubleU00
A Firelord
 
JDoubleU00's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 463
Fading Player Unit Frames

I'd like to fade out the player unit frames when not in combat or target another unit. oUF_Fader is no longer being developed. The latest Kong UI Hider does not see any frames for oUF. Any suggestions? I've been using oUF_Phanx and oUF_Adirelle.
__________________
Author of JWExpBar and JWRepBar.
  Reply With Quote
02-16-15, 04:49 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Lua Code:
  1. --Variables
  2. local frameList = {"frameName1","frameName2","frameName3"} --add the name of your frames here
  3. local addon     = CreateFrame("Frame")
  4. local _G        = _G
  5.  
  6. --ChangeFrameAlpha func
  7. local function ChangeFrameAlpha(a)
  8.   for _, frameName in next, frameList do
  9.     if _G[frameName] then
  10.       _G[frameName]:SetAlpha(a)
  11.     end
  12.   end
  13. end
  14.  
  15. --OnEvent func
  16. local function OnEvent(self,event)
  17.   if InCombatLockdown() then
  18.     ChangeFrameAlpha(1)
  19.   else
  20.     ChangeFrameAlpha(0.5)
  21.   end
  22. end
  23.  
  24. --RegisterEvent
  25. frame:RegisterEvent("PLAYER_REGEN_ENABLED")
  26. frame:RegisterEvent("PLAYER_REGEN_DISABLED")
  27. frame:RegisterEvent("PLAYER_ENTERING_WORLD")
  28.  
  29. --SetScript
  30. frame:SetScript("OnEvent", OnEvent)

If your oUF layouts do not generate a global frame name you can edit them to make one.

Additionally you can make the above work without using _G. You can do this by adding your unitframes by reference to the frameList table.

Lua Code:
  1. local addonName, addonTabe = ...
  2. addonTable.frameList = addonTable.frameList or {}
  3.  
  4. --ChangeFrameAlpha func
  5. local function ChangeFrameAlpha(a)
  6.   for _, frame in next, addonTable.frameList do
  7.     frame:SetAlpha(a)
  8.   end
  9. end
  10.  
  11. --inside of the unit creation (factory or template function)
  12. tinsert(addonTable.frameList,self)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)

Last edited by zork : 02-16-15 at 04:57 AM.
  Reply With Quote
02-16-15, 05:05 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You don't need global names at all... just iterate over oUF's internal list of frames:

Code:
for _, frame in next, oUF.objects do
    frame:SetAlpha(0.5)
end
Also, InCombatLockdown() is always false inside the PLAYER_REGEN_DISABLED event, since the purpose (or one of the purposes) of that event is to notify addons that combat is beginning so they can make changes for combat. Lockdown doesn't take effect until the event is finished being handled. Use UnitAffectingCombat("player") instead.

Also also, there's really no need to factor that out into multiple independent functions when there is only one chain of execution. Function calls are slow. Avoid them whenever posisble.

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:RegisterEvent("PLAYER_REGEN_DISABLED")
f:RegisterEvent("PLAYER_REGEN_ENABLED")
f:SetScript("OnEvent", function()
     local a = UnitAffectingCombat("player") and 1 or 0.5
     for _, frame in next, oUF.objects do
          frame:SetAlpha(a)
     end
end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Fading Player Unit Frames


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off