Advertisement
Guest User

Actionbars.lua

a guest
Apr 25th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.40 KB | None | 0 0
  1. local Addon = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
  2. local Module = Addon:NewModule("Actionbars")
  3.  
  4. local L = setmetatable({}, { __index = function(t,k)
  5. local v = tostring(k)
  6. rawset(t, k, v)
  7. return v
  8. end })
  9.  
  10. local db
  11. local defaults = {
  12. profile = {
  13. enable = true,
  14. showHotKeys = false, -- Set the Alpha
  15. showMacronames = false, -- Set the Alpha
  16. auraborder = false,
  17.  
  18. -- Button Colors
  19. color = {
  20. enable = true,
  21. OutOfRange = { r = 0.9, g = 0, b = 0 },
  22. OutOfMana = { r = 0, g = 0, b = 0.9 },
  23. NotUsable = { r = 0.3, g = 0.3, b = 0.3 },
  24. },
  25. }
  26. }
  27.  
  28. function Module:OnInitialize()
  29. self.db = Addon.db:RegisterNamespace("Actionbars", defaults)
  30. db = self.db.profile
  31.  
  32. self:SetEnabledState(Addon:GetModuleEnabled("Actionbars"))
  33. local _, class = UnitClass("player")
  34. classColor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  35. end
  36.  
  37. function Module:OnEnable()
  38.  
  39. db = self.db.profile
  40.  
  41. if InCombatLockdown() then
  42. return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
  43. end
  44. self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  45.  
  46. if self.SetupHooks then
  47. self:SetupHooks()
  48. end
  49.  
  50. if enabled or not db.enable then return end
  51. enabled = true -- since most of this stuff is non-undoable (eg. hooksecurefunc)
  52.  
  53. local hotkeyAlpha = db.showHotKeys and 1 or 0
  54. for i = 1, 12 do
  55. _G["ActionButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- main bar
  56. _G["MultiBarBottomRightButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- bottom right bar
  57. _G["MultiBarBottomLeftButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- bottom left bar
  58. _G["MultiBarRightButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- right bar
  59. _G["MultiBarLeftButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- left bar
  60. end
  61.  
  62. local macroAlpha = db.showMacronames and 1 or 0
  63. for i = 1, 12 do
  64. _G["ActionButton"..i.."Name"]:SetAlpha(macroAlpha) -- main bar
  65. _G["MultiBarBottomRightButton"..i.."Name"]:SetAlpha(macroAlpha) -- bottom right bar
  66. _G["MultiBarBottomLeftButton"..i.."Name"]:SetAlpha(macroAlpha) -- bottom left bar
  67. _G["MultiBarRightButton"..i.."Name"]:SetAlpha(macroAlpha) -- right bar
  68. _G["MultiBarLeftButton"..i.."Name"]:SetAlpha(macroAlpha) -- left bar
  69. end
  70. end
  71.  
  72. function Module:SetupHooks()
  73. -- BetterBlizzardButtonBorder v1.1.1
  74. -- By Aprikot - http://aprikot.wowinterface.com
  75. -- Based upon functions within nMainbar by Neal, and thek: Buttonskin by thek
  76.  
  77. local function AddRegionKeys(self)
  78. local name = self:GetName()
  79. self.__name = _G[name.."Name"]
  80. self.__count = _G[name.."Count"]
  81. self.__hotkey = _G[name.."HotKey"]
  82. self.__border = _G[name.."Border"]
  83. self.__flash = _G[name.."Flash"]
  84. self.__normalTexture = _G[name.."NormalTexture"]
  85. self.__normalTexture2 = _G[name.."NormalTexture2"]
  86. self.__pushedTexture = self:GetPushedTexture()
  87. self.__highlightTexture = self:GetHighlightTexture()
  88. self.__checkedTexture = self:GetCheckedTexture()
  89. return name
  90. end
  91.  
  92. local function ColorButton(texture)
  93. if Addon.db.profile.media.classcolor then
  94. texture:SetVertexColor(classColor.r * 1.2, classColor.g * 1.2, classColor.b * 1.2)
  95. else
  96. local color = db.color
  97. texture:SetVertexColor(color.r, color.g, color.b)
  98. end
  99. end
  100.  
  101. local extraActionButtons = setmetatable({}, { __index = function(t, self)
  102. local name = AddRegionKeys(self)
  103. local v = not not strmatch(name, "ExtraActionButton")
  104. t[f] = v
  105. return v
  106. end })
  107.  
  108. hooksecurefunc("ActionButton_Update", function(self)
  109. if extraActionButtons[self] then return end
  110.  
  111. self:SetNormalTexture("Interface\\BUTTONS\\UI-Quickslot2")
  112.  
  113. local icon = self.icon
  114. icon:SetTexCoord(.05, .95, .05, .95)
  115. icon:ClearAllPoints()
  116. icon:SetPoint("TOPLEFT")
  117. icon:SetPoint("BOTTOMRIGHT")
  118.  
  119. local normalTexture = self.__normalTexture
  120. normalTexture:ClearAllPoints()
  121. normalTexture:SetPoint("TOPLEFT", -14, 14)
  122. normalTexture:SetPoint("BOTTOMRIGHT", 14, -14)
  123. ColorButton(normalTexture)
  124. end)
  125.  
  126. hooksecurefunc("ActionButton_UpdateUsable", function(self)
  127. if extraActionButtons[self] then return end
  128. ColorButton(self.__normalTexture)
  129. end)
  130.  
  131. hooksecurefunc("ActionButton_ShowGrid", function(self)
  132. if extraActionButtons[self] then return end
  133. ColorButton(self.__normalTexture)
  134. end)
  135.  
  136. local petButtons = { "PetActionButton", "PossessButton", "ShapeshiftButton" }
  137. hooksecurefunc("PetActionBar_Update", function()
  138. for i = 1, #petButtons do
  139. for j = 1, 12 do
  140. local button = _G[petButtons[i]..j]
  141. button:SetNormalTexture("Interface\\BUTTONS\\UI-Quickslot2")
  142.  
  143. AddRegionKeys(button)
  144.  
  145. local icon = button.icon
  146. icon:SetTexCoord(.05, .95, .05, .95)
  147. icon:ClearAllPoints()
  148. icon:SetPoint("TOPLEFT", -1, 1)
  149. icon:SetPoint("BOTTOMRIGHT", 1, -1)
  150.  
  151. local normalTexture = button.__normalTexture2 or button.__normalTexture
  152. normalTexture:ClearAllPoints()
  153. normalTexture:SetPoint("TOPLEFT", -15, 15)
  154. normalTexture:SetPoint("BOTTOMRIGHT",15, -15)
  155.  
  156. ColorButton(normalTexture)
  157. end
  158. end
  159. end)
  160.  
  161. hooksecurefunc("AuraButton_Update", function(buttonName, index, filter)
  162. if not db.auraborder then return end
  163.  
  164. local buffName = buttonName..index
  165. local self = _G[buffName]
  166. if not self.__border then AddRegionKeys(self) end
  167.  
  168. local icon = self.icon
  169. if icon then
  170. icon:SetTexCoord(.07, .93, .07, .93)
  171. end
  172.  
  173. local border = self.__border
  174. if not border then
  175. border = self:CreateTexture("$parentOverlay", "ARTWORK")
  176. self.__border = border
  177. end
  178. border:SetTexture("Interface\\BUTTONS\\UI-Quickslot2")
  179. border:ClearAllPoints()
  180. border:SetPoint("TOPLEFT", bu, -12, 12)
  181. border:SetPoint("BOTTOMRIGHT", bu, 12, -12)
  182. border:SetTexCoord(0, 1, 0, 1)
  183. ColorButton(border)
  184. end)
  185.  
  186. ---------------------------------------------------------------------
  187.  
  188. local rangeAddons = {
  189. "GreenRange",
  190. "RangeColors",
  191. "RedRange",
  192. "tullaRange",
  193. }
  194. for i = 1, #rangeAddons do
  195. local _, _, _, enabled = GetAddOnInfo(rangeAddons[i])
  196. if enabled then
  197. rangeAddons = nil
  198. break
  199. end
  200. end
  201.  
  202. if rangeAddons then
  203. hooksecurefunc("ActionButton_UpdateUsable", function(self)
  204. local isUsable, notEnoughMana = IsUsableAction(self.action)
  205. if isUsable then
  206. self.icon:SetVertexColor(1, 1, 1)
  207. elseif notEnoughMana then
  208. local color = db.color.OutOfMana
  209. self.icon:SetVertexColor(color.r, color.g, color.b)
  210. else
  211. local color = db.color.NotUsable
  212. self.icon:SetVertexColor(color.r, color.g, color.b)
  213. end
  214. end)
  215.  
  216. hooksecurefunc("ActionButton_OnUpdate", function(self, elapsed)
  217. local rangeTimer = self.rangeTimer2 or 0
  218. rangeTimer = rangeTimer - elapsed
  219. if rangeTimer <= 0 then
  220. if IsActionInRange(self.action) == 0 then
  221. local color = db.color.OutOfRange
  222. self.icon:SetVertexColor(color.r, color.g, color.b)
  223. end
  224. rangeTimer = TOOLTIP_UPDATE_TIME
  225. end
  226. self.rangeTimer2 = rangeTimer
  227. end)
  228. end
  229.  
  230. self.SetupHooks = nil
  231. end
  232.  
  233. -- Leave this out if the module doesn't have any settings:
  234. function Module:Refresh()
  235. db = self.db.profile -- update the upvalue
  236.  
  237. -- change stuff here
  238. end
  239.  
  240. -- Leave this out if the module doesn't have any options:
  241. local options
  242. function Module:GetOptions()
  243. options = options or {
  244. type = "group",
  245. name = L["Actionbars"],
  246. desc = L["Actionbar Button Modifications."],
  247. childGroups = "tree",
  248. get = function(info) return db[ info[#info] ] end,
  249. set = function(info, value) db[ info[#info] ] = value; end,
  250. args = {
  251. ---------------------------
  252. --Option Type Seperators
  253. sep1 = {
  254. type = "description",
  255. order = 2,
  256. name = " ",
  257. },
  258. sep2 = {
  259. type = "description",
  260. order = 3,
  261. name = " ",
  262. },
  263. sep3 = {
  264. type = "description",
  265. order = 4,
  266. name = " ",
  267. },
  268. sep4 = {
  269. type = "description",
  270. order = 5,
  271. name = " ",
  272. },
  273. ---------------------------
  274. reloadUI = {
  275. type = "execute",
  276. name = "Reload UI",
  277. desc = " ",
  278. order = 0,
  279. func = function()
  280. ReloadUI()
  281. end,
  282. },
  283. Text = {
  284. type = "description",
  285. order = 0,
  286. name = "When changes are made a reload of the UI is needed.",
  287. width = "full",
  288. },
  289. Text1 = {
  290. type = "description",
  291. order = 1,
  292. name = " ",
  293. width = "full",
  294. },
  295. enable = {
  296. type = "toggle",
  297. order = 1,
  298. name = L["Enable"],
  299. desc = L["Enables Actionbar Button Module"],
  300. width = "full",
  301. },
  302. auraborder = {
  303. type = "toggle",
  304. order = 2,
  305. name = L["Aura Border"],
  306. desc = L["Make & Color Aura Borders."],
  307. disabled = function() return not db.enable end,
  308. },
  309. showHotKeys = {
  310. type = "toggle",
  311. order = 2,
  312. name = L["Show Hot Keys"],
  313. desc = L["If Checked Hot Keys will Show."],
  314. disabled = function() return not db.enable end,
  315. },
  316. showMacronames = {
  317. type = "toggle",
  318. order = 2,
  319. name = L["Show Macro Names"],
  320. desc = L["If Checked Macros Will Show."],
  321. disabled = function() return not db.enable end,
  322. },
  323. color = {
  324. type = "group",
  325. order = 6,
  326. name = L["Actionbar Button Color"],
  327. desc = L["Enables Actionbar Button Color Modifications."],
  328. guiInline = true,
  329. get = function(info) return db.color[ info[#info] ] end,
  330. set = function(info, value) db.color[ info[#info] ] = value; end,
  331. args = {
  332. ---------------------------
  333. --Option Type Seperators
  334. sep1 = {
  335. type = "description",
  336. order = 2,
  337. name = " ",
  338. },
  339. sep2 = {
  340. type = "description",
  341. order = 3,
  342. name = " ",
  343. },
  344. sep3 = {
  345. type = "description",
  346. order = 4,
  347. name = " ",
  348. },
  349. sep4 = {
  350. type = "description",
  351. order = 5,
  352. name = " ",
  353. },
  354. ---------------------------
  355. enable = {
  356. type = "toggle",
  357. order = 1,
  358. name = L["Enable"],
  359. desc = L["Enables Coloring"],
  360. width = "full",
  361. },
  362. OutOfRange = {
  363. type = "color",
  364. order = 4,
  365. name = L["Out of Range"],
  366. desc = L["Picks the Out of Range Button Fade Color."],
  367. disabled = function() return not db.enable or not db.color.enable end,
  368. get = function(info)
  369. local rc = db.color[ info[#info] ]
  370. return rc.r, rc.g, rc.b
  371. end,
  372. set = function(info, r, g, b)
  373. db.color[ info[#info] ] = {}
  374. local rc = db.color[ info[#info] ]
  375. rc.r, rc.g, rc.b = r, g, b
  376. end,
  377. },
  378. OutOfMana = {
  379. type = "color",
  380. order = 4,
  381. name = L["Out of Mana"],
  382. desc = L["Picks the Out of Mana Button Fade Color."],
  383. disabled = function() return not db.enable or not db.color.enable end,
  384. get = function(info)
  385. local mc = db.color[ info[#info] ]
  386. return mc.r, mc.g, mc.b
  387. end,
  388. set = function(info, r, g, b)
  389. db.color[ info[#info] ] = {}
  390. local mc = db.color[ info[#info] ]
  391. mc.r, mc.g, mc.b = r, g, b
  392. end,
  393. },
  394. NotUsable = {
  395. type = "color",
  396. order = 4,
  397. name = L["Not Usable"],
  398. desc = L["Picks the Not Usable Button Fade Color."],
  399. disabled = function() return not db.enable or not db.color.enable end,
  400. get = function(info)
  401. local nu = db.color[ info[#info] ]
  402. return nu.r, nu.g, nu.b
  403. end,
  404. set = function(info, r, g, b)
  405. db.color[ info[#info] ] = {}
  406. local nu = db.color[ info[#info] ]
  407. nu.r, nu.g, nu.b = r, g, b
  408. end,
  409. },
  410. },
  411. },
  412. },
  413. }
  414. return options
  415. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement