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:
43
Content.Client/Fullscreen/FullscreenHook.cs
Normal file
43
Content.Client/Fullscreen/FullscreenHook.cs
Normal 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user