24 protected ref array<int> m_aWidths = {};
25 protected ref array<int> m_aHeights = {};
26 protected ref array<int> m_aAAvalues = { 0, 2, 4, 8, 16, 32 };
34 protected string m_sResolutionScaleLocalisation;
36 protected UserSettings m_Video;
37 protected UserSettings m_Pipeline;
38 protected UserSettings m_ResourceManager;
40 protected static const string RESOLUTION_FORMAT =
"%1 × %2";
41 protected static const int CUSTOM_PRESET_INDEX = 4;
44 protected static const ref array<string> PRESET_SETTINGS = {
72 "TerrainSurfaceDetail",
81 if (m_bLoadingSettings)
85 SetQualityPresetIndex(binding.GetWidgetName());
87 super.OnMenuItemChanged(binding);
91 protected void OnCustomMenuItemChanged(
string widgetName)
97 protected void SetQualityPresetIndex(
string changedSetting)
99 if (!PRESET_SETTINGS.Contains(changedSetting))
104 qualityPreset.SetCurrentItem(CUSTOM_PRESET_INDEX);
106 BaseContainer display =
GetGame().GetEngineUserSettings().GetModule(
"DisplayUserSettings");
107 display.Set(
"OverallQuality", CUSTOM_PRESET_INDEX);
111 override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout,
int index)
113 super.OnTabCreate(menuRoot, buttonsLayout,
index);
115 m_ResourceManager =
GetGame().GetEngineUserSettings().GetModule(
"ResourceManagerUserSettings");
116 m_Pipeline =
GetGame().GetEngineUserSettings().GetModule(
"PipelineUserSettings");
117 m_Video =
GetGame().GetEngineUserSettings().GetModule(
"VideoUserSettings");
127 aspectRatio.SetVisible(
false);
130 m_aSettingsBindings.Clear();
132 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"ResourceManagerUserSettings",
"GeometricDetail",
"GeometricDetail"));
133 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"TerrainGenMaterialSettings",
"GeometryLevel",
"TerrainDetail"));
139 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"TerrainGenMaterialSettings",
"Detail",
"TerrainSurfaceDetail"));
140 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"MaterialSystemUserSettings",
"TextureFilter",
"TextureFiltering"));
142 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"GraphicsQualitySettings",
"ObjectDrawDistanceScale",
"ObjectDrawDistance"));
144 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"VideoUserSettings",
"ResolutionScale",
"ResolutionScale"));
146 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"VideoUserSettings",
"RenderFormat",
"RenderTargetFormat"));
147 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"VideoUserSettings",
"DistantShadowsQuality",
"DistantShadows"));
148 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"VideoUserSettings",
"EnvironmentQuality",
"EnvironmentQuality"));
152 m_aSettingsBindings.Insert(
new SCR_SettingBindingEngine(
"DisplayUserSettings",
"PPAA",
"PostprocessAA",
"PPQuality"));
161 SetupQualityPreset();
163 SetupGrassDistance();
165 SetupResolutionScale();
166 SetupShadowQuality();
168 SetupTextureDetail();
171 RemoveQualityPresetFocus();
177 protected void SetupTextureDetail(
bool isInit =
true)
179 if (!m_ResourceManager)
186 float value, min, max, step, item;
187 m_ResourceManager.Get(
"TextureDetail", value);
188 m_ResourceManager.GetLimits(item, min, max, step);
190 int current = (max - value);
191 textureDetail.SetCurrentItem(current);
194 textureDetail.m_OnChanged.Insert(OnTextureDetailChanged);
201 if (!comp || !m_MaxFPS || !m_Video)
204 bool isEnabled = m_MaxFPS.GetCurrentIndex();
208 value = m_MaxFPS.GetCurrentItem().ToInt();
210 m_Video.Set(
"MaxFps", value);
212 OnCustomMenuItemChanged(
"MaxFPS");
219 if (!m_ResourceManager)
222 float min, max, step, item;
223 m_ResourceManager.GetLimits(item, min, max, step);
225 int current = max - i;
226 m_ResourceManager.Set(
"TextureDetail", current);
228 OnCustomMenuItemChanged(
"TextureDetail");
234 if (m_bLoadingSettings)
237 if (combobox.GetCurrentIndex() == CUSTOM_PRESET_INDEX)
240 GetGame().ApplySettingsPreset();
241 GetGame().UserSettingsChanged();
245 m_bLoadingSettings =
true;
247 SetupHardwareAA(
false);
248 SetupTextureDetail(
false);
249 SetupShadowQuality(
false);
251 m_bLoadingSettings =
false;
255 protected void SetupQualityPreset()
261 qualityPreset.m_OnChanged.Insert(OnQualityPresetChanged);
265 protected void SetupHardwareAA(
bool isInit =
true)
281 m_Video.Get(
"Fsaa", value);
283 int i = m_aAAvalues.Find(value);
285 antiAliasing.SetCurrentItem(i);
288 antiAliasing.m_OnChanged.Insert(OnHardwareAAChanged);
291 if (foliageSmoothing && i == 0)
292 foliageSmoothing.SetEnabled(
false);
299 if (!m_Video || i < 0 || i >= m_aAAvalues.Count())
302 m_Video.Set(
"Fsaa", m_aAAvalues[i]);
305 if (foliageSmoothing)
306 foliageSmoothing.SetEnabled(i > 0);
308 OnCustomMenuItemChanged(
"HardwareAA");
315 value = Math.Round(value * 100);
317 comp.ShowCustomValue(value.ToString());
319 OnRenderResolutionChanged();
321 OnCustomMenuItemChanged(
"ResolutionScale");
326 protected void OnRenderResolutionChanged()
328 if (!m_ResolutionScale || !m_sResolutionScaleLocalisation)
331 TextWidget labelWidget = m_ResolutionScale.GetLabel();
335 float uiResWidth, uiResHeight;
336 int renderResWidth, renderResHeight;
337 GetGame().GetWorkspace().GetScreenSize(uiResWidth, uiResHeight);
338 float scale = m_ResolutionScale.GetValue();
339 renderResWidth = Math.Round(uiResWidth * scale);
340 renderResHeight = Math.Round(uiResHeight * scale);
342 labelWidget.SetTextFormat(m_sResolutionScaleLocalisation, renderResWidth, renderResHeight);
352 m_Pipeline.Set(
"ShadowQuality", i + 1);
353 OnCustomMenuItemChanged(
"ShadowQuality");
360 GetGame().SetViewDistance(value);
362 BaseContainer m_VideoSettings =
GetGame().GetGameUserSettings().GetModule(
"SCR_VideoSettings");
365 m_VideoSettings.Set(
"m_iViewDistance", value);
367 OnCustomMenuItemChanged(
"DrawDistance");
373 GetGame().SetGrassDistance(value);
374 OnCustomMenuItemChanged(
"GrassDistance");
381 if (!m_Video || !m_ResolutionCombo || !m_ResolutionScale)
384 bool borderlessFullscreen = (
index == 0);
386 m_ResolutionCombo.GetRootWidget().SetVisible(!borderlessFullscreen);
387 m_ResolutionScale.GetRootWidget().SetVisible(borderlessFullscreen);
389 int nativeWidth, nativeHeight;
392 if (borderlessFullscreen)
401 System.GetNativeResolution(nativeWidth, nativeHeight);
402 int i = combo.GetCurrentIndex();
403 scale = m_aWidths[i] / nativeWidth;
404 m_Video.Set(
"ResolutionScale", scale);
406 m_ResolutionScale.SetValue(scale);
413 m_Video.Get(
"ResolutionScale", scale);
414 System.GetNativeResolution(nativeWidth, nativeHeight);
416 int width = nativeWidth * scale;
417 int bestDiff =
int.MAX;
420 for (
int i, cnt = m_aWidths.Count(); i < cnt; i++)
422 int diff = Math.AbsInt(m_aWidths[i] - width);
434 m_Video.Set(
"ScreenWidth", m_aWidths[bestIdx]);
435 m_Video.Set(
"ScreenHeight", m_aHeights[bestIdx]);
436 m_Video.Set(
"ResolutionScale", 1.0);
438 SetResolutionCombo(m_ResolutionCombo);
441 OnCustomMenuItemChanged(
"WindowMode");
450 int scale, nativeWidth, nativeHeight, width, height;
451 m_Video.Get(
"ResolutionScale", scale);
452 m_Video.Get(
"ScreenWidth", width);
453 m_Video.Get(
"ScreenHeight", height);
454 System.GetNativeResolution(nativeWidth, nativeHeight);
456 width = width * scale;
457 height = height * scale;
458 int bestDiff =
int.MAX;
461 for (
int i, cnt = m_aWidths.Count(); i < cnt; i++)
463 int diff = Math.AbsInt(m_aWidths[i] - width);
474 int bestDiffH =
int.MAX;
477 for (
int i, cnt = m_aHeights.Count(); i < cnt; i++)
479 int diff = Math.AbsInt(m_aHeights[i] - height);
481 if (diff < bestDiffH)
490 string resolutionStr =
string.Format(RESOLUTION_FORMAT, m_aWidths[bestIdx], m_aHeights[bestIdxH]);
492 foreach (
int i,
string elementName : combo.m_aElementNames)
494 if (elementName != resolutionStr)
497 combo.SetCurrentItem(i);
503 protected void SetupViewDistance()
510 float min =
GetGame().GetMinimumViewDistance();
511 float max =
GetGame().GetMaximumViewDistance();
514 BaseContainer m_VideoSettings =
GetGame().GetGameUserSettings().GetModule(
"SCR_VideoSettings");
517 m_VideoSettings.Get(
"m_iViewDistance", viewDistance);
518 GetGame().SetViewDistance(viewDistance);
521 float current =
GetGame().GetViewDistance();
527 distance.GetOnChangedFinal().Insert(OnViewDistanceChanged);
531 protected void SetupGrassDistance()
537 int min =
GetGame().GetMinimumGrassDistance();
538 int max =
GetGame().GetMaximumGrassDistance();
539 int current =
GetGame().GetGrassDistance();
545 distance.GetOnChangedFinal().Insert(OnGrassDistanceChanged);
549 protected void SetupShadowQuality(
bool isInit =
true)
559 m_Pipeline.Get(
"ShadowQuality", shadowQuality);
560 shadowDetail.SetCurrentItem(Math.ClampInt(shadowQuality - 1, 0, shadowDetail.GetNumItems() - 1));
563 shadowDetail.m_OnChanged.Insert(OnShadowDetailChanged);
567 protected void SetupResolution()
569 if (!m_ResolutionCombo || !m_ResolutionScale || !m_WindowMode || !m_Video)
573 m_Video.Get(
"WindowMode", mode);
577 #ifdef PLATFORM_CONSOLE
578 bool fullScreen =
true;
579 bool showWindowMode =
false;
582 bool showWindowMode =
true;
587 showWindowMode =
false;
592 m_WindowMode.SetCurrentItem(!fullScreen);
593 m_WindowMode.m_OnChanged.Insert(OnWindowModeChanged);
596 m_WindowMode.GetRootWidget().SetVisible(showWindowMode);
598 if (m_ResolutionScale)
599 m_ResolutionScale.GetRootWidget().SetVisible(fullScreen);
600 if (m_ResolutionCombo)
601 m_ResolutionCombo.GetRootWidget().SetVisible(!fullScreen);
603 System.GetSupportedResolutions(m_aWidths, m_aHeights);
604 for (
int i = 0, cnt = m_aWidths.Count(); i < cnt; i++)
606 m_ResolutionCombo.AddItem(
string.Format(RESOLUTION_FORMAT, m_aWidths[i], m_aHeights[i]));
609 SetResolutionCombo(m_ResolutionCombo);
610 m_ResolutionCombo.m_OnChanged.Insert(UpdateResolution);
614 protected void SetupResolutionScale()
616 if (!m_ResolutionScale)
619 float scale = m_ResolutionScale.GetValue() * 100;
620 scale = Math.Round(scale);
621 m_ResolutionScale.ShowCustomValue(scale.ToString());
623 TextWidget labelWidget = m_ResolutionScale.GetLabel();
625 m_sResolutionScaleLocalisation = labelWidget.GetText();
627 m_ResolutionScale.m_OnChanged.Insert(OnResolutionScaleChanged);
628 OnRenderResolutionChanged();
634 protected void RemoveQualityPresetFocus()
636 ButtonWidget qualityPreset = ButtonWidget.Cast(
m_wRoot.FindAnyWidget(
"QualityPreset"));
640 VerticalLayoutWidget settingsEntries = VerticalLayoutWidget.Cast(m_wScroll.FindAnyWidget(
"SettingsEntries"));
641 if (!settingsEntries)
644 Widget child = settingsEntries.GetChildren();
647 if (ButtonWidget.Cast(child))
649 GetGame().GetCallqueue().CallLater(
GetGame().GetWorkspace().SetFocusedWidget, 0,
false, child,
false);
652 child = child.GetSibling();
660 if (!resolution || !m_Video)
663 m_Video.Set(
"ScreenWidth", m_aWidths[current]);
664 m_Video.Set(
"ScreenHeight", m_aHeights[current]);
666 OnRenderResolutionChanged();
668 OnCustomMenuItemChanged(
"Resolution");
672 protected void SetupMaxFPS()
674 if (!m_Video || !m_MaxFPS)
678 m_Video.Get(
"MaxFps", maxFPS);
682 m_MaxFPS.SetCurrentItem(0);
686 for (
int i = 1, cnt = m_MaxFPS.GetNumItems(); i < cnt; i++)
688 if (m_MaxFPS.GetItemName(i).ToInt() == maxFPS)
690 m_MaxFPS.SetCurrentItem(i);
696 m_MaxFPS.m_OnChanged.Insert(OnMaxFPSChanged);