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