Files
RobustToolbox/Robust.Client/UserInterface/CustomControls/OptionsMenu.cs
T
ShadowCommanderandGitHub 3b49e0df82 Implement ContainerButton and refactor buttons (#975)
* Add style to TextureRect

* Implement ContainerButton

ContainerButton is a button that resizes to fit the Controls it contains.

* Refactor OptionButton to use ContainerButton

This allows OptionButton to have an inverted triangle icon on the right to make it more obvious that the button is an OptionButton.

* Fix Popup not updating size when opened

* Fix DrawMode not getting updated when _pressed is changed

* Refactor Button to inherit from ContainerButton

* Refactor CheckBox to inherit from ContainerButton

* Fix Control.StyleClasses.GetEnumerator

It was calling GetEnumerator in an infinite loop instead of getting _styleClasses.GetEnumerator like it was supposed to do.

* Update Button references

* Fix Styling
2020-02-17 11:06:16 +01:00

80 lines
3.1 KiB
C#

using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Interfaces.Configuration;
using Robust.Shared.Maths;
namespace Robust.Client.UserInterface.CustomControls
{
public sealed class OptionsMenu : SS14Window
{
private readonly Button ApplyButton;
private readonly CheckBox VSyncCheckBox;
private readonly CheckBox FullscreenCheckBox;
private readonly CheckBox HighResLightsCheckBox;
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;
HighResLightsCheckBox = new CheckBox {Text = "High-Res Lights"};
vBox.AddChild(HighResLightsCheckBox);
HighResLightsCheckBox.OnToggled += OnCheckBoxToggled;
ApplyButton = new Button
{
Text = "Apply", TextAlign = Label.AlignMode.Center,
SizeFlagsVertical = SizeFlags.ShrinkCenter
};
vBox.AddChild(ApplyButton);
ApplyButton.OnPressed += OnApplyButtonPressed;
VSyncCheckBox.Pressed = configManager.GetCVar<bool>("display.vsync");
HighResLightsCheckBox.Pressed = configManager.GetCVar<bool>("display.highreslights");
FullscreenCheckBox.Pressed = ConfigIsFullscreen;
}
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{
configManager.SetCVar("display.vsync", VSyncCheckBox.Pressed);
configManager.SetCVar("display.highreslights", HighResLightsCheckBox.Pressed);
configManager.SetCVar("display.windowmode",
(int) (FullscreenCheckBox.Pressed ? WindowMode.Fullscreen : WindowMode.Windowed));
configManager.SaveToFile();
UpdateApplyButton();
}
private void OnCheckBoxToggled(BaseButton.ButtonToggledEventArgs args)
{
UpdateApplyButton();
}
private void UpdateApplyButton()
{
var isVSyncSame = VSyncCheckBox.Pressed == configManager.GetCVar<bool>("display.vsync");
var isHighResLightsSame = HighResLightsCheckBox.Pressed == configManager.GetCVar<bool>("display.highreslights");
var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen;
ApplyButton.Disabled = isVSyncSame && isHighResLightsSame && isFullscreenSame;
}
private bool ConfigIsFullscreen =>
configManager.GetCVar<int>("display.windowmode") == (int) WindowMode.Fullscreen;
}
}