Thread Tools Display Modes
02-23-16, 10:55 PM   #1
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
oUF - ClassIcons

Let me apologize that I'm writing multiple threads within a short term

So, here's my new questions.

I was trying to create "ClassIcon Bar" with "ClassIcon" element.

However, there was few problems with this.

Have a look at the code first:
Lua Code:
  1. A.CreateClassIcons = function(f, unit)
  2.     local _, Class = UnitClass(unit);
  3.     local MaxPower;
  4.     local ClassIcons = {};
  5.     local ClassIconName = {
  6.         Monk = "ChiOrb",
  7.         Paladin = "HolyPower",
  8.         Priest = "ShadowOrb",
  9.         Warlock = "SoulShard",
  10.     };
  11.     local ClassIconColor = {
  12.         Monk = {
  13.             r = 0.52,
  14.             g = 0.90,
  15.             b = 0.50,
  16.         },
  17.  
  18.         Paladin = {
  19.             r = 1.00,
  20.             g = 0.70,
  21.             b = 0.85,
  22.         },
  23.  
  24.         Priest = {
  25.             r = 1.00,
  26.             g = 1.00,
  27.             b = 1.00,
  28.         },
  29.         Warlock = {
  30.             r = 0.65,
  31.             g = 0.40,
  32.             b = 1.00,
  33.         },
  34.     };
  35.  
  36.     if (Class == "MONK") then
  37.         MaxPower = UnitPowerMax(unit, SPELL_POWER_CHI);
  38.     end
  39.  
  40.     local lowerClass = A.FirstToUpper(Class);
  41.  
  42.     for i = 1, 6 do
  43.         local ClassIcon = CreateFrame("Frame", ("YUI_" .. ClassIconName[lowerClass] .. i), f);
  44.    
  45.         ClassIcon:SetBackdrop({
  46.             bgFile = BACKDROP,
  47.             tile = true,
  48.             tileSize = 16,
  49.         });
  50.         ClassIcon:SetBackdropColor(0.1, 0.1, 0.1, 1);
  51.         ClassIcon:SetWidth((G[unit]["width"] - (MaxPower - 1)) / MaxPower);
  52.         ClassIcon:SetHeight(16);
  53.  
  54.         if i == 1 then
  55.             ClassIcon:SetPoint("TOPLEFT", f, "BOTTOMLEFT", 0, -2);
  56.         else
  57.             ClassIcon:SetPoint("LEFT", ClassIcons[i - 1], "RIGHT", 1, 0);
  58.         end
  59.  
  60.         local texture = ClassIcon:CreateTexture(nil, "OVERLAY");
  61.         texture:SetTexture(COMBO_POINT);
  62.         texture:SetVertexColor(ClassIconColor[lowerClass]["r"], ClassIconColor[lowerClass]["g"], ClassIconColor[lowerClass]["b"], 1);
  63.         texture:SetWidth(ClassIcon:GetWidth() - 4);
  64.         texture:SetHeight(ClassIcon:GetHeight() - 4);
  65.         texture:SetPoint("CENTER");
  66.  
  67.         ClassIcon.texture = texture;
  68.         ClassIcons[i] = ClassIcon;
  69.     end
  70.  
  71.     f.ClassIcons = ClassIcons;
  72. end

The first issue with this code is that when I enter the game, "UnitPowerMax(unit, SPELL_POWER_CHI)" returns 0 and only returns the proper value when I reload the game.

The next issue is that since I'm using my own textures for Chi, I have to update the size and position of icon if I select "Ascension (Monk Talent: 3/2)" which increases max number of chi by 1. However, it seems not working as I expected ...

Lastly, instead of utilizing default "ClassIcons" element, I was trying to create my own element module for each classes, Monk, Warlock, Priest and Paladin. So, I've attempted to interpret the original "ClassIcons" module, but as a newbie, it was pretty complex to understand what each function performs.

Could anyone please help me with interpreting this module

Last edited by jeAz_ : 02-23-16 at 11:41 PM.
  Reply With Quote
02-24-16, 02:46 AM   #2
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
I did my own classbars for oUF_Diablo. They can be found under modules.
https://github.com/zorker/rothui/tre...Diablo/modules

Example for Harmony:
https://github.com/zorker/rothui/blo...UF_Harmony.lua

On top of that make sure to check out the wow api changes for legion regarding that topic:
http://www.wowinterface.com/forums/s...ad.php?t=53140

Taking a look at rClassBars may help out aswell.
http://www.wowinterface.com/download...ClassBars.html
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
02-24-16, 03:42 AM   #3
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by zork View Post
I did my own classbars for oUF_Diablo. They can be found under modules.
https://github.com/zorker/rothui/tre...Diablo/modules

Example for Harmony:
https://github.com/zorker/rothui/blo...UF_Harmony.lua

On top of that make sure to check out the wow api changes for legion regarding that topic:
http://www.wowinterface.com/forums/s...ad.php?t=53140

Taking a look at rClassBars may help out aswell.
http://www.wowinterface.com/download...ClassBars.html
Hi zork,

Thank you for those nice references, and let me ask step by step.


About Default "classicon.lua":

1. On default oUF's default "classicon.lua" there is "PreUpdate" and "PostUpdate" functions. I understand when they are triggered, but ain't sure of what they actually process. Could you please explain me, if you know about them?


About your "oUF_Harmony.lua":

2. On your "oUF_Harmony.lua", it contains the following codes:
Lua Code:
  1. local w = 64*(max+2)
  2. bar:SetWidth(w)
  3. for i = 1, bar.maxOrbs do
  4.   local orb = self.Harmony[i]
  5.   if i > max then
  6.      if orb:IsShown() then orb:Hide() end
  7.   else
  8.     if not orb:IsShown() then orb:Show() end
  9.   end
  10. end
  11. for i = 1, max do
  12.   local orb = self.Harmony[i]
  13.   local full = num/max
  14.   if(i <= num) then
  15.     if full == 1 then
  16.       orb.fill:SetVertexColor(1,0,0)
  17.       orb.glow:SetVertexColor(1,0,0)
  18.     else
  19.       orb.fill:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  20.       orb.glow:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  21.     end
  22.     orb.fill:Show()
  23.     orb.glow:Show()
  24.     orb.highlight:Show()
  25.   else
  26.     orb.fill:Hide()
  27.     orb.glow:Hide()
  28.     orb.highlight:Hide()
  29.   end
  30. end

If I'm going set the appearance of "Chi Orbs" outside of this module, do I still have to have

local w = 64*(max+2)
bar:SetWidth(w)

and

second "for" loop?

3. Where does "bar.maxOrbs" come from?

4. How does "ForceUpdate" and "Path" functions work?

5. On "ForceUpdate" function and "Enable" function, there is "element.__owner". Does "__" mean something special in Lua when you are indexing an element from table?




Please excuse me if I'm asking too many questions.
  Reply With Quote
02-24-16, 04:18 AM   #4
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
1. Pre and Postupdate are hook functions. They let you manipulate values in case you need to do that to make the function process data correctly. Example you can change the color PostUpdate.
2. My chi bar has textures that are left and right of the orbs. Orbs number is dynamic depending on talents and what not. Thus I need to make sure that if the number of orbs changes the final bar still looks good. See 3.
3. My max orb value is hardcoded upon bar creation. That number could have been 10 or 100, but you know. The less frames you create the better.
https://github.com/zorker/rothui/blo.../bars.lua#L204
4. When the visibility changes a force update is needed to trigger the power update. You are right that I may have not needed the Path function but it gives you the ability to define a an Override function for a specific element. Like...you spawn 2 chi orb bars for example and want one to behave differently on update. That is where override is needed.
5. Nothing special. Just a prefix haste was using for the root element. (each bar is anchored to a root frame aka owner)
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
02-24-16, 07:10 PM   #5
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by zork View Post
1. Pre and Postupdate are hook functions. They let you manipulate values in case you need to do that to make the function process data correctly. Example you can change the color PostUpdate.
2. My chi bar has textures that are left and right of the orbs. Orbs number is dynamic depending on talents and what not. Thus I need to make sure that if the number of orbs changes the final bar still looks good. See 3.
3. My max orb value is hardcoded upon bar creation. That number could have been 10 or 100, but you know. The less frames you create the better.
https://github.com/zorker/rothui/blo.../bars.lua#L204
4. When the visibility changes a force update is needed to trigger the power update. You are right that I may have not needed the Path function but it gives you the ability to define a an Override function for a specific element. Like...you spawn 2 chi orb bars for example and want one to behave differently on update. That is where override is needed.
5. Nothing special. Just a prefix haste was using for the root element. (each bar is anchored to a root frame aka owner)
2. So, the purpose of following lines of code in "oUF_Harmony.lua":

Lua Code:
  1. local w = 64*(max+2)
  2. bar:SetWidth(w)

and

Lua Code:
  1. for i = 1, max do
  2.   local orb = self.Harmony[i]
  3.   local full = num/max
  4.   if(i <= num) then
  5.     if full == 1 then
  6.       orb.fill:SetVertexColor(1,0,0)
  7.       orb.glow:SetVertexColor(1,0,0)
  8.     else
  9.       orb.fill:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  10.       orb.glow:SetVertexColor(bar.color.r,bar.color.g,bar.color.b)
  11.     end
  12.     orb.fill:Show()
  13.     orb.glow:Show()
  14.     orb.highlight:Show()
  15.   else
  16.     orb.fill:Hide()
  17.     orb.glow:Hide()
  18.     orb.highlight:Hide()
  19.   end
  20. end

is to re-size the bar's width when there is a update on talent or spec which affects the max number of chi.

Am I getting it right?


6. Also, I still don't get why I can't get a "UnitPowerMax("player", SPELL_POWER_CHI)" doesn't work on Player Login...

I have read through about Legion's API Change that you wrote, but since that is being applied from Legion, I don't think this issue is related to that yet.

7.(???) Did you make those textures by yourself?

They look so cool !!

Last edited by jeAz_ : 02-24-16 at 10:32 PM.
  Reply With Quote
02-25-16, 02:46 AM   #6
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
2. Yes
6. I had some issues with ouf element registration aswell. That is why I am doing nasty things like this
https://github.com/zorker/rothui/blo...armony.lua#L90
Not sure why the event is not firing properly for the element.
7. Yes, I made the textures myself in the process of creating Roth UI. Some of them are based on Blizzard art, some of them are made from scratch.
__________________
| Simple is beautiful.
| WoWI AddOns | GitHub | Zork (WoW)

"I wonder what the non-pathetic people are doing tonight?" - Rajesh Koothrappali (The Big Bang Theory)
  Reply With Quote
02-25-16, 04:19 AM   #7
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by zork View Post
2. Yes
6. I had some issues with ouf element registration aswell. That is why I am doing nasty things like this
https://github.com/zorker/rothui/blo...armony.lua#L90
Not sure why the event is not firing properly for the element.
7. Yes, I made the textures myself in the process of creating Roth UI. Some of them are based on Blizzard art, some of them are made from scratch.
6. I actually tried this outside oUF (created another lua file) and it had same issues. Like what you did, I had to create a helper frame to get the value from UnitPowerMax("player", SPELL_POWER_CHI).

However, the problem is that I don't know how I should pull out the value that I got from event function.

Here's what it currently looks like.

Lua Code:
  1. local Helper = CreateFrame("Frame");
  2. local _, Class = UnitClass("player");
  3.  
  4. PowerMax = nil;
  5. PowerType = {
  6.     Paladin = SPELL_POWER_HOLY_POWER,
  7.     Monk = SPELL_POWER_CHI,
  8.     Priest = SPELL_POWER_SHADOW_ORBS,
  9.     Warlock = SPELL_POWER_SOUL_SHARDS,
  10. };
  11.  
  12. D.A["RegEvent"](Helper, "PLAYER_LOGIN");
  13.  
  14. Helper:SetScript("OnEvent", function(self, event, ...)
  15.     if (event == "PLAYER_LOGIN") then
  16.         PowerMax = UnitPowerMax("player", PowerType[D.A.FirstToUpper(Class)]);
  17.     end
  18. end);

Since those two PowerMax variables have different scope, it is not working as I expectd
  Reply With Quote
02-25-16, 07:53 AM   #8
zork
A Pyroguard Emberseer
 
zork's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 1,740
Well. If I had to write a unified class bar element today I would probably start with sth like this.

config.lua
Lua Code:
  1. --addonName, addonTable (namespace)
  2. local an, at = ...
  3.  
  4. --------------------------
  5. --CONFIG
  6. --------------------------
  7.  
  8. at.cfg = at.cfg or {}
  9.  
  10. at.cfg.monk_windwalker = {
  11.   class = "MONK",
  12.   power_type_token = "CHI",
  13.   power_type_index = SPELL_POWER_CHI,
  14.   req_spec = SPEC_MONK_WINDWALKER,
  15.   req_spell = nil,
  16.   width = 100,
  17.   height = 10,
  18.   scale = 1,
  19.   texture = "Interface\\AddOns\\etc\\pp",
  20.   point = {"CENTER",0,0}
  21.   color = {1,0.5,0,1}
  22. }

core.lua
Lua Code:
  1. --addonName, addonTable (namespace)
  2. local an, at = ...
  3.  
  4. --------------------------
  5. --CORE
  6. --------------------------
  7.  
  8. at.core = at.core or {}
  9. at.core.playerClass = select(2, UnitClass("player"))
  10.  
  11. --------------------------
  12. --FUNCTIONS
  13. --------------------------
  14.  
  15. --update func
  16. local function Update(...)
  17.  
  18.   local bar,event,unit,token = ...
  19.  
  20.   if not bar:IsShown() then return end
  21.   if not unit or (unit and unit ~= bar.unit) then return end
  22.   if powerType and powerType ~= bar.cfg.power_type_token then return end
  23.  
  24.   bar.upc1 = UnitPower(unit, bar.cfg.power_type_index)
  25.   bar.upc2 = UnitPower(unit, bar.cfg.power_type_index, true)
  26.   bar.upm1 = UnitPowerMax(unit, bar.cfg.power_type_index)
  27.   bar.upm2 = UnitPowerMax(unit, bar.cfg.power_type_index, true)
  28.  
  29.   bar:SetMinMaxValues(0, bar.upm2)
  30.   bar:SetValue(bar.upc2)
  31.  
  32.   if bar.PostUpdate then
  33.     bar.PostUpdate(...)
  34.   end
  35.  
  36. end
  37.  
  38. --event func
  39. local function Event(...)
  40.   local bar, event = ...
  41.   if event == "UNIT_POWER_FREQUENT" then
  42.     Update(...)
  43.   else
  44.     --has spell?
  45.     if bar.cfg.req_spell then
  46.       if IsPlayerSpell(bar.cfg.req_spell) then
  47.         bar:Show()
  48.       else
  49.         bar:Hide()
  50.       end
  51.     --has spec?
  52.     elseif bar.cfg.req_spec then
  53.       if GetSpecialization() ==  bar.cfg.req_spec then
  54.         bar:Show()
  55.       else
  56.         bar:Hide()
  57.       end
  58.     end
  59.     Update(bar,event,bar.unit,bar.cfg.power_type_token)
  60.   end
  61. end
  62.  
  63. --create func
  64. local function Create(cfg)
  65.  
  66.   if at.core.playerClass ~= cfg.class then return end
  67.  
  68.   local bar = CreateFrame("StatusBar", name, UIParent)
  69.   bar.cfg = cfg
  70.  
  71.   bar.unit = "player"
  72.   bar:RegisterUnitEvent("UNIT_POWER_FREQUENT", bar.unit)
  73.   bar:RegisterUnitEvent("UNIT_DISPLAYPOWER", bar.unit)
  74.   bar:RegisterEvent("SPELLS_CHANGED")
  75.   bar:SetScript("OnEvent", Event)
  76.  
  77.   return bar
  78.  
  79. end
  80.  
  81. at.core.Create = Create

chibar.lua
Lua Code:
  1. --addonName, addonTable (namespace)
  2. local an, at = ...
  3. --------------------------
  4. --CALL for Windwalker Monk
  5. --------------------------
  6.  
  7. local cfg = at.cfg.monk_windwalker
  8.  
  9. if at.core.playerClass == cfg.class then
  10.  
  11.   --create the bar
  12.   local bar = at.core.Create(cfg)
  13.  
  14.   --chibar PostUpdate
  15.  
  16.   local function ChiBarPostUpdate(...)
  17.     print("ChiBarPostUpdate",...)
  18.   end
  19.  
  20.   --style the bar
  21.   bar:SetWidth(cfg.width)
  22.   bar:SetHeight(cfg.height)
  23.   bar:SetScale(cfg.scale)
  24.   bar:SetStatusBarTexture(cfg.texture)
  25.   bar:SetPoint(unpack(cfg.point))
  26.   bar:SetStatusBarColor(unpack(cfg.color))
  27.  
  28.   bar.PostUpdate = ChiBarPostUpdate
  29.  
  30. end

Basically you have 3 core functions for creation, eventHandling and updating. Additionally those functions only handle the events and leave the styling out. Thus you can do any styling later on via PostUpdate. You can even add orbs or stuff like that later on by creating them as a child of the bar element and create them on the fly via PostUpdate.
__________________
| 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-25-16 at 08:18 AM.
  Reply With Quote
02-25-16, 08:02 AM   #9
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by zork View Post
6. I had some issues with ouf element registration aswell. That is why I am doing nasty things like this
https://github.com/zorker/rothui/blo...armony.lua#L90
Not sure why the event is not firing properly for the element.
All elements are updated with the event "OnShow" during PLAYER_LOGIN, and is also updated on "PLAYER_ENTERING_WORLD".
  Reply With Quote
02-25-16, 08:31 AM   #10
jeAz_
A Deviate Faerie Dragon
Join Date: Feb 2016
Posts: 13
Originally Posted by zork View Post
Basically you have 3 core functions for creation, eventHandling and updating. Additionally those functions only handle the events and leave the styling out. Thus you can do any styling later on via PostUpdate. You can even add orbs or stuff like that later on by creating them as a child of the bar element and create them on the fly via PostUpdate.
That's amazing!!

Now I can study more about lua with what you just provided

I actually gotta go and have some rest now since I have been staring at monitor for about 12 hours...

I'll have a look at it tomorrow and see how I go with your example

Thank you!
  Reply With Quote
02-26-16, 06:26 AM   #11
sezz
A Chromatic Dragonspawn
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 158
PostUpdate tells you when max power has changed:

https://github.com/haste/oUF/blob/ma...classicons.lua
Lua Code:
  1. --[[ :PostUpdate(cur, max, hasMaxChanged, event)
  2.      Called after the element has been updated
  3.      Arguments
  4.      self          - The ClassIcons element
  5.      cur           - The current amount of power
  6.      max           - The maximum amount of power
  7.      hasMaxChanged - Shows if the maximum amount has changed since the last
  8.                      update
  9.      event         - The event, which the update happened for
  10.     ]]

Lua Code:
  1. local PostUpdateClassIcons = function(self, cur, max, oldMaxChanged)
  2.     if (oldMaxChanged) then
  3.         -- resize/move/whatever
  4.     end
  5. end
  6.  
  7. yourClassIcons.PostUpdate = PostUpdateClassIcons

If you don't want to use PostUpdate, I use ACTIVE_TALENT_GROUP_CHANGED, UNIT_MAXPOWER and PLAYER_TALENT_UPDATE to determine if max power has changed in my power bars addon. And also PLAYER_LEAVING_WORLD and PLAYER_ENTERING_WORLD, because while zoning UnitPowerMax sometimes returns 0 (atleast it did 2 years ago). But it's propably easier to just use the PostUpdate hook, because it's already there and works fine.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » oUF - ClassIcons


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