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

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using Content.Client.Administration;
using Content.Client.Interfaces.Chat;
using Content.Shared.Administration;
@@ -61,13 +61,14 @@ namespace Content.Client.Chat
private const char MeAlias = '@';
private const char AdminChatAlias = ']';
private readonly List<StoredChatMessage> filteredHistory = new();
private readonly List<StoredChatMessage> _filteredHistory = new();
// Filter Button States
private bool _allState;
private bool _localState;
private bool _oocState;
private bool _adminState;
private bool _deadState;
// Flag Enums for holding filtered channels
private ChatChannel _filteredChannels;
@@ -98,8 +99,8 @@ namespace Content.Client.Chat
public void Initialize()
{
_netManager.RegisterNetMessage<MsgChatMessage>(MsgChatMessage.NAME, _onChatMessage);
_netManager.RegisterNetMessage<ChatMaxMsgLengthMessage>(ChatMaxMsgLengthMessage.NAME, _onMaxLengthReceived);
_netManager.RegisterNetMessage<MsgChatMessage>(MsgChatMessage.NAME, OnChatMessage);
_netManager.RegisterNetMessage<ChatMaxMsgLengthMessage>(ChatMaxMsgLengthMessage.NAME, OnMaxLengthReceived);
_speechBubbleRoot = new LayoutContainer();
LayoutContainer.SetAnchorPreset(_speechBubbleRoot, LayoutContainer.LayoutPreset.Wide);
@@ -152,24 +153,25 @@ namespace Content.Client.Chat
{
if (_currentChatBox != null)
{
_currentChatBox.TextSubmitted -= _onChatBoxTextSubmitted;
_currentChatBox.FilterToggled -= _onFilterButtonToggled;
_currentChatBox.TextSubmitted -= OnChatBoxTextSubmitted;
_currentChatBox.FilterToggled -= OnFilterButtonToggled;
}
_currentChatBox = chatBox;
if (_currentChatBox != null)
{
_currentChatBox.TextSubmitted += _onChatBoxTextSubmitted;
_currentChatBox.FilterToggled += _onFilterButtonToggled;
_currentChatBox.TextSubmitted += OnChatBoxTextSubmitted;
_currentChatBox.FilterToggled += OnFilterButtonToggled;
_currentChatBox.AllButton.Pressed = !_allState;
_currentChatBox.LocalButton.Pressed = !_localState;
_currentChatBox.OOCButton.Pressed = !_oocState;
_currentChatBox.AdminButton.Pressed = !_adminState;
_currentChatBox.DeadButton.Pressed = !_deadState;
AdminStatusUpdated();
}
RepopulateChat(filteredHistory);
RepopulateChat(_filteredHistory);
}
public void RemoveSpeechBubble(EntityUid entityUid, SpeechBubble bubble)
@@ -224,7 +226,7 @@ namespace Content.Client.Chat
_currentChatBox?.AddLine(messageText, message.Channel, color);
}
private void _onChatBoxTextSubmitted(ChatBox chatBox, string text)
private void OnChatBoxTextSubmitted(ChatBox chatBox, string text)
{
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)
{
@@ -336,6 +338,13 @@ namespace Content.Client.Chat
_filteredChannels &= ~ChatChannel.AdminChat;
break;
}
case "Dead":
_deadState = !_deadState;
if (_deadState)
_filteredChannels |= ChatChannel.Dead;
else
_filteredChannels &= ~ChatChannel.Dead;
break;
case "ALL":
chatBox.LocalButton.Pressed ^= true;
@@ -346,7 +355,7 @@ namespace Content.Client.Chat
break;
}
RepopulateChat(filteredHistory);
RepopulateChat(_filteredHistory);
}
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
var storedMessage = new StoredChatMessage(msg);
filteredHistory.Add(storedMessage);
_filteredHistory.Add(storedMessage);
WriteChatMessage(storedMessage);
// 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;
}
@@ -522,6 +531,18 @@ namespace Content.Client.Chat
if (_currentChatBox != null)
{
_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;
}
}