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

/scripts/style.lua

https://github.com/AlleyKat/DerpyActionBars
Lua | 503 lines | 440 code | 54 blank | 9 comment | 74 complexity | 7f721c76c79eead7e8f549360e7ac0d2 MD5 | raw file
  1. local C,M,L,V = unpack(select(2,...))
  2. local _G = _G
  3. -- HOOK FOR VERTEX COLOR
  4. local teh_new_vertex = function(self,r,g,b)
  5. if self.r_old == r and self.g_old == g and self.b_old == b then return end
  6. self.r_old = r
  7. self.g_old = g
  8. self.b_old = b
  9. if r < .5 and b < .5 and g < .5 then
  10. self:SetGradient("VERTICAL",r*.24, g*.24, b*.24, r, g, b)
  11. else
  12. self:SetGradient("VERTICAL",r*.5, g*.5, b*.5, r, g, b)
  13. end
  14. end
  15. -- MAIN STYLE
  16. local style
  17. do
  18. local showmacro = V.showmacro
  19. local hovermacro = V.hovermacro
  20. local select = select
  21. local teh_new_vertex = teh_new_vertex
  22. local getregion = function(self,num)
  23. local x = select(num,self:GetRegions())
  24. return x
  25. end
  26. style = function(self,mode)
  27. local __t = self:GetPushedTexture()
  28. if __t then
  29. if __t.maked ~= true then
  30. __t:SetTexture(M.media.blank)
  31. __t:SetVertexColor(1,1,1,.2)
  32. __t.SetTexture = M.null
  33. __t.maked = true
  34. end
  35. end
  36. local Border = getregion(self,14)
  37. if Border then
  38. if Border.maked ~= true then
  39. Border:SetTexture(nil)
  40. Border:Hide()
  41. Border.Show = M.null
  42. Border.maked = true
  43. end
  44. end
  45. if self.setd then return end -- END
  46. local name = self:GetName()
  47. self:SetNormalTexture(nil)
  48. self.SetSetNormalTexture = M.null
  49. local Flash = _G[name.."Flash"]
  50. Flash:SetTexture(nil)
  51. Flash.SetTexture = M.null
  52. local __t = self:GetCheckedTexture()
  53. __t:SetTexture(M.media.blank)
  54. __t:SetVertexColor(1,1,1,.2)
  55. __t.SetTexture = M.null
  56. local __t = self:GetHighlightTexture()
  57. __t:SetTexture(M.media.blank)
  58. __t:SetVertexColor(1,1,1,.2)
  59. __t.SetTexture = M.null
  60. local __t = getregion(self,3)
  61. __t:Hide()
  62. __t.Show = M.null
  63. local __t = getregion(self,4)
  64. __t:Hide()
  65. __t.Show = M.null
  66. local f
  67. if name:match("MultiCast") then
  68. f = true
  69. local icon = getregion(self,1)
  70. icon:SetGradient("VERTICAL",.5,.5,.5,1,1,1)
  71. icon.SetVertexColor = teh_new_vertex
  72. end
  73. local HotKey = _G[name.."HotKey"]
  74. HotKey:ClearAllPoints()
  75. HotKey:SetPoint("TOPRIGHT", 1, -1)
  76. HotKey:SetFont(M["media"].font, 13, "OUTLINE")
  77. HotKey:SetShadowOffset(1, -1)
  78. self.setd = true
  79. if f then return end
  80. local Icon = _G[name.."Icon"]
  81. local Count = _G[name.."Count"]
  82. local Btname = _G[name.."Name"]
  83. if not mode then
  84. if self.flyR then
  85. Icon:SetTexCoord(5/32,1-5/32,3/32,1-3/32)
  86. else
  87. Icon:SetTexCoord(3/32,1-3/32,5/32,1-5/32)
  88. end
  89. end
  90. Icon:SetPoint("TOPLEFT", self)
  91. Icon:SetPoint("BOTTOMRIGHT", self)
  92. Icon:SetGradient("VERTICAL",.5,.5,.5,1,1,1)
  93. if not mode then
  94. Icon.SetVertexColor = teh_new_vertex
  95. end
  96. if V.shownames ~= true then
  97. HotKey:Hide()
  98. elseif V.hovernames == true then
  99. HotKey:SetDrawLayer("HIGHLIGHT")
  100. end
  101. HotKey.ClearAllPoints = M.null
  102. HotKey.SetPoint = M.null
  103. if HotKey:GetText() then
  104. HotKey:SetFormattedText("|cffFFFFFF%s",HotKey:GetText())
  105. end
  106. if Btname then
  107. Btname:ClearAllPoints()
  108. Btname:SetPoint("LEFT",.5,-1)
  109. Btname:SetPoint("RIGHT",-.5,-1)
  110. Btname:SetJustifyH("CENTER")
  111. if showmacro ~= true then
  112. Btname:SetText("")
  113. Btname:Hide()
  114. Btname.Show = M.null
  115. elseif hovermacro == true then
  116. Btname:SetDrawLayer("HIGHLIGHT")
  117. end
  118. end
  119. Count:ClearAllPoints()
  120. Count:SetPoint("BOTTOMRIGHT", 1, 1)
  121. Count:SetShadowOffset(1, -1)
  122. Count:SetFont(M["media"].font, 13, "OUTLINE")
  123. end
  124. end
  125. --PET BAR
  126. local StylePet
  127. do
  128. local teh_new_vertex = teh_new_vertex
  129. local function stylesmallbutton(name)
  130. local button = _G[name]
  131. if button.setd then return end
  132. local Flash = _G[name.."Flash"]
  133. Flash:SetTexture(nil)
  134. Flash.SetTexture = M.null
  135. button:SetNormalTexture(nil)
  136. button.SetNormalTexture = M.null
  137. local hilight = button:GetHighlightTexture()
  138. hilight:SetTexture(M.media.blank)
  139. hilight:SetVertexColor(1,1,1,.2)
  140. hilight.SetTexture = M.null
  141. local pushed = button:GetPushedTexture()
  142. pushed:SetTexture(M.media.blank)
  143. pushed:SetVertexColor(0,0,0,.4)
  144. pushed.SetTexture = M.null
  145. local check = button:GetCheckedTexture()
  146. check:SetTexture(M.media.blank)
  147. check:SetVertexColor(1,1,1,.2)
  148. check.SetTexture = M.null
  149. button:SetWidth(28)
  150. button:SetHeight(32)
  151. local icon = _G[name.."Icon"]
  152. icon:SetTexCoord(5/32,1-5/32,3/32,1-3/32)
  153. icon:ClearAllPoints()
  154. icon:SetGradient("VERTICAL",.5,.5,.5,1,1,1)
  155. icon:SetAllPoints()
  156. icon.SetVertexColor = teh_new_vertex
  157. button.setd = true
  158. local autocast = _G[name.."AutoCastable"]
  159. autocast:Hide()
  160. autocast.Show = M.null
  161. end
  162. local NUM_PET_ACTION_SLOTS = NUM_PET_ACTION_SLOTS
  163. StylePet = function()
  164. for i=1, NUM_PET_ACTION_SLOTS do
  165. stylesmallbutton("PetActionButton"..i)
  166. end
  167. end
  168. end
  169. -- COOLDOWN POINTS
  170. do
  171. local tostring = tostring
  172. local ipairs = ipairs
  173. local buttonNames = {
  174. "ActionButton",
  175. "MultiBarBottomLeftButton",
  176. "MultiBarBottomRightButton",
  177. "MultiBarLeftButton",
  178. "MultiBarRightButton",
  179. "ShapeshiftButton",
  180. "PetActionButton"}
  181. for _, name in ipairs( buttonNames ) do
  182. for index = 1, 12 do
  183. local buttonName = name .. tostring(index)
  184. local button = _G[buttonName]
  185. local cooldown = _G[buttonName .. "Cooldown"]
  186. if ( button == nil or cooldown == nil ) then
  187. break
  188. end
  189. cooldown:ClearAllPoints()
  190. cooldown:SetPoint("TOPLEFT", button)
  191. cooldown:SetPoint("BOTTOMRIGHT", button)
  192. end
  193. end
  194. end
  195. -- FLYOUT
  196. local styleflyout
  197. do
  198. local SpellFlyout = SpellFlyout
  199. local buttons = 0
  200. local function SetupFlyoutButton()
  201. for i=1, buttons do
  202. local p = _G["SpellFlyoutButton"..i]
  203. if p then style(p,true) end
  204. end
  205. end
  206. SpellFlyout:HookScript("OnShow", SetupFlyoutButton)
  207. local function FlyoutButtonPos(self, buttons, direction)
  208. for i=1, buttons do
  209. local parent = SpellFlyout:GetParent()
  210. if not _G["SpellFlyoutButton"..i] then return end
  211. if InCombatLockdown() then return end
  212. local x = _G["SpellFlyoutButton"..i]
  213. if direction == "LEFT" then
  214. if i == 1 then
  215. x:ClearAllPoints()
  216. x:SetPoint("RIGHT", parent, "LEFT", -6, 0)
  217. else
  218. x:ClearAllPoints()
  219. x:SetPoint("RIGHT", _G["SpellFlyoutButton"..i-1], "LEFT", -6, 0)
  220. end
  221. x:SetSize(28,32)
  222. _G["SpellFlyoutButton"..i.."Icon"]:SetTexCoord(5/32,1-5/32,3/32,1-3/32)
  223. else
  224. if i == 1 then
  225. x:ClearAllPoints()
  226. x:SetPoint("BOTTOM", parent, "TOP", 0, 6)
  227. else
  228. x:ClearAllPoints()
  229. x:SetPoint("BOTTOM", _G["SpellFlyoutButton"..i-1], "TOP", 0, 6)
  230. end
  231. x:SetSize(32,28)
  232. _G["SpellFlyoutButton"..i.."Icon"]:SetTexCoord(3/32,1-3/32,5/32,1-5/32)
  233. end
  234. end
  235. end
  236. local GetFlyoutID = GetFlyoutID
  237. local SetClampedTextureRotation = SetClampedTextureRotation
  238. local GetMouseFocus = GetMouseFocus
  239. M.addenter(function()
  240. SpellFlyoutHorizontalBackground:Hide()
  241. SpellFlyoutVerticalBackground:Hide()
  242. SpellFlyoutBackgroundEnd:Hide()
  243. SpellFlyoutHorizontalBackground.Show = M.null
  244. SpellFlyoutVerticalBackground.Show = M.null
  245. SpellFlyoutBackgroundEnd.Show = M.null
  246. end)
  247. styleflyout = function(self)
  248. for i=1, GetNumFlyouts() do
  249. local x = GetFlyoutID(i)
  250. local _, _, numSlots, isKnown = GetFlyoutInfo(x)
  251. if isKnown then
  252. buttons = numSlots
  253. break
  254. end
  255. end
  256. local arrowDistance
  257. if ((SpellFlyout and SpellFlyout:IsShown() and SpellFlyout:GetParent() == self) or GetMouseFocus() == self) then
  258. arrowDistance = 5
  259. else
  260. arrowDistance = 2
  261. end
  262. if (self.flyR) then
  263. self.FlyoutArrow:ClearAllPoints()
  264. self.FlyoutArrow:SetPoint("LEFT", self, "LEFT", -arrowDistance, 0)
  265. SetClampedTextureRotation(self.FlyoutArrow, 270)
  266. FlyoutButtonPos(self,buttons,"LEFT")
  267. elseif (self.flyT) then
  268. self.FlyoutArrow:ClearAllPoints()
  269. self.FlyoutArrow:SetPoint("TOP", self, "TOP", 0, arrowDistance)
  270. SetClampedTextureRotation(self.FlyoutArrow, 0)
  271. FlyoutButtonPos(self,buttons,"UP")
  272. elseif not self:GetParent():GetParent() == "SpellBookSpellIconsFrame" then
  273. FlyoutButtonPos(self,buttons,"UP")
  274. end
  275. end
  276. end
  277. -- PETBAR UPDATE
  278. local PetBarUpdate
  279. do
  280. local NUM_PET_ACTION_SLOTS = NUM_PET_ACTION_SLOTS
  281. local IsPetAttackAction = IsPetAttackAction
  282. local PetActionButton_StopFlash = PetActionButton_StopFlash
  283. local PetActionButton_StartFlash = PetActionButton_StartFlash
  284. local AutoCastShine_AutoCastStart = AutoCastShine_AutoCastStart
  285. local GetPetActionSlotUsable = GetPetActionSlotUsable
  286. local SetDesaturation = SetDesaturation
  287. local GetPetActionInfo = GetPetActionInfo
  288. local PetHasActionBar = PetHasActionBar
  289. PetBarUpdate = function()
  290. local petActionButton
  291. local petActionIcon
  292. local petAutoCastableTexture
  293. local petAutoCastShine
  294. for i=1, NUM_PET_ACTION_SLOTS do
  295. local buttonName = "PetActionButton" .. i
  296. local petActionButton = _G[buttonName]
  297. local petActionIcon = _G[buttonName.."Icon"]
  298. local petAutoCastShine = _G[buttonName.."Shine"]
  299. local name, subtext, texture, isToken, isActive, autoCastAllowed, autoCastEnabled = GetPetActionInfo(i)
  300. if not isToken then
  301. petActionIcon:SetTexture(texture)
  302. petActionButton.tooltipName = name
  303. else
  304. petActionIcon:SetTexture(_G[texture])
  305. petActionButton.tooltipName = _G[name]
  306. end
  307. petAutoCastShine:SetScale(1.2)
  308. petActionButton.isToken = isToken
  309. petActionButton.tooltipSubtext = subtext
  310. if isActive and name ~= "PET_ACTION_FOLLOW" then
  311. petActionButton:SetChecked(1)
  312. if IsPetAttackAction(i) then
  313. PetActionButton_StartFlash(petActionButton)
  314. end
  315. else
  316. petActionButton:SetChecked(0)
  317. if IsPetAttackAction(i) then
  318. PetActionButton_StopFlash(petActionButton)
  319. end
  320. end
  321. if autoCastEnabled then
  322. AutoCastShine_AutoCastStart(petAutoCastShine)
  323. else
  324. AutoCastShine_AutoCastStop(petAutoCastShine)
  325. end
  326. if texture then
  327. if GetPetActionSlotUsable(i) then
  328. SetDesaturation(petActionIcon, nil)
  329. else
  330. SetDesaturation(petActionIcon, 1)
  331. end
  332. petActionIcon:Show()
  333. else
  334. petActionIcon:Hide()
  335. end
  336. if not PetHasActionBar() and texture and name ~= "PET_ACTION_FOLLOW" then
  337. PetActionButton_StopFlash(petActionButton)
  338. SetDesaturation(petActionIcon, 1)
  339. petActionButton:SetChecked(0)
  340. end
  341. end
  342. end
  343. end
  344. -- INIT PET STYLE AND UPDATE
  345. do
  346. local bar = CreateFrame("Frame", "DerpyPetBar", UIParent, "SecureHandlerStateTemplate")
  347. bar:ClearAllPoints()
  348. bar:SetAllPoints(DerpyMainMenuBar)
  349. bar:RegisterEvent("PLAYER_LOGIN")
  350. bar:RegisterEvent("PLAYER_CONTROL_LOST")
  351. bar:RegisterEvent("PLAYER_CONTROL_GAINED")
  352. bar:RegisterEvent("PLAYER_ENTERING_WORLD")
  353. bar:RegisterEvent("PLAYER_FARSIGHT_FOCUS_CHANGED")
  354. bar:RegisterEvent("PET_BAR_UPDATE")
  355. bar:RegisterEvent("PET_BAR_UPDATE_USABLE")
  356. bar:RegisterEvent("PET_BAR_UPDATE_COOLDOWN")
  357. bar:RegisterEvent("PET_BAR_HIDE")
  358. bar:RegisterEvent("UNIT_PET")
  359. bar:RegisterEvent("UNIT_FLAGS")
  360. bar:RegisterEvent("UNIT_AURA")
  361. local PetBarUpdate = PetBarUpdate
  362. local PetActionBar_UpdateCooldowns = PetActionBar_UpdateCooldowns
  363. local StylePet = StylePet
  364. bar:SetScript("OnEvent", function(self, event, arg1)
  365. if event == "PET_BAR_UPDATE" or
  366. (event == "UNIT_PET" and arg1 == "player") or
  367. event == "PLAYER_CONTROL_LOST" or
  368. event == "PLAYER_CONTROL_GAINED" or
  369. event == "PLAYER_FARSIGHT_FOCUS_CHANGED" or
  370. event == "UNIT_FLAGS" or
  371. (arg1 == "pet" and event == "UNIT_AURA")
  372. then
  373. PetBarUpdate()
  374. elseif event == "PET_BAR_UPDATE_COOLDOWN" then
  375. PetActionBar_UpdateCooldowns()
  376. elseif event == "PLAYER_LOGIN" then
  377. PetActionBarFrame.showgrid = 1
  378. for i = 1, 10 do
  379. local button = _G["PetActionButton"..i]
  380. button:ClearAllPoints()
  381. button:SetParent(self)
  382. button:SetSize(28,32)
  383. if i ~= 1 then
  384. button:SetPoint("TOP", _G["PetActionButton"..(i - 1)], "BOTTOM", 0, -6)
  385. end
  386. button:Show()
  387. local bg = M.frame(button,0,"MEDIUM")
  388. bg:SetPoint("TOPLEFT",-4,4)
  389. bg:SetPoint("BOTTOMRIGHT",4,-4)
  390. self:SetAttribute("addchild", button)
  391. end
  392. RegisterStateDriver(self, "visibility", "[pet,novehicleui,nobonusbar:5] show; hide")
  393. PetActionButton_OnDragStart = M.null
  394. self:UnregisterEvent("PLAYER_LOGIN")
  395. else
  396. StylePet()
  397. end
  398. end)
  399. end
  400. -- SECURE HOOKS
  401. hooksecurefunc("ActionButton_Update",style)
  402. hooksecurefunc("ActionButton_UpdateFlyout",styleflyout)
  403. -- HIDE AND UNREGISTER SOME STUFF
  404. do
  405. MainMenuBar:SetScale(0.00001)
  406. MainMenuBar:SetAlpha(0)
  407. MainMenuBar:EnableMouse(false)
  408. VehicleMenuBar:SetScale(0.00001)
  409. VehicleMenuBar:SetAlpha(0)
  410. VehicleMenuBar:EnableMouse(false)
  411. PetActionBarFrame:EnableMouse(false)
  412. ShapeshiftBarFrame:EnableMouse(false)
  413. local elements = {
  414. MainMenuBar, MainMenuBarArtFrame, BonusActionBarFrame, VehicleMenuBar, PossessBarFrame,
  415. PetActionBarFrame, ShapeshiftBarFrame, ShapeshiftBarLeft, ShapeshiftBarMiddle, ShapeshiftBarRight,
  416. }
  417. for _, element in pairs(elements) do
  418. if element:GetObjectType() == "Frame" then
  419. element:UnregisterAllEvents()
  420. end
  421. element:Hide()
  422. element:SetAlpha(0)
  423. end
  424. local uiManagedFrames = {
  425. "MultiBarLeft",
  426. "MultiBarRight",
  427. "MultiBarBottomLeft",
  428. "MultiBarBottomRight",
  429. "ShapeshiftBarFrame",
  430. "PossessBarFrame",
  431. "PETACTIONBAR_YPOS",
  432. "MultiCastActionBarFrame",
  433. "MULTICASTACTIONBAR_YPOS",
  434. "ChatFrame1",
  435. "ChatFrame2",
  436. }
  437. for _, frame in pairs(uiManagedFrames) do
  438. UIPARENT_MANAGED_FRAME_POSITIONS[frame] = nil
  439. end
  440. local have = {
  441. "MultiBarBottomLeft",
  442. "MultiBarLeft",
  443. "MultiBarRight",
  444. "MultiBarBottomRight",}
  445. for i=1, #have do
  446. _G[have[i]].Hide = M.null
  447. _G[have[i]]:Show()
  448. end
  449. end