Allows admins to see deadchat and adds a toggle for deadchat for admins and ghosts (#2904)

This commit is contained in:
Leo
2021-01-04 05:25:33 -03:00
committed by GitHub
parent c1f53a4303
commit 447f0af6c2
5 changed files with 57 additions and 18 deletions

View File

@@ -23,6 +23,7 @@ namespace Content.Client.Chat
public Button LocalButton { get; } public Button LocalButton { get; }
public Button OOCButton { get; } public Button OOCButton { get; }
public Button AdminButton { get; } public Button AdminButton { get; }
public Button DeadButton { get; }
/// <summary> /// <summary>
/// Default formatting string for the ClientChatConsole. /// Default formatting string for the ClientChatConsole.
@@ -103,13 +104,23 @@ namespace Content.Client.Chat
Visible = false Visible = false
}; };
DeadButton = new Button
{
Text = Loc.GetString("Dead"),
Name = "Dead",
ToggleMode = true,
Visible = false
};
AllButton.OnToggled += OnFilterToggled; AllButton.OnToggled += OnFilterToggled;
LocalButton.OnToggled += OnFilterToggled; LocalButton.OnToggled += OnFilterToggled;
OOCButton.OnToggled += OnFilterToggled; OOCButton.OnToggled += OnFilterToggled;
AdminButton.OnToggled += OnFilterToggled; AdminButton.OnToggled += OnFilterToggled;
DeadButton.OnToggled += OnFilterToggled;
hBox.AddChild(AllButton); hBox.AddChild(AllButton);
hBox.AddChild(LocalButton); hBox.AddChild(LocalButton);
hBox.AddChild(DeadButton);
hBox.AddChild(OOCButton); hBox.AddChild(OOCButton);
hBox.AddChild(AdminButton); hBox.AddChild(AdminButton);

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Client.Administration; using Content.Client.Administration;
using Content.Client.Interfaces.Chat; using Content.Client.Interfaces.Chat;
using Content.Shared.Administration; using Content.Shared.Administration;
@@ -61,13 +61,14 @@ namespace Content.Client.Chat
private const char MeAlias = '@'; private const char MeAlias = '@';
private const char AdminChatAlias = ']'; private const char AdminChatAlias = ']';
private readonly List<StoredChatMessage> filteredHistory = new(); private readonly List<StoredChatMessage> _filteredHistory = new();
// Filter Button States // Filter Button States
private bool _allState; private bool _allState;
private bool _localState; private bool _localState;
private bool _oocState; private bool _oocState;
private bool _adminState; private bool _adminState;
private bool _deadState;
// Flag Enums for holding filtered channels // Flag Enums for holding filtered channels
private ChatChannel _filteredChannels; private ChatChannel _filteredChannels;
@@ -98,8 +99,8 @@ namespace Content.Client.Chat
public void Initialize() public void Initialize()
{ {
_netManager.RegisterNetMessage<MsgChatMessage>(MsgChatMessage.NAME, _onChatMessage); _netManager.RegisterNetMessage<MsgChatMessage>(MsgChatMessage.NAME, OnChatMessage);
_netManager.RegisterNetMessage<ChatMaxMsgLengthMessage>(ChatMaxMsgLengthMessage.NAME, _onMaxLengthReceived); _netManager.RegisterNetMessage<ChatMaxMsgLengthMessage>(ChatMaxMsgLengthMessage.NAME, OnMaxLengthReceived);
_speechBubbleRoot = new LayoutContainer(); _speechBubbleRoot = new LayoutContainer();
LayoutContainer.SetAnchorPreset(_speechBubbleRoot, LayoutContainer.LayoutPreset.Wide); LayoutContainer.SetAnchorPreset(_speechBubbleRoot, LayoutContainer.LayoutPreset.Wide);
@@ -152,24 +153,25 @@ namespace Content.Client.Chat
{ {
if (_currentChatBox != null) if (_currentChatBox != null)
{ {
_currentChatBox.TextSubmitted -= _onChatBoxTextSubmitted; _currentChatBox.TextSubmitted -= OnChatBoxTextSubmitted;
_currentChatBox.FilterToggled -= _onFilterButtonToggled; _currentChatBox.FilterToggled -= OnFilterButtonToggled;
} }
_currentChatBox = chatBox; _currentChatBox = chatBox;
if (_currentChatBox != null) if (_currentChatBox != null)
{ {
_currentChatBox.TextSubmitted += _onChatBoxTextSubmitted; _currentChatBox.TextSubmitted += OnChatBoxTextSubmitted;
_currentChatBox.FilterToggled += _onFilterButtonToggled; _currentChatBox.FilterToggled += OnFilterButtonToggled;
_currentChatBox.AllButton.Pressed = !_allState; _currentChatBox.AllButton.Pressed = !_allState;
_currentChatBox.LocalButton.Pressed = !_localState; _currentChatBox.LocalButton.Pressed = !_localState;
_currentChatBox.OOCButton.Pressed = !_oocState; _currentChatBox.OOCButton.Pressed = !_oocState;
_currentChatBox.AdminButton.Pressed = !_adminState; _currentChatBox.AdminButton.Pressed = !_adminState;
_currentChatBox.DeadButton.Pressed = !_deadState;
AdminStatusUpdated(); AdminStatusUpdated();
} }
RepopulateChat(filteredHistory); RepopulateChat(_filteredHistory);
} }
public void RemoveSpeechBubble(EntityUid entityUid, SpeechBubble bubble) public void RemoveSpeechBubble(EntityUid entityUid, SpeechBubble bubble)
@@ -224,7 +226,7 @@ namespace Content.Client.Chat
_currentChatBox?.AddLine(messageText, message.Channel, color); _currentChatBox?.AddLine(messageText, message.Channel, color);
} }
private void _onChatBoxTextSubmitted(ChatBox chatBox, string text) private void OnChatBoxTextSubmitted(ChatBox chatBox, string text)
{ {
DebugTools.Assert(chatBox == _currentChatBox); DebugTools.Assert(chatBox == _currentChatBox);
@@ -295,7 +297,7 @@ namespace Content.Client.Chat
} }
} }
private void _onFilterButtonToggled(ChatBox chatBox, BaseButton.ButtonToggledEventArgs e) private void OnFilterButtonToggled(ChatBox chatBox, BaseButton.ButtonToggledEventArgs e)
{ {
switch (e.Button.Name) switch (e.Button.Name)
{ {
@@ -336,6 +338,13 @@ namespace Content.Client.Chat
_filteredChannels &= ~ChatChannel.AdminChat; _filteredChannels &= ~ChatChannel.AdminChat;
break; break;
} }
case "Dead":
_deadState = !_deadState;
if (_deadState)
_filteredChannels |= ChatChannel.Dead;
else
_filteredChannels &= ~ChatChannel.Dead;
break;
case "ALL": case "ALL":
chatBox.LocalButton.Pressed ^= true; chatBox.LocalButton.Pressed ^= true;
@@ -346,7 +355,7 @@ namespace Content.Client.Chat
break; break;
} }
RepopulateChat(filteredHistory); RepopulateChat(_filteredHistory);
} }
private void RepopulateChat(IEnumerable<StoredChatMessage> filteredMessages) private void RepopulateChat(IEnumerable<StoredChatMessage> filteredMessages)
@@ -364,11 +373,11 @@ namespace Content.Client.Chat
} }
} }
private void _onChatMessage(MsgChatMessage msg) private void OnChatMessage(MsgChatMessage msg)
{ {
// Log all incoming chat to repopulate when filter is un-toggled // Log all incoming chat to repopulate when filter is un-toggled
var storedMessage = new StoredChatMessage(msg); var storedMessage = new StoredChatMessage(msg);
filteredHistory.Add(storedMessage); _filteredHistory.Add(storedMessage);
WriteChatMessage(storedMessage); WriteChatMessage(storedMessage);
// Local messages that have an entity attached get a speech bubble. // Local messages that have an entity attached get a speech bubble.
@@ -388,7 +397,7 @@ namespace Content.Client.Chat
} }
} }
private void _onMaxLengthReceived(ChatMaxMsgLengthMessage msg) private void OnMaxLengthReceived(ChatMaxMsgLengthMessage msg)
{ {
_maxMessageLength = msg.MaxMessageLength; _maxMessageLength = msg.MaxMessageLength;
} }
@@ -522,6 +531,18 @@ namespace Content.Client.Chat
if (_currentChatBox != null) if (_currentChatBox != null)
{ {
_currentChatBox.AdminButton.Visible = _adminMgr.HasFlag(AdminFlags.Admin); _currentChatBox.AdminButton.Visible = _adminMgr.HasFlag(AdminFlags.Admin);
_currentChatBox.DeadButton.Visible = _adminMgr.HasFlag(AdminFlags.Admin);
}
}
public void ToggleDeadChatButtonVisibility(bool visibility)
{
if (_currentChatBox != null)
{
// If the user is an admin and returned to body, don't set the flag as null
if (!visibility && _adminMgr.HasFlag(AdminFlags.Admin))
return;
_currentChatBox.DeadButton.Visible = visibility;
} }
} }

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Client.Interfaces.Chat;
using Content.Client.UserInterface; using Content.Client.UserInterface;
using Content.Shared.GameObjects.Components.Observer; using Content.Shared.GameObjects.Components.Observer;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
@@ -19,6 +20,7 @@ namespace Content.Client.GameObjects.Components.Observer
[Dependency] private readonly IGameHud _gameHud = default!; [Dependency] private readonly IGameHud _gameHud = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IComponentManager _componentManager = default!; [Dependency] private readonly IComponentManager _componentManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
public List<string> WarpNames = new(); public List<string> WarpNames = new();
public Dictionary<EntityUid,string> PlayerNames = new(); public Dictionary<EntityUid,string> PlayerNames = new();
@@ -83,6 +85,7 @@ namespace Content.Client.GameObjects.Components.Observer
_gameHud.HandsContainer.AddChild(_gui); _gameHud.HandsContainer.AddChild(_gui);
SetGhostVisibility(true); SetGhostVisibility(true);
_isAttached = true; _isAttached = true;
_chatManager.ToggleDeadChatButtonVisibility(true);
break; break;
@@ -90,6 +93,7 @@ namespace Content.Client.GameObjects.Components.Observer
_gui!.Parent?.RemoveChild(_gui); _gui!.Parent?.RemoveChild(_gui);
SetGhostVisibility(false); SetGhostVisibility(false);
_isAttached = false; _isAttached = false;
_chatManager.ToggleDeadChatButtonVisibility(false);
break; break;
} }
} }

View File

@@ -13,5 +13,7 @@ namespace Content.Client.Interfaces.Chat
void SetChatBox(ChatBox chatBox); void SetChatBox(ChatBox chatBox);
void RemoveSpeechBubble(EntityUid entityUid, SpeechBubble bubble); void RemoveSpeechBubble(EntityUid entityUid, SpeechBubble bubble);
void ToggleDeadChatButtonVisibility(bool visibility);
} }
} }

View File

@@ -52,7 +52,7 @@ namespace Content.Server.Chat
public void Initialize() public void Initialize()
{ {
_netManager.RegisterNetMessage<MsgChatMessage>(MsgChatMessage.NAME); _netManager.RegisterNetMessage<MsgChatMessage>(MsgChatMessage.NAME);
_netManager.RegisterNetMessage<ChatMaxMsgLengthMessage>(ChatMaxMsgLengthMessage.NAME, _onMaxLengthRequest); _netManager.RegisterNetMessage<ChatMaxMsgLengthMessage>(ChatMaxMsgLengthMessage.NAME, OnMaxLengthRequest);
// Tell all the connected players the chat's character limit // Tell all the connected players the chat's character limit
var msg = _netManager.CreateNetMessage<ChatMaxMsgLengthMessage>(); var msg = _netManager.CreateNetMessage<ChatMaxMsgLengthMessage>();
@@ -244,7 +244,8 @@ namespace Content.Server.Chat
{ {
return _playerManager return _playerManager
.GetPlayersBy(x => x.AttachedEntity != null && x.AttachedEntity.HasComponent<GhostComponent>()) .GetPlayersBy(x => x.AttachedEntity != null && x.AttachedEntity.HasComponent<GhostComponent>())
.Select(p => p.ConnectedClient); .Select(p => p.ConnectedClient)
.Union(_adminManager.ActiveAdmins.Select(p => p.ConnectedClient));
} }
public void SendAdminChat(IPlayerSession player, string message) public void SendAdminChat(IPlayerSession player, string message)
@@ -288,7 +289,7 @@ namespace Content.Server.Chat
_netManager.ServerSendToAll(msg); _netManager.ServerSendToAll(msg);
} }
private void _onMaxLengthRequest(ChatMaxMsgLengthMessage msg) private void OnMaxLengthRequest(ChatMaxMsgLengthMessage msg)
{ {
var response = _netManager.CreateNetMessage<ChatMaxMsgLengthMessage>(); var response = _netManager.CreateNetMessage<ChatMaxMsgLengthMessage>();
response.MaxMessageLength = MaxMessageLength; response.MaxMessageLength = MaxMessageLength;