/TelUI_AddonSkins/compat_TukUI.lua

http://github.com/Asphyxia/Tukui · Lua · 169 lines · 101 code · 15 blank · 53 comment · 28 complexity · 93dc9542ef71ca2045344b4f51ad759a MD5 · raw file

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