PageRenderTime 56ms CodeModel.GetById 27ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 1ms

/Tukui/modules/actionbars/Style.lua

http://github.com/Asphyxia/Tukui
Lua | 557 lines | 454 code | 76 blank | 27 comment | 68 complexity | 89dbf48716eb457561921416067f00aa MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2if not C["actionbar"].enable == true then return end
  3
  4local _G = _G
  5local media = C["media"]
  6local securehandler = CreateFrame("Frame", nil, nil, "SecureHandlerBaseTemplate")
  7local replace = string.gsub
  8
  9local function style(self)
 10	local name = self:GetName()
 11	
 12	--> fixing a taint issue while changing totem flyout button in combat.
 13	if name:match("MultiCastActionButton") then return end 
 14	
 15	local action = self.action
 16	local Button = self
 17	local Icon = _G[name.."Icon"]
 18	local Count = _G[name.."Count"]
 19	local Flash	 = _G[name.."Flash"]
 20	local HotKey = _G[name.."HotKey"]
 21	local Border  = _G[name.."Border"]
 22	local Btname = _G[name.."Name"]
 23	local normal  = _G[name.."NormalTexture"]
 24 
 25	Flash:SetTexture("")
 26	Button:SetNormalTexture("")
 27 
 28	Border:Hide()
 29	Border = T.dummy
 30 
 31	Count:ClearAllPoints()
 32	Count:Point("BOTTOMRIGHT", 0, 2)
 33	Count:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 34 
 35	if not C["actionbar"].macrotext == true then
 36		Btname:SetText("")
 37		Btname:Kill()
 38	else
 39		Btname:SetAlphaGradient(0,Button:GetWidth())
 40		Btname:SetFont(C.media.pixelfont, C["datatext"].fontsize+1, "MONOCHROMEOUTLINE")
 41	end
 42 
 43	if not _G[name.."Panel"] then
 44		-- resize all button not matching T.buttonsize
 45		if self:GetHeight() ~= T.buttonsize and not InCombatLockdown() then --Taint fix for Flyout Buttons
 46			self:Size(T.buttonsize, T.buttonsize)
 47		end
 48
 49		-- create the bg/border panel
 50		local panel = CreateFrame("Frame", name.."Panel", self)
 51		panel:CreatePanel("Default", T.buttonsize, T.buttonsize, "CENTER", self, "CENTER", 0, 0)
 52 
 53		panel:SetFrameStrata(self:GetFrameStrata())
 54		panel:SetFrameLevel(self:GetFrameLevel() - 1)
 55 
 56		Icon:SetTexCoord(.09, .91, .09, .91)
 57		Icon:Point("TOPLEFT", 2, -2)
 58		Icon:Point("BOTTOMRIGHT", -2, 2)
 59	end
 60
 61	HotKey:ClearAllPoints()
 62	HotKey:Point("TOPRIGHT", 0, -3)
 63	HotKey:SetFont(C.media.pixelfont, C["datatext"].fontsize+1, "MONOCHROMEOUTLINE")
 64	HotKey.ClearAllPoints = T.dummy
 65	HotKey.SetPoint = T.dummy
 66 
 67	if not C["actionbar"].hotkey == true then
 68		HotKey:SetText("")
 69		HotKey:Kill()
 70	end
 71 
 72	if normal then
 73		normal:ClearAllPoints()
 74		normal:Point("TOPLEFT")
 75		normal:Point("BOTTOMRIGHT")
 76	end
 77end
 78
 79local function stylesmallbutton(normal, button, icon, name, pet)
 80	local Flash	 = _G[name.."Flash"]
 81	button:SetNormalTexture("")
 82	
 83	-- another bug fix reported by Affli in t12 beta
 84	button.SetNormalTexture = T.dummy
 85	
 86	Flash:SetTexture(media.buttonhover)
 87	
 88	if not _G[name.."Panel"] then
 89		if pet then
 90			button:Width(T.petbuttonsize)
 91			button:Height(T.petbuttonsize)
 92		
 93			local panel = CreateFrame("Frame", name.."Panel", button)
 94			panel:CreatePanel("Default", T.petbuttonsize, T.petbuttonsize, "CENTER", button, "CENTER", 0, 0)
 95			panel:SetFrameStrata(button:GetFrameStrata())
 96			panel:SetFrameLevel(button:GetFrameLevel() - 1)
 97			
 98			-- let's kill auto-castable triangles instead
 99			_G[name.."AutoCastable"]:Kill()
100
101			local shine = _G[name.."Shine"]
102			shine:Size(T.petbuttonsize, T.petbuttonsize)
103		else
104			button:Width(T.stancebuttonsize)
105			button:Height(T.stancebuttonsize)
106
107			local panel = CreateFrame("Frame", name.."Panel", button)
108			panel:CreatePanel("Default", T.stancebuttonsize, T.stancebuttonsize, "CENTER", button, "CENTER", 0, 0)
109			panel:SetFrameStrata(button:GetFrameStrata())
110			panel:SetFrameLevel(button:GetFrameLevel() - 1)
111		end
112		
113		icon:SetTexCoord(.09, .91, .09, .91)
114		icon:ClearAllPoints()
115		icon:Point("TOPLEFT", 2, -2)
116		icon:Point("BOTTOMRIGHT", -2, 2)
117	end
118	
119	if normal then
120		normal:ClearAllPoints()
121		normal:Point("TOPLEFT")
122		normal:Point("BOTTOMRIGHT")
123	end
124end
125
126function T.StyleShift()
127	for i=1, NUM_SHAPESHIFT_SLOTS do
128		local name = "ShapeshiftButton"..i
129		local button  = _G[name]
130		local icon  = _G[name.."Icon"]
131		local normal  = _G[name.."NormalTexture"]
132		stylesmallbutton(normal, button, icon, name)
133	end
134end
135
136function T.StylePet()
137	for i=1, NUM_PET_ACTION_SLOTS do
138		local name = "PetActionButton"..i
139		local button  = _G[name]
140		local icon  = _G[name.."Icon"]
141		local normal  = _G[name.."NormalTexture2"]
142		stylesmallbutton(normal, button, icon, name, true)
143	end
144end
145
146function T.TukuiShiftBarUpdate()
147	local numForms = GetNumShapeshiftForms()
148	local texture, name, isActive, isCastable
149	local button, icon, cooldown
150	local start, duration, enable
151	for i = 1, NUM_SHAPESHIFT_SLOTS do
152		button = _G["ShapeshiftButton"..i]
153		icon = _G["ShapeshiftButton"..i.."Icon"]
154		if i <= numForms then
155			texture, name, isActive, isCastable = GetShapeshiftFormInfo(i)
156			icon:SetTexture(texture)
157			
158			cooldown = _G["ShapeshiftButton"..i.."Cooldown"]
159			if texture then
160				cooldown:SetAlpha(1)
161			else
162				cooldown:SetAlpha(0)
163			end
164			
165			start, duration, enable = GetShapeshiftFormCooldown(i)
166			CooldownFrame_SetTimer(cooldown, start, duration, enable)
167			
168			if isActive then
169				ShapeshiftBarFrame.lastSelected = button:GetID()
170				button:SetChecked(1)
171			else
172				button:SetChecked(0)
173			end
174
175			if isCastable then
176				icon:SetVertexColor(1.0, 1.0, 1.0)
177			else
178				icon:SetVertexColor(0.4, 0.4, 0.4)
179			end
180		end
181	end
182end
183
184T.TukuiPetBarUpdate = function(self, event)
185	local petActionButton, petActionIcon, petAutoCastableTexture, petAutoCastShine
186	for i=1, NUM_PET_ACTION_SLOTS, 1 do
187		local buttonName = "PetActionButton" .. i
188		petActionButton = _G[buttonName]
189		petActionIcon = _G[buttonName.."Icon"]
190		petAutoCastableTexture = _G[buttonName.."AutoCastable"]
191		petAutoCastShine = _G[buttonName.."Shine"]
192		local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(i)
193		
194		if not isToken then
195			petActionIcon:SetTexture(texture)
196			petActionButton.tooltipName = name
197		else
198			petActionIcon:SetTexture(_G[texture])
199			petActionButton.tooltipName = _G[name]
200		end
201		
202		petActionButton.isToken = isToken
203		petActionButton.tooltipSubtext = subtext
204
205		if isActive and name ~= "PET_ACTION_FOLLOW" then
206			petActionButton:SetChecked(1)
207			if IsPetAttackAction(i) then
208				PetActionButton_StartFlash(petActionButton)
209			end
210		else
211			petActionButton:SetChecked(0)
212			if IsPetAttackAction(i) then
213				PetActionButton_StopFlash(petActionButton)
214			end			
215		end
216		
217		if autoCastAllowed then
218			petAutoCastableTexture:Show()
219		else
220			petAutoCastableTexture:Hide()
221		end
222		
223		if autoCastEnabled then
224			AutoCastShine_AutoCastStart(petAutoCastShine)
225		else
226			AutoCastShine_AutoCastStop(petAutoCastShine)
227		end
228		
229		-- grid display
230		if name then
231			if not C["actionbar"].showgrid then
232				petActionButton:SetAlpha(1)
233			end			
234		else
235			if not C["actionbar"].showgrid then
236				petActionButton:SetAlpha(0)
237			end
238		end
239		
240		if texture then
241			if GetPetActionSlotUsable(i) then
242				SetDesaturation(petActionIcon, nil)
243			else
244				SetDesaturation(petActionIcon, 1)
245			end
246			petActionIcon:Show()
247		else
248			petActionIcon:Hide()
249		end
250		
251		-- between level 1 and 10 on cata, we don't have any control on Pet. (I lol'ed so hard)
252		-- Setting desaturation on button to true until you learn the control on class trainer.
253		-- you can at least control "follow" button.
254		if not PetHasActionBar() and texture and name ~= "PET_ACTION_FOLLOW" then
255			PetActionButton_StopFlash(petActionButton)
256			SetDesaturation(petActionIcon, 1)
257			petActionButton:SetChecked(0)
258		end
259	end
260end
261
262local function updatehotkey(self, actionButtonType)
263	local hotkey = _G[self:GetName() .. 'HotKey']
264	local text = hotkey:GetText()
265	
266	text = replace(text, '(s%-)', 'S')
267	text = replace(text, '(a%-)', 'A')
268	text = replace(text, '(c%-)', 'C')
269	text = replace(text, '(Mouse Button )', 'M')
270	text = replace(text, '(Middle Mouse)', 'M3')
271	text = replace(text, '(Mouse Wheel Up)', 'MU')
272	text = replace(text, '(Mouse Wheel Down)', 'MD')
273	text = replace(text, '(Num Pad )', 'N')
274	text = replace(text, '(Page Up)', 'PU')
275	text = replace(text, '(Page Down)', 'PD')
276	text = replace(text, '(Spacebar)', 'SpB')
277	text = replace(text, '(Insert)', 'Ins')
278	text = replace(text, '(Home)', 'Hm')
279	text = replace(text, '(Delete)', 'Del')
280	
281	if hotkey:GetText() == _G['RANGE_INDICATOR'] then
282		hotkey:SetText('')
283	else
284		hotkey:SetText(text)
285	end
286end
287
288-- rescale cooldown spiral to fix texture.
289local buttonNames = { "ActionButton",  "MultiBarBottomLeftButton", "MultiBarBottomRightButton", "MultiBarLeftButton", "MultiBarRightButton", "ShapeshiftButton", "PetActionButton", "MultiCastActionButton"}
290for _, name in ipairs( buttonNames ) do
291	for index = 1, 12 do
292		local buttonName = name .. tostring(index)
293		local button = _G[buttonName]
294		local cooldown = _G[buttonName .. "Cooldown"]
295 
296		if ( button == nil or cooldown == nil ) then
297			break
298		end
299		
300		cooldown:ClearAllPoints()
301		cooldown:Point("TOPLEFT", button, "TOPLEFT", 2, -2)
302		cooldown:Point("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2)
303	end
304end
305
306local buttons = 0
307local function SetupFlyoutButton()
308	for i=1, buttons do
309		--prevent error if you don't have max ammount of buttons
310		if _G["SpellFlyoutButton"..i] then
311			style(_G["SpellFlyoutButton"..i])
312			
313			if _G["SpellFlyoutButton"..i]:GetChecked() then
314				_G["SpellFlyoutButton"..i]:SetChecked(nil)
315			end
316		end
317	end
318end
319SpellFlyout:HookScript("OnShow", SetupFlyoutButton)
320
321 
322--Hide the Mouseover texture and attempt to find the ammount of buttons to be skinned
323local function styleflyout(self)
324	self.FlyoutBorder:SetAlpha(0)
325	self.FlyoutBorderShadow:SetAlpha(0)
326	
327	SpellFlyoutHorizontalBackground:SetAlpha(0)
328	SpellFlyoutVerticalBackground:SetAlpha(0)
329	SpellFlyoutBackgroundEnd:SetAlpha(0)
330	
331	for i=1, GetNumFlyouts() do
332		local x = GetFlyoutID(i)
333		local _, _, numSlots, isKnown = GetFlyoutInfo(x)
334		if isKnown then
335			buttons = numSlots
336			break
337		end
338	end
339	
340	--Change arrow direction depending on what bar the button is on
341	local arrowDistance
342	if ((SpellFlyout and SpellFlyout:IsShown() and SpellFlyout:GetParent() == self) or GetMouseFocus() == self) then
343		arrowDistance = 5
344	else
345		arrowDistance = 2
346	end
347	
348	if self:GetParent():GetParent():GetName() == "SpellBookSpellIconsFrame" then return end
349	
350	if self:GetAttribute("flyoutDirection") ~= nil then
351		local point, _, _, _, _ = self:GetParent():GetParent():GetPoint()
352		
353		if strfind(point, "BOTTOM") then
354			self.FlyoutArrow:ClearAllPoints()
355			self.FlyoutArrow:SetPoint("TOP", self, "TOP", 0, arrowDistance)
356			SetClampedTextureRotation(self.FlyoutArrow, 0)
357			if not InCombatLockdown() then self:SetAttribute("flyoutDirection", "UP") end
358		else
359			self.FlyoutArrow:ClearAllPoints()
360			self.FlyoutArrow:SetPoint("LEFT", self, "LEFT", -arrowDistance, 0)
361			SetClampedTextureRotation(self.FlyoutArrow, 270)
362			if not InCombatLockdown() then self:SetAttribute("flyoutDirection", "LEFT") end
363		end
364	end
365end
366
367-- rework the mouseover, pushed, checked texture to match Tukui theme.
368do
369	for i = 1, 12 do
370		_G["ActionButton"..i]:StyleButton(true)
371		_G["MultiBarBottomLeftButton"..i]:StyleButton(true)
372		_G["MultiBarBottomRightButton"..i]:StyleButton(true)
373		_G["MultiBarLeftButton"..i]:StyleButton(true)
374		_G["MultiBarRightButton"..i]:StyleButton(true)
375	end
376		 
377	for i=1, 10 do
378		_G["ShapeshiftButton"..i]:StyleButton(true)
379		_G["PetActionButton"..i]:StyleButton(true)
380	end
381end
382
383hooksecurefunc("ActionButton_Update", style)
384hooksecurefunc("ActionButton_UpdateHotkeys", updatehotkey)
385hooksecurefunc("ActionButton_UpdateFlyout", styleflyout)
386
387---------------------------------------------------------------
388-- Totem Style, they need a lot more work than "normal" buttons
389-- Because of this, we skin it via separate styling codes
390-- Special thank's to DarthAndroid
391---------------------------------------------------------------
392
393-- don't continue executing code in this file is not playing a shaman.
394if not T.myclass == "SHAMAN" then return end
395
396-- Tex Coords for empty buttons
397SLOT_EMPTY_TCOORDS = {
398	[EARTH_TOTEM_SLOT] = {
399		left	= 66 / 128,
400		right	= 96 / 128,
401		top		= 3 / 256,
402		bottom	= 33 / 256,
403	},
404	[FIRE_TOTEM_SLOT] = {
405		left	= 67 / 128,
406		right	= 97 / 128,
407		top		= 100 / 256,
408		bottom	= 130 / 256,
409	},
410	[WATER_TOTEM_SLOT] = {
411		left	= 39 / 128,
412		right	= 69 / 128,
413		top		= 209 / 256,
414		bottom	= 239 / 256,
415	},
416	[AIR_TOTEM_SLOT] = {
417		left	= 66 / 128,
418		right	= 96 / 128,
419		top		= 36 / 256,
420		bottom	= 66 / 256,
421	},
422}
423
424local function StyleTotemFlyout(flyout)
425	-- remove blizzard flyout texture
426	flyout.top:SetTexture(nil)
427	flyout.middle:SetTexture(nil)
428	
429	-- Skin buttons
430	local last = nil
431	
432	for _,button in ipairs(flyout.buttons) do
433		button:SetTemplate("Default")
434		local icon = select(1,button:GetRegions())
435		icon:SetTexCoord(.09,.91,.09,.91)
436		icon:SetDrawLayer("ARTWORK")
437		icon:Point("TOPLEFT",button,"TOPLEFT",2,-2)
438		icon:Point("BOTTOMRIGHT",button,"BOTTOMRIGHT",-2,2)			
439		if not InCombatLockdown() then
440			button:Size(T.stancebuttonsize)
441			button:ClearAllPoints()
442			button:Point("BOTTOM",last,"TOP",0,4)
443		end			
444		if button:IsVisible() then last = button end
445		button:SetBackdropBorderColor(flyout.parent:GetBackdropBorderColor())
446		button:StyleButton()
447	end
448	
449	flyout.buttons[1]:SetPoint("BOTTOM",flyout,"BOTTOM")
450	
451	if flyout.type == "slot" then
452		local tcoords = SLOT_EMPTY_TCOORDS[flyout.parent:GetID()]
453		flyout.buttons[1].icon:SetTexCoord(tcoords.left,tcoords.right,tcoords.top,tcoords.bottom)
454	end
455	
456	-- Skin Close button
457	local close = MultiCastFlyoutFrameCloseButton
458	close:SetTemplate("Default")	
459	close:GetHighlightTexture():SetTexture([[Interface\Buttons\ButtonHilight-Square]])
460	close:GetHighlightTexture():Point("TOPLEFT",close,"TOPLEFT",1,-1)
461	close:GetHighlightTexture():Point("BOTTOMRIGHT",close,"BOTTOMRIGHT",-1,1)
462	close:GetNormalTexture():SetTexture(nil)
463	close:ClearAllPoints()
464	close:Point("BOTTOMLEFT",last,"TOPLEFT",0,4)
465	close:Point("BOTTOMRIGHT",last,"TOPRIGHT",0,4)	
466	close:Height(8)
467	
468	close:SetBackdropBorderColor(last:GetBackdropBorderColor())
469	flyout:ClearAllPoints()
470	flyout:Point("BOTTOM",flyout.parent,"TOP",0,4)
471end
472hooksecurefunc("MultiCastFlyoutFrame_ToggleFlyout",function(self) StyleTotemFlyout(self) end)
473	
474local function StyleTotemOpenButton(button, parent)
475	button:GetHighlightTexture():SetTexture(nil)
476	button:GetNormalTexture():SetTexture(nil)
477	button:Height(20)
478	button:ClearAllPoints()
479	button:Point("BOTTOMLEFT", parent, "TOPLEFT", 0, -3)
480	button:Point("BOTTOMRIGHT", parent, "TOPRIGHT", 0, -3)
481	if not button.visibleBut then
482		button.visibleBut = CreateFrame("Frame",nil,button)
483		button.visibleBut:Height(8)
484		button.visibleBut:Width(button:GetWidth() + 2)
485		button.visibleBut:SetPoint("CENTER")
486		button.visibleBut.highlight = button.visibleBut:CreateTexture(nil,"HIGHLIGHT")
487		button.visibleBut.highlight:SetTexture([[Interface\Buttons\ButtonHilight-Square]])
488		button.visibleBut.highlight:Point("TOPLEFT",button.visibleBut,"TOPLEFT",1,-1)
489		button.visibleBut.highlight:Point("BOTTOMRIGHT",button.visibleBut,"BOTTOMRIGHT",-1,1)
490		button.visibleBut:SetTemplate("Default")
491	end
492	
493	button.visibleBut:SetBackdropBorderColor(parent:GetBackdropBorderColor())
494end
495hooksecurefunc("MultiCastFlyoutFrameOpenButton_Show",function(button,_, parent) StyleTotemOpenButton(button, parent) end)
496
497-- the color we use for border
498local bordercolors = {
499	{.23,.45,.13},   -- Earth
500	{.58,.23,.10},   -- Fire
501	{.19,.48,.60},   -- Water
502	{.42,.18,.74},   -- Air
503}
504
505local function StyleTotemSlotButton(button, index)
506	button:SetTemplate("Default")
507	button.overlayTex:SetTexture(nil)
508	button.background:SetDrawLayer("ARTWORK")
509	button.background:ClearAllPoints()
510	button.background:Point("TOPLEFT",button,"TOPLEFT",2,-2)
511	button.background:Point("BOTTOMRIGHT",button,"BOTTOMRIGHT",-2,2)
512	if not InCombatLockdown() then button:Size(T.stancebuttonsize) end
513	button:SetBackdropBorderColor(unpack(bordercolors[((index-1) % 4) + 1]))
514	button:CreateShadow("Default")
515	button:StyleButton()
516end
517hooksecurefunc("MultiCastSlotButton_Update",function(self, slot) StyleTotemSlotButton(self,tonumber( string.match(self:GetName(),"MultiCastSlotButton(%d)"))) end)
518
519-- Skin the actual totem buttons
520local function StyleTotemActionButton(button, index)
521	local icon = select(1,button:GetRegions())
522	icon:SetTexCoord(.09,.91,.09,.91)
523	icon:SetDrawLayer("ARTWORK")
524	icon:Point("TOPLEFT",button,"TOPLEFT",2,-2)
525	icon:Point("BOTTOMRIGHT",button,"BOTTOMRIGHT",-2,2)
526	button.overlayTex:SetTexture(nil)
527	button.overlayTex:Hide()
528	button:GetNormalTexture():SetTexCoord(0,0,0,0)
529	if not InCombatLockdown() and button.slotButton then
530		button:ClearAllPoints()
531		button:SetAllPoints(button.slotButton)
532		button:SetFrameLevel(button.slotButton:GetFrameLevel()+1)
533	end
534	button:SetBackdropBorderColor(unpack(bordercolors[((index-1) % 4) + 1]))
535	button:SetBackdropColor(0,0,0,0)
536	button:StyleButton(true)
537end
538hooksecurefunc("MultiCastActionButton_Update",function(actionButton, actionId, actionIndex, slot) StyleTotemActionButton(actionButton,actionIndex) end)
539
540-- Skin the summon and recall buttons
541local function StyleTotemSpellButton(button, index)
542	if not button then return end
543	local icon = select(1,button:GetRegions())
544	icon:SetTexCoord(.09,.91,.09,.91)
545	icon:SetDrawLayer("ARTWORK")
546	icon:Point("TOPLEFT",button,"TOPLEFT",2,-2)
547	icon:Point("BOTTOMRIGHT",button,"BOTTOMRIGHT",-2,2)
548	button:SetTemplate("Default")
549	button:GetNormalTexture():SetTexture(nil)
550	if not InCombatLockdown() then button:Size(T.stancebuttonsize) end
551	_G[button:GetName().."Highlight"]:SetTexture(nil)
552	_G[button:GetName().."NormalTexture"]:SetTexture(nil)
553	button:CreateShadow("Default")
554	button:StyleButton()
555end
556hooksecurefunc("MultiCastSummonSpellButton_Update", function(self) StyleTotemSpellButton(self,0) end)
557hooksecurefunc("MultiCastRecallSpellButton_Update", function(self) StyleTotemSpellButton(self,5) end)