WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   What's the proper way to update color of last class power bar? (https://www.wowinterface.com/forums/showthread.php?t=58545)

devilArt 01-13-21 01:49 AM

What's the proper way to update color of last class power bar?
 
This is my PostUpdate code for classpower

lua Code:
  1. local function PostUpdateClassPower(element, cur, max, hasMaxChanged, powerType)
  2.     local style = element.__owner.unitStyle
  3.     local gap = 3
  4.     local maxWidth
  5.  
  6.     if style == 'player' then
  7.         maxWidth = C.DB.unitframe.player_width
  8.     else
  9.         maxWidth = C.DB.nameplate.pp_width
  10.     end
  11.  
  12.     if hasMaxChanged then
  13.         for i = 1, max do
  14.             element[i]:SetWidth((maxWidth - (max - 1) * gap) / max)
  15.         end
  16.  
  17.         element[max]:SetStatusBarColor(unpack(lastBarColors[C.MyClass]))
  18.     end
  19. end

When I log into the game for the first time


After /reload it returns to normal


Dose anyone konw the reason?

neverg 01-16-21 07:38 AM

I'm currently re-writing my layout / UI, but on my old layout, I did this:

https://github.com/greven/oUF_Lumen/...tions.lua#L659

Lua Code:
  1. -- Colorize the last power color element
  2. local function SetMaxClassPowerColor(element, max, powerType)
  3.     if not element or not max then return end
  4.  
  5.     local color = element.__owner.colors.power.max[powerType]
  6.  
  7.     if element[max] and color then
  8.         local r, g, b = color[1], color[2], color[3]
  9.  
  10.         local LastBar = element[max]
  11.         LastBar:SetStatusBarColor(r, g, b)
  12.  
  13.         local bg = LastBar.bg
  14.         if (bg) then
  15.             local mu = bg.multiplier or 1
  16.             bg:SetColorTexture(r * mu, g * mu, b * mu)
  17.         end
  18.     end
  19. end
  20.  
  21. -- Post Update ClassPower
  22. local function PostUpdateClassPower(element, cur, max, diff, powerType)
  23.     local frame = element.__owner.mystyle
  24.  
  25.     if (diff) then
  26.         local maxWidth, gap = cfg.units[frame].width, 6
  27.  
  28.         for i = 1, max do
  29.             local Bar = element[i]
  30.             Bar:SetWidth(((maxWidth / max) - (((max - 1) * gap) / max)))
  31.  
  32.             if (i > 1) then
  33.                 Bar:ClearAllPoints()
  34.                 Bar:SetPoint("LEFT", element[i - 1], "RIGHT", gap, 0)
  35.             end
  36.         end
  37.     end
  38.  
  39.     SetMaxClassPowerColor(element, max, powerType)
  40. end


All times are GMT -6. The time now is 06:58 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI