View Single Post
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