Thread Tools Display Modes
07-23-13, 10:49 AM   #1
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
3 Questions

http://i.imgur.com/zI9jLCR.jpg

1.
How do I change the value for health to be shortened?
For example, in the screenshot my health is 113k and my target is 2482.
How do I change it so it shortens from 999 and up?

2.
As seen on the screenshot the texture on the EXP bar is thicker on the bottom of it compared to the top.
Can I either make it as thin as on the top side or simply remove the border completely?

Last edited by laukond : 07-23-13 at 12:09 PM. Reason: Found the answer to the 3. question
  Reply With Quote
07-23-13, 01:34 PM   #2
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
Can you provide some info about what UI this is, and/or if you are writing some addon yourself, please provide code to look at
  Reply With Quote
07-23-13, 01:37 PM   #3
laukond
A Black Drake
Join Date: Dec 2011
Posts: 87
Originally Posted by ravagernl View Post
Can you provide some info about what UI this is, and/or if you are writing some addon yourself, please provide code to look at
It's blizzard UI with lots of zzzz:SetAlpha(0);

As for the health text I use this code currently:
Code:
	hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function()
        PlayerFrameHealthBar.TextString:SetText(AbbreviateLargeNumbers(UnitHealth("player")))
        PlayerFrameManaBar.TextString:SetText(AbbreviateLargeNumbers(UnitMana("player")))
		-- PlayerFrameAlternateManaBar.TextString:SetText(AbbreviateLargeNumbers(UnitPower("player")))
		
        TargetFrameHealthBar.TextString:SetText(AbbreviateLargeNumbers(UnitHealth("target")))
        TargetFrameManaBar.TextString:SetText(AbbreviateLargeNumbers(UnitMana("target")))

        FocusFrameHealthBar.TextString:SetText(AbbreviateLargeNumbers(UnitHealth("focus")))
        FocusFrameManaBar.TextString:SetText(AbbreviateLargeNumbers(UnitMana("focus")))
		
		
	end)
  Reply With Quote
07-23-13, 04:31 PM   #4
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
1. You will have to write your own AbbreviateLargeNumbers function for it.
lua Code:
  1. local SiValue = function(val)
  2.     if (val >= 1e6) then
  3.         return ("%.1fm"):format(val / 1e6)
  4.     elseif (val >= 1e3) then
  5.         return ("%.1fk"):format(val / 1e3)
  6.     else
  7.         return val
  8.     end
  9. end
would be a simple example without using blizzard's separators.

2. I'm not sure what's the texture shown there, but it might be these:
MainMenuXPBarTextureLeftCap
MainMenuXPBarTextureRightCap
MainMenuXPBarTextureMid
(Those are global names)
If so, you could use MainMenuXPBarTextureLeftCap:SetTexture(nil) and so on or play with SetTexCoords to make the border suit your needs. You might have to hook MainMenuExpBar_SetWidth as well.

Apart from that, when you use hooksecurefunc, your hook will be called with the same arguments as the function you hook to. In the case of TextStatusBar_UpdateTextStringWithValues those are:
statusFrame - StatusBar - the status bar the text is being changed on (i.e. PlayerFrameHealthBar)
textString - FontString - the text being changed (i.e. PlayerFrameHealthBar.TextString)
value - number - the current value of the statusbar (probably the same as the return of UnitHealth("player") +/- some negligible lag, if the func is being called for the player)
valueMin - number - the min value of the statusbar (probably 0)
valueMax - number - the max value of the statusbar (probably the same as the return of UnitMaxHealth("player") +/- some negligible lag, if the func is being called for the player)

By using those you could spare yourself some global look-ups and only update when there is need to and not all player, target and focus every time TextStatusBar_UpdateTextStringWithValues has been called.

Edit: By the way, what is the third question?

Last edited by Rainrider : 07-23-13 at 04:33 PM.
  Reply With Quote
07-23-13, 10:56 PM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by Rainrider View Post
lua Code:
  1. local SiValue = function(val)
  2.     if (val >= 1e6) then
  3.         return ("%.1fm"):format(val / 1e6)
  4.     elseif (val >= 1e3) then
  5.         return ("%.1fk"):format(val / 1e3)
  6.     else
  7.         return val
  8.     end
  9. end
would be a simple example without using blizzard's separators.
Just FYI, ("%d"):format(5) is slower than format("%d", 5) even if you don't upvalue format. If you do upvalue the global format, then format("%d", 5) is faster by a huge margin.

The only time you should use slower method syntax is if you're chaining a lot of operations together and want to keep it more human-readable, eg. ("blah blah %d blah"):format(5):upper():sub(8):gsub("a", "x")

Even small differences in speed can really add up in code that's run often, like inside a function that's formatting text every time a unit's health changes.
__________________
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
07-24-13, 05:18 PM   #6
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Oh, thank you, Phanx. Is there a good resource for all this stuff? I always suck at efficiency.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » 3 Questions


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