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
This commit is contained in:
Miro Kavaliou
2023-09-28 19:55:10 -04:00
committed by GitHub
parent 3477349dfe
commit c06586f942
11 changed files with 82 additions and 9 deletions

View 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();

View File

@@ -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}");
}
}
}

View 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);

View 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>();

View 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>

View 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();
}
}
}

View 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()

View 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);

View File

@@ -47,6 +47,8 @@ public sealed class OptionsUIController : UIController
{
EnsureWindow();
_optionsWindow.UpdateTabs();
_optionsWindow.OpenCentered();
_optionsWindow.MoveToFront();
}

View 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";

View File

@@ -89,6 +89,9 @@ binds:
- function: ShowEscapeMenu
type: State
key: F10
- function: ToggleFullscreen
type: State
key: F11
- function: CycleChatChannelForward
type: State
key: Tab