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? |
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 :)
|
Quote:
As for the health text I use this code currently: Code:
hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function() |
1. You will have to write your own AbbreviateLargeNumbers function for it.
lua Code:
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? :) |
Quote:
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. |
Oh, thank you, Phanx. Is there a good resource for all this stuff? I always suck at efficiency.
|
How do I use the code you wrote?
I'm pretty new to Lua. |
1. Go to http://addon.bool.no/
2. Copy this code and paste it in the box on that page: Code:
hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax) You can remove the comments in the above code if you want to keep it shorter. If you only want to see whole numbers (eg. 157k or 12m) and never decimals (eg. 12.8m or 13.4k) use this code instead: Code:
hooksecurefunc("TextStatusBar_UpdateTextStringWithValues", function(statusBar, fontString, value, valueMin, valueMax) |
Quote:
|
Quote:
|
Fixed; I'd copied the code from my unitframes addon, but forgot to change that variable name.
|
It works, thanks you very much :-D
Sometimes I raid, and then percentage hp is very useful. So I thought of making a slashcommand: /pct to turn on percentage hp, since this can't be done in the interface options because this code disregards those settings. So current hp is default and when /pct is run it will run for the session only (until /reload etc.) Is this possible to do? |
1. Add this line to your addon's TOC file:
Code:
## SavedVariables: MyCustomTextFormat Code:
MyCustomTextFormat = "VALUE" |
Thank you Phanx you're very helpful :)
Can you make it update the values when you run the command somehow? Else you need to /rl, lose health, or gain health for it to update with your new setting (at least for your own frame). |
I would just modify it to use the setting from the interface by checking if GetCVar("statusTextDisplay") is "PERCENT", "NUMERIC" or "BOTH".
|
Here's a version that will use your CVar setting instead, as suggested by Semlar. I also converted the growing if-else chain into an easier-to-maintain indexed table loop:
Code:
local shorts = { |
I changed a little bit:
Code:
local shorts = { I can't get the SetCVar to work, it doesn't change the CVar. It displays numeric health when it is set to BOTH I don't know if this is intentional, since I do not understand what this line: Code:
if value >= t[1] then I also tried changing: Code:
{ 1e9, 1e9, "%.1fb" }, -- 1b+ as 8.3b Code:
{ 1e9, 1e9, "% . 1fb" }, -- 1b+ as 8 . 3b Also, in my country we use comma, I know of :gsub('%.', ',') but can it be used here? |
t[1] equals shorts[i][1] (i.e. 1e10, 1e9 and so on) where i is the running index in the for loop. The meaning is to compare your current health value with t[1] so you don't end with 0.9k instead of 900.
SetFormattedText works just like lua's own format which in turn is based of C's printf. http://www.cplusplus.com/reference/cstdio/printf/ is a good reference. In order to produce language dependant output, you'll have to use gsub I believe Something like that should work: Code:
fontString:SetText(format(t[3], value/t[2]):gsub("%.", " , ")) As for your slash command: The upvalue style is initialized when the file is first processed by the game. It takes the value of statusTextDisplay at this time and does not change later. You either have to call GetCVar("statusTextDisplay") in your slash command function or reassign style after calling SetCVar("statusTextDisplay", "whatever") |
Okay it is more readable now and the CVar actually does change.
I still have the problem from earlier though: By changing the CVar this way the frames do not update in order to reflect the new change, so you have to re-target, lose/gain hp, etc. If I do change it through the Interface menu it does update. Edit: I am onto something! Code:
/click InterfaceOptionsStatusTextPanelDisplayDropDownButton Edit2: It works! Code:
SLASH_HP1 = "/hp" |
The reason for this behavior is that Blizzard updates the status texts when CVAR_UPDATE fires. This event does not (always?) fire when using SetCVar, unless you provide a third argument, typically your addon name. You could skip the
Code:
InterfaceOptionsStatusTextPanelDisplayDropDownButton:Click(); Code:
SetCVar("statusTextDisplay", "whatever_value_you_need", "HP") |
All times are GMT -6. The time now is 10:02 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI