-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.lua
More file actions
581 lines (559 loc) · 23.9 KB
/
options.lua
File metadata and controls
581 lines (559 loc) · 23.9 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
--- @class DialogKeyNS
local ns = select(2, ...)
local issecretvalue = issecretvalue or function(v) return false end
ns.configPanelName = 'DialogKey - Numy Edition'
--- @class DialogKeyDB
ns.defaultOptions = {
--- @type string[]
keys = {
"SPACE",
},
ignoreDisabledButtons = false,
ignoreWithModifier = false,
showGlow = true,
--- @type table<string, boolean> # [text] = true
dialogBlacklist = {},
--- @type table<string, number> # [frameName] = priority
customFrames = {},
numKeysForGossip = true,
riskyNumKeysForGossip = true,
numKeysForQuestRewards = true,
dontClickSummons = true,
dontClickDuels = true,
dontClickRevives = true,
dontClickReleases = true,
dontAcceptInvite = true,
dontAcceptAbandonVote = true,
dontAcceptVoteKick = true,
dontAcceptInstanceLocks = false,
useSoulstoneRez = true,
handleCraftingOrders = true,
handlePlayerChoice = true,
numKeysForPlayerChoice = true,
handleSpecFrame = true,
postAuctions = false,
ignoreInProgressQuests = true,
}
--- @param dialogKey DialogKey
function ns:InitDB(dialogKey)
for k, v in pairs(self.defaultOptions) do
if dialogKey.db[k] == nil then dialogKey.db[k] = v end
end
if select(2, next(dialogKey.db.customFrames)) == true then -- unordered list
local i = 1
for k, _ in pairs(dialogKey.db.customFrames) do
dialogKey.db.customFrames[k] = i
i = i + 1
end
end
-- check for gaps
self:GuardAgainstGaps()
end
function ns:GuardAgainstGaps()
local db = self.Core.db
local count = 0
for _, _ in pairs(db.customFrames) do
count = count + 1
end
ns.orderedCustomFrames = tInvert(db.customFrames)
local orderedCount = 0
for _, _ in ipairs(ns.orderedCustomFrames) do -- ipairs stops at the first gap
orderedCount = orderedCount + 1
end
if count ~= orderedCount then
for i = 1, count do
if ns.orderedCustomFrames[i] == nil then
local j = i + 1
while j < i+100 do -- exit after 100, to avoid infinite loops in case of issues
if ns.orderedCustomFrames[j] then
ns.orderedCustomFrames[i] = ns.orderedCustomFrames[j]
ns.orderedCustomFrames[j] = nil
db.customFrames[ns.orderedCustomFrames[i]] = i
break
end
j = j + 1
end
end
end
ns.orderedCustomFrames = tInvert(db.customFrames)
end
end
function ns:RemoveFromWatchlist(frameName)
local db = self.Core.db
local index = db.customFrames[frameName]
if not index then return end
tremove(self.orderedCustomFrames, index)
db.customFrames[frameName] = nil
for i = index, #self.orderedCustomFrames do
db.customFrames[self.orderedCustomFrames[i]] = i
end
self:RegisterOptions()
end
function ns:AddToWatchlist(frameName)
local db = self.Core.db
if db.customFrames[frameName] then return end
tinsert(self.orderedCustomFrames, frameName)
db.customFrames[frameName] = #self.orderedCustomFrames
self:RegisterOptions()
end
local arrowNext = C_Texture.GetAtlasInfo('common-dropdown-icon-next') or error('Failed to find atlas for Next icon')
local arrowBack = C_Texture.GetAtlasInfo('common-dropdown-icon-back') or error('Failed to find atlas for Back icon')
local cross = C_Texture.GetAtlasInfo('Radial_Wheel_Icon_Close') or C_Texture.GetAtlasInfo('XMarksTheSpot') or error('Failed to find atlas for cross icon')
local search = C_Texture.GetAtlasInfo('common-search-magnifyingglass') or error('Failed to find atlas for Search icon')
local width_multiplier = 170
-- only want this for toggles
local function wrapName(name)
return "|cffffd100" .. name .. "|r"
end
------- hack to allow tooltips to work on nameless execute icons
local MAGIC_TOOLTIP_TEXTS = {
up = 'DialogKey_Numy_MagicTooltipUp',
down = 'DialogKey_Numy_MagicTooltipDown',
remove = 'DialogKey_Numy_MagicTooltipRemove',
glow = 'DialogKey_Numy_MagicTooltipGlow',
}
do
local lastSetOwnerCall
local ACDTooltip = LibStub("AceConfigDialog-3.0").tooltip
hooksecurefunc(ACDTooltip, 'SetOwner', function(_, ...)
lastSetOwnerCall = { ... }
end)
--- @param tooltip GameTooltip
hooksecurefunc(ACDTooltip, 'AddLine', function(tooltip, text, r, g, b, wrap)
if issecretvalue(text) then return end
local title, desc
if text == MAGIC_TOOLTIP_TEXTS.up then
title = "Move up"
desc = "Move the frame higher in the priority list"
elseif text == MAGIC_TOOLTIP_TEXTS.down then
title = "Move down"
desc = "Move the frame lower in the priority list"
elseif text == MAGIC_TOOLTIP_TEXTS.remove then
title = "Remove"
desc = "Remove the frame from the custom watchlist"
elseif text == MAGIC_TOOLTIP_TEXTS.glow then
title = "Find"
desc = "Show a short glow effect around the frame to make it easier to find"
end
if title then
-- setting text to an empty string seems to clear the owner and effectively resets the tooltip :/
tooltip:SetOwner(unpack(lastSetOwnerCall))
tooltip:SetText(title, 1, .82, 0, true)
tooltip:AddLine(desc, r, g, b, wrap)
end
end)
end
local initialized = false
function ns:RegisterOptions()
if not initialized then
initialized = true
LibStub("AceConfig-3.0"):RegisterOptionsTable(self.configPanelName, function() return self:GetOptionsTable() end)
local _, categoryID = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(self.configPanelName)
self.categoryID = categoryID
else
LibStub("AceConfigRegistry-3.0"):NotifyChange(self.configPanelName)
end
end
function ns:OpenConfig()
if C_SettingsUtil and C_SettingsUtil.OpenSettingsPanel and InCombatLockdown() then
LibStub("AceConfigDialog-3.0"):Open(self.configPanelName);
return;
end
Settings.OpenToCategory(self.categoryID)
end
function ns:GetOptionsTable()
local db = self.Core.db
local function optionSetter(info, val) db[info[#info]] = val end
local function optionGetter(info) return db[info[#info]] end
local function swapWatchlistFrames(index1, index2)
local frame1 = self.orderedCustomFrames[index1]
local frame2 = self.orderedCustomFrames[index2]
if not frame1 or not frame2 then return end
self.orderedCustomFrames[index1] = frame2
self.orderedCustomFrames[index2] = frame1
db.customFrames[frame1] = index2
db.customFrames[frame2] = index1
self:RegisterOptions()
end
local increment = CreateCounter()
local options = {
type = "group",
set = optionSetter,
get = optionGetter,
name = self.configPanelName,
args = {
header1 = {
order = increment(),
name = "Primary Keybinds",
type = "header",
},
key1 = {
order = increment(),
name = "",
type = "keybinding",
set = (function(_, val) db.keys[1] = val end),
get = (function(_) return db.keys[1] end),
},
key2 = {
order = increment(),
name = "",
type = "keybinding",
set = (function(_, val) db.keys[2] = val end),
get = (function(_) return db.keys[2] end),
},
header2 = {
order = increment(),
name = "Options",
type = "header",
},
generalGroup = {
order = increment(),
name = "General",
desc = "Basic Options for personal preferences",
type = "group",
args = {
showGlow = {
order = increment(),
name = wrapName("Enable Glow"),
desc = "Show the glow effect when DialogKey clicks a button",
descStyle = "inline", width = "full", type = "toggle",
},
ignoreWithModifier = {
order = increment(),
name = wrapName("Ignore DialogKey with Modifiers"),
desc = "Disable DialogKey while any modifier key is held (Shift, Alt, Ctrl)",
descStyle = "inline", width = "full", type = "toggle",
},
ignoreDisabledButtons = {
order = increment(),
name = wrapName("Ignore Disabled Buttons"),
desc = "Don't allow DialogKey to click on disabled (greyed out) buttons",
descStyle = "inline", width = "full", type = "toggle",
},
ignoreInProgressQuests = {
order = increment(),
name = wrapName("Ignore In-Progress Quests"),
desc = "Gossip options for in-progress quests are ignored, and only completed or unaccepted quests are clicked",
descStyle = "inline", width = "full", type = "toggle",
},
numKeysForGossip = {
order = increment(),
name = wrapName("Number keys for Gossip"),
desc = "Use the number keys (1 -> 0) to select Gossip options or Quests from an NPC dialog window",
descStyle = "inline", width = "full", type = "toggle",
},
riskyNumKeysForGossip = {
order = increment(),
name = wrapName("Number keys for Gossip - Risky"),
disabled = function() return not db.numKeysForGossip end,
desc = "Ensure scrollbar is enabled if the text becomes too long. This may taint objective frame buttons. If you encounter issues, just disable this option.",
descStyle = "inline", width = "full", type = "toggle",
},
numKeysForQuestRewards = {
order = increment(),
name = wrapName("Number keys for Quest Rewards"),
desc = "Use the number keys (1 -> 0) to select Quest rewards when multiple are available",
descStyle = "inline", width = "full", type = "toggle",
},
postAuctions = {
order = increment(),
name = wrapName("Post Auctions"),
desc = "Post Auctions",
descStyle = "inline", width = "full", type = "toggle",
},
handleCraftingOrders = {
order = increment(),
name = wrapName("Crafting Orders"),
desc = "Handle Crafting Orders: Start them, Craft them, Complete them",
descStyle = "inline", width = "full", type = "toggle",
hidden = WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE,
},
handlePlayerChoice = {
order = increment(),
name = wrapName("Keybind for Player Choice"),
desc = "Use keybinding to select the first Player Choice option",
descStyle = "inline", width = "full", type = "toggle",
hidden = not C_AddOns.DoesAddOnExist("Blizzard_PlayerChoice"),
},
numKeysForPlayerChoice = {
order = increment(),
name = wrapName("Number keys for Player Choice"),
desc = "Use the number keys (1 -> 0) to select Player Choices",
descStyle = "inline", width = "full", type = "toggle",
hidden = not C_AddOns.DoesAddOnExist("Blizzard_PlayerChoice"),
},
handleSpecFrame = {
order = increment(),
name = wrapName(SPECIALIZATION),
desc = "Use the number keys (1 -> 4) to select a specialization while the specialization tab is open",
descStyle = "inline", width = "full", type = "toggle",
hidden = WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE,
},
},
},
watchlistGroup = {
order = increment(),
name = "Custom Watchlist",
desc = "List of custom buttons for DialogKey to attempt to click",
type = "group",
args = {
desc = {
order = increment(),
name = [[
You can add custom frames to "click" with your keybinds here.
Simply enter the name of the frame to handle, or hover over the frame and write "/dialogkey add" to add the frame under your mouse.
If you have trouble finding the name, try "/fstack", pressing ALT until the frame you want is highlighted. If there are random letters and numbers in the name (e.g. "GameMenuFrame.2722d8f518"), then the frame cannot be clicked by DialogKey.
]],
type = "description",
fontSize = "medium",
},
addFrame = {
order = increment(),
type = "input",
name = "Add a Frame to watch",
width = "full",
set = function(_, value)
self:AddToWatchlist(value)
end,
},
priority = self:CreateCustomFramesPriorityListOptions(increment(), swapWatchlistFrames),
},
},
popupBlacklistGroup = {
order = increment(),
name = "Popup Blacklist",
desc = "List of popup dialogs for DialogKey to completely ignore",
type = "group",
args = {
dontAcceptInvite = {
order = increment(),
name = wrapName("Don't Accept Group Invites"),
desc = "Don't allow DialogKey to accept Raid/Party Invitations",
width = 1.2, type = "toggle",
},
dontAcceptInstanceLocks = {
order = increment(),
name = wrapName("Don't Accept Instance Lockouts"),
desc = "Don't allow DialogKey to accept/\"save\" Instance Lockouts",
width = 1.2, type = "toggle",
},
dontAcceptAbandonVote = {
order = increment(),
name = wrapName("Don't Accept M+ Abandon Key Votes"),
desc = "Don't allow DialogKey to vote to abandon a m+ key",
width = 1.2, type = "toggle",
},
dontAcceptVoteKick = {
order = increment(),
name = wrapName("Don't Accept Vote Kicks"),
desc = "Don't allow DialogKey to vote in Vote Kicks",
width = 1.2, type = "toggle",
},
dontClickSummons = {
order = increment(),
name = wrapName("Don't Accept Summons"),
desc = "Don't allow DialogKey to accept Summon Requests",
width = 1.2, type = "toggle",
},
dontClickDuels = {
order = increment(),
name = wrapName("Don't Accept Duels"),
desc = "Don't allow DialogKey to accept Duel Requests",
width = 1.2, type = "toggle",
},
dontClickRevives = {
order = increment(),
name = wrapName("Don't Accept Revives"),
desc = "Don't allow DialogKey to accept Resurrections",
width = 1.2, type = "toggle",
},
useSoulstoneRez = {
order = increment(),
name = wrapName("Use Class-specific Revive"),
desc = "Use Soulstone/Ankh/etc. resurrection option when one is available and a normal/battle resurrection is not\n\nThis option |cffff0000ignores|r the |cffffd100Don't Accept Revives|r option!",
width = 1.2, type = "toggle",
},
dontClickReleases = {
order = increment(),
name = wrapName("Don't Release Spirit"),
desc = "Don't allow DialogKey to Release Spirit",
width = 1.2, type = "toggle",
},
desc = {
order = increment(),
name = [[
Here you can create a custom list of popups that DialogKey should ignore.
Simply add (part of) the text that appears in the popup, and DialogKey will ignore it.
Alternatively, you can add the technical name of the popup, which you can find with /dump StaticPopup1.which while the popup is open.
]],
type = "description",
fontSize = "medium",
},
addText = {
order = increment(),
type = "input",
name = "Add a text to ignore",
width = "full",
set = function(_, value)
db.dialogBlacklist[value] = true
end,
},
removeText = {
order = increment(),
type = "select",
style = "dropdown",
name = "Remove Ignored Text",
width = "full",
values = function()
local tempTable = {}
if not next(db.dialogBlacklist) then
return { [''] = ' * No texts are currently ignored *' }
end
for text, _ in pairs(db.dialogBlacklist) do
tempTable[text] = text
end
return tempTable
end,
get = function(_, _) return false end,
set = function(_, index, ...)
db.dialogBlacklist[index] = nil
end,
},
listOfTexts = {
order = increment(),
type = "description",
name = function()
local text = wrapName("Currently ignored texts:") .. "\n"
for k, _ in pairs(db.dialogBlacklist) do
text = text .. " - " .. k .. "\n"
end
return text
end,
},
},
},
},
}
return options
end
function ns:CreateCustomFramesPriorityListOptions(order, swapWatchlistFrames)
local increment = CreateCounter()
local options = {
order = order,
name = "Manage currently watched frames",
type = "group",
inline = true,
args = {
header = {
order = increment(),
name = "If multiple frames are visible, the one highest on the list will be clicked.",
type = "description",
width = "full",
},
},
};
if #self.orderedCustomFrames == 0 then
options.args.noFrames = {
order = increment(),
name = " * No frames are currently being watched * ",
type = "description",
fontSize = "medium",
width = "full",
};
return options;
end
local numberOfIcons = 4;
local iconWidth = 26;
local groupWidth = 405; -- depends on whether there's a scrollbar
for i, frame in ipairs(self.orderedCustomFrames) do
options.args["glow" .. i] = {
order = increment(),
name = "",
desc = MAGIC_TOOLTIP_TEXTS.glow,
disabled = function() return not self.Core:GetFrameByName(frame) end,
type = "execute",
func = function()
local frameRef = self.Core:GetFrameByName(frame)
if not frameRef then return end
self.Core:Glow(frameRef, 0.25, true)
end,
image = search.file,
imageWidth = 16,
imageHeight = 16,
imageCoords = {
search.leftTexCoord, search.rightTexCoord, search.topTexCoord, search.bottomTexCoord,
},
width = iconWidth / width_multiplier,
};
options.args["name" .. i] = {
order = increment(),
name = frame,
type = "description",
fontSize = "medium",
width = (groupWidth - iconWidth * numberOfIcons) / width_multiplier,
};
options.args["up" .. i] = {
order = increment(),
name = "",
desc = MAGIC_TOOLTIP_TEXTS.up,
type = "execute",
disabled = function() return i == 1 end,
func = function()
swapWatchlistFrames(i, i - 1)
end,
image = arrowBack.file,
imageWidth = 16,
imageHeight = 16,
imageCoords = {
arrowBack.leftTexCoord, arrowBack.bottomTexCoord, -- UL
arrowBack.rightTexCoord, arrowBack.bottomTexCoord, -- LL
arrowBack.leftTexCoord, arrowBack.topTexCoord, -- UR
arrowBack.rightTexCoord, arrowBack.topTexCoord, -- LR
},
width = iconWidth / width_multiplier,
};
options.args["down" .. i] = {
order = increment(),
type = "execute",
name = "",
desc = MAGIC_TOOLTIP_TEXTS.down,
disabled = function() return i == #self.orderedCustomFrames end,
func = function()
swapWatchlistFrames(i, i + 1)
end,
image = arrowNext.file,
imageWidth = 16,
imageHeight = 16,
width = iconWidth / width_multiplier,
imageCoords = {
arrowNext.leftTexCoord, arrowNext.bottomTexCoord, -- UL
arrowNext.rightTexCoord, arrowNext.bottomTexCoord, -- LL
arrowNext.leftTexCoord, arrowNext.topTexCoord, -- UR
arrowNext.rightTexCoord, arrowNext.topTexCoord, -- LR
},
};
options.args["delete" .. i] = {
order = increment(),
name = "",
desc = MAGIC_TOOLTIP_TEXTS.remove,
type = "execute",
func = function()
self:RemoveFromWatchlist(frame)
end,
image = cross.file,
imageWidth = 16,
imageHeight = 16,
imageCoords = {
cross.leftTexCoord, cross.rightTexCoord, cross.topTexCoord, cross.bottomTexCoord,
},
width = iconWidth / width_multiplier,
};
options.args["spacer" .. i] = {
order = increment(),
name = "",
type = "description",
width = "full",
};
end
return options;
end