From 676c23eb1ebeb543cb3ff474054cafef22135ce0 Mon Sep 17 00:00:00 2001 From: Mark W Date: Fri, 30 Sep 2022 18:50:51 +0200 Subject: [PATCH] Add options UI --- .gitignore | 1 + .pkgmeta | 7 ++ TalentTreeTweaks.toc | 4 + core.lua | 162 +++++++++++++++++++++++++++----------- libs/embeds.xml | 8 ++ modules/tooltipIds.lua | 174 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 309 insertions(+), 47 deletions(-) create mode 100644 .gitignore create mode 100644 .pkgmeta create mode 100644 libs/embeds.xml create mode 100644 modules/tooltipIds.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..86d937e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/libs/*/ diff --git a/.pkgmeta b/.pkgmeta new file mode 100644 index 0000000..63f4b3a --- /dev/null +++ b/.pkgmeta @@ -0,0 +1,7 @@ +externals: + libs/LibStub: https://repos.wowace.com/wow/ace3/trunk/LibStub + libs/AceAddon-3.0: https://repos.wowace.com/wow/ace3/trunk/AceAddon-3.0 + libs/AceConfig-3.0: https://repos.wowace.com/wow/ace3/trunk/AceConfig-3.0 + libs/AceConsole-3.0: https://repos.wowace.com/wow/ace3/trunk/AceConsole-3.0 + libs/AceHook-3.0: https://repos.wowace.com/wow/ace3/trunk/AceHook-3.0 + libs/AceEvent-3.0: https://repos.wowace.com/wow/ace3/trunk/AceEvent-3.0 diff --git a/TalentTreeTweaks.toc b/TalentTreeTweaks.toc index f8e41ef..ab9c739 100644 --- a/TalentTreeTweaks.toc +++ b/TalentTreeTweaks.toc @@ -4,5 +4,9 @@ ## Notes: Various improvements and addition to the Dragonflight talent tree UI ## Version: @project-version@ ## X-Curse-Project-ID: 678792 +## SavedVariables: TalentTreeTweaksDB + +libs\embeds.xml core.lua +modules\tooltipIds.lua diff --git a/core.lua b/core.lua index 9cfdb75..afd8247 100644 --- a/core.lua +++ b/core.lua @@ -5,65 +5,133 @@ _G.TalentTreeTweaks = TTT; if not _G.TTT then _G.TTT = TTT; end --@end-debug@ ---- @class Main -local Main = {} +--- @class TalentTreeTweaks_Main +local Main = LibStub('AceAddon-3.0'):NewAddon(name, 'AceConsole-3.0', 'AceHook-3.0', 'AceEvent-3.0'); if not Main then return; end TTT.Main = Main; -function Main:AlreadyAdded(textLine, tooltip) - if textLine == nil then - return false +function Main:OnInitialize() + TalentTreeTweaksDB = TalentTreeTweaksDB or {}; + self.db = TalentTreeTweaksDB; + self.version = GetAddOnMetadata(name, "Version") or ""; + self:InitDefaults(); + for moduleName, module in self:IterateModules() do + if self.db.modules[moduleName] == false then + module:Disable(); + end end - for i = 1,15 do - local tooltipFrame = _G[tooltip:GetName() .. "TextLeft" .. i] - local textRight = _G[tooltip:GetName().."TextRight"..i] - local text, right - if tooltipFrame then text = tooltipFrame:GetText() end - if text and string.find(text, textLine, 1, true) then return true end - if textRight then right = textRight:GetText() end - if right and string.find(right, textLine, 1, true) then return true end - end + self:InitConfig(); + + self:RegisterChatCommand('ttt', function() self:OpenConfig(); end); end -function Main:AddItemToTooltip(idName, value, tooltip) - if value == nil then - return - end - local text = "|cFFEE6161" .. idName .. "|r " .. value - if(not self:AlreadyAdded(text, tooltip)) then - tooltip:AddLine(text) +function Main:InitDefaults() + local defaults = { + modules = {}, + moduleDb = {}, + }; + + for key, value in pairs(defaults) do + if self.db[key] == nil then + self.db[key] = value; + end end - tooltip:Show() end -function Main:AddGenericTraitButtonTooltips(button, tooltip) - self:AddItemToTooltip('EntryId', button:GetEntryID(), tooltip) - self:AddItemToTooltip('SpellId', button:GetSpellID(), tooltip) - self:AddItemToTooltip('DefinitionId', button.GetDefinitionID and button:GetDefinitionID() or nil, tooltip) -end +function Main:InitConfig() + local count = 1; + local function increment() count = count + 1; return count end; + self.options = { + type = 'group', + name = 'Talent Tree Tweaks', + desc = 'Various tweaks and improvements to the talent tree UI', + childGroups = 'tab', + args = { + version = { + order = increment(), + type = 'description', + name = 'Version: ' .. self.version, + }, + modules = { + order = increment(), + type = 'group', + name = 'Modules', + childGroups = 'tree', + args = { + desc = { + order = increment(), + type = 'description', + name = 'This addon consists of a number of modules, each of which can be enabled or disabled, to fine-tune your experience.', + }, + }, + } + } + }; + local defaultModuleOptions = { + type = 'group', + name = function(info) + return info[#info - 1]; + end, + args = { + name = { + order = 1, + type = 'header', + name = function(info) + return info.options.args.modules.args[info[#info - 1]].name; + end, + }, + description = { + order = 2, + type = 'description', + name = function(info) + local module = Main:GetModule(info[#info - 1]); + return module.GetDescription and module:GetDescription() or ''; + end, + hidden = function(info) + return '' == info.option.name(info) + end, + }, + enable = { + order = 3, + name = 'Enable', + desc = 'Enable this module', + type = 'toggle', + get = function(info) return Main:IsModuleEnabled(info[#info - 1]); end, + set = function(info, enabled) Main:SetModuleState(info[#info - 1], enabled); end, + }, + }, + }; + for moduleName, module in self:IterateModules() do + local copy = CopyTable(defaultModuleOptions); + self.db.moduleDb[moduleName] = self.db.moduleDb[moduleName] or {}; + local moduleOptions = module.GetOptions and module:GetOptions(copy, self.db.moduleDb[moduleName]) or copy; + moduleOptions.name = module.GetName and module:GetName() or moduleName; + moduleOptions.order = increment(); + self.options.args.modules.args[moduleName] = moduleOptions; + end -EventRegistry:RegisterCallback("TalentDisplay.TooltipCreated", function(self, button, tooltip) - self:AddItemToTooltip('NodeId', button.GetNodeID and button:GetNodeID() or button:GetNodeInfo().ID, tooltip) - self:AddGenericTraitButtonTooltips(button, tooltip) -end, Main) + self.configCategory = 'Talent Tree Tweaks'; + LibStub('AceConfig-3.0'):RegisterOptionsTable(self.configCategory, self.options); + LibStub("AceConfigDialog-3.0"):AddToBlizOptions(self.configCategory); +end -EventRegistry:RegisterCallback("ProfessionSpecs.SpecPerkEntered", function(self, perkId) - local tooltip = GameTooltip - if not tooltip:IsShown() then return end - local button = tooltip:GetOwner() - if not button or button.perkID ~= perkId then return end +function Main:OpenConfig() + InterfaceOptionsFrame_OpenToCategory(self.configCategory); + InterfaceOptionsFrame_OpenToCategory(self.configCategory); +end - self:AddItemToTooltip('Perk NodeId', perkId, tooltip) - self:AddGenericTraitButtonTooltips(button, tooltip) -end, Main) +function Main:SetModuleState(moduleName, enabled) + if enabled then + self:EnableModule(moduleName); + else + self:DisableModule(moduleName); + end + self.db.modules[moduleName] = enabled; +end -EventRegistry:RegisterCallback("ProfessionSpecs.SpecPathEntered", function(self, nodeId) - local tooltip = GameTooltip - if not tooltip:IsShown() then return end - local button = tooltip:GetOwner() - if not button or not button.nodeInfo or button.nodeInfo.ID ~= nodeId then return end +function Main:IsModuleEnabled(moduleName) + local module = self:GetModule(moduleName); - self:AddItemToTooltip('Path NodeId', nodeId, tooltip) - self:AddGenericTraitButtonTooltips(button, tooltip) -end, Main) + return module and module:IsEnabled() or false; +end diff --git a/libs/embeds.xml b/libs/embeds.xml new file mode 100644 index 0000000..e643ba9 --- /dev/null +++ b/libs/embeds.xml @@ -0,0 +1,8 @@ + +