Files
wwdpublic/Content.Client/Gameplay/GameplayState.cs
DEATHB4DEFEAT 544fd135de Default to Separated UI Layout (#433)
# Description

<sub>~~Change from Nyano~~</sub>
Uses space a lot better. The old layout still exists if people want it
for whatever reason.
I also renamed "Default" to "Overlay", which should stay anyway if the
default change is denied.

---

<details><summary><h1>Media</h1></summary>
<p>

## Separated


![image](https://github.com/Simple-Station/Einstein-Engines/assets/77995199/b97c4373-99ac-4ac5-80a5-149122238551)

## Overlay


![image](https://github.com/Simple-Station/Einstein-Engines/assets/77995199/3891756f-91f0-4336-b075-6c461ee1b8e6)

</p>
</details>

---

# Changelog

🆑
- tweak: UI layout now defaults to separated, the old one is still
available in settings
2024-06-16 18:38:10 -04:00

121 lines
4.0 KiB
C#

using Content.Client.Hands;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Screens;
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.Viewport;
using Content.Shared.CCVar;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;
namespace Content.Client.Gameplay
{
[Virtual]
public class GameplayState : GameplayStateBase, IMainViewportState
{
[Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IOverlayManager _overlayManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
private FpsCounter _fpsCounter = default!;
public MainViewport Viewport => _uiManager.ActiveScreen!.GetWidget<MainViewport>()!;
private readonly GameplayStateLoadController _loadController;
public GameplayState()
{
IoCManager.InjectDependencies(this);
_loadController = _uiManager.GetUIController<GameplayStateLoadController>();
}
protected override void Startup()
{
base.Startup();
LoadMainScreen();
// Add the hand-item overlay.
_overlayManager.AddOverlay(new ShowHandItemOverlay());
// FPS counter.
// yeah this can just stay here, whatever
_fpsCounter = new FpsCounter(_gameTiming);
UserInterfaceManager.PopupRoot.AddChild(_fpsCounter);
_fpsCounter.Visible = _configurationManager.GetCVar(CCVars.HudFpsCounterVisible);
_configurationManager.OnValueChanged(CCVars.HudFpsCounterVisible, (show) => { _fpsCounter.Visible = show; });
_configurationManager.OnValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
}
protected override void Shutdown()
{
_overlayManager.RemoveOverlay<ShowHandItemOverlay>();
base.Shutdown();
// Clear viewport to some fallback, whatever.
_eyeManager.MainViewport = UserInterfaceManager.MainViewport;
_fpsCounter.Dispose();
_uiManager.ClearWindows();
_configurationManager.UnsubValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
UnloadMainScreen();
}
private void ReloadMainScreenValueChange(string _)
{
ReloadMainScreen();
}
public void ReloadMainScreen()
{
if (_uiManager.ActiveScreen?.GetWidget<MainViewport>() == null)
{
return;
}
UnloadMainScreen();
LoadMainScreen();
}
private void UnloadMainScreen()
{
_loadController.UnloadScreen();
_uiManager.UnloadScreen();
}
private void LoadMainScreen()
{
var screenTypeString = _configurationManager.GetCVar(CCVars.UILayout);
if (!Enum.TryParse(screenTypeString, out ScreenType screenType))
{
screenType = ScreenType.Separated;
}
switch (screenType)
{
case ScreenType.Separated:
_uiManager.LoadScreen<SeparatedChatGameScreen>();
break;
case ScreenType.Overlay:
_uiManager.LoadScreen<OverlayChatGameScreen>();
break;
}
_loadController.LoadScreen();
}
protected override void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)
{
if (args.Viewport == null)
base.OnKeyBindStateChanged(new ViewportBoundKeyEventArgs(args.KeyEventArgs, Viewport.Viewport));
else
base.OnKeyBindStateChanged(args);
}
}
}