PageRenderTime 58ms CodeModel.GetById 45ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/databars/currency.lua

http://github.com/Asphyxia/Tukui
Lua | 133 lines | 115 code | 17 blank | 1 comment | 12 complexity | 2fc1f3c6ce7b5e777f4bb43ab7619c37 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2
  3if C["databars"].currency == true then
  4-- CURRENCY DATA BARS
  5local CurrencyData = {}
  6local tokens = {
  7	{61, 250},	 -- Dalaran Jewelcrafter's Token
  8	{81, 250},	 -- Dalaran Cooking Award
  9	{241, 250},	 -- Champion Seal
 10	{361, 200},  -- Illustrious Jewelcrafter's Token
 11	{390, 3000}, -- Conquest Points
 12	{391, 2000},  -- Tol Barad Commendation
 13	{392, 4000}, -- Honor Points
 14	{395, 4000}, -- Justice Points
 15	{396, 4000}, -- Valor Points
 16	{402, 10},	 -- Chef's Award 
 17	{416, 300}, -- Mark of the World Tree
 18}
 19
 20local function updateCurrency()
 21	if CurrencyData[1] then
 22		for i = 1, getn(CurrencyData) do
 23			CurrencyData[i]:Kill()
 24		end
 25		wipe(CurrencyData) 
 26	end
 27
 28	for i, v in ipairs(tokens) do
 29		local id, max = unpack(v)
 30		local name, amount, icon = GetCurrencyInfo(id)
 31		local r, g, b = oUFTukui.ColorGradient(amount/max, 0,.8,0,.8,.8,0,.8,0,0)
 32
 33		if name and amount > 0 then
 34			local frame = CreateFrame("Frame", "CurrencyData"..id, UIParent)
 35			frame:CreatePanel("Transparent", 120, 20, "CENTER", UIParent, "CENTER", 0, 0)
 36			frame:EnableMouse(true)
 37			frame:CreateShadow("Default")
 38			frame:Animate(-140, 0, 0.4)
 39			frame:Hide()
 40
 41			frame.Status = CreateFrame("StatusBar", "CurrencyDataStatus"..id, frame)
 42			frame.Status:SetFrameLevel(12)
 43			frame.Status:SetStatusBarTexture((C["media"].raidTex) or (C["media"].normTex))
 44			frame.Status:SetMinMaxValues(0, max)
 45			frame.Status:SetValue(amount)
 46			frame.Status:SetStatusBarColor(r, g, b, 1)
 47			frame.Status:Point("TOPLEFT", frame, "TOPLEFT", 2, -2)
 48			frame.Status:Point("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)
 49
 50			frame.Text = frame.Status:CreateFontString(nil, "OVERLAY")
 51			frame.Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 52			frame.Text:Point("CENTER", frame, "CENTER", 0, 2)
 53			frame.Text:Width(frame:GetWidth() - 4)
 54			frame.Text:SetShadowColor(0, 0, 0)
 55			frame.Text:SetShadowOffset(1.25, -1.25)
 56			frame.Text:SetText(format("%s / %s", amount, max))
 57				
 58			frame.IconBG = CreateFrame("Frame", "CurrencyDataIconBG"..id, frame)
 59			frame.IconBG:CreatePanel(nil, 20, 20, "BOTTOMLEFT", frame, "BOTTOMRIGHT", T.Scale(3), 0)
 60			frame.Icon = frame.IconBG:CreateTexture(nil, "ARTWORK")
 61			frame.Icon:Point("TOPLEFT", frame.IconBG, "TOPLEFT", 4, -2)
 62			frame.Icon:Point("BOTTOMRIGHT", frame.IconBG, "BOTTOMRIGHT", -2, 2)
 63			frame.IconBG:CreateShadow("Default")
 64			frame.Icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
 65			frame.Icon:SetTexture("Interface\\Icons\\"..icon)
 66
 67			frame:SetScript("OnEnter", function(self) frame.Text:SetText(format("%s", name)) end)
 68			frame:SetScript("OnLeave", function(self) frame.Text:SetText(format("%s / %s", amount, max)) end)
 69			
 70			tinsert(CurrencyData, frame)
 71		end
 72	end
 73	
 74	for key, frame in ipairs(CurrencyData) do
 75		frame:ClearAllPoints()
 76		if key == 1 then
 77			frame:Point("TOPLEFT", UIParent, "TOPLEFT", 3, -30)
 78		else
 79			frame:Point("TOP", CurrencyData[key-1], "BOTTOM", 0, -3)
 80		end
 81	end
 82end
 83
 84local function ModifiedBackdrop(self)
 85	local color = RAID_CLASS_COLORS[T.myclass]
 86	self:SetBackdropColor(unpack(C["media"].backdropcolor))
 87	self:SetBackdropBorderColor(color.r, color.g, color.b)
 88end
 89
 90local function OriginalBackdrop(self)
 91	self:SetBackdropColor(unpack(C["media"].backdropcolor))
 92	self:SetBackdropBorderColor(unpack(C["media"].bordercolor))
 93end
 94
 95local toggle = CreateFrame("Frame", "CurrencyToggle", UIParent)
 96toggle:CreatePanel("Default", 30, 15, "TOPRIGHT", TukuiChatBackgroundRight, "TOPRIGHT", -2, -84)
 97toggle:EnableMouse(true)
 98toggle:SetFrameStrata("MEDIUM")
 99toggle:SetFrameLevel(2)
100toggle:CreateOverlay(toggle)
101toggle:CreateShadow("Default")
102toggle:SetAlpha(0)
103toggle:HookScript("OnEnter", ModifiedBackdrop)
104toggle:HookScript("OnLeave", OriginalBackdrop)
105
106toggle:SetScript("OnEnter", function()
107		if InCombatLockdown() then return end
108		toggle:FadeIn()
109	end)
110
111	toggle:SetScript("OnLeave", function()
112		toggle:FadeOut()
113	end)
114
115toggle.Text = toggle:CreateFontString(nil, "OVERLAY")
116toggle.Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
117toggle.Text:Point("CENTER", toggle, "CENTER", 1.5, 1)
118toggle.Text:SetText(T.datacolor.."C")
119toggle:SetScript("OnMouseUp", function(self)
120	for _, frame in pairs(CurrencyData) do
121		if frame and frame:IsVisible() then
122			frame:SlideOut()
123		else
124			frame:SlideIn()
125		end
126	end
127end)
128
129local updater = CreateFrame("Frame")
130updater:RegisterEvent("PLAYER_HONOR_GAIN")	
131updater:SetScript("OnEvent", updateCurrency)
132hooksecurefunc("BackpackTokenFrame_Update", updateCurrency)
133end