Advertisement
Guest User

Actionbars.lua

a guest
Apr 27th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.56 KB | None | 0 0
  1. local MODULE_NAME = "Actionbar"
  2. local ADDON_NAME = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
  3. local MODULE = ADDON_NAME:NewModule(MODULE_NAME, "AceEvent-3.0")
  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. ------------------------------------------------------------------------
  11. -- Module Database
  12. ------------------------------------------------------------------------
  13.  
  14. local db
  15. local defaults = {
  16. profile = {
  17. enable = true,
  18. showHotKeys = false, -- Set the Alpha
  19. showMacronames = false, -- Set the Alpha
  20. auraborder = true,
  21. color = {
  22. enable = true,
  23. OutOfRange = { r = 0.9, g = 0, b = 0 },
  24. OutOfMana = { r = 0, g = 0, b = 0.9 },
  25. NotUsable = { r = 0.3, g = 0.3, b = 0.3 },
  26. },
  27. }
  28. }
  29.  
  30. ------------------------------------------------------------------------
  31. -- Module Functions
  32. ------------------------------------------------------------------------
  33.  
  34. local classColor
  35.  
  36. function MODULE:OnInitialize()
  37. self.db = ADDON_NAME.db:RegisterNamespace(MODULE_NAME, defaults)
  38. db = self.db.profile
  39.  
  40. local _, class = UnitClass("player")
  41. classColor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
  42.  
  43. self:SetEnabledState(ADDON_NAME:GetModuleEnabled(MODULE_NAME))
  44. end
  45.  
  46. function MODULE:OnEnable()
  47. if InCombatLockdown() then
  48. return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
  49. end
  50. self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  51.  
  52. if self.SetupHooks then
  53. self:SetupHooks()
  54. end
  55.  
  56. self:Refresh()
  57. end
  58.  
  59. function MODULE:Refresh()
  60.  
  61. local hotkeyAlpha = db.showHotKeys and 1 or 0
  62. for i = 1, 12 do
  63. _G["ActionButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- main bar
  64. _G["MultiBarBottomRightButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- bottom right bar
  65. _G["MultiBarBottomLeftButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- bottom left bar
  66. _G["MultiBarRightButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- right bar
  67. _G["MultiBarLeftButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- left bar
  68. end
  69.  
  70. local macroAlpha = db.showMacronames and 1 or 0
  71. for i = 1, 12 do
  72. _G["ActionButton"..i.."Name"]:SetAlpha(macroAlpha) -- main bar
  73. _G["MultiBarBottomRightButton"..i.."Name"]:SetAlpha(macroAlpha) -- bottom right bar
  74. _G["MultiBarBottomLeftButton"..i.."Name"]:SetAlpha(macroAlpha) -- bottom left bar
  75. _G["MultiBarRightButton"..i.."Name"]:SetAlpha(macroAlpha) -- right bar
  76. _G["MultiBarLeftButton"..i.."Name"]:SetAlpha(macroAlpha) -- left bar
  77. end
  78. end
  79.  
  80. function MODULE:SetupHooks()
  81. local function AddRegionKeys(self)
  82. local name = self:GetName()
  83. self.__name = _G[name.."Name"]
  84. self.__count = _G[name.."Count"]
  85. self.__hotkey = _G[name.."HotKey"]
  86. self.__border = _G[name.."Border"]
  87. self.__flash = _G[name.."Flash"]
  88. self.__normalTexture = _G[name.."NormalTexture"]
  89. self.__normalTexture2 = _G[name.."NormalTexture2"]
  90. self.__pushedTexture = self:GetPushedTexture()
  91. self.__highlightTexture = self:GetHighlightTexture()
  92. self.__checkedTexture = self:GetCheckedTexture()
  93. return name
  94. end
  95.  
  96. local function ColorButton(texture)
  97. if ADDON_NAME.db.profile.media.classcolor then
  98. texture:SetVertexColor(classColor.r * 1.2, classColor.g * 1.2, classColor.b * 1.2)
  99. else
  100. texture:SetVertexColor(db.color.r, db.color.g, db.color.b)
  101. end
  102. end
  103.  
  104. local function UpdateButton(button, iconOffset, borderOffset)
  105. if not button then return end
  106. iconOffset = iconOffset or 1
  107. borderOffset = borderOffset or 15
  108.  
  109. button:SetNormalTexture("Interface\\BUTTONS\\UI-Quickslot2")
  110.  
  111. local icon = button.icon
  112. icon:ClearAllPoints()
  113. icon:SetPoint("TOPLEFT", -iconOffset, iconOffset)
  114. icon:SetPoint("BOTTOMRIGHT", iconOffset, -iconOffset)
  115. icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
  116.  
  117. local normalTexture = button.__normalTexture2 or button.__normalTexture
  118. normalTexture:ClearAllPoints()
  119. normalTexture:SetPoint("TOPLEFT", -borderOffset, borderOffset)
  120. normalTexture:SetPoint("BOTTOMRIGHT", borderOffset, -borderOffset)
  121.  
  122. ColorButton(normalTexture)
  123. end
  124.  
  125. local extraActionButtons = setmetatable({}, { __index = function(t, self)
  126. local name = AddRegionKeys(self)
  127. local v = not not strmatch(name, "ExtraActionButton")
  128. t[self] = v
  129. return v
  130. end })
  131.  
  132. hooksecurefunc("ActionButton_Update", function(self)
  133. if not extraActionButtons[self] then
  134. UpdateButton(self, 0, 14)
  135. end
  136. end)
  137.  
  138. hooksecurefunc("ActionButton_UpdateUsable", function(self)
  139. if not extraActionButtons[self] then
  140. ColorButton(self.__normalTexture)
  141. end
  142. end)
  143.  
  144. hooksecurefunc("ActionButton_ShowGrid", function(self)
  145. if not extraActionButtons[self] then
  146. ColorButton(self.__normalTexture)
  147. end
  148. end)
  149.  
  150. for i = 1, NUM_PET_ACTION_SLOTS do
  151. AddRegionKeys(_G["PetActionButton"..i])
  152. end
  153. hooksecurefunc("PetActionBar_Update", function()
  154. for i = 1, NUM_PET_ACTION_SLOTS do
  155. UpdateButton(_G["PetActionButton"..i])
  156. end
  157. end)
  158.  
  159. for i = 1, NUM_POSSESS_SLOTS do
  160. AddRegionKeys(_G["PossessButton"..i])
  161. end
  162. hooksecurefunc("PossessBar_UpdateState", function()
  163. for i = 1, NUM_POSSESS_SLOTS do
  164. UpdateButton(_G["PossessButton"..i])
  165. end
  166. end)
  167.  
  168. for i = 1, NUM_STANCE_SLOTS do
  169. AddRegionKeys(_G["StanceButton"..i])
  170. end
  171. hooksecurefunc("StanceBar_UpdateState", function()
  172. for i = 1, NUM_STANCE_SLOTS do
  173. UpdateButton(_G["StanceButton"..i])
  174. end
  175. end)
  176.  
  177. ---------------------------------------------------------------------
  178.  
  179. hooksecurefunc("AuraButton_Update", function(self, index)
  180. if not db.auraborder then return end
  181.  
  182. local buffName = _G[self..index]
  183. local buffIcon = _G[self..index.."Icon"]
  184. local buffBorder = _G[self..index.."Border"]
  185.  
  186. if buffIcon then
  187. buffIcon:SetTexCoord(.07, .93, .07, .93)
  188. end
  189.  
  190. if buffBorder then
  191. buffBorder:SetTexture("Interface\\BUTTONS\\UI-Quickslot2")
  192. buffBorder:ClearAllPoints()
  193. buffBorder:SetPoint("TOPLEFT", buffName, -12, 12)
  194. buffBorder:SetPoint("BOTTOMRIGHT", buffName, 12, -12)
  195. buffBorder:SetTexCoord(0, 1, 0, 1)
  196. ColorButton(buffBorder)
  197. end
  198.  
  199. if buffName and not buffBorder then
  200. nobuffBorder = buffName:CreateTexture("$parentOverlay", "ARTWORK")
  201. nobuffBorder:SetParent(buffName)
  202. nobuffBorder:SetTexture("Interface\\BUTTONS\\UI-Quickslot2")
  203. nobuffBorder:ClearAllPoints()
  204. nobuffBorder:SetPoint("TOPLEFT", buffName, -12, 12)
  205. nobuffBorder:SetPoint("BOTTOMRIGHT", buffName, 12, -12)
  206. ColorButton(nobuffBorder)
  207. end
  208. end)
  209.  
  210. ---------------------------------------------------------------------
  211.  
  212. local rangeAddons = {
  213. "GreenRange",
  214. "RangeColors",
  215. "RedRange",
  216. "tullaRange",
  217. }
  218. for i = 1, #rangeAddons do
  219. local _, _, _, enabled = GetAddOnInfo(rangeAddons[i])
  220. if enabled then
  221. rangeAddons = nil
  222. break
  223. end
  224. end
  225.  
  226. if rangeAddons then
  227. hooksecurefunc("ActionButton_UpdateUsable", function(self)
  228. local isUsable, notEnoughMana = IsUsableAction(self.action)
  229. if isUsable then
  230. self.icon:SetVertexColor(1, 1, 1)
  231. elseif notEnoughMana then
  232. local color = db.color.OutOfMana
  233. self.icon:SetVertexColor(color.r, color.g, color.b)
  234. else
  235. local color = db.color.NotUsable
  236. self.icon:SetVertexColor(color.r, color.g, color.b)
  237. end
  238. end)
  239.  
  240. hooksecurefunc("ActionButton_OnUpdate", function(self, elapsed)
  241. local rangeTimer = self.rangeTimer2 or 0
  242. rangeTimer = rangeTimer - elapsed
  243. if rangeTimer <= 0 then
  244. if IsActionInRange(self.action) == 0 then
  245. local color = db.color.OutOfRange
  246. self.icon:SetVertexColor(color.r, color.g, color.b)
  247. end
  248. rangeTimer = TOOLTIP_UPDATE_TIME
  249. end
  250. self.rangeTimer2 = rangeTimer
  251. end)
  252. end
  253.  
  254. self.SetupHooks = nil
  255. end
  256.  
  257. ------------------------------------------------------------------------
  258. -- Module Options
  259. ------------------------------------------------------------------------
  260.  
  261. local options
  262. function MODULE:GetOptions()
  263.  
  264. if options then
  265. return options
  266. end
  267.  
  268. local function isModuleDisabled()
  269. return not ADDON_NAME:GetModuleEnabled(MODULE_NAME)
  270. end
  271.  
  272. options = {
  273. type = "group",
  274. name = L[MODULE_NAME],
  275. get = function(info) return db[ info[#info] ] end,
  276. set = function(info, value) db[ info[#info] ] = value end,
  277. disabled = isModuleDisabled(),
  278. args = {
  279. reloadUI = {
  280. type = "execute",
  281. name = "Reload UI",
  282. desc = " ",
  283. order = 0,
  284. func = function()
  285. ReloadUI()
  286. end,
  287. },
  288. Text = {
  289. type = "description",
  290. order = 0,
  291. name = "When changes are made a reload of the UI is needed.",
  292. width = "full",
  293. },
  294. Text1 = {
  295. type = "description",
  296. order = 1,
  297. name = " ",
  298. width = "full",
  299. },
  300. enable = {
  301. type = "toggle",
  302. order = 1,
  303. name = L["Enable Actionbar Module"],
  304. width = "full",
  305. disabled = false,
  306. },
  307. Text2 = {
  308. type = "description",
  309. name = " ",
  310. width = "full",
  311. },
  312. auraborder = {
  313. type = "toggle",
  314. name = L["Aura borders"],
  315. desc = L["Show colored borders on action buttons to show when auras are active."],
  316. disabled = function() return isModuleDisabled() or not db.enable end,
  317. },
  318. showHotKeys = {
  319. type = "toggle",
  320. name = L["Show Hot Keys"],
  321. desc = L["Show key bindings on action buttons."],
  322. disabled = function() return isModuleDisabled() or not db.enable end,
  323. },
  324. showMacronames = {
  325. type = "toggle",
  326. name = L["Show Macro Names"],
  327. desc = L["Show macro names on action buttons."],
  328. disabled = function() return isModuleDisabled() or not db.enable end,
  329. },
  330. color = {
  331. type = "group",
  332. order = -1,
  333. name = L["Button Coloring"],
  334. guiInline = true,
  335. get = function(info) return db.color[ info[#info] ] end,
  336. set = function(info, value) db.color[ info[#info] ] = value; end,
  337. args = {
  338. enable = {
  339. order = 1,
  340. type = "toggle",
  341. name = L["Enable"],
  342. desc = L["Enable action button coloring."],
  343. width = "full",
  344. disabled = function() return isModuleDisabled() or not db.enable end,
  345. },
  346. OutOfRange = {
  347. order = 2,
  348. type = "color",
  349. name = L["Out of Range"],
  350. desc = L["Use this color for actions you are too far from the target to use."],
  351. disabled = function() return isModuleDisabled() or not db.enable or not db.color.enable end,
  352. get = function(info)
  353. return db.color.OutOfRange.r, db.color.OutOfRange.g, db.color.OutOfRange.b
  354. end,
  355. set = function(info, r, g, b)
  356. db.color.OutOfRange.r, db.color.OutOfRange.g, db.color.OutOfRange.b = r, g, b
  357. end,
  358. },
  359. OutOfMana = {
  360. order = 3,
  361. type = "color",
  362. name = L["Out of Mana"],
  363. desc = L["Use this color for actions you don't have enough mana to use."],
  364. disabled = function() return isModuleDisabled() or not db.enable or not db.color.enable end,
  365. get = function(info)
  366. return db.color.OutOfMana.r, db.color.OutOfMana.g, db.color.OutOfMana.b
  367. end,
  368. set = function(info, r, g, b)
  369. db.color.OutOfMana.r, db.color.OutOfMana.g, db.color.OutOfMana.b = r, g, b
  370. end,
  371. },
  372. NotUsable = {
  373. order = 4,
  374. type = "color",
  375. name = L["Not Usable"],
  376. desc = L["Use this color for actions you can't use for some other reason."],
  377. disabled = function() return isModuleDisabled() or not db.enable or not db.color.enable end,
  378. get = function(info)
  379. return db.color.NotUsable.r, db.color.NotUsable.g, db.color.NotUsable.b
  380. end,
  381. set = function(info, r, g, b)
  382. db.color.NotUsable.r, db.color.NotUsable.g, db.color.NotUsable.b = r, g, b
  383. end,
  384. }
  385. }
  386. }
  387. }
  388. }
  389. return options
  390. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement