PageRenderTime 63ms CodeModel.GetById 50ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/TelUI_AddonSkins/compat_TukUI.lua

http://github.com/Asphyxia/Tukui
Lua | 169 lines | 101 code | 15 blank | 53 comment | 16 complexity | 93dc9542ef71ca2045344b4f51ad759a MD5 | raw file
  1--[[
  2	Compatibility layer for TukUI v10 and v11
  3
  4	Provides the base implementation of Mod_AddonSkins, Skin, Layout, and TelUI.config needed to
  5	support skinning inside of the TukUI environment. There is no OOP or memory management
  6	available.
  7
  8	*TukUI Edit Authors*
  9	These skins can be easily hooked by defining methods in the CustomSkin object. There are several
 10	base functions defined by this file, and each skin has its own functions which can be hooked. Please
 11	check the headers of each file for a list and description of what methods can be customized. An example of overriding
 12	a skin would be as follows:
 13
 14	function CustomSkin:SkinBackgroundFrame(frame)
 15		self:SkinFrame(frame)
 16		T.CreateShadow(frame)
 17	end
 18
 19	Here we're modifying the :SkinBackground() method to add shadows. Note that self is a reference to the skin object,
 20	which means you can call any of the other skinning functions from it. The above block of code may be placed anywhere
 21	in your own addon or code, so long as it is executed before the PLAYER_LOGIN event fires. To remove a skin customization,
 22	simply dereference the function like so:
 23
 24	CustomSkin.SkinBackgroundFrame = nil
 25
 26	This will cause the skins to fall back to the default skinning function. *PLEASE NOTE* All skinning functions must be able
 27	to handle being called with the same arguments many times. This means that Adding shadows or highlights must be able to
 28	check if they've already created and attached a shadow, to prevent memory leaks. Some of these functions are called many
 29	times a second with the same frame! Due to the way that these skins are implemented with TukUI, both SKIN functions and
 30	LAYOUT functions are customized through CustomSkin.
 31
 32	Availble SKIN methods:
 33
 34	:SkinFrame(frame) -- Applies a basic skin to the frame "frame". This method will be called to skin any frames created or managed
 35	by the skins, including frames that are stacked on top of one another.
 36
 37	:SkinBackgroundFrame(frame) -- Similar to :SkinFrame(frame), this method only handles frames which are directly above the WorldFrame,
 38	or which are the base of a UI element. This is where you want to apply your shadows and such.
 39
 40	:SkinFrame(frame) -- Applies a skin to a frame, which will be used as a panel against the background
 41
 42	:SkinButton(button) -- This method will skin a button, including icon, to fit within the skin.	
 43
 44	File version v91.109
 45	(C)2010 Darth Android / Telroth-The Venture Co.
 46]]
 47
 48-- Don't run if TelUI is loaded, or TukUI isn't.
 49if IsAddOnLoaded("TelUI") or Mod_AddonSkins or not IsAddOnLoaded("Tukui") then return end
 50
 51local T, C, L = unpack(Tukui) -- Import: T - functions, constants, variables; C - config; L - locales
 52
 53local TukVer = tonumber(T.version)
 54
 55Mod_AddonSkins = CreateFrame("Frame")
 56local Mod_AddonSkins = Mod_AddonSkins
 57
 58function Mod_AddonSkins:SkinFrame(frame)
 59	frame:SetTemplate("Default")
 60end
 61
 62function Mod_AddonSkins:SkinBackgroundFrame(frame)
 63	frame:SetTemplate("Transparent")
 64end
 65
 66function Mod_AddonSkins:SkinButton(button)
 67	self:SkinFrame(button)
 68	button:StyleButton(button.GetCheckedTexture and button:GetCheckedTexture())
 69end
 70
 71function Mod_AddonSkins:SkinActionButton(button)
 72	if not button then return end
 73	self:SkinButton(button)
 74	local name = button:GetName()
 75	button.count = button.count or _G[name.."Count"]
 76	if button.count then
 77		button.count:SetFont(self.font,self.fontSize,self.fontFlags)
 78		button.count:SetDrawLayer("OVERLAY")
 79	end
 80	button.hotkey = button.hotkey or _G[name.."HotKey"]
 81	if button.hotkey then
 82		button.hotkey:SetFont(self.font,self.fontSize,self.fontFlags)
 83		button.hotkey:SetDrawLayer("OVERLAY")
 84	end
 85	button.icon = button.icon or _G[name.."Icon"]
 86	if button.icon then
 87		button.icon:SetTexCoord(unpack(self.buttonZoom))
 88		button.icon:SetDrawLayer("ARTWORK",-1)
 89		button.icon:ClearAllPoints()
 90		button.icon:SetPoint("TOPLEFT",button,"TOPLEFT",self.borderWidth, -self.borderWidth)
 91		button.icon:SetPoint("BOTTOMRIGHT",button,"BOTTOMRIGHT",-self.borderWidth, self.borderWidth)
 92	end
 93	button.textName = button.textName or _G[name.."Name"]
 94	if button.textName then
 95		button.textName:SetAlpha(0)
 96	end
 97	button.cd = button.cd or _G[name.."Cooldown"]
 98end
 99
100Mod_AddonSkins.barTexture = C.media.normTex
101Mod_AddonSkins.bgTexture = C.media.blank
102Mod_AddonSkins.font = C.media.pixelfont
103Mod_AddonSkins.smallFont = C.media.pixelfont
104Mod_AddonSkins.fontSize = 8
105Mod_AddonSkins.fontStyle = "MONOCHROMEOUTLINE"
106Mod_AddonSkins.buttonSize = T.Scale(27)
107Mod_AddonSkins.buttonSpacing = T.Scale(4)
108Mod_AddonSkins.borderWidth = T.Scale(2)
109Mod_AddonSkins.buttonZoom = {.08,.92,.08,.92}
110Mod_AddonSkins.barSpacing = T.Scale(1)
111Mod_AddonSkins.barHeight = T.Scale(20)
112Mod_AddonSkins.skins = {}
113Mod_AddonSkins.__index = Mod_AddonSkins
114
115-- TukUI-Specific Integration Support
116
117local CustomSkin = setmetatable(CustomSkin or {},Mod_AddonSkins)
118
119-- Custom SexyCooldown positioning. This is used to lock the bars into place above the action bar or over either info bar.
120-- To achieve this, the user must name their bar either "actionbar", "infoleft", or "inforight" depending on where they want
121-- the bar anchored.
122if not CustomSkin.PositionSexyCooldownBar then
123	function CustomSkin:PositionSexyCooldownBar(bar)
124		if bar.settings.bar.name == "actionbar" then
125			self:SCDStripLayoutSettings(bar)
126			bar.settings.bar.inactiveAlpha = 1
127			bar:SetHeight(self.buttonSize)
128			bar:SetWidth(TukuiActionBarBackground:GetWidth() - 2 * self.buttonSpacing)
129			bar:SetPoint("TOPLEFT",TukuiActionBarBackground,"TOPLEFT",self.buttonSpacing,-self.buttonSpacing)
130			bar:SetPoint("TOPRIGHT",TukuiActionBarBackground,"TOPRIGHT",-self.buttonSpacing,-self.buttonSpacing)
131			if not TukuiActionBarBackground.resized then
132				TukuiActionBarBackground:SetHeight(TukuiActionBarBackground:GetHeight() + self.buttonSize + self.buttonSpacing)
133				InvTukuiActionBarBackground:SetHeight(TukuiActionBarBackground:GetHeight())
134				TukuiActionBarBackground.resized = true
135			end
136		elseif bar.settings.bar.name == "infoleft" then
137			self:SCDStripLayoutSettings(bar)
138			bar.settings.bar.inactiveAlpha = 0
139			bar:SetAllPoints(TukuiInfoLeft)
140		elseif bar.settings.bar.name == "inforight" then
141			self:SCDStripLayoutSettings(bar)
142			bar.settings.bar.inactiveAlpha = 0
143			bar:SetAllPoints(TukuiInfoRight)
144		end
145	end
146end
147
148-- Dummy function expected by some skins
149function dummy() end
150
151function Mod_AddonSkins:RegisterSkin(name, initFunc)
152	self = Mod_AddonSkins -- Static function
153	if type(initFunc) ~= "function" then error("initFunc must be a function!",2) end
154	self.skins[name] = initFunc
155	if name == "LibSharedMedia" then -- Load LibSharedMedia early.
156		initFunc(self, CustomSkin, self, CustomSkin, CustomSkin)
157		self.skins[name] = nil
158	end
159end
160
161Mod_AddonSkins:RegisterEvent("PLAYER_LOGIN")
162Mod_AddonSkins:SetScript("OnEvent",function(self)
163	self:UnregisterEvent("PLAYER_LOGIN")
164	self:SetScript("OnEvent",nil)
165	-- Initialize all skins
166	for name, func in pairs(self.skins) do
167		func(self,CustomSkin,self,CustomSkin,CustomSkin) -- Mod_AddonSkins functions as skin, layout, and config.
168	end
169end)