Respond to gaining/losing a Breakable skill

The mod now reacts by adding or removing the Breakable button row when the player gains or loses an appropriate skill or profession. So if you train Enchanting, a disenchant bar will be added and if you unlearn it it will go away, for example.
This commit is contained in:
2022-09-22 21:18:06 -05:00
parent a27b2a7301
commit 59b1cafee3

View File

@ -339,11 +339,27 @@ function Breakables:InitLDB()
end
end
function Breakables:OnEnable()
function Breakables:SetCapabilities()
CanMill = IsUsableSpell(GetSpellInfo(MillingId))
CanProspect = IsUsableSpell(GetSpellInfo(ProspectingId))
CanDisenchant = IsUsableSpell(GetSpellInfo(DisenchantId))
CanPickLock = IsUsableSpell(GetSpellInfo(PickLockId))
end
function Breakables:OnSpellsChanged()
local couldMill = CanMill
local couldProspect = CanProspect
local couldDisenchant = CanDisenchant
local couldPick = CanPickLock
self:SetCapabilities()
if couldMill ~= CanMill or couldProspect ~= CanProspect or couldDisenchant ~= CanDisenchant or couldPick ~= CanPickLock then
self:SetupButtons()
end
end
function Breakables:OnEnable()
self:SetCapabilities()
self.EnchantingLevel = 0
@ -361,7 +377,16 @@ function Breakables:OnEnable()
self:RegisterEvents()
if CanMill or CanProspect or CanDisenchant or CanPickLock then
self:SetupButtons()
end
local canBreakSomething = function()
return CanMill or CanProspect or CanDisenchant or CanPickLock
end
function Breakables:SetupButtons()
numEligibleProfessions = 0
if canBreakSomething() then
if CanMill then
numEligibleProfessions = numEligibleProfessions + 1
end
@ -387,7 +412,7 @@ function Breakables:OnEnable()
end
self.frame:SetScript("OnUpdate", self.frame.OnUpdateFunc)
else
self:UnregisterAllEvents()
self:ToggleButtonFrameVisibility(false)
end
end
@ -416,14 +441,13 @@ function Breakables:RegisterEvents()
self:RegisterEvent("PLAYER_REGEN_ENABLED", "OnLeaveCombat")
self:RegisterEvent("MODIFIER_STATE_CHANGED", "FindBreakables")
self:RegisterEvent("SPELLS_CHANGED", "OnSpellsChanged")
if CanDisenchant and ShouldHookTradeskillUpdate then
if ShouldHookTradeskillUpdate then
self:RegisterEvent("TRADE_SKILL_UPDATE", "OnTradeSkillUpdate")
end
if CanPickLock then
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED", "OnSpellCastSucceeded")
end
if UnitCanPetBattle then
self:RegisterEvent("PET_BATTLE_OPENING_START", "PetBattleStarted")
@ -489,12 +513,16 @@ function Breakables:OnLeaveCombat()
end
function Breakables:OnTradeSkillUpdate()
if not CanDisenchant then
return
end
self:GetEnchantingLevel()
self:FindBreakables()
end
function Breakables:OnSpellCastSucceeded(evt, unit, guid, spell)
if spell ~= PickLockId then
if spell ~= PickLockId or not CanPickLock then
return
end
@ -765,11 +793,7 @@ function Breakables:GetOptions()
hidden = function() return not IsIgnoringAnything() end,
order = 31,
},
},
}
if CanDisenchant then
opts.args.showSoulbound = {
showSoulbound = {
type = "toggle",
name = L["Show soulbound items"],
desc = L["Whether or not to display soulbound items as breakables."],
@ -783,8 +807,14 @@ function Breakables:GetOptions()
end
self:FindBreakables()
end,
hidden = function()
return not CanDisenchant
end,
order = 20,
},
},
}
if GetNumEquipmentSets or C_EquipmentSet then
opts.args.hideEqManagerItems = {
type = "toggle",
@ -801,11 +831,12 @@ function Breakables:GetOptions()
self:FindBreakables()
end,
hidden = function()
return not self.settings.showSoulbound
return not CanDisenchant and not self.settings.showSoulbound
end,
order = 21,
}
end
if ShouldShowTabardControls then
opts.args.hideTabards = {
type = "toggle",
@ -843,7 +874,6 @@ function Breakables:GetOptions()
order = 10,
}
end
end
if UnitCanPetBattle then
opts.args.hideInPetBattle = {
@ -875,6 +905,11 @@ function Breakables:CreateButtonFrame()
self.buttonFrame = {}
end
for i=numEligibleProfessions+1,#self.buttonFrame do
self.buttonFrame[i]:ClearAllPoints()
self.buttonFrame[i]:Hide()
end
for i=1,numEligibleProfessions do
if not self.buttonFrame[i] then
self.buttonFrame[i] = CreateFrame("Button", "BREAKABLES_BUTTON_FRAME"..i, self.frame, "SecureActionButtonTemplate")
@ -1005,6 +1040,10 @@ function Breakables:FindBreakables(bag)
return
end
if not canBreakSomething() then
return
end
if self.bCombat then
self.bPendingUpdate = true
return