Add ahelp typing indicator for admins (#19060)
* Add ahelp typing indicator for admins * Lower typing updates throttle from 3 seconds to 1 * Add stopping typing when sending a message * Lower typing indicator timeout from 15 to 10 seconds
This commit is contained in:
@@ -2,6 +2,7 @@ using Content.Shared.Administration;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Administration.UI.Bwoink
|
||||
@@ -13,6 +14,8 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
|
||||
public int Unread { get; private set; } = 0;
|
||||
public DateTime LastMessage { get; private set; } = DateTime.MinValue;
|
||||
private List<string> PeopleTyping { get; set; } = new();
|
||||
public event Action<string>? InputTextChanged;
|
||||
|
||||
public BwoinkPanel(Action<string> messageSender)
|
||||
{
|
||||
@@ -32,6 +35,8 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
Unread = 0;
|
||||
};
|
||||
SenderLineEdit.OnTextEntered += Input_OnTextEntered;
|
||||
SenderLineEdit.OnTextChanged += Input_OnTextChanged;
|
||||
UpdateTypingIndicator();
|
||||
}
|
||||
|
||||
private void Input_OnTextEntered(LineEdit.LineEditEventArgs args)
|
||||
@@ -43,6 +48,11 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
SenderLineEdit.Clear();
|
||||
}
|
||||
|
||||
private void Input_OnTextChanged(LineEdit.LineEditEventArgs args)
|
||||
{
|
||||
InputTextChanged?.Invoke(args.Text);
|
||||
}
|
||||
|
||||
public void ReceiveLine(SharedBwoinkSystem.BwoinkTextMessage message)
|
||||
{
|
||||
if (!Visible)
|
||||
@@ -53,5 +63,54 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
TextOutput.AddMessage(formatted);
|
||||
LastMessage = message.SentAt;
|
||||
}
|
||||
|
||||
private void UpdateTypingIndicator()
|
||||
{
|
||||
var msg = new FormattedMessage();
|
||||
msg.PushColor(Color.LightGray);
|
||||
|
||||
var text = PeopleTyping.Count == 0
|
||||
? string.Empty
|
||||
: Loc.GetString("bwoink-system-typing-indicator",
|
||||
("players", string.Join(", ", PeopleTyping)),
|
||||
("count", PeopleTyping.Count));
|
||||
|
||||
msg.AddText(text);
|
||||
msg.Pop();
|
||||
|
||||
TypingIndicator.SetMessage(msg);
|
||||
}
|
||||
|
||||
public void UpdatePlayerTyping(string name, bool typing)
|
||||
{
|
||||
if (typing)
|
||||
{
|
||||
if (PeopleTyping.Contains(name))
|
||||
return;
|
||||
|
||||
PeopleTyping.Add(name);
|
||||
Timer.Spawn(TimeSpan.FromSeconds(10), () =>
|
||||
{
|
||||
if (Disposed)
|
||||
return;
|
||||
|
||||
PeopleTyping.Remove(name);
|
||||
UpdateTypingIndicator();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
PeopleTyping.Remove(name);
|
||||
}
|
||||
|
||||
UpdateTypingIndicator();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
InputTextChanged = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user