diff --git a/Content.Client/Options/UI/Tabs/MiscTab.xaml b/Content.Client/Options/UI/Tabs/MiscTab.xaml
index c1733e209d..8a73aa9aec 100644
--- a/Content.Client/Options/UI/Tabs/MiscTab.xaml
+++ b/Content.Client/Options/UI/Tabs/MiscTab.xaml
@@ -9,6 +9,8 @@
StyleClasses="LabelKeyText"/>
+
+
diff --git a/Content.Client/Options/UI/Tabs/MiscTab.xaml.cs b/Content.Client/Options/UI/Tabs/MiscTab.xaml.cs
index 79000af58c..b254dd401b 100644
--- a/Content.Client/Options/UI/Tabs/MiscTab.xaml.cs
+++ b/Content.Client/Options/UI/Tabs/MiscTab.xaml.cs
@@ -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.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.ValueOption>();
+ for (var option = 0; option <= 3; option++)
+ {
+ chatStackEntries.Add(
+ new OptionDropDownCVar.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(EECVars.ChatStackLastLines, ChatStackLastLines, chatStackEntries); // EE - Chat stacking
Control.AddOptionCheckBox(CVars.DiscordEnabled, DiscordRich);
Control.AddOptionCheckBox(CCVars.ShowOocPatronColor, ShowOocPatronColor);
diff --git a/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs b/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
index f6c4cf407d..e7af05530f 100644
--- a/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
+++ b/Content.Client/UserInterface/Systems/Chat/Widgets/ChatBox.xaml.cs
@@ -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 _chatStackList;
+ // End EE - Chat stacking
+
public ChatBox()
{
RobustXamlLoader.Load(this);
+ IoCManager.InjectDependencies(this);
_entManager = IoCManager.Resolve();
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(_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
+ }
+
+ ///
+ /// 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.
+ ///
+ ///
+ /// zero index is the very last line in chat, 1 is the line before the last one, 2 is the line before that, etc.
+ ///
+ // 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(_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
}
diff --git a/Content.Shared/_EE/CCVars/CCVars.EE.cs b/Content.Shared/_EE/CCVars/CCVars.EE.cs
new file mode 100644
index 0000000000..151a7270e5
--- /dev/null
+++ b/Content.Shared/_EE/CCVars/CCVars.EE.cs
@@ -0,0 +1,13 @@
+using Robust.Shared.Configuration;
+
+namespace Content.Shared._EE.CCVars;
+
+[CVarDefs]
+public sealed partial class EECVars
+{
+ ///
+ /// How many lines back in the chat log to look for collapsing repeated messages into one.
+ ///
+ public static readonly CVarDef 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.");
+}
diff --git a/Resources/Locale/en-US/_EE/chat/chatstack.ftl b/Resources/Locale/en-US/_EE/chat/chatstack.ftl
new file mode 100644
index 0000000000..229a09a9ed
--- /dev/null
+++ b/Resources/Locale/en-US/_EE/chat/chatstack.ftl
@@ -0,0 +1 @@
+chat-system-repeated-message-counter = {" "}[font size={$size}][color=#DD3333][bold]x{$count}![/bold][/color][/font]
\ No newline at end of file
diff --git a/Resources/Locale/en-US/_EE/escape-menu/ui/options-menu.ftl b/Resources/Locale/en-US/_EE/escape-menu/ui/options-menu.ftl
new file mode 100644
index 0000000000..a98b21b90f
--- /dev/null
+++ b/Resources/Locale/en-US/_EE/escape-menu/ui/options-menu.ftl
@@ -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
+}