diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 9439fc1..63caf5a 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -40,7 +40,7 @@ internal class Tab { return this.ChatCodes.TryGetValue(message.Code.Type, out var sources) && (message.Code.Source is 0 or (ChatSource) 1 || sources.HasFlag(message.Code.Source)); } - internal void AddMessage(Message message) { + internal void AddMessage(Message message, bool unread = true) { this.MessagesMutex.WaitOne(); this.Messages.Add(message); if (this.Messages.Count > 1000) { @@ -49,7 +49,9 @@ internal class Tab { this.MessagesMutex.ReleaseMutex(); - this.Unread += 1; + if (unread) { + this.Unread += 1; + } } internal Tab Clone() { diff --git a/ChatTwo/Store.cs b/ChatTwo/Store.cs index e63ba29..6938d88 100755 --- a/ChatTwo/Store.cs +++ b/ChatTwo/Store.cs @@ -75,17 +75,17 @@ internal class Store : IDisposable { } } - internal void FilterAllTabs() { + internal void FilterAllTabs(bool unread = true) { foreach (var tab in this.Plugin.Config.Tabs) { - this.FilterTab(tab); + this.FilterTab(tab, unread); } } - internal void FilterTab(Tab tab) { + internal void FilterTab(Tab tab, bool unread) { using var messages = this.GetMessages(); foreach (var message in messages.Messages) { if (tab.Matches(message)) { - tab.AddMessage(message); + tab.AddMessage(message, unread); } } } diff --git a/ChatTwo/Ui/Settings.cs b/ChatTwo/Ui/Settings.cs index 7874aa0..fd584c2 100755 --- a/ChatTwo/Ui/Settings.cs +++ b/ChatTwo/Ui/Settings.cs @@ -2,6 +2,7 @@ using ChatTwo.Code; using ChatTwo.Util; using Dalamud.Game.Command; +using Dalamud.Interface; using ImGuiNET; namespace ChatTwo.Ui; @@ -86,16 +87,33 @@ internal sealed class Settings : IUiComponent { } if (ImGui.TreeNodeEx("Tabs")) { - if (ImGui.Button("Add")) { + if (ImGuiUtil.IconButton(FontAwesomeIcon.Plus, tooltip: "Add")) { this._tabs.Add(new Tab()); } + var toRemove = -1; for (var i = 0; i < this._tabs.Count; i++) { var tab = this._tabs[i]; if (ImGui.TreeNodeEx($"{tab.Name}###tab-{i}")) { ImGui.PushID($"tab-{i}"); + if (ImGuiUtil.IconButton(FontAwesomeIcon.TrashAlt, tooltip: "Delete")) { + toRemove = i; + } + + ImGui.SameLine(); + + if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowUp, tooltip: "Move up") && i > 0) { + (this._tabs[i - 1], this._tabs[i]) = (this._tabs[i], this._tabs[i - 1]); + } + + ImGui.SameLine(); + + if (ImGuiUtil.IconButton(FontAwesomeIcon.ArrowDown, tooltip: "Move down") && i < this._tabs.Count - 1) { + (this._tabs[i + 1], this._tabs[i]) = (this._tabs[i], this._tabs[i + 1]); + } + ImGui.InputText("Name", ref tab.Name, 512, ImGuiInputTextFlags.EnterReturnsTrue); ImGui.Checkbox("Show unread count", ref tab.DisplayUnread); ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp); @@ -107,7 +125,7 @@ internal sealed class Settings : IUiComponent { } foreach (var channel in Enum.GetValues()) { - if (ImGui.Selectable(channel.ToChatType().Name() ?? "???", tab.Channel == channel)) { + if (ImGui.Selectable(channel.ToChatType().Name(), tab.Channel == channel)) { tab.Channel = channel; } } @@ -151,6 +169,10 @@ internal sealed class Settings : IUiComponent { ImGui.PopID(); } } + + if (toRemove > -1) { + this._tabs.RemoveAt(toRemove); + } } ImGui.EndChild(); @@ -190,7 +212,7 @@ internal sealed class Settings : IUiComponent { this.Ui.Plugin.SaveConfig(); - this.Ui.Plugin.Store.FilterAllTabs(); + this.Ui.Plugin.Store.FilterAllTabs(false); if (fontSizeChanged) { this.Ui.Plugin.Interface.UiBuilder.RebuildFonts(); diff --git a/ChatTwo/Util/ImGuiUtil.cs b/ChatTwo/Util/ImGuiUtil.cs index 6619847..c5a618c 100755 --- a/ChatTwo/Util/ImGuiUtil.cs +++ b/ChatTwo/Util/ImGuiUtil.cs @@ -81,7 +81,7 @@ internal static class ImGuiUtil { } } - internal static bool IconButton(FontAwesomeIcon icon, string? id = null) { + internal static bool IconButton(FontAwesomeIcon icon, string? id = null, string? tooltip = null) { ImGui.PushFont(UiBuilder.IconFont); var label = icon.ToIconString(); @@ -93,6 +93,12 @@ internal static class ImGuiUtil { ImGui.PopFont(); + if (tooltip != null && ImGui.IsItemHovered()) { + ImGui.BeginTooltip(); + ImGui.TextUnformatted(tooltip); + ImGui.EndTooltip(); + } + return ret; } }