WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Druid power value not changing color on shapeshift (https://www.wowinterface.com/forums/showthread.php?t=51908)

Sauerkraut 02-14-15 04:33 PM

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?

Phanx 02-14-15 08:02 PM

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.

Sauerkraut 02-14-15 10:47 PM

Quote:

Originally Posted by Phanx (Post 306484)
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

Quote:

Originally Posted by Phanx (Post 306484)
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.

Quote:

Originally Posted by Phanx (Post 306484)
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.

Quote:

Originally Posted by Phanx (Post 306484)
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.

Sauerkraut 02-15-15 10:53 AM

Here is a short video I made to show the problem. Not sure if it will help any.

http://youtu.be/Fy4h8hXgdYA

p3lim 02-15-15 01:27 PM

Show your whole code, everything. We have no idea what the variables are.

Sauerkraut 02-15-15 04:36 PM

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.

p3lim 02-15-15 05:46 PM

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.

Sauerkraut 02-15-15 07:40 PM

Quote:

Originally Posted by p3lim (Post 306503)
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?

p3lim 02-16-15 03:39 AM

Quote:

Originally Posted by Sauerkraut (Post 306504)
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.

Sauerkraut 02-16-15 07:59 AM

Quote:

Originally Posted by p3lim (Post 306511)
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.


All times are GMT -6. The time now is 11:51 PM.

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