Port ChatStack (#3332)
* Add Chatstack (#1422) Chatstack. Can be changed/disabled in settings, and the chat automatically updates to reflect the change. Does not interfere with filters, etc. Also updated ChatMessage class and serverside IChatManager with a new IgnoreChatStack bool option, default false. Currently is limited to looking up to 3 messages behind, only because I feel off adding a textbox to the options. --- - [x] Make sure it works - [x] Add it to settings --- <details><summary><h1>Media</h1></summary> <p>  [ee.webm](https://github.com/user-attachments/assets/bf1c92f0-b52a-47a0-b142-70b1ee5003cc) </p> </details> --- 🆑 - add: Chatstack. Look for it in Options under "General - Accessibility". --------- Co-authored-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> * fix missing param; use default value * Properly save entries option * Move added EE content to _EE where possible, comment where not. * Comments; simplify l10n; cleanup/standards * remove ignoreChatStack, unused l10n strings * l10n moment; style/untouch * Simplify ftl; int → var * Whitespace * Fix naming for get-only property Co-authored-by: Tobias Berger <toby@tobot.dev> Signed-off-by: Madison Rye Progress <makyo@drab-makyo.com> * Fix instance of old variable name. --------- Signed-off-by: Madison Rye Progress <makyo@drab-makyo.com> Co-authored-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com> Co-authored-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com> Co-authored-by: Tobias Berger <toby@tobot.dev>
This commit is contained in:
parent
7443161ab8
commit
d23b01f040
|
|
@ -9,6 +9,8 @@
|
|||
StyleClasses="LabelKeyText"/>
|
||||
<ui:OptionDropDown Name="DropDownHudTheme" Title="{Loc 'ui-options-hud-theme'}" />
|
||||
<ui:OptionDropDown Name="DropDownHudLayout" Title="{Loc 'ui-options-hud-layout'}" />
|
||||
<!-- EE - chat stacking -->
|
||||
<ui:OptionDropDown Name="ChatStackLastLines" Title="{Loc 'ui-options-chatstack'}" />
|
||||
<Label Text="{Loc 'ui-options-general-discord'}"
|
||||
StyleClasses="LabelKeyText"/>
|
||||
<CheckBox Name="DiscordRich" Text="{Loc 'ui-options-discordrich'}" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Linq;
|
||||
using Content.Client.UserInterface.Screens;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared._EE.CCVars; // EE - chat stack
|
||||
using Content.Shared.HUD;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Player;
|
||||
|
|
@ -36,12 +37,22 @@ public sealed partial class MiscTab : Control
|
|||
layoutEntries.Add(new OptionDropDownCVar<string>.ValueOption(layout.ToString()!, Loc.GetString($"ui-options-hud-layout-{layout.ToString()!.ToLower()}")));
|
||||
}
|
||||
|
||||
// EE - Chat stacking options for how far back in the chat to stack.
|
||||
var chatStackEntries = new List<OptionDropDownCVar<int>.ValueOption>();
|
||||
for (var option = 0; option <= 3; option++)
|
||||
{
|
||||
chatStackEntries.Add(
|
||||
new OptionDropDownCVar<int>.ValueOption(option, Loc.GetString("ui-options-chatstack-count", ("count", option))));
|
||||
}
|
||||
// End EE - Chat stacking
|
||||
|
||||
// Channel can be null in replays so.
|
||||
// ReSharper disable once ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
|
||||
ShowOocPatronColor.Visible = _playerManager.LocalSession?.Channel?.UserData.PatronTier is { };
|
||||
|
||||
Control.AddOptionDropDown(CVars.InterfaceTheme, DropDownHudTheme, themeEntries);
|
||||
Control.AddOptionDropDown(CCVars.UILayout, DropDownHudLayout, layoutEntries);
|
||||
Control.AddOptionDropDown<int>(EECVars.ChatStackLastLines, ChatStackLastLines, chatStackEntries); // EE - Chat stacking
|
||||
|
||||
Control.AddOptionCheckBox(CVars.DiscordEnabled, DiscordRich);
|
||||
Control.AddOptionCheckBox(CCVars.ShowOocPatronColor, ShowOocPatronColor);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
using Content.Client.UserInterface.Systems.Chat.Controls;
|
||||
using Content.Shared._EE.CCVars; // EE - chat stacking
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.Audio;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Utility;
|
||||
|
|
@ -21,14 +22,23 @@ public partial class ChatBox : UIWidget
|
|||
{
|
||||
private readonly ChatUIController _controller;
|
||||
private readonly IEntityManager _entManager;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!; // EE - Chat stacking
|
||||
[Dependency] private readonly ILocalizationManager _loc = default!; // EE - Chat stacking
|
||||
|
||||
public bool Main { get; set; }
|
||||
|
||||
public ChatSelectChannel SelectedChannel => ChatInput.ChannelSelector.SelectedChannel;
|
||||
|
||||
// EE - Chat stacking
|
||||
private int _chatStackAmount = 0;
|
||||
private bool ChatStackEnabled => _chatStackAmount > 0;
|
||||
private List<ChatStackData> _chatStackList;
|
||||
// End EE - Chat stacking
|
||||
|
||||
public ChatBox()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
_entManager = IoCManager.Resolve<IEntityManager>();
|
||||
|
||||
ChatInput.Input.OnTextEntered += OnTextEntered;
|
||||
|
|
@ -41,6 +51,18 @@ public partial class ChatBox : UIWidget
|
|||
_controller.OnAutoHighlightsUpdated += ChatInput.FilterButton.Popup.SetAutoHighlights; // DeltaV - Message highlighting
|
||||
_controller.MessageAdded += OnMessageAdded;
|
||||
_controller.RegisterChat(this);
|
||||
|
||||
// EE - Chat stacking
|
||||
_chatStackList = new List<ChatStackData>(_chatStackAmount);
|
||||
_cfg.OnValueChanged(EECVars.ChatStackLastLines, UpdateChatStack, true);
|
||||
// End EE - Chat stacking
|
||||
}
|
||||
|
||||
// EE - Chat stacking
|
||||
private void UpdateChatStack(int value)
|
||||
{
|
||||
_chatStackAmount = value >= 0 ? value : 0;
|
||||
Repopulate();
|
||||
}
|
||||
|
||||
private void OnTextEntered(LineEditEventArgs args)
|
||||
|
|
@ -63,7 +85,54 @@ public partial class ChatBox : UIWidget
|
|||
|
||||
var color = msg.MessageColorOverride ?? msg.Channel.TextColor();
|
||||
|
||||
AddLine(msg.WrappedMessage, color);
|
||||
|
||||
// EE - Chat stacking
|
||||
var index = _chatStackList.FindIndex(data => data.WrappedMessage == msg.WrappedMessage);
|
||||
|
||||
if (index == -1) // this also handles chatstack being disabled, since FindIndex won't find anything in an empty array
|
||||
{
|
||||
TrackNewMessage(msg.WrappedMessage, color);
|
||||
AddLine(msg.WrappedMessage, color);
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateRepeatingLine(index);
|
||||
// End EE - Chat stacking
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removing and then adding instantly nudges the chat window up before slowly dragging it back down, which makes the whole chat log shake.
|
||||
/// With rapid enough updates, the whole chat becomes unreadable.
|
||||
/// Adding first and then removing does not produce any visual effects.
|
||||
/// The other option is to duplicate OutputPanel functionality and everything internal to the engine it relies on.
|
||||
/// But OutputPanel relies on directly setting Control.Position for control embedding. (which is not exposed to Content.)
|
||||
/// Thanks robustengine, very cool.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// zero index is the very last line in chat, 1 is the line before the last one, 2 is the line before that, etc.
|
||||
/// </remarks>
|
||||
// EE - Chat stacking
|
||||
private void UpdateRepeatingLine(int index)
|
||||
{
|
||||
_chatStackList[index].RepeatCount++;
|
||||
for (var i = index; i >= 0; i--)
|
||||
{
|
||||
var data = _chatStackList[i];
|
||||
AddLine(data.WrappedMessage, data.ColorOverride, data.RepeatCount);
|
||||
Contents.RemoveEntry(Index.FromEnd(index + 2));
|
||||
}
|
||||
}
|
||||
|
||||
// EE - Chat stacking
|
||||
private void TrackNewMessage(string wrappedMessage, Color colorOverride)
|
||||
{
|
||||
if (!ChatStackEnabled)
|
||||
return;
|
||||
|
||||
if (_chatStackList.Count == _chatStackList.Capacity)
|
||||
_chatStackList.RemoveAt(_chatStackList.Capacity - 1);
|
||||
|
||||
_chatStackList.Insert(0, new ChatStackData(wrappedMessage, colorOverride));
|
||||
}
|
||||
|
||||
private void OnChannelSelect(ChatSelectChannel channel)
|
||||
|
|
@ -74,7 +143,7 @@ public partial class ChatBox : UIWidget
|
|||
public void Repopulate()
|
||||
{
|
||||
Contents.Clear();
|
||||
|
||||
_chatStackList = new List<ChatStackData>(_chatStackAmount); // EE - Chat stacking
|
||||
foreach (var message in _controller.History)
|
||||
{
|
||||
OnMessageAdded(message.Item2);
|
||||
|
|
@ -96,12 +165,25 @@ public partial class ChatBox : UIWidget
|
|||
}
|
||||
}
|
||||
|
||||
public void AddLine(string message, Color color)
|
||||
public void AddLine(string message, Color color, int repeat = 0) // EE - Chat stacking - repeat
|
||||
{
|
||||
var formatted = new FormattedMessage(3);
|
||||
var formatted = new FormattedMessage(4); // EE - Chat stacking - up from 3
|
||||
formatted.PushColor(color);
|
||||
formatted.AddMarkupOrThrow(message);
|
||||
formatted.Pop();
|
||||
|
||||
// EE - Chat stacking
|
||||
if (repeat != 0)
|
||||
{
|
||||
var displayRepeat = repeat + 1;
|
||||
var sizeIncrease = Math.Min(displayRepeat / 6, 5);
|
||||
formatted.AddMarkupOrThrow(_loc.GetString("chat-system-repeated-message-counter",
|
||||
("count", displayRepeat),
|
||||
("size", 8 + sizeIncrease)
|
||||
));
|
||||
}
|
||||
// End EE - Chat stacking
|
||||
|
||||
Contents.AddMessage(formatted);
|
||||
}
|
||||
|
||||
|
|
@ -185,5 +267,20 @@ public partial class ChatBox : UIWidget
|
|||
ChatInput.Input.OnKeyBindDown -= OnInputKeyBindDown;
|
||||
ChatInput.Input.OnTextChanged -= OnTextChanged;
|
||||
ChatInput.ChannelSelector.OnChannelSelect -= OnChannelSelect;
|
||||
_cfg.UnsubValueChanged(EECVars.ChatStackLastLines, UpdateChatStack); // EE - Chat stacking
|
||||
}
|
||||
|
||||
// EE - Chat stacking
|
||||
private sealed class ChatStackData
|
||||
{
|
||||
public string WrappedMessage;
|
||||
public Color ColorOverride;
|
||||
public int RepeatCount = 0;
|
||||
public ChatStackData(string wrappedMessage, Color colorOverride)
|
||||
{
|
||||
WrappedMessage = wrappedMessage;
|
||||
ColorOverride = colorOverride;
|
||||
}
|
||||
}
|
||||
// End EE - Chat stacking
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
using Robust.Shared.Configuration;
|
||||
|
||||
namespace Content.Shared._EE.CCVars;
|
||||
|
||||
[CVarDefs]
|
||||
public sealed partial class EECVars
|
||||
{
|
||||
/// <summary>
|
||||
/// How many lines back in the chat log to look for collapsing repeated messages into one.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<int> ChatStackLastLines =
|
||||
CVarDef.Create("chat.chatstack_last_lines", 1, CVar.CLIENTONLY | CVar.ARCHIVE, "How far into the chat history to look when looking for similiar messages to coalesce them.");
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
chat-system-repeated-message-counter = {" "}[font size={$size}][color=#DD3333][bold]x{$count}![/bold][/color][/font]
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
ui-options-chatstack = Automatically merge identical chat messages
|
||||
ui-options-chatstack-count = { $count ->
|
||||
[0] Off
|
||||
[1] Last 1 message
|
||||
*[other] Last {$count} messages
|
||||
}
|
||||
Loading…
Reference in New Issue