Thread Tools Display Modes
02-23-16, 04:24 PM   #1
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
(Question Update) oUF - ClassIcon

So I have two modules, api.lua and core.lua, and here's what they look like.

api.lua:
Lua Code:
  1. local E, D, U, B = unpack(select(2, ...));
  2.  
  3. local G, A, C = unpack(U);
  4.  
  5. local BACKDROP = LSM:Fetch("background", "backdrop");
  6.  
  7. A.InitFrame = function(f, unit)
  8.     f:RegisterForClicks("anyup");
  9.  
  10.     f:SetScript("OnEnter", UnitFrame_OnEnter);
  11.     f:SetScript("OnLeave", UnitFrame_OnLeave);
  12.  
  13.     f:SetFrameStrata("LOW");
  14.  
  15.     f:SetBackdrop({
  16.         bgFile = BACKDROP,
  17.         tile = true,
  18.         tileSize = 16,
  19.     });
  20.     f:SetBackdropColor(0.1, 0.1, 0.1, 1);
  21.     f:SetSize(G[unit]["width"], G[unit]["height"]);
  22.  
  23.     A.GenPosition(f, unit);
  24. end
  25.  
  26. A.RegEvent = function(f, ...)
  27.     for i = 1, select("#", ...) do
  28.         f:RegisterEvent(select(i, ...));
  29.     end
  30. end
  31.  
  32. so on..........

core.lua:
Lua Code:
  1. local E, D, U, B = unpack(select(2, ...));
  2.  
  3. local G, A, C = unpack(U);
  4.  
  5. C.stylemanager = function(f, unit)
  6.     if C.styles[unit] then
  7.         C.styles[unit](f, unit);
  8.     end
  9. end
  10.  
  11. YUF:RegisterStyle("YUF_Style", C.stylemanager);
  12.  
  13. YUF:Spawn("player", "YUI_PlayerFrame");
  14. YUF:Spawn("target", "YUI_TargetFrame");

Inside "A.InitFrame" function I was trying to register event if the unit is "player" by using "A.RegEvent" which would look like:
Lua Code:
  1. if (unit == "player") then
  2.     A.RegEvent(f, "PLAYER_REGEN_DISABLED", "PLAYER_REGEN_ENABLED");
  3.  
  4.     f:SetScript("OnEvent", function(self, event, ...)
  5.         if (event == "PLAYER_REGEN_DISABLED") then
  6.             if UnitAffectingCombat(unit) then
  7.                 f:SetBackdropColor(1, 0, 0, 1);
  8.             end
  9.         else
  10.             f:SetBackdropColor(0.1, 0.1, 0.1, 1);
  11.         end
  12.     end);
  13. else
  14.     f:SetBackdropColor(0.1, 0.1, 0.1, 1);
  15. end

But, oUF printed the following errors which I don't really get with:



Could anyone please tell me what is going wrong with my code?

Thank you.


EDIT: The reason that I'm doing this is to change background color to red when the player is in combat.

If there is any better ways to do so, please let me know

Last edited by jeAz_ : 02-23-16 at 10:52 PM.
  Reply With Quote
02-23-16, 06:15 PM   #2
sezz
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 158
I think it should work like this, because oUF handles the events of the unitframe frame:

Lua Code:
  1. local PlayerRegenChanged = function(self)
  2.     if (UnitAffectingCombat("player")) then
  3.         self:SetBackdropColor(1, 0, 0, 1);
  4.     else
  5.         self:SetBackdropColor(0.1, 0.1, 0.1, 1);
  6.     end
  7. end
  8.  
  9. if (unit == "player") then
  10.     table.insert(f.__elements, PlayerRegenChanged);
  11.     f:RegisterEvent("PLAYER_REGEN_DISABLED", PlayerRegenChanged);
  12.     f:RegisterEvent("PLAYER_REGEN_ENABLED", PlayerRegenChanged);
  13. else
  14.     f:SetBackdropColor(0.1, 0.1, 0.1, 1);
  15. end

But I could be wrong, I've been using my oUF style since ~2008 and only update them every new WoW addon to fix API stuff

You can propably also ignore the table.insert(f.__elements... line, because "player" should be always visible.

BTW: There's also a combat element, if you don't want to use custom events at all.

Last edited by sezz : 02-23-16 at 07:48 PM.
  Reply With Quote
02-23-16, 06:27 PM   #3
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by sezz View Post
Code:
f:RegisterEvent("PLAYER_REGEN_DISABLED", PlayerRegenChanged);
f:RegisterEvent("PLAYER_REGEN_DISABLED", PlayerRegenChanged);
Don't you mean this?
Code:
f:RegisterEvent("PLAYER_REGEN_DISABLED", PlayerRegenChanged);
f:RegisterEvent("PLAYER_REGEN_ENABLED", PlayerRegenChanged);
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
02-23-16, 07:48 PM   #4
sezz
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 158
Originally Posted by SDPhantom View Post
Don't you mean this?
Code:
f:RegisterEvent("PLAYER_REGEN_DISABLED", PlayerRegenChanged);
f:RegisterEvent("PLAYER_REGEN_ENABLED", PlayerRegenChanged);
yep, sorry. fixed
  Reply With Quote
02-23-16, 10:13 PM   #5
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by sezz View Post
yep, sorry. fixed
Sweet!

Thank you for your reply
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Registering Event to spawned Frame

Thread Tools
Display Modes

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