Refresh zCraft after profession ranks

This commit is contained in:
DuvelCorp
2026-09-12 08:05:44 +02:00
parent 402cd8aef0
commit af31acdb3e
3 changed files with 39 additions and 16 deletions
+32 -13
View File
@@ -26,6 +26,7 @@ local ZHUNTER_CRAFT_BUTTON_MAX = 14
local zButtonCraft_LastSpellSignature = nil
local zButtonCraft_LastRefreshAt = 0
local zButtonCraft_MinRefreshInterval = 0.50
local zButtonCraft_PendingRefresh = false
-- Exact spell names as they appear in the General spellbook tab.
-- spellName = the name returned by GetSpellName() to match against (case-insensitive)
@@ -278,6 +279,7 @@ function zButtonCraft_OnEvent()
zButtonCraft_CreateButtons()
MTH_ZH_CraftAdjust = CreateFrame("Frame", "MTH_ZH_CraftAdjust")
MTH_ZH_CraftAdjust:RegisterEvent("SPELLS_CHANGED")
MTH_ZH_CraftAdjust:RegisterEvent("LEARNED_SPELL_IN_TAB")
MTH_ZH_CraftAdjust:RegisterEvent("PLAYER_ENTERING_WORLD")
MTH_ZH_CraftAdjust:SetScript("OnEvent", MTH_ZH_CraftAdjust_OnEvent)
zButtonCraft_SetupSizeAndPosition()
@@ -307,6 +309,7 @@ function zButtonCraft_SetupSizeAndPosition()
end
if MTH_ZH_CraftAdjust then
MTH_ZH_CraftAdjust:RegisterEvent("SPELLS_CHANGED")
MTH_ZH_CraftAdjust:RegisterEvent("LEARNED_SPELL_IN_TAB")
MTH_ZH_CraftAdjust:RegisterEvent("PLAYER_ENTERING_WORLD")
MTH_ZH_CraftAdjust:SetScript("OnEvent", MTH_ZH_CraftAdjust_OnEvent)
end
@@ -342,21 +345,19 @@ function zButtonCraft_Reset()
zButtonCraft_EnsureConfig()
end
function MTH_ZH_CraftAdjust_OnEvent()
local function zButtonCraft_RefreshAfterSpellbookChange()
if not zButtonCraft then return end
if event == "SPELLS_CHANGED" then
local now = GetTime and GetTime() or 0
if now > 0 and zButtonCraft_LastRefreshAt > 0 and (now - zButtonCraft_LastRefreshAt) < zButtonCraft_MinRefreshInterval then
return
end
local spellIds, _ = zButtonCraft_CollectProfessions()
local signature = zButtonCraft_GetSpellSignature(spellIds)
if signature == zButtonCraft_LastSpellSignature and not GameTooltip:IsOwned(zButtonCraft) then
return
end
zButtonCraft_LastSpellSignature = signature
zButtonCraft_LastRefreshAt = now
local now = GetTime and GetTime() or 0
if now > 0 and zButtonCraft_LastRefreshAt > 0 and (now - zButtonCraft_LastRefreshAt) < zButtonCraft_MinRefreshInterval then
return
end
local spellIds, _ = zButtonCraft_CollectProfessions()
local signature = zButtonCraft_GetSpellSignature(spellIds)
if signature == zButtonCraft_LastSpellSignature and not GameTooltip:IsOwned(zButtonCraft) then
return
end
zButtonCraft_LastSpellSignature = signature
zButtonCraft_LastRefreshAt = now
zButtonCraft_RefreshProfessions()
zButtonCraft_SetupSizeAndPosition()
if GameTooltip:IsOwned(zButtonCraft) then
@@ -364,6 +365,24 @@ function MTH_ZH_CraftAdjust_OnEvent()
end
end
function MTH_ZH_CraftAdjust_OnEvent()
if not zButtonCraft then return end
if event == "SPELLS_CHANGED" or event == "LEARNED_SPELL_IN_TAB" then
if zButtonCraft_PendingRefresh then return end
zButtonCraft_PendingRefresh = true
MTH_ZH_CraftAdjust.elapsed = 0
MTH_ZH_CraftAdjust:SetScript("OnUpdate", function()
this.elapsed = (this.elapsed or 0) + (arg1 or 0)
if this.elapsed < 0.6 then return end
this:SetScript("OnUpdate", nil)
zButtonCraft_PendingRefresh = false
zButtonCraft_RefreshAfterSpellbookChange()
end)
return
end
zButtonCraft_RefreshAfterSpellbookChange()
end
function zButtonCraft_KeyBinding(index)
if MTH_ZH_IsModuleEnabled and not MTH_ZH_IsModuleEnabled() then return end
local button