PageRenderTime 29ms CodeModel.GetById 2ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/actionbars/Toggle.lua

http://github.com/Asphyxia/Tukui
Lua | 447 lines | 363 code | 75 blank | 9 comment | 98 complexity | a3385a175545044c76bc19a10b1e044b MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2
  3if not C["actionbar"].enable then return end
  4
  5-- � 2011 Ecl�ps�
  6
  7local function ModifiedBackdrop(self)
  8	local color = RAID_CLASS_COLORS[T.myclass]
  9	self:SetBackdropColor(color.r*.15, color.g*.15, color.b*.15)
 10	self:SetBackdropBorderColor(color.r, color.g, color.b)
 11end
 12
 13local function OriginalBackdrop(self)
 14	self:SetTemplate("Default")
 15end
 16
 17local TukuiBar1 = TukuiBar1
 18local TukuiBar2 = TukuiBar2
 19local TukuiBar3 = TukuiBar3
 20local TukuiBar4 = TukuiBar4
 21local TukuiSplitBarLeft = TukuiSplitBarLeft
 22local TukuiSplitBarRight = TukuiSplitBarRight
 23local TukuiRightBar = TukuiRightBar
 24local TukuiPetBar = TukuiPetBar
 25
 26local Toggle = CreateFrame("Frame", "TukuiToggleActionbar", actionBarBG)
 27
 28local ToggleText = function(index, text, plus, neg)
 29	if plus then
 30		Toggle[index].Text:SetText(text)
 31		Toggle[index].Text:SetTextColor(.3, .3, .9)
 32	elseif neg then
 33		Toggle[index].Text:SetText(text)
 34		Toggle[index].Text:SetTextColor(.9, .3, .3)
 35	end
 36end
 37
 38local MainBars = function()
 39	if TukuiSaved.bottomrows == 1 then
 40		TukuiBar1:Height((T.buttonsize + T.buttonspacing * 2) + 2)
 41		TukuiSplitBarLeft:Height(TukuiBar1:GetHeight())
 42		TukuiSplitBarRight:Height(TukuiBar1:GetHeight())
 43		
 44		ToggleText(1, "+ + +", true)
 45		
 46		TukuiBar2:Hide()
 47			
 48		if TukuiSaved.splitbars == true then
 49			MultiBarLeft:SetParent(TukuiSplitBarLeft)
 50			for i = 7, 12 do
 51				local b = _G["MultiBarLeftButton"..i]
 52				b:SetAlpha(1)
 53				b:SetScale(0.000001)
 54			end
 55		else
 56			MultiBarLeft:SetParent(TukuiBar3)
 57		end
 58
 59	elseif TukuiSaved.bottomrows == 2 then
 60		TukuiBar1:Height((T.buttonsize * 2 + T.buttonspacing * 3) + 2)
 61		TukuiSplitBarLeft:Height(TukuiBar1:GetHeight())
 62		TukuiSplitBarRight:Height(TukuiBar1:GetHeight())
 63	
 64		ToggleText(1, "- - -", false, true)
 65
 66		TukuiBar2:Show()
 67		
 68		if TukuiSaved.splitbars == true then
 69			MultiBarLeft:SetParent(TukuiSplitBarLeft)
 70			for i = 7, 12 do
 71				local b = _G["MultiBarLeftButton"..i]
 72				b:SetAlpha(1)
 73				b:SetScale(1)
 74			end
 75		else
 76			MultiBarLeft:SetParent(TukuiBar3)
 77		end
 78
 79	end	
 80	Toggle[4]:Height(16)
 81	Toggle[4]:Width(39)
 82	
 83	Toggle[5]:Height(16)
 84	Toggle[5]:Width(39)
 85end
 86
 87local RightBars = function()
 88	if TukuiSaved.rightbars >= 1 then
 89		TukuiPetBar:ClearAllPoints()
 90		if C["actionbar"].vertical_rightbars == true then
 91			if not C["chat"].background then
 92				TukuiPetBar:Point("RIGHT", TukuiRightBar, "LEFT", -3, 0)
 93			else
 94				TukuiPetBar:Point("BOTTOMRIGHT", TukuiRightBar, "BOTTOMLEFT", -3, 0)
 95			end
 96		else
 97			TukuiPetBar:Point("BOTTOM", TukuiRightBar, "TOP", 0, 3)
 98		end
 99	else
100		TukuiPetBar:ClearAllPoints()
101		if not C["chat"].background then
102			TukuiPetBar:Point("RIGHT", UIParent, "RIGHT", -8, 0)
103		elseif C["actionbar"].vertical_rightbars == true then
104			TukuiPetBar:Point("BOTTOMRIGHT", TukuiChatBackgroundRight, "TOPRIGHT", 0, 3)
105		else
106			TukuiPetBar:Point("BOTTOM", TukuiChatBackgroundRight, "TOP", 0, 3)
107		end
108	end
109
110	if TukuiSaved.rightbars == 1 then
111		TukuiRightBar:Show()
112		TukuiBar4:Hide()
113
114		if C["actionbar"].vertical_rightbars == true then
115			TukuiRightBar:Width((T.buttonsize + T.buttonspacing * 2) + 2)
116		else
117			TukuiRightBar:Height((T.buttonsize + T.buttonspacing * 2) + 2)
118		end
119		
120		if TukuiSaved.splitbars ~= true and TukuiBar3:IsShown() then
121			MultiBarLeft:SetParent(TukuiBar3)
122			TukuiBar3:Hide()
123		end
124	elseif TukuiSaved.rightbars == 2 then
125		TukuiRightBar:Show()
126		TukuiBar4:Show()
127
128		if C["actionbar"].vertical_rightbars == true then
129			TukuiRightBar:Width((T.buttonsize * 2 + T.buttonspacing * 3) + 2)
130		else
131			TukuiRightBar:Height((T.buttonsize * 2 + T.buttonspacing * 3) + 2)
132		end
133		
134		if TukuiSaved.splitbars ~= true and TukuiBar3:IsShown() then
135			MultiBarLeft:SetParent(TukuiBar3)
136			TukuiBar3:Hide()
137		end
138	elseif TukuiSaved.rightbars == 3 then
139		TukuiRightBar:Show()
140		TukuiBar4:Show()
141
142		if C["actionbar"].vertical_rightbars == true then
143			TukuiRightBar:Width((T.buttonsize * 3 + T.buttonspacing * 4) + 2)
144		else
145			TukuiRightBar:Height((T.buttonsize * 3 + T.buttonspacing * 4) + 2)
146		end
147		
148		if TukuiSaved.splitbars ~= true then
149			MultiBarLeft:SetParent(TukuiBar3)
150			TukuiBar3:Show()
151			for i = 1, 12 do
152				local b = _G["MultiBarLeftButton"..i]
153				local b2 = _G["MultiBarLeftButton"..i-1]
154				b:SetSize(T.buttonsize, T.buttonsize)
155				b:ClearAllPoints()
156				
157				if i == 1 then
158					b:Point("TOPLEFT", TukuiRightBar, 5, -5)
159				else
160					if not TukuiSaved.splitbars and C["actionbar"].vertical_rightbars == true then
161						b:Point("TOP", b2, "BOTTOM", 0, -T.buttonspacing)
162					else
163						b:Point("LEFT", b2, "RIGHT", T.buttonspacing, 0)
164					end
165				end
166			end
167		end
168
169	elseif TukuiSaved.rightbars == 0 then
170		TukuiRightBar:Hide()
171		TukuiBar4:Hide()
172
173		if TukuiSaved.splitbars ~= true then
174			MultiBarLeft:SetParent(TukuiBar3)
175			TukuiBar3:Hide()
176		end			
177	end
178end
179
180local SplitBars = function()
181	if TukuiSaved.splitbars == true then
182		MultiBarLeft:SetParent(TukuiSplitBarLeft)
183		for i = 1, 12 do
184			local b = _G["MultiBarLeftButton"..i]
185			local b2 = _G["MultiBarLeftButton"..i-1]
186			b:ClearAllPoints()
187			if i == 1 then
188				b:Point("BOTTOMLEFT", TukuiSplitBarLeft, 5, 5)
189			else
190				if i == 4 then
191					b:Point("BOTTOMLEFT", TukuiSplitBarRight, 5, 5)
192				elseif i == 7 then
193					b:Point("BOTTOMLEFT", _G["MultiBarLeftButton1"], "TOPLEFT", 0, T.buttonspacing)
194				elseif i == 10 then
195					b:Point("BOTTOMLEFT", _G["MultiBarLeftButton4"], "TOPLEFT", 0, T.buttonspacing)
196				else
197					b:Point("LEFT", b2, "RIGHT", T.buttonspacing, 0)
198				end
199			end
200		end
201		
202		if TukuiSaved.rightbars == 3 then
203			TukuiRightBar:Show()
204			if C["actionbar"].vertical_rightbars == true then
205				TukuiRightBar:Width((T.buttonsize * 2 + T.buttonspacing * 3) + 2)
206			else
207				TukuiRightBar:Height((T.buttonsize * 2 + T.buttonspacing * 3) + 2)
208			end
209		end
210
211		for i = 7, 12 do
212			if TukuiSaved.bottomrows == 1 then
213				local b = _G["MultiBarLeftButton"..i]
214				b:SetAlpha(1)
215				b:SetScale(0.000001)
216			elseif TukuiSaved.bottomrows == 2 then
217				local b = _G["MultiBarLeftButton"..i]
218				b:SetAlpha(1)	
219				b:SetScale(1)
220			end
221		end
222		TukuiSplitBarLeft:Show()
223		TukuiSplitBarRight:Show()
224	
225		Toggle[4]:ClearAllPoints(); Toggle[5]:ClearAllPoints()
226		
227		Toggle[4]:Point("BOTTOMLEFT", closeAB, "TOPLEFT", 0, 23) -- Splitbar Toggle left
228		Toggle[4]:SetFrameStrata("DIALOG")
229		Toggle[4]:CreateOverlay(Toggle[4])
230		
231		Toggle[4]:HookScript("OnEnter", ModifiedBackdrop)
232		Toggle[4]:HookScript("OnLeave", OriginalBackdrop)
233		
234		Toggle[5]:Point("LEFT", Toggle[4], "RIGHT", 4, 0) -- Splitbar Toggle right
235		Toggle[5]:SetFrameStrata("DIALOG")
236		Toggle[5]:CreateOverlay(Toggle[5])
237		
238		Toggle[5]:HookScript("OnEnter", ModifiedBackdrop)
239		Toggle[5]:HookScript("OnLeave", OriginalBackdrop)
240		
241		ToggleText(4, ">", false, true)
242		ToggleText(5, "<", false, true)
243
244	elseif TukuiSaved.splitbars == false then
245		MultiBarLeft:SetParent(TukuiBar3)
246
247		for i = 1, 12 do
248			local b = _G["MultiBarLeftButton"..i]
249			local b2 = _G["MultiBarLeftButton"..i-1]
250			b:ClearAllPoints()
251			if i == 1 then
252				b:Point("TOPLEFT", TukuiRightBar, 5, -5)
253			else
254				b:Point("LEFT", b2, "RIGHT", T.buttonspacing, 0)
255			end
256		end
257		
258		Toggle[4]:ClearAllPoints(); Toggle[5]:ClearAllPoints()
259		
260		Toggle[4]:Point("BOTTOMLEFT", closeAB, "TOPLEFT", 0, 23)-- Splitbar Toggle left
261		Toggle[4]:SetFrameStrata("DIALOG")
262		
263		Toggle[5]:Point("LEFT", Toggle[4], "RIGHT", 4, 0) -- Splitbar Toggle right
264		Toggle[5]:SetFrameStrata("DIALOG")
265		
266		ToggleText(4, "<", true)
267		ToggleText(5, ">", true)
268
269		RightBars()
270
271		for i = 7, 12 do
272			local b = _G["MultiBarLeftButton"..i]
273			b:SetAlpha(1)	
274			b:SetScale(1)
275		end
276
277		TukuiSplitBarLeft:Hide()
278		TukuiSplitBarRight:Hide()
279	end
280end
281
282local function LockCheck(index)
283	if TukuiSaved.actionbarsLocked == true then
284		Toggle[index].Text:SetText("|cff50e468Unlock")
285	elseif TukuiSaved.actionbarsLocked == false then
286		Toggle[index].Text:SetText("|cffe45050Lock")
287	end
288end
289
290for i = 1, 6 do
291	Toggle[i] = CreateFrame("Frame", "TukuiToggle"..i, Toggle)
292	Toggle[i]:EnableMouse(true)
293	Toggle[i]:SetAlpha(1)
294	Toggle[i]:CreateBorder(true, false)
295	
296	Toggle[i].Text = Toggle[i]:CreateFontString(nil, "OVERLAY")
297	Toggle[i].Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
298	Toggle[i].Text:Point("CENTER", 2, 1)
299		
300	if i == 1 then
301		Toggle[i]:CreatePanel("Default", actionBarBG:GetWidth() - 8, 15, "TOP", actionBarBG, "TOP", 0, -4) -- Collapse button
302		Toggle[i]:SetFrameStrata("DIALOG")
303		Toggle[i]:CreateOverlay(Toggle[i])
304		
305		Toggle[i]:HookScript("OnEnter", ModifiedBackdrop)
306		Toggle[i]:HookScript("OnLeave", OriginalBackdrop)
307		
308		Toggle[i]:SetScript("OnMouseDown", function()
309			if InCombatLockdown() then return end
310
311			TukuiSaved.bottomrows = TukuiSaved.bottomrows + 1
312
313			if TukuiSaved.bottomrows > 2 then
314				TukuiSaved.bottomrows = 1
315			end
316			
317			MainBars()
318		end)
319		Toggle[i]:SetScript("OnEvent", MainBars)
320	elseif i == 2 then
321		Toggle[i]:CreatePanel("Default", T.buttonsize, actionBarBG:GetHeight() - 44, "RIGHT", actionBarBG, "RIGHT", -4, 0) -- Rightbar toggle right
322		Toggle[i]:SetFrameLevel(actionBarBG:GetFrameLevel() + 1)
323		Toggle[i]:CreateOverlay(Toggle[i])
324		
325		if C["actionbar"].vertical_rightbars then
326			ToggleText(i, ">", false, true)
327		else
328			ToggleText(i, "-", false, true)
329		end
330		
331		Toggle[i]:HookScript("OnEnter", ModifiedBackdrop)
332		Toggle[i]:HookScript("OnLeave", OriginalBackdrop)
333
334		Toggle[i]:SetScript("OnMouseDown", function()
335			if InCombatLockdown() then return end
336
337			TukuiSaved.rightbars = TukuiSaved.rightbars - 1
338
339			if TukuiSaved.splitbars == true and TukuiSaved.rightbars > 2 then
340				TukuiSaved.rightbars = 1
341			elseif TukuiSaved.rightbars < 0 then
342				if TukuiSaved.splitbars == true then
343					TukuiSaved.rightbars = 2
344				else
345					TukuiSaved.rightbars = 3
346				end
347			end
348			RightBars()
349		end)
350		Toggle[i]:SetScript("OnEvent", RightBars)	
351	elseif i == 3 then
352		Toggle[i]:CreatePanel("Default", Toggle[i-1]:GetWidth(), Toggle[i-1]:GetHeight(), "TOPRIGHT", Toggle[i-1], "TOPLEFT", -3, 0) -- Rightbar toggle left
353		Toggle[i]:SetFrameLevel(Toggle[i-1]:GetFrameLevel())
354		Toggle[i]:CreateOverlay(Toggle[i])
355		
356		if C["actionbar"].vertical_rightbars then
357			ToggleText(i, "<", true, false)
358		else
359			ToggleText(i, "+", true, false)
360		end
361		
362		Toggle[i]:HookScript("OnEnter", ModifiedBackdrop)
363		Toggle[i]:HookScript("OnLeave", OriginalBackdrop)
364
365		Toggle[i]:SetScript("OnMouseDown", function()
366			if InCombatLockdown() then return end
367
368			TukuiSaved.rightbars = TukuiSaved.rightbars + 1
369			
370			if TukuiSaved.splitbars == true and TukuiSaved.rightbars > 2 then
371				TukuiSaved.rightbars = 0
372			elseif TukuiSaved.rightbars > 3 then
373				TukuiSaved.rightbars = 0
374			end
375
376			RightBars()
377		end)
378		Toggle[i]:SetScript("OnEvent", RightBars)
379	elseif i == 4 then
380		Toggle[i]:CreatePanel("Default", T.buttonsize / 2, 15, "BOTTOMRIGHT", actionBarBG, "BOTTOMLEFT", -3, 0)
381	elseif i == 5 then
382		Toggle[i]:CreatePanel("Default", T.buttonsize / 2, 15, "BOTTOMLEFT", actionBarBG, "BOTTOMRIGHT", 3, 0)
383	elseif i == 6 then
384		Toggle[i]:CreatePanel("Default", 82, 17, "BOTTOMLEFT", closeAB, "TOPLEFT", 0, 3) -- Lock button 
385		Toggle[i]:SetFrameStrata("DIALOG")
386		Toggle[i]:CreateOverlay(Toggle[i])
387		
388		Toggle[i]:HookScript("OnEnter", ModifiedBackdrop)
389		Toggle[i]:HookScript("OnLeave", OriginalBackdrop)
390		
391		Toggle[i]:SetScript("OnMouseDown", function()	
392			if InCombatLockdown() then return end
393			
394			if TukuiSaved.actionbarsLocked == true then
395				TukuiSaved.actionbarsLocked = false
396				print(L.actionbars_unlocked)
397			elseif TukuiSaved.actionbarsLocked == false then
398				TukuiSaved.actionbarsLocked = true
399				print(L.actionbars_locked)
400			end
401
402			LockCheck(i)
403		end)
404
405		Toggle[i]:SetScript("OnEvent", function()
406			LockCheck(i)
407		end)
408	end
409	
410	if i == 4 or i == 5 then
411		Toggle[i]:SetScript("OnMouseDown", function()
412			if InCombatLockdown() then return end
413
414			if TukuiSaved.splitbars == false then
415				TukuiSaved.splitbars = true
416			elseif TukuiSaved.splitbars == true then
417				TukuiSaved.splitbars = false
418			end
419			SplitBars()
420		end)
421		Toggle[i]:SetScript("OnEvent", SplitBars)
422	end
423	Toggle[i]:RegisterEvent("PLAYER_ENTERING_WORLD")
424	Toggle[i]:RegisterEvent("PLAYER_REGEN_DISABLED")
425	Toggle[i]:RegisterEvent("PLAYER_REGEN_ENABLED")
426	
427	--[[Toggle[i]:SetScript("OnEnter", function()
428		if InCombatLockdown() then return end
429		Toggle[i]:FadeIn()
430	end)
431
432	Toggle[i]:SetScript("OnLeave", function()
433		Toggle[i]:FadeOut()
434	end)--]]
435	
436	Toggle[i]:SetScript("OnUpdate", function() 
437		if TukuiSaved.actionbarsLocked == true then
438			for i = 1, 5 do
439				Toggle[i]:EnableMouse(false)
440			end
441		elseif TukuiSaved.actionbarsLocked == false then
442			for i = 1, 5 do
443				Toggle[i]:EnableMouse(true)
444			end
445		end
446	end)		
447end