-- Button snippets in relevant order
button:SetAttribute("_childupdate-state", [[
if self:GetAttribute("mainbutton") then -- this is only true for 15 / 60 buttons
self:RunAttribute("UpdateState", message)
self:CallMethod("UpdateAction")
end
]])
button:SetAttribute("UpdateState", [[
local state = ...
self:SetAttribute("state", state)
local type, action = (self:GetAttribute(format("labtype-%s", state)) or "empty"), self:GetAttribute(format("labaction-%s", state))
self:SetAttribute("type", type)
if type ~= "empty" and type ~= "custom" then
local action_field = (type == "pet") and "action" or type
self:SetAttribute(action_field, action)
self:SetAttribute("action_field", action_field)
end
local onStateChanged = self:GetAttribute("OnStateChanged")
if onStateChanged then
self:Run(onStateChanged, state, type, action)
end
]])
function Generic:UpdateAction(force)
local type, action = self:GetAction()
if force or type ~= self._state_type or action ~= self._state_action then
-- type changed, update the metatable
if force or self._state_type ~= type then
local meta = type_meta_map[type] or type_meta_map.empty
setmetatable(self, meta)
self._state_type = type
end
self._state_action = action
Update(self)
end
end
function Update(self)
if self:HasAction() then
ActiveButtons[self] = true
if self._state_type == "action" then
ActionButtons[self] = true
NonActionButtons[self] = nil
else
ActionButtons[self] = nil
NonActionButtons[self] = true
end
-- self:SetAlpha(1.0)
UpdateButtonState(self)
UpdateUsable(self)
UpdateCooldown(self)
UpdateFlash(self)
else
ActiveButtons[self] = nil
ActionButtons[self] = nil
NonActionButtons[self] = nil
if gridCounter == 0 and not self.config.showGrid then
-- self:SetAlpha(0.0)
end
self.cooldown:Hide()
self:SetChecked(false)
if self.chargeCooldown then
EndChargeCooldown(self.chargeCooldown)
end
end
-- Add a green border if button is an equipped item
if self:IsEquipped() and not self.config.hideElements.equipped then
self.Border:SetVertexColor(0, 1.0, 0, 0.35)
self.Border:Show()
else
self.Border:Hide()
end
-- Update Action Text
if not self:IsConsumableOrStackable() then
self.Name:SetText(self:GetActionText())
else
self.Name:SetText("")
end
-- Update icon and hotkey
local texture = self:GetTexture()
-- Draenor zone button handling
self.draenorZoneDisabled = false
self.icon:SetDesaturated(false)
if self._state_type == "action" then
local action_type, id = GetActionInfo(self._state_action)
if ((action_type == "spell" or action_type == "companion") and DraenorZoneAbilityFrame and DraenorZoneAbilityFrame.baseName and not HasDraenorZoneAbility()) then
local name = GetSpellInfo(DraenorZoneAbilityFrame.baseName)
local abilityName = GetSpellInfo(id)
if name == abilityName then
texture = GetLastDraenorSpellTexture()
self.draenorZoneDisabled = true
self.icon:SetDesaturated(true)
end
end
end
if texture and texture ~= self.cachedTexture then
self.cachedTexture = texture
self.icon:SetTexture(texture) -- where it breaks down when icons are masked
self.icon:Show()
self.rangeTimer = - 1
elseif not texture then
self.cachedTexture = nil
self.icon:Hide()
self.cooldown:Hide()
self.rangeTimer = nil
end
UpdateCount(self)
UpdateFlyout(self)
UpdateOverlayGlow(self)
UpdateNewAction(self)
if GameTooltip:GetOwner() == self then
UpdateTooltip(self)
end
-- this could've been a spec change, need to call OnStateChanged for action buttons, if present
if not InCombatLockdown() and self._state_type == "action" then
local onStateChanged = self:GetAttribute("OnStateChanged")
if onStateChanged then
self.header:SetFrameRef("updateButton", self)
self.header:Execute(([[
local frame = self:GetFrameRef("updateButton")
control:RunFor(frame, frame:GetAttribute("OnStateChanged"), %s, %s, %s)
]]):format(formatHelper(self:GetAttribute("state")), formatHelper(self._state_type), formatHelper(self._state_action)))
end
end
lib.callbacks:Fire("OnButtonUpdate", self)
end