feat: add tab pop-out

This commit is contained in:
Anna 2022-02-18 13:35:46 -05:00
parent fed6b9c5a6
commit 04783fcf02
4 changed files with 57 additions and 2 deletions

View File

@ -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,
};
}
}

View File

@ -123,6 +123,15 @@ namespace ChatTwo.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Pop out.
/// </summary>
internal static string ChatLog_Tabs_PopOut {
get {
return ResourceManager.GetString("ChatLog_Tabs_PopOut", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Alliance Member.
/// </summary>

View File

@ -473,4 +473,7 @@
<data name="Options_SharedMode_Warning" xml:space="preserve">
<value>This option is not recommended. No support will be offered if you enable this option. This option will hurt the performance of {0}.</value>
</data>
<data name="ChatLog_Tabs_PopOut" xml:space="preserve">
<value>Pop out</value>
</data>
</root>

View File

@ -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();
}
/// <returns>true if window was rendered</returns>
@ -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);