fix: toggle bags keybinding
This commit is contained in:
+4
-17
@@ -1,23 +1,10 @@
|
|||||||
<Bindings>
|
<Bindings>
|
||||||
<Binding name="GUDA_TOGGLE_BAGS" header="GUDA">
|
<Binding name="GUDA_TOGGLE_BAGS" header="GUDA">
|
||||||
Guda.Modules.BagFrame:Toggle()
|
-- Use safe global wrapper that defers until addon is ready
|
||||||
|
Guda_ToggleBags()
|
||||||
</Binding>
|
</Binding>
|
||||||
<Binding name="GUDA_TOGGLE_BANK" header="GUDA">
|
<Binding name="GUDA_TOGGLE_BANK" header="GUDA">
|
||||||
if Guda_BankFrame and Guda_BankFrame:IsShown() then
|
-- Use safe global wrapper that defers until addon is ready
|
||||||
Guda_BankFrame:Hide()
|
Guda_ToggleBank()
|
||||||
else
|
|
||||||
-- Open the same bank view as the "View Bank" dropdown option
|
|
||||||
-- Show current character's saved bank (read-only), centered
|
|
||||||
if Guda and Guda.Modules and Guda.Modules.DB then
|
|
||||||
local fullName = Guda.Modules.DB:GetPlayerFullName()
|
|
||||||
if fullName and Guda_BagFrame_ShowCharacterBank then
|
|
||||||
Guda_BagFrame_ShowCharacterBank(fullName)
|
|
||||||
elseif Guda and Guda.Modules and Guda.Modules.BankFrame then
|
|
||||||
-- Fallback: ensure the frame is shown
|
|
||||||
Guda.Modules.BankFrame:ShowCharacter(fullName)
|
|
||||||
if Guda_BankFrame then Guda_BankFrame:Show() end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
</Binding>
|
</Binding>
|
||||||
</Bindings>
|
</Bindings>
|
||||||
|
|||||||
@@ -96,6 +96,79 @@ addon.Constants = {
|
|||||||
-- Initialize modules storage
|
-- Initialize modules storage
|
||||||
addon.Modules = {}
|
addon.Modules = {}
|
||||||
|
|
||||||
|
-- Readiness flags for safe early keybind handling
|
||||||
|
addon._ready = false
|
||||||
|
addon._pendingToggleBags = false
|
||||||
|
addon._pendingToggleBank = false
|
||||||
|
addon._deferBagsRegistered = false
|
||||||
|
addon._deferBankRegistered = false
|
||||||
|
|
||||||
|
-- Global safe wrappers for keybindings (defined early and always available)
|
||||||
|
function Guda_ToggleBags()
|
||||||
|
local a = Guda
|
||||||
|
if a and a._ready and a.Modules and a.Modules.BagFrame and a.Modules.BagFrame.Toggle then
|
||||||
|
a.Modules.BagFrame:Toggle()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Defer until PLAYER_LOGIN completes addon initialization
|
||||||
|
if a and a.Modules and a.Modules.Events and not a._deferBagsRegistered then
|
||||||
|
a._pendingToggleBags = true
|
||||||
|
a._deferBagsRegistered = true
|
||||||
|
a.Modules.Events:OnPlayerLogin(function()
|
||||||
|
if Guda and Guda._pendingToggleBags then
|
||||||
|
Guda._pendingToggleBags = false
|
||||||
|
if Guda.Modules and Guda.Modules.BagFrame and Guda.Modules.BagFrame.Toggle then
|
||||||
|
Guda.Modules.BagFrame:Toggle()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end, "Guda_KeybindDefer_Bags")
|
||||||
|
else
|
||||||
|
-- If Events not yet available, set pending flag; Main will clear it when ready
|
||||||
|
if a then a._pendingToggleBags = true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Guda_ToggleBank()
|
||||||
|
local a = Guda
|
||||||
|
local function doToggleBank()
|
||||||
|
if Guda_BankFrame and Guda_BankFrame:IsShown() then
|
||||||
|
Guda_BankFrame:Hide()
|
||||||
|
else
|
||||||
|
if a and a.Modules and a.Modules.DB then
|
||||||
|
local fullName = a.Modules.DB:GetPlayerFullName()
|
||||||
|
-- WoW 1.12 uses getglobal/setglobal; `_G` is not available (Lua 5.0)
|
||||||
|
local showBankFn = getglobal and getglobal("Guda_BagFrame_ShowCharacterBank") or nil
|
||||||
|
if fullName and showBankFn then
|
||||||
|
-- Prefer exported helper if available
|
||||||
|
showBankFn(fullName)
|
||||||
|
elseif a and a.Modules and a.Modules.BankFrame then
|
||||||
|
a.Modules.BankFrame:ShowCharacter(fullName)
|
||||||
|
if Guda_BankFrame then Guda_BankFrame:Show() end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if a and a._ready then
|
||||||
|
doToggleBank()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if a and a.Modules and a.Modules.Events and not a._deferBankRegistered then
|
||||||
|
a._pendingToggleBank = true
|
||||||
|
a._deferBankRegistered = true
|
||||||
|
a.Modules.Events:OnPlayerLogin(function()
|
||||||
|
if Guda and Guda._pendingToggleBank then
|
||||||
|
Guda._pendingToggleBank = false
|
||||||
|
doToggleBank()
|
||||||
|
end
|
||||||
|
end, "Guda_KeybindDefer_Bank")
|
||||||
|
else
|
||||||
|
if a then a._pendingToggleBank = true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Helper to apply backdrop with color
|
-- Helper to apply backdrop with color
|
||||||
function addon:ApplyBackdrop(frame, backdropType, colorType)
|
function addon:ApplyBackdrop(frame, backdropType, colorType)
|
||||||
local backdrop = self.Constants.Backdrops[backdropType]
|
local backdrop = self.Constants.Backdrops[backdropType]
|
||||||
|
|||||||
@@ -36,6 +36,21 @@ function Main:Initialize()
|
|||||||
-- Setup slash commands
|
-- Setup slash commands
|
||||||
Main:SetupSlashCommands()
|
Main:SetupSlashCommands()
|
||||||
|
|
||||||
|
-- Mark addon ready for keybind wrappers and process any pending toggles
|
||||||
|
addon._ready = true
|
||||||
|
if addon._pendingToggleBags then
|
||||||
|
addon._pendingToggleBags = false
|
||||||
|
if addon.Modules.BagFrame and addon.Modules.BagFrame.Toggle then
|
||||||
|
addon.Modules.BagFrame:Toggle()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if addon._pendingToggleBank then
|
||||||
|
addon._pendingToggleBank = false
|
||||||
|
if addon.Modules.BankFrame and addon.Modules.BankFrame.Toggle then
|
||||||
|
addon.Modules.BankFrame:Toggle()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
addon:Debug("Initialization complete")
|
addon:Debug("Initialization complete")
|
||||||
addon:Print("Ready! Type /guda to open bags")
|
addon:Print("Ready! Type /guda to open bags")
|
||||||
end, "Main")
|
end, "Main")
|
||||||
|
|||||||
Reference in New Issue
Block a user