-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitialize.lua
More file actions
342 lines (305 loc) · 11 KB
/
Copy pathInitialize.lua
File metadata and controls
342 lines (305 loc) · 11 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
local addonName, addon = ...
local EUI = _G.EllesmereUI
if not EUI or not EUI.Lite then
local frame = _G.DEFAULT_CHAT_FRAME
if frame then
frame:AddMessage("EllesmereUI_WindTools requires EllesmereUI to load first.")
end
return
end
local CreateCompatE = addon.CreateCompatE
local InstallModuleSystem = addon.InstallModuleSystem
if not CreateCompatE or not InstallModuleSystem then
local frame = _G.DEFAULT_CHAT_FRAME
if frame then
frame:AddMessage("EllesmereUI_WindTools compat layer did not load.")
end
return
end
local xpcall = xpcall
local geterrorhandler = geterrorhandler
local function SafeCall(func, ...)
if type(func) == "function" then
local args = {...}
return xpcall(function()
return func(unpack(args))
end, function(err)
return geterrorhandler()(err)
end)
end
end
local function L(text)
return EUI.L and EUI.L(text) or text
end
local E = CreateCompatE()
local W = EUI.Lite.NewAddon(addonName)
InstallModuleSystem(W)
local V, P, G = {}, {}, {}
addon[1] = W
addon[2] = {}
addon[3] = E
addon[4] = setmetatable({}, {
__index = function(_, key)
return L(key)
end
})
addon[5] = V
addon[6] = P
addon[7] = G
local F = addon[2]
F.GetCompatibleFont = function(name)
return name
end
_WindTools = addon
_G.WindTools = addon
W.Title = "WindTools"
W.DisplayVersion = C_AddOns.GetAddOnMetadata(addonName, "X-Version") or "0.2.1"
W.Version = W.DisplayVersion
W.Utilities = W.Utilities or {}
W.CompatibleFont = false
W.Modules.Misc = W:NewModule("Misc")
W.Modules.Skins = W:NewModule("Skins")
W.Modules.Tooltips = W:NewModule("Tooltips")
W.Modules.MoveFrames = W:NewModule("MoveFrames")
W:NewModule("QuestProgress")
E:AddLib("OpenRaid", "LibOpenRaid-1.0")
E:AddLib("ObjectiveProgressWT", "LibObjectiveProgress-WT")
E:AddLib("RangeCheck", "LibRangeCheck-3.0")
E:AddLib("Keystone", "LibKeystone")
E:AddLib("WTItemEnchant", "LibItemEnchant-WT")
local db
local function InitDB()
if db then
return
end
db = EUI.Lite.NewDB("EllesmereUI_WindToolsDB", {
profile = P
})
E.db.WT = db.profile
_G.WindToolsGlobalDB = _G.WindToolsGlobalDB or {}
if EUI.Lite.DeepMergeDefaults then
EUI.Lite.DeepMergeDefaults(_G.WindToolsGlobalDB, G)
end
E.global.WT = _G.WindToolsGlobalDB
_G.WindToolsPrivateDB = _G.WindToolsPrivateDB or {}
if EUI.Lite.DeepMergeDefaults then
EUI.Lite.DeepMergeDefaults(_G.WindToolsPrivateDB, V)
end
E.private.WT = _G.WindToolsPrivateDB
W.db = db
end
local function Print(...)
if EUI.Print then
EUI.Print("|cff0cd29f[WindTools]|r", ...)
end
end
addon.Print = Print
-------------------------------------------------------------------------------
-- Options page definitions
-- PAGE_GROUPS: ordered list of pages; each page aggregates one or more
-- category builders registered via addon.RegisterOptionBuilder.
-- A page renders by walking its categories and calling each builder with
-- (parent, y, title). Builders return the new y offset.
--
-- CATEGORY_TITLES: maps the internal category key (used in
-- RegisterOptionBuilder) to the human-readable title passed as the third
-- argument to each builder. Builders use this title for section headers.
-------------------------------------------------------------------------------
local CATEGORY_TITLES = {
information = "Information",
misc = "Misc",
announcement = "Announcement",
item = "Item",
extraItemsBar = "Extra Items Bar",
combat = "Combat",
social = "Social",
maps = "Maps",
quest = "Quest",
tooltips = "Tooltips",
unitFrames = "Unit Frames",
skins = "Skins",
advanced = "Advanced",
}
-- All pages and their category mappings (flat, used by BuildPage).
local PAGE_GROUPS = {{
page = "Information", categories = {"information"}
}, {
page = "General", categories = {"misc"}
}, {
page = "Loot & Trade", categories = {"item"}
}, {
page = "Display", categories = {"item"}
}, {
page = "Inspect", categories = {"item"}
}, {
page = "Item Level", categories = {"item"}
}, {
page = "Merchant", categories = {"item"}
}, {
page = "Extra Items Bar", categories = {"extraItemsBar"}
}, {
page = "Announcement", categories = {"announcement"}
}, {
page = "Raid Markers", categories = {"combat"}
}, {
page = "Combat Alert", categories = {"combat"}
}, {
page = "Quick Tools", categories = {"combat"}
}, {
page = "Damage Meter", categories = {"combat"}
}, {
page = "Chat Bar", categories = {"social"}
}, {
page = "Smart Tab", categories = {"social"}
}, {
page = "Super Tracker", categories = {"maps"}
}, {
page = "Minimap", categories = {"maps"}
}, {
page = "World Map", categories = {"maps"}
}, {
page = "Difficulty & Events", categories = {"maps"}
}, {
page = "Objective Tracker", categories = {"quest"}
}, {
page = "Automation", categories = {"quest"}
}, {
page = "Progress & Turn In", categories = {"quest"}
}, {
page = "Achievement", categories = {"quest"}
}, {
page = "Tooltip Info", categories = {"tooltips"}
}, {
page = "Progression", categories = {"tooltips"}
}, {
page = "Keystone & Group Info", categories = {"tooltips"}
}, {
page = "Tooltip Advanced", categories = {"tooltips"}
}, {
page = "Quick Focus", categories = {"unitFrames"}
}, {
page = "Absorb", categories = {"unitFrames"}
}, {
page = "Name Clip", categories = {"unitFrames"}
}, {
page = "Skins", categories = {"skins"}
}, {
page = "Advanced", categories = {"advanced"}
}}
local PAGE_NAMES = {}
local GROUP_BY_PAGE = {}
for _, group in ipairs(PAGE_GROUPS) do
PAGE_NAMES[#PAGE_NAMES + 1] = group.page
GROUP_BY_PAGE[group.page] = group
end
-------------------------------------------------------------------------------
-- Sidebar layout
-- Mirrors EllesmereUI's sidebar structure: special buttons at the top,
-- then a search bar, then grouped page rows with accent-colored headers.
-------------------------------------------------------------------------------
-- Pages shown as full-width special buttons above the search bar.
local SPECIAL_PAGES = { "Information", "Advanced" }
-- Grouped pages shown below the search bar. Each group has a label and an
-- ordered list of page names.
local SIDEBAR_GROUPS = {
{ label = "General", pages = { "General" } },
{ label = "Items", pages = { "Loot & Trade", "Display", "Inspect", "Item Level", "Merchant", "Extra Items Bar" } },
{ label = "Combat", pages = { "Raid Markers", "Combat Alert", "Quick Tools", "Damage Meter" } },
{ label = "Social", pages = { "Chat Bar", "Smart Tab", "Announcement" } },
{ label = "Maps", pages = { "Super Tracker", "Minimap", "World Map", "Difficulty & Events" } },
{ label = "Quest", pages = { "Objective Tracker", "Automation", "Progress & Turn In", "Achievement" } },
{ label = "UI Tweaks", pages = { "Tooltip Info", "Progression", "Keystone & Group Info", "Tooltip Advanced", "Quick Focus", "Absorb", "Name Clip", "Skins" } },
}
-- Build a single options page by invoking its registered category builders.
-- pageName is passed as the 4th arg (subPage) so dispatch builders can
-- route to the correct section. Returns total content height.
local function BuildPage(pageName, parent, yOffset)
local y = yOffset or -6
local group = GROUP_BY_PAGE[pageName]
if not group then
return math.abs(y) + 30
end
local Widgets = EllesmereUI.Widgets
for index, categoryKey in ipairs(group.categories or {}) do
local builder = addon.OptionBuilders and addon.OptionBuilders[categoryKey]
if builder then
if index > 1 then
local _, sh = Widgets:Spacer(parent, y, 8)
y = y - sh
end
local title = CATEGORY_TITLES[categoryKey] or categoryKey
local ok, newY = xpcall(function()
return builder(parent, y, title, pageName)
end, function(err)
return geterrorhandler()(err)
end)
if ok and type(newY) == "number" then
y = newY
end
end
end
return math.abs(y) + 30
end
-- Expose options metadata + builders to the rest of the addon (Panel.lua).
addon.OptionPageGroups = PAGE_GROUPS
addon.OptionPageNames = PAGE_NAMES
addon.OptionGroupByPage = GROUP_BY_PAGE
addon.SpecialPages = SPECIAL_PAGES
addon.SidebarGroups = SIDEBAR_GROUPS
addon.BuildOptionsPage = BuildPage
addon.InitDB = InitDB
addon.GetDB = function() return db end
-------------------------------------------------------------------------------
-- Blizzard Settings panel entry (Options -> AddOns)
-- Registers a canvas-layout category with a single button that opens the
-- standalone WindTools options panel. Uses the same Settings API as
-- EllesmereUI's own entry.
-------------------------------------------------------------------------------
local function RegisterBlizzardOptionsEntry()
if not Settings or not Settings.RegisterCanvasLayoutCategory then return end
local panel = CreateFrame("Frame")
panel.name = L("WindTools") .. " for EllesmereUI"
local btn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
btn:SetSize(220, 30)
btn:SetPoint("CENTER", panel, "CENTER", 0, 0)
btn:SetText("Open WindTools")
btn:SetScript("OnClick", function()
-- Close Blizzard settings first to avoid overlapping windows
if SettingsPanel and SettingsPanel:IsShown() then
HideUIPanel(SettingsPanel)
end
C_Timer.After(0, function()
if W.ToggleOptions then
W:ToggleOptions()
end
end)
end)
local category = Settings.RegisterCanvasLayoutCategory(panel, panel.name)
Settings.RegisterAddOnCategory(category)
end
function W:OnProfileChanged()
self:UpdateModules()
end
W:RegisterEvent("PLAYER_LOGIN", function()
InitDB()
W.initialized = true
SafeCall(W.InitializeModules, W)
RegisterBlizzardOptionsEntry()
if db and db.profile.core and db.profile.core.loginMessage then
Print("loaded for EllesmereUI.")
end
end)
-------------------------------------------------------------------------------
-- AddOn Compartment + slash command entry
-- Both open the standalone WindTools options panel (W:ToggleOptions).
-- The panel is implemented in Options/Panel.lua and lazily built on first
-- open, so it is safe to reference here even before that file has loaded
-- its body (the function is looked up at call time via W:ToggleOptions).
-------------------------------------------------------------------------------
_G.WindTools_OnAddonCompartmentClick = function()
if W.ToggleOptions then
W:ToggleOptions()
else
Print("options panel is not available.")
end
end