diff --git a/Config/GUI.lua b/Config/GUI.lua deleted file mode 100644 index 53235bd..0000000 --- a/Config/GUI.lua +++ /dev/null @@ -1,141 +0,0 @@ - -local ADDON_NAME, Data = ... - -local Addon = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME) - - - -local tblConcat = table.concat - - -do - Addon.GUI = {} - local GUI = Addon.GUI - - local links = setmetatable({}, {__index = function(t, k) return k end}) - - function GUI:SwapLinks(link1, link2) - links[link1], links[link2] = links[link2], links[link1] - end - - local defaultInc = 1000 - local defaultOrder = 1000 - local order = defaultOrder - - function GUI:GetOrder() - return order - end - function GUI:SetOrder(newOrder) - order = newOrder - return self - end - function GUI:ResetOrder() - order = defaultOrder - return self - end - function GUI:Order(inc) - self:SetOrder(self:GetOrder() + (inc or defaultInc)) - return self:GetOrder() - end - - function GUI:CreateEntry(opts, keys, name, desc, widgetType, disabled, order) - if type(keys) ~= "table" then keys = {keys} end - local key = widgetType .. "_" .. (tblConcat(keys, ".") or "") - opts.args[key] = {name = name, desc = desc, type = widgetType, order = order or self:Order(), disabled = disabled} - opts.args[key].set = function(info, val) Addon:SetOption(val, unpack(keys)) end - opts.args[key].get = function(info) return Addon:GetOption(unpack(keys)) end - return opts.args[key] - end - - function GUI:CreateHeader(opts, name) - return self:CreateEntry(opts, self:Order(), name, nil, "header", nil, self:Order(0)) - end - - function GUI:CreateDescription(opts, desc, fontSize) - local option = self:CreateEntry(opts, self:Order(), desc, nil, "description", nil, self:Order(0)) - option.fontSize = fontSize or "large" - return option - end - function GUI:CreateDivider(opts, count, fontSize) - for i = 1, count or 1 do - self:CreateDescription(opts, " ", fontSize or "small") - end - end - function GUI:CreateNewline(opts) - return self:CreateDescription(opts, " ", fontSize or "small") - end - - function GUI:CreateToggle(opts, keys, name, desc, disabled) - return self:CreateEntry(opts, keys, name, desc, "toggle", disabled) - end - - function GUI:CreateReverseToggle(opts, keys, name, desc, disabled) - local option = self:CreateEntry(opts, keys, name, desc, "toggle", disabled) - local set, get = option.set, option.get - option.set = function(info, val) set(info, not val) end - option.get = function(info) return not get() end - return option - end - - function GUI:CreateSelect(opts, keys, name, desc, values, sorting, disabled) - local option = self:CreateEntry(opts, keys, name, desc, "select", disabled) - option.values = values - option.sorting = sorting - option.style = "dropdown" - return option - end - - function GUI:CreateMultiSelect(opts, keys, name, desc, values, disabled) - local option = self:CreateEntry(opts, keys, name, desc, "multiselect", disabled) - option.values = values - return option - end - - function GUI:CreateRange(opts, keys, name, desc, min, max, step, disabled) - local option = self:CreateEntry(opts, keys, name, desc, "range", disabled) - option.min = min - option.max = max - option.step = step - return option - end - - function GUI:CreateInput(opts, keys, name, desc, multiline, disabled) - local option = self:CreateEntry(opts, keys, name, desc, "input", disabled) - option.multiline = multiline - return option - end - - function GUI:CreateColor(opts, keys, name, desc, disabled) - local option = self:CreateEntry(opts, keys, name, desc, "color", disabled) - option.set = function(info, r, g, b) Addon:SetOption(Addon:ConvertColorFromBlizzard(r, g, b), unpack(keys)) end - option.get = function(info) return Addon:ConvertColorToBlizzard(Addon:GetOption(unpack(keys))) end - return option - end - - function GUI:CreateExecute(opts, key, name, desc, func, disabled) - local option = self:CreateEntry(opts, key, name, desc, "execute", disabled) - option.func = func - return option - end - - function GUI:CreateGroup(opts, key, name, desc, groupType, disabled) - key = "group_" .. links[key] - opts.args[key] = {name = name, desc = desc, type = "group", childGroups = groupType, args = {}, order = self:Order(), disabled = disabled} - return opts.args[key] - end - - function GUI:CreateGroupBox(opts, name) - local key = "group_" .. self:Order(-1) - opts.args[key] = {name = name, type = "group", args = {}, order = self:Order(), inline = true} - return opts.args[key] - end - - function GUI:CreateGroupTop(name, groupType, disabled) - return {name = name, type = "group", childGroups = groupType, args = {}, order = self:Order(), disabled = disabled} - end -end - - - - - diff --git a/Config/OptionsTables.lua b/Config/OptionsTables.lua index 51befa6..70b98ee 100644 --- a/Config/OptionsTables.lua +++ b/Config/OptionsTables.lua @@ -8,38 +8,32 @@ local L = LibStub("AceLocale-3.0"):GetLocale(ADDON_NAME) - --- █████╗ ██████╗ ██████╗ ██████╗ ███╗ ██╗ ██████╗ ██████╗ ████████╗██╗ ██████╗ ███╗ ██╗███████╗ --- ██╔══██╗██╔══██╗██╔══██╗██╔═══██╗████╗ ██║ ██╔═══██╗██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║██╔════╝ --- ███████║██║ ██║██║ ██║██║ ██║██╔██╗ ██║ ██║ ██║██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║███████╗ --- ██╔══██║██║ ██║██║ ██║██║ ██║██║╚██╗██║ ██║ ██║██╔═══╝ ██║ ██║██║ ██║██║╚██╗██║╚════██║ --- ██║ ██║██████╔╝██████╔╝╚██████╔╝██║ ╚████║ ╚██████╔╝██║ ██║ ██║╚██████╔╝██║ ╚████║███████║ --- ╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝ - -function Addon:MakeAddonOptions(chatCmd) - local title = format("%s v%s (/%s)", ADDON_NAME, tostring(self:GetOption"version"), chatCmd) - local title = format("%s", ADDON_NAME) - local panel = self:CreateOptionsCategory(nil, function() +-- ██████╗ ███████╗███╗ ██╗███████╗██████╗ █████╗ ██╗ ██████╗ ██████╗ ████████╗██╗ ██████╗ ███╗ ██╗███████╗ +-- ██╔════╝ ██╔════╝████╗ ██║██╔════╝██╔══██╗██╔══██╗██║ ██╔═══██╗██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║██╔════╝ +-- ██║ ███╗█████╗ ██╔██╗ ██║█████╗ ██████╔╝███████║██║ ██║ ██║██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║███████╗ +-- ██║ ██║██╔══╝ ██║╚██╗██║██╔══╝ ██╔══██╗██╔══██║██║ ██║ ██║██╔═══╝ ██║ ██║██║ ██║██║╚██╗██║╚════██║ +-- ╚██████╔╝███████╗██║ ╚████║███████╗██║ ██║██║ ██║███████╗ ╚██████╔╝██║ ██║ ██║╚██████╔╝██║ ╚████║███████║ +-- ╚═════╝ ╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝ + +local function MakeGeneralOptions(opts) + local self = Addon + local GUI = self.GUI + local opts = GUI:CreateGroup(opts, ADDON_NAME, ADDON_NAME) + - local GUI = self.GUI:ResetOrder() - local opts = GUI:CreateGroupTop(title, "tab") + GUI:SetDBType"Global" + local option = GUI:CreateToggle(opts, {"UsePersistentStorage"}, L["Use Persistent Storage"], L["If enabled, cache will be stored on logout. This may slightly increase loading time.|n|nIf disabled, cache will be rebuilt during each session. This will result in dramatically more cache misses."]) - GUI:CreateNewline(opts) - local option = GUI:CreateToggle(opts, {"..", "global", "UsePersistentStorage"}, L["Use Persistent Storage"], L["If enabled, cache will be stored on logout. This may slightly increase loading time.|n|nIf disabled, cache will be rebuilt during each session. This will result in dramatically more cache misses."]) - option.set = function(info, val) self:SetGlobalOption(val, "UsePersistentStorage") end - option.get = function(info) return self:GetGlobalOption"UsePersistentStorage" end + GUI:ResetDBType() return opts - end) - function self:OpenAddonOptions() return self:OpenConfig(panel) end end - -- ██████╗ ███████╗██████╗ ██╗ ██╗ ██████╗ ██████╗ ██████╗ ████████╗██╗ ██████╗ ███╗ ██╗███████╗ -- ██╔══██╗██╔════╝██╔══██╗██║ ██║██╔════╝ ██╔═══██╗██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║██╔════╝ -- ██║ ██║█████╗ ██████╔╝██║ ██║██║ ███╗ ██║ ██║██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║███████╗ @@ -47,14 +41,16 @@ end -- ██████╔╝███████╗██████╔╝╚██████╔╝╚██████╔╝ ╚██████╔╝██║ ██║ ██║╚██████╔╝██║ ╚████║███████║ -- ╚═════╝ ╚══════╝╚═════╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝ -function Addon:MakeDebugOptions(categoryName, chatCmd, arg1, ...) - local title = format("%s v%s > %s (/%s %s)", ADDON_NAME, tostring(self:GetOption"version"), categoryName, chatCmd, arg1) - local title = format("%s", categoryName) - local panel = self:CreateOptionsCategory(categoryName, function() +local function MakeDebugOptions(opts, categoryName) + local self = Addon + local GUI = self.GUI + + if not self:IsDebugEnabled() then return end - local GUI = self.GUI:ResetOrder() - local opts = GUI:CreateGroupTop(title, "tab") + GUI:SetDBType"Global" + local opts = GUI:CreateGroup(opts, categoryName, categoryName) + GUI:CreateExecute(opts, "reload", self.L["Reload UI"], nil, ReloadUI) -- Enable do @@ -64,7 +60,12 @@ function Addon:MakeDebugOptions(categoryName, chatCmd, arg1, ...) local opts = GUI:CreateGroupBox(opts, "Debug") GUI:CreateToggle(opts, {"debug"}, self.L["Enable"]) GUI:CreateNewline(opts) - GUI:CreateExecute(opts, "reload", self.L["Reload UI"], nil, ReloadUI) + + GUI:CreateToggle(opts, {"debugShowLuaErrors"}, self.L["Display Lua Errors"], nil).width = 2 + GUI:CreateNewline(opts) + + local disabled = not self:GetGlobalOption"debugShowLuaErrors" + GUI:CreateToggle(opts, {"debugShowLuaWarnings"}, self.L["Lua Warning"], nil, disabled).width = 2 end end @@ -72,7 +73,7 @@ function Addon:MakeDebugOptions(categoryName, chatCmd, arg1, ...) do local opts = GUI:CreateGroup(opts, GUI:Order(), "Output") - local disabled = not self:GetOption"debug" + local disabled = not self:GetGlobalOption"debug" do local opts = GUI:CreateGroupBox(opts, "Suppress All") @@ -83,16 +84,93 @@ function Addon:MakeDebugOptions(categoryName, chatCmd, arg1, ...) do local opts = GUI:CreateGroupBox(opts, "Message Types") - local disabled = disabled or self:GetOption("debugOutput", "suppressAll") + local disabled = disabled or self:GetGlobalOption("debugOutput", "suppressAll") - GUI:CreateToggle(opts, {"debugOutput", "luaError"}, "Lua Error", nil, disabled).width = 2 + for i, data in ipairs{ + {"optionSet", "Option Set"}, + } do + if i ~= 1 then + GUI:CreateNewline(opts) + end + GUI:CreateToggle(opts, {"debugOutput", data[1]}, data[2], nil, disabled).width = 2 + end end end + GUI:ResetDBType() + return opts - end) - local function OpenOptions() return self:OpenConfig(panel) end - for _, arg in ipairs{arg1, ...} do - self.chatArgs[arg] = OpenOptions +end + + + + + +-- █████╗ ██████╗ ██████╗ ██████╗ ███╗ ██╗ ██████╗ ██████╗ ████████╗██╗ ██████╗ ███╗ ██╗███████╗ +-- ██╔══██╗██╔══██╗██╔══██╗██╔═══██╗████╗ ██║ ██╔═══██╗██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║██╔════╝ +-- ███████║██║ ██║██║ ██║██║ ██║██╔██╗ ██║ ██║ ██║██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║███████╗ +-- ██╔══██║██║ ██║██║ ██║██║ ██║██║╚██╗██║ ██║ ██║██╔═══╝ ██║ ██║██║ ██║██║╚██╗██║╚════██║ +-- ██║ ██║██████╔╝██████╔╝╚██████╔╝██║ ╚████║ ╚██████╔╝██║ ██║ ██║╚██████╔╝██║ ╚████║███████║ +-- ╚═╝ ╚═╝╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝ + +function Addon:MakeAddonOptions(chatCmd) + local title = format("%s v%s (/%s)", ADDON_NAME, tostring(self:GetOption"version"), chatCmd) + + local sections = {} + for _, data in ipairs{ + {MakeGeneralOptions, nil}, + {MakeDebugOptions, self.L["Debug"], "debug", "db"}, + } do + + local func = data[1] + local name = data[2] + local args = {unpack(data, 3)} + + tinsert(sections, function(opts) return func(opts, name) end) + + local function OpenOptions() return self:OpenConfig(name) end + if name == self.L["Debug"] then + local OpenOptions_Old = OpenOptions + OpenOptions = function(...) + if not self:GetGlobalOption"debug" then + self:SetGlobalOption(true, "debug") + self:Debug("Debug mode enabled") + end + return OpenOptions_Old(...) + end + end + + for _, arg in ipairs(args) do + self:RegisterChatArgAliases(arg, OpenOptions) + end end + + self.AceConfig:RegisterOptionsTable(ADDON_NAME, function() + local GUI = self.GUI:ResetOrder() + local opts = GUI:CreateOpts(title, "tab") + + for _, func in ipairs(sections) do + func(opts) + end + + return opts + end) + + self.AceConfigDialog:SetDefaultSize(ADDON_NAME, 700, 800) end + + +function Addon:MakeBlizzardOptions(chatCmd) + local title = format("%s v%s (/%s)", ADDON_NAME, tostring(self:GetOption"version"), chatCmd) + local panel = self:CreateBlizzardOptionsCategory(function() + local GUI = self.GUI:ResetOrder() + local opts = GUI:CreateOpts(title, "tab") + + GUI:CreateExecute(opts, "key", ADDON_NAME .. " " .. self.L["Options"], nil, function() + self:OpenConfig(ADDON_NAME) + self:CloseBlizzardConfig() + end) + + return opts + end) +end \ No newline at end of file diff --git a/Config/Settings.lua b/Config/Settings.lua index aa24612..d497aa9 100644 --- a/Config/Settings.lua +++ b/Config/Settings.lua @@ -9,19 +9,22 @@ local Addon = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME) function Addon:MakeDefaultOptions() local fakeAddon = { db = { - profile = { + profile = {}, + + global = { + UsePersistentStorage = true, + -- Debug options debug = false, + + debugShowLuaErrors = true, + debugShowLuaWarnings = true, debugOutput = { ["*"] = false, }, }, - - global = { - UsePersistentStorage = true, - }, }, } return fakeAddon.db diff --git a/Config/_config.xml b/Config/_config.xml index 0982105..e697f04 100644 --- a/Config/_config.xml +++ b/Config/_config.xml @@ -1,6 +1,5 @@