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:
20kdc
2021-11-03 23:48:12 +00:00
committed by GitHub
parent 3ab4a30a0f
commit 9eb6e5a109
5 changed files with 77 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ using Content.Server.Ghost.Roles.Components;
using Content.Server.Ghost.Roles.UI;
using Content.Shared.GameTicking;
using Content.Shared.Ghost.Roles;
using Content.Shared.Ghost;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
using Robust.Server.Player;
@@ -13,6 +14,7 @@ using Robust.Shared.Console;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.ViewVariables;
using Robust.Shared.Enums;
namespace Content.Server.Ghost.Roles
{
@@ -20,8 +22,10 @@ namespace Content.Server.Ghost.Roles
public class GhostRoleSystem : EntitySystem
{
[Dependency] private readonly EuiManager _euiManager = default!;
[Dependency] private IPlayerManager _playerManager = default!;
private uint _nextRoleIdentifier = 0;
private bool _needsUpdateGhostRoleCount = true;
private readonly Dictionary<uint, GhostRoleComponent> _ghostRoles = new();
private readonly Dictionary<IPlayerSession, GhostRolesEui> _openUis = new();
private readonly Dictionary<IPlayerSession, MakeGhostRoleEui> _openMakeGhostRoleUis = new();
@@ -35,6 +39,15 @@ namespace Content.Server.Ghost.Roles
SubscribeLocalEvent<RoundRestartCleanupEvent>(Reset);
SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttached);
_playerManager.PlayerStatusChanged += PlayerStatusChanged;
}
public override void Shutdown()
{
base.Shutdown();
_playerManager.PlayerStatusChanged -= PlayerStatusChanged;
}
private uint GetNextRoleIdentifier()
@@ -91,6 +104,31 @@ namespace Content.Server.Ghost.Roles
{
eui.StateDirty();
}
// Note that this, like the EUIs, is deferred.
// This is for roughly the same reasons, too:
// Someone might spawn a ton of ghost roles at once.
_needsUpdateGhostRoleCount = true;
}
public override void Update(float frameTime)
{
base.Update(frameTime);
if (_needsUpdateGhostRoleCount)
{
_needsUpdateGhostRoleCount = false;
var response = new GhostUpdateGhostRoleCountEvent(_ghostRoles.Count);
foreach (var player in _playerManager.GetAllPlayers())
RaiseNetworkEvent(response, player.ConnectedClient);
}
}
private void PlayerStatusChanged(object? blah, SessionStatusEventArgs args)
{
if (args.NewStatus == SessionStatus.InGame)
{
var response = new GhostUpdateGhostRoleCountEvent(_ghostRoles.Count);
RaiseNetworkEvent(response, args.Session.ConnectedClient);
}
}
public void RegisterGhostRole(GhostRoleComponent role)