PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/actionbars/Style.lua

http://github.com/Asphyxia/Tukui
Lua | 557 lines | 454 code | 76 blank | 27 comment | 68 complexity | 89dbf48716eb457561921416067f00aa MD5 | raw file
  1. local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2. if not C["actionbar"].enable == true then return end
  3. local _G = _G
  4. local media = C["media"]
  5. local securehandler = CreateFrame("Frame", nil, nil, "SecureHandlerBaseTemplate")
  6. local replace = string.gsub
  7. local function style(self)
  8. local name = self:GetName()
  9. --> fixing a taint issue while changing totem flyout button in combat.
  10. if name:match("MultiCastActionButton") then return end
  11. local action = self.action
  12. local Button = self
  13. local Icon = _G[name.."Icon"]
  14. local Count = _G[name.."Count"]
  15. local Flash = _G[name.."Flash"]
  16. local HotKey = _G[name.."HotKey"]
  17. local Border = _G[name.."Border"]
  18. local Btname = _G[name.."Name"]
  19. local normal = _G[name.."NormalTexture"]
  20. Flash:SetTexture("")
  21. Button:SetNormalTexture("")
  22. Border:Hide()
  23. Border = T.dummy
  24. Count:ClearAllPoints()
  25. Count:Point("BOTTOMRIGHT", 0, 2)
  26. Count:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
  27. if not C["actionbar"].macrotext == true then
  28. Btname:SetText("")
  29. Btname:Kill()
  30. else
  31. Btname:SetAlphaGradient(0,Button:GetWidth())
  32. Btname:SetFont(C.media.pixelfont, C["datatext"].fontsize+1, "MONOCHROMEOUTLINE")
  33. end
  34. if not _G[name.."Panel"] then
  35. -- resize all button not matching T.buttonsize
  36. if self:GetHeight() ~= T.buttonsize and not InCombatLockdown() then --Taint fix for Flyout Buttons
  37. self:Size(T.buttonsize, T.buttonsize)
  38. end
  39. -- create the bg/border panel
  40. local panel = CreateFrame("Frame", name.."Panel", self)
  41. panel:CreatePanel("Default", T.buttonsize, T.buttonsize, "CENTER", self, "CENTER", 0, 0)
  42. panel:SetFrameStrata(self:GetFrameStrata())
  43. panel:SetFrameLevel(self:GetFrameLevel() - 1)
  44. Icon:SetTexCoord(.09, .91, .09, .91)
  45. Icon:Point("TOPLEFT", 2, -2)
  46. Icon:Point("BOTTOMRIGHT", -2, 2)
  47. end
  48. HotKey:ClearAllPoints()
  49. HotKey:Point("TOPRIGHT", 0, -3)
  50. HotKey:SetFont(C.media.pixelfont, C["datatext"].fontsize+1, "MONOCHROMEOUTLINE")
  51. HotKey.ClearAllPoints = T.dummy
  52. HotKey.SetPoint = T.dummy
  53. if not C["actionbar"].hotkey == true then
  54. HotKey:SetText("")
  55. HotKey:Kill()
  56. end
  57. if normal then
  58. normal:ClearAllPoints()
  59. normal:Point("TOPLEFT")
  60. normal:Point("BOTTOMRIGHT")
  61. end
  62. end
  63. local function stylesmallbutton(normal, button, icon, name, pet)
  64. local Flash = _G[name.."Flash"]
  65. button:SetNormalTexture("")
  66. -- another bug fix reported by Affli in t12 beta
  67. button.SetNormalTexture = T.dummy
  68. Flash:SetTexture(media.buttonhover)
  69. if not _G[name.."Panel"] then
  70. if pet then
  71. button:Width(T.petbuttonsize)
  72. button:Height(T.petbuttonsize)
  73. local panel = CreateFrame("Frame", name.."Panel", button)
  74. panel:CreatePanel("Default", T.petbuttonsize, T.petbuttonsize, "CENTER", button, "CENTER", 0, 0)
  75. panel:SetFrameStrata(button:GetFrameStrata())
  76. panel:SetFrameLevel(button:GetFrameLevel() - 1)
  77. -- let's kill auto-castable triangles instead
  78. _G[name.."AutoCastable"]:Kill()
  79. local shine = _G[name.."Shine"]
  80. shine:Size(T.petbuttonsize, T.petbuttonsize)
  81. else
  82. button:Width(T.stancebuttonsize)
  83. button:Height(T.stancebuttonsize)
  84. local panel = CreateFrame("Frame", name.."Panel", button)
  85. panel:CreatePanel("Default", T.stancebuttonsize, T.stancebuttonsize, "CENTER", button, "CENTER", 0, 0)
  86. panel:SetFrameStrata(button:GetFrameStrata())
  87. panel:SetFrameLevel(button:GetFrameLevel() - 1)
  88. end
  89. icon:SetTexCoord(.09, .91, .09, .91)
  90. icon:ClearAllPoints()
  91. icon:Point("TOPLEFT", 2, -2)
  92. icon:Point("BOTTOMRIGHT", -2, 2)
  93. end
  94. if normal then
  95. normal:ClearAllPoints()
  96. normal:Point("TOPLEFT")
  97. normal:Point("BOTTOMRIGHT")
  98. end
  99. end
  100. function T.StyleShift()
  101. for i=1, NUM_SHAPESHIFT_SLOTS do
  102. local name = "ShapeshiftButton"..i
  103. local button = _G[name]
  104. local icon = _G[name.."Icon"]
  105. local normal = _G[name.."NormalTexture"]
  106. stylesmallbutton(normal, button, icon, name)
  107. end
  108. end
  109. function T.StylePet()
  110. for i=1, NUM_PET_ACTION_SLOTS do
  111. local name = "PetActionButton"..i
  112. local button = _G[name]
  113. local icon = _G[name.."Icon"]
  114. local normal = _G[name.."NormalTexture2"]
  115. stylesmallbutton(normal, button, icon, name, true)
  116. end
  117. end
  118. function T.TukuiShiftBarUpdate()
  119. local numForms = GetNumShapeshiftForms()
  120. local texture, name, isActive, isCastable
  121. local button, icon, cooldown
  122. local start, duration, enable
  123. for i = 1, NUM_SHAPESHIFT_SLOTS do
  124. button = _G["ShapeshiftButton"..i]
  125. icon = _G["ShapeshiftButton"..i.."Icon"]
  126. if i <= numForms then
  127. texture, name, isActive, isCastable = GetShapeshiftFormInfo(i)
  128. icon:SetTexture(texture)
  129. cooldown = _G["ShapeshiftButton"..i.."Cooldown"]
  130. if texture then
  131. cooldown:SetAlpha(1)
  132. else
  133. cooldown:SetAlpha(0)
  134. end
  135. start, duration, enable = GetShapeshiftFormCooldown(i)
  136. CooldownFrame_SetTimer(cooldown, start, duration, enable)
  137. if isActive then
  138. ShapeshiftBarFrame.lastSelected = button:GetID()
  139. button:SetChecked(1)
  140. else
  141. button:SetChecked(0)
  142. end
  143. if isCastable then
  144. icon:SetVertexColor(1.0, 1.0, 1.0)
  145. else
  146. icon:SetVertexColor(0.4, 0.4, 0.4)
  147. end
  148. end
  149. end
  150. end
  151. T.TukuiPetBarUpdate = function(self, event)
  152. local petActionButton, petActionIcon, petAutoCastableTexture, petAutoCastShine
  153. for i=1, NUM_PET_ACTION_SLOTS, 1 do
  154. local buttonName = "PetActionButton" .. i
  155. petActionButton = _G[buttonName]
  156. petActionIcon = _G[buttonName.."Icon"]
  157. petAutoCastableTexture = _G[buttonName.."AutoCastable"]
  158. petAutoCastShine = _G[buttonName.."Shine"]
  159. local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(i)
  160. if not isToken then
  161. petActionIcon:SetTexture(texture)
  162. petActionButton.tooltipName = name
  163. else
  164. petActionIcon:SetTexture(_G[texture])
  165. petActionButton.tooltipName = _G[name]
  166. end
  167. petActionButton.isToken = isToken
  168. petActionButton.tooltipSubtext = subtext
  169. if isActive and name ~= "PET_ACTION_FOLLOW" then
  170. petActionButton:SetChecked(1)
  171. if IsPetAttackAction(i) then
  172. PetActionButton_StartFlash(petActionButton)
  173. end
  174. else
  175. petActionButton:SetChecked(0)
  176. if IsPetAttackAction(i) then
  177. PetActionButton_StopFlash(petActionButton)
  178. end
  179. end
  180. if autoCastAllowed then
  181. petAutoCastableTexture:Show()
  182. else
  183. petAutoCastableTexture:Hide()
  184. end
  185. if autoCastEnabled then
  186. AutoCastShine_AutoCastStart(petAutoCastShine)
  187. else
  188. AutoCastShine_AutoCastStop(petAutoCastShine)
  189. end
  190. -- grid display
  191. if name then
  192. if not C["actionbar"].showgrid then
  193. petActionButton:SetAlpha(1)
  194. end
  195. else
  196. if not C["actionbar"].showgrid then
  197. petActionButton:SetAlpha(0)
  198. end
  199. end
  200. if texture then
  201. if GetPetActionSlotUsable(i) then
  202. SetDesaturation(petActionIcon, nil)
  203. else
  204. SetDesaturation(petActionIcon, 1)
  205. end
  206. petActionIcon:Show()
  207. else
  208. petActionIcon:Hide()
  209. end
  210. -- between level 1 and 10 on cata, we don't have any control on Pet. (I lol'ed so hard)
  211. -- Setting desaturation on button to true until you learn the control on class trainer.
  212. -- you can at least control "follow" button.
  213. if not PetHasActionBar() and texture and name ~= "PET_ACTION_FOLLOW" then
  214. PetActionButton_StopFlash(petActionButton)
  215. SetDesaturation(petActionIcon, 1)
  216. petActionButton:SetChecked(0)
  217. end
  218. end
  219. end
  220. local function updatehotkey(self, actionButtonType)
  221. local hotkey = _G[self:GetName() .. 'HotKey']
  222. local text = hotkey:GetText()
  223. text = replace(text, '(s%-)', 'S')
  224. text = replace(text, '(a%-)', 'A')
  225. text = replace(text, '(c%-)', 'C')
  226. text = replace(text, '(Mouse Button )', 'M')
  227. text = replace(text, '(Middle Mouse)', 'M3')
  228. text = replace(text, '(Mouse Wheel Up)', 'MU')
  229. text = replace(text, '(Mouse Wheel Down)', 'MD')
  230. text = replace(text, '(Num Pad )', 'N')
  231. text = replace(text, '(Page Up)', 'PU')
  232. text = replace(text, '(Page Down)', 'PD')
  233. text = replace(text, '(Spacebar)', 'SpB')
  234. text = replace(text, '(Insert)', 'Ins')
  235. text = replace(text, '(Home)', 'Hm')
  236. text = replace(text, '(Delete)', 'Del')
  237. if hotkey:GetText() == _G['RANGE_INDICATOR'] then
  238. hotkey:SetText('')
  239. else
  240. hotkey:SetText(text)
  241. end
  242. end
  243. -- rescale cooldown spiral to fix texture.
  244. local buttonNames = { "ActionButton", "MultiBarBottomLeftButton", "MultiBarBottomRightButton", "MultiBarLeftButton", "MultiBarRightButton", "ShapeshiftButton", "PetActionButton", "MultiCastActionButton"}
  245. for _, name in ipairs( buttonNames ) do
  246. for index = 1, 12 do
  247. local buttonName = name .. tostring(index)
  248. local button = _G[buttonName]
  249. local cooldown = _G[buttonName .. "Cooldown"]
  250. if ( button == nil or cooldown == nil ) then
  251. break
  252. end
  253. cooldown:ClearAllPoints()
  254. cooldown:Point("TOPLEFT", button, "TOPLEFT", 2, -2)
  255. cooldown:Point("BOTTOMRIGHT", button, "BOTTOMRIGHT", -2, 2)
  256. end
  257. end
  258. local buttons = 0
  259. local function SetupFlyoutButton()
  260. for i=1, buttons do
  261. --prevent error if you don't have max ammount of buttons
  262. if _G["SpellFlyoutButton"..i] then
  263. style(_G["SpellFlyoutButton"..i])
  264. if _G["SpellFlyoutButton"..i]:GetChecked() then
  265. _G["SpellFlyoutButton"..i]:SetChecked(nil)
  266. end
  267. end
  268. end
  269. end
  270. SpellFlyout:HookScript("OnShow", SetupFlyoutButton)
  271. --Hide the Mouseover texture and attempt to find the ammount of buttons to be skinned
  272. local function styleflyout(self)
  273. self.FlyoutBorder:SetAlpha(0)
  274. self.FlyoutBorderShadow:SetAlpha(0)
  275. SpellFlyoutHorizontalBackground:SetAlpha(0)
  276. SpellFlyoutVerticalBackground:SetAlpha(0)
  277. SpellFlyoutBackgroundEnd:SetAlpha(0)
  278. for i=1, GetNumFlyouts() do
  279. local x = GetFlyoutID(i)
  280. local _, _, numSlots, isKnown = GetFlyoutInfo(x)
  281. if isKnown then
  282. buttons = numSlots
  283. break
  284. end
  285. end
  286. --Change arrow direction depending on what bar the button is on
  287. local arrowDistance
  288. if ((SpellFlyout and SpellFlyout:IsShown() and SpellFlyout:GetParent() == self) or GetMouseFocus() == self) then
  289. arrowDistance = 5
  290. else
  291. arrowDistance = 2
  292. end
  293. if self:GetParent():GetParent():GetName() == "SpellBookSpellIconsFrame" then return end
  294. if self:GetAttribute("flyoutDirection") ~= nil then
  295. local point, _, _, _, _ = self:GetParent():GetParent():GetPoint()
  296. if strfind(point, "BOTTOM") then
  297. self.FlyoutArrow:ClearAllPoints()
  298. self.FlyoutArrow:SetPoint("TOP", self, "TOP", 0, arrowDistance)
  299. SetClampedTextureRotation(self.FlyoutArrow, 0)
  300. if not InCombatLockdown() then self:SetAttribute("flyoutDirection", "UP") end
  301. else
  302. self.FlyoutArrow:ClearAllPoints()
  303. self.FlyoutArrow:SetPoint("LEFT", self, "LEFT", -arrowDistance, 0)
  304. SetClampedTextureRotation(self.FlyoutArrow, 270)
  305. if not InCombatLockdown() then self:SetAttribute("flyoutDirection", "LEFT") end
  306. end
  307. end
  308. end
  309. -- rework the mouseover, pushed, checked texture to match Tukui theme.
  310. do
  311. for i = 1, 12 do
  312. _G["ActionButton"..i]:StyleButton(true)
  313. _G["MultiBarBottomLeftButton"..i]:StyleButton(true)
  314. _G["MultiBarBottomRightButton"..i]:StyleButton(true)
  315. _G["MultiBarLeftButton"..i]:StyleButton(true)
  316. _G["MultiBarRightButton"..i]:StyleButton(true)
  317. end
  318. for i=1, 10 do
  319. _G["ShapeshiftButton"..i]:StyleButton(true)
  320. _G["PetActionButton"..i]:StyleButton(true)
  321. end
  322. end
  323. hooksecurefunc("ActionButton_Update", style)
  324. hooksecurefunc("ActionButton_UpdateHotkeys", updatehotkey)
  325. hooksecurefunc("ActionButton_UpdateFlyout", styleflyout)
  326. ---------------------------------------------------------------
  327. -- Totem Style, they need a lot more work than "normal" buttons
  328. -- Because of this, we skin it via separate styling codes
  329. -- Special thank's to DarthAndroid
  330. ---------------------------------------------------------------
  331. -- don't continue executing code in this file is not playing a shaman.
  332. if not T.myclass == "SHAMAN" then return end
  333. -- Tex Coords for empty buttons
  334. SLOT_EMPTY_TCOORDS = {
  335. [EARTH_TOTEM_SLOT] = {
  336. left = 66 / 128,
  337. right = 96 / 128,
  338. top = 3 / 256,
  339. bottom = 33 / 256,
  340. },
  341. [FIRE_TOTEM_SLOT] = {
  342. left = 67 / 128,
  343. right = 97 / 128,
  344. top = 100 / 256,
  345. bottom = 130 / 256,
  346. },
  347. [WATER_TOTEM_SLOT] = {
  348. left = 39 / 128,
  349. right = 69 / 128,
  350. top = 209 / 256,
  351. bottom = 239 / 256,
  352. },
  353. [AIR_TOTEM_SLOT] = {
  354. left = 66 / 128,
  355. right = 96 / 128,
  356. top = 36 / 256,
  357. bottom = 66 / 256,
  358. },
  359. }
  360. local function StyleTotemFlyout(flyout)
  361. -- remove blizzard flyout texture
  362. flyout.top:SetTexture(nil)
  363. flyout.middle:SetTexture(nil)
  364. -- Skin buttons
  365. local last = nil
  366. for _,button in ipairs(flyout.buttons) do
  367. button:SetTemplate("Default")
  368. local icon = select(1,button:GetRegions())
  369. icon:SetTexCoord(.09,.91,.09,.91)
  370. icon:SetDrawLayer("ARTWORK")
  371. icon:Point("TOPLEFT",button,"TOPLEFT",2,-2)
  372. icon:Point("BOTTOMRIGHT",button,"BOTTOMRIGHT",-2,2)
  373. if not InCombatLockdown() then
  374. button:Size(T.stancebuttonsize)
  375. button:ClearAllPoints()
  376. button:Point("BOTTOM",last,"TOP",0,4)
  377. end
  378. if button:IsVisible() then last = button end
  379. button:SetBackdropBorderColor(flyout.parent:GetBackdropBorderColor())
  380. button:StyleButton()
  381. end
  382. flyout.buttons[1]:SetPoint("BOTTOM",flyout,"BOTTOM")
  383. if flyout.type == "slot" then
  384. local tcoords = SLOT_EMPTY_TCOORDS[flyout.parent:GetID()]
  385. flyout.buttons[1].icon:SetTexCoord(tcoords.left,tcoords.right,tcoords.top,tcoords.bottom)
  386. end
  387. -- Skin Close button
  388. local close = MultiCastFlyoutFrameCloseButton
  389. close:SetTemplate("Default")
  390. close:GetHighlightTexture():SetTexture([[Interface\Buttons\ButtonHilight-Square]])
  391. close:GetHighlightTexture():Point("TOPLEFT",close,"TOPLEFT",1,-1)
  392. close:GetHighlightTexture():Point("BOTTOMRIGHT",close,"BOTTOMRIGHT",-1,1)
  393. close:GetNormalTexture():SetTexture(nil)
  394. close:ClearAllPoints()
  395. close:Point("BOTTOMLEFT",last,"TOPLEFT",0,4)
  396. close:Point("BOTTOMRIGHT",last,"TOPRIGHT",0,4)
  397. close:Height(8)
  398. close:SetBackdropBorderColor(last:GetBackdropBorderColor())
  399. flyout:ClearAllPoints()
  400. flyout:Point("BOTTOM",flyout.parent,"TOP",0,4)
  401. end
  402. hooksecurefunc("MultiCastFlyoutFrame_ToggleFlyout",function(self) StyleTotemFlyout(self) end)
  403. local function StyleTotemOpenButton(button, parent)
  404. button:GetHighlightTexture():SetTexture(nil)
  405. button:GetNormalTexture():SetTexture(nil)
  406. button:Height(20)
  407. button:ClearAllPoints()
  408. button:Point("BOTTOMLEFT", parent, "TOPLEFT", 0, -3)
  409. button:Point("BOTTOMRIGHT", parent, "TOPRIGHT", 0, -3)
  410. if not button.visibleBut then
  411. button.visibleBut = CreateFrame("Frame",nil,button)
  412. button.visibleBut:Height(8)
  413. button.visibleBut:Width(button:GetWidth() + 2)
  414. button.visibleBut:SetPoint("CENTER")
  415. button.visibleBut.highlight = button.visibleBut:CreateTexture(nil,"HIGHLIGHT")
  416. button.visibleBut.highlight:SetTexture([[Interface\Buttons\ButtonHilight-Square]])
  417. button.visibleBut.highlight:Point("TOPLEFT",button.visibleBut,"TOPLEFT",1,-1)
  418. button.visibleBut.highlight:Point("BOTTOMRIGHT",button.visibleBut,"BOTTOMRIGHT",-1,1)
  419. button.visibleBut:SetTemplate("Default")
  420. end
  421. button.visibleBut:SetBackdropBorderColor(parent:GetBackdropBorderColor())
  422. end
  423. hooksecurefunc("MultiCastFlyoutFrameOpenButton_Show",function(button,_, parent) StyleTotemOpenButton(button, parent) end)
  424. -- the color we use for border
  425. local bordercolors = {
  426. {.23,.45,.13}, -- Earth
  427. {.58,.23,.10}, -- Fire
  428. {.19,.48,.60}, -- Water
  429. {.42,.18,.74}, -- Air
  430. }
  431. local function StyleTotemSlotButton(button, index)
  432. button:SetTemplate("Default")
  433. button.overlayTex:SetTexture(nil)
  434. button.background:SetDrawLayer("ARTWORK")
  435. button.background:ClearAllPoints()
  436. button.background:Point("TOPLEFT",button,"TOPLEFT",2,-2)
  437. button.background:Point("BOTTOMRIGHT",button,"BOTTOMRIGHT",-2,2)
  438. if not InCombatLockdown() then button:Size(T.stancebuttonsize) end
  439. button:SetBackdropBorderColor(unpack(bordercolors[((index-1) % 4) + 1]))
  440. button:CreateShadow("Default")
  441. button:StyleButton()
  442. end
  443. hooksecurefunc("MultiCastSlotButton_Update",function(self, slot) StyleTotemSlotButton(self,tonumber( string.match(self:GetName(),"MultiCastSlotButton(%d)"))) end)
  444. -- Skin the actual totem buttons
  445. local function StyleTotemActionButton(button, index)
  446. local icon = select(1,button:GetRegions())
  447. icon:SetTexCoord(.09,.91,.09,.91)
  448. icon:SetDrawLayer("ARTWORK")
  449. icon:Point("TOPLEFT",button,"TOPLEFT",2,-2)
  450. icon:Point("BOTTOMRIGHT",button,"BOTTOMRIGHT",-2,2)
  451. button.overlayTex:SetTexture(nil)
  452. button.overlayTex:Hide()
  453. button:GetNormalTexture():SetTexCoord(0,0,0,0)
  454. if not InCombatLockdown() and button.slotButton then
  455. button:ClearAllPoints()
  456. button:SetAllPoints(button.slotButton)
  457. button:SetFrameLevel(button.slotButton:GetFrameLevel()+1)
  458. end
  459. button:SetBackdropBorderColor(unpack(bordercolors[((index-1) % 4) + 1]))
  460. button:SetBackdropColor(0,0,0,0)
  461. button:StyleButton(true)
  462. end
  463. hooksecurefunc("MultiCastActionButton_Update",function(actionButton, actionId, actionIndex, slot) StyleTotemActionButton(actionButton,actionIndex) end)
  464. -- Skin the summon and recall buttons
  465. local function StyleTotemSpellButton(button, index)
  466. if not button then return end
  467. local icon = select(1,button:GetRegions())
  468. icon:SetTexCoord(.09,.91,.09,.91)
  469. icon:SetDrawLayer("ARTWORK")
  470. icon:Point("TOPLEFT",button,"TOPLEFT",2,-2)
  471. icon:Point("BOTTOMRIGHT",button,"BOTTOMRIGHT",-2,2)
  472. button:SetTemplate("Default")
  473. button:GetNormalTexture():SetTexture(nil)
  474. if not InCombatLockdown() then button:Size(T.stancebuttonsize) end
  475. _G[button:GetName().."Highlight"]:SetTexture(nil)
  476. _G[button:GetName().."NormalTexture"]:SetTexture(nil)
  477. button:CreateShadow("Default")
  478. button:StyleButton()
  479. end
  480. hooksecurefunc("MultiCastSummonSpellButton_Update", function(self) StyleTotemSpellButton(self,0) end)
  481. hooksecurefunc("MultiCastRecallSpellButton_Update", function(self) StyleTotemSpellButton(self,5) end)