-
Notifications
You must be signed in to change notification settings - Fork 3
/
core.lua
174 lines (157 loc) · 5.79 KB
/
core.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
local name, TTT = ...;
--@debug@
_G.TalentTreeTweaks = TTT;
if not _G.TTT then _G.TTT = TTT; end
--@end-debug@
--- @class TalentTreeTweaks_Main: AceAddon, AceConsole-3.0, AceHook-3.0, AceEvent-3.0
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;
TTT.L = LibStub('AceLocale-3.0'):GetLocale(name);
local L = TTT.L;
function Main:OnInitialize()
if NumyProfiler then
NumyProfiler:WrapModules(name, 'Main', self);
NumyProfiler:WrapModules(name, 'Util', TTT.Util);
for moduleName, module in self:IterateModules() do
NumyProfiler:WrapModules(name, moduleName, module);
end
end
TalentTreeTweaksDB = TalentTreeTweaksDB or {};
self.db = TalentTreeTweaksDB;
self.version = C_AddOns.GetAddOnMetadata(name, "Version") or "";
self:InitDefaults();
TTT.Util:OnInitialize();
for moduleName, module in self:IterateModules() do
--- @type TalentTreeTweaks_Module
local module = module;
if self.db.modules[moduleName] == false then
module:Disable();
end
end
self:InitConfig();
self:RegisterChatCommand('ttt', function() self:OpenConfig(); end);
end
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
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 = L['Various tweaks and improvements to the talent tree UI'],
childGroups = 'tab',
args = {
version = {
order = increment(),
type = 'description',
name = string.format(L['Version: %s'], self.version),
},
modules = {
order = increment(),
type = 'group',
name = L['Modules'],
childGroups = 'tree',
args = {
desc = {
order = increment(),
type = 'description',
name = L['This addon consists of a number of modules, each of which can be enabled or disabled, to fine-tune your experience.'],
},
},
}
}
};
local function GetFormattedModuleName(moduleName, disabledSuffix)
--- @type TalentTreeTweaks_Module
local module = self:GetModule(moduleName);
local prettyName = module.GetName and module:GetName() or moduleName;
if not self:IsModuleEnabled(moduleName) then
return RED_FONT_COLOR:WrapTextInColorCode(prettyName .. (disabledSuffix or ''));
end
return prettyName;
end
local defaultModuleOptions = {
type = 'group',
name = function(info)
local moduleName = info[#info];
return GetFormattedModuleName(moduleName);
end,
desc = function(info)
local moduleName = info[#info];
if not self:IsModuleEnabled(moduleName) then
return RED_FONT_COLOR:WrapTextInColorCode(ADDON_DISABLED);
end
end,
args = {
name = {
order = 1,
type = 'header',
name = function(info)
local moduleName = info[#info - 1];
return GetFormattedModuleName(moduleName);
end,
},
description = {
order = 2,
type = 'description',
name = function(info)
--- @type TalentTreeTweaks_Module
local module = self: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 = L['Enable this module'],
type = 'toggle',
get = function(info) return self:IsModuleEnabled(info[#info - 1]); end,
set = function(info, enabled) self:SetModuleState(info[#info - 1], enabled); end,
},
},
};
for moduleName, module in self:IterateModules() do
--- @type TalentTreeTweaks_Module
local module = module;
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.order = increment();
self.options.args.modules.args[moduleName] = moduleOptions;
end
self.configCategory = 'Talent Tree Tweaks';
LibStub('AceConfig-3.0'):RegisterOptionsTable(self.configCategory, self.options);
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(self.configCategory);
end
function Main:OpenConfig()
Settings.OpenToCategory(self.configCategory);
end
function Main:SetModuleState(moduleName, enabled)
if enabled then
self:EnableModule(moduleName);
else
self:DisableModule(moduleName);
end
self.db.modules[moduleName] = enabled;
end
function Main:IsModuleEnabled(moduleName)
local module = self:GetModule(moduleName);
return module and module:IsEnabled() or false;
end
function Main:IsTalentTreeViewerEnabled()
return C_AddOns.GetAddOnEnableState(TalentViewerLoader and TalentViewerLoader:GetLodAddonName() or 'TalentTreeViewer', UnitName('player')) == 2;
end