Thread Tools Display Modes
09-28-17, 05:49 AM   #1
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
currency display issues

Hello folks,

as seen here i have set up a currency display on my orderhallbar.
So i wanted to step up the game and update the currencies with
Code:
hooksecurefunc("TokenFrame_Update", getCurrencies)
the issue i'm having is that the 3rd currency still is displayed, even when it jumps to the 2nd slot after the update. when i use something like
Code:
local function updateCurrencies()
	currency = {}
	prevName = nil
	getCurrencies()
end

hooksecurefunc("TokenFrame_Update", updateCurrencies)
I'm out of ideas how to solve this as every attempt i've made failed miserably and open to improvements alltogether, as i'm sure there's something more elegant anyways.

Thanks in advance WoWI community.


Last edited by Lolzen : 09-28-17 at 05:59 AM. Reason: picture
  Reply With Quote
09-28-17, 11:54 AM   #2
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
In my addon that does something similar I used :Hide() before making the object visible.
Minor fix: after
Lua Code:
  1. if not OrderHallCommandBar then return end
you might want to declare a
Lua Code:
  1. local prevName

Last edited by Kakjens : 09-28-17 at 12:38 PM.
  Reply With Quote
09-28-17, 01:21 PM   #3
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
Originally Posted by Kakjens View Post
In my addon that does something similar I used :Hide() before making the object visible.
Minor fix: after
Lua Code:
  1. if not OrderHallCommandBar then return end
you might want to declare a
Lua Code:
  1. local prevName
prevName is used as placing later on actually
Code:
if prevName == nil then
	currency[name]:SetPoint("LEFT", OrderHallCommandBar.Currency, "RIGHT", 10, 0)
	prevName = name
else
	currency[name]:SetPoint("LEFT", currency[prevName].text, "RIGHT", 10, 0)
	prevName = name
end
as i is not 1, 2, 3.. for isWatched it's 4, 10, 13 in my case, otherwise i'd have used currency[i] in the first place.
Bearing in mind flexibility as not every char/user would want to use the exact same currencies i use, there's my dilemma, therefore i used prevName as a variable to use currency[prevName].
i tried polluting a table and using a counter variable, so i could have used (e.g) slots[i], but that brought other issues.
Like i said i tried much working around this so i could effectively use a flexible system that displays the isWatched currencies (up to 3 as limited per defaultUI).
it's very likely just a structural problem with my code, as it does kinda work.
before i had it hardcoded in, later on used saved vars where i could add an item to the list, but it always required an uireload. And that's what i want to prevent here

edit: just had an idea pop up.
As the Default UI dictates 3 or less currencies i could create the frames beforehand and use :Hide() and :Show() as you've mentioned before. I'll try that now, thanks!

Last edited by Lolzen : 09-28-17 at 01:32 PM.
  Reply With Quote
09-28-17, 02:09 PM   #4
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
I suggested something like this
Lua Code:
  1. local currency = {}
  2. local function getCurrencies()
  3.     if not OrderHallCommandBar then return end
  4.     local prevName
for better scoping (and resetting) of variable prevName.
For me it feels like
Lua Code:
  1. if not currency[name] then
should be the first check within loop, with isWatched setting visibility and order.
I think
Lua Code:
  1. else
  2.     currency[name].text:SetText(count)
  3. end
is missing code relating setpoints and prevName.
  Reply With Quote
09-28-17, 02:23 PM   #5
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
Originally Posted by Kakjens View Post
I suggested something like this
Lua Code:
  1. local currency = {}
  2. local function getCurrencies()
  3.     if not OrderHallCommandBar then return end
  4.     local prevName
for better scoping (and resetting) of variable prevName.
For me it feels like
Lua Code:
  1. if not currency[name] then
should be the first check within loop, with isWatched setting visibility and order.
I think
Lua Code:
  1. else
  2.     currency[name].text:SetText(count)
  3. end
is missing code relating setpoints and prevName.
Good points. However currency[name].text is an object always pointing to currency[name], therefore count is always related to name.

Anyways, i misliked the prevName variable anyways, and tried a different aproach (altough i now again have to use a counter variable).

it's almost working (at least if i watched 3 currencies, removed one, and added one back), but still bugs out if i remove two currencies. It's more or less tzhe same anyways, but i feel this is a bit of an better aproach as it only crates 3 textures/frames/fontstrings and reuses them.

Code:
local currency = {}
local function getCurrencies()
	if not OrderHallCommandBar then return end
	for i=1, 3 do
		if not currency[i] then
			currency[i] = OrderHallCommandBar:CreateTexture("currencyTexture"..i)
			currency[i]:SetSize(LolzenUIcfg.orderhallbar["ohb_currency_icon_size"], LolzenUIcfg.orderhallbar["ohb_currency_icon_size"])
			currency[i]:SetTexCoord(.04, .94, .04, .94)
			
			if not currency[i].text then
				currency[i].text = OrderHallCommandBar:CreateFontString(nil, "OVERLAY")
				currency[i].text:SetFont("Interface\\AddOns\\LolzenUI\\fonts\\"..LolzenUIcfg.orderhallbar["ohb_currency_font"], LolzenUIcfg.orderhallbar["ohb_currency_font_size"] ,LolzenUIcfg.orderhallbar["ohb_currency_font_flag"])
				currency[i].text:SetTextColor(1, 1, 1)
				currency[i].text:SetPoint("LEFT", currency[i], "RIGHT", 5, 0)
			end

			if not currency[i].frame then
				currency[i].frame = CreateFrame("Frame", nil, OrderHallCommandBar)
				currency[i].frame:SetAllPoints(currency[i])
				currency[i].frame:SetScript("OnEnter", function(self) 
					GameTooltip:SetOwner(currency[i], "ANCHOR_BOTTOMRIGHT")
					if currency[i].tooltipinfo ~= nil then
						GameTooltip:SetCurrencyByID(currency[i].tooltipinfo)
						GameTooltip:Show()
					end
				end)
				currency[i].frame:SetScript("OnLeave", function(self)
					GameTooltip:Hide()
				end)
			end
		
			
			if i == 1 then
				currency[i]:SetPoint("LEFT", OrderHallCommandBar.Currency, "RIGHT", 10, 0)
			else
				currency[i]:SetPoint("LEFT", currency[i-1].text, "RIGHT", 10, 0)
			end
		end
	end
	local counter = 1
	for i=1, GetCurrencyListSize() do
		local name, _, _, _, isWatched, count = GetCurrencyListInfo(i)
		if isWatched then
			local link = GetCurrencyListLink(i)
			local _, _, icon = GetCurrencyInfo(link:match("|Hcurrency:(%d+)|"))
			if currency[counter] then
				currency[counter]:SetTexture(icon)
				currency[counter].text:SetText(count)
				if not currency[counter].name then
					currency[counter].name = name
				end
				-- make the link available
				if not currency[counter].tooltipinfo then
					currency[counter].tooltipinfo = link:match("|Hcurrency:(%d+)|")
				else
					currency[counter].tooltipinfo = link:match("|Hcurrency:(%d+)|")
				end
				currency[counter]:Show()
				currency[counter].text:Show()
				counter = counter + 1
			end
		elseif not isWatched then
			if currency[counter] and currency[counter].name == name then
				currency[counter+1]:Hide()
				currency[counter+1].text:Hide()
				currency[counter].tooltipinfo = currency[counter+1].tooltipinfo
				currency[counter+1].tooltipinfo = nil
			end
		end
	end
end
Thank you very much for your support here, Kakjens!

Done! Works flawless now as far as my 30 sec test goes
Thank you again! here is the commit for future references.

Last edited by Lolzen : 09-28-17 at 02:53 PM.
  Reply With Quote
09-28-17, 04:02 PM   #6
Kakjens
A Cliff Giant
Join Date: Apr 2017
Posts: 75
Glad that I was able to be of assistance.
The logic still feels wrong. Separating creation and visibility of objects is a good start.
Don't see the reason why
Lua Code:
  1. if not currency[counter].tooltipinfo then
  2.                     currency[counter].tooltipinfo = link:match("|Hcurrency:(%d+)|")
  3.                 else
  4.                     currency[counter].tooltipinfo = link:match("|Hcurrency:(%d+)|")
  5.                 end
can't be simplified into
Lua Code:
  1. if not currency[counter].tooltipinfo then
  2.     currency[counter].tooltipinfo = link:match("|Hcurrency:(%d+)|")
  3. end
I think
Lua Code:
  1. elseif not isWatched then
can be changed into
Lua Code:
  1. else
.
  Reply With Quote
09-29-17, 02:47 AM   #7
Lolzen
An Aku'mai Servant
 
Lolzen's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 36
True. I was hurrying yesterday and didn't "clean up".
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » currency display issues

Thread Tools
Display Modes

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