Add indicator showing amount of ghost roles available (#5150)
* Add indicator showing amount of ghost roles available * Make the indicator turn red if ghost roles are available
This commit is contained in:
@@ -16,6 +16,10 @@ namespace Content.Client.Ghost
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IGameHud _gameHud = default!;
|
||||
|
||||
// Changes to this value are manually propagated.
|
||||
// No good way to get an event into the UI.
|
||||
public int AvailableGhostRoleCount { get; private set; } = 0;
|
||||
|
||||
private bool _ghostVisibility;
|
||||
|
||||
private bool GhostVisibility
|
||||
@@ -51,6 +55,7 @@ namespace Content.Client.Ghost
|
||||
SubscribeLocalEvent<GhostComponent, PlayerDetachedEvent>(OnGhostPlayerDetach);
|
||||
|
||||
SubscribeNetworkEvent<GhostWarpsResponseEvent>(OnGhostWarpsResponse);
|
||||
SubscribeNetworkEvent<GhostUpdateGhostRoleCountEvent>(OnUpdateGhostRoleCount);
|
||||
}
|
||||
|
||||
private void OnGhostInit(EntityUid uid, GhostComponent component, ComponentInit args)
|
||||
@@ -78,7 +83,7 @@ namespace Content.Client.Ghost
|
||||
// I hate UI I hate UI I Hate UI
|
||||
if (component.Gui == null)
|
||||
{
|
||||
component.Gui = new GhostGui(component, EntityManager.EntityNetManager!);
|
||||
component.Gui = new GhostGui(component, this, EntityManager.EntityNetManager!);
|
||||
component.Gui.Update();
|
||||
}
|
||||
|
||||
@@ -113,5 +118,12 @@ namespace Content.Client.Ghost
|
||||
window.Populate();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnUpdateGhostRoleCount(GhostUpdateGhostRoleCountEvent msg)
|
||||
{
|
||||
AvailableGhostRoleCount = msg.AvailableGhostRoles;
|
||||
foreach (var ghost in EntityManager.EntityQuery<GhostComponent>(true))
|
||||
ghost.Gui?.Update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Content.Client.Stylesheets;
|
||||
using Content.Shared.Ghost;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.UserInterface;
|
||||
@@ -13,16 +14,18 @@ namespace Content.Client.Ghost.UI
|
||||
{
|
||||
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() {Text = Loc.GetString("ghost-gui-ghost-roles-button") };
|
||||
private readonly Button _ghostRoles = new();
|
||||
private readonly GhostComponent _owner;
|
||||
private readonly GhostSystem _system;
|
||||
|
||||
public GhostTargetWindow? TargetWindow { get; }
|
||||
|
||||
public GhostGui(GhostComponent owner, IEntityNetworkManager eventBus)
|
||||
public GhostGui(GhostComponent owner, GhostSystem system, IEntityNetworkManager eventBus)
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_owner = owner;
|
||||
_system = system;
|
||||
|
||||
TargetWindow = new GhostTargetWindow(eventBus);
|
||||
|
||||
@@ -57,6 +60,15 @@ namespace Content.Client.Ghost.UI
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user