diff --git a/Breakables.lua b/Breakables.lua index 0b7a15a..aff6228 100644 --- a/Breakables.lua +++ b/Breakables.lua @@ -339,12 +339,28 @@ 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 LibStub("AceConfig-3.0"):RegisterOptionsTable("Breakables", self:GetOptions(), "breakables") @@ -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 + self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED", "OnSpellCastSucceeded") 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,84 +793,86 @@ function Breakables:GetOptions() hidden = function() return not IsIgnoringAnything() end, order = 31, }, - }, - } - - if CanDisenchant then - opts.args.showSoulbound = { - type = "toggle", - name = L["Show soulbound items"], - desc = L["Whether or not to display soulbound items as breakables."], - get = function(info) - return self.settings.showSoulbound - end, - set = function(info, v) - self.settings.showSoulbound = v - if info.uiType == "cmd" then - print("|cff33ff99Breakables|r: set |cffffff78showSoulbound|r to " .. tostring(self.settings.showSoulbound)) - end - self:FindBreakables() - end, - order = 20, - } - if GetNumEquipmentSets or C_EquipmentSet then - opts.args.hideEqManagerItems = { + showSoulbound = { type = "toggle", - name = L["Hide Eq. Mgr items"], - desc = L["Whether or not to hide items that are part of an equipment set in the game's equipment manager."], + name = L["Show soulbound items"], + desc = L["Whether or not to display soulbound items as breakables."], get = function(info) - return self.settings.hideEqManagerItems + return self.settings.showSoulbound end, set = function(info, v) - self.settings.hideEqManagerItems = v + self.settings.showSoulbound = v if info.uiType == "cmd" then - print("|cff33ff99Breakables|r: set |cffffff78hideEqManagerItems|r to " .. tostring(self.settings.hideEqManagerItems)) + print("|cff33ff99Breakables|r: set |cffffff78showSoulbound|r to " .. tostring(self.settings.showSoulbound)) end self:FindBreakables() end, hidden = function() - return not self.settings.showSoulbound + return not CanDisenchant end, - order = 21, - } - end - if ShouldShowTabardControls then - opts.args.hideTabards = { - type = "toggle", - name = L["Hide Tabards"], - desc = L["Whether or not to hide tabards from the disenchantable items list."], - get = function(info) - return self.settings.hideTabards - end, - set = function(info, v) - self.settings.hideTabards = v - if info.uiType == "cmd" then - print("|cff33ff99Breakables|r: set |cffffff78hideTabards|r to " .. tostring(self.settings.hideTabards)) - end - self:FindBreakables() - end, - order = 22, - } - end + order = 20, + }, + }, + } - if not IgnoreEnchantingSkillLevelForDisenchant then - opts.args.ignoreEnchantingSkillLevel = { - type = "toggle", - name = L["Ignore Enchanting skill level"], - desc = L["Whether or not items should be shown when Breakables thinks you don't have the appropriate skill level to disenchant it."], - get = function(info) - return self.settings.ignoreEnchantingSkillLevel - end, - set = function(info, v) - self.settings.ignoreEnchantingSkillLevel = v - self:FindBreakables() - if info.uiType == "cmd" then - print("|cff33ff99Breakables|r: set |cffffff78ignoreEnchantingSkillLevel|r to " .. tostring(self.settings.ignoreEnchantingSkillLevel)) - end - end, - order = 10, - } - end + if GetNumEquipmentSets or C_EquipmentSet then + opts.args.hideEqManagerItems = { + type = "toggle", + name = L["Hide Eq. Mgr items"], + desc = L["Whether or not to hide items that are part of an equipment set in the game's equipment manager."], + get = function(info) + return self.settings.hideEqManagerItems + end, + set = function(info, v) + self.settings.hideEqManagerItems = v + if info.uiType == "cmd" then + print("|cff33ff99Breakables|r: set |cffffff78hideEqManagerItems|r to " .. tostring(self.settings.hideEqManagerItems)) + end + self:FindBreakables() + end, + hidden = function() + return not CanDisenchant and not self.settings.showSoulbound + end, + order = 21, + } + end + + if ShouldShowTabardControls then + opts.args.hideTabards = { + type = "toggle", + name = L["Hide Tabards"], + desc = L["Whether or not to hide tabards from the disenchantable items list."], + get = function(info) + return self.settings.hideTabards + end, + set = function(info, v) + self.settings.hideTabards = v + if info.uiType == "cmd" then + print("|cff33ff99Breakables|r: set |cffffff78hideTabards|r to " .. tostring(self.settings.hideTabards)) + end + self:FindBreakables() + end, + order = 22, + } + end + + if not IgnoreEnchantingSkillLevelForDisenchant then + opts.args.ignoreEnchantingSkillLevel = { + type = "toggle", + name = L["Ignore Enchanting skill level"], + desc = L["Whether or not items should be shown when Breakables thinks you don't have the appropriate skill level to disenchant it."], + get = function(info) + return self.settings.ignoreEnchantingSkillLevel + end, + set = function(info, v) + self.settings.ignoreEnchantingSkillLevel = v + self:FindBreakables() + if info.uiType == "cmd" then + print("|cff33ff99Breakables|r: set |cffffff78ignoreEnchantingSkillLevel|r to " .. tostring(self.settings.ignoreEnchantingSkillLevel)) + end + end, + order = 10, + } end if UnitCanPetBattle then @@ -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