2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Construction.UI;
|
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;
|
2022-10-17 15:13:41 -07:00
|
|
|
using Content.Client.UserInterface.Systems.Actions;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Alerts;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Chat;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Ghost;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Hands;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Hotbar;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Hotbar.Widgets;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Inventory;
|
|
|
|
|
using Content.Client.UserInterface.Systems.MenuBar;
|
|
|
|
|
using Content.Client.UserInterface.Systems.Viewport;
|
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;
|
2020-02-26 16:42:12 +01:00
|
|
|
using Robust.Client.UserInterface.Controls;
|
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;
|
2022-10-13 05:37:32 +13:00
|
|
|
using Robust.Client.Player;
|
|
|
|
|
using Robust.Client.GameObjects;
|
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
|
|
|
{
|
2022-09-04 17:21:14 -07:00
|
|
|
public sealed 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-13 05:37:32 +13:00
|
|
|
[Dependency] private readonly IPlayerManager _playerMan = 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!;
|
2022-10-13 05:37:32 +13:00
|
|
|
[Dependency] private readonly IEntityManager _entMan = 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>()!;
|
|
|
|
|
|
|
|
|
|
private readonly GhostUIController _ghostController;
|
|
|
|
|
private readonly ActionUIController _actionController;
|
|
|
|
|
private readonly AlertsUIController _alertsController;
|
|
|
|
|
private readonly HotbarUIController _hotbarController;
|
|
|
|
|
private readonly ChatUIController _chatController;
|
|
|
|
|
private readonly ViewportUIController _viewportController;
|
|
|
|
|
private readonly GameTopMenuBarUIController _menuController;
|
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
|
|
|
|
|
|
|
|
_ghostController = _uiManager.GetUIController<GhostUIController>();
|
|
|
|
|
_actionController = _uiManager.GetUIController<ActionUIController>();
|
|
|
|
|
_alertsController = _uiManager.GetUIController<AlertsUIController>();
|
|
|
|
|
_hotbarController = _uiManager.GetUIController<HotbarUIController>();
|
|
|
|
|
_chatController = _uiManager.GetUIController<ChatUIController>();
|
|
|
|
|
_viewportController = _uiManager.GetUIController<ViewportUIController>();
|
|
|
|
|
_menuController = _uiManager.GetUIController<GameTopMenuBarUIController>();
|
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()
|
|
|
|
|
{
|
|
|
|
|
_chatController.SetMainChat(false);
|
|
|
|
|
_menuController.UnloadButtons();
|
2022-10-17 18:01:28 -07:00
|
|
|
_ghostController.UnloadGui();
|
|
|
|
|
_actionController.UnloadGui();
|
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
|
|
|
|
2022-10-17 15:13:41 -07:00
|
|
|
_chatController.SetMainChat(true);
|
|
|
|
|
_viewportController.ReloadViewport();
|
|
|
|
|
_menuController.LoadButtons();
|
|
|
|
|
|
|
|
|
|
// TODO: This could just be like, the equivalent of an event or something
|
2022-10-17 18:01:28 -07:00
|
|
|
_ghostController.LoadGui();
|
|
|
|
|
_actionController.LoadGui();
|
2022-10-17 15:13:41 -07:00
|
|
|
_alertsController.SyncAlerts();
|
|
|
|
|
_hotbarController.ReloadHotbar();
|
|
|
|
|
|
|
|
|
|
var viewportContainer = _uiManager.ActiveScreen!.FindControl<LayoutContainer>("ViewportContainer");
|
|
|
|
|
_chatController.SetSpeechBubbleRoot(viewportContainer);
|
2021-04-19 09:52:40 +02:00
|
|
|
}
|
2021-04-29 15:01:13 -07:00
|
|
|
|
2022-10-17 15:13:41 -07: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
|
|
|
}
|
|
|
|
|
}
|