PageRenderTime 27ms CodeModel.GetById 11ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/addonskins/bigwigs.lua

http://github.com/Asphyxia/Tukui
Lua | 204 lines | 161 code | 27 blank | 16 comment | 27 complexity | 02b453d5f5b145003eecab0dfe779f56 MD5 | raw file
  1--[[
  2Author: Affli@RU-Howling Fjord, 
  3Modified: Elv
  4All rights reserved.
  5]]--
  6local T, C, L = unpack(select(2, ...))
  7
  8if not IsAddOnLoaded("BigWigs") or not C.Addon_Skins.bigwigs then return end
  9
 10local buttonsize = 19
 11
 12-- init some tables to store backgrounds
 13local freebg = {}
 14
 15-- styling functions
 16local createbg = function()
 17	local bg = CreateFrame("Frame")
 18	bg:SetTemplate("Transparent")
 19	return bg
 20end
 21
 22local function freestyle(bar)
 23
 24	-- reparent and hide bar background
 25	local bg = bar:Get("bigwigs:Tukui:bg")
 26	if bg then
 27		bg:ClearAllPoints()
 28		bg:SetParent(UIParent)
 29		bg:Hide()
 30		freebg[#freebg + 1] = bg
 31	end
 32
 33	-- reparent and hide icon background
 34	local ibg = bar:Get("bigwigs:Tukui:bg")
 35	if ibg then
 36		ibg:ClearAllPoints()
 37		ibg:SetParent(UIParent)
 38		ibg:Hide()
 39		freebg[#freebg + 1] = ibg
 40	end
 41
 42	-- replace dummies with original method functions
 43	bar.candyBarBar.SetPoint=bar.candyBarBar.OldSetPoint
 44	bar.candyBarIconFrame.SetWidth=bar.candyBarIconFrame.OldSetWidth
 45	bar.SetScale=bar.OldSetScale
 46end
 47
 48local applystyle = function(bar)
 49
 50	-- general bar settings
 51	bar:SetHeight(buttonsize)
 52	bar:SetScale(1)
 53	bar.OldSetScale=bar.SetScale
 54	bar.SetScale=T.dummy
 55
 56	-- create or reparent and use bar background
 57	local bg = nil
 58	if #freebg > 0 then
 59		bg = table.remove(freebg)
 60	else
 61		bg = createbg()
 62	end
 63	
 64	bg:SetParent(bar)
 65	bg:ClearAllPoints()
 66	bg:Point("TOPLEFT", bar, "TOPLEFT", -2, 2)
 67	bg:Point("BOTTOMRIGHT", bar, "BOTTOMRIGHT", 2, -2)
 68	bg:SetFrameStrata("BACKGROUND")
 69	bg:Show()
 70	bar:Set("bigwigs:Tukui:bg", bg)
 71
 72	-- create or reparent and use icon background
 73	local ibg = nil
 74	if bar.candyBarIconFrame:GetTexture() then
 75		if #freebg > 0 then
 76			ibg = table.remove(freebg)
 77		else
 78			ibg = createbg()
 79		end
 80		ibg:SetParent(bar)
 81		ibg:ClearAllPoints()
 82		ibg:Point("TOPLEFT", bar.candyBarIconFrame, "TOPLEFT", -2, 2)
 83		ibg:Point("BOTTOMRIGHT", bar.candyBarIconFrame, "BOTTOMRIGHT", 2, -2)
 84		ibg:SetFrameStrata("BACKGROUND")
 85		ibg:Show()
 86		bar:Set("bigwigs:Tukui:bg", ibg)
 87	end
 88
 89	-- setup timer and bar name fonts and positions
 90	bar.candyBarLabel:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 91	bar.candyBarLabel:SetShadowColor(0, 0, 0, 0)
 92	bar.candyBarLabel:SetJustifyH("LEFT")
 93	bar.candyBarLabel:ClearAllPoints()
 94	bar.candyBarLabel:Point("LEFT", bar, "LEFT", 4, 0)
 95	
 96	bar.candyBarDuration:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 97	bar.candyBarDuration:SetShadowColor(0, 0, 0, 0)
 98	bar.candyBarDuration:SetJustifyH("RIGHT")
 99	bar.candyBarDuration:ClearAllPoints()
100	bar.candyBarDuration:Point("RIGHT", bar, "RIGHT", -4, 0)
101
102	-- setup bar positions and look
103	bar.candyBarBar:ClearAllPoints()
104	bar.candyBarBar:SetAllPoints(bar)
105	bar.candyBarBar.OldSetPoint = bar.candyBarBar.SetPoint
106	bar.candyBarBar.SetPoint=T.dummy
107	bar.candyBarBar:SetStatusBarTexture(C["media"].normTex)
108	bar.candyBarBackground:SetTexture(unpack(C.media.backdropcolor))
109	
110	-- setup icon positions and other things
111	bar.candyBarIconFrame:ClearAllPoints()
112	bar.candyBarIconFrame:Point("BOTTOMRIGHT", bar, "BOTTOMLEFT", -7, 0)
113	bar.candyBarIconFrame:SetSize(buttonsize, buttonsize)
114	bar.candyBarIconFrame.OldSetWidth = bar.candyBarIconFrame.SetWidth
115	bar.candyBarIconFrame.SetWidth=T.dummy
116	bar.candyBarIconFrame:SetTexCoord(0.08, 0.92, 0.08, 0.92)
117end
118	
119
120local f = CreateFrame("Frame")
121
122local function RegisterStyle()
123	if not BigWigs then return end
124	local bars = BigWigs:GetPlugin("Bars", true)
125	local prox = BigWigs:GetPlugin("Proximity", true)
126	if bars then
127		bars:RegisterBarStyle("Tukui", {
128			apiVersion = 1,
129			version = 1,
130			GetSpacing = function(bar) return 7 end,
131			ApplyStyle = applystyle,
132			BarStopped = freestyle,
133			GetStyleName = function() return "Tukui" end,
134		})
135	end
136	if prox and BigWigs.pluginCore.modules.Bars.db.profile.barStyle == "Tukui" then
137		hooksecurefunc(BigWigs.pluginCore.modules.Proximity, "RestyleWindow", function()
138			BigWigsProximityAnchor:SetTemplate("Transparent")
139		end)
140	end
141end
142
143local function PositionBWAnchor()
144	if not BigWigsAnchor then return end
145	BigWigsAnchor:ClearAllPoints()
146	if E.CheckAddOnShown() == true then
147		if C["chat"].background == true and T.ChatRightShown == true then
148			BigWigsAnchor:Point("TOP", ChatRBGDummy, "TOP", 12, 0)	
149		else
150			BigWigsAnchor:Point("TOP", ChatRBGDummy, "TOP", 12, -32)
151		end	
152	else
153		BigWigsAnchor:Point("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -5, 8)		
154	end
155end
156
157local function PositionBWAnchor()
158	if not BigWigsAnchor then return end
159	BigWigsAnchor:ClearAllPoints()
160	BigWigsAnchor:Point("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -5, 3)		
161end
162
163f:RegisterEvent("ADDON_LOADED")
164f:SetScript("OnEvent", function(self, event, addon)
165	if event == "ADDON_LOADED" and addon == "BigWigs_Plugins" then
166		RegisterStyle()
167		local profile = BigWigs3DB["profileKeys"][T.myname.." - "..T.myrealm]
168		local path = BigWigs3DB["namespaces"]["BigWigs_Plugins_Bars"]["profiles"][profile]
169		path.texture = "Tukui Norm"
170		path.barStyle = "Tukui"
171		path.font = "Tukui Font"
172		
173		local path = BigWigs3DB["namespaces"]["BigWigs_Plugins_Messages"]["profiles"][profile]
174		path.font = "Tukui Font"
175		
176		local path = BigWigs3DB["namespaces"]["BigWigs_Plugins_Proximity"]["profiles"][profile]
177		path.font = "Tukui Font"
178		
179		f:UnregisterEvent("ADDON_LOADED")
180	elseif event == "PLAYER_ENTERING_WORLD" then
181		LoadAddOn("BigWigs_Core")
182		LoadAddOn("BigWigs_Plugins")
183		LoadAddOn("BigWigs_Options")
184		BigWigs:Enable()
185		BigWigsOptions:SendMessage("BigWigs_StartConfigureMode", true)
186		BigWigsOptions:SendMessage("BigWigs_StopConfigureMode")
187		PositionBWAnchor()
188
189		if Skada and Skada:GetWindows() and Skada:GetWindows()[1] and C["skin"].embed == "Skada" then
190			Skada:GetWindows()[1].bargroup:HookScript("OnShow", function() PositionBWAnchor() end)
191			Skada:GetWindows()[1].bargroup:HookScript("OnHide", function() PositionBWAnchor() end)
192		elseif Recount_MainWindow and C["skin"].embed == "Recount" then
193			Recount_MainWindow:HookScript("OnShow", function() PositionBWAnchor() end)
194			Recount_MainWindow:HookScript("OnHide", function() PositionBWAnchor() end)
195		elseif OmenAnchor and C["skin"].embed == "Omen" then
196			OmenAnchor:HookScript("OnShow", function() PositionBWAnchor() end)
197			OmenAnchor:HookScript("OnHide", function() PositionBWAnchor() end)		
198		end
199	elseif event == "PLAYER_REGEN_DISABLED" then
200		PositionBWAnchor()
201	elseif event == "PLAYER_REGEN_ENABLED" then
202		PositionBWAnchor()
203	end
204end)