forked from Azurency/Civ6-UIFiles
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Options.lua
2104 lines (1748 loc) · 82.8 KB
/
Options.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
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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- ===========================================================================
-- Options
-- ===========================================================================
include("Civ6Common");
include("InstanceManager");
include("PopupDialog");
include("PlayerSetupLogic");
-- Quick utility function to determine if Rise and Fall is installed.
function HasExpansion1()
local xp1ModId = "1B28771A-C749-434B-9053-D1380C553DE9";
return Modding.IsModInstalled(xp1ModId);
end
-- Quick utility function to determine if Rise and Fall is installed.
function HasExpansion2()
local xpModId = "4873eb62-8ccc-4574-b784-dda455e74e68";
return Modding.IsModInstalled(xpModId);
end
function IsInGame()
if(GameConfiguration ~= nil) then
return GameConfiguration.GetGameState() ~= GameStateTypes.GAMESTATE_PREGAME;
end
return false;
end
-- ===========================================================================
-- DEBUG
-- Toggle these for temporary debugging help.
-- ===========================================================================
local m_debugAlwaysAllowAllOptions :boolean= false; -- (false) When true no options are disabled, even when in game. :/
-- ===========================================================================
-- MEMBERS / VARIABLES
-- ===========================================================================
local _KeyBindingCategories = InstanceManager:new("KeyBindingCategory", "CategoryName", Controls.KeyBindingsStack);
local _KeyBindingActions = InstanceManager:new("KeyBindingAction", "Root", Controls.KeyBindingsStack);
local m_tabs;
local m_pendingGameConfigChanges;
local BORDERLESS_OPTION = 2;
local FULLSCREEN_OPTION = 1;
local WINDOWED_OPTION = 0;
local MIN_CHAT_TEXT_SIZE = 12;
local MAX_CHAT_TEXT_SIZE = 18;
local MIN_SCROLL_SPEED = 0;
local MAX_SCROLL_SPEED = 1.0;
local MIN_SCREEN_Y = 768;
local SCREEN_OFFSET_Y = 63;
local MIN_SCREEN_OFFSET_Y = -53;
_PromptRestartApp = false;
_PromptRestartGame = false;
_PromptResolutionAck = false;
-- Options for WebHook Frequency Pulldown
local webhookFreq_options =
{
{"LOC_WEBHOOK_FREQ_MY_TURN", TurnNotifyFrequencyModes.TurnNotify_MyTurn},
{"LOC_WEBHOOK_FREQ_EVERY_TURN", TurnNotifyFrequencyModes.TurnNotify_EveryTurn}
};
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function OnOptionChangeRequiresAppRestart()
_PromptRestartApp = true
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function OnOptionChangeRequiresGameRestart()
_PromptRestartGame = true;
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function OnOptionChangeRequiresResolutionAck()
_PromptResolutionAck = true;
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function OnPBCNotifyRemind_ShowOptions()
-- Go to first tab where play-by-cloud options exist
OnSelectTab(1);
UIManager:QueuePopup( ContextPtr, PopupPriority.Current );
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function OnCancel()
Options.RevertOptions();
UserConfiguration.RestoreCheckpoint();
RefreshKeyBinding();
_PromptRestartApp = false;
_PromptRestartGame = false;
_PromptResolutionAck = false;
local value = Options.GetAudioOption("Sound", "Master Volume");
Controls.MasterVolSlider:SetValue(value / 100.0);
Options.SetAudioOption("Sound", "Master Volume", value, 0);
value = Options.GetAudioOption("Sound", "Music Volume");
Controls.MusicVolSlider:SetValue(value / 100.0);
Options.SetAudioOption("Sound", "Music Volume", value, 0);
value = Options.GetAudioOption("Sound", "SFX Volume");
Controls.SFXVolSlider:SetValue(value / 100.0);
Options.SetAudioOption("Sound", "SFX Volume", value, 0);
value = Options.GetAudioOption("Sound", "Ambience Volume");
Controls.AmbVolSlider:SetValue(value / 100.0);
Options.SetAudioOption("Sound", "Ambience Volume", value, 0);
value = Options.GetAudioOption("Sound", "Speech Volume");
Controls.SpeechVolSlider:SetValue(value / 100.0);
Options.SetAudioOption("Sound", "Speech Volume", value, 0);
value = Options.GetGraphicsOption("General", "MinimapSize") or 0.0;
Controls.MinimapSizeSlider:SetValue(value);
UI.SetMinimapSize(value);
value = Options.GetUserOption("Interface", "ChatTextValue") or 12;
Controls.ChatTextSizeSlider:SetValue(value);
Options.SetUserOption("Interface", "ChatTextValue", value);
value = Options.GetAudioOption("Sound", "Mute Focus");
if (value == 0) then
Controls.MuteFocusCheckbox:SetSelected(false);
else
Controls.MuteFocusCheckbox:SetSelected(true);
end
Options.SetAudioOption("Sound", "Mute Focus", value, 0);
UIManager:DequeuePopup(ContextPtr);
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function OnReset()
function EnableControls()
Controls.ResetButton:SetDisabled(false);
Controls.WindowCloseButton:SetDisabled(false);
Controls.ConfirmButton:SetDisabled(true);
end
function ResetOptions()
Options.ResetOptions();
_PromptRestartApp = false;
_PromptRestartGame = false;
_PromptResolutionAck = false;
PopulateGraphicsOptions();
TemporaryHardCodedGoodness();
EnableControls();
end
function CancelReset()
EnableControls();
end
_kPopupDialog:AddText(Locale.Lookup("LOC_OPTIONS_RESET_OPTIONS_POPUP_TEXT"));
_kPopupDialog:AddButton(Locale.Lookup("LOC_OPTIONS_RESET_OPTIONS_POPUP_YES"), function() ResetOptions(); end, nil, nil,"PopupButtonInstanceRed");
_kPopupDialog:AddButton(Locale.Lookup("LOC_OPTIONS_RESET_OPTIONS_POPUP_NO"), function() CancelReset(); end);
_kPopupDialog:Open();
Controls.ResetButton:SetDisabled(true);
Controls.ConfirmButton:SetDisabled(true);
Controls.WindowCloseButton:SetDisabled(true);
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function OnConfirm()
function KeepGraphicsChanges()
-- Make sure the next game start uploads the changed settings telemetry
Options.SetAppOption("Misc", "TelemetryUploadNecessary", 1);
-- Save after applying the options to make sure they are valid
Options.SaveOptions();
PopulateGraphicsOptions();
_PromptRestartApp = false;
_PromptRestartGame = false;
_PromptResolutionAck = false;
-- Do not call DequeuePopup, because PopupDialog calls self.Close() before calling this function
--UIManager:DequeuePopup(ContextPtr);
end
function RevertGraphicsChanges()
-- Revert the graphics option changes
Options.RevertResolutionChanges();
-- Save after reverting the options to make sure they are valid
Options.SaveOptions();
PopulateGraphicsOptions();
_PromptRestartApp = false;
_PromptRestartGame = false;
_PromptResolutionAck = false;
end
function ConfirmChanges()
-- Confirm clicked: set audio system's .ini to slider values --
Options.SetAudioOption("Sound", "Master Volume", Controls.MasterVolSlider:GetValue() * 100.0, 1);
Options.SetAudioOption("Sound", "Music Volume", Controls.MusicVolSlider:GetValue() * 100.0, 1);
Options.SetAudioOption("Sound", "SFX Volume", Controls.SFXVolSlider:GetValue() * 100.0, 1);
Options.SetAudioOption("Sound", "Ambience Volume", Controls.AmbVolSlider:GetValue() * 100.0, 1);
Options.SetAudioOption("Sound", "Speech Volume", Controls.SpeechVolSlider:GetValue() * 100.0, 1);
if (Controls.MuteFocusCheckbox:IsSelected()) then
Options.SetAudioOption("Sound", "Mute Focus", 1, 1);
else
Options.SetAudioOption("Sound", "Mute Focus", 0, 1);
end
-- Now we apply the userconfig options
UserConfiguration.SetValue("QuickCombat", Options.GetUserOption("Gameplay", "QuickCombat"));
UserConfiguration.SetValue("QuickMovement", Options.GetUserOption("Gameplay", "QuickMovement"));
UserConfiguration.SetValue("AutoEndTurn", Options.GetUserOption("Gameplay", "AutoEndTurn"));
UserConfiguration.SetValue("CityRangeAttackTurnBlocking", Options.GetUserOption("Gameplay", "CityRangeAttackTurnBlocking"));
UserConfiguration.SetValue("TutorialLevel", Options.GetUserOption("Gameplay", "TutorialLevel"));
UserConfiguration.SetValue("EdgePan", Options.GetUserOption("Gameplay", "EdgePan"));
UserConfiguration.SetValue("AutoProdQueue", Options.GetUserOption("Gameplay", "AutoProdQueue"));
UserConfiguration.SetValue("AutoUnitCycle", Options.GetUserOption("Gameplay", "AutoUnitCycle"));
UserConfiguration.SetValue("RibbonStats", Options.GetUserOption("Interface", "RibbonStats"));
UserConfiguration.SetValue("PlotTooltipDelay", Options.GetUserOption("Interface", "PlotTooltipDelay"));
UserConfiguration.SetValue("ChatTextValue", Options.GetUserOption("Interface", "ChatTextValue"));
UserConfiguration.SetValue("ScrollSpeed", Options.GetUserOption("Interface", "ScrollSpeed"));
-- Apply the graphics options (modifies in-memory values and modifies the engine, but does not save to disk)
local bSuccess = Options.ApplyGraphicsOptions();
-- tell the colorblindness adapatation code to switch to the new base palette
-- Do not do this if the game has started as it will reset player colors.
if(not IsInGame()) then
UI.RefreshColorSet();
end
UI.TouchEnableChanged();
-- Re-populate the graphics options to update any settings that the engine had to modify from the user's selected values
PopulateGraphicsOptions();
-- Show the resolution acknowledgment pop-up
if bSuccess then
if _PromptResolutionAck then
_kPopupDialog:AddText(Locale.Lookup("LOC_OPTIONS_RESOLUTION_OK"));
_kPopupDialog:AddButton(Locale.Lookup("LOC_OPTIONS_RESET_OPTIONS_POPUP_YES"),
function()
KeepGraphicsChanges();
UserConfiguration.SaveCheckpoint();
end);
_kPopupDialog:AddButton(Locale.Lookup("LOC_OPTIONS_RESET_OPTIONS_POPUP_NO"), function() RevertGraphicsChanges(); end);
_kPopupDialog:AddCountDown(15, function() RevertGraphicsChanges(); end );
_kPopupDialog:Open();
else
KeepGraphicsChanges();
UserConfiguration.SaveCheckpoint();
end
end
-- Save game config options if they have been modified
if m_pendingGameConfigChanges and table.count(m_pendingGameConfigChanges) > 0 then
for group, values in pairs(m_pendingGameConfigChanges) do
for id, value in pairs(values) do
BASE_Config_Write(SetupParameters, group, id, value);
end
end
Network.BroadcastGameConfig();
end
Controls.ConfirmButton:SetDisabled(true);
_PromptResolutionAck = false;
end
if(_PromptRestartApp) then
_kPopupDialog:AddText(Locale.Lookup("LOC_OPTIONS_CHANGES_REQUIRE_APP_RESTART"));
_kPopupDialog:AddButton(Locale.Lookup("LOC_OPTIONS_RESET_OPTIONS_POPUP_OK"), function() ConfirmChanges(); end);
_kPopupDialog:Open();
Controls.ConfirmButton:SetDisabled(true);
elseif(_PromptRestartGame and IsInGame()) then
_kPopupDialog:AddText(Locale.Lookup("LOC_OPTIONS_CHANGES_REQUIRE_GAME_RESTART"));
_kPopupDialog:AddButton(Locale.Lookup("LOC_OPTIONS_RESET_OPTIONS_POPUP_OK"), function() ConfirmChanges(); end);
_kPopupDialog:Open();
else
ConfirmChanges();
end
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function PopulateComboBox(control, values, selected_value, selection_handler, is_locked)
if (is_locked == nil) then
is_locked = false;
end
control:ClearEntries();
for i, v in ipairs(values) do
local instance = {};
control:BuildEntry( "InstanceOne", instance );
instance.Button:SetVoid1(i);
instance.Button:LocalizeAndSetText(v[1]);
if(v[2] == selected_value) then
local button = control:GetButton();
button:LocalizeAndSetText(v[1]);
end
end
control:CalculateInternals();
control:SetDisabled(is_locked ~= false);
if(selection_handler) then
control:GetButton():RegisterCallback(Mouse.eMouseEnter, function()
UI.PlaySound("Main_Menu_Mouse_Over");
end);
control:RegisterSelectionCallback(
function(voidValue1, voidValue2, control)
local option = values[voidValue1];
local button = control:GetButton();
button:LocalizeAndSetText(option[1]);
selection_handler(option[2]);
end
);
end
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function PopulateCheckBox(control, current_value, check_handler, is_locked)
if (is_locked == nil) then
is_locked = false;
end
if(current_value == 0) then
control:SetSelected(false);
else
control:SetSelected(true);
end
control:SetDisabled(is_locked ~= false);
if(check_handler) then
control:RegisterCallback(Mouse.eLClick,
function()
local selected = not control:IsSelected();
control:SetSelected(selected);
check_handler(selected);
end
);
control:RegisterCallback(Mouse.eMouseEnter, function()
UI.PlaySound("Main_Menu_Mouse_Over");
end);
end
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function PopulateEditBox(control, current_value, commit_handler, is_locked)
if (is_locked == nil) then
is_locked = false;
end
control:SetText(current_value);
control:SetDisabled(is_locked ~= false);
control:RegisterMouseEnterCallback(function()
UI.PlaySound("Main_Menu_Mouse_Over");
end);
if(commit_handler) then
control:RegisterCommitCallback(
function(editString)
commit_handler(editString);
end
);
end
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function InvertOptionInt(option)
if(option == 0) then
return 1;
else
return 0;
end
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function ImpactValueToSliderStep(slider, impact_value)
if(impact_value == -1) then
return slider:GetNumSteps();
else
return impact_value;
end
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function SliderStepToImpactValue(slider, slider_step)
if(slider_step == slider:GetNumSteps()) then
return -1;
else
return slider_step;
end
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
local TIME_SCALE = 23.0 + (59.0 / 60.0); -- 11:59 PM
function UpdateTimeLabel(value)
local iHours = math.floor(value);
local iMins = math.floor((value - iHours) * 60);
local meridiem = "";
if (UserConfiguration.GetClockFormat() == 0) then
meridiem = " am";
if ( iHours >= 12 ) then
meridiem = " pm";
if( iHours > 12 ) then iHours = iHours - 12; end
end
if( iHours < 1 ) then iHours = 12; end
end
local strTime = string.format("%.2d:%.2d%s", iHours, iMins, meridiem);
Controls.TODText:SetText(strTime);
end
-- Change the state of the resolution pulldown based on whether we have selected borderless mode or not
function AdjustResolutionPulldown(window_mode, is_in_game )
local named_modes = {};
local modes = Options.GetAvailableDisplayModes();
for i, v in ipairs(modes) do
local s = v.Width .. "x" .. v.Height;
if( window_mode == FULLSCREEN_OPTION) then
s = s .. " (" .. v.RefreshRate .. " Hz)";
end
named_modes[s] = v;
end
local indexed_modes = {};
for k, v in pairs(named_modes) do
table.insert(indexed_modes, {k, v});
end
table.sort(indexed_modes, function(a, b) return a[1] > b[1]; end);
--remove duplicate modes if in windowed (same res, different refresh rate)
local final_indexed_modes = {};
if( window_mode == WINDOWED_OPTION ) then
local last = "";
for i,v in ipairs(indexed_modes) do
if( v[1] ~= last ) then
table.insert(final_indexed_modes, v );
end
last = v[1];
end
else
final_indexed_modes = indexed_modes;
end
Controls.ResolutionPullDown:ClearEntries();
for i, v in ipairs(final_indexed_modes) do
local instance = {};
Controls.ResolutionPullDown:BuildEntry( "InstanceOne", instance );
instance.Button:SetVoid1(i);
instance.Button:SetText(v[1]);
end
Controls.ResolutionPullDown:CalculateInternals();
Controls.ResolutionPullDown:RegisterSelectionCallback(
function(voidValue1, voidValue2, control)
local option = final_indexed_modes[voidValue1];
local resolution_button = control:GetButton();
resolution_button:SetText(option[1]);
Options.SetAppOption("Video", "RenderWidth", option[2].Width);
Options.SetAppOption("Video", "RenderHeight", option[2].Height);
Options.SetGraphicsOption("Video", "RefreshRateInHz", option[2].RefreshRate);
local fullscreen_option = Options.GetAppOption("Video", "FullScreen");
_PromptResolutionAck = (fullscreen_option == FULLSCREEN_OPTION);
Controls.ConfirmButton:SetDisabled(false);
end
);
local current_width = Options.GetAppOption("Video", "RenderWidth");
local current_height = Options.GetAppOption("Video", "RenderHeight");
local refresh_rate = Options.GetGraphicsOption("Video", "RefreshRateInHz");
local resolution_button = Controls.ResolutionPullDown:GetButton();
if( window_mode ~= FULLSCREEN_OPTION ) then
resolution_button:SetText(current_width .. "x" .. current_height);
else
resolution_button:SetText(current_width .. "x" .. current_height .. " (" .. refresh_rate .. " Hz)");
end
local debug_enabled = Options.GetAppOption("Debug", "EnableDebugMenu"); -- When debugging allow game resolution change. TODO: Evaluate allowing change for everyone.
if is_in_game and debug_enabled==0 then
Controls.ResolutionPullDown:SetDisabled(true);
else
if(window_mode == BORDERLESS_OPTION) then
Controls.ResolutionPullDown:SetDisabled(true);
local resolution_button = Controls.ResolutionPullDown:GetButton();
local display_width = Options.GetDisplayWidth();
local display_height = Options.GetDisplayHeight();
resolution_button:SetText(display_width .. "x" .. display_height );
else
Controls.ResolutionPullDown:SetDisabled(false);
local current_width = Options.GetAppOption("Video", "RenderWidth");
local current_height = Options.GetAppOption("Video", "RenderHeight");
local refresh_rate = Options.GetGraphicsOption("Video", "RefreshRateInHz");
local resolution_button = Controls.ResolutionPullDown:GetButton();
local resolution_text = current_width .. "x" .. current_height;
if( window_mode == FULLSCREEN_OPTION ) then
resolution_text = resolution_text .. " (" .. refresh_rate .. " Hz)";
end
resolution_button:SetText(resolution_text);
end
end
end
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
function PopulateGraphicsOptions()
local tickInterval_options =
{
{"LOC_OPTIONS_DISABLED", 0},
{"LOC_OPTIONS_TICK_INTERVAL_20_FPS", 49},
{"LOC_OPTIONS_TICK_INTERVAL_30_FPS", 32},
{"LOC_OPTIONS_TICK_INTERVAL_60_FPS", 16},
};
local windowed_options =
{
{"LOC_OPTIONS_WINDOW_MODE_WINDOWED", WINDOWED_OPTION},
{"LOC_OPTIONS_WINDOW_MODE_FULLSCREEN", FULLSCREEN_OPTION},
{"LOC_OPTIONS_WINDOW_MODE_BORDERLESS", BORDERLESS_OPTION}
};
local uiscale_options =
{
{"LOC_OPTIONS_100_PERCENT", 0.0},
{"LOC_OPTIONS_150_PERCENT", 0.5},
{"LOC_OPTIONS_200_PERCENT", 1.0}
};
local performanceImpact_options =
{
[0]="LOC_OPTIONS_MINIMUM",
"LOC_OPTIONS_LOW",
"LOC_OPTIONS_MEDIUM",
"LOC_OPTIONS_HIGH",
"LOC_OPTIONS_ULTRA",
"LOC_OPTIONS_CUSTOM"
};
local memoryImpact_options =
{
[0]="LOC_OPTIONS_MINIMUM",
"LOC_OPTIONS_LOW",
"LOC_OPTIONS_MEDIUM",
"LOC_OPTIONS_HIGH",
"LOC_OPTIONS_ULTRA",
"LOC_OPTIONS_CUSTOM"
};
local msaa_options =
{
{"LOC_OPTIONS_DISABLED", {1, 0}},
{"LOC_OPTIONS_MSAA_2X", {2, 0}},
{"LOC_OPTIONS_MSAA_4X", {4, 0}},
{"LOC_OPTIONS_MSAA_8X", {8, 0}},
{"LOC_OPTIONS_MSAA_16X", {16, 0}},
{"LOC_OPTIONS_MSAA_32X", {32, 0}},
};
local csaa_options =
{
{"LOC_OPTIONS_CSAA_2X", {2, 4}},
{"LOC_OPTIONS_CSAA_4X", {4, 8}},
{"LOC_OPTIONS_CSAA_8X", {8, 16}},
{"LOC_OPTIONS_CSAA_16X", {16, 32}},
};
local eqaa_options =
{
{"LOC_OPTIONS_EQAA_2X", {2, 4}},
{"LOC_OPTIONS_EQAA_4X", {4, 8}},
{"LOC_OPTIONS_EQAA_8X", {8, 16}},
{"LOC_OPTIONS_EQAA_16X", {16, 32}},
};
local vfx_options =
{
{"LOC_OPTIONS_LOW", 0},
{"LOC_OPTIONS_HIGH", 1}
};
local aoResolution_options =
{
{"1024x1024", 1024},
{"2048x2048", 2048},
};
local shadowResolution_options =
{
{"2048x2048", 2048},
{"4096x4096", 4096},
};
local fowMaskResolution_options =
{
{"512x512", 512},
{"1024x1024", 1024},
};
local terrainQuality_options =
{
{"LOC_OPTIONS_LOW_MEMORY_OPTIMIZED", 0},
{"LOC_OPTIONS_LOW_PERFORMANCE_OPTIMIZED", 1},
{"LOC_OPTIONS_MEDIUM_MEMORY_OPTIMIZED", 2},
{"LOC_OPTIONS_MEDIUM_PERFORMANCE_OPTIMIZED", 3},
{"LOC_OPTIONS_HIGH", 4},
};
local reflectionPasses_options =
{
{"LOC_OPTIONS_DISABLED", 0},
{"LOC_OPTIONS_REFLECTION_1PASS", 1},
{"LOC_OPTIONS_REFLECTION_2PASSES", 2},
{"LOC_OPTIONS_REFLECTION_3PASSES", 3},
{"LOC_OPTIONS_REFLECTION_4PASSES", 4},
};
local leaderQuality_options =
{
{"LOC_OPTIONS_LEADERS_STATIC", 0},
{"LOC_OPTIONS_LOW", 1},
{"LOC_OPTIONS_MEDIUM", 2},
{"LOC_OPTIONS_HIGH", 3},
}
-------------------------------------------------------------------------------
-- Main Options
-------------------------------------------------------------------------------
local is_in_game = Options.IsAppInMainMenuState() == 0;
if m_debugAlwaysAllowAllOptions then
is_in_game = false
end
-- Adapter
local adapters = Options.GetAvailableDisplayAdapters();
Controls.AdapterPullDown:ClearEntries();
for i, v in pairs(adapters) do
local instance = {};
Controls.AdapterPullDown:BuildEntry( "InstanceOne", instance );
instance.Button:SetVoid1(i);
instance.Button:SetText(v);
end
Controls.AdapterPullDown:CalculateInternals();
local adapter_index = Options.GetAppOption("Video", "DeviceID");
local adapter_button = Controls.AdapterPullDown:GetButton();
adapter_button:SetText(adapters[adapter_index]);
Controls.AdapterPullDown:RegisterSelectionCallback(
function(voidValue1, voidValue2, control)
local adapter_button = control:GetButton();
adapter_button:SetText(adapters[voidValue1]);
Options.SetAppOption("Video", "DeviceID", voidValue1);
Controls.ConfirmButton:SetDisabled(false);
_PromptRestartApp = true;
end
);
-- Multi-GPU
local bMGPUValue = 0;
if Options.GetGraphicsOption("DX12", "EnableSplitScreenMultiGPU") == 1 then
bMGPUValue = 1;
end
PopulateCheckBox(Controls.MultiGPUCheckbox, bMGPUValue,
function(option)
Options.SetGraphicsOption("DX12", "EnableSplitScreenMultiGPU", option);
Controls.ConfirmButton:SetDisabled(false);
_PromptRestartApp = true;
end
);
Controls.MultiGPUCheckbox:SetDisabled( Options.IsMultiNodeGPU() == 0 );
-- UI Upscaling
local available_scales = {};
for k, v in pairs(uiscale_options) do
if (Options.IsUIUpscaleAllowed(v[2] + 1.0)) then
table.insert(available_scales, v);
end
end
Controls.UIScalePulldown:ClearEntries();
PopulateComboBox(Controls.UIScalePulldown, available_scales, Options.GetAppOption("Video", "UIUpscale"),
function(option)
Options.SetAppOption("Video", "UIUpscale", option);
Controls.ConfirmButton:SetDisabled(false);
end
);
Controls.UIScalePulldown:SetDisabled( not Options.IsUIUpscaleAllowed() );
-- Performance Impact
local performance_customStep = Controls.PerformanceSlider:GetNumSteps();
local memory_customStep = Controls.MemorySlider:GetNumSteps();
local performance_sliderStep = ImpactValueToSliderStep(Controls.PerformanceSlider, Options.GetGraphicsOption("Video", "PerformanceImpact"));
Controls.PerformanceSlider:SetStep(performance_sliderStep);
Controls.PerformanceValue:LocalizeAndSetText(performanceImpact_options[performance_sliderStep]);
local performance_sliderValue = Controls.PerformanceSlider:GetValue();
Controls.PerformanceSlider:RegisterSliderCallback(
function(option)
-- Guard against multiple calls with the same value
if(performance_sliderValue ~= option) then
-- This has to happen before SetStepAndCall(), otherwise we get into an endless loop
performance_sliderValue = option;
-- We can't rely on option, because it is a float value [0.0 .. 1.0] and we need the step integer number
performance_sliderStep = Controls.PerformanceSlider:GetStep();
-- Update the option set with the new preset, which updates all other options (see OptionSet::ProcessExternally())
Options.SetGraphicsOption("Video", "PerformanceImpact", SliderStepToImpactValue(Controls.PerformanceSlider, performance_sliderStep));
Controls.ConfirmButton:SetDisabled(false);
-- Update the text description
Controls.PerformanceValue:LocalizeAndSetText(performanceImpact_options[performance_sliderStep]);
if(performance_sliderStep ~= performance_customStep) then
if(Controls.MemorySlider:GetStep() == memory_customStep) then
-- The memory slider is set to "custom", so reset it to its default value
Controls.MemorySlider:SetStepAndCall(ImpactValueToSliderStep(Controls.MemorySlider, Options.GetGraphicsDefault("Video", "MemoryImpact")));
end
-- Update all settings in the UI if the performance impact changed to something other than "custom"
PopulateGraphicsOptions();
else
-- The performance slider is set to "custom", so set the memory slider to "custom" as well
Controls.MemorySlider:SetStepAndCall(memory_customStep);
end
end
end
);
-- Memory Impact
local memory_sliderStep = ImpactValueToSliderStep(Controls.MemorySlider, Options.GetGraphicsOption("Video", "MemoryImpact"));
Controls.MemorySlider:SetStep(memory_sliderStep);
Controls.MemoryValue:LocalizeAndSetText(memoryImpact_options[memory_sliderStep]);
local memory_sliderValue = Controls.MemorySlider:GetValue();
Controls.MemorySlider:RegisterSliderCallback(
function(option)
-- Guard against multiple calls with the same value
if(memory_sliderValue ~= option) then
-- This has to happen before SetStepAndCall(), otherwise we get into an endless loop
memory_sliderValue = option;
-- We can't rely on option, because it is a float value [0.0 .. 1.0] and we need the step integer number
memory_sliderStep = Controls.MemorySlider:GetStep();
-- Update the option set with the new preset, which updates all other options (see OptionSet::ProcessExternally())
Options.SetGraphicsOption("Video", "MemoryImpact", SliderStepToImpactValue(Controls.MemorySlider, memory_sliderStep));
Controls.ConfirmButton:SetDisabled(false);
-- Update the text description
Controls.MemoryValue:LocalizeAndSetText(memoryImpact_options[memory_sliderStep]);
if(memory_sliderStep ~= memory_customStep) then
if(Controls.PerformanceSlider:GetStep() == performance_customStep) then
-- The performance slider is set to "custom", so reset it to its default
Controls.PerformanceSlider:SetStepAndCall(ImpactValueToSliderStep(Controls.PerformanceSlider, Options.GetGraphicsDefault("Video", "PerformanceImpact")));
end
-- Update all settings in the UI if the memory impact changed to something other than "custom"
PopulateGraphicsOptions();
else
-- The memory slider is set to "custom", so set the performance slider to "custom" as well
Controls.PerformanceSlider:SetStepAndCall(performance_customStep);
end
end
end
);
-------------------------------------------------------------------------------
-- Advanced Settings
-------------------------------------------------------------------------------
-- VSync
PopulateCheckBox(Controls.VSyncEnabledCheckbox, Options.GetGraphicsOption("Video", "VSync"),
function(option)
Options.SetGraphicsOption("Video", "VSync", option);
Controls.ConfirmButton:SetDisabled(false);
end
);
-- Tick Interval
PopulateComboBox(Controls.TickIntervalPullDown, tickInterval_options, Options.GetAppOption("Performance", "TickIntervalInMS"),
function(option)
Options.SetAppOption("Performance", "TickIntervalInMS", option);
Controls.ConfirmButton:SetDisabled(false);
end
);
-- Fullscreen
PopulateComboBox(Controls.FullScreenPullDown, windowed_options, Options.GetAppOption("Video", "FullScreen"),
function(option)
Options.SetAppOption("Video", "FullScreen", option);
-- In borderless mode, snap width/height to desktop size
if option == BORDERLESS_OPTION then
Options.SetAppOption("Video", "RenderWidth", Options.GetDisplayWidth());
Options.SetAppOption("Video", "RenderHeight", Options.GetDisplayHeight());
end
AdjustResolutionPulldown(option, is_in_game )
_PromptResolutionAck = (option == FULLSCREEN_OPTION);
Controls.ConfirmButton:SetDisabled(false);
end
);
-- MSAA
local nMaxMSAACount = UI.GetMaxMSAACount();
local availableMSAAOptions = {};
for i, v in ipairs(msaa_options) do
local bValid = UI.CanHaveMSAAQuality(v[2][1], v[2][2])
if(bValid) then
table.insert(availableMSAAOptions, {v[1], v[2]});
end
end
local ihvMSAAModes = nil;
if UI.IsVendorAMD() then
ihvMSAAModes = eqaa_options;
elseif UI.IsVendorNVIDIA() then
ihvMSAAModes = csaa_options;
end
if ihvMSAAModes ~= nil then
for i, v in ipairs(ihvMSAAModes) do
local bValid = UI.CanHaveMSAAQuality(v[2][1], v[2][2])
if(bValid) then
table.insert(availableMSAAOptions, {v[1], v[2]});
end
end
end
local nMSAACount = Options.GetGraphicsOption("Video", "MSAA");
if nMSAACount == -1 then
nMSAACount = nMaxMSAACount;
end
local nMSAAQuality = Options.GetGraphicsOption("Video", "MSAAQuality");
-- PopulateComboBox() does a "pointer" compare with non POD, so we have to find the current sample / quality in the MSAA tables
-- so that we can pass it into PopulateComboBox()
local msaaValue = msaa_options[1][2];
if nMSAAQuality == 0 then
for i, v in ipairs(msaa_options) do
if v[2][1] == nMSAACount and v[2][2] == nMSAAQuality then
msaaValue = v[2];
break;
end
end
elseif ihvMSAAModes ~= nil then
for i, v in ipairs(ihvMSAAModes) do
if v[2][1] == nMSAACount and v[2][2] == nMSAAQuality then
msaaValue = v[2];
break;
end
end
end
PopulateComboBox(Controls.MSAAPullDown, availableMSAAOptions, msaaValue,
function(option)
Options.SetGraphicsOption("Video", "MSAA", option[1]); -- First set the sliders to "custom", then set the new value, otherwise ProcessExternally() will overwrite the new value with a preset
Options.SetGraphicsOption("Video", "MSAAQuality", option[2]);
Controls.ConfirmButton:SetDisabled(false);
end
);
-- High-Resolution Asset Textures
PopulateCheckBox(Controls.AssetTextureResolutionCheckbox, InvertOptionInt(Options.GetGraphicsOption("Video", "ReducedAssetTextures")),
function(option)
Controls.MemorySlider:SetStepAndCall(memory_customStep); -- It's enough to set just one of the Impact sliders to "custom", the logic sets the other one
Options.SetGraphicsOption("Video", "ReducedAssetTextures", not option); -- First set the sliders to "custom", then set the new value, otherwise ProcessExternally() will overwrite the new value with a preset
Controls.ConfirmButton:SetDisabled(false);
_PromptRestartGame = true;
end
);
-- High-Quality Visual Effects
PopulateComboBox(Controls.VFXDetailLevelPullDown, vfx_options, Options.GetGraphicsOption("General", "VFXDetailLevel"),
function(option)
Controls.PerformanceSlider:SetStepAndCall(performance_customStep); -- It's enough to set just one of the Impact sliders to "custom", the logic sets the other one
Options.SetGraphicsOption("General", "VFXDetailLevel", option); -- First set the sliders to "custom", then set the new value, otherwise ProcessExternally() will overwrite the new value with a preset
Controls.ConfirmButton:SetDisabled(false);
end
);
-------------------------------------------------------------------------------
-- Advanced Settings - Lighting
-------------------------------------------------------------------------------
-- Bloom Enabled
PopulateCheckBox(Controls.LightingBloomEnabledCheckbox, Options.GetGraphicsOption("Bloom", "EnableBloom"),
function(option)
Controls.PerformanceSlider:SetStepAndCall(performance_customStep); -- It's enough to set just one of the Impact sliders to "custom", the logic sets the other one
Options.SetGraphicsOption("Bloom", "EnableBloom", option); -- First set the sliders to "custom", then set the new value, otherwise ProcessExternally() will overwrite the new value with a preset
Controls.ConfirmButton:SetDisabled(false);
end
);
-- Dynamic Lighting Enabled
PopulateCheckBox(Controls.LightingDynamicLightingEnabledCheckbox, Options.GetGraphicsOption("DynamicLighting", "EnableDynamicLighting"),
function(option)
Controls.PerformanceSlider:SetStepAndCall(performance_customStep); -- It's enough to set just one of the Impact sliders to "custom", the logic sets the other one
Options.SetGraphicsOption("DynamicLighting", "EnableDynamicLighting", option); -- First set the sliders to "custom", then set the new value, otherwise ProcessExternally() will overwrite the new value with a preset
Controls.ConfirmButton:SetDisabled(false);
end
);
-------------------------------------------------------------------------------
-- Advanced Settings - Shadows