2021-10-22 04:26:02 +02:00
|
|
|
using Content.Client.Hands;
|
2022-09-11 20:42:12 -07:00
|
|
|
using Content.Client.UserInterface.Controls;
|
2022-10-12 01:16:23 -07:00
|
|
|
using Content.Client.UserInterface.Screens;
|
2023-03-10 19:25:56 -08:00
|
|
|
using Content.Client.UserInterface.Systems.Gameplay;
|
2022-09-04 17:21:14 -07:00
|
|
|
using Content.Client.Viewport;
|
2021-11-30 14:31:13 +03:00
|
|
|
using Content.Shared.CCVar;
|
2021-04-19 09:52:40 +02:00
|
|
|
using Robust.Client.Graphics;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Input;
|
|
|
|
|
using Robust.Client.UserInterface;
|
2021-11-30 14:31:13 +03:00
|
|
|
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
|
|
|
|
2022-09-04 17:21:14 -07: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!;
|
2021-10-22 04:26:02 +02:00
|
|
|
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
2021-11-30 14:31:13 +03:00
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2022-10-12 01:16:23 -07:00
|
|
|
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
|
2021-11-30 14:31:13 +03:00
|
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
2019-12-06 00:41:30 +01:00
|
|
|
|
2021-11-30 14:31:13 +03:00
|
|
|
private FpsCounter _fpsCounter = default!;
|
|
|
|
|
|
2022-10-17 15:13:41 -07:00
|
|
|
public MainViewport Viewport => _uiManager.ActiveScreen!.GetWidget<MainViewport>()!;
|
|
|
|
|
|
2023-03-10 19:25:56 -08:00
|
|
|
private readonly GameplayStateLoadController _loadController;
|
2021-04-19 09:52:40 +02:00
|
|
|
|
2022-10-12 01:16:23 -07:00
|
|
|
public GameplayState()
|
|
|
|
|
{
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
2022-10-17 15:13:41 -07:00
|
|
|
|
2023-03-10 19:25:56 -08:00
|
|
|
_loadController = _uiManager.GetUIController<GameplayStateLoadController>();
|
2022-10-12 01:16:23 -07:00
|
|
|
}
|
|
|
|
|
|
2022-09-04 16:17:05 -07:00
|
|
|
protected override void Startup()
|
2019-12-06 00:41:30 +01:00
|
|
|
{
|
2020-02-26 16:42:12 +01:00
|
|
|
base.Startup();
|
2022-10-17 15:13:41 -07:00
|
|
|
|
|
|
|
|
LoadMainScreen();
|
|
|
|
|
|
|
|
|
|
// Add the hand-item overlay.
|
2021-10-22 04:26:02 +02:00
|
|
|
_overlayManager.AddOverlay(new ShowHandItemOverlay());
|
2022-10-17 15:13:41 -07:00
|
|
|
|
|
|
|
|
// FPS counter.
|
|
|
|
|
// yeah this can just stay here, whatever
|
2021-11-30 14:31:13 +03:00
|
|
|
_fpsCounter = new FpsCounter(_gameTiming);
|
2022-10-12 01:16:23 -07:00
|
|
|
UserInterfaceManager.PopupRoot.AddChild(_fpsCounter);
|
2021-11-30 14:31:13 +03:00
|
|
|
_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
|
|
|
}
|
|
|
|
|
|
2022-09-04 16:17:05 -07:00
|
|
|
protected override void Shutdown()
|
2019-12-06 00:41:30 +01:00
|
|
|
{
|
2021-10-22 04:26:02 +02:00
|
|
|
_overlayManager.RemoveOverlay<ShowHandItemOverlay>();
|
2021-02-20 12:05:59 -08:00
|
|
|
|
2020-02-26 16:42:12 +01:00
|
|
|
base.Shutdown();
|
2021-04-19 09:52:40 +02:00
|
|
|
// Clear viewport to some fallback, whatever.
|
2022-10-12 01:16:23 -07:00
|
|
|
_eyeManager.MainViewport = UserInterfaceManager.MainViewport;
|
2021-11-30 14:31:13 +03:00
|
|
|
_fpsCounter.Dispose();
|
2022-10-12 01:16:23 -07:00
|
|
|
_uiManager.ClearWindows();
|
2022-10-17 23:45:32 -07:00
|
|
|
_configurationManager.UnsubValueChanged(CCVars.UILayout, ReloadMainScreenValueChange);
|
2022-10-17 15:13:41 -07:00
|
|
|
UnloadMainScreen();
|
2020-07-08 05:18:16 -05:00
|
|
|
}
|
2021-04-19 09:52:40 +02:00
|
|
|
|
2022-10-17 23:45:32 -07:00
|
|
|
private void ReloadMainScreenValueChange(string _)
|
|
|
|
|
{
|
|
|
|
|
ReloadMainScreen();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-17 15:13:41 -07:00
|
|
|
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)
|
2022-10-17 15:13:41 -07:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-04-19 09:52:40 +02:00
|
|
|
|
2022-10-17 15:13:41 -07:00
|
|
|
UnloadMainScreen();
|
|
|
|
|
LoadMainScreen();
|
|
|
|
|
}
|
2022-10-13 05:37:32 +13:00
|
|
|
|
2022-10-17 15:13:41 -07:00
|
|
|
private void UnloadMainScreen()
|
|
|
|
|
{
|
2023-03-10 19:25:56 -08:00
|
|
|
_loadController.UnloadScreen();
|
2022-10-17 15:13:41 -07:00
|
|
|
_uiManager.UnloadScreen();
|
|
|
|
|
}
|
2022-10-13 05:37:32 +13:00
|
|
|
|
2022-10-17 15:13:41 -07: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
|
|
|
|
2022-10-17 15:13:41 -07: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
|
|
|
|
2023-03-10 19:25:56 -08:00
|
|
|
_loadController.LoadScreen();
|
2021-04-19 09:52:40 +02:00
|
|
|
}
|
2021-04-29 15:01:13 -07: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
|
|
|
}
|
|
|
|
|
}
|