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:
@@ -10,15 +10,13 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class GhostTargetWindow : DefaultWindow
|
||||
{
|
||||
private readonly IEntityNetworkManager _netManager;
|
||||
|
||||
private List<(string, EntityUid)> _warps = new();
|
||||
|
||||
public GhostTargetWindow(IEntityNetworkManager netManager)
|
||||
public event Action<EntityUid>? WarpClicked;
|
||||
|
||||
public GhostTargetWindow()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
_netManager = netManager;
|
||||
}
|
||||
|
||||
public void UpdateWarps(IEnumerable<GhostWarp> warps)
|
||||
@@ -47,7 +45,7 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
|
||||
|
||||
private void AddButtons()
|
||||
{
|
||||
foreach (var (name, warp) in _warps)
|
||||
foreach (var (name, warpTarget) in _warps)
|
||||
{
|
||||
var currentButtonRef = new Button
|
||||
{
|
||||
@@ -60,11 +58,7 @@ namespace Content.Client.UserInterface.Systems.Ghost.Controls
|
||||
ClipText = true,
|
||||
};
|
||||
|
||||
currentButtonRef.OnPressed += _ =>
|
||||
{
|
||||
var msg = new GhostWarpToTargetRequestEvent(warp);
|
||||
_netManager.SendSystemNetworkMessage(msg);
|
||||
};
|
||||
currentButtonRef.OnPressed += _ => WarpClicked?.Invoke(warpTarget);
|
||||
|
||||
ButtonContainer.AddChild(currentButtonRef);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Shared.Configuration;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using Content.Shared.Ghost.Roles;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using Content.Shared.Ghost.Roles;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
|
||||
@@ -4,8 +4,6 @@ using Content.Shared.Ghost.Roles;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.GameObjects;
|
||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
using Content.Client.Ghost;
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface.Systems.Ghost.Controls;
|
||||
using Content.Shared.Ghost;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Ghost
|
||||
{
|
||||
public sealed class GhostGui : Control
|
||||
{
|
||||
private readonly Button _returnToBody = new() {Text = Loc.GetString("ghost-gui-return-to-body-button") };
|
||||
private readonly Button _ghostWarp = new() {Text = Loc.GetString("ghost-gui-ghost-warp-button") };
|
||||
private readonly Button _ghostRoles = new();
|
||||
private readonly GhostComponent _owner;
|
||||
private readonly GhostSystem _system;
|
||||
|
||||
public GhostTargetWindow? TargetWindow { get; }
|
||||
|
||||
public GhostGui(GhostComponent owner, GhostSystem system, IEntityNetworkManager eventBus)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_owner = owner;
|
||||
_system = system;
|
||||
|
||||
TargetWindow = new GhostTargetWindow(eventBus);
|
||||
|
||||
MouseFilter = MouseFilterMode.Ignore;
|
||||
|
||||
_ghostWarp.OnPressed += _ =>
|
||||
{
|
||||
eventBus.SendSystemNetworkMessage(new GhostWarpsRequestEvent());
|
||||
TargetWindow.Populate();
|
||||
TargetWindow.OpenCentered();
|
||||
};
|
||||
_returnToBody.OnPressed += _ =>
|
||||
{
|
||||
var msg = new GhostReturnToBodyRequest();
|
||||
eventBus.SendSystemNetworkMessage(msg);
|
||||
};
|
||||
_ghostRoles.OnPressed += _ => IoCManager.Resolve<IClientConsoleHost>()
|
||||
.RemoteExecuteCommand(null, "ghostroles");
|
||||
|
||||
AddChild(new BoxContainer
|
||||
{
|
||||
Orientation = LayoutOrientation.Horizontal,
|
||||
Children =
|
||||
{
|
||||
_returnToBody,
|
||||
_ghostWarp,
|
||||
_ghostRoles,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
_returnToBody.Disabled = !_owner.CanReturnToBody;
|
||||
_ghostRoles.Text = Loc.GetString("ghost-gui-ghost-roles-button", ("count", _system.AvailableGhostRoleCount));
|
||||
if (_system.AvailableGhostRoleCount != 0)
|
||||
{
|
||||
_ghostRoles.StyleClasses.Add(StyleBase.ButtonCaution);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ghostRoles.StyleClasses.Remove(StyleBase.ButtonCaution);
|
||||
}
|
||||
TargetWindow?.Populate();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
TargetWindow?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
130
Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
Normal file
130
Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using Content.Client.Gameplay;
|
||||
using Content.Client.Ghost;
|
||||
using Content.Client.UserInterface.Systems.Ghost.Widgets;
|
||||
using Content.Shared.Ghost;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Ghost;
|
||||
|
||||
// TODO hud refactor BEFORE MERGE fix ghost gui being too far up
|
||||
public sealed class GhostUIController : UIController, IOnStateChanged<GameplayState>, IOnSystemChanged<GhostSystem>
|
||||
{
|
||||
[Dependency] private readonly IEntityNetworkManager _net = default!;
|
||||
|
||||
[UISystemDependency] private readonly GhostSystem? _system = default;
|
||||
|
||||
private GhostGui? Gui => UIManager.GetActiveUIWidgetOrNull<GhostGui>();
|
||||
|
||||
public void OnSystemLoaded(GhostSystem system)
|
||||
{
|
||||
system.PlayerRemoved += OnPlayerRemoved;
|
||||
system.PlayerUpdated += OnPlayerUpdated;
|
||||
system.PlayerAttached += OnPlayerAttached;
|
||||
system.PlayerDetached += OnPlayerDetached;
|
||||
system.GhostWarpsResponse += OnWarpsResponse;
|
||||
system.GhostRoleCountUpdated += OnRoleCountUpdated;
|
||||
}
|
||||
|
||||
public void OnSystemUnloaded(GhostSystem system)
|
||||
{
|
||||
system.PlayerRemoved -= OnPlayerRemoved;
|
||||
system.PlayerUpdated -= OnPlayerUpdated;
|
||||
system.PlayerAttached -= OnPlayerAttached;
|
||||
system.PlayerDetached -= OnPlayerDetached;
|
||||
system.GhostWarpsResponse -= OnWarpsResponse;
|
||||
system.GhostRoleCountUpdated -= OnRoleCountUpdated;
|
||||
}
|
||||
|
||||
private void UpdateGui()
|
||||
{
|
||||
Gui?.Update(_system?.AvailableGhostRoleCount, _system?.Player?.CanReturnToBody);
|
||||
}
|
||||
|
||||
private void OnPlayerRemoved(GhostComponent component)
|
||||
{
|
||||
Gui?.Hide();
|
||||
}
|
||||
|
||||
private void OnPlayerUpdated(GhostComponent component)
|
||||
{
|
||||
UpdateGui();
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(GhostComponent component)
|
||||
{
|
||||
if (Gui == null)
|
||||
return;
|
||||
|
||||
Gui.Visible = true;
|
||||
UpdateGui();
|
||||
}
|
||||
|
||||
private void OnPlayerDetached()
|
||||
{
|
||||
Gui?.Hide();
|
||||
}
|
||||
|
||||
private void OnWarpsResponse(GhostWarpsResponseEvent msg)
|
||||
{
|
||||
if (Gui?.TargetWindow is not { } window)
|
||||
return;
|
||||
|
||||
window.UpdateWarps(msg.Warps);
|
||||
window.Populate();
|
||||
}
|
||||
|
||||
private void OnRoleCountUpdated(GhostUpdateGhostRoleCountEvent msg)
|
||||
{
|
||||
UpdateGui();
|
||||
}
|
||||
|
||||
private void OnWarpClicked(EntityUid player)
|
||||
{
|
||||
var msg = new GhostWarpToTargetRequestEvent(player);
|
||||
_net.SendSystemNetworkMessage(msg);
|
||||
}
|
||||
|
||||
public void OnStateEntered(GameplayState state)
|
||||
{
|
||||
if (Gui == null)
|
||||
return;
|
||||
|
||||
Gui.RequestWarpsPressed += RequestWarps;
|
||||
Gui.ReturnToBodyPressed += ReturnToBody;
|
||||
Gui.GhostRolesPressed += GhostRolesPressed;
|
||||
Gui.TargetWindow.WarpClicked += OnWarpClicked;
|
||||
|
||||
Gui.Visible = _system?.IsGhost ?? false;
|
||||
}
|
||||
|
||||
public void OnStateExited(GameplayState state)
|
||||
{
|
||||
if (Gui == null)
|
||||
return;
|
||||
|
||||
Gui.RequestWarpsPressed -= RequestWarps;
|
||||
Gui.ReturnToBodyPressed -= ReturnToBody;
|
||||
Gui.GhostRolesPressed -= GhostRolesPressed;
|
||||
Gui.TargetWindow.WarpClicked -= OnWarpClicked;
|
||||
|
||||
Gui.Hide();
|
||||
}
|
||||
|
||||
private void ReturnToBody()
|
||||
{
|
||||
_system?.ReturnToBody();
|
||||
}
|
||||
|
||||
private void RequestWarps()
|
||||
{
|
||||
_system?.RequestWarps();
|
||||
Gui?.TargetWindow.Populate();
|
||||
Gui?.TargetWindow.OpenCentered();
|
||||
}
|
||||
|
||||
private void GhostRolesPressed()
|
||||
{
|
||||
_system?.OpenGhostRoles();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<widgets:GhostGui xmlns="https://spacestation14.io"
|
||||
xmlns:widgets="clr-namespace:Content.Client.UserInterface.Systems.Ghost.Widgets"
|
||||
HorizontalAlignment="Center">
|
||||
<BoxContainer Orientation="Horizontal">
|
||||
<Button Name="ReturnToBodyButton" Text="{Loc ghost-gui-return-to-body-button}" />
|
||||
<Button Name="GhostWarpButton" Text="{Loc ghost-gui-ghost-warp-button}" />
|
||||
<Button Name="GhostRolesButton" />
|
||||
</BoxContainer>
|
||||
</widgets:GhostGui>
|
||||
@@ -0,0 +1,66 @@
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Client.UserInterface.Systems.Ghost.Controls;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Ghost.Widgets;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class GhostGui : UIWidget
|
||||
{
|
||||
public GhostTargetWindow TargetWindow { get; }
|
||||
|
||||
public event Action? RequestWarpsPressed;
|
||||
public event Action? ReturnToBodyPressed;
|
||||
public event Action? GhostRolesPressed;
|
||||
|
||||
public GhostGui()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
TargetWindow = new GhostTargetWindow();
|
||||
|
||||
MouseFilter = MouseFilterMode.Ignore;
|
||||
|
||||
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
|
||||
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
|
||||
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
|
||||
}
|
||||
|
||||
public void Hide()
|
||||
{
|
||||
TargetWindow.Close();
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
public void Update(int? roles, bool? canReturnToBody)
|
||||
{
|
||||
ReturnToBodyButton.Disabled = !canReturnToBody ?? true;
|
||||
|
||||
if (roles != null)
|
||||
{
|
||||
GhostRolesButton.Text = Loc.GetString("ghost-gui-ghost-roles-button", ("count", roles));
|
||||
if (roles > 0)
|
||||
{
|
||||
GhostRolesButton.StyleClasses.Add(StyleBase.ButtonCaution);
|
||||
}
|
||||
else
|
||||
{
|
||||
GhostRolesButton.StyleClasses.Remove(StyleBase.ButtonCaution);
|
||||
}
|
||||
}
|
||||
|
||||
TargetWindow.Populate();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
TargetWindow.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user