From e0793a51daeb2b1dac959f9c7175e1aa5d7d0d0a Mon Sep 17 00:00:00 2001 From: Harold Iedema Date: Thu, 18 Apr 2024 16:13:46 +0200 Subject: [PATCH] Add option to limit the amount of shown log lines --- ChatTwo/Configuration.cs | 2 + ChatTwo/Resources/Language.Designer.cs | 18 ++++++++ ChatTwo/Resources/Language.nl.resx | 62 ++++++++++++++------------ ChatTwo/Resources/Language.resx | 6 +++ ChatTwo/Ui/ChatLogWindow.cs | 6 ++- ChatTwo/Ui/SettingsTabs/Display.cs | 6 +++ ChatTwo/Util/ImGuiUtil.cs | 9 ++++ 7 files changed, 80 insertions(+), 29 deletions(-) diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 85c4a06..14446cb 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -39,6 +39,7 @@ internal class Configuration : IPluginConfiguration public bool SortAutoTranslate; public bool CollapseDuplicateMessages; public bool PlaySounds = true; + public int MaxLinesToRender = 10_000; public bool FontsEnabled = true; public ExtraGlyphRanges ExtraGlyphRanges = 0; @@ -83,6 +84,7 @@ internal class Configuration : IPluginConfiguration SortAutoTranslate = other.SortAutoTranslate; CollapseDuplicateMessages = other.CollapseDuplicateMessages; PlaySounds = other.PlaySounds; + MaxLinesToRender = other.MaxLinesToRender; FontsEnabled = other.FontsEnabled; ExtraGlyphRanges = other.ExtraGlyphRanges; FontSize = other.FontSize; diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index b4b4520..5cb6019 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -2093,6 +2093,24 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to Limits the amount of log lines to show in the chat window. This may slightly improve performance.. + /// + internal static string Options_MaxLinesToShow_Description { + get { + return ResourceManager.GetString("Options_MaxLinesToShow_Description", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Maximum amount of log lines to display in the chat window. + /// + internal static string Options_MaxLinesToShow_Name { + get { + return ResourceManager.GetString("Options_MaxLinesToShow_Name", resourceCulture); + } + } + /// /// Looks up a localized string similar to Miscellaneous. /// diff --git a/ChatTwo/Resources/Language.nl.resx b/ChatTwo/Resources/Language.nl.resx index 66c05b5..d8d0abe 100644 --- a/ChatTwo/Resources/Language.nl.resx +++ b/ChatTwo/Resources/Language.nl.resx @@ -1,17 +1,17 @@ - @@ -841,4 +841,10 @@ Vervang opeenvolgende dubbele berichten door een teller die is toegevoegd aan het eerste exemplaar van het bericht. + + Maximum aantal regels om te tonen in het chat venster + + + Limiteer het maximum aantal regels die worden getoont in het chatvester. + diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index bf1eaf5..d8c212c 100644 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -994,4 +994,10 @@ Play sounds on interaction. + + Maximum amount of log lines to display in the chat window + + + Limits the amount of log lines to show in the chat window. This may slightly improve performance. + diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index b6ea0e6..60893da 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -874,7 +874,11 @@ public sealed class ChatLogWindow : Window, IUiComponent var lastTimestamp = string.Empty; int? lastMessageHash = null; var sameCount = 0; - for (var i = 0; i < tab.Messages.Count; i++) + + int maxLines = Plugin.Config.MaxLinesToRender; + int startLine = tab.Messages.Count > maxLines ? tab.Messages.Count - maxLines : 0; + + for (int i = startLine; i < tab.Messages.Count; i++) { var message = tab.Messages[i]; diff --git a/ChatTwo/Ui/SettingsTabs/Display.cs b/ChatTwo/Ui/SettingsTabs/Display.cs index 8a73122..839d887 100755 --- a/ChatTwo/Ui/SettingsTabs/Display.cs +++ b/ChatTwo/Ui/SettingsTabs/Display.cs @@ -87,6 +87,12 @@ internal sealed class Display : ISettingsTab { ImGuiUtil.DragFloatVertical(Language.Options_WindowOpacity_Name, ref Mutable.WindowAlpha, .25f, 0f, 100f, $"{Mutable.WindowAlpha:N2}%%", ImGuiSliderFlags.AlwaysClamp); ImGui.Spacing(); + + if (ImGuiUtil.InputIntVertical(Language.Options_MaxLinesToShow_Name, Language.Options_MaxLinesToShow_Description, ref Mutable.MaxLinesToRender)) { + Mutable.MaxLinesToRender = Math.Clamp(Mutable.MaxLinesToRender, 1, 10_000); + } + ImGui.Spacing(); + ImGuiUtil.OptionCheckbox(ref Mutable.CanMove, Language.Options_CanMove_Name); ImGui.Spacing(); diff --git a/ChatTwo/Util/ImGuiUtil.cs b/ChatTwo/Util/ImGuiUtil.cs index ffb1534..3df1d9d 100755 --- a/ChatTwo/Util/ImGuiUtil.cs +++ b/ChatTwo/Util/ImGuiUtil.cs @@ -234,6 +234,15 @@ internal static class ImGuiUtil { return r; } + internal static bool InputIntVertical(string label, string description, ref int value, int step = 1, int stepFast = 100, ImGuiInputTextFlags flags = ImGuiInputTextFlags.None) { + ImGui.TextUnformatted(label); + ImGui.SetNextItemWidth(-1); + var r = ImGui.InputInt($"##{label}", ref value, step, stepFast, flags); + HelpText(description); + + return r; + } + internal static bool CtrlShiftButton(string label, string tooltip = "") { var io = ImGui.GetIO();