/Tukui/modules/addonskins/Skada.lua

http://github.com/Asphyxia/Tukui · Lua · 189 lines · 157 code · 30 blank · 2 comment · 22 complexity · f6e3408a7dcc8a38ddfcb8a696b9359e MD5 · raw file

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