Thread Tools Display Modes
08/09/17, 04:21 AM   #1
p6kocka
Join Date: Apr 2014
Posts: 19
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?
  Reply With Quote
08/09/17, 05:49 AM   #2
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
Wait an update from the author, he knows the answer.
  Reply With Quote
08/09/17, 05:55 AM   #3
p6kocka
Join Date: Apr 2014
Posts: 19
Iīve already asked. I know, the answer can be very late, thatīs why Iīm asking here too.
  Reply With Quote
08/09/17, 06:36 AM   #4
Ayantir
 
Ayantir's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 1,019
ZO_CommaDelimitNumber(number)
  Reply With Quote
08/09/17, 06:47 AM   #5
p6kocka
Join Date: Apr 2014
Posts: 19
Where to put it pls?
  Reply With Quote
08/09/17, 08:47 AM   #6
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
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.
  Reply With Quote
08/09/17, 10:07 AM   #7
p6kocka
Join Date: Apr 2014
Posts: 19
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
  Reply With Quote
08/09/17, 10:55 AM   #8
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
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)
  Reply With Quote
08/09/17, 11:10 AM   #9
p6kocka
Join Date: Apr 2014
Posts: 19
It seems it doesnīt work. Itś a pitty, because itīs hard to read for example this number on HP:
12256682
  Reply With Quote
08/09/17, 11:24 AM   #10
Rhyono
AddOn Author - Click to view addons
Join Date: Sep 2016
Posts: 659
Then you'll have to find GetBarText() and change it there, rather than the input to it.
  Reply With Quote
08/09/17, 11:42 AM   #11
p6kocka
Join Date: Apr 2014
Posts: 19
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)
  Reply With Quote
08/09/17, 12:06 PM   #12
p6kocka
Join Date: Apr 2014
Posts: 19
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
  Reply With Quote
08/09/17, 12:07 PM   #13
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
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.
  Reply With Quote
08/09/17, 12:21 PM   #14
p6kocka
Join Date: Apr 2014
Posts: 19
OK. Iīve tried it. No luck. Iīll wait then for your update.
Wish you good evening
  Reply With Quote

ESOUI » AddOns » AddOn Help/Support » How to add thousands separator for existing addon?


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