diff --git a/Clicked/Clicked2.toc b/Clicked/Clicked2.toc index 5622d17..d202e71 100644 --- a/Clicked/Clicked2.toc +++ b/Clicked/Clicked2.toc @@ -41,6 +41,7 @@ Core\StringUtils.lua Core\Serializer.lua Core\Upgrader.lua +Modules\ConfigWindow.lua Modules\Minimap.lua Conditions\ConditionRegistry.lua diff --git a/Clicked/Core/Clicked.lua b/Clicked/Core/Clicked.lua index d5b0083..9497152 100644 --- a/Clicked/Core/Clicked.lua +++ b/Clicked/Core/Clicked.lua @@ -21,7 +21,6 @@ local Addon = select(2, ...) local isPlayerInCombat = false local isInitialized = false -local openConfigOnCombatExit = false local wasHouseEditorActive = false --- @type table @@ -37,23 +36,25 @@ local function HandleChatCommand(input) while true do local arg, next = AceConsole:GetArgs(input, 1, start) - table.insert(args, arg) if next == 1e9 then break end + table.insert(args, arg) start = next end - if #args == 0 then - if InCombatLockdown() then - openConfigOnCombatExit = true - Clicked2:LogWarning(Addon.L["Binding configuration will open once you leave combat."]) - else - Addon.BindingConfig.Window:Open() + for _, module in Clicked2:IterateModules() do + --- @cast module SlashCommandHandler + local handler = module.HandleSlashCommand + + if type(handler) == "function" and handler(module, args) then + return end - elseif #args == 1 then + end + + if #args == 1 then if args[1] == "opt" or args[1] == "options" then Addon:OpenSettingsMenu("Clicked2") elseif args[1] == "dump" then @@ -78,9 +79,6 @@ local function PLAYER_REGEN_DISABLED() Clicked2:LogVerbose("Received event {eventName}", "PLAYER_REGEN_DISABLED") isPlayerInCombat = true - openConfigOnCombatExit = Addon.BindingConfig.Window:IsOpen() - - Addon.BindingConfig.Window:Close() if Addon:IsCombatProcessRequired() then Clicked2:ProcessActiveBindings() @@ -97,11 +95,6 @@ local function PLAYER_REGEN_ENABLED() if Addon:IsCombatProcessRequired() then Clicked2:ProcessActiveBindings() end - - if openConfigOnCombatExit then - Addon.BindingConfig.Window:Open() - openConfigOnCombatExit = false - end end local function PLAYER_ENTERING_WORLD() diff --git a/Clicked/Definitions.lua b/Clicked/Definitions.lua index 050ff32..aff146b 100644 --- a/Clicked/Definitions.lua +++ b/Clicked/Definitions.lua @@ -19,6 +19,9 @@ --- @class AddonOptionsProvider --- @field public GetAddonOptions fun(self: AddonOptionsProvider): table +--- @class SlashCommandHandler +--- @field public HandleSlashCommand fun(self: SlashCommandHandler, args: string[]): boolean + --- @class Profile --- @field public version integer --- @field public options Profile.Options diff --git a/Clicked/Modules/ConfigWindow.lua b/Clicked/Modules/ConfigWindow.lua new file mode 100644 index 0000000..373e6bc --- /dev/null +++ b/Clicked/Modules/ConfigWindow.lua @@ -0,0 +1,63 @@ +-- Clicked, a World of Warcraft keybind manager. +-- Copyright (C) 2026 Kevin Krol +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see . + +--- @class Addon +local Addon = select(2, ...) + +--- @class ConfigWindowModule : AceModule, AceEvent-3.0, LibLog-1.0.Logger, SlashCommandHandler +local Prototype = {} + +--- @protected +function Prototype:OnInitialize() + self:RegisterEvent("PLAYER_REGEN_DISABLED", self.PLAYER_REGEN_DISABLED, self) + self:RegisterEvent("PLAYER_REGEN_ENABLED", self.PLAYER_REGEN_ENABLED, self) + + self:LogDebug("Initialized config window module") +end + +--- @param args string[] +--- @return boolean +function Prototype:HandleSlashCommand(args) + if #args == 0 then + if InCombatLockdown() then + self.openConfigPending = true + self:LogWarning(Addon.L["Binding configuration will open once you leave combat."]) + else + Addon.BindingConfig.Window:Open() + end + + return true + end + + return false +end + +--- @private +function Prototype:PLAYER_REGEN_DISABLED() + self.openConfigPending = Addon.BindingConfig.Window:IsOpen() + + Addon.BindingConfig.Window:Close() +end + +--- @private +function Prototype:PLAYER_REGEN_ENABLED() + if self.openConfigPending then + Addon.BindingConfig.Window:Open() + self.openConfigPending = false + end +end + +Clicked2:NewModule("ConfigWindow", Prototype, "AceEvent-3.0")