diff --git a/Clicked/Clicked2.toc b/Clicked/Clicked2.toc index a993aa2..5622d17 100644 --- a/Clicked/Clicked2.toc +++ b/Clicked/Clicked2.toc @@ -41,6 +41,8 @@ Core\StringUtils.lua Core\Serializer.lua Core\Upgrader.lua +Modules\Minimap.lua + Conditions\ConditionRegistry.lua Conditions\ConditionUtils.lua Conditions\LoadConditions.lua diff --git a/Clicked/Config/Addon.lua b/Clicked/Config/Addon.lua index 62aa6f3..c97df54 100644 --- a/Clicked/Config/Addon.lua +++ b/Clicked/Config/Addon.lua @@ -16,8 +16,6 @@ local AceConfig = LibStub("AceConfig-3.0") local AceConfigDialog = LibStub("AceConfigDialog-3.0") -local LibDBIcon = LibStub("LibDBIcon-1.0") -local LibLog = LibStub("LibLog-1.0") --- @class Addon local Addon = select(2, ...) @@ -33,47 +31,10 @@ end --- @private --- @return AceConfig.OptionsTable function AddonOptions:CreateOptionsTable() - return { + local result = { type = "group", name = Addon.L["Clicked2"], args = { - minimapIcon = { - name = Addon.L["Enable minimap icon"], - desc = Addon.L["Enable or disable the minimap icon."], - type = "toggle", - order = 100, - width = "full", - set = function(_, val) - Addon.db.profile.options.minimap.hide = not val - - if val then - LibDBIcon:Show(Addon.L["Clicked2"]) - else - LibDBIcon:Hide(Addon.L["Clicked2"]) - end - end, - get = function(_) - return not Addon.db.profile.options.minimap.hide - end - }, - addonCompartmentButton = { - name = Addon.L["Enable addon compartment button"], - desc = Addon.L["Enable or disable the addon compartment button."], - type = "toggle", - order = 101, - width = "full", - hidden = Addon.EXPANSION < Addon.Expansion.DF, - set = function (_, val) - if val then - LibDBIcon:AddButtonToCompartment(Addon.L["Clicked2"]) - else - LibDBIcon:RemoveButtonFromCompartment(Addon.L["Clicked2"]) - end - end, - get = function(_) - return LibDBIcon:IsButtonInCompartment(Addon.L["Clicked2"]) - end - }, onKeyDown = { name = Addon.L["Cast on key down rather than key up"], desc = Addon.L["This option will make bindings trigger on the 'down' portion of a button press rather than the 'up' portion."], @@ -130,9 +91,7 @@ function AddonOptions:CreateOptionsTable() type = "toggle", order = 600, width = "full", - hidden = function() - return Addon.EXPANSION < Addon.Expansion.TWW - end, + hidden = Addon.EXPANSION < Addon.Expansion.TWW, set = function (_, val) Addon.db.profile.options.disableInHouse = val Addon:ReloadBindings("HOUSE_EDITOR_MODE_CHANGED") @@ -146,6 +105,19 @@ function AddonOptions:CreateOptionsTable() }) } } + + for _, module in Clicked2:IterateModules() do + --- @cast module AceModule|AddonOptionsProvider + local handler = module.GetAddonOptions + + if type(handler) == "function" then + for key, option in pairs(handler(module)) do + result.args[module.moduleName .. "_" .. key] = option + end + end + end + + return result end Addon.AddonOptions = AddonOptions diff --git a/Clicked/Core/Clicked.lua b/Clicked/Core/Clicked.lua index a225ba2..d5b0083 100644 --- a/Clicked/Core/Clicked.lua +++ b/Clicked/Core/Clicked.lua @@ -15,8 +15,6 @@ -- along with this program. If not, see . local AceConsole = LibStub("AceConsole-3.0") -local LibDataBroker = LibStub("LibDataBroker-1.1") -local LibDBIcon = LibStub("LibDBIcon-1.0") --- @class Addon local Addon = select(2, ...) @@ -29,25 +27,6 @@ local wasHouseEditorActive = false --- @type table local playerFlagsCache = {} --- Local support functions - -local function RegisterIcons() - local iconData = LibDataBroker:NewDataObject("Clicked2", { - type = "launcher", - label = Addon.L["Clicked2"], - icon = "Interface\\Icons\\inv_misc_punchcards_yellow", - OnClick = function() - Addon.BindingConfig.Window:Open() - end, - OnTooltipShow = function(tooltip) - tooltip:AddLine(Addon.L["Clicked2"]) - end - }) - - LibDBIcon:Register(Addon.L["Clicked2"], iconData, Addon.db.profile.options.minimap) - LibDBIcon:AddButtonToCompartment(Addon.L["Clicked2"]) -end - --- Parse a chat command input and handle it appropriately. --- --- @param input string The data of the chat command, excluding the first word @@ -360,8 +339,6 @@ function Clicked2:OnInitialize() Addon:UpgradeDatabase() - RegisterIcons() - Addon:RegisterClickCastHeader() Addon:RegisterBlizzardUnitFrames() diff --git a/Clicked/Core/Init.lua b/Clicked/Core/Init.lua index 92c30d9..393e30e 100644 --- a/Clicked/Core/Init.lua +++ b/Clicked/Core/Init.lua @@ -18,6 +18,7 @@ Clicked2 = LibStub("AceAddon-3.0"):NewAddon("Clicked2", "AceEvent-3.0", "LibLog-1.0") Clicked2.VERSION = C_AddOns.GetAddOnMetadata("Clicked2", "Version") +Clicked2:SetDefaultModuleLibraries("LibLog-1.0") Clicked2:LogVerbose("Initializing Clicked") --@debug@ diff --git a/Clicked/Definitions.lua b/Clicked/Definitions.lua index 8b40b8c..050ff32 100644 --- a/Clicked/Definitions.lua +++ b/Clicked/Definitions.lua @@ -16,12 +16,8 @@ --- @meta ---- @class Clicked : AceAddon, AceEvent-3.0 ---- @field public VERSION string - ---- @class Addon : AceEvent-3.0 ---- @field public L table ---- @field public db AceDBObject-3.0 +--- @class AddonOptionsProvider +--- @field public GetAddonOptions fun(self: AddonOptionsProvider): table --- @class Profile --- @field public version integer diff --git a/Clicked/Modules/Minimap.lua b/Clicked/Modules/Minimap.lua new file mode 100644 index 0000000..9a7b713 --- /dev/null +++ b/Clicked/Modules/Minimap.lua @@ -0,0 +1,113 @@ +-- 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 . + +local LibDataBroker = LibStub("LibDataBroker-1.1") +local LibDBIcon = LibStub("LibDBIcon-1.0") + +--- @class Addon +local Addon = select(2, ...) + +--- @class MinimapModule : AceModule, LibLog-1.0.Logger, AddonOptionsProvider +local Prototype = {} + +--- @protected +function Prototype:OnInitialize() + local iconData = LibDataBroker:NewDataObject("Clicked2", { + type = "launcher", + label = Addon.L["Clicked2"], + icon = "Interface\\Icons\\inv_misc_punchcards_yellow", + OnClick = function() + Addon.BindingConfig.Window:Open() + end, + OnTooltipShow = function(tooltip) + tooltip:AddLine(Addon.L["Clicked2"]) + end + }) + + LibDBIcon:Register(Addon.L["Clicked2"], iconData, Addon.db.profile.options.minimap) + LibDBIcon:AddButtonToCompartment(Addon.L["Clicked2"]) + + self:LogDebug("Initialized minimap module") +end + +--- @param enabled boolean +function Prototype:SetMinimapButtonEnabled(enabled) + self:LogDebug("Set minimap button visibility to {visible}", enabled) + + Addon.db.profile.options.minimap.hide = not enabled + + if enabled then + LibDBIcon:Show(Addon.L["Clicked2"]) + else + LibDBIcon:Hide(Addon.L["Clicked2"]) + end +end + +--- @param enabled boolean +function Prototype:SetCompartmentButtonEnabled(enabled) + self:LogDebug("Set addon compartment button visibility to {visible}", enabled) + + if enabled then + LibDBIcon:AddButtonToCompartment(Addon.L["Clicked2"]) + else + LibDBIcon:RemoveButtonFromCompartment(Addon.L["Clicked2"]) + end +end + +--- @return boolean +function Prototype:IsMinimapButtonEnabled() + return not Addon.db.profile.options.minimap.hide +end + +--- @return boolean +function Prototype:IsCompartmentButtonEnabled() + return LibDBIcon:IsButtonInCompartment(Addon.L["Clicked2"]) +end + +--- @return table +function Prototype:GetAddonOptions() + return { + minimapIcon = { + name = Addon.L["Enable minimap icon"], + desc = Addon.L["Enable or disable the minimap icon."], + type = "toggle", + order = 100, + width = "full", + set = function(_, val) + self:SetMinimapButtonEnabled(val) + end, + get = function(_) + return self:IsMinimapButtonEnabled() + end + }, + addonCompartmentButton = { + name = Addon.L["Enable addon compartment button"], + desc = Addon.L["Enable or disable the addon compartment button."], + type = "toggle", + order = 101, + width = "full", + hidden = Addon.EXPANSION < Addon.Expansion.DF, + set = function (_, val) + self:SetCompartmentButtonEnabled(val) + end, + get = function() + return self:IsCompartmentButtonEnabled() + end + } + } +end + +Clicked2:NewModule("Minimap", Prototype)