Thread Tools Display Modes
02-14-15, 04:33 PM   #1
Sauerkraut
A Wyrmkin Dreamwalker
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 52
Druid power value not changing color on shapeshift

I've noticed a rather irritating issue with my unit frames. When I switch from caster to cat the color of the power text does not update with the bar. To clarify this is only when shifting. Upon using any ability in cat form the text changes to the proper color. (See attached image)


Here is the code used to color the text

Lua Code:
  1. local text = lib.gen_fontstring(f.Health, cfg.font, 18, "OUTLINE")
  2.             text:SetPoint("RIGHT", s.arrow, "LEFT", 6, -8)
  3.             s:HookScript("OnValueChanged", function(self, value)
  4.            
  5.             if (value >= 1e3) then
  6.             text:SetFormattedText("%.1fk", value / 1e3, 0)
  7.             else
  8.             text:SetFormattedText("%d", value, 0)
  9.             end
  10.            
  11.             local r, g, b = s:GetStatusBarColor()
  12.             text:SetTextColor(r, g, b)
  13.             text:SetJustifyH("RIGHT")

S is the power bar in this case. Does anyone have any suggestions as to how I can force it to change on shape shift?
  Reply With Quote
02-14-15, 08:02 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Using an actual hook to set the power text is pretty hack-y... you should really just use a PostUpdate function:
Code:
local text = lib.gen_fontstring(f.Health, cfg.font, 18, "OUTLINE")
text:SetPoint("RIGHT", s.arrow, "LEFT", 6, -8)

s.text = text
s.PostUpdate = function(self, unit, value, maxvalue, minvalue)
      local r, g, b = self:GetStatusBarColor()
      if (value >= 1e3) then
            self.text:SetFormattedText("|cff%02x%02x%02x%.1fk", r * 255, g * 255, b * 255, value / 1e3)
      else
            self.text:SetFormattedText("|cff%02x%02x%02x%d", r * 255, g * 255, b * 255, value)
      end
end
On a side note, I don't know what that 0 you were passing to SetFormattedText was supposed to do... SetFormattedText takes the same arguments as string.format, so if your pattern (arg1) is "%d" then only one further argument will have any effect.

You also don't need to explicitly set the justification; if your font string only has one anchor point (eg. RIGHT), it will always grow away from that point (eg. towards the left) no matter what justification (if any) is set on it.

Another option would be to use a tag, but the "do it yourself" approach is more efficient in this case since the current power value is already available in the PostUpdate function without needing to call UnitPower again.
__________________
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
02-14-15, 10:47 PM   #3
Sauerkraut
A Wyrmkin Dreamwalker
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 52
Originally Posted by Phanx View Post
Using an actual hook to set the power text is pretty hack-y... you should really just use a PostUpdate function:
The HookScript function is used to get a smooth power value transition. The original discussion is available here: http://www.wowinterface.com/forums/s...ad.php?t=45676

Originally Posted by Phanx View Post
Code:
local text = lib.gen_fontstring(f.Health, cfg.font, 18, "OUTLINE")
text:SetPoint("RIGHT", s.arrow, "LEFT", 6, -8)

s.text = text
s.PostUpdate = function(self, unit, value, maxvalue, minvalue)
      local r, g, b = self:GetStatusBarColor()
      if (value >= 1e3) then
            self.text:SetFormattedText("|cff%02x%02x%02x%.1fk", r * 255, g * 255, b * 255, value / 1e3)
      else
            self.text:SetFormattedText("|cff%02x%02x%02x%d", r * 255, g * 255, b * 255, value)
      end
end
On a side note, I don't know what that 0 you were passing to SetFormattedText was supposed to do... SetFormattedText takes the same arguments as string.format, so if your pattern (arg1) is "%d" then only one further argument will have any effect.
Thank you I will fix that.

Originally Posted by Phanx View Post
You also don't need to explicitly set the justification; if your font string only has one anchor point (eg. RIGHT), it will always grow away from that point (eg. towards the left) no matter what justification (if any) is set on it.
Thank you I was unaware of this.

Originally Posted by Phanx View Post
Another option would be to use a tag, but the "do it yourself" approach is more efficient in this case since the current power value is already available in the PostUpdate function without needing to call UnitPower again.
I think trying to work the smooth power value transitions out in a tag may be more work than what I am doing now. This particular text is only used on the player frame. All other frames are handled by tags.

I have tried the code you posted, thank you for that. It didn't however seem to work. I didn't get any errors, but there was no output. I will fiddle with it some more see if I can figure out what I am doing wrong.
  Reply With Quote
02-15-15, 10:53 AM   #4
Sauerkraut
A Wyrmkin Dreamwalker
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 52
Here is a short video I made to show the problem. Not sure if it will help any.

http://youtu.be/Fy4h8hXgdYA
  Reply With Quote
02-15-15, 01:27 PM   #5
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Show your whole code, everything. We have no idea what the variables are.
  Reply With Quote
02-15-15, 04:36 PM   #6
Sauerkraut
A Wyrmkin Dreamwalker
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 52
Here is the whole power bar code section

Lua Code:
  1. --gen powerbar func
  2.   lib.gen_ppbar = function(f)
  3.     --statusbar
  4.     local s = CreateFrame("StatusBar", nil, f)
  5.     s:SetStatusBarTexture(cfg.powerbar_texture)
  6.     fixStatusbar(s)
  7.     if f.mystyle == "player" or f.mystyle == "pet" then
  8.         s:SetHeight(16)
  9.         s:SetWidth(f:GetWidth())
  10.         s:SetPoint("TOP",f,"TOP",8,0)
  11.     else
  12.         s:SetHeight(retVal(f,16,14,10))
  13.         s:SetWidth(f:GetWidth())
  14.         s:SetPoint("TOP",f,"TOP",6,0)
  15.     end
  16.     s:SetFrameLevel(1)
  17.  
  18.     --helper
  19.     local h = CreateFrame("Frame", nil, s)
  20.     h:SetFrameLevel(0)
  21.     h:SetPoint("TOPLEFT",-5,5)
  22.     h:SetPoint("BOTTOMRIGHT",5,-5)
  23.     lib.gen_backdrop(h)
  24.     --bg
  25.     local b = s:CreateTexture(nil, "BACKGROUND")
  26.     b:SetTexture(cfg.powerbar_texture)
  27.     b:SetAllPoints(s)
  28.     --arrow
  29.     if f.mystyle ~= "tot" and f.mystyle ~= "failRaid" and f.mystyle ~= "pet" then
  30.         s.arrow = s:CreateTexture(nil, "OVERLAY")
  31.         s.arrow:SetTexture([[Interface\Addons\oUF_Fail\media\textureArrow]])
  32.         s.arrow:SetSize(16,16)
  33.         s.arrow:SetPoint("BOTTOM", s:GetStatusBarTexture(), "RIGHT", 0, retVal(f,9,9,6))
  34.         fixTex(s.arrow)
  35.  
  36.         if f.mystyle == "player" then
  37.         --== smooth power text for player==--  
  38.             local text = lib.gen_fontstring(f.Health, cfg.font, 18, "OUTLINE")
  39.             text:SetPoint("RIGHT", s.arrow, "LEFT", 6, -8)
  40.  
  41.             s:HookScript("OnValueChanged", function(self, value)
  42.                 local r, g, b = s:GetStatusBarColor()
  43.                 if (value >= 1e3) then
  44.                     text:SetFormattedText("|cff%02x%02x%02x%.1fk", r * 255, g * 255, b * 255, value / 1e3)
  45.                 else
  46.                     text:SetFormattedText("|cff%02x%02x%02x%d", r * 255, g * 255, b * 255, value)
  47.                 end
  48.             end)
  49.  
  50.         else
  51.         --==regular power text for everyone else==--
  52.             local powertext = lib.gen_fontstring(f.Health, cfg.font, 18, "OUTLINE")
  53.             powertext:SetPoint("RIGHT", s.arrow, "LEFT", 6, -8)
  54.             --powertext:SetJustifyH("RIGHT")
  55.             f:Tag(powertext, "[fail:pp]")
  56.         end
  57.         --==No arrows for raid and boss==--
  58.         if f.mystyle ~="raid" and f.mystyle ~="failBoss" then
  59.             f:Tag(powa, "[fail:pp]")
  60.         end
  61.        
  62.     if cfg.ShowExtraUnitArrows == "true" then
  63.         s.arrow:Show()
  64.     else
  65.         s.arrow:Hide()
  66.     end
  67.     end
  68.  
  69.     f.Power = s
  70.     f.Power.bg = b
  71. end

Thank you and please let me know if you need any more or anything else. Excuse my noobness I'm in no way a programmer.
  Reply With Quote
02-15-15, 05:46 PM   #7
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
I was looking for where and when you actually set the colors for the power bar.
I'm guessing it's set after the OnValueChanged/PostUpdate fires, which is why you don't see it update.
  Reply With Quote
02-15-15, 07:40 PM   #8
Sauerkraut
A Wyrmkin Dreamwalker
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 52
Originally Posted by p3lim View Post
I was looking for where and when you actually set the colors for the power bar.
I'm guessing it's set after the OnValueChanged/PostUpdate fires, which is why you don't see it update.
I follow. You are correct I believe that it is set after. Is there a better way to set the text color aside from grabbing the color of the bar?
  Reply With Quote
02-16-15, 03:39 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 Sauerkraut View Post
I follow. You are correct I believe that it is set after. Is there a better way to set the text color aside from grabbing the color of the bar?
You can set them at the same time in the same function using the same values.
Basically, move the coloring of your text to where you color your bar.
  Reply With Quote
02-16-15, 07:59 AM   #10
Sauerkraut
A Wyrmkin Dreamwalker
 
Sauerkraut's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 52
Originally Posted by p3lim View Post
You can set them at the same time in the same function using the same values.
Basically, move the coloring of your text to where you color your bar.
Thank you p3lim I will try that.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Druid power value not changing color on shapeshift

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