ESOUI

ESOUI (https://www.esoui.com/forums/index.php)
-   AddOn Help/Support (https://www.esoui.com/forums/forumdisplay.php?f=164)
-   -   How to add thousands separator for existing addon? (https://www.esoui.com/forums/showthread.php?t=7280)

p6kocka 08/09/17 04:21 AM

How to add thousands separator for existing addon?
 
There is an addon "sidWarTools" which doesnīt have thousands separator on target label text. It is hard to read bigger numbers. How to add thousands separator for this addon?

there is a line in "target.lua":

local targetBarText = CreateControlFromVirtual(parent:GetName().."HpText1", parent, "ZO_UnitFrameBarText")
targetBarText:SetAnchor(TOP, nil, BOTTOM, 0, -22)
targetBarText:SetFont("ZoFontWinT2")
targetHealthBar.leftText = targetBarText


I īve tried to add this lines, but it doesnīt work.:

strformat('%s / %s (%d%%)', comma_value(current), comma_value(effMax), (current / effMax) * 100)

How to resolve this pls?

Ayantir 08/09/17 05:49 AM

Wait an update from the author, he knows the answer.

p6kocka 08/09/17 05:55 AM

Iīve already asked. I know, the answer can be very late, thatīs why Iīm asking here too.

Ayantir 08/09/17 06:36 AM

ZO_CommaDelimitNumber(number)

p6kocka 08/09/17 06:47 AM

Where to put it pls?

Rhyono 08/09/17 08:47 AM

I've never used it so I don't know anything about what it is displaying, but
targetHealthBar.leftText = targetBarText
writes the text to the bar. So what does targetBarText contain? If it's purely the number, then you can do:
targetHealthBar.leftText = ZO_CommaDelimitNumber(targetBarText)

If it isn't just the number, then you need to go back to the point where that is first created and ensure the number added to that text is formatted first.

p6kocka 08/09/17 10:07 AM

Adding this resolved to this lua error:

EsoUI/Libraries/Globals/Localization.lua:112: operator < is not supported for userdata < number
stack traceback:
EsoUI/Libraries/Globals/Localization.lua:112: in function 'ZO_CommaDelimitNumber'
user:/AddOns/sidWarTools/misc/AttributeBars.lua:209: in function 'InitializeTargetFrameHealthBar'
user:/AddOns/sidWarTools/misc/AttributeBars.lua:565: in function 'Initialize'
user:/AddOns/sidWarTools/StartUp.lua:59: in function 'callback'
user:/AddOns/sidWarTools/StartUp.lua:39: in function '(anonymous)'


EDIT:
and thatīs the whole text in this target lua:


local function InitializeTargetFrameHealthBar(saveData, dividerPool)
local activeDividers = {}

local HIDE_BAR_TEXT, SHOW_BAR_TEXT = 0, 2 -- keep synced with constants in unitframes.lua
local targetFrame = ZO_UnitFrames_GetUnitFrame(TARGET_UNIT_TAG)
local targetHealthBar = targetFrame.healthBar
local parent = targetFrame.frame
local barLeft = targetHealthBar.barControls[1]
local barRight = targetHealthBar.barControls[2]

local targetBarText = CreateControlFromVirtual(parent:GetName().."HpText1", parent, "ZO_UnitFrameBarText")
targetBarText:SetAnchor(TOP, nil, BOTTOM, 0, -22)
targetBarText:SetFont("ZoFontWinT2")
targetHealthBar.leftText = ZO_CommaDelimitNumber(targetBarText)

targetHealthBar.UpdateText = function(self)
if(self.showBarText == SHOW_BAR_TEXT) then
local shieldValue = GetUnitAttributeVisualizerEffectInfo(TARGET_UNIT_TAG, ATTRIBUTE_VISUAL_POWER_SHIELDING, STAT_MITIGATION, ATTRIBUTE_HEALTH, POWERTYPE_HEALTH)
local text = GetBarText(self.currentValue, shieldValue, self.maxValue, self.useDividerTextMode and saveData.dividerTextMode or saveData.generalTextMode)
self.leftText:SetText(text)
self.leftText:SetHidden(false)
else
self.leftText:SetHidden(true)
end
end

Rhyono 08/09/17 10:55 AM

The first part looks like it was the wrong part of the code then.

Code:

local text = GetBarText(self.currentValue, shieldValue, self.maxValue, self.useDividerTextMode and saveData.dividerTextMode or saveData.generalTextMode)
is likely the correct part.

I believe GetBarText() is a custom function. If it is, you'll have to find it and it'd likely be the place to modify the number display, unless the following works:


Code:

local text = GetBarText(ZO_CommaDelimitNumber(self.currentValue), ZO_CommaDelimitNumber(shieldValue), ZO_CommaDelimitNumber(self.maxValue), self.useDividerTextMode and saveData.dividerTextMode or saveData.generalTextMode)

p6kocka 08/09/17 11:10 AM

It seems it doesnīt work. Itś a pitty, because itīs hard to read for example this number on HP:
12256682

Rhyono 08/09/17 11:24 AM

Then you'll have to find GetBarText() and change it there, rather than the input to it.

p6kocka 08/09/17 11:42 AM

Found it:

WrapFunction(attributeBar.label, "SetText", function(originalSetText, self)
local shieldValue
if(hasShield) then
shieldValue = GetUnitAttributeVisualizerEffectInfo(PLAYER_UNIT_TAG, ATTRIBUTE_VISUAL_POWER_SHIELDING, STAT_MITIGATION, ATTRIBUTE_HEALTH, POWERTYPE_HEALTH)
end
local text = GetBarText(attributeBar.current, shieldValue, attributeBar.max, attributeBar.useDividerTextMode and saveData.dividerTextMode or saveData.generalTextMode)
originalSetText(self, text)
end)

p6kocka 08/09/17 12:06 PM

Iīve also discovered this one:

local function GetBarText(current, shieldValue, max, format)
if(format == TEXT_MODE_PERCENT) then
return GetPercentText(current, max)
elseif(format == TEXT_MODE_ABSOLUTE) then
return zo_strformat("<<1>> / <<2>>", current, max)
elseif(format == TEXT_MODE_BOTH) then
if(shieldValue and shieldValue > 0) then
return zo_strformat("<<1>> + <<2>> / <<3>> (<<4>> + <<5>>)", current, shieldValue, max, GetPercentText(current, max), GetPercentText(shieldValue, max))
else
return zo_strformat("<<1>> / <<2>> (<<3>>)", current, max, GetPercentText(current, max))
end
end
end

sirinsidiator 08/09/17 12:07 PM

Hi there,

The part you should edit is the GetBarText function in line 147 of misc/AttributeBars.lua. That's where the text is generated based on your addon settings.
In case you use the mode where only absolute numbers are shown you would want to change line 151 to
Lua Code:
  1. return zo_strformat("<<1>> / <<2>>", ZO_CommaDelimitNumber(current), ZO_CommaDelimitNumber(max))


For the next release, I can add additional options for how the numbers are formatted.
I am thinking about adding the choices "raw" (like it has been until now), "comma separated" and "shortened" (e.g. 100k).

Let me know what you think.

p6kocka 08/09/17 12:21 PM

OK. Iīve tried it. No luck. Iīll wait then for your update.
Wish you good evening


All times are GMT -6. The time now is 03:16 PM.

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