From c152f3dfdefe75185c2fbfc65ea864ed9f544c42 Mon Sep 17 00:00:00 2001 From: Infi Date: Sun, 21 Apr 2024 16:44:45 +0200 Subject: [PATCH] use ImRaii in settings window --- ChatTwo/Ui/ChatLogWindow.cs | 2 +- ChatTwo/Ui/Popout.cs | 5 +- ChatTwo/Ui/Settings.cs | 128 +++++----- ChatTwo/Ui/SettingsTabs/About.cs | 9 +- ChatTwo/Ui/SettingsTabs/ChatColours.cs | 33 +-- ChatTwo/Ui/SettingsTabs/Database.cs | 151 ++++++------ ChatTwo/Ui/SettingsTabs/Display.cs | 84 +++---- ChatTwo/Ui/SettingsTabs/Fonts.cs | 70 +++--- ChatTwo/Ui/SettingsTabs/ISettingsTab.cs | 3 +- ChatTwo/Ui/SettingsTabs/Miscellaneous.cs | 48 ++-- ChatTwo/Ui/SettingsTabs/Tabs.cs | 302 +++++++++++------------ ChatTwo/Ui/UiComponent.cs | 5 - 12 files changed, 402 insertions(+), 438 deletions(-) delete mode 100755 ChatTwo/Ui/UiComponent.cs diff --git a/ChatTwo/Ui/ChatLogWindow.cs b/ChatTwo/Ui/ChatLogWindow.cs index 2b43c99..37a8c6d 100644 --- a/ChatTwo/Ui/ChatLogWindow.cs +++ b/ChatTwo/Ui/ChatLogWindow.cs @@ -23,7 +23,7 @@ using Lumina.Excel.GeneratedSheets; namespace ChatTwo.Ui; -public sealed class ChatLogWindow : Window, IUiComponent +public sealed class ChatLogWindow : Window { private const string ChatChannelPicker = "chat-channel-picker"; private const string AutoCompleteId = "##chat2-autocomplete"; diff --git a/ChatTwo/Ui/Popout.cs b/ChatTwo/Ui/Popout.cs index 3df1795..3883a67 100644 --- a/ChatTwo/Ui/Popout.cs +++ b/ChatTwo/Ui/Popout.cs @@ -1,5 +1,6 @@ using System.Numerics; using Dalamud.Interface.Style; +using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; using ImGuiNET; @@ -47,7 +48,7 @@ internal class Popout : Window public override void Draw() { - ImGui.PushID($"popout-{Tab.Name}"); + using var id = ImRaii.PushId($"popout-{Tab.Name}"); if (!ChatLogWindow.Plugin.Config.ShowPopOutTitleBar) { ImGui.TextUnformatted(Tab.Name); @@ -56,8 +57,6 @@ internal class Popout : Window var handler = ChatLogWindow.HandlerLender.Borrow(); ChatLogWindow.DrawMessageLog(Tab, handler, ImGui.GetContentRegionAvail().Y, false); - - ImGui.PopID(); } public override void PostDraw() diff --git a/ChatTwo/Ui/Settings.cs b/ChatTwo/Ui/Settings.cs index 4abae74..2e21e6f 100755 --- a/ChatTwo/Ui/Settings.cs +++ b/ChatTwo/Ui/Settings.cs @@ -2,13 +2,14 @@ using System.Numerics; using ChatTwo.Resources; using ChatTwo.Ui.SettingsTabs; using ChatTwo.Util; +using Dalamud.Interface.Utility.Raii; using Dalamud.Interface.Windowing; using Dalamud.Utility; using ImGuiNET; namespace ChatTwo.Ui; -public sealed class SettingsWindow : Window, IUiComponent +public sealed class SettingsWindow : Window { private readonly Plugin Plugin; @@ -30,7 +31,8 @@ public sealed class SettingsWindow : Window, IUiComponent Plugin = plugin; Mutable = new Configuration(); - Tabs = new List { + Tabs = new List + { new Display(Mutable), new Ui.SettingsTabs.Fonts(Mutable), new ChatColours(Mutable, Plugin), @@ -49,17 +51,20 @@ public sealed class SettingsWindow : Window, IUiComponent Plugin.Interface.UiBuilder.OpenConfigUi += Toggle; } - public void Dispose() { + public void Dispose() + { Plugin.Interface.UiBuilder.OpenConfigUi -= Toggle; Plugin.Commands.Register("/chat2").Execute -= Command; } - private void Command(string command, string args) { + private void Command(string command, string args) + { if (string.IsNullOrWhiteSpace(args)) Toggle(); } - private void Initialise() { + private void Initialise() + { Mutable.UpdateFrom(Plugin.Config); } @@ -68,33 +73,33 @@ public sealed class SettingsWindow : Window, IUiComponent if (ImGui.IsWindowAppearing()) Initialise(); - if (ImGui.BeginTable("##chat2-settings-table", 2)) { - ImGui.TableSetupColumn("tab", ImGuiTableColumnFlags.WidthFixed); - ImGui.TableSetupColumn("settings", ImGuiTableColumnFlags.WidthStretch); + using (var table = ImRaii.Table("##chat2-settings-table", 2)) + { + if (table) + { + ImGui.TableSetupColumn("tab", ImGuiTableColumnFlags.WidthFixed); + ImGui.TableSetupColumn("settings", ImGuiTableColumnFlags.WidthStretch); - ImGui.TableNextColumn(); + ImGui.TableNextColumn(); + + var changed = false; + for (var i = 0; i < Tabs.Count; i++) + { + if (!ImGui.Selectable($"{Tabs[i].Name}###tab-{i}", CurrentTab == i)) + continue; - var changed = false; - for (var i = 0; i < Tabs.Count; i++) { - if (ImGui.Selectable($"{Tabs[i].Name}###tab-{i}", CurrentTab == i)) { CurrentTab = i; changed = true; } + + ImGui.TableNextColumn(); + + var height = ImGui.GetContentRegionAvail().Y - ImGui.GetStyle().FramePadding.Y * 2 - ImGui.GetStyle().ItemSpacing.Y + - ImGui.GetStyle().ItemInnerSpacing.Y * 2 - ImGui.CalcTextSize("A").Y; + using var child = ImRaii.Child("##chat2-settings", new Vector2(-1, height)); + if (child) + Tabs[CurrentTab].Draw(changed); } - - ImGui.TableNextColumn(); - - var height = ImGui.GetContentRegionAvail().Y - - ImGui.GetStyle().FramePadding.Y * 2 - - ImGui.GetStyle().ItemSpacing.Y - - ImGui.GetStyle().ItemInnerSpacing.Y * 2 - - ImGui.CalcTextSize("A").Y; - if (ImGui.BeginChild("##chat2-settings", new Vector2(-1, height))) { - Tabs[CurrentTab].Draw(changed); - ImGui.EndChild(); - } - - ImGui.EndTable(); } ImGui.Separator(); @@ -114,65 +119,52 @@ public sealed class SettingsWindow : Window, IUiComponent IsOpen = false; } - var buttonLabel = "Anna's Ko-fi"; - var buttonLabel2 = "Infi's Ko-fi"; + const string buttonLabel = "Anna's Ko-fi"; + const string buttonLabel2 = "Infi's Ko-fi"; - ImGui.PushStyleColor(ImGuiCol.Button, ColourUtil.RgbaToAbgr(0xFF5E5BFF)); - ImGui.PushStyleColor(ImGuiCol.ButtonHovered, ColourUtil.RgbaToAbgr(0xFF7775FF)); - ImGui.PushStyleColor(ImGuiCol.ButtonActive, ColourUtil.RgbaToAbgr(0xFF4542FF)); - ImGui.PushStyleColor(ImGuiCol.Text, 0xFFFFFFFF); - - try { + using (ImRaii.PushColor(ImGuiCol.Button, ColourUtil.RgbaToAbgr(0xFF5E5BFF))) + using (ImRaii.PushColor(ImGuiCol.ButtonHovered, ColourUtil.RgbaToAbgr(0xFF7775FF))) + using (ImRaii.PushColor(ImGuiCol.ButtonActive, ColourUtil.RgbaToAbgr(0xFF4542FF))) + using (ImRaii.PushColor(ImGuiCol.Text, 0xFFFFFFFF)) + { var buttonWidth = ImGui.CalcTextSize(buttonLabel).X + ImGui.GetStyle().FramePadding.X * 2; var buttonWidth2 = ImGui.CalcTextSize(buttonLabel2).X + ImGui.GetStyle().FramePadding.X * 2; ImGui.SameLine(ImGui.GetContentRegionAvail().X - buttonWidth - buttonWidth2); - if (ImGui.Button(buttonLabel2)) { + if (ImGui.Button(buttonLabel2)) Dalamud.Utility.Util.OpenLink("https://ko-fi.com/infiii"); - } ImGui.SameLine(); - if (ImGui.Button(buttonLabel)) { + if (ImGui.Button(buttonLabel)) Dalamud.Utility.Util.OpenLink("https://ko-fi.com/lojewalo"); - } - } finally { - ImGui.PopStyleColor(4); } - if (save) { - var config = Plugin.Config; + if (!save) + return; - var hideChatChanged = Mutable.HideChat != Plugin.Config.HideChat; - var fontChanged = Mutable.GlobalFont != Plugin.Config.GlobalFont - || Mutable.JapaneseFont != Plugin.Config.JapaneseFont - || Mutable.ExtraGlyphRanges != Plugin.Config.ExtraGlyphRanges; - var fontSizeChanged = Math.Abs(Mutable.FontSize - Plugin.Config.FontSize) > 0.001 - || Math.Abs(Mutable.JapaneseFontSize - Plugin.Config.JapaneseFontSize) > 0.001 - || Math.Abs(Mutable.SymbolsFontSize - Plugin.Config.SymbolsFontSize) > 0.001; - var langChanged = Mutable.LanguageOverride != Plugin.Config.LanguageOverride; + Plugin.Config.UpdateFrom(Mutable); - config.UpdateFrom(Mutable); + // save after 60 frames have passed, which should hopefully not + // commit any changes that cause a crash + Plugin.DeferredSaveFrames = 60; + Plugin.MessageManager.FilterAllTabs(false); - // save after 60 frames have passed, which should hopefully not - // commit any changes that cause a crash - Plugin.DeferredSaveFrames = 60; + var fontChanged = Mutable.GlobalFont != Plugin.Config.GlobalFont + || Mutable.JapaneseFont != Plugin.Config.JapaneseFont + || Mutable.ExtraGlyphRanges != Plugin.Config.ExtraGlyphRanges; + var fontSizeChanged = Math.Abs(Mutable.FontSize - Plugin.Config.FontSize) > 0.001 + || Math.Abs(Mutable.JapaneseFontSize - Plugin.Config.JapaneseFontSize) > 0.001 + || Math.Abs(Mutable.SymbolsFontSize - Plugin.Config.SymbolsFontSize) > 0.001; + if (fontChanged || fontSizeChanged) + Plugin.FontManager.BuildFonts(); - Plugin.MessageManager.FilterAllTabs(false); + if (Mutable.LanguageOverride != Plugin.Config.LanguageOverride) + Plugin.LanguageChanged(Plugin.Interface.UiLanguage); - if (fontChanged || fontSizeChanged) { - Plugin.FontManager.BuildFonts(); - } + if (!Mutable.HideChat && Mutable.HideChat != Plugin.Config.HideChat) + GameFunctions.GameFunctions.SetChatInteractable(true); - if (langChanged) { - Plugin.LanguageChanged(Plugin.Interface.UiLanguage); - } - - if (!Mutable.HideChat && hideChatChanged) { - GameFunctions.GameFunctions.SetChatInteractable(true); - } - - Initialise(); - } + Initialise(); } } diff --git a/ChatTwo/Ui/SettingsTabs/About.cs b/ChatTwo/Ui/SettingsTabs/About.cs index 58575eb..1f81526 100755 --- a/ChatTwo/Ui/SettingsTabs/About.cs +++ b/ChatTwo/Ui/SettingsTabs/About.cs @@ -9,7 +9,8 @@ using ImGuiNET; namespace ChatTwo.Ui.SettingsTabs; -internal sealed class About : ISettingsTab { +internal sealed class About : ISettingsTab +{ public string Name => string.Format(Language.Options_About_Tab, Plugin.PluginName) + "###tabs-about"; private readonly List _translators = @@ -25,11 +26,13 @@ internal sealed class About : ISettingsTab { "zomsakura", "Sirayuki" ]; - internal About() { + internal About() + { _translators.Sort((a, b) => string.Compare(a.ToLowerInvariant(), b.ToLowerInvariant(), StringComparison.Ordinal)); } - public void Draw(bool changed) { + public void Draw(bool changed) + { ImGui.PushTextWrapPos(); ImGui.TextUnformatted(string.Format(Language.Options_About_Opening, Plugin.PluginName)); diff --git a/ChatTwo/Ui/SettingsTabs/ChatColours.cs b/ChatTwo/Ui/SettingsTabs/ChatColours.cs index afbfb34..2dbfb62 100755 --- a/ChatTwo/Ui/SettingsTabs/ChatColours.cs +++ b/ChatTwo/Ui/SettingsTabs/ChatColours.cs @@ -6,46 +6,50 @@ using ImGuiNET; namespace ChatTwo.Ui.SettingsTabs; -internal sealed class ChatColours : ISettingsTab { +internal sealed class ChatColours : ISettingsTab +{ private Configuration Mutable { get; } private Plugin Plugin { get; } public string Name => Language.Options_ChatColours_Tab + "###tabs-chat-colours"; - internal ChatColours(Configuration mutable, Plugin plugin) { + internal ChatColours(Configuration mutable, Plugin plugin) + { Mutable = mutable; Plugin = plugin; #if DEBUG + // Users can set colours for ExtraChat linkshells in the ExtraChat plugin directly. var sortable = ChatTypeExt.SortOrder .SelectMany(entry => entry.Item2) - // Users can set colours for ExtraChat linkshells in the ExtraChat - // plugin directly. .Where(type => !type.IsGm() && !type.IsExtraChatLinkshell()) .ToHashSet(); var total = Enum.GetValues() .Where(type => !type.IsGm() && !type.IsExtraChatLinkshell()) .ToHashSet(); - if (sortable.Count != total.Count) { + if (sortable.Count != total.Count) + { Plugin.Log.Warning($"There are {sortable.Count} sortable channels, but there are {total.Count} total channels."); total.ExceptWith(sortable); - foreach (var missing in total) { + foreach (var missing in total) Plugin.Log.Information($"Missing {missing}"); - } } #endif } - public void Draw(bool changed) { - foreach (var (_, types) in ChatTypeExt.SortOrder) { - foreach (var type in types) { - if (ImGuiUtil.IconButton(FontAwesomeIcon.UndoAlt, $"{type}", Language.Options_ChatColours_Reset)) { + public void Draw(bool changed) + { + foreach (var (_, types) in ChatTypeExt.SortOrder) + { + foreach (var type in types) + { + if (ImGuiUtil.IconButton(FontAwesomeIcon.UndoAlt, $"{type}", Language.Options_ChatColours_Reset)) Mutable.ChatColours.Remove(type); - } ImGui.SameLine(); - if (ImGuiUtil.IconButton(FontAwesomeIcon.LongArrowAltDown, $"{type}", Language.Options_ChatColours_Import)) { + if (ImGuiUtil.IconButton(FontAwesomeIcon.LongArrowAltDown, $"{type}", Language.Options_ChatColours_Import)) + { var gameColour = Plugin.Functions.Chat.GetChannelColour(type); Mutable.ChatColours[type] = gameColour ?? type.DefaultColour() ?? 0; } @@ -55,9 +59,8 @@ internal sealed class ChatColours : ISettingsTab { var vec = Mutable.ChatColours.TryGetValue(type, out var colour) ? ColourUtil.RgbaToVector3(colour) : ColourUtil.RgbaToVector3(type.DefaultColour() ?? 0); - if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs)) { + if (ImGui.ColorEdit3(type.Name(), ref vec, ImGuiColorEditFlags.NoInputs)) Mutable.ChatColours[type] = ColourUtil.Vector3ToRgba(vec); - } } } diff --git a/ChatTwo/Ui/SettingsTabs/Database.cs b/ChatTwo/Ui/SettingsTabs/Database.cs index 2e75604..aa75cb4 100755 --- a/ChatTwo/Ui/SettingsTabs/Database.cs +++ b/ChatTwo/Ui/SettingsTabs/Database.cs @@ -5,6 +5,7 @@ using ChatTwo.Util; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface.Internal.Notifications; +using Dalamud.Interface.Utility.Raii; using ImGuiNET; namespace ChatTwo.Ui.SettingsTabs; @@ -29,7 +30,8 @@ internal sealed class Database : ISettingsTab private long DatabaseLogSize; private int DatabaseMessageCount; - public void Draw(bool changed) { + public void Draw(bool changed) + { if (changed) ShowAdvanced = ImGui.GetIO().KeyShift; @@ -37,18 +39,14 @@ internal sealed class Database : ISettingsTab ImGui.Spacing(); if (ImGuiUtil.OptionCheckbox(ref Mutable.LoadPreviousSession, Language.Options_LoadPreviousSession_Name, Language.Options_LoadPreviousSession_Description)) - { if (Mutable.LoadPreviousSession) Mutable.FilterIncludePreviousSessions = true; - } ImGui.Spacing(); if (ImGuiUtil.OptionCheckbox(ref Mutable.FilterIncludePreviousSessions, Language.Options_FilterIncludePreviousSessions_Name, Language.Options_FilterIncludePreviousSessions_Description)) - { if (!Mutable.FilterIncludePreviousSessions) Mutable.LoadPreviousSession = false; - } ImGui.Spacing(); ImGui.Separator(); @@ -80,86 +78,86 @@ internal sealed class Database : ISettingsTab } ImGui.TextUnformatted(Language.Options_Database_Metadata_Heading); - var style = ImGui.GetStyle(); - ImGui.Indent(style.IndentSpacing); - - // Refresh the database size and message count every 5 seconds to avoid - // constant stat calls and spamming the database. - if (DatabaseLastRefreshTicks + 5 * 1000 < Environment.TickCount64) + using (ImRaii.PushIndent(ImGui.GetStyle().IndentSpacing, false)) { - DatabaseSize = Plugin.MessageManager.Store.DatabaseSize(); - DatabaseLogSize = Plugin.MessageManager.Store.DatabaseLogSize(); - DatabaseMessageCount = Plugin.MessageManager.Store.MessageCount(); - DatabaseLastRefreshTicks = Environment.TickCount64; - } + // Refresh the database size and message count every 5 seconds to avoid + // constant stat calls and spamming the database. + if (DatabaseLastRefreshTicks + 5 * 1000 < Environment.TickCount64) + { + DatabaseSize = Plugin.MessageManager.Store.DatabaseSize(); + DatabaseLogSize = Plugin.MessageManager.Store.DatabaseLogSize(); + DatabaseMessageCount = Plugin.MessageManager.Store.MessageCount(); + DatabaseLastRefreshTicks = Environment.TickCount64; + } - ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Path, MessageManager.DatabasePath())); - if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) - { // Copy the directory path instead of the file path so people can // paste it into their file explorer. - var path = Path.GetDirectoryName(MessageManager.DatabasePath()); - ImGui.SetClipboardText(path); - WrapperUtil.AddNotification(Language.Options_Database_Metadata_CopyConfigPathNotification, NotificationType.Info); + ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Path, MessageManager.DatabasePath())); + if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) + { + var path = Path.GetDirectoryName(MessageManager.DatabasePath()); + ImGui.SetClipboardText(path); + WrapperUtil.AddNotification(Language.Options_Database_Metadata_CopyConfigPathNotification, NotificationType.Info); + } + + if (ImGui.IsItemHovered()) + { + ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); + ImGui.SetTooltip(Language.Options_Database_Metadata_CopyConfigPath); + } + + ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Size, StringUtil.BytesToString(DatabaseSize))); + if (ImGui.IsItemHovered()) + ImGui.SetTooltip(DatabaseSize.ToString("N0") + "B"); + + ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_LogSize, StringUtil.BytesToString(DatabaseLogSize))); + if (ImGui.IsItemHovered()) + ImGui.SetTooltip(DatabaseLogSize.ToString("N0") + "B"); + + ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_MessageCount, DatabaseMessageCount)); + + if (ImGuiUtil.CtrlShiftButton(Language.Options_ClearDatabase_Button, Language.Options_ClearDatabase_Tooltip)) + { + Plugin.Log.Warning("Clearing messages from database"); + Plugin.MessageManager.Store.ClearMessages(); + foreach (var tab in Plugin.Config.Tabs) + tab.Clear(); + + // Refresh on next draw + DatabaseLastRefreshTicks = 0; + WrapperUtil.AddNotification(Language.Options_ClearDatabase_Success, NotificationType.Info); + } } - if (ImGui.IsItemHovered()) + ImGui.Spacing(); + + if (!ShowAdvanced) + return; + + using var treeNode = ImRaii.TreeNode(Language.Options_Database_Advanced); + ImGui.PushTextWrapPos(); + ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning); + + if (ImGuiUtil.CtrlShiftButton("Perform maintenance", "Ctrl+Shift: MessageManager.Store.PerformMaintenance()")) + Plugin.MessageManager.Store.PerformMaintenance(); + + if (ImGuiUtil.CtrlShiftButton("Reload messages from database", "Ctrl+Shift: MessageManager.FilterAllTabs(false)")) { - ImGui.SetMouseCursor(ImGuiMouseCursor.Hand); - ImGui.SetTooltip(Language.Options_Database_Metadata_CopyConfigPath); - } - - ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_Size, StringUtil.BytesToString(DatabaseSize))); - if (ImGui.IsItemHovered()) - ImGui.SetTooltip(DatabaseSize.ToString("N0") + "B"); - - ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_LogSize, StringUtil.BytesToString(DatabaseLogSize))); - if (ImGui.IsItemHovered()) - ImGui.SetTooltip(DatabaseLogSize.ToString("N0") + "B"); - - ImGuiUtil.HelpText(string.Format(Language.Options_Database_Metadata_MessageCount, DatabaseMessageCount)); - - if (ImGuiUtil.CtrlShiftButton(Language.Options_ClearDatabase_Button, Language.Options_ClearDatabase_Tooltip)) - { - Plugin.Log.Warning("Clearing messages from database"); - Plugin.MessageManager.Store.ClearMessages(); foreach (var tab in Plugin.Config.Tabs) tab.Clear(); - // Refresh on next draw - DatabaseLastRefreshTicks = 0; - WrapperUtil.AddNotification(Language.Options_ClearDatabase_Success, NotificationType.Info); + Plugin.MessageManager.FilterAllTabs(false); } - ImGui.Unindent(style.IndentSpacing); - ImGui.Spacing(); - - if (ShowAdvanced && ImGui.TreeNodeEx(Language.Options_Database_Advanced)) - { - ImGui.PushTextWrapPos(); - ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning); - - if (ImGuiUtil.CtrlShiftButton("Perform maintenance", "Ctrl+Shift: MessageManager.Store.PerformMaintenance()")) - Plugin.MessageManager.Store.PerformMaintenance(); - - if (ImGuiUtil.CtrlShiftButton("Reload messages from database", - "Ctrl+Shift: MessageManager.FilterAllTabs(false)")) { - foreach (var tab in Plugin.Config.Tabs) - tab.Clear(); - Plugin.MessageManager.FilterAllTabs(false); - } - - if (ImGuiUtil.CtrlShiftButton("Inject 10,000 messages", "Ctrl+Shift: creates 10,000 unique messages (async)")) - new Thread(() => InsertMessages(10_000)).Start(); - - ImGui.PopTextWrapPos(); - ImGui.TreePop(); - } + if (ImGuiUtil.CtrlShiftButton("Inject 10,000 messages", "Ctrl+Shift: creates 10,000 unique messages (async)")) + new Thread(() => InsertMessages(10_000)).Start(); + ImGui.PopTextWrapPos(); ImGui.Spacing(); } - private void InsertMessages(int count) { + private void InsertMessages(int count) + { Plugin.Log.Info($"Inserting {count} messages due to user request"); // Generate @@ -175,7 +173,8 @@ internal sealed class Database : ISettingsTab .Build(); var senderChunks = ChunkUtil.ToChunks(senderSource, ChunkSource.Sender, ChatType.Debug).ToList(); var messages = new List(count); - for (var i = 0; i < count; i++) { + for (var i = 0; i < count; i++) + { var contentSource = new SeStringBuilder() .AddText("Random message payload - ") .AddItalics(Guid.NewGuid().ToString()) @@ -203,28 +202,28 @@ internal sealed class Database : ISettingsTab // Insert stopwatch = Stopwatch.StartNew(); - foreach (var message in messages) { + foreach (var message in messages) Plugin.MessageManager.Store.UpsertMessage(message); - } elapsedTicks = stopwatch.ElapsedTicks; stopwatch.Stop(); Plugin.Log.Info($"Upserted {count} messages in {elapsedTicks} ticks ({elapsedTicks / TimeSpan.TicksPerMillisecond}ms)"); // Clear tabs during framework frame - Plugin.Framework.Run(() => { + Plugin.Framework.Run(() => + { stopwatch = Stopwatch.StartNew(); foreach (var tab in Plugin.Config.Tabs) tab.Clear(); elapsedTicks = stopwatch.ElapsedTicks; stopwatch.Stop(); - Plugin.Log.Info( - $"Cleared {Plugin.Config.Tabs.Count} tabs in {elapsedTicks} ticks ({elapsedTicks / TimeSpan.TicksPerMillisecond}ms)"); + Plugin.Log.Info($"Cleared {Plugin.Config.Tabs.Count} tabs in {elapsedTicks} ticks ({elapsedTicks / TimeSpan.TicksPerMillisecond}ms)"); }).Wait(); // Fetch and filter during framework frame - Plugin.Framework.Run(() => { + Plugin.Framework.Run(() => + { stopwatch = Stopwatch.StartNew(); Plugin.MessageManager.FilterAllTabs(false); elapsedTicks = stopwatch.ElapsedTicks; diff --git a/ChatTwo/Ui/SettingsTabs/Display.cs b/ChatTwo/Ui/SettingsTabs/Display.cs index 1d820b8..07ad72e 100755 --- a/ChatTwo/Ui/SettingsTabs/Display.cs +++ b/ChatTwo/Ui/SettingsTabs/Display.cs @@ -1,20 +1,24 @@ using ChatTwo.Resources; using ChatTwo.Util; using Dalamud.Interface.Style; +using Dalamud.Interface.Utility.Raii; using ImGuiNET; namespace ChatTwo.Ui.SettingsTabs; -internal sealed class Display : ISettingsTab { +internal sealed class Display : ISettingsTab +{ private Configuration Mutable { get; } public string Name => Language.Options_Display_Tab + "###tabs-display"; - internal Display(Configuration mutable) { + internal Display(Configuration mutable) + { Mutable = mutable; } - public void Draw(bool changed) { + public void Draw(bool changed) + { ImGui.PushTextWrapPos(); ImGuiUtil.OptionCheckbox(ref Mutable.PlaySounds, Language.Options_PlaySounds_Name, Language.Options_PlaySounds_Description); @@ -23,56 +27,33 @@ internal sealed class Display : ISettingsTab { ImGuiUtil.OptionCheckbox(ref Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description); ImGui.Spacing(); - ImGuiUtil.OptionCheckbox( - ref Mutable.HideDuringCutscenes, - Language.Options_HideDuringCutscenes_Name, - string.Format(Language.Options_HideDuringCutscenes_Description, Plugin.PluginName) - ); + ImGuiUtil.OptionCheckbox(ref Mutable.HideDuringCutscenes, Language.Options_HideDuringCutscenes_Name, string.Format(Language.Options_HideDuringCutscenes_Description, Plugin.PluginName)); ImGui.Spacing(); - ImGuiUtil.OptionCheckbox( - ref Mutable.HideWhenNotLoggedIn, - Language.Options_HideWhenNotLoggedIn_Name, - string.Format(Language.Options_HideWhenNotLoggedIn_Description, Plugin.PluginName) - ); + ImGuiUtil.OptionCheckbox(ref Mutable.HideWhenNotLoggedIn, Language.Options_HideWhenNotLoggedIn_Name, string.Format(Language.Options_HideWhenNotLoggedIn_Description, Plugin.PluginName)); ImGui.Spacing(); - ImGuiUtil.OptionCheckbox( - ref Mutable.HideWhenUiHidden, - Language.Options_HideWhenUiHidden_Name, - string.Format(Language.Options_HideWhenUiHidden_Description, Plugin.PluginName) - ); + ImGuiUtil.OptionCheckbox(ref Mutable.HideWhenUiHidden, Language.Options_HideWhenUiHidden_Name, string.Format(Language.Options_HideWhenUiHidden_Description, Plugin.PluginName)); ImGui.Spacing(); - ImGuiUtil.OptionCheckbox( - ref Mutable.HideInLoadingScreens, - Language.Options_HideInLoadingScreens_Name, - string.Format(Language.Options_HideInLoadingScreens_Description, Plugin.PluginName)); + ImGuiUtil.OptionCheckbox(ref Mutable.HideInLoadingScreens, Language.Options_HideInLoadingScreens_Name, string.Format(Language.Options_HideInLoadingScreens_Description, Plugin.PluginName)); ImGui.Spacing(); - ImGuiUtil.OptionCheckbox( - ref Mutable.NativeItemTooltips, - Language.Options_NativeItemTooltips_Name, - string.Format(Language.Options_NativeItemTooltips_Description, Plugin.PluginName) - ); + ImGuiUtil.OptionCheckbox(ref Mutable.NativeItemTooltips, Language.Options_NativeItemTooltips_Name, string.Format(Language.Options_NativeItemTooltips_Description, Plugin.PluginName)); ImGui.Spacing(); - ImGuiUtil.OptionCheckbox( - ref Mutable.SidebarTabView, - Language.Options_SidebarTabView_Name, - string.Format(Language.Options_SidebarTabView_Description, Plugin.PluginName) - ); + ImGuiUtil.OptionCheckbox(ref Mutable.SidebarTabView, Language.Options_SidebarTabView_Name, string.Format(Language.Options_SidebarTabView_Description, Plugin.PluginName)); ImGui.Spacing(); ImGuiUtil.OptionCheckbox(ref Mutable.PrettierTimestamps, Language.Options_PrettierTimestamps_Name, Language.Options_PrettierTimestamps_Description); - if (Mutable.PrettierTimestamps) { + if (Mutable.PrettierTimestamps) + { ImGui.TreePush(); ImGuiUtil.OptionCheckbox(ref Mutable.MoreCompactPretty, Language.Options_MoreCompactPretty_Name, Language.Options_MoreCompactPretty_Description); ImGuiUtil.OptionCheckbox(ref Mutable.HideSameTimestamps, Language.Options_HideSameTimestamps_Name, Language.Options_HideSameTimestamps_Description); ImGui.TreePop(); } - ImGui.Spacing(); ImGuiUtil.OptionCheckbox(ref Mutable.CollapseDuplicateMessages, Language.Options_CollapseDuplicateMessages_Name, Language.Options_CollapseDuplicateMessages_Description); @@ -106,29 +87,26 @@ internal sealed class Display : ISettingsTab { ImGuiUtil.OptionCheckbox(ref Mutable.OverrideStyle, Language.Options_OverrideStyle_Name, Language.Options_OverrideStyle_Name_Desc); ImGui.Spacing(); + ImGui.PopTextWrapPos(); - if (Mutable.OverrideStyle) + if (!Mutable.OverrideStyle) + return; + + var styles = StyleModel.GetConfiguredStyles(); + if (styles == null) { - var styles = StyleModel.GetConfiguredStyles(); - if (styles != null) - { - var currentStyle = Mutable.ChosenStyle ?? Language.Options_OverrideStyle_NotSelected; - if (ImGui.BeginCombo(Language.Options_OverrideStyleDropdown_Name, currentStyle)) - { - foreach (var style in styles) - if (ImGui.Selectable(style.Name, Mutable.ChosenStyle == style.Name)) - Mutable.ChosenStyle = style.Name; - - ImGui.EndCombo(); - } - } - else - { - ImGui.TextUnformatted(Language.Options_OverrideStyle_NotAvailable); - } + ImGui.TextUnformatted(Language.Options_OverrideStyle_NotAvailable); + ImGui.Spacing(); + return; } + var currentStyle = Mutable.ChosenStyle ?? Language.Options_OverrideStyle_NotSelected; + using var combo = ImRaii.Combo(Language.Options_OverrideStyleDropdown_Name, currentStyle); + if (combo) + foreach (var style in styles) + if (ImGui.Selectable(style.Name, Mutable.ChosenStyle == style.Name)) + Mutable.ChosenStyle = style.Name; + ImGui.Spacing(); - ImGui.PopTextWrapPos(); } } diff --git a/ChatTwo/Ui/SettingsTabs/Fonts.cs b/ChatTwo/Ui/SettingsTabs/Fonts.cs index 7aa45d7..f2f2954 100755 --- a/ChatTwo/Ui/SettingsTabs/Fonts.cs +++ b/ChatTwo/Ui/SettingsTabs/Fonts.cs @@ -4,55 +4,58 @@ using ImGuiNET; namespace ChatTwo.Ui.SettingsTabs; -public class Fonts : ISettingsTab { +public class Fonts : ISettingsTab +{ private Configuration Mutable { get; } public string Name => Language.Options_Fonts_Tab + "###tabs-fonts"; - private List GlobalFonts { get; set; } = new(); - private List JpFonts { get; set; } = new(); + private List GlobalFonts { get; set; } = []; + private List JpFonts { get; set; } = []; - internal Fonts(Configuration mutable) { + internal Fonts(Configuration mutable) + { Mutable = mutable; UpdateFonts(); } - private void UpdateFonts() { + private void UpdateFonts() + { GlobalFonts = Ui.Fonts.GetFonts(); JpFonts = Ui.Fonts.GetJpFonts(); } - public void Draw(bool changed) { - if (changed) { + public void Draw(bool changed) + { + if (changed) UpdateFonts(); - } ImGui.PushTextWrapPos(); ImGui.Checkbox(Language.Options_FontsEnabled, ref Mutable.FontsEnabled); ImGui.Spacing(); - if (Mutable.FontsEnabled) { - if (ImGuiUtil.BeginComboVertical(Language.Options_Font_Name, Mutable.GlobalFont)) { - foreach (var font in Ui.Fonts.GlobalFonts) { - if (ImGui.Selectable(font.Name, Mutable.GlobalFont == font.Name)) { + if (Mutable.FontsEnabled) + { + if (ImGuiUtil.BeginComboVertical(Language.Options_Font_Name, Mutable.GlobalFont)) + { + foreach (var font in Ui.Fonts.GlobalFonts) + { + if (ImGui.Selectable(font.Name, Mutable.GlobalFont == font.Name)) Mutable.GlobalFont = font.Name; - } - if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == font.Name) { + if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == font.Name) ImGui.SetScrollHereY(0.5f); - } } ImGui.Separator(); - foreach (var name in GlobalFonts) { - if (ImGui.Selectable(name, Mutable.GlobalFont == name)) { + foreach (var name in GlobalFonts) + { + if (ImGui.Selectable(name, Mutable.GlobalFont == name)) Mutable.GlobalFont = name; - } - if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == name) { + if (ImGui.IsWindowAppearing() && Mutable.GlobalFont == name) ImGui.SetScrollHereY(0.5f); - } } ImGui.EndCombo(); @@ -62,27 +65,26 @@ public class Fonts : ISettingsTab { ImGuiUtil.WarningText(Language.Options_Font_Warning); ImGui.Spacing(); - if (ImGuiUtil.BeginComboVertical(Language.Options_JapaneseFont_Name, Mutable.JapaneseFont)) { - foreach (var (name, _) in Ui.Fonts.JapaneseFonts) { - if (ImGui.Selectable(name, Mutable.JapaneseFont == name)) { + if (ImGuiUtil.BeginComboVertical(Language.Options_JapaneseFont_Name, Mutable.JapaneseFont)) + { + foreach (var (name, _) in Ui.Fonts.JapaneseFonts) + { + if (ImGui.Selectable(name, Mutable.JapaneseFont == name)) Mutable.JapaneseFont = name; - } - if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == name) { + if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == name) ImGui.SetScrollHereY(0.5f); - } } ImGui.Separator(); - foreach (var family in JpFonts) { - if (ImGui.Selectable(family, Mutable.JapaneseFont == family)) { + foreach (var family in JpFonts) + { + if (ImGui.Selectable(family, Mutable.JapaneseFont == family)) Mutable.JapaneseFont = family; - } - if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == family) { + if (ImGui.IsWindowAppearing() && Mutable.JapaneseFont == family) ImGui.SetScrollHereY(0.5f); - } } ImGui.EndCombo(); @@ -91,13 +93,13 @@ public class Fonts : ISettingsTab { ImGuiUtil.HelpText(string.Format(Language.Options_JapaneseFont_Description, Plugin.PluginName)); ImGui.Spacing(); - if (ImGui.CollapsingHeader(Language.Options_ExtraGlyphs_Name)) { + if (ImGui.CollapsingHeader(Language.Options_ExtraGlyphs_Name)) + { ImGuiUtil.HelpText(string.Format(Language.Options_ExtraGlyphs_Description, Plugin.PluginName)); var range = (int) Mutable.ExtraGlyphRanges; - foreach (var extra in Enum.GetValues()) { + foreach (var extra in Enum.GetValues()) ImGui.CheckboxFlags(extra.Name(), ref range, (int) extra); - } Mutable.ExtraGlyphRanges = (ExtraGlyphRanges) range; } diff --git a/ChatTwo/Ui/SettingsTabs/ISettingsTab.cs b/ChatTwo/Ui/SettingsTabs/ISettingsTab.cs index fc16039..16befd2 100755 --- a/ChatTwo/Ui/SettingsTabs/ISettingsTab.cs +++ b/ChatTwo/Ui/SettingsTabs/ISettingsTab.cs @@ -1,6 +1,7 @@ namespace ChatTwo.Ui.SettingsTabs; -internal interface ISettingsTab { +internal interface ISettingsTab +{ string Name { get; } void Draw(bool changed); } diff --git a/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs b/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs index 2bc2e2d..848339b 100755 --- a/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs +++ b/ChatTwo/Ui/SettingsTabs/Miscellaneous.cs @@ -4,22 +4,18 @@ using ImGuiNET; namespace ChatTwo.Ui.SettingsTabs; -internal sealed class Miscellaneous : ISettingsTab { - private Configuration Mutable { get; } - +internal sealed class Miscellaneous(Configuration mutable) : ISettingsTab +{ + private Configuration Mutable { get; } = mutable; public string Name => Language.Options_Miscellaneous_Tab + "###tabs-miscellaneous"; - public Miscellaneous(Configuration mutable) { - Mutable = mutable; - } - - public void Draw(bool changed) { - if (ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, Mutable.LanguageOverride.Name())) { - foreach (var language in Enum.GetValues()) { - if (ImGui.Selectable(language.Name())) { + public void Draw(bool changed) + { + if (ImGuiUtil.BeginComboVertical(Language.Options_Language_Name, Mutable.LanguageOverride.Name())) + { + foreach (var language in Enum.GetValues()) + if (ImGui.Selectable(language.Name())) Mutable.LanguageOverride = language; - } - } ImGui.EndCombo(); } @@ -27,12 +23,11 @@ internal sealed class Miscellaneous : ISettingsTab { ImGuiUtil.HelpText(string.Format(Language.Options_Language_Description, Plugin.PluginName)); ImGui.Spacing(); - if (ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name())) { - foreach (var side in Enum.GetValues()) { - if (ImGui.Selectable(side.Name(), Mutable.CommandHelpSide == side)) { + if (ImGuiUtil.BeginComboVertical(Language.Options_CommandHelpSide_Name, Mutable.CommandHelpSide.Name())) + { + foreach (var side in Enum.GetValues()) + if (ImGui.Selectable(side.Name(), Mutable.CommandHelpSide == side)) Mutable.CommandHelpSide = side; - } - } ImGui.EndCombo(); } @@ -40,17 +35,15 @@ internal sealed class Miscellaneous : ISettingsTab { ImGuiUtil.HelpText(string.Format(Language.Options_CommandHelpSide_Description, Plugin.PluginName)); ImGui.Spacing(); - if (ImGuiUtil.BeginComboVertical(Language.Options_KeybindMode_Name, Mutable.KeybindMode.Name())) { - foreach (var mode in Enum.GetValues()) { - if (ImGui.Selectable(mode.Name(), Mutable.KeybindMode == mode)) { + if (ImGuiUtil.BeginComboVertical(Language.Options_KeybindMode_Name, Mutable.KeybindMode.Name())) + { + foreach (var mode in Enum.GetValues()) + { + if (ImGui.Selectable(mode.Name(), Mutable.KeybindMode == mode)) Mutable.KeybindMode = mode; - } - if (ImGui.IsItemHovered()) { - ImGui.BeginTooltip(); - ImGui.TextUnformatted(mode.Tooltip()); - ImGui.EndTooltip(); - } + if (ImGui.IsItemHovered()) + ImGui.SetTooltip(mode.Tooltip()); } ImGui.EndCombo(); @@ -61,7 +54,6 @@ internal sealed class Miscellaneous : ISettingsTab { ImGui.Checkbox(Language.Options_SortAutoTranslate_Name, ref Mutable.SortAutoTranslate); ImGuiUtil.HelpText(Language.Options_SortAutoTranslate_Description); - ImGui.Spacing(); } } diff --git a/ChatTwo/Ui/SettingsTabs/Tabs.cs b/ChatTwo/Ui/SettingsTabs/Tabs.cs index 6c238a7..32406b2 100755 --- a/ChatTwo/Ui/SettingsTabs/Tabs.cs +++ b/ChatTwo/Ui/SettingsTabs/Tabs.cs @@ -2,11 +2,13 @@ using ChatTwo.Code; using ChatTwo.Resources; using ChatTwo.Util; using Dalamud.Interface; +using Dalamud.Interface.Utility.Raii; using ImGuiNET; namespace ChatTwo.Ui.SettingsTabs; -internal sealed class Tabs : ISettingsTab { +internal sealed class Tabs : ISettingsTab +{ private Plugin Plugin { get; } private Configuration Mutable { get; } @@ -14,193 +16,191 @@ internal sealed class Tabs : ISettingsTab { private int _toOpen = -2; - internal Tabs(Plugin plugin, Configuration mutable) { + internal Tabs(Plugin plugin, Configuration mutable) + { Plugin = plugin; Mutable = mutable; } - public void Draw(bool changed) { + public void Draw(bool changed) + { const string addTabPopup = "add-tab-popup"; - if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: Language.Options_Tabs_Add)) { + if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: Language.Options_Tabs_Add)) ImGui.OpenPopup(addTabPopup); - } - if (ImGui.BeginPopup(addTabPopup)) { - if (ImGui.Selectable(Language.Options_Tabs_NewTab)) { - Mutable.Tabs.Add(new Tab()); + using (var popup = ImRaii.Popup(addTabPopup)) + { + if (popup) + { + if (ImGui.Selectable(Language.Options_Tabs_NewTab)) + Mutable.Tabs.Add(new Tab()); + + ImGui.Separator(); + + if (ImGui.Selectable(string.Format(Language.Options_Tabs_Preset, Language.Tabs_Presets_General))) + Mutable.Tabs.Add(TabsUtil.VanillaGeneral); + + if (ImGui.Selectable(string.Format(Language.Options_Tabs_Preset, Language.Tabs_Presets_Event))) + Mutable.Tabs.Add(TabsUtil.VanillaEvent); } - - ImGui.Separator(); - - if (ImGui.Selectable(string.Format(Language.Options_Tabs_Preset, Language.Tabs_Presets_General))) { - Mutable.Tabs.Add(TabsUtil.VanillaGeneral); - } - - if (ImGui.Selectable(string.Format(Language.Options_Tabs_Preset, Language.Tabs_Presets_Event))) { - Mutable.Tabs.Add(TabsUtil.VanillaEvent); - } - - ImGui.EndPopup(); } var toRemove = -1; var doOpens = _toOpen > -2; - for (var i = 0; i < Mutable.Tabs.Count; i++) { + for (var i = 0; i < Mutable.Tabs.Count; i++) + { var tab = Mutable.Tabs[i]; - if (doOpens) { + if (doOpens) ImGui.SetNextItemOpen(i == _toOpen); + + using var treeNode = ImRaii.TreeNode($"{tab.Name}###tab-{i}"); + if (!treeNode.Success) + continue; + + using var pushedId = ImRaii.PushId($"tab-{i}"); + + if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: Language.Options_Tabs_Delete)) + { + toRemove = i; + _toOpen = -1; } - if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) { - ImGui.PushID($"tab-{i}"); + ImGui.SameLine(); - if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: Language.Options_Tabs_Delete)) { - toRemove = i; - _toOpen = -1; + if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: Language.Options_Tabs_MoveUp) && i > 0) + { + (Mutable.Tabs[i - 1], Mutable.Tabs[i]) = (Mutable.Tabs[i], Mutable.Tabs[i - 1]); + _toOpen = i - 1; + } + + ImGui.SameLine(); + + if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: Language.Options_Tabs_MoveDown) && i < Mutable.Tabs.Count - 1) + { + (Mutable.Tabs[i + 1], Mutable.Tabs[i]) = (Mutable.Tabs[i], Mutable.Tabs[i + 1]); + _toOpen = i + 1; + } + + ImGui.InputText(Language.Options_Tabs_Name, ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue); + ImGui.Checkbox(Language.Options_Tabs_ShowTimestamps, ref tab.DisplayTimestamp); + ImGui.Checkbox(Language.Options_Tabs_PopOut, ref tab.PopOut); + if (tab.PopOut) + { + ImGui.Checkbox(Language.Options_Tabs_IndependentOpacity, ref tab.IndependentOpacity); + if (tab.IndependentOpacity) + ImGuiUtil.DragFloatVertical(Language.Options_Tabs_Opacity, ref tab.Opacity, 0.25f, 0f, 100f, $"{tab.Opacity:N2}%%", ImGuiSliderFlags.AlwaysClamp); + } + + if (ImGuiUtil.BeginComboVertical(Language.Options_Tabs_UnreadMode, tab.UnreadMode.Name())) + { + foreach (var mode in Enum.GetValues()) + { + if (ImGui.Selectable(mode.Name(), tab.UnreadMode == mode)) + tab.UnreadMode = mode; + + if (mode.Tooltip() is { } tooltip && ImGui.IsItemHovered()) + ImGui.SetTooltip(tooltip); } - ImGui.SameLine(); + ImGui.EndCombo(); + } - if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: Language.Options_Tabs_MoveUp) && i > 0) { - (Mutable.Tabs[i - 1], Mutable.Tabs[i]) = (Mutable.Tabs[i], Mutable.Tabs[i - 1]); - _toOpen = i - 1; - } + var input = tab.Channel?.ToChatType().Name() ?? Language.Options_Tabs_NoInputChannel; + if (ImGuiUtil.BeginComboVertical(Language.Options_Tabs_InputChannel, input)) + { + if (ImGui.Selectable(Language.Options_Tabs_NoInputChannel, tab.Channel == null)) + tab.Channel = null; - ImGui.SameLine(); + foreach (var channel in Enum.GetValues()) + if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) + tab.Channel = channel; - if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: Language.Options_Tabs_MoveDown) && i < Mutable.Tabs.Count - 1) { - (Mutable.Tabs[i + 1], Mutable.Tabs[i]) = (Mutable.Tabs[i], Mutable.Tabs[i + 1]); - _toOpen = i + 1; - } + ImGui.EndCombo(); + } - ImGui.InputText(Language.Options_Tabs_Name, ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue); - ImGui.Checkbox(Language.Options_Tabs_ShowTimestamps, ref tab.DisplayTimestamp); - ImGui.Checkbox(Language.Options_Tabs_PopOut, ref tab.PopOut); - if (tab.PopOut) { - ImGui.Checkbox(Language.Options_Tabs_IndependentOpacity, ref tab.IndependentOpacity); - if (tab.IndependentOpacity) { - ImGuiUtil.DragFloatVertical(Language.Options_Tabs_Opacity, ref tab.Opacity, 0.25f, 0f, 100f, $"{tab.Opacity:N2}%%", ImGuiSliderFlags.AlwaysClamp); - } - } + using (var channelNode = ImRaii.TreeNode(Language.Options_Tabs_Channels)) + { + if (channelNode) + { + foreach (var (header, types) in ChatTypeExt.SortOrder) + { + using var headerNode = ImRaii.TreeNode(header + $"##{i}"); + if (!headerNode.Success) + continue; - if (ImGuiUtil.BeginComboVertical(Language.Options_Tabs_UnreadMode, tab.UnreadMode.Name())) { - foreach (var mode in Enum.GetValues()) { - if (ImGui.Selectable(mode.Name(), tab.UnreadMode == mode)) { - tab.UnreadMode = mode; - } + foreach (var type in types) + { + if (type.IsGm()) + continue; - if (mode.Tooltip() is { } tooltip && ImGui.IsItemHovered()) { - ImGui.BeginTooltip(); - ImGui.TextUnformatted(tooltip); - ImGui.EndTooltip(); - } - } - - ImGui.EndCombo(); - } - - var input = tab.Channel?.ToChatType().Name() ?? Language.Options_Tabs_NoInputChannel; - if (ImGuiUtil.BeginComboVertical(Language.Options_Tabs_InputChannel, input)) { - if (ImGui.Selectable(Language.Options_Tabs_NoInputChannel, tab.Channel == null)) { - tab.Channel = null; - } - - foreach (var channel in Enum.GetValues()) { - if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) { - tab.Channel = channel; - } - } - - ImGui.EndCombo(); - } - - if (ImGui.TreeNodeEx(Language.Options_Tabs_Channels)) { - foreach (var (header, types) in ChatTypeExt.SortOrder) { - if (ImGui.TreeNodeEx(header + $"##{i}")) { - foreach (var type in types) { - if (type.IsGm()) { - continue; - } - - var enabled = tab.ChatCodes.ContainsKey(type); - if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled)) { - if (enabled) { - tab.ChatCodes[type] = ChatSourceExt.All; - } else { - tab.ChatCodes.Remove(type); - } - } - - ImGui.SameLine(); - - if (type.HasSource()) { - if (ImGui.TreeNodeEx($"{type.Name()}##{i}")) { - tab.ChatCodes.TryGetValue(type, out var sourcesEnum); - var sources = (uint) sourcesEnum; - - foreach (var source in Enum.GetValues()) { - if (ImGui.CheckboxFlags(source.Name(), ref sources, (uint) source)) { - tab.ChatCodes[type] = (ChatSource) sources; - } - } - - ImGui.TreePop(); - } - } else { - ImGui.TextUnformatted(type.Name()); - } + var enabled = tab.ChatCodes.ContainsKey(type); + if (ImGui.Checkbox($"##{type.Name()}-{i}", ref enabled)) + { + if (enabled) + tab.ChatCodes[type] = ChatSourceExt.All; + else + tab.ChatCodes.Remove(type); } - ImGui.TreePop(); + ImGui.SameLine(); + + if (!type.HasSource()) + { + ImGui.TextUnformatted(type.Name()); + continue; + } + + using var typeNode = ImRaii.TreeNode($"{type.Name()}##{i}"); + if (!typeNode.Success) + continue; + + tab.ChatCodes.TryGetValue(type, out var sourcesEnum); + var sources = (uint) sourcesEnum; + + foreach (var source in Enum.GetValues()) + if (ImGui.CheckboxFlags(source.Name(), ref sources, (uint) source)) + tab.ChatCodes[type] = (ChatSource) sources; } } - - ImGui.TreePop(); } - - if (Plugin.ExtraChat.ChannelNames.Count > 0 && ImGui.TreeNodeEx(Language.Options_Tabs_ExtraChatChannels)) { - ImGui.Checkbox(Language.Options_Tabs_ExtraChatAll, ref tab.ExtraChatAll); - - ImGui.Separator(); - - if (tab.ExtraChatAll) { - ImGui.BeginDisabled(); - } - - foreach (var (id, name) in Plugin.ExtraChat.ChannelNames) { - var enabled = tab.ExtraChatChannels.Contains(id); - if (!ImGui.Checkbox($"{name}##ec-{id}", ref enabled)) { - continue; - } - - if (enabled) { - tab.ExtraChatChannels.Add(id); - } else { - tab.ExtraChatChannels.Remove(id); - } - } - - if (tab.ExtraChatAll) { - ImGui.EndDisabled(); - } - - ImGui.TreePop(); - } - - ImGui.TreePop(); - - ImGui.PopID(); } + + + if (Plugin.ExtraChat.ChannelNames.Count <= 0) + continue; + + using var extraTree = ImRaii.TreeNode(Language.Options_Tabs_ExtraChatChannels); + if (!extraTree.Success) + continue; + + ImGui.Checkbox(Language.Options_Tabs_ExtraChatAll, ref tab.ExtraChatAll); + ImGui.Separator(); + + if (tab.ExtraChatAll) + ImGui.BeginDisabled(); + + foreach (var (id, name) in Plugin.ExtraChat.ChannelNames) + { + var enabled = tab.ExtraChatChannels.Contains(id); + if (!ImGui.Checkbox($"{name}##ec-{id}", ref enabled)) + continue; + + if (enabled) + tab.ExtraChatChannels.Add(id); + else + tab.ExtraChatChannels.Remove(id); + } + + if (tab.ExtraChatAll) + ImGui.EndDisabled(); } - if (toRemove > -1) { + if (toRemove > -1) Mutable.Tabs.RemoveAt(toRemove); - } - if (doOpens) { + if (doOpens) _toOpen = -2; - } } } diff --git a/ChatTwo/Ui/UiComponent.cs b/ChatTwo/Ui/UiComponent.cs deleted file mode 100755 index d779f88..0000000 --- a/ChatTwo/Ui/UiComponent.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace ChatTwo.Ui; - -internal interface IUiComponent : IDisposable { - void Draw(); -}