]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Added a toggle fullscreen button (default F11) (#20272)
authorMiro Kavaliou <miraslauk@gmail.com>
Thu, 28 Sep 2023 23:55:10 +0000 (19:55 -0400)
committerGitHub <noreply@github.com>
Thu, 28 Sep 2023 23:55:10 +0000 (18:55 -0500)
* Added a toggle fullscreen button (default F11)

* Removed un-needed comments

* Review Requested Changes

* Fixed Acidental Spacing Change

* bwoink, removed extraneous code

* nothing, litterally

Content.Client/Entry/EntryPoint.cs
Content.Client/Fullscreen/FullscreenHook.cs [new file with mode: 0644]
Content.Client/Input/ContentContexts.cs
Content.Client/IoC/ClientContentIoC.cs
Content.Client/Options/UI/OptionsMenu.xaml
Content.Client/Options/UI/OptionsMenu.xaml.cs
Content.Client/Options/UI/Tabs/GraphicsTab.xaml.cs
Content.Client/Options/UI/Tabs/KeyRebindTab.xaml.cs
Content.Client/UserInterface/Systems/EscapeMenu/OptionsUIController.cs
Content.Shared/Input/ContentKeyFunctions.cs
Resources/keybinds.yml

index 5e6852ff2373b64716abba071e70144b6d5e9804..04f0acac971c1e6589062a2382ff3235e2b3ae91 100644 (file)
@@ -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 (file)
index 0000000..78a0151
--- /dev/null
@@ -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}");
+        }
+    }
+}
index 63809f88c1efbf6f1210ace8faa45ced899bd631..8efd977b20690d39a1a4141309a3be426b40ed9a 100644 (file)
@@ -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);
index b98b907cd035714a231b042928345597240ed213..70fe1916584eb44ad57a62c540f9fac64d74cbda 100644 (file)
@@ -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<IClientPreferencesManager, ClientPreferencesManager>();
             IoCManager.Register<IStylesheetManager, StylesheetManager>();
             IoCManager.Register<IScreenshotHook, ScreenshotHook>();
+            IoCManager.Register<FullscreenHook, FullscreenHook>();
             IoCManager.Register<IClickMapManager, ClickMapManager>();
             IoCManager.Register<IClientAdminManager, ClientAdminManager>();
             IoCManager.Register<ISharedAdminManager, ClientAdminManager>();
index 8ecbc6f227ab3cc21f8e623a4fd3ad247d0b880b..5d028879fe886c7ecf22ff4785f5f7f2bd250372 100644 (file)
@@ -3,9 +3,9 @@
             Title="{Loc 'ui-options-title'}"
             MinSize="800 450">
     <TabContainer Name="Tabs" Access="Public">
-        <tabs:GraphicsTab />
-        <tabs:KeyRebindTab />
-        <tabs:AudioTab />
-        <tabs:NetworkTab/>
+        <tabs:GraphicsTab Name="GraphicsTab" />
+        <tabs:KeyRebindTab Name="KeyRebindTab" />
+        <tabs:AudioTab Name="AudioTab" />
+        <tabs:NetworkTab Name="NetworkTab" />
     </TabContainer>
 </DefaultWindow>
index fdb3ac745b9cde9d9017b2e3667d0d594f860183..1a924d2af17ec56c802c4425676ea19e1447f97f 100644 (file)
@@ -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();
         }
     }
 }
index 99076c853d72337c5301f5a6fc410182ceee7806..852a3c28661a87956bbe83851d8ef66c0a6f992e 100644 (file)
@@ -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()
index ba77c431609facd6754ac062aaf656a582d7d919..188fe7740cc6d9cb090a9dfeb8170f7d6c4f1d1c 100644 (file)
@@ -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<BaseButton.ButtonToggledEventArgs>? 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);
 
index 70a9847331aff977da0ae4d1bd59561a15a94bf0..fedd64a43ff6ada032ae0c10516cbe4d5f7c7df7 100644 (file)
@@ -47,6 +47,8 @@ public sealed class OptionsUIController : UIController
     {
         EnsureWindow();
 
+        _optionsWindow.UpdateTabs();
+
         _optionsWindow.OpenCentered();
         _optionsWindow.MoveToFront();
     }
index c50531e29588eb790800bb5082347130911d81a2..840320b0d3b89f1ac8c6b00cc2693b86b027ff09 100644 (file)
@@ -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";
index e3e7a09657bf5f166bc4dd958d5c19139d154a54..1b82435861aa65a1247ea7c029084696b439a5f9 100644 (file)
@@ -89,6 +89,9 @@ binds:
 - function: ShowEscapeMenu
   type: State
   key: F10
+- function: ToggleFullscreen
+  type: State
+  key: F11
 - function: CycleChatChannelForward
   type: State
   key: Tab