Skip to content

Commit

Permalink
Add options UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Numynum committed Sep 30, 2022
1 parent a1b1876 commit 676c23e
Show file tree
Hide file tree
Showing 6 changed files with 309 additions and 47 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/libs/*/
7 changes: 7 additions & 0 deletions .pkgmeta
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions TalentTreeTweaks.toc
Original file line number Diff line number Diff line change
Expand Up @@ -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
162 changes: 115 additions & 47 deletions core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 8 additions & 0 deletions libs/embeds.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/ ..\FrameXML\UI.xsd">
<Script file="LibStub\LibStub.lua"/>
<Include file="AceAddon-3.0\AceAddon-3.0.xml"/>
<Include file="AceConfig-3.0\AceConfig-3.0.xml"/>
<Include file="AceConsole-3.0\AceConsole-3.0.xml"/>
<Include file="AceHook-3.0\AceHook-3.0.xml"/>
<Include file="AceEvent-3.0\AceEvent-3.0.xml"/>
</Ui>
174 changes: 174 additions & 0 deletions modules/tooltipIds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
local _, TTT = ...;
--- @type TalentTreeTweaks_Main
local Main = TTT.Main;

local Module = Main:NewModule('TooltipIds');

function Module:OnInitialize()
EventRegistry:RegisterCallback("TalentDisplay.TooltipCreated", self.OnTalentTooltipCreated, self)
EventRegistry:RegisterCallback("ProfessionSpecs.SpecPerkEntered", self.OnProfessionPerkEntered, self)
EventRegistry:RegisterCallback("ProfessionSpecs.SpecPathEntered", self.OnProfessionPathEntered, self)
end

function Module:OnEnable()
self.enabled = true
end

function Module:OnDisable()
self.enabled = false
end

function Module:GetDescription()
return 'Adds spell id and more to the various talent tree tooltips.'
end

function Module:GetName()
return 'Tooltip IDs'
end

local defaultDb = {
talentTooltip = {
enabled = true,
nodeId = true,
entryId = false,
definitionId = false,
spellId = true,
},
professionTooltip = {
enabled = true,
nodeId = true,
entryId = false,
definitionId = false,
spellId = true,
},
}

function Module:GetOptions(defaultOptionsTable, db)
self.db = db;
for k, v in pairs(defaultDb) do
if db[k] == nil then
db[k] = v;
end
end

local order = 5;
local function increment() order = order + 1; return order; end;

local getter = function(info, key)
return self.db[info[#info]][key];
end;
local setter = function(info, key, value)
self.db[info[#info]][key] = value;
end;

defaultOptionsTable.args.talentTooltip = {
order = increment(),
type = 'multiselect',
name = 'Talent Tooltip',
desc = 'Toggles for the Talent Tooltips.',
values = {
enabled = 'Enable Talent Tooltip',
nodeId = 'Enable Node ID',
entryId = 'Enable Entry ID',
definitionId = 'Enable Definition ID',
spellId = 'Enable Spell ID',
},
get = getter,
set = setter,
};
defaultOptionsTable.args.professionTooltip = {
order = increment(),
type = 'multiselect',
name = 'Talent Tooltip',
desc = 'Toggles for the Professions Tooltips.',
values = {
enabled = 'Enable Professions Tooltip',
nodeId = 'Enable Node ID',
entryId = 'Enable Entry ID',
definitionId = 'Enable Definition ID',
spellId = 'Enable Spell ID',
},
get = getter,
set = setter,
};

return defaultOptionsTable;
end

function Module:AlreadyAdded(textLine, tooltip)
if textLine == nil then
return false
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
end

function Module: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)
end
tooltip:Show()
end

function Module:AddGenericTraitButtonTooltips(button, tooltip, settings)
if settings.entryId then
self:AddItemToTooltip('EntryId', button:GetEntryID(), tooltip)
end
if settings.spellId then
self:AddItemToTooltip('SpellId', button:GetSpellID(), tooltip)
end
if settings.definitionId then
self:AddItemToTooltip('DefinitionId', button.GetDefinitionID and button:GetDefinitionID() or nil, tooltip)
end
end

function Module:OnTalentTooltipCreated(button, tooltip)
if not self.enabled or not self.db.talentTooltip.enabled then return end
local settings = self.db.talentTooltip
if settings.nodeId then
self:AddItemToTooltip('NodeId', button.GetNodeID and button:GetNodeID() or button:GetNodeInfo().ID, tooltip)
end
self:AddGenericTraitButtonTooltips(button, tooltip, settings)
end

function Module:OnProfessionPerkEntered(perkId)
if not self.enabled or not self.db.professionTooltip.enabled then return end

local tooltip = GameTooltip
if not tooltip:IsShown() then return end
local button = tooltip:GetOwner()
if not button or button.perkID ~= perkId then return end

local settings = self.db.professionTooltip
if settings.nodeId then
self:AddItemToTooltip('Perk NodeId', perkId, tooltip)
end
self:AddGenericTraitButtonTooltips(button, tooltip, settings)
end

function Module:OnProfessionPathEntered(nodeId)
if not self.enabled or not self.db.professionTooltip.enabled then return end

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

local settings = self.db.professionTooltip
if settings.nodeId then
self:AddItemToTooltip('Path NodeId', nodeId, tooltip)
end
self:AddGenericTraitButtonTooltips(button, tooltip, settings)
end

0 comments on commit 676c23e

Please sign in to comment.