PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/datatext/currency.lua

http://github.com/Asphyxia/Tukui
Lua | 43 lines | 34 code | 6 blank | 3 comment | 6 complexity | e3b6d17bed512357ea220a8f712a5b67 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2--------------------------------------------------------------------
 3 -- CURRENCY
 4--------------------------------------------------------------------
 5
 6if C["datatext"].currency and C["datatext"].currency > 0 then
 7	local Stat = CreateFrame("Frame")
 8	Stat:EnableMouse(true)
 9	Stat:SetFrameStrata("BACKGROUND")
10	Stat:SetFrameLevel(3)
11
12	local Text  = TukuiInfoLeft:CreateFontString(nil, "OVERLAY")
13	Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
14	T.PP(C["datatext"].currency, Text)
15	
16	local function update()
17		local _text = T.datacolor.."---"
18		for i = 1, MAX_WATCHED_TOKENS do
19			local name, count, _, _, _ = GetBackpackCurrencyInfo(i)
20			if name and count then
21				if(i ~= 1) then _text = _text .. " " else _text = "" end
22				words = { strsplit(" ", name) }
23				for _, word in ipairs(words) do
24					_text = _text .. string.sub(word,1,1)
25				end
26				_text = _text .. ": " .. T.datacolor .. count .. "|r"
27			end
28		end
29		
30		Text:SetText(_text)
31	end
32	
33	local function OnEvent(self, event, ...)
34		update()
35		self:SetAllPoints(Text)
36		Stat:UnregisterEvent("PLAYER_LOGIN")	
37	end
38
39	Stat:RegisterEvent("PLAYER_LOGIN")	
40	hooksecurefunc("BackpackTokenFrame_Update", update)
41	Stat:SetScript("OnEvent", OnEvent)
42	Stat:SetScript("OnMouseDown", function() ToggleCharacter("TokenFrame") end)
43end