View Single Post
09-17-17, 10:54 PM   #6
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
Nope, you are correct, got it in one!

After testing with randomly assigned colours, yes, because the actual increase is too subtle or small, I did learn the colour was updating, so that was a great tip!

Turns out there is another bug that revealed itself, but that is more to do with how I am getting the values of currentXP and maximumXP and thus the average. That is clearly an ElvUI thing, so I have asked on their forums.

In any case, you guys solved my xp vs bar colour issue, and I definitely learned something. The random test was truly amazing, so thank you!

I further took the suggestion to adjust the scope of my variables, so that was appreciated. And since trying to make the XP status bar look all blue when at max level wasn't working, I took that code out, and also used SetText() directly without a variable. And finally, I knocked the rounding decimal to 1 so it should look like 0.6 instead of 0.59 or the like.

All good and useful stuff, thank you everybody!

For anyone else, yes, apparently you can assign dynamic colours to a status bar. Here is the finished code, albeit with the current/maximum/average bug intact. But as I mentioned, that is something I'm doing wrong with the ElvUI returns.
Lua Code:
  1. local function UpdateExperience(self, event)
  2.     if not E.db.PCB.enabled then return end
  3.  
  4.     local bar = self.expBar
  5.     local isMaxLevel = UnitLevel("player") == MAX_PLAYER_LEVEL_TABLE[GetExpansionLevel()]
  6.  
  7.     if isMaxLevel and E.db.PCB.experienceBar.capped then
  8.         bar.text:SetText(L["Capped"])
  9.     elseif E.db.PCB.experienceBar.progress and not isMaxLevel then
  10.         local current, maximum = self:GetXP("player") or 0, 0
  11.         local avg = current / maximum or 0
  12.         avg = PCB:Round(avg, 1)
  13.         bar.statusBar:SetStatusBarColor(0, 0, avg, 0.8)
  14.         --@debug@
  15.         local r = math.random(0, 1)
  16.         local g = math.random(0, 1)
  17.         local b = math.random(0, 1)
  18.         r = PCB:Round(r, 1)
  19.         g = PCB:Round(g, 1)
  20.         b = PCB:Round(b, 1)
  21.         bar.statusBar:SetStatusBarColor(r, g, b, 0.8)
  22.         print("The average XP is %d"):format(avg)
  23.         --@end-debug@
  24.     end
  25. end
  Reply With Quote