Re-organize all projects (#4166)

This commit is contained in:
DrSmugleaf
2021-06-09 22:19:39 +02:00
committed by GitHub
parent 9f50e4061b
commit ff1a2d97ea
1773 changed files with 5258 additions and 5508 deletions

View File

@@ -0,0 +1,15 @@
<SS14Window xmlns="https://spacestation14.io"
xmlns:voting="clr-namespace:Content.Client.Voting"
xmlns:changelog="clr-namespace:Content.Client.Changelog"
xmlns:ui="clr-namespace:Content.Client.Voting.UI"
Title="{Loc 'ui-escape-title'}"
Resizable="False">
<VBoxContainer SeparationOverride="4" CustomMinimumSize="150 160">
<changelog:ChangelogButton />
<ui:VoteCallMenuButton />
<Button Name="OptionsButton" Text="{Loc 'ui-escape-options'}" />
<Button Name="DisconnectButton" Text="{Loc 'ui-escape-disconnect'}" />
<Button Name="QuitButton" Text="{Loc 'ui-escape-quit'}" />
</VBoxContainer>
</SS14Window>

View File

@@ -0,0 +1,56 @@
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.EscapeMenu.UI
{
[GenerateTypedNameReferences]
internal partial class EscapeMenu : SS14Window
{
private readonly IClientConsoleHost _consoleHost;
private readonly OptionsMenu _optionsMenu;
public EscapeMenu(IClientConsoleHost consoleHost)
{
_consoleHost = consoleHost;
RobustXamlLoader.Load(this);
_optionsMenu = new OptionsMenu();
OptionsButton.OnPressed += OnOptionsButtonClicked;
QuitButton.OnPressed += OnQuitButtonClicked;
DisconnectButton.OnPressed += OnDisconnectButtonClicked;
}
private void OnQuitButtonClicked(BaseButton.ButtonEventArgs args)
{
_consoleHost.ExecuteCommand("quit");
Dispose();
}
private void OnDisconnectButtonClicked(BaseButton.ButtonEventArgs args)
{
_consoleHost.ExecuteCommand("disconnect");
Dispose();
}
private void OnOptionsButtonClicked(BaseButton.ButtonEventArgs args)
{
_optionsMenu.OpenCentered();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
_optionsMenu.Dispose();
}
}
}
}

View File

@@ -0,0 +1,197 @@
using Content.Client.HUD.UI;
using Content.Client.Stylesheets;
using Content.Shared;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
namespace Content.Client.EscapeMenu.UI
{
public sealed partial class OptionsMenu
{
private sealed class AudioControl : Control
{
private readonly IConfigurationManager _cfg;
private readonly IClydeAudio _clydeAudio;
private readonly Button ApplyButton;
private readonly Label MasterVolumeLabel;
private readonly Slider MasterVolumeSlider;
private readonly CheckBox AmbienceCheckBox;
private readonly CheckBox LobbyMusicCheckBox;
private readonly Button ResetButton;
public AudioControl(IConfigurationManager cfg, IClydeAudio clydeAudio)
{
_cfg = cfg;
_clydeAudio = clydeAudio;
var vBox = new VBoxContainer();
var contents = new VBoxContainer
{
Margin = new Thickness(2, 2, 2, 0),
VerticalExpand = true,
};
MasterVolumeSlider = new Slider
{
MinValue = 0.0f,
MaxValue = 100.0f,
HorizontalExpand = true,
MinSize = (80, 8),
Rounded = true
};
MasterVolumeLabel = new Label
{
MinSize = (48, 0),
Align = Label.AlignMode.Right
};
contents.AddChild(new HBoxContainer
{
Children =
{
new Control {MinSize = (4, 0)},
new Label {Text = Loc.GetString("ui-options-master-volume")},
new Control {MinSize = (8, 0)},
MasterVolumeSlider,
new Control {MinSize = (8, 0)},
MasterVolumeLabel,
new Control {MinSize = (4, 0)},
}
});
// sets up ambience checkbox. i am sorry for not fixing the rest of this code.
AmbienceCheckBox = new CheckBox {Text = Loc.GetString("ui-options-ambient-hum")};
contents.AddChild(AmbienceCheckBox);
AmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.AmbienceBasicEnabled);
LobbyMusicCheckBox = new CheckBox {Text = Loc.GetString("ui-options-lobby-music")};
contents.AddChild(LobbyMusicCheckBox);
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
ApplyButton = new Button
{
Text = Loc.GetString("ui-options-apply"), TextAlign = Label.AlignMode.Center,
HorizontalAlignment = HAlignment.Right
};
vBox.AddChild(new Label
{
Text = Loc.GetString("ui-options-volume-sliders"),
FontColorOverride = StyleNano.NanoGold,
StyleClasses = {StyleNano.StyleClassLabelKeyText}
});
vBox.AddChild(contents);
ResetButton = new Button
{
Text = Loc.GetString("ui-options-reset-all"),
StyleClasses = {StyleBase.ButtonCaution},
HorizontalExpand = true,
HorizontalAlignment = HAlignment.Right
};
vBox.AddChild(new StripeBack
{
HasBottomEdge = false,
HasMargins = false,
Children =
{
new HBoxContainer
{
Align = BoxContainer.AlignMode.End,
HorizontalExpand = true,
VerticalExpand = true,
Children =
{
ResetButton,
new Control {MinSize = (2, 0)},
ApplyButton
}
}
}
});
ApplyButton.OnPressed += OnApplyButtonPressed;
ResetButton.OnPressed += OnResetButtonPressed;
MasterVolumeSlider.OnValueChanged += OnMasterVolumeSliderChanged;
AmbienceCheckBox.OnToggled += OnAmbienceCheckToggled;
LobbyMusicCheckBox.OnToggled += OnLobbyMusicCheckToggled;
AddChild(vBox);
Reset();
}
protected override void Dispose(bool disposing)
{
ApplyButton.OnPressed -= OnApplyButtonPressed;
ResetButton.OnPressed -= OnResetButtonPressed;
MasterVolumeSlider.OnValueChanged -= OnMasterVolumeSliderChanged;
AmbienceCheckBox.OnToggled -= OnAmbienceCheckToggled;
base.Dispose(disposing);
}
private void OnMasterVolumeSliderChanged(Range range)
{
MasterVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", MasterVolumeSlider.Value / 100));
_clydeAudio.SetMasterVolume(MasterVolumeSlider.Value / 100);
UpdateChanges();
}
private void OnAmbienceCheckToggled(BaseButton.ButtonEventArgs args)
{
UpdateChanges();
}
private void OnLobbyMusicCheckToggled(BaseButton.ButtonEventArgs args)
{
UpdateChanges();
}
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{
_cfg.SetCVar(CVars.AudioMasterVolume, MasterVolumeSlider.Value / 100);
_cfg.SetCVar(CCVars.AmbienceBasicEnabled, AmbienceCheckBox.Pressed);
_cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed);
_cfg.SaveToFile();
UpdateChanges();
}
private void OnResetButtonPressed(BaseButton.ButtonEventArgs args)
{
Reset();
}
private void Reset()
{
MasterVolumeSlider.Value = _cfg.GetCVar(CVars.AudioMasterVolume) * 100;
MasterVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", MasterVolumeSlider.Value / 100));
AmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.AmbienceBasicEnabled);
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
UpdateChanges();
}
private void UpdateChanges()
{
var isMasterVolumeSame =
System.Math.Abs(MasterVolumeSlider.Value - _cfg.GetCVar(CVars.AudioMasterVolume) * 100) < 0.01f;
var isAmbienceSame = AmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.AmbienceBasicEnabled);
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
var isEverythingSame = isMasterVolumeSame && isAmbienceSame && isLobbySame;
ApplyButton.Disabled = isEverythingSame;
ResetButton.Disabled = isEverythingSame;
}
}
}
}

View File

@@ -0,0 +1,336 @@
using Content.Client.HUD.UI;
using Content.Shared;
using Content.Shared.HUD;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared;
using Robust.Shared.Configuration;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Prototypes;
namespace Content.Client.EscapeMenu.UI
{
public sealed partial class OptionsMenu
{
private sealed class GraphicsControl : Control
{
private static readonly float[] UIScaleOptions =
{
0f,
0.75f,
1f,
1.25f,
1.50f,
1.75f,
2f
};
private readonly IConfigurationManager _cfg;
private readonly IPrototypeManager _prototypeManager;
private readonly Button ApplyButton;
private readonly CheckBox VSyncCheckBox;
private readonly CheckBox FullscreenCheckBox;
private readonly OptionButton LightingPresetOption;
private readonly OptionButton _uiScaleOption;
private readonly OptionButton _hudThemeOption;
private readonly CheckBox _viewportStretchCheckBox;
private readonly CheckBox _viewportLowResCheckBox;
private readonly Slider _viewportScaleSlider;
private readonly Control _viewportScaleBox;
private readonly Label _viewportScaleText;
public GraphicsControl(IConfigurationManager cfg, IPrototypeManager proMan)
{
_cfg = cfg;
_prototypeManager = proMan;
var vBox = new VBoxContainer();
var contents = new VBoxContainer
{
Margin = new Thickness(2, 2, 2, 0),
VerticalExpand = true,
};
VSyncCheckBox = new CheckBox {Text = Loc.GetString("ui-options-vsync")};
contents.AddChild(VSyncCheckBox);
VSyncCheckBox.OnToggled += OnCheckBoxToggled;
FullscreenCheckBox = new CheckBox {Text = Loc.GetString("ui-options-fullscreen")};
contents.AddChild(FullscreenCheckBox);
FullscreenCheckBox.OnToggled += OnCheckBoxToggled;
LightingPresetOption = new OptionButton {MinSize = (100, 0)};
LightingPresetOption.AddItem(Loc.GetString("ui-options-lighting-very-low"));
LightingPresetOption.AddItem(Loc.GetString("ui-options-lighting-low"));
LightingPresetOption.AddItem(Loc.GetString("ui-options-lighting-medium"));
LightingPresetOption.AddItem(Loc.GetString("ui-options-lighting-high"));
LightingPresetOption.OnItemSelected += OnLightingQualityChanged;
contents.AddChild(new HBoxContainer
{
Children =
{
new Label {Text = Loc.GetString("ui-options-lighting-label")},
new Control {MinSize = (4, 0)},
LightingPresetOption
}
});
ApplyButton = new Button
{
Text = Loc.GetString("ui-options-apply"), TextAlign = Label.AlignMode.Center,
HorizontalAlignment = HAlignment.Right
};
_uiScaleOption = new OptionButton();
_uiScaleOption.AddItem(Loc.GetString("ui-options-scale-auto",
("scale", UserInterfaceManager.DefaultUIScale)));
_uiScaleOption.AddItem(Loc.GetString("ui-options-scale-75"));
_uiScaleOption.AddItem(Loc.GetString("ui-options-scale-100"));
_uiScaleOption.AddItem(Loc.GetString("ui-options-scale-125"));
_uiScaleOption.AddItem(Loc.GetString("ui-options-scale-150"));
_uiScaleOption.AddItem(Loc.GetString("ui-options-scale-175"));
_uiScaleOption.AddItem(Loc.GetString("ui-options-scale-200"));
_uiScaleOption.OnItemSelected += OnUIScaleChanged;
contents.AddChild(new HBoxContainer
{
Children =
{
new Label {Text = Loc.GetString("ui-options-scale-label")},
new Control {MinSize = (4, 0)},
_uiScaleOption
}
});
_hudThemeOption = new OptionButton();
foreach (var gear in _prototypeManager.EnumeratePrototypes<HudThemePrototype>())
{
_hudThemeOption.AddItem(Loc.GetString(gear.Name));
}
_hudThemeOption.OnItemSelected += OnHudThemeChanged;
contents.AddChild(new HBoxContainer
{
Children =
{
new Label {Text = Loc.GetString("ui-options-hud-theme")},
new Control {MinSize = (4, 0)},
_hudThemeOption
}
});
_viewportStretchCheckBox = new CheckBox
{
Text = Loc.GetString("ui-options-vp-stretch")
};
_viewportStretchCheckBox.OnToggled += _ =>
{
UpdateViewportScale();
UpdateApplyButton();
};
_viewportScaleSlider = new Slider
{
MinValue = 1,
MaxValue = 5,
Rounded = true,
MinWidth = 200
};
_viewportScaleSlider.OnValueChanged += _ =>
{
UpdateApplyButton();
UpdateViewportScale();
};
_viewportLowResCheckBox = new CheckBox { Text = Loc.GetString("ui-options-vp-low-res")};
_viewportLowResCheckBox.OnToggled += OnCheckBoxToggled;
contents.AddChild(new HBoxContainer
{
Children =
{
_viewportStretchCheckBox,
(_viewportScaleBox = new HBoxContainer
{
Children =
{
(_viewportScaleText = new Label
{
Margin = new Thickness(8, 0)
}),
_viewportScaleSlider,
}
})
}
});
contents.AddChild(_viewportLowResCheckBox);
vBox.AddChild(contents);
vBox.AddChild(new StripeBack
{
HasBottomEdge = false,
HasMargins = false,
Children =
{
ApplyButton
}
});
ApplyButton.OnPressed += OnApplyButtonPressed;
VSyncCheckBox.Pressed = _cfg.GetCVar(CVars.DisplayVSync);
FullscreenCheckBox.Pressed = ConfigIsFullscreen;
LightingPresetOption.SelectId(GetConfigLightingQuality());
_uiScaleOption.SelectId(GetConfigUIScalePreset(ConfigUIScale));
_hudThemeOption.SelectId(_cfg.GetCVar(CCVars.HudTheme));
_viewportScaleSlider.Value = _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
_viewportStretchCheckBox.Pressed = _cfg.GetCVar(CCVars.ViewportStretch);
_viewportLowResCheckBox.Pressed = !_cfg.GetCVar(CCVars.ViewportScaleRender);
UpdateViewportScale();
UpdateApplyButton();
AddChild(vBox);
}
private void OnUIScaleChanged(OptionButton.ItemSelectedEventArgs args)
{
_uiScaleOption.SelectId(args.Id);
UpdateApplyButton();
}
private void OnHudThemeChanged(OptionButton.ItemSelectedEventArgs args)
{
_hudThemeOption.SelectId(args.Id);
UpdateApplyButton();
}
private void OnApplyButtonPressed(BaseButton.ButtonEventArgs args)
{
_cfg.SetCVar(CVars.DisplayVSync, VSyncCheckBox.Pressed);
SetConfigLightingQuality(LightingPresetOption.SelectedId);
if (_hudThemeOption.SelectedId != _cfg.GetCVar(CCVars.HudTheme)) // Don't unnecessarily redraw the HUD
{
_cfg.SetCVar(CCVars.HudTheme, _hudThemeOption.SelectedId);
}
_cfg.SetCVar(CVars.DisplayWindowMode,
(int) (FullscreenCheckBox.Pressed ? WindowMode.Fullscreen : WindowMode.Windowed));
_cfg.SetCVar(CVars.DisplayUIScale, UIScaleOptions[_uiScaleOption.SelectedId]);
_cfg.SetCVar(CCVars.ViewportStretch, _viewportStretchCheckBox.Pressed);
_cfg.SetCVar(CCVars.ViewportFixedScaleFactor, (int) _viewportScaleSlider.Value);
_cfg.SetCVar(CCVars.ViewportScaleRender, !_viewportLowResCheckBox.Pressed);
_cfg.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 == _cfg.GetCVar(CVars.DisplayVSync);
var isFullscreenSame = FullscreenCheckBox.Pressed == ConfigIsFullscreen;
var isLightingQualitySame = LightingPresetOption.SelectedId == GetConfigLightingQuality();
var isHudThemeSame = _hudThemeOption.SelectedId == _cfg.GetCVar(CCVars.HudTheme);
var isUIScaleSame = MathHelper.CloseTo(UIScaleOptions[_uiScaleOption.SelectedId], ConfigUIScale);
var isVPStretchSame = _viewportStretchCheckBox.Pressed == _cfg.GetCVar(CCVars.ViewportStretch);
var isVPScaleSame = (int) _viewportScaleSlider.Value == _cfg.GetCVar(CCVars.ViewportFixedScaleFactor);
var isVPResSame = _viewportLowResCheckBox.Pressed == !_cfg.GetCVar(CCVars.ViewportScaleRender);
ApplyButton.Disabled = isVSyncSame &&
isFullscreenSame &&
isLightingQualitySame &&
isUIScaleSame &&
isVPStretchSame &&
isVPScaleSame &&
isVPResSame &&
isHudThemeSame;
}
private bool ConfigIsFullscreen =>
_cfg.GetCVar(CVars.DisplayWindowMode) == (int) WindowMode.Fullscreen;
private float ConfigUIScale => _cfg.GetCVar(CVars.DisplayUIScale);
private int GetConfigLightingQuality()
{
var val = _cfg.GetCVar(CVars.DisplayLightMapDivider);
var soft = _cfg.GetCVar(CVars.DisplaySoftShadows);
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:
_cfg.SetCVar(CVars.DisplayLightMapDivider, 8);
_cfg.SetCVar(CVars.DisplaySoftShadows, false);
break;
case 1:
_cfg.SetCVar(CVars.DisplayLightMapDivider, 2);
_cfg.SetCVar(CVars.DisplaySoftShadows, false);
break;
case 2:
_cfg.SetCVar(CVars.DisplayLightMapDivider, 2);
_cfg.SetCVar(CVars.DisplaySoftShadows, true);
break;
case 3:
_cfg.SetCVar(CVars.DisplayLightMapDivider, 1);
_cfg.SetCVar(CVars.DisplaySoftShadows, true);
break;
}
}
private static int GetConfigUIScalePreset(float value)
{
for (var i = 0; i < UIScaleOptions.Length; i++)
{
if (MathHelper.CloseTo(UIScaleOptions[i], value))
{
return i;
}
}
return 0;
}
private void UpdateViewportScale()
{
_viewportScaleBox.Visible = !_viewportStretchCheckBox.Pressed;
_viewportScaleText.Text = Loc.GetString("ui-options-vp-scale", ("scale", _viewportScaleSlider.Value));
}
}
}
}

View File

@@ -0,0 +1,491 @@
using System;
using System.Collections.Generic;
using Content.Client.HUD.UI;
using Content.Client.Stylesheets;
using Content.Shared.Input;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.EscapeMenu.UI
{
public sealed partial class OptionsMenu
{
private sealed class KeyRebindControl : Control
{
// List of key functions that must be registered as toggle instead.
private static readonly HashSet<BoundKeyFunction> ToggleFunctions = new()
{
EngineKeyFunctions.ShowDebugMonitors,
EngineKeyFunctions.HideUI,
};
[Dependency] private readonly IInputManager _inputManager = default!;
private BindButton? _currentlyRebinding;
private readonly Dictionary<BoundKeyFunction, KeyControl> _keyControls =
new();
private readonly List<Action> _deferCommands = new();
public KeyRebindControl()
{
IoCManager.InjectDependencies(this);
Button resetAllButton;
var vBox = new VBoxContainer {Margin = new Thickness(2, 0, 0, 0)};
AddChild(new VBoxContainer
{
Children =
{
new ScrollContainer
{
VerticalExpand = true,
Children = {vBox}
},
new StripeBack
{
HasBottomEdge = false,
HasMargins = false,
Children =
{
new HBoxContainer
{
Children =
{
new Control {MinSize = (2, 0)},
new Label
{
StyleClasses = {StyleBase.StyleClassLabelSubText},
Text = Loc.GetString("ui-options-binds-explanation")
},
(resetAllButton = new Button
{
Text = Loc.GetString("ui-options-binds-reset-all"),
StyleClasses = {StyleBase.ButtonCaution},
HorizontalExpand = true,
HorizontalAlignment = HAlignment.Right
})
}
}
}
}
}
});
resetAllButton.OnPressed += _ =>
{
_deferCommands.Add(() =>
{
_inputManager.ResetAllBindings();
_inputManager.SaveToUserData();
});
};
var first = true;
void AddHeader(string headerContents)
{
if (!first)
{
vBox.AddChild(new Control {MinSize = (0, 8)});
}
first = false;
vBox.AddChild(new Label
{
Text = Loc.GetString(headerContents),
FontColorOverride = StyleNano.NanoGold,
StyleClasses = {StyleNano.StyleClassLabelKeyText}
});
}
void AddButton(BoundKeyFunction function)
{
var control = new KeyControl(this, function);
vBox.AddChild(control);
_keyControls.Add(function, control);
}
AddHeader("ui-options-header-movement");
AddButton(EngineKeyFunctions.MoveUp);
AddButton(EngineKeyFunctions.MoveLeft);
AddButton(EngineKeyFunctions.MoveDown);
AddButton(EngineKeyFunctions.MoveRight);
AddButton(EngineKeyFunctions.Walk);
AddHeader("ui-options-header-interaction-basic");
AddButton(EngineKeyFunctions.Use);
AddButton(ContentKeyFunctions.WideAttack);
AddButton(ContentKeyFunctions.ActivateItemInHand);
AddButton(ContentKeyFunctions.ActivateItemInWorld);
AddButton(ContentKeyFunctions.Drop);
AddButton(ContentKeyFunctions.ExamineEntity);
AddButton(ContentKeyFunctions.SwapHands);
AddHeader("ui-options-header-interaction-adv");
AddButton(ContentKeyFunctions.SmartEquipBackpack);
AddButton(ContentKeyFunctions.SmartEquipBelt);
AddButton(ContentKeyFunctions.ThrowItemInHand);
AddButton(ContentKeyFunctions.TryPullObject);
AddButton(ContentKeyFunctions.MovePulledObject);
AddButton(ContentKeyFunctions.ReleasePulledObject);
AddButton(ContentKeyFunctions.Point);
AddHeader("ui-options-header-ui");
AddButton(ContentKeyFunctions.FocusChat);
AddButton(ContentKeyFunctions.FocusLocalChat);
AddButton(ContentKeyFunctions.FocusRadio);
AddButton(ContentKeyFunctions.FocusOOC);
AddButton(ContentKeyFunctions.FocusAdminChat);
AddButton(ContentKeyFunctions.CycleChatChannelForward);
AddButton(ContentKeyFunctions.CycleChatChannelBackward);
AddButton(ContentKeyFunctions.OpenCharacterMenu);
AddButton(ContentKeyFunctions.OpenContextMenu);
AddButton(ContentKeyFunctions.OpenCraftingMenu);
AddButton(ContentKeyFunctions.OpenInventoryMenu);
AddButton(ContentKeyFunctions.OpenInfo);
AddButton(ContentKeyFunctions.OpenActionsMenu);
AddButton(ContentKeyFunctions.OpenEntitySpawnWindow);
AddButton(ContentKeyFunctions.OpenSandboxWindow);
AddButton(ContentKeyFunctions.OpenTileSpawnWindow);
AddButton(ContentKeyFunctions.OpenAdminMenu);
AddHeader("ui-options-header-misc");
AddButton(ContentKeyFunctions.TakeScreenshot);
AddButton(ContentKeyFunctions.TakeScreenshotNoUI);
AddHeader("ui-options-header-hotbar");
AddButton(ContentKeyFunctions.Hotbar1);
AddButton(ContentKeyFunctions.Hotbar2);
AddButton(ContentKeyFunctions.Hotbar3);
AddButton(ContentKeyFunctions.Hotbar4);
AddButton(ContentKeyFunctions.Hotbar5);
AddButton(ContentKeyFunctions.Hotbar6);
AddButton(ContentKeyFunctions.Hotbar7);
AddButton(ContentKeyFunctions.Hotbar8);
AddButton(ContentKeyFunctions.Hotbar9);
AddButton(ContentKeyFunctions.Hotbar0);
AddButton(ContentKeyFunctions.Loadout1);
AddButton(ContentKeyFunctions.Loadout2);
AddButton(ContentKeyFunctions.Loadout3);
AddButton(ContentKeyFunctions.Loadout4);
AddButton(ContentKeyFunctions.Loadout5);
AddButton(ContentKeyFunctions.Loadout6);
AddButton(ContentKeyFunctions.Loadout7);
AddButton(ContentKeyFunctions.Loadout8);
AddButton(ContentKeyFunctions.Loadout9);
AddHeader("ui-options-header-map-editor");
AddButton(EngineKeyFunctions.EditorPlaceObject);
AddButton(EngineKeyFunctions.EditorCancelPlace);
AddButton(EngineKeyFunctions.EditorGridPlace);
AddButton(EngineKeyFunctions.EditorLinePlace);
AddButton(EngineKeyFunctions.EditorRotateObject);
AddHeader("ui-options-header-dev");
AddButton(EngineKeyFunctions.ShowDebugConsole);
AddButton(EngineKeyFunctions.ShowDebugMonitors);
AddButton(EngineKeyFunctions.HideUI);
foreach (var control in _keyControls.Values)
{
UpdateKeyControl(control);
}
}
private void UpdateKeyControl(KeyControl control)
{
var activeBinds = _inputManager.GetKeyBindings(control.Function);
IKeyBinding? bind1 = null;
IKeyBinding? bind2 = null;
if (activeBinds.Count > 0)
{
bind1 = activeBinds[0];
if (activeBinds.Count > 1)
{
bind2 = activeBinds[1];
}
}
control.BindButton1.Binding = bind1;
control.BindButton1.UpdateText();
control.BindButton2.Binding = bind2;
control.BindButton2.UpdateText();
control.BindButton2.Button.Disabled = activeBinds.Count == 0;
control.ResetButton.Disabled = !_inputManager.IsKeyFunctionModified(control.Function);
}
protected override void EnteredTree()
{
base.EnteredTree();
_inputManager.FirstChanceOnKeyEvent += InputManagerOnFirstChanceOnKeyEvent;
_inputManager.OnKeyBindingAdded += OnKeyBindAdded;
_inputManager.OnKeyBindingRemoved += OnKeyBindRemoved;
}
protected override void ExitedTree()
{
base.ExitedTree();
_inputManager.FirstChanceOnKeyEvent -= InputManagerOnFirstChanceOnKeyEvent;
_inputManager.OnKeyBindingAdded -= OnKeyBindAdded;
_inputManager.OnKeyBindingRemoved -= OnKeyBindRemoved;
}
private void OnKeyBindRemoved(IKeyBinding obj)
{
OnKeyBindModified(obj, true);
}
private void OnKeyBindAdded(IKeyBinding obj)
{
OnKeyBindModified(obj, false);
}
private void OnKeyBindModified(IKeyBinding bind, bool removal)
{
if (!_keyControls.TryGetValue(bind.Function, out var keyControl))
{
return;
}
if (removal && _currentlyRebinding?.KeyControl == keyControl)
{
// Don't do update if the removal was from initiating a rebind.
return;
}
UpdateKeyControl(keyControl);
if (_currentlyRebinding == keyControl.BindButton1 || _currentlyRebinding == keyControl.BindButton2)
{
_currentlyRebinding = null;
}
}
private void InputManagerOnFirstChanceOnKeyEvent(KeyEventArgs keyEvent, KeyEventType type)
{
DebugTools.Assert(IsInsideTree);
if (_currentlyRebinding == null)
{
return;
}
keyEvent.Handle();
if (type != KeyEventType.Up)
{
return;
}
var key = keyEvent.Key;
// Figure out modifiers based on key event.
// TODO: this won't allow for combinations with keys other than the standard modifier keys,
// even though the input system totally supports it.
var mods = new Keyboard.Key[3];
var i = 0;
if (keyEvent.Control && key != Keyboard.Key.Control)
{
mods[i] = Keyboard.Key.Control;
i += 1;
}
if (keyEvent.Shift && key != Keyboard.Key.Shift)
{
mods[i] = Keyboard.Key.Shift;
i += 1;
}
if (keyEvent.Alt && key != Keyboard.Key.Alt)
{
mods[i] = Keyboard.Key.Alt;
i += 1;
}
// The input system can only handle 3 modifier keys so if you hold all 4 of the modifier keys
// then system gets the shaft, I guess.
if (keyEvent.System && i != 3 && key != Keyboard.Key.LSystem && key != Keyboard.Key.RSystem)
{
mods[i] = Keyboard.Key.LSystem;
}
var function = _currentlyRebinding.KeyControl.Function;
var bindType = KeyBindingType.State;
if (ToggleFunctions.Contains(function))
{
bindType = KeyBindingType.Toggle;
}
var registration = new KeyBindingRegistration
{
Function = function,
BaseKey = key,
Mod1 = mods[0],
Mod2 = mods[1],
Mod3 = mods[2],
Priority = 0,
Type = bindType,
CanFocus = key == Keyboard.Key.MouseLeft
|| key == Keyboard.Key.MouseRight
|| key == Keyboard.Key.MouseMiddle,
CanRepeat = false
};
_inputManager.RegisterBinding(registration);
// OnKeyBindModified will cause _currentlyRebinding to be reset and the UI to update.
_inputManager.SaveToUserData();
}
private void RebindButtonPressed(BindButton button)
{
if (_currentlyRebinding != null)
{
return;
}
_currentlyRebinding = button;
_currentlyRebinding.Button.Text = Loc.GetString("ui-options-key-prompt");
if (button.Binding != null)
{
_deferCommands.Add(() =>
{
// Have to do defer this or else there will be an exception in InputManager.
// Because this IS fired from an input event.
_inputManager.RemoveBinding(button.Binding);
});
}
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (_deferCommands.Count == 0)
{
return;
}
foreach (var command in _deferCommands)
{
command();
}
_deferCommands.Clear();
}
private sealed class KeyControl : Control
{
public readonly BoundKeyFunction Function;
public readonly BindButton BindButton1;
public readonly BindButton BindButton2;
public readonly Button ResetButton;
public KeyControl(KeyRebindControl parent, BoundKeyFunction function)
{
Function = function;
var name = new Label
{
Text = Loc.GetString(
$"ui-options-function-{CaseConversion.PascalToKebab(function.FunctionName)}"),
HorizontalExpand = true,
HorizontalAlignment = HAlignment.Left
};
BindButton1 = new BindButton(parent, this, StyleBase.ButtonOpenRight);
BindButton2 = new BindButton(parent, this, StyleBase.ButtonOpenLeft);
ResetButton = new Button {Text = Loc.GetString("ui-options-bind-reset"), StyleClasses = {StyleBase.ButtonCaution}};
var hBox = new HBoxContainer
{
Children =
{
new Control {MinSize = (5, 0)},
name,
BindButton1,
BindButton2,
new Control {MinSize = (10, 0)},
ResetButton
}
};
ResetButton.OnPressed += args =>
{
parent._deferCommands.Add(() =>
{
parent._inputManager.ResetBindingsFor(function);
parent._inputManager.SaveToUserData();
});
};
AddChild(hBox);
}
}
private sealed class BindButton : Control
{
private readonly KeyRebindControl _control;
public readonly KeyControl KeyControl;
public readonly Button Button;
public IKeyBinding? Binding;
public BindButton(KeyRebindControl control, KeyControl keyControl, string styleClass)
{
_control = control;
KeyControl = keyControl;
Button = new Button {StyleClasses = {styleClass}};
UpdateText();
AddChild(Button);
Button.OnPressed += args =>
{
control.RebindButtonPressed(this);
};
Button.OnKeyBindDown += ButtonOnOnKeyBindDown;
MinSize = (200, 0);
}
private void ButtonOnOnKeyBindDown(GUIBoundKeyEventArgs args)
{
if (args.Function == EngineKeyFunctions.UIRightClick)
{
if (Binding != null)
{
_control._deferCommands.Add(() =>
{
_control._inputManager.RemoveBinding(Binding);
_control._inputManager.SaveToUserData();
});
}
args.Handle();
}
}
public void UpdateText()
{
Button.Text = Binding?.GetKeyString() ?? Loc.GetString("ui-options-unbound");
}
}
}
}
}

View File

@@ -0,0 +1,45 @@
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Configuration;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Prototypes;
namespace Content.Client.EscapeMenu.UI
{
public sealed partial class OptionsMenu : SS14Window
{
[Dependency] private readonly IConfigurationManager _configManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IClydeAudio _clydeAudio = default!;
public OptionsMenu()
{
SetSize = MinSize = (800, 450);
IoCManager.InjectDependencies(this);
Title = Loc.GetString("ui-options-title");
GraphicsControl graphicsControl;
KeyRebindControl rebindControl;
AudioControl audioControl;
var tabs = new TabContainer
{
Children =
{
(graphicsControl = new GraphicsControl(_configManager, _prototypeManager)),
(rebindControl = new KeyRebindControl()),
(audioControl = new AudioControl(_configManager, _clydeAudio)),
}
};
TabContainer.SetTabTitle(graphicsControl, Loc.GetString("ui-options-tab-graphics"));
TabContainer.SetTabTitle(rebindControl, Loc.GetString("ui-options-tab-controls"));
TabContainer.SetTabTitle(audioControl, Loc.GetString("ui-options-tab-audio"));
Contents.AddChild(tabs);
}
}
}