PageRenderTime 101ms CodeModel.GetById 40ms app.highlight 12ms RepoModel.GetById 30ms app.codeStats 1ms

/Tukui/modules/addonskins/Skada.lua

http://github.com/Asphyxia/Tukui
Lua | 189 lines | 154 code | 33 blank | 2 comment | 23 complexity | f6e3408a7dcc8a38ddfcb8a696b9359e MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import Functions/Constants, Config, Locales
  2
  3
  4if not IsAddOnLoaded("Skada") or not C.Addon_Skins.Skada then return end
  5local Skada = Skada
  6
  7local Skada = Skada
  8local barSpacing = T.Scale(1, 1)
  9local borderWidth = T.Scale(2, 2)
 10
 11local barmod = Skada.displays["bar"]
 12
 13-- Used to strip unecessary options from the in-game config
 14local function StripOptions(options)
 15	options.baroptions.args.barspacing = nil
 16	options.titleoptions.args.texture = nil
 17	options.titleoptions.args.bordertexture = nil
 18	options.titleoptions.args.thickness = nil
 19	options.titleoptions.args.margin = nil
 20	options.titleoptions.args.color = nil
 21	options.windowoptions = nil
 22	options.baroptions.args.barfont = nil
 23	options.titleoptions.args.font = nil
 24end
 25
 26local barmod = Skada.displays["bar"]
 27barmod.AddDisplayOptions_ = barmod.AddDisplayOptions
 28barmod.AddDisplayOptions = function(self, win, options)
 29	self:AddDisplayOptions_(win, options)
 30	StripOptions(options)
 31end
 32
 33for k, options in pairs(Skada.options.args.windows.args) do
 34	if options.type == "group" then
 35		StripOptions(options.args)
 36	end
 37end
 38
 39local titleBG = {
 40	bgFile = C["media"].normTex,
 41	tile = false,
 42	tileSize = 0
 43}
 44
 45barmod.ApplySettings_ = barmod.ApplySettings
 46barmod.ApplySettings = function(self, win)
 47	barmod.ApplySettings_(self, win)
 48
 49	local skada = win.bargroup
 50
 51	if win.db.enabletitle then
 52		skada.button:SetBackdrop(titleBG)
 53	end
 54
 55	skada:SetTexture(C["media"].normTex)
 56	skada:SetSpacing(barSpacing)
 57	skada:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 58	skada:SetFrameLevel(5)
 59	
 60	local titlefont = CreateFont("TitleFont"..win.db.name)
 61	titlefont:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 62	win.bargroup.button:SetNormalFontObject(titlefont)
 63
 64	local color = win.db.title.color
 65	win.bargroup.button:SetBackdropColor(unpack(C["media"].bordercolor))
 66
 67	skada:SetBackdrop(nil)
 68	if not skada.backdrop then
 69		skada:CreateBackdrop("Default")
 70	end
 71	skada.backdrop:ClearAllPoints()
 72	if win.db.enabletitle then
 73		skada.backdrop:Point('TOPLEFT', win.bargroup.button, 'TOPLEFT', -2, 2)
 74	else
 75		skada.backdrop:Point('TOPLEFT', win.bargroup, 'TOPLEFT', -2, 2)
 76	end
 77	skada.backdrop:Point('BOTTOMRIGHT', win.bargroup, 'BOTTOMRIGHT', 2, -2)
 78
 79	if C["Addon_Skins"].embedright == "Skada" then
 80		win.bargroup.button:SetFrameStrata("MEDIUM")
 81		win.bargroup.button:SetFrameLevel(5)	
 82		win.bargroup:SetFrameStrata("MEDIUM")
 83	end
 84end
 85
 86local function EmbedWindow(window, width, barheight, height, point, relativeFrame, relativePoint, ofsx, ofsy)
 87	window.db.barwidth = width
 88	window.db.barheight = barheight
 89	if window.db.enabletitle then 
 90		height = height - barheight
 91	end
 92	window.db.background.height = height
 93	window.db.spark = false
 94	window.db.barslocked = true
 95	window.bargroup:ClearAllPoints()
 96	window.bargroup:SetPoint(point, relativeFrame, relativePoint, ofsx, ofsy)
 97	
 98	barmod.ApplySettings(barmod, window)
 99end
100
101local windows = {}
102function EmbedSkada()
103	if #windows == 1 then
104		EmbedWindow(windows[1], TukuiChatBackgroundRight:GetWidth() - 4,   (TukuiChatBackgroundRight:GetHeight() - 4 - (barSpacing * 4)) / 10, (TukuiChatBackgroundRight:GetHeight() - 6), "BOTTOMRIGHT", TukuiChatBackgroundRight, "BOTTOMRIGHT", -2, 3)
105	elseif #windows == 2 then
106		EmbedWindow(windows[1], ((TukuiChatBackgroundRight:GetWidth() - 4) / 2) - (borderWidth + T.mult), (TukuiChatBackgroundRight:GetHeight() - 4 - (barSpacing * 4)) / 10, TukuiChatBackgroundRight:GetHeight() - 4,    "BOTTOMRIGHT", TukuiChatBackgroundRight, "BOTTOMRIGHT", -2, 3)
107		EmbedWindow(windows[2], ((TukuiChatBackgroundRight:GetWidth() - 4) / 2) - (borderWidth + T.mult), (TukuiChatBackgroundRight:GetHeight() - 4 - (barSpacing * 4)) / 10, TukuiChatBackgroundRight:GetHeight() - 4,    "BOTTOMLEFT", TukuiChatBackgroundRight, "BOTTOMLEFT", 2, 3)
108	elseif #windows > 2 then
109		EmbedWindow(windows[1], ((TukuiChatBackgroundRight:GetWidth() - 4) / 2) - (borderWidth + T.mult), (TukuiChatBackgroundRight:GetHeight() - 4 - (barSpacing * 4)) / 10, TukuiChatBackgroundRight:GetHeight() - 4,    "BOTTOMRIGHT", TukuiChatBackgroundRight, "BOTTOMRIGHT", -2, 3)
110		EmbedWindow(windows[2], ((TukuiChatBackgroundRight:GetWidth() - 4) / 2) - (borderWidth + T.mult), ((TukuiChatBackgroundRight:GetHeight() - 6 / 2) - (barSpacing * 4)) / 10, TukuiChatBackgroundRight:GetHeight() - 4 / 2 - 2,  "BOTTOMLEFT", TukuiChatBackgroundRight, "BOTTOMLEFT", 2, 3)
111		EmbedWindow(windows[3], windows[2].db.barwidth -1 , ((TukuiChatBackgroundRight:GetHeight() - 6 / 2) - (barSpacing * 4)) / 10, TukuiChatBackgroundRight:GetHeight() - 4 / 2 - 2,  "BOTTOMLEFT", windows[2].bargroup.backdrop, "TOPLEFT", 2, 4)
112	end
113end
114
115-- Update pre-existing displays
116for _, window in ipairs(Skada:GetWindows()) do
117	window:UpdateDisplay()
118end
119
120if C["Addon_Skins"].embedright == "Skada" then
121	Skada.CreateWindow_ = Skada.CreateWindow
122	function Skada:CreateWindow(name, db)
123		Skada:CreateWindow_(name, db)
124		
125		windows = {}
126		for _, window in ipairs(Skada:GetWindows()) do
127			tinsert(windows, window)
128		end	
129		
130		EmbedSkada()
131	end
132
133	Skada.DeleteWindow_ = Skada.DeleteWindow
134	function Skada:DeleteWindow(name)
135		Skada:DeleteWindow_(name)
136		
137		windows = {}
138		for _, window in ipairs(Skada:GetWindows()) do
139			tinsert(windows, window)
140		end	
141		
142		EmbedSkada()
143	end
144
145	local Skada_Skin = CreateFrame("Frame")
146	Skada_Skin:RegisterEvent("PLAYER_ENTERING_WORLD")
147	Skada_Skin:SetScript("OnEvent", function(self)
148		self:UnregisterAllEvents()
149		self = nil
150		
151		EmbedSkada()
152	end)
153
154	if TukuiTabsRightBackground then
155		local button = CreateFrame('Button', 'SkadaToggleSwitch', TukuiTabsRightBackground)
156		button:Width(90)
157		button:Height(TukuiTabsRightBackground:GetHeight() - 4)
158		button:Point("CENTER", TukuiTabsRightBackground, "CENTER", 2, 0)
159		
160		button.tex = button:CreateTexture(nil, 'OVERLAY')
161		button.tex:SetTexture([[Interface\AddOns\Tukui\medias\textures\addons_toggle.tga]])
162		button.tex:Point('TOPRIGHT', -2, 0)
163		button.tex:Height(button:GetHeight() - 4)
164		button.tex:Width(16)
165		
166		button:FontString(nil, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
167		button.text:SetPoint('RIGHT', button.tex, 'LEFT')
168		button.text:SetTextColor(unpack(C["media"].datacolor))
169		
170		button:SetScript('OnEnter', function(self) button.text:SetText(L.addons_toggle..' Skada') end)
171		button:SetScript('OnLeave', function(self) self.tex:Point('TOPRIGHT', -2, 0); button.text:SetText(nil) end)
172		button:SetScript('OnMouseDown', function(self) self.tex:Point('TOPRIGHT', -4, -4) end)
173		button:SetScript('OnMouseUp', function(self) self.tex:Point('TOPRIGHT', -2, -2) end)
174		button:SetScript('OnClick', function(self) Skada:ToggleWindow() end)
175	end	
176	
177	if C["Addon_Skins"].embedrighttoggle == true then
178		TukuiChatBackgroundRight:HookScript("OnShow", function()
179			for _, window in ipairs(Skada:GetWindows()) do
180				window:Hide()
181			end
182		end)
183		TukuiChatBackgroundRight:HookScript("OnHide", function()
184			for _, window in ipairs(Skada:GetWindows()) do
185				window:Show()
186			end
187		end)
188	end
189end