From: Miro Kavaliou Date: Thu, 28 Sep 2023 23:55:10 +0000 (-0400) Subject: Added a toggle fullscreen button (default F11) (#20272) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=c06586f94296250e9585b5cb7e2ad64b92e9f59b;p=space-station-14.git Added a toggle fullscreen button (default F11) (#20272) * Added a toggle fullscreen button (default F11) * Removed un-needed comments * Review Requested Changes * Fixed Acidental Spacing Change * bwoink, removed extraneous code * nothing, litterally --- diff --git a/Content.Client/Entry/EntryPoint.cs b/Content.Client/Entry/EntryPoint.cs index 5e6852ff23..04f0acac97 100644 --- a/Content.Client/Entry/EntryPoint.cs +++ b/Content.Client/Entry/EntryPoint.cs @@ -3,6 +3,7 @@ using Content.Client.Changelog; using Content.Client.Chat.Managers; using Content.Client.Eui; using Content.Client.Flash; +using Content.Client.Fullscreen; using Content.Client.GhostKick; using Content.Client.Guidebook; using Content.Client.Info; @@ -49,6 +50,7 @@ namespace Content.Client.Entry [Dependency] private readonly IConfigurationManager _configManager = default!; [Dependency] private readonly IStylesheetManager _stylesheetManager = default!; [Dependency] private readonly IScreenshotHook _screenshotHook = default!; + [Dependency] private readonly FullscreenHook _fullscreenHook = default!; [Dependency] private readonly ChangelogManager _changelogManager = default!; [Dependency] private readonly RulesManager _rulesManager = default!; [Dependency] private readonly ViewportManager _viewportManager = default!; @@ -123,6 +125,7 @@ namespace Content.Client.Entry _componentFactory.GenerateNetIds(); _adminManager.Initialize(); _screenshotHook.Initialize(); + _fullscreenHook.Initialize(); _changelogManager.Initialize(); _rulesManager.Initialize(); _viewportManager.Initialize(); diff --git a/Content.Client/Fullscreen/FullscreenHook.cs b/Content.Client/Fullscreen/FullscreenHook.cs new file mode 100644 index 0000000000..78a0151736 --- /dev/null +++ b/Content.Client/Fullscreen/FullscreenHook.cs @@ -0,0 +1,43 @@ +using Content.Shared.Input; +using Robust.Client.Graphics; +using Robust.Client.Input; +using Robust.Shared.Input.Binding; +using Robust.Shared; +using Robust.Shared.Configuration; +using Robust.Shared.Players; + +namespace Content.Client.Fullscreen; +public sealed class FullscreenHook +{ + [Dependency] private readonly IInputManager _inputManager = default!; + [Dependency] private readonly IConfigurationManager _cfg = default!; + [Dependency] private readonly ILogManager _logManager = default!; + private ISawmill _sawmill = default!; + + public void Initialize() + { + _inputManager.SetInputCommand(ContentKeyFunctions.ToggleFullscreen, InputCmdHandler.FromDelegate(ToggleFullscreen)); + _sawmill = _logManager.GetSawmill("fullscreen"); + } + + private void ToggleFullscreen(ICommonSession? session) + { + var currentWindowMode = _cfg.GetCVar(CVars.DisplayWindowMode); + + switch (currentWindowMode) + { + case (int) WindowMode.Windowed: + _cfg.SetCVar(CVars.DisplayWindowMode, (int) WindowMode.Fullscreen); + _sawmill.Info("Switched to Fullscreen mode"); + break; + + case (int) WindowMode.Fullscreen: + _cfg.SetCVar(CVars.DisplayWindowMode, (int) WindowMode.Windowed); + _sawmill.Info("Switched to Windowed mode"); + break; + + default: + throw new InvalidOperationException($"Unexpected WindowMode value: {currentWindowMode}"); + } + } +} diff --git a/Content.Client/Input/ContentContexts.cs b/Content.Client/Input/ContentContexts.cs index 63809f88c1..8efd977b20 100644 --- a/Content.Client/Input/ContentContexts.cs +++ b/Content.Client/Input/ContentContexts.cs @@ -29,6 +29,7 @@ namespace Content.Client.Input common.AddFunction(ContentKeyFunctions.OpenAHelp); common.AddFunction(ContentKeyFunctions.TakeScreenshot); common.AddFunction(ContentKeyFunctions.TakeScreenshotNoUI); + common.AddFunction(ContentKeyFunctions.ToggleFullscreen); common.AddFunction(ContentKeyFunctions.Point); common.AddFunction(ContentKeyFunctions.ZoomOut); common.AddFunction(ContentKeyFunctions.ZoomIn); diff --git a/Content.Client/IoC/ClientContentIoC.cs b/Content.Client/IoC/ClientContentIoC.cs index b98b907cd0..70fe191658 100644 --- a/Content.Client/IoC/ClientContentIoC.cs +++ b/Content.Client/IoC/ClientContentIoC.cs @@ -11,6 +11,7 @@ using Content.Client.Parallax.Managers; using Content.Client.Players.PlayTimeTracking; using Content.Client.Preferences; using Content.Client.Screenshot; +using Content.Client.Fullscreen; using Content.Client.Stylesheets; using Content.Client.Viewport; using Content.Client.Voting; @@ -21,6 +22,7 @@ using Content.Client.Guidebook; using Content.Client.Replay; using Content.Shared.Administration.Managers; + namespace Content.Client.IoC { internal static class ClientContentIoC @@ -32,6 +34,7 @@ namespace Content.Client.IoC IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); + IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Client/Options/UI/OptionsMenu.xaml b/Content.Client/Options/UI/OptionsMenu.xaml index 8ecbc6f227..5d028879fe 100644 --- a/Content.Client/Options/UI/OptionsMenu.xaml +++ b/Content.Client/Options/UI/OptionsMenu.xaml @@ -3,9 +3,9 @@ Title="{Loc 'ui-options-title'}" MinSize="800 450"> - - - - + + + + diff --git a/Content.Client/Options/UI/OptionsMenu.xaml.cs b/Content.Client/Options/UI/OptionsMenu.xaml.cs index fdb3ac745b..1a924d2af1 100644 --- a/Content.Client/Options/UI/OptionsMenu.xaml.cs +++ b/Content.Client/Options/UI/OptionsMenu.xaml.cs @@ -1,6 +1,9 @@ using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; +using Robust.Shared.IoC; +using Content.Client.Options.UI.Tabs; + namespace Content.Client.Options.UI { @@ -16,6 +19,13 @@ namespace Content.Client.Options.UI Tabs.SetTabTitle(1, Loc.GetString("ui-options-tab-controls")); Tabs.SetTabTitle(2, Loc.GetString("ui-options-tab-audio")); Tabs.SetTabTitle(3, Loc.GetString("ui-options-tab-network")); + + UpdateTabs(); + } + + public void UpdateTabs() + { + GraphicsTab.UpdateProperties(); } } } diff --git a/Content.Client/Options/UI/Tabs/GraphicsTab.xaml.cs b/Content.Client/Options/UI/Tabs/GraphicsTab.xaml.cs index 99076c853d..852a3c2866 100644 --- a/Content.Client/Options/UI/Tabs/GraphicsTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/GraphicsTab.xaml.cs @@ -229,6 +229,12 @@ namespace Content.Client.Options.UI.Tabs private bool ConfigIsFullscreen => _cfg.GetCVar(CVars.DisplayWindowMode) == (int) WindowMode.Fullscreen; + public void UpdateProperties() + { + FullscreenCheckBox.Pressed = ConfigIsFullscreen; + } + + private float ConfigUIScale => _cfg.GetCVar(CVars.DisplayUIScale); private int GetConfigLightingQuality() diff --git a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs index ba77c43160..188fe7740c 100644 --- a/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs +++ b/Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs @@ -61,7 +61,7 @@ namespace Content.Client.Options.UI.Tabs { if (!first) { - KeybindsContainer.AddChild(new Control {MinSize = new Vector2(0, 8)}); + KeybindsContainer.AddChild(new Control { MinSize = new Vector2(0, 8) }); } first = false; @@ -69,7 +69,7 @@ namespace Content.Client.Options.UI.Tabs { Text = Loc.GetString(headerContents), FontColorOverride = StyleNano.NanoGold, - StyleClasses = {StyleNano.StyleClassLabelKeyText} + StyleClasses = { StyleNano.StyleClassLabelKeyText } }); } @@ -82,7 +82,7 @@ namespace Content.Client.Options.UI.Tabs void AddCheckBox(string checkBoxName, bool currentState, Action? callBackOnClick) { - CheckBox newCheckBox = new CheckBox() { Text = Loc.GetString(checkBoxName)}; + CheckBox newCheckBox = new CheckBox() { Text = Loc.GetString(checkBoxName) }; newCheckBox.Pressed = currentState; newCheckBox.OnToggled += callBackOnClick; @@ -159,6 +159,7 @@ namespace Content.Client.Options.UI.Tabs AddHeader("ui-options-header-misc"); AddButton(ContentKeyFunctions.TakeScreenshot); AddButton(ContentKeyFunctions.TakeScreenshotNoUI); + AddButton(ContentKeyFunctions.ToggleFullscreen); AddHeader("ui-options-header-hotbar"); foreach (var boundKey in ContentKeyFunctions.GetHotbarBoundKeys()) @@ -409,7 +410,7 @@ namespace Content.Client.Options.UI.Tabs 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}}; + ResetButton = new Button { Text = Loc.GetString("ui-options-bind-reset"), StyleClasses = { StyleBase.ButtonCaution } }; var hBox = new BoxContainer { @@ -449,7 +450,7 @@ namespace Content.Client.Options.UI.Tabs { _tab = tab; KeyControl = keyControl; - Button = new Button {StyleClasses = {styleClass}}; + Button = new Button { StyleClasses = { styleClass } }; UpdateText(); AddChild(Button); diff --git a/Content.Client/UserInterface/Systems/EscapeMenu/OptionsUIController.cs b/Content.Client/UserInterface/Systems/EscapeMenu/OptionsUIController.cs index 70a9847331..fedd64a43f 100644 --- a/Content.Client/UserInterface/Systems/EscapeMenu/OptionsUIController.cs +++ b/Content.Client/UserInterface/Systems/EscapeMenu/OptionsUIController.cs @@ -47,6 +47,8 @@ public sealed class OptionsUIController : UIController { EnsureWindow(); + _optionsWindow.UpdateTabs(); + _optionsWindow.OpenCentered(); _optionsWindow.MoveToFront(); } diff --git a/Content.Shared/Input/ContentKeyFunctions.cs b/Content.Shared/Input/ContentKeyFunctions.cs index c50531e295..840320b0d3 100644 --- a/Content.Shared/Input/ContentKeyFunctions.cs +++ b/Content.Shared/Input/ContentKeyFunctions.cs @@ -44,6 +44,7 @@ namespace Content.Shared.Input public static readonly BoundKeyFunction OpenAdminMenu = "OpenAdminMenu"; public static readonly BoundKeyFunction TakeScreenshot = "TakeScreenshot"; public static readonly BoundKeyFunction TakeScreenshotNoUI = "TakeScreenshotNoUI"; + public static readonly BoundKeyFunction ToggleFullscreen = "ToggleFullscreen"; public static readonly BoundKeyFunction Point = "Point"; public static readonly BoundKeyFunction ZoomOut = "ZoomOut"; public static readonly BoundKeyFunction ZoomIn = "ZoomIn"; diff --git a/Resources/keybinds.yml b/Resources/keybinds.yml index e3e7a09657..1b82435861 100644 --- a/Resources/keybinds.yml +++ b/Resources/keybinds.yml @@ -89,6 +89,9 @@ binds: - function: ShowEscapeMenu type: State key: F10 +- function: ToggleFullscreen + type: State + key: F11 - function: CycleChatChannelForward type: State key: Tab