Files

121 lines
4.0 KiB
C#
Raw Permalink Normal View History

using Content.Client.Hands;
2022-09-11 20:42:12 -07:00
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Screens;
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.Viewport;
using Content.Shared.CCVar;
2021-04-19 09:52:40 +02:00
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;
2021-02-16 20:14:32 +01:00
using Robust.Shared.Configuration;
2021-04-19 09:52:40 +02:00
using Robust.Shared.Timing;
2019-12-06 00:41:30 +01:00
namespace Content.Client.Gameplay
2019-12-06 00:41:30 +01:00
{
2023-06-05 16:33:49 +12:00
[Virtual]
public class GameplayState : GameplayStateBase, IMainViewportState
2019-12-06 00:41:30 +01:00
{
2021-04-19 09:52:40 +02:00
[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!;
2019-12-06 00:41:30 +01:00
private FpsCounter _fpsCounter = default!;
public MainViewport Viewport => _uiManager.ActiveScreen!.GetWidget<MainViewport>()!;
private readonly GameplayStateLoadController _loadController;
2021-04-19 09:52:40 +02:00
public GameplayState()
{
IoCManager.InjectDependencies(this);
_loadController = _uiManager.GetUIController<GameplayStateLoadController>();
}
protected override void Startup()
2019-12-06 00:41:30 +01:00
{
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; });
2022-10-17 23:45:32 -07:00
_configurationManager.OnValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
2019-12-06 00:41:30 +01:00
}
protected override void Shutdown()
2019-12-06 00:41:30 +01:00
{
_overlayManager.RemoveOverlay<ShowHandItemOverlay>();
base.Shutdown();
2021-04-19 09:52:40 +02:00
// Clear viewport to some fallback, whatever.
_eyeManager.MainViewport = UserInterfaceManager.MainViewport;
_fpsCounter.Dispose();
_uiManager.ClearWindows();
2022-10-17 23:45:32 -07:00
_configurationManager.UnsubValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
UnloadMainScreen();
}
2021-04-19 09:52:40 +02:00
2022-10-17 23:45:32 -07:00
private void ReloadMainScreenValueChange(string _)
{
ReloadMainScreen();
}
public void ReloadMainScreen()
2021-04-19 09:52:40 +02:00
{
2022-10-17 23:45:32 -07:00
if (_uiManager.ActiveScreen?.GetWidget<MainViewport>() == null)
{
return;
}
2021-04-19 09:52:40 +02:00
UnloadMainScreen();
LoadMainScreen();
}
2022-10-13 05:37:32 +13:00
private void UnloadMainScreen()
{
_loadController.UnloadScreen();
_uiManager.UnloadScreen();
}
2022-10-13 05:37:32 +13:00
private void LoadMainScreen()
{
var screenTypeString = _configurationManager.GetCVar(CCVars.UILayout);
if (!Enum.TryParse(screenTypeString, out ScreenType screenType))
{
screenType = default;
}
2022-10-13 05:37:32 +13:00
switch (screenType)
{
case ScreenType.Default:
_uiManager.LoadScreen<DefaultGameScreen>();
break;
case ScreenType.Separated:
_uiManager.LoadScreen<SeparatedChatGameScreen>();
break;
}
2022-10-13 05:37:32 +13:00
_loadController.LoadScreen();
2021-04-19 09:52:40 +02:00
}
protected override void OnKeyBindStateChanged(ViewportBoundKeyEventArgs args)
{
if (args.Viewport == null)
base.OnKeyBindStateChanged(new ViewportBoundKeyEventArgs(args.KeyEventArgs, Viewport.Viewport));
else
base.OnKeyBindStateChanged(args);
}
2019-12-06 00:41:30 +01:00
}
}