PageRenderTime 126ms CodeModel.GetById 109ms app.highlight 8ms RepoModel.GetById 5ms app.codeStats 0ms

/Tukui/modules/databars/barPanels.lua

http://github.com/Asphyxia/Tukui
Lua | 90 lines | 77 code | 12 blank | 1 comment | 14 complexity | 353670b040fc430fa4c4f65d503ceed8 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2
 3local pWidth, pHeight = C.databars.settings.width, C.databars.settings.height
 4T["databars"] = {}
 5
 6T.maxDatabars = 0
 7for i,v in pairs(C.databars) do
 8	if type(v) == "number" then T.maxDatabars = max(T.maxDatabars, v) end
 9end
10if T.maxDatabars == 0 then return end
11
12for i = 1, T.maxDatabars do
13	T.databars[i] = CreateFrame("Frame", "TukuiDataBar"..i.."_Panel", UIParent)
14	T.databars[i]:CreateShadow()
15	if i == 1 then
16		T.databars[i]:CreatePanel("Transparent", pWidth, pHeight, "TOPLEFT", UIParent, "TOPLEFT", 2, -8)
17	else
18		if C.databars.settings.vertical then
19			T.databars[i]:CreatePanel("Transparent", pWidth, pHeight, "TOPRIGHT", T.databars[i-1], "BOTTOMRIGHT", 0, -C.databars.settings.spacing)
20		else
21			T.databars[i]:CreatePanel("Transparent", pWidth, pHeight, "TOPLEFT", T.databars[i-1], "TOPRIGHT", C.databars.settings.spacing, 0)
22		end
23	end
24	
25	T.databars[i].statusbar = CreateFrame("StatusBar",  "TukuiDataBar"..i.."_StatusBar", T.databars[i], "TextStatusBar")
26	T.databars[i].statusbar:SetFrameStrata("BACKGROUND")
27	T.databars[i].statusbar:SetStatusBarTexture(C.media.normTex)
28	T.databars[i].statusbar:SetStatusBarColor(1,1,1)
29	T.databars[i].statusbar:SetFrameLevel(2)
30	T.databars[i].statusbar:SetPoint("TOPRIGHT", T.databars[i], "TOPRIGHT", -2, -2)
31	T.databars[i].statusbar:SetPoint("BOTTOMLEFT", T.databars[i], "BOTTOMLEFT", 2, 2)
32	T.databars[i].statusbar:SetMinMaxValues(0,1)
33	T.databars[i].statusbar:SetValue(0)
34	
35	T.databars[i].text = T.databars[i].statusbar:CreateFontString("DataBar"..i.."_Text", "OVERLAY")
36	T.databars[i].text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
37	T.databars[i].text:SetPoint("TOPRIGHT", T.databars[i].statusbar, "TOPRIGHT", -2, -2)
38	T.databars[i].text:SetPoint("BOTTOMLEFT", T.databars[i].statusbar, "BOTTOMLEFT", 2, 2)
39end
40
41
42local function hideDatabars(self)
43	for i = 1, T.maxDatabars do
44		T.databars[i]:Hide()
45	end
46	self.text:SetText(T.datacolor.."Open")
47	self:ClearAllPoints()
48	self:SetPoint(T.databars[1]:GetPoint())
49end
50
51local function showDatabars(self)
52	for i = 1, T.maxDatabars do
53		T.databars[i]:Show()
54	end
55	self.text:SetText(T.datacolor.."Close")
56	self:ClearAllPoints()
57	if not C.databars.settings.vertical then
58		self:SetPoint("LEFT", T.databars[T.maxDatabars], "RIGHT", C.databars.settings.spacing, 0)
59	else
60		self:SetPoint("TOP", T.databars[T.maxDatabars], "BOTTOM", 0, -C.databars.settings.spacing)
61	end
62end
63
64T.databars["toggle"] = CreateFrame("Frame", "TukuiDataBarToggle", UIParent)
65T.databars["toggle"]:SetAlpha(0)
66T.databars["toggle"].text = T.databars["toggle"]:CreateFontString(nil, "OVERLAY")
67T.databars["toggle"].text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
68T.databars["toggle"].text:SetJustifyH("LEFT")
69T.databars["toggle"].text:SetPoint("CENTER", 2)
70T.databars["toggle"].text:SetText(T.datacolor.."Close")
71
72if C.databars.settings.vertical then
73	T.databars["toggle"]:CreatePanel("Transparent", pWidth, C.databars.settings.height, "TOP", T.databars[T.maxDatabars], "BOTTOM", 0, -C.databars.settings.spacing)
74else
75	T.databars["toggle"]:CreatePanel("Transparent", pWidth, C.databars.settings.height, "LEFT", T.databars[T.maxDatabars], "RIGHT", C.databars.settings.spacing, 0)
76end
77T.databars["toggle"]:CreateShadow()
78
79T.databars["toggle"]:EnableMouse(true)
80T.databars["toggle"]:HookScript("OnMouseDown", function(self) 
81	if T.databars[1]:IsShown() then
82		hideDatabars(self)
83	else
84		showDatabars(self)
85	end
86end)
87T.databars["toggle"]:HookScript("OnEnter", function(self) self:SetAlpha(1) end)
88T.databars["toggle"]:HookScript("OnLeave", function(self) self:SetAlpha(0) end)
89
90--/script for i = 1, _G.Tukui[1].maxDatabars do _G.Tukui[1].databars[i]:Show() end