Correctly update the admin button the chat box.

This commit is contained in:
Pieter-Jan Briers
2020-11-01 23:55:55 +01:00
parent 711166f43a
commit 637581bf3b
4 changed files with 60 additions and 29 deletions

View File

@@ -19,6 +19,8 @@ namespace Content.Client.Administration
private AdminData? _adminData; private AdminData? _adminData;
private readonly HashSet<string> _availableCommands = new HashSet<string>(); private readonly HashSet<string> _availableCommands = new HashSet<string>();
public event Action? AdminStatusUpdated;
public bool HasFlag(AdminFlags flag) public bool HasFlag(AdminFlags flag)
{ {
return _adminData?.HasFlag(flag) ?? false; return _adminData?.HasFlag(flag) ?? false;
@@ -70,6 +72,8 @@ namespace Content.Client.Administration
{ {
Logger.InfoS("admin", $"Updated admin status: Not admin"); Logger.InfoS("admin", $"Updated admin status: Not admin");
} }
AdminStatusUpdated?.Invoke();
} }
public event Action? ConGroupUpdated; public event Action? ConGroupUpdated;

View File

@@ -1,9 +1,12 @@
using Content.Shared.Administration; using System;
using Content.Shared.Administration;
namespace Content.Client.Administration namespace Content.Client.Administration
{ {
public interface IClientAdminManager public interface IClientAdminManager
{ {
public event Action AdminStatusUpdated;
bool HasFlag(AdminFlags flag); bool HasFlag(AdminFlags flag);
bool CanCommand(string cmdName); bool CanCommand(string cmdName);

View File

@@ -1,10 +1,8 @@
using Content.Shared.Chat; using Content.Shared.Chat;
using Robust.Client.Console;
using Robust.Client.Graphics.Drawing; using Robust.Client.Graphics.Drawing;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input; using Robust.Shared.Input;
using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -97,16 +95,13 @@ namespace Content.Client.Chat
ToggleMode = true, ToggleMode = true,
}; };
var groupController = IoCManager.Resolve<IClientConGroupController>(); AdminButton = new Button
if(groupController.CanCommand("asay"))
{ {
AdminButton = new Button Text = Loc.GetString("Admin"),
{ Name = "Admin",
Text = Loc.GetString("Admin"), ToggleMode = true,
Name = "Admin", Visible = false
ToggleMode = true, };
};
}
AllButton.OnToggled += OnFilterToggled; AllButton.OnToggled += OnFilterToggled;
LocalButton.OnToggled += OnFilterToggled; LocalButton.OnToggled += OnFilterToggled;

View File

@@ -1,6 +1,7 @@
using System; using System.Collections.Generic;
using System.Collections.Generic; using Content.Client.Administration;
using Content.Client.Interfaces.Chat; using Content.Client.Interfaces.Chat;
using Content.Shared.Administration;
using Content.Shared.Chat; using Content.Shared.Chat;
using Robust.Client.Console; using Robust.Client.Console;
using Robust.Client.Interfaces.Graphics.ClientEye; using Robust.Client.Interfaces.Graphics.ClientEye;
@@ -18,9 +19,11 @@ using Robust.Shared.Network;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility; using Robust.Shared.Utility;
#nullable enable
namespace Content.Client.Chat namespace Content.Client.Chat
{ {
internal sealed class ChatManager : IChatManager internal sealed class ChatManager : IChatManager, IPostInjectInit
{ {
private struct SpeechBubbleData private struct SpeechBubbleData
{ {
@@ -75,9 +78,10 @@ namespace Content.Client.Chat
[Dependency] private readonly IEyeManager _eyeManager = default!; [Dependency] private readonly IEyeManager _eyeManager = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!; [Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IClientConGroupController _groupController = default!; [Dependency] private readonly IClientConGroupController _groupController = default!;
[Dependency] private readonly IClientAdminManager _adminMgr = default!;
private ChatBox _currentChatBox; private ChatBox? _currentChatBox;
private Control _speechBubbleRoot; private Control _speechBubbleRoot = null!;
/// <summary> /// <summary>
/// Speech bubbles that are currently visible on screen. /// Speech bubbles that are currently visible on screen.
@@ -103,7 +107,7 @@ namespace Content.Client.Chat
_speechBubbleRoot.SetPositionFirst(); _speechBubbleRoot.SetPositionFirst();
// When connexion is achieved, request the max chat message length // When connexion is achieved, request the max chat message length
_netManager.Connected += new EventHandler<NetChannelArgs>(RequestMaxLength); _netManager.Connected += RequestMaxLength;
} }
public void FrameUpdate(FrameEventArgs delta) public void FrameUpdate(FrameEventArgs delta)
@@ -157,14 +161,15 @@ namespace Content.Client.Chat
{ {
_currentChatBox.TextSubmitted += _onChatBoxTextSubmitted; _currentChatBox.TextSubmitted += _onChatBoxTextSubmitted;
_currentChatBox.FilterToggled += _onFilterButtonToggled; _currentChatBox.FilterToggled += _onFilterButtonToggled;
_currentChatBox.AllButton.Pressed = !_allState;
_currentChatBox.LocalButton.Pressed = !_localState;
_currentChatBox.OOCButton.Pressed = !_oocState;
_currentChatBox.AdminButton.Pressed = !_adminState;
AdminStatusUpdated();
} }
RepopulateChat(filteredHistory); RepopulateChat(filteredHistory);
_currentChatBox.AllButton.Pressed = !_allState;
_currentChatBox.LocalButton.Pressed = !_localState;
_currentChatBox.OOCButton.Pressed = !_oocState;
if(chatBox.AdminButton != null)
_currentChatBox.AdminButton.Pressed = !_adminState;
} }
public void RemoveSpeechBubble(EntityUid entityUid, SpeechBubble bubble) public void RemoveSpeechBubble(EntityUid entityUid, SpeechBubble bubble)
@@ -229,9 +234,12 @@ namespace Content.Client.Chat
// Check if message is longer than the character limit // Check if message is longer than the character limit
if (text.Length > _maxMessageLength) if (text.Length > _maxMessageLength)
{ {
string locWarning = Loc.GetString("Your message exceeds {0} character limit", _maxMessageLength); if (_currentChatBox != null)
_currentChatBox?.AddLine(locWarning, ChatChannel.Server, Color.Orange); {
_currentChatBox.ClearOnEnter = false; // The text shouldn't be cleared if it hasn't been sent string locWarning = Loc.GetString("Your message exceeds {0} character limit", _maxMessageLength);
_currentChatBox.AddLine(locWarning, ChatChannel.Server, Color.Orange);
_currentChatBox.ClearOnEnter = false; // The text shouldn't be cleared if it hasn't been sent
}
return; return;
} }
@@ -257,13 +265,15 @@ namespace Content.Client.Chat
var conInput = text.Substring(1); var conInput = text.Substring(1);
if (string.IsNullOrWhiteSpace(conInput)) if (string.IsNullOrWhiteSpace(conInput))
return; return;
if (_groupController.CanCommand("asay")){ if (_groupController.CanCommand("asay"))
{
_console.ProcessCommand($"asay \"{CommandParsing.Escape(conInput)}\""); _console.ProcessCommand($"asay \"{CommandParsing.Escape(conInput)}\"");
} }
else else
{ {
_console.ProcessCommand($"ooc \"{CommandParsing.Escape(conInput)}\""); _console.ProcessCommand($"ooc \"{CommandParsing.Escape(conInput)}\"");
} }
break; break;
} }
case MeAlias: case MeAlias:
@@ -276,7 +286,7 @@ namespace Content.Client.Chat
} }
default: default:
{ {
var conInput = _currentChatBox.DefaultChatFormat != null var conInput = _currentChatBox?.DefaultChatFormat != null
? string.Format(_currentChatBox.DefaultChatFormat, CommandParsing.Escape(text)) ? string.Format(_currentChatBox.DefaultChatFormat, CommandParsing.Escape(text))
: text; : text;
_console.ProcessCommand(conInput); _console.ProcessCommand(conInput);
@@ -341,6 +351,11 @@ namespace Content.Client.Chat
private void RepopulateChat(IEnumerable<StoredChatMessage> filteredMessages) private void RepopulateChat(IEnumerable<StoredChatMessage> filteredMessages)
{ {
if (_currentChatBox == null)
{
return;
}
_currentChatBox.Contents.Clear(); _currentChatBox.Contents.Clear();
foreach (var msg in filteredMessages) foreach (var msg in filteredMessages)
@@ -463,7 +478,8 @@ namespace Content.Client.Chat
private void CreateSpeechBubble(IEntity entity, SpeechBubbleData speechData) private void CreateSpeechBubble(IEntity entity, SpeechBubbleData speechData)
{ {
var bubble = SpeechBubble.CreateSpeechBubble(speechData.Type, speechData.Message, entity, _eyeManager, this); var bubble =
SpeechBubble.CreateSpeechBubble(speechData.Type, speechData.Message, entity, _eyeManager, this);
if (_activeSpeechBubbles.TryGetValue(entity.Uid, out var existing)) if (_activeSpeechBubbles.TryGetValue(entity.Uid, out var existing))
{ {
@@ -496,6 +512,19 @@ namespace Content.Client.Chat
return _allState ^ _filteredChannels.HasFlag(channel); return _allState ^ _filteredChannels.HasFlag(channel);
} }
void IPostInjectInit.PostInject()
{
_adminMgr.AdminStatusUpdated += AdminStatusUpdated;
}
private void AdminStatusUpdated()
{
if (_currentChatBox != null)
{
_currentChatBox.AdminButton.Visible = _adminMgr.HasFlag(AdminFlags.Admin);
}
}
private sealed class SpeechBubbleQueueData private sealed class SpeechBubbleQueueData
{ {
/// <summary> /// <summary>