PageRenderTime 34ms CodeModel.GetById 31ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/datatext/bags.lua

http://github.com/Asphyxia/Tukui
Lua | 43 lines | 36 code | 4 blank | 3 comment | 3 complexity | 34568e863c93d71e0b1209c1169b0e6c MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2--------------------------------------------------------------------
 3 -- BAGS
 4--------------------------------------------------------------------
 5
 6if C["datatext"].bags and C["datatext"].bags > 0 then
 7	local Stat = CreateFrame("Frame")
 8	Stat:EnableMouse(true)
 9	Stat:SetFrameStrata("HIGH")
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"].bags, Text)
15
16	local function OnEvent(self, event, ...)
17		local free, total, used = 0, 0, 0
18		for i = 0, NUM_BAG_SLOTS do
19			free, total = free + GetContainerNumFreeSlots(i), total + GetContainerNumSlots(i)
20		end
21		used = total - free
22		Text:SetText("Bag Slots: "..T.datacolor..free)
23		self:SetAllPoints(Text)
24		Stat:SetScript("OnEnter", function()
25		if not InCombatLockdown() then
26			local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)	
27			GameTooltip:SetOwner(panel, anchor, xoff, yoff)
28			GameTooltip:ClearLines()
29			GameTooltip:AddDoubleLine(L.datatext_bags)
30			GameTooltip:AddLine(" ")
31			GameTooltip:AddDoubleLine(T.datacolor.."Total",total, 1, 1, 1, 1, 1, 1)
32			GameTooltip:AddDoubleLine(T.datacolor.."Used",used, 1, 1, 1, 1, 1, 1)
33		end
34		GameTooltip:Show()
35	end)
36	Stat:SetScript("OnLeave", function() GameTooltip:Hide() end)
37	end
38          
39	Stat:RegisterEvent("PLAYER_LOGIN")
40	Stat:RegisterEvent("BAG_UPDATE")
41	Stat:SetScript("OnEvent", OnEvent)
42	Stat:SetScript("OnMouseDown", function() ToggleAllBags() end)
43end