-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.lua
More file actions
679 lines (549 loc) · 21.2 KB
/
Copy pathoptions.lua
File metadata and controls
679 lines (549 loc) · 21.2 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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
local folderName, addon = ...
local L = LibStub("AceAddon-3.0"):GetAddon(folderName)
-- For the options menu.
local appName = "Screen Manager"
-- A local variable for saved variable ScreenManager_config for easier access.
local config
local CONFIG_DEFAULTS = {
fadeInAfterLoading = false,
fadeInAfterLoading_notInCombat = true,
fadeInAfterLoading_startAfter = 0.2,
fadeInAfterLoading_fadeTime = 1.2,
fullScreenToggle_windowResize = true,
monitorToggle_windowResize = true,
monitorScalings = {},
resolutionProfileList = {},
}
local currentResolutionProfileId = nil -- Maybe in main.lua?
local selectedResolutionProfileId = nil
local editingResolutionProfileId = nil
local tmpEditingResolutionProfile = {}
local function SelectResolutionProfile()
if currentResolutionProfileId then
selectedResolutionProfileId = currentResolutionProfileId
else
selectedResolutionProfileId = next(config.resolutionProfileList)
end
end
local function NewResolutionProfile()
tinsert(config.resolutionProfileList, {name = "New Profle"})
return #config.resolutionProfileList
end
local function StartEditingResolutionProfile(id)
tmpEditingResolutionProfile = {}
for k, v in pairs(config.resolutionProfileList[id]) do
tmpEditingResolutionProfile[k] = v
end
editingResolutionProfileId = id
end
local function DeleteResolutionProfile(id)
config.resolutionProfileList[id] = nil
editingResolutionProfileId = nil
SelectResolutionProfile()
end
local function SaveEditingResolutionProfile(id)
for k, v in pairs(tmpEditingResolutionProfile) do
if v ~= config.resolutionProfileList[id][k] then
config.resolutionProfileList[id][k] = v
end
end
editingResolutionProfileId = nil
end
local function CancelEditingResolutionProfile()
tmpEditingResolutionProfile = {}
editingResolutionProfileId = nil
end
local function GetResolutionProfileList()
-- TODO: Meaningful sorting.
local listToReturn = {}
for k, v in pairs(config.resolutionProfileList) do
listToReturn[k] = v["name"]
end
return listToReturn
end
local currentlyEditedCommand = nil
local keyPressFrame = CreateFrame("Frame")
local KeyPressedFunction = function(self, key)
if key == "ESCAPE" then
StaticPopup_Hide("SCREEN_MANAGER_KEYBIND_PROMPT")
return
end
if key == "LCTRL" or key == "RCTRL" or key == "LALT" or key == "RALT" or key == "LSHIFT" or key == "RSHIFT" then
return
end
if IsShiftKeyDown() then
key = "SHIFT-" .. key
end
if IsControlKeyDown() then
key = "CTRL-" .. key
end
if IsAltKeyDown() then
key = "ALT-" .. key
end
-- Check last key bind.
local lastKey = GetBindingKey(currentlyEditedCommand)
if lastKey and lastKey == key then
StaticPopup_Hide("SCREEN_MANAGER_KEYBIND_PROMPT")
return
end
-- Check if key is already taken. GetBindingAction() returns "" if key has no action.
local command = GetBindingAction(key)
if command ~= "" and command ~= currentlyEditedCommand then
local data = {
["lastKey"] = lastKey,
["key"] = key,
["command"] = currentlyEditedCommand
}
StaticPopup_Hide("SCREEN_MANAGER_KEYBIND_PROMPT")
StaticPopup_Show("SCREEN_MANAGER_KEYBIND_CONFIRM", key .. " is already assigned to \"" .. GetBindingName(command) .. "\". Do you really want to assign it to \"" .. GetBindingName(data.command) .. "\" instead?", _, data)
return
end
-- Assign new binding.
if lastKey then
SetBinding(lastKey)
end
SetBinding(key)
SetBinding(key, currentlyEditedCommand)
StaticPopup_Hide("SCREEN_MANAGER_KEYBIND_PROMPT")
LibStub("AceConfigRegistry-3.0"):NotifyChange(appName)
end
-- Cover the remaining options and make them unclickable while our keybind prompt is open.
local coverOptionsFrame = CreateFrame("Frame")
coverOptionsFrame:SetFrameStrata("HIGH")
coverOptionsFrame:SetFrameLevel(10000)
coverOptionsFrame.blackTexture = coverOptionsFrame:CreateTexture(nil, "ARTWORK")
coverOptionsFrame.blackTexture:SetAllPoints()
coverOptionsFrame.blackTexture:SetColorTexture(0, 0, 0, 0.75)
coverOptionsFrame:EnableMouse(true)
local function ShowCoverOptionsFrame()
if SettingsPanel and SettingsPanel:IsShown() then
coverOptionsFrame:ClearAllPoints()
coverOptionsFrame:SetPoint("TOPLEFT", SettingsPanel, "TOPLEFT", 3, -1)
coverOptionsFrame:SetPoint("BOTTOMRIGHT", SettingsPanel, "BOTTOMRIGHT", 0, 1)
coverOptionsFrame:Show()
end
end
StaticPopupDialogs["SCREEN_MANAGER_KEYBIND_PROMPT"] = {
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3, -- avoid some UI taint, see https://authors.curseforge.com/forums/world-of-warcraft/general-chat/lua-code-discussion/226040-how-to-reduce-chance-of-ui-taint-from
text = "%s",
OnShow = function (_, data)
currentlyEditedCommand = data.command
-- print(currentlyEditedCommand)
ShowCoverOptionsFrame()
keyPressFrame:SetScript("OnKeyDown", KeyPressedFunction)
end,
OnHide = function()
currentlyEditedCommand = nil
keyPressFrame:SetScript("OnKeyDown", nil)
coverOptionsFrame:Hide()
end,
button1 = "Cancel",
OnButton1 = function() end,
}
StaticPopupDialogs["SCREEN_MANAGER_KEYBIND_CONFIRM"] = {
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3, -- avoid some UI taint, see https://authors.curseforge.com/forums/world-of-warcraft/general-chat/lua-code-discussion/226040-how-to-reduce-chance-of-ui-taint-from
text = "%s",
OnShow = function ()
ShowCoverOptionsFrame()
end,
OnHide = function()
coverOptionsFrame:Hide()
end,
-- So that we can have different functions for each button.
selectCallbackByIndex = true,
button1 = "Yes",
OnButton1 = function(_, data)
if data.lastKey then
SetBinding(data.lastKey)
end
SetBinding(data.key)
SetBinding(data.key, data.command)
LibStub("AceConfigRegistry-3.0"):NotifyChange(appName)
end,
button2 = "No",
OnButton2 = function() end,
}
local fullScreenToggleBindingName = "SCREEN_MANAGER_FULLSCREEN_TOGGLE"
local monitorToggleBindingName = "SCREEN_MANAGER_MONITOR_TOGGLE"
-- For console messages in main.lua.
addon.fullScreenToggleBindingName = fullScreenToggleBindingName
-- If I ever do i18n for this, it would be here.
_G["BINDING_NAME_" .. fullScreenToggleBindingName] = "Fullscreen Toggle"
_G["BINDING_NAME_" .. monitorToggleBindingName] = "Monitor Toggle"
local optionsTable = {
type = "group",
args = {
n01 = {order = 0.1, type = "description", name = " ",},
resolutionBasedLayoutsGroup = {
order = 1,
type = "group",
name = "Screen Resolution-Based HUD Layouts",
inline = true,
args = {
resolutionProfileSelect = {
order = 1,
type = "select",
name = "Select a Profile",
width = 2.3,
desc = "|cFF00FF00Currently active profile is green.|r",
get =
function()
return selectedResolutionProfileId
end,
set =
function(_, newValue)
selectedResolutionProfileId = newValue
editingResolutionProfileId = nil
end,
values =
function()
return GetResolutionProfileList()
end,
disabled = function() return selectedResolutionProfileId ~= nil and selectedResolutionProfileId == editingResolutionProfileId end,
},
blank11 = {order = 1.1, type = "description", name = " ", width = 0.1,},
resolutionProfileEditButton = {
order = 2,
type = "execute",
name = "Edit",
width = 0.5,
func =
function()
StartEditingResolutionProfile(selectedResolutionProfileId)
end,
disabled = function() return selectedResolutionProfileId == nil or selectedResolutionProfileId == editingResolutionProfileId end,
},
blank21 = {order = 2.1, type = "description", name = " ", width = 0.1,},
resolutionProfileNewButton = {
order = 3,
type = "execute",
name = "New",
width = 0.5,
func =
function()
selectedResolutionProfileId = NewResolutionProfile()
-- LibStub("AceConfigRegistry-3.0"):NotifyChange(appName)
end,
disabled = function() return selectedResolutionProfileId ~= nil and selectedResolutionProfileId == editingResolutionProfileId end,
},
resolutionProfileProperties = {
order = 4,
type = "group",
name =
function()
if selectedResolutionProfileId ~= nil and selectedResolutionProfileId == editingResolutionProfileId then
return "Editing Profile Properties"
else
return "Profile Properties "
end
end,
inline = true,
hidden =
function()
return selectedResolutionProfileId == nil
end,
args = {
resolutionProfileName = {
order = 1,
type = "input",
name = "Profile Name",
width = 2.3,
get =
function()
if editingResolutionProfileId == nil and selectedResolutionProfileId ~= nil and config.resolutionProfileList[selectedResolutionProfileId].name then
return config.resolutionProfileList[selectedResolutionProfileId].name
elseif editingResolutionProfileId ~= nil and tmpEditingResolutionProfile.name then
return tmpEditingResolutionProfile.name
else
return ""
end
end,
set = function(_, newValue) tmpEditingResolutionProfile.name = newValue end,
disabled = function() return editingResolutionProfileId == nil or selectedResolutionProfileId ~= editingResolutionProfileId end,
},
n11 = {order = 1.1, type = "description", name = " ", hidden = function() return editingResolutionProfileId == nil or selectedResolutionProfileId ~= editingResolutionProfileId end},
resolutionProfileSaveButton = {
order = 2,
type = "execute",
name = "Save",
width = 1,
func =
function()
SaveEditingResolutionProfile(editingResolutionProfileId)
-- LibStub("AceConfigRegistry-3.0"):NotifyChange(appName)
end,
hidden = function() return editingResolutionProfileId == nil or selectedResolutionProfileId ~= editingResolutionProfileId end,
},
blank21 = {order = 2.1, type = "description", name = " ", width = 0.1, hidden = function() return editingResolutionProfileId == nil or selectedResolutionProfileId ~= editingResolutionProfileId end},
resolutionProfileCancelButton = {
order = 3,
type = "execute",
name = "Cancel",
width = 1,
func =
function()
CancelEditingResolutionProfile()
-- LibStub("AceConfigRegistry-3.0"):NotifyChange(appName)
end,
hidden = function() return editingResolutionProfileId == nil or selectedResolutionProfileId ~= editingResolutionProfileId end,
},
blank31 = {order = 3.1, type = "description", name = " ", width = 0.1, hidden = function() return editingResolutionProfileId == nil or selectedResolutionProfileId ~= editingResolutionProfileId end},
resolutionProfileDeleteButton = {
order = 4,
type = "execute",
name = "Delete",
width = 1,
func =
function()
DeleteResolutionProfile(editingResolutionProfileId)
-- LibStub("AceConfigRegistry-3.0"):NotifyChange(appName)
end,
hidden = function() return editingResolutionProfileId == nil or selectedResolutionProfileId ~= editingResolutionProfileId end,
},
},
},
},
},
n11 = {order = 1.1, type = "description", name = " ",},
fullScreenToggleGroup = {
type = "group",
name = _G["BINDING_NAME_SCREEN_MANAGER_FULLSCREEN_TOGGLE"],
order = 2,
inline = true,
args = {
fullScreenToggleSpace = {order = 0, type = "description", name = " ", width = 0.04,},
fullScreenToggleLabel = {
order = 1,
type = "description",
name =
function()
local key = GetBindingKey(fullScreenToggleBindingName)
if key then
return "Assigned Hotkey: |cffffd200" .. key .. "|r"
else
return "Assigned Hotkey: |cff808080Not Bound|r"
end
end,
width = 1.5 - 0.04,
},
fullScreenToggleAssignButton = {
order = 2,
type = "execute",
name = "New Key Bind",
desc = "Assign a new hotkey binding.",
width = 0.9,
func =
function()
local data = { ["command"] = fullScreenToggleBindingName }
StaticPopup_Show("SCREEN_MANAGER_KEYBIND_PROMPT", SETTINGS_BIND_KEY_TO_COMMAND_OR_CANCEL:format(GetBindingName(fullScreenToggleBindingName), GetBindingText("ESCAPE")), _, data)
end,
},
blank21 = {order = 2.1, type = "description", name = " ", width = 0.1,},
fullScreenToggleUnassignButton = {
order = 3,
type = "execute",
name = "Unbind",
desc = "Unassign the current binding.",
width = 0.9,
func =
function()
SetBinding(GetBindingKey(fullScreenToggleBindingName))
end,
disabled =
function()
if GetBindingKey(fullScreenToggleBindingName) then return false else return true end
end,
},
fullScreenToggleWindowResizeToggle = {
order = 4,
type = "toggle",
name = "Resize Window to Match Monitor",
desc = "When the game window is put into windowed mode, automatically set it to an aspect ratio matching the monitor.",
width = "full",
get = function() return config.fullScreenToggle_windowResize end,
set = function(_, newValue) config.fullScreenToggle_windowResize = newValue end,
},
},
},
n21 = {order = 2.1, type = "description", name = " ",},
monitorToggleGroup = {
type = "group",
name = _G["BINDING_NAME_SCREEN_MANAGER_MONITOR_TOGGLE"],
order = 3,
inline = true,
args = {
monitorToggleSpace = {order = 0, type = "description", name = " ", width = 0.04,},
monitorToggleLabel = {
order = 1,
type = "description",
name =
function()
local key = GetBindingKey(monitorToggleBindingName)
if key then
return "Assigned Hotkey: |cffffd200" .. key .. "|r"
else
return "Assigned Hotkey: |cff808080Not Bound|r"
end
end,
width = 1.5 - 0.04,
},
monitorToggleAssignButton = {
order = 2,
type = "execute",
name = "New Key Bind",
desc = "Assign a new hotkey binding.",
width = 0.9,
func =
function()
local data = { ["command"] = monitorToggleBindingName }
StaticPopup_Show("SCREEN_MANAGER_KEYBIND_PROMPT", SETTINGS_BIND_KEY_TO_COMMAND_OR_CANCEL:format(GetBindingName(monitorToggleBindingName), GetBindingText("ESCAPE")), _, data)
end,
},
blank21 = {order = 2.1, type = "description", name = " ", width = 0.1,},
monitorToggleUnassignButton = {
order = 3,
type = "execute",
name = "Unbind",
desc = "Unassign the current binding.",
width = 0.9,
func =
function()
SetBinding(GetBindingKey(monitorToggleBindingName))
end,
disabled =
function()
if GetBindingKey(monitorToggleBindingName) then return false else return true end
end,
},
monitorToggleWindowResizeToggle = {
order = 4,
type = "toggle",
name = "Resize Window to Match Monitor",
desc = "When the windowed game window is moved to another monitor, automatically set it to an aspect ratio matching the monitor.",
width = "full",
get = function() return config.monitorToggle_windowResize end,
set = function(_, newValue) config.monitorToggle_windowResize = newValue end,
},
},
},
n31 = {order = 3.1, type = "description", name = " ",},
fadeInAfterLoadingGroup = {
type = "group",
name = "Fade In After Loading Screen",
order = 4,
inline = true,
args = {
fadeInAfterLoadingToggle = {
order = 1,
type = "toggle",
name = "Enable",
desc = "Gradually fade in from black after the loading screen.",
width = 1,
get = function() return config.fadeInAfterLoading end,
set = function(_, newValue) config.fadeInAfterLoading = newValue end,
},
fadeInAfterLoadingNotInCombatToggle = {
order = 2,
type = "toggle",
name = "Disable In Combat",
desc = "When you are in combat, directly show the game after the loading screen without fade in.",
width = 1,
disabled = function() return not config.fadeInAfterLoading end,
get = function() return config.fadeInAfterLoading_notInCombat end,
set = function(_, newValue) config.fadeInAfterLoading_notInCombat = newValue end,
},
n21 = {order = 2.1, type = "description", name = " ",},
fadeInAfterLoadingStartAfter = {
order = 3,
type = "range",
name = "Seconds Before Fading Starts",
desc = "How long the screen stays black after the loading screen before the fade in starts.",
min = 0,
max = 5,
step = .1,
width = 1.5,
disabled = function() return not config.fadeInAfterLoading end,
get = function() return config.fadeInAfterLoading_startAfter end,
set = function(_, newValue) config.fadeInAfterLoading_startAfter = newValue end,
},
blank31 = {order = 3.1, type = "description", name = " ", width = 0.1,},
fadeInAfterLoadingFadeTime = {
order = 4,
type = "range",
name = "Seconds to Fade In",
desc = "How long the fade in takes to complete.",
min = 0,
max = 5,
step = .1,
width = 1.5,
disabled = function() return not config.fadeInAfterLoading end,
get = function() return config.fadeInAfterLoading_fadeTime end,
set = function(_, newValue) config.fadeInAfterLoading_fadeTime = newValue end,
},
n41 = {order = 4.1, type = "description", name = " ",},
fadeInAfterLoadingTest = {
order = 5,
type = "execute",
name = "Test",
desc = "Test what the fade in looks like.",
width = "normal",
disabled = function() return not config.fadeInAfterLoading end,
func = addon.FadeIn,
},
blank51 = {order = 5.1, type = "description", name = " ", width = 0.1,},
fadeInAfterLoadingRestoreDefaults = {
order = 6,
type = "execute",
name = "Restore Defaults",
desc = "Restore settings to the preference of the addon developer.",
width = "normal",
disabled =
function()
if not config.fadeInAfterLoading then return true end
if config.fadeInAfterLoading_notInCombat == CONFIG_DEFAULTS.fadeInAfterLoading_notInCombat and
config.fadeInAfterLoading_startAfter == CONFIG_DEFAULTS.fadeInAfterLoading_startAfter and
config.fadeInAfterLoading_fadeTime == CONFIG_DEFAULTS.fadeInAfterLoading_fadeTime then
return true
end
end,
func =
function()
config.fadeInAfterLoading_notInCombat = CONFIG_DEFAULTS.fadeInAfterLoading_notInCombat
config.fadeInAfterLoading_startAfter = CONFIG_DEFAULTS.fadeInAfterLoading_startAfter
config.fadeInAfterLoading_fadeTime = CONFIG_DEFAULTS.fadeInAfterLoading_fadeTime
end,
},
},
},
},
}
function L:OnInitialize()
ScreenManager_config = ScreenManager_config or CONFIG_DEFAULTS
-- For easier access.
config = ScreenManager_config
-- Remove keys from previous versions.
for k, v in pairs(config) do
-- print (k, v)
if CONFIG_DEFAULTS[k] == nil then
-- print(k, "not in CONFIG_DEFAULTS")
config[k] = nil
end
end
-- Set CONFIG_DEFAULTS for new key.
for k, v in pairs(CONFIG_DEFAULTS) do
-- print (k, v)
if config[k] == nil then
-- print(k, "not there")
config[k] = v
end
end
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable(appName, optionsTable)
self.optionsMenu = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(appName)
SelectResolutionProfile()
end