From 04783fcf02f6690cacc9b6c614c748b2110902e9 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 18 Feb 2022 13:35:46 -0500 Subject: [PATCH] feat: add tab pop-out --- ChatTwo/Configuration.cs | 2 ++ ChatTwo/Resources/Language.Designer.cs | 9 ++++++ ChatTwo/Resources/Language.resx | 3 ++ ChatTwo/Ui/ChatLog.cs | 45 ++++++++++++++++++++++++-- 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index d0fffb4..00d441b 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -136,6 +136,7 @@ internal class Tab { public UnreadMode UnreadMode = UnreadMode.Unseen; public bool DisplayTimestamp = true; public InputChannel? Channel; + public bool PopOut; [NonSerialized] public uint Unread; @@ -184,6 +185,7 @@ internal class Tab { UnreadMode = this.UnreadMode, DisplayTimestamp = this.DisplayTimestamp, Channel = this.Channel, + PopOut = this.PopOut, }; } } diff --git a/ChatTwo/Resources/Language.Designer.cs b/ChatTwo/Resources/Language.Designer.cs index b8a9b93..04c26aa 100755 --- a/ChatTwo/Resources/Language.Designer.cs +++ b/ChatTwo/Resources/Language.Designer.cs @@ -123,6 +123,15 @@ namespace ChatTwo.Resources { } } + /// + /// Looks up a localized string similar to Pop out. + /// + internal static string ChatLog_Tabs_PopOut { + get { + return ResourceManager.GetString("ChatLog_Tabs_PopOut", resourceCulture); + } + } + /// /// Looks up a localized string similar to Alliance Member. /// diff --git a/ChatTwo/Resources/Language.resx b/ChatTwo/Resources/Language.resx index a909fa4..4a7c25a 100755 --- a/ChatTwo/Resources/Language.resx +++ b/ChatTwo/Resources/Language.resx @@ -473,4 +473,7 @@ This option is not recommended. No support will be offered if you enable this option. This option will hurt the performance of {0}. + + Pop out + diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index 84d32f2..b90c134 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -317,9 +317,12 @@ internal sealed class ChatLog : IUiComponent { private HideState _hideState = HideState.None; public void Draw() { - if (this.DrawChatLog()) { - this._commandHelp?.Draw(); + if (!this.DrawChatLog()) { + return; } + + this._commandHelp?.Draw(); + this.DrawPopOuts(); } /// true if window was rendered @@ -725,6 +728,9 @@ internal sealed class ChatLog : IUiComponent { for (var tabI = 0; tabI < this.Ui.Plugin.Config.Tabs.Count; tabI++) { var tab = this.Ui.Plugin.Config.Tabs[tabI]; + if (tab.PopOut) { + continue; + } var unread = tabI == this.LastTab || tab.UnreadMode == UnreadMode.None || tab.Unread == 0 ? "" : $" ({tab.Unread})"; var draw = ImGui.BeginTabItem($"{tab.Name}{unread}###log-tab-{tabI}"); @@ -766,6 +772,9 @@ internal sealed class ChatLog : IUiComponent { if (ImGui.BeginChild("##chat2-tab-sidebar", new Vector2(-1, childHeight))) { for (var tabI = 0; tabI < this.Ui.Plugin.Config.Tabs.Count; tabI++) { var tab = this.Ui.Plugin.Config.Tabs[tabI]; + if (tab.PopOut) { + continue; + } var unread = tabI == this.LastTab || tab.UnreadMode == UnreadMode.None || tab.Unread == 0 ? "" : $" ({tab.Unread})"; var clicked = ImGui.Selectable($"{tab.Name}{unread}###log-tab-{tabI}", this.LastTab == tabI); @@ -841,6 +850,12 @@ internal sealed class ChatLog : IUiComponent { anyChanged = true; } + ImGui.SameLine(); + if (ImGuiUtil.IconButton(FontAwesomeIcon.WindowRestore, tooltip: Language.ChatLog_Tabs_PopOut)) { + tab.PopOut = true; + anyChanged = true; + } + if (anyChanged) { this.Ui.Plugin.SaveConfig(); } @@ -849,6 +864,32 @@ internal sealed class ChatLog : IUiComponent { ImGui.EndPopup(); } + private void DrawPopOuts() { + foreach (var tab in this.Ui.Plugin.Config.Tabs.Where(tab => tab.PopOut)) { + this.DrawPopOut(tab); + } + } + + private void DrawPopOut(Tab tab) { + ImGui.SetNextWindowSize(new Vector2(350, 350) * ImGuiHelpers.GlobalScale, ImGuiCond.FirstUseEver); + if (!ImGui.Begin($"{tab.Name}##popout", ref tab.PopOut)) { + goto End; + } + + ImGui.PushID($"popout-{tab.Name}"); + + this.DrawMessageLog(tab, ImGui.GetContentRegionAvail().Y, false); + + ImGui.PopID(); + + End: + ImGui.End(); + + if (!tab.PopOut) { + this.Ui.Plugin.SaveConfig(); + } + } + private unsafe int Callback(ImGuiInputTextCallbackData* data) { var ptr = new ImGuiInputTextCallbackDataPtr(data);