diff --git a/Content.Client/State/MainMenu.cs b/Content.Client/State/MainMenu.cs index 06c7e46a3a..473cb03d90 100644 --- a/Content.Client/State/MainMenu.cs +++ b/Content.Client/State/MainMenu.cs @@ -1,5 +1,6 @@ using System; using System.Text.RegularExpressions; +using Content.Client.UserInterface; using Robust.Client; using Robust.Client.Interfaces; using Robust.Client.Interfaces.ResourceManagement; @@ -7,7 +8,6 @@ using Robust.Client.Interfaces.UserInterface; using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; using Robust.Client.UserInterface.Controls; -using Robust.Client.UserInterface.CustomControls; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.Network; using Robust.Shared.IoC; diff --git a/Content.Client/UserInterface/OptionsMenu.cs b/Content.Client/UserInterface/OptionsMenu.cs new file mode 100644 index 0000000000..4ecd54d249 --- /dev/null +++ b/Content.Client/UserInterface/OptionsMenu.cs @@ -0,0 +1,136 @@ +using Robust.Client.Graphics; +using Robust.Client.UserInterface.Controls; +using Robust.Client.UserInterface.CustomControls; +using Robust.Shared.Interfaces.Configuration; +using Robust.Shared.Maths; + +namespace Content.Client.UserInterface +{ + public sealed class OptionsMenu : SS14Window + { + private readonly Button ApplyButton; + private readonly CheckBox VSyncCheckBox; + private readonly CheckBox FullscreenCheckBox; + private readonly OptionButton LightingPresetOption; + private readonly IConfigurationManager configManager; + + protected override Vector2? CustomSize => (180, 160); + + public OptionsMenu(IConfigurationManager configMan) + { + configManager = configMan; + + Title = "Options"; + + var vBox = new VBoxContainer(); + Contents.AddChild(vBox); + //vBox.SetAnchorAndMarginPreset(LayoutPreset.Wide); + + VSyncCheckBox = new CheckBox {Text = "VSync"}; + vBox.AddChild(VSyncCheckBox); + VSyncCheckBox.OnToggled += OnCheckBoxToggled; + + FullscreenCheckBox = new CheckBox {Text = "Fullscreen"}; + vBox.AddChild(FullscreenCheckBox); + FullscreenCheckBox.OnToggled += OnCheckBoxToggled; + + vBox.AddChild(new Label {Text = "Lighting Quality"}); + + LightingPresetOption = new OptionButton(); + LightingPresetOption.AddItem("Very Low"); + LightingPresetOption.AddItem("Low"); + LightingPresetOption.AddItem("Medium"); + LightingPresetOption.AddItem("High"); + vBox.AddChild(LightingPresetOption); + LightingPresetOption.OnItemSelected += OnLightingQualityChanged; + + ApplyButton = new Button + { + Text = "Apply", TextAlign = Label.AlignMode.Center, + SizeFlagsVertical = SizeFlags.ShrinkCenter + }; + vBox.AddChild(ApplyButton); + ApplyButton.OnPressed += OnApplyButtonPressed; + + VSyncCheckBox.Pressed = configManager.GetCVar("display.vsync"); + FullscreenCheckBox.Pressed = ConfigIsFullscreen; + LightingPresetOption.SelectId(GetConfigLightingQuality()); + } + + private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args) + { + configManager.SetCVar("display.vsync", VSyncCheckBox.Pressed); + SetConfigLightingQuality(LightingPresetOption.SelectedId); + configManager.SetCVar("display.windowmode", + (int) (FullscreenCheckBox.Pressed ? WindowMode.Fullscreen : WindowMode.Windowed)); + configManager.SaveToFile(); + UpdateApplyButton(); + } + + private void OnCheckBoxToggled(BaseButton.ButtonToggledEventArgs args) + { + UpdateApplyButton(); + } + + private void OnLightingQualityChanged(OptionButton.ItemSelectedEventArgs args) + { + LightingPresetOption.SelectId(args.Id); + UpdateApplyButton(); + } + + private void UpdateApplyButton() + { + var isVSyncSame = VSyncCheckBox.Pressed == configManager.GetCVar("display.vsync"); + var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen; + var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality(); + ApplyButton.Disabled = isVSyncSame && isFullscreenSame && isLightingQualitySame; + } + + private bool ConfigIsFullscreen => + configManager.GetCVar("display.windowmode") == (int) WindowMode.Fullscreen; + + private int GetConfigLightingQuality() + { + var val = configManager.GetCVar("display.lightmapdivider"); + var soft = configManager.GetCVar("display.softshadows"); + if (val >= 8) + { + return 0; + } + else if ((val >= 2) && !soft) + { + return 1; + } + else if (val >= 2) + { + return 2; + } + else + { + return 3; + } + } + private void SetConfigLightingQuality(int value) + { + switch (value) + { + case 0: + configManager.SetCVar("display.lightmapdivider", 8); + configManager.SetCVar("display.softshadows", false); + break; + case 1: + configManager.SetCVar("display.lightmapdivider", 2); + configManager.SetCVar("display.softshadows", false); + break; + case 2: + configManager.SetCVar("display.lightmapdivider", 2); + configManager.SetCVar("display.softshadows", true); + break; + case 3: + configManager.SetCVar("display.lightmapdivider", 1); + configManager.SetCVar("display.softshadows", true); + break; + } + } + } +} diff --git a/RobustToolbox b/RobustToolbox index 5146bf8ac2..4e6f8ca224 160000 --- a/RobustToolbox +++ b/RobustToolbox @@ -1 +1 @@ -Subproject commit 5146bf8ac2d7617b99454ffcbe0394ca800b2d3b +Subproject commit 4e6f8ca2241ded7e7948b4d71fe6f726006fa3e1