Quantcast
WoWInterface - View Single Post - currency display issues
View Single Post
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