Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local MODULE_NAME = "Actionbar"
- local Core = LibStub("AceAddon-3.0"):GetAddon("BasicUI")
- local Actionbar = Core:NewModule(MODULE_NAME)
- local L = Core.L
- local db
- local defaults = {
- profile = {
- enable = true,
- showHotKeys = false, -- Set the Alpha
- showMacronames = false, -- Set the Alpha
- auraborder = false,
- color = {
- enable = true,
- OutOfRange = { r = 0.9, g = 0, b = 0 },
- OutOfMana = { r = 0, g = 0, b = 0.9 },
- NotUsable = { r = 0.3, g = 0.3, b = 0.3 },
- },
- }
- }
- ------------------------------------------------------------------------
- -- Module functions
- ------------------------------------------------------------------------
- local classColor
- function Actionbar:OnInitialize()
- self.db = Core.db:RegisterNamespace(MODULE_NAME, defaults)
- db = self.db.profile
- local _, class = UnitClass("player")
- classColor = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
- self:SetEnabledState(Core:GetModuleEnabled(MODULE_NAME)
- end
- function Actionbar:OnEnable()
- if InCombatLockdown() then
- return self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnEnable")
- end
- self:UnregisterEvent("PLAYER_REGEN_ENABLED")
- if self.SetupHooks then
- self:SetupHooks()
- end
- self:Refresh()
- end
- function Actionbar:Refresh()
- db = self.db.profile
- local hotkeyAlpha = db.showHotKeys and 1 or 0
- for i = 1, 12 do
- _G["ActionButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- main bar
- _G["MultiBarBottomRightButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- bottom right bar
- _G["MultiBarBottomLeftButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- bottom left bar
- _G["MultiBarRightButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- right bar
- _G["MultiBarLeftButton"..i.."HotKey"]:SetAlpha(hotkeyAlpha) -- left bar
- end
- local macroAlpha = db.showMacronames and 1 or 0
- for i = 1, 12 do
- _G["ActionButton"..i.."Name"]:SetAlpha(macroAlpha) -- main bar
- _G["MultiBarBottomRightButton"..i.."Name"]:SetAlpha(macroAlpha) -- bottom right bar
- _G["MultiBarBottomLeftButton"..i.."Name"]:SetAlpha(macroAlpha) -- bottom left bar
- _G["MultiBarRightButton"..i.."Name"]:SetAlpha(macroAlpha) -- right bar
- _G["MultiBarLeftButton"..i.."Name"]:SetAlpha(macroAlpha) -- left bar
- end
- end
- function Module:SetupHooks()
- local function AddRegionKeys(self)
- local name = self:GetName()
- self.__name = _G[name.."Name"]
- self.__count = _G[name.."Count"]
- self.__hotkey = _G[name.."HotKey"]
- self.__border = _G[name.."Border"]
- self.__flash = _G[name.."Flash"]
- self.__normalTexture = _G[name.."NormalTexture"]
- self.__normalTexture2 = _G[name.."NormalTexture2"]
- self.__pushedTexture = self:GetPushedTexture()
- self.__highlightTexture = self:GetHighlightTexture()
- self.__checkedTexture = self:GetCheckedTexture()
- return name
- end
- local function ColorButton(texture)
- if core.db.profile.misc.classcolor then
- texture:SetVertexColor(classColor.r * 1.2, classColor.g * 1.2, classColor.b * 1.2)
- else
- local color = db.color
- texture:SetVertexColor(color.r, color.g, color.b)
- end
- end
- local function UpdateButton(button, iconOffset, borderOffset)
- if not button then return end
- iconOffset = iconOffset or 1
- borderOffset = borderOffset or 15
- button:SetNormalTexture("Interface\\BUTTONS\\UI-Quickslot2")
- local icon = button.icon
- icon:ClearAllPoints()
- icon:SetPoint("TOPLEFT", -iconOffset, iconOffset)
- icon:SetPoint("BOTTOMRIGHT", iconOffset, -iconOffset)
- icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
- local normalTexture = button.__normalTexture2 or button.__normalTexture
- normalTexture:ClearAllPoints()
- normalTexture:SetPoint("TOPLEFT", -borderOffset, borderOffset)
- normalTexture:SetPoint("BOTTOMRIGHT", borderOffset, -borderOffset)
- ColorButton(normalTexture)
- end
- local extraActionButtons = setmetatable({}, { __index = function(t, self)
- local name = AddRegionKeys(self)
- local v = not not strmatch(name, "ExtraActionButton")
- t[f] = v
- return v
- end })
- hooksecurefunc("ActionButton_Update", function(self)
- if not extraActionButtons[self] then
- UpdateButton(self, 0, 14)
- end
- end)
- hooksecurefunc("ActionButton_UpdateUsable", function(self)
- if not extraActionButtons[self] then
- ColorButton(self.__normalTexture)
- end
- end)
- hooksecurefunc("ActionButton_ShowGrid", function(self)
- if not extraActionButtons[self] then
- ColorButton(self.__normalTexture)
- end
- end)
- for i = 1, NUM_PET_ACTION_SLOTS do
- AddRegionKeys(_G["PetActionButton"..i])
- end
- hooksecurefunc("PetActionBar_Update", function()
- for i = 1, NUM_PET_ACTION_SLOTS do
- UpdateButton(_G["PetActionButton"..i])
- end
- end)
- for i = 1, NUM_POSSESS_SLOTS do
- AddRegionKeys(_G["PossessButton"..i])
- end
- hooksecurefunc("PossessBar_UpdateState", function()
- for i = 1, NUM_POSSESS_SLOTS do
- UpdateButton(_G["PossessButton"..i])
- end
- end)
- for i = 1, NUM_STANCE_SLOTS do
- AddRegionKeys(_G["StanceButton"..i])
- end
- hooksecurefunc("StanceBar_UpdateState", function()
- for i = 1, NUM_STANCE_SLOTS do
- UpdateButton(_G["StanceButton"..i])
- end
- end)
- ---------------------------------------------------------------------
- hooksecurefunc("AuraButton_Update", function(buttonName, index, filter)
- if not db.auraborder then return end
- local buffName = buttonName..index
- local self = _G[buffName]
- if not self.__border then AddRegionKeys(self) end
- local icon = self.icon
- if icon then
- icon:SetTexCoord(.07, .93, .07, .93)
- end
- local border = self.__border
- if not border then
- border = self:CreateTexture("$parentOverlay", "ARTWORK")
- self.__border = border
- end
- border:SetTexture("Interface\\BUTTONS\\UI-Quickslot2")
- border:ClearAllPoints()
- border:SetPoint("TOPLEFT", bu, -12, 12)
- border:SetPoint("BOTTOMRIGHT", bu, 12, -12)
- border:SetTexCoord(0, 1, 0, 1)
- ColorButton(border)
- end)
- ---------------------------------------------------------------------
- local rangeAddons = {
- "GreenRange",
- "RangeColors",
- "RedRange",
- "tullaRange",
- }
- for i = 1, #rangeAddons do
- local _, _, _, enabled = GetAddOnInfo(rangeAddons[i])
- if enabled then
- rangeAddons = nil
- break
- end
- end
- if rangeAddons then
- hooksecurefunc("ActionButton_UpdateUsable", function(self)
- local isUsable, notEnoughMana = IsUsableAction(self.action)
- if isUsable then
- self.icon:SetVertexColor(1, 1, 1)
- elseif notEnoughMana then
- local color = db.color.OutOfMana
- self.icon:SetVertexColor(color.r, color.g, color.b)
- else
- local color = db.color.NotUsable
- self.icon:SetVertexColor(color.r, color.g, color.b)
- end
- end)
- hooksecurefunc("ActionButton_OnUpdate", function(self, elapsed)
- local rangeTimer = self.rangeTimer2 or 0
- rangeTimer = rangeTimer - elapsed
- if rangeTimer <= 0 then
- if IsActionInRange(self.action) == 0 then
- local color = db.color.OutOfRange
- self.icon:SetVertexColor(color.r, color.g, color.b)
- end
- rangeTimer = TOOLTIP_UPDATE_TIME
- end
- self.rangeTimer2 = rangeTimer
- end)
- end
- self.SetupHooks = nil
- end
- ------------------------------------------------------------------------
- -- Module options
- ------------------------------------------------------------------------
- local options
- function Actionbar:GetOptions()
- if options then
- return options
- end
- local function isModuleDisabled()
- return not Core:GetModuleEnabled(MODULE_NAME)
- end
- options = {
- type = "group",
- name = L[MODULE_NAME],
- get = function(info) return db[ info[#info] ] end,
- set = function(info, value) db[ info[#info] ] = value end,
- disabled = isModuleDisabled,
- args = {
- enable = {
- type = "toggle",
- order = 1,
- name = L["Enable"],
- desc = L["Enable the Actionbar module."],
- width = "full",
- disabled = false,
- },
- auraborder = {
- type = "toggle",
- name = L["Aura borders"],
- desc = L["Show colored borders on action buttons to show when auras are active."],
- },
- showHotKeys = {
- type = "toggle",
- name = L["Show Hot Keys"],
- desc = L["Show key bindings on action buttons."],
- },
- showMacronames = {
- type = "toggle",
- name = L["Show Macro Names"],
- desc = L["Show macro names on action buttons."],
- },
- color = {
- type = "group",
- order = -1,
- name = L["Button Coloring"],
- guiInline = true,
- get = function(info)
- local v = db.color[ info[#info] ]
- return v.r, v.g, v.b
- end,
- set = function(info, r, g, b)
- local v = db.color[ info[#info] ]
- v.r, v.g, v.b = r, g, b
- end,
- disabled = function() return isModuleDisabled() or not db.color.enable end,
- args = {
- enable = {
- order = 1,
- type = "toggle",
- name = L["Enable"],
- desc = L["Enable action button coloring."],
- width = "full",
- disabled = isModuleDisabled,
- },
- OutOfRange = {
- order = 2,
- type = "color",
- name = L["Out of Range"],
- desc = L["Use this color for actions you are too far from the target to use."],
- },
- OutOfMana = {
- order = 3,
- type = "color",
- name = L["Out of Mana"],
- desc = L["Use this color for actions you don't have enough mana to use."],
- },
- NotUsable = {
- order = 4,
- type = "color",
- name = L["Not Usable"],
- desc = L["Use this color for actions you can't use for some other reason."],
- }
- }
- }
- }
- }
- return options
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement