Hud refactor (#7202)

Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
Co-authored-by: Jezithyr <jmaster9999@gmail.com>
Co-authored-by: Jezithyr <Jezithyr@gmail.com>
Co-authored-by: Visne <39844191+Visne@users.noreply.github.com>
Co-authored-by: wrexbe <wrexbe@protonmail.com>
Co-authored-by: wrexbe <81056464+wrexbe@users.noreply.github.com>
This commit is contained in:
Jezithyr
2022-10-12 01:16:23 -07:00
committed by GitHub
parent d09fbc1849
commit 571dd4e6d5
168 changed files with 6940 additions and 7817 deletions

View File

@@ -1,14 +1,8 @@
using Content.Client.Alerts.UI;
using Content.Client.Chat;
using Content.Client.Chat.Managers;
using Content.Client.Chat.UI;
using Content.Client.Construction.UI;
using Content.Client.Hands;
using Content.Client.HUD;
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Screens;
using Content.Client.Viewport;
using Content.Client.Voting;
using Content.Shared.Chat;
using Content.Shared.CCVar;
using Robust.Client.Graphics;
using Robust.Client.Input;
@@ -22,40 +16,26 @@ namespace Content.Client.Gameplay
{
public sealed class GameplayState : GameplayStateBase, IMainViewportState
{
public static readonly Vector2i ViewportSize = (EyeManager.PixelsPerMeter * 21, EyeManager.PixelsPerMeter * 15);
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IGameHud _gameHud = default!;
[Dependency] private readonly IInputManager _inputManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly IVoteManager _voteManager = default!;
[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!;
[ViewVariables] private ChatBox? _gameChat;
private ConstructionMenuPresenter? _constructionMenu;
private AlertsFramePresenter? _alertsFramePresenter;
protected override Type? LinkedScreenType => typeof(DefaultGameScreen);
public static readonly Vector2i ViewportSize = (EyeManager.PixelsPerMeter * 21, EyeManager.PixelsPerMeter * 15);
private FpsCounter _fpsCounter = default!;
public MainViewport Viewport { get; private set; } = default!;
public GameplayState()
{
IoCManager.InjectDependencies(this);
}
protected override void Startup()
{
base.Startup();
_gameChat = new HudChatBox {PreferredChannel = ChatSelectChannel.Local};
UserInterfaceManager.StateRoot.AddChild(_gameChat);
LayoutContainer.SetAnchorAndMarginPreset(_gameChat, LayoutContainer.LayoutPreset.TopRight, margin: 10);
LayoutContainer.SetAnchorAndMarginPreset(_gameChat, LayoutContainer.LayoutPreset.TopRight, margin: 10);
LayoutContainer.SetMarginLeft(_gameChat, -475);
LayoutContainer.SetMarginBottom(_gameChat, HudChatBox.InitialChatBottom);
_chatManager.ChatBoxOnResized(new ChatResizedEventArgs(HudChatBox.InitialChatBottom));
Viewport = new MainViewport
{
Viewport =
@@ -63,25 +43,13 @@ namespace Content.Client.Gameplay
ViewportSize = ViewportSize
}
};
_userInterfaceManager.StateRoot.AddChild(Viewport);
UserInterfaceManager.StateRoot.AddChild(Viewport);
LayoutContainer.SetAnchorPreset(Viewport, LayoutContainer.LayoutPreset.Wide);
Viewport.SetPositionFirst();
_userInterfaceManager.StateRoot.AddChild(_gameHud.RootControl);
_chatManager.SetChatBox(_gameChat);
_voteManager.SetPopupContainer(_gameHud.VoteContainer);
ChatInput.SetupChatInputHandlers(_inputManager, _gameChat);
SetupPresenters();
_eyeManager.MainViewport = Viewport.Viewport;
_overlayManager.AddOverlay(new ShowHandItemOverlay());
_fpsCounter = new FpsCounter(_gameTiming);
_userInterfaceManager.StateRoot.AddChild(_fpsCounter);
UserInterfaceManager.PopupRoot.AddChild(_fpsCounter);
_fpsCounter.Visible = _configurationManager.GetCVar(CCVars.HudFpsCounterVisible);
_configurationManager.OnValueChanged(CCVars.HudFpsCounterVisible, (show) => { _fpsCounter.Visible = show; });
}
@@ -89,56 +57,13 @@ namespace Content.Client.Gameplay
protected override void Shutdown()
{
_overlayManager.RemoveOverlay<ShowHandItemOverlay>();
DisposePresenters();
base.Shutdown();
_gameChat?.Dispose();
Viewport.Dispose();
_gameHud.RootControl.Orphan();
// Clear viewport to some fallback, whatever.
_eyeManager.MainViewport = _userInterfaceManager.MainViewport;
_eyeManager.MainViewport = UserInterfaceManager.MainViewport;
_fpsCounter.Dispose();
}
/// <summary>
/// All UI Presenters should be constructed in here.
/// </summary>
private void SetupPresenters()
{
// HUD
_alertsFramePresenter = new AlertsFramePresenter();
// Windows
_constructionMenu = new ConstructionMenuPresenter(_gameHud);
}
/// <summary>
/// All UI Presenters should be disposed in here.
/// </summary>
private void DisposePresenters()
{
// Windows
_constructionMenu?.Dispose();
// HUD
_alertsFramePresenter?.Dispose();
}
internal static void FocusChat(ChatBox chat)
{
if (chat.UserInterfaceManager.KeyboardFocused != null)
return;
chat.Focus();
}
internal static void FocusChannel(ChatBox chat, ChatSelectChannel channel)
{
if (chat.UserInterfaceManager.KeyboardFocused != null)
return;
chat.Focus(channel);
_uiManager.ClearWindows();
}
public override void FrameUpdate(FrameEventArgs e)