WoWInterface SVN DivinePleaReminder

[/] [trunk/] [DivinePleaReminder/] [DivinePleaReminder.lua] - Rev 4

Compare with Previous | Blame | View Log

--[[
DivinePleaReminder v1.2, by sigmalmtd
A lightweight AddOn for Protection Paladins.  Flashes the Divine Plea button when in combat and the buff is inactive.
]]--

DivinePleaReminder = LibStub("AceAddon-3.0"):NewAddon("DivinePleaReminder", "AceEvent-3.0")
local DIVINE_PLEA = GetSpellInfo(54428)

function DivinePleaReminder:OnInitialize()
  self.buttons = {}
end

function DivinePleaReminder:OnEnable()
  local class, slot
  -- Only enable for Paladins
  _, class = UnitClass("player")
  if class == "PALADIN" then
    self:RegisterEvent("ACTIONBAR_SLOT_CHANGED", "CheckButton")
    self:RegisterEvent("UNIT_AURA", "Update")
    self:RegisterEvent("PLAYER_REGEN_DISABLED", "Update")
    self:RegisterEvent("PLAYER_REGEN_ENABLED", "Update")
    self:RegisterEvent("UNIT_ENTERING_VEHICLE", "Update")
    self:RegisterEvent("UNIT_EXITED_VEHICLE", "Update")
    -- Check all buttons
    for slot = 1, 120 do
      self:CheckButton(nil, slot)
    end
  end
end

function DivinePleaReminder:OnDisable()
  local idx, slot
  self:UnregisterEvent("ACTIONBAR_SLOT_CHANGED")
  self:UnregisterEvent("UNIT_AURA")
  self:UnregisterEvent("PLAYER_REGEN_DISABLED")
  self:UnregisterEvent("PLAYER_REGEN_ENABLED")
  self:UnregisterEvent("UNIT_ENTERING_VEHICLE")
  self:UnregisterEvent("UNIT_EXITED_VEHICLE")
  -- Hide and free all textures
  for idx, slot in pairs(self.buttons) do
    UIFrameFlashStop(slot.texture)
    slot.texture:Hide()
    slot.texture = nil
    self.buttons[idx] = nil
  end
  self.buttons = {}
end

-- Called on all buttons when the mod is enabled and called on single buttons when ACTIONBAR_SLOT_CHANGED is fired for that slot
-- Checks if the button contains the Divine Plea spell, and creates a texture, and/or enabling or disabling it as necessary 
function DivinePleaReminder:CheckButton(eventName, slot)
  local slotType, spellId, spellSubType, parent, texture
  if slot > 120 or slot < 1 then
    return
  end
  slotType, spellId, spellSubType = GetActionInfo(slot)
  if not UnitInVehicle("player") and slotType == "spell" and GetSpellName(spellId, spellSubType) == DIVINE_PLEA then
    if self.buttons[slot] then
      -- Texture has already been created
      self.buttons[slot].enabled = true
    else
      -- Texture has not been created.  Find its parent and set it up
      parent = nil
      if Bartender4 then
        parent = _G["BT4Button" .. slot]
      elseif slot <= 12 then
        parent = _G["ActionButton" .. slot]
      elseif slot <= 24 then
        parent = _G["BonusActionButton" .. (slot-12)]
      elseif slot <= 36 then
        parent = _G["MultiBarRightButton" .. (slot-24)]
      elseif slot <= 48 then
        parent = _G["MultiBarLeftButton" .. (slot-36)]
      elseif slot <= 60 then
        parent = _G["MultiBarBottomRightButton" .. (slot-48)]
      elseif slot <= 72 then
        parent = _G["MultiBarBottomLeftButton" .. (slot-60)]
      elseif Dominos then
        parent = _G["DominosActionButton" .. (slot-72)]
      end
      if parent then
        self.buttons[slot] = {}
        self.buttons[slot].enabled = true
        texture = parent:CreateTexture("DivinePleaReminderHighlight" .. slot, "OVERLAY")
        self.buttons[slot].texture = texture
        texture:SetWidth(parent:GetWidth() * 1.722)
        texture:SetHeight(parent:GetHeight() * 1.722)
        texture:SetTexture("Interface\\Buttons\\UI-ActionButton-Border")
        texture:SetBlendMode("ADD")
        texture:SetPoint("CENTER", parent, "CENTER", 0, 0)
        texture:SetVertexColor(1.0, 0.2, 0.2, 0.8)
      end
    end
  elseif self.buttons[slot] then
    -- Texture has been created, but this slot no longer holds Divine Plea.  Disable it
    self.buttons[slot].enabled = false
  end
  self:Update()
end

-- Update all textures' shown status
function DivinePleaReminder:Update()
  local slot, show
  -- Only show the highlight if we're in combat and don't have Divine Plea active
  if not UnitAffectingCombat("player") or UnitAura("player", DIVINE_PLEA) or UnitInVehicle("player") then
    show = false
  else
    show = true
  end
  
  -- Iterate over the active textures and start/slop the flashing as necessary
  for _, slot in pairs(self.buttons) do
    if slot.enabled and show then
      UIFrameFlash(slot.texture, 0.5, 0.5, -1, false, 0.1, 0.1)
      slot.texture:Show()
    else
      UIFrameFlashStop(slot.texture)
      slot.texture:Hide()
    end
  end
end

Compare with Previous | Blame