From 663ce5dbbdbefa190edcd471213f34d4a256f3ed Mon Sep 17 00:00:00 2001 From: Anna Date: Thu, 6 Jan 2022 15:57:24 -0500 Subject: [PATCH] feat: add input channels --- ChatTwo/Code/InputChannelExt.cs | 29 +++++++++++++++++++++++++++++ ChatTwo/Configuration.cs | 2 ++ ChatTwo/Ui/ChatLog.cs | 25 +++++++++++++++++++++++-- ChatTwo/Ui/Settings.cs | 15 +++++++++++++++ 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/ChatTwo/Code/InputChannelExt.cs b/ChatTwo/Code/InputChannelExt.cs index afdcaba..b379efd 100755 --- a/ChatTwo/Code/InputChannelExt.cs +++ b/ChatTwo/Code/InputChannelExt.cs @@ -49,4 +49,33 @@ internal static class InputChannelExt { InputChannel.CrossLinkshell8 => 7, _ => uint.MaxValue, }; + + public static string Prefix(this InputChannel channel) => channel switch { + InputChannel.Tell => "/tell", + InputChannel.Say => "/say", + InputChannel.Party => "/party", + InputChannel.Alliance => "/alliance", + InputChannel.Yell => "/yell", + InputChannel.Shout => "/shout", + InputChannel.FreeCompany => "/freecompany", + InputChannel.PvpTeam => "/pvpteam", + InputChannel.NoviceNetwork => "/novice", + InputChannel.CrossLinkshell1 => "/cwlinkshell1", + InputChannel.CrossLinkshell2 => "/cwlinkshell2", + InputChannel.CrossLinkshell3 => "/cwlinkshell3", + InputChannel.CrossLinkshell4 => "/cwlinkshell4", + InputChannel.CrossLinkshell5 => "/cwlinkshell5", + InputChannel.CrossLinkshell6 => "/cwlinkshell6", + InputChannel.CrossLinkshell7 => "/cwlinkshell7", + InputChannel.CrossLinkshell8 => "/cwlinkshell8", + InputChannel.Linkshell1 => "/linkshell1", + InputChannel.Linkshell2 => "/linkshell2", + InputChannel.Linkshell3 => "/linkshell3", + InputChannel.Linkshell4 => "/linkshell4", + InputChannel.Linkshell5 => "/linkshell5", + InputChannel.Linkshell6 => "/linkshell6", + InputChannel.Linkshell7 => "/linkshell7", + InputChannel.Linkshell8 => "/linkshell8", + _ => "", + }; } diff --git a/ChatTwo/Configuration.cs b/ChatTwo/Configuration.cs index 375bc5b..b3c7179 100755 --- a/ChatTwo/Configuration.cs +++ b/ChatTwo/Configuration.cs @@ -20,6 +20,7 @@ internal class Tab { public Dictionary ChatCodes = new(); public bool DisplayUnread = true; public bool DisplayTimestamp = true; + public InputChannel? Channel; [NonSerialized] public uint Unread; @@ -56,6 +57,7 @@ internal class Tab { ChatCodes = this.ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value), DisplayUnread = this.DisplayUnread, DisplayTimestamp = this.DisplayTimestamp, + Channel = this.Channel, }; } } diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index 8b03a69..bccea77 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -64,12 +64,14 @@ internal sealed class ChatLog : IUiComponent { var lineHeight = ImGui.CalcTextSize("A").Y; + var currentTab = -1; if (ImGui.BeginTabBar("##chat2-tabs")) { for (var tabI = 0; tabI < this.Ui.Plugin.Config.Tabs.Count; tabI++) { var tab = this.Ui.Plugin.Config.Tabs[tabI]; var unread = tabI == this._lastTab || !tab.DisplayUnread || tab.Unread == 0 ? "" : $" ({tab.Unread})"; if (ImGui.BeginTabItem($"{tab.Name}{unread}###log-tab-{tabI}")) { + currentTab = tabI; var switchedTab = this._lastTab != tabI; this._lastTab = tabI; tab.Unread = 0; @@ -147,19 +149,34 @@ internal sealed class ChatLog : IUiComponent { ImGui.SetKeyboardFocusHere(); } + Tab? activeTab = null; + if (currentTab > -1) { + activeTab = this.Ui.Plugin.Config.Tabs[currentTab]; + } + ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero); try { - this.DrawChunks(this.Ui.Plugin.Functions.ChatChannel.name); + if (activeTab is { Channel: { } channel }) { + ImGui.TextUnformatted(channel.ToChatType().Name()); + } else { + this.DrawChunks(this.Ui.Plugin.Functions.ChatChannel.name); + } } finally { ImGui.PopStyleVar(); } var beforeIcon = ImGui.GetCursorPos(); - if (ImGuiUtil.IconButton(FontAwesomeIcon.Comment)) { + if (ImGuiUtil.IconButton(FontAwesomeIcon.Comment) && activeTab is not { Channel: { } }) { ImGui.OpenPopup(ChatChannelPicker); } + if (activeTab is { Channel: { } } && ImGui.IsItemHovered()) { + ImGui.BeginTooltip(); + ImGui.TextUnformatted("Disabled for this tab."); + ImGui.EndTooltip(); + } + if (ImGui.BeginPopup(ChatChannelPicker)) { foreach (var channel in Enum.GetValues()) { var name = this.Ui.Plugin.DataManager.GetExcelSheet()! @@ -200,6 +217,10 @@ internal sealed class ChatLog : IUiComponent { this.AddBacklog(trimmed); this._inputBacklogIdx = -1; + if (activeTab is { Channel: { } channel } && !trimmed.StartsWith('/')) { + trimmed = $"{channel.Prefix()} {trimmed}"; + } + this.Ui.Plugin.Common.Functions.Chat.SendMessage(trimmed); } diff --git a/ChatTwo/Ui/Settings.cs b/ChatTwo/Ui/Settings.cs index 103edba..c52bf09 100755 --- a/ChatTwo/Ui/Settings.cs +++ b/ChatTwo/Ui/Settings.cs @@ -97,6 +97,21 @@ internal sealed class Settings : IUiComponent { ImGui.Checkbox("Show unread count", ref tab.DisplayUnread); ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp); + var input = tab.Channel?.ToChatType().Name() ?? ""; + if (ImGui.BeginCombo("Input channel", input)) { + if (ImGui.Selectable("", 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("Channels")) { foreach (var type in Enum.GetValues()) { var enabled = tab.ChatCodes.ContainsKey(type);