feat: add input channels

This commit is contained in:
Anna
2022-01-06 15:57:24 -05:00
parent a6bda4dd63
commit 663ce5dbbd
4 changed files with 69 additions and 2 deletions
+29
View File
@@ -49,4 +49,33 @@ internal static class InputChannelExt {
InputChannel.CrossLinkshell8 => 7, InputChannel.CrossLinkshell8 => 7,
_ => uint.MaxValue, _ => 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",
_ => "",
};
} }
+2
View File
@@ -20,6 +20,7 @@ internal class Tab {
public Dictionary<ChatType, ChatSource> ChatCodes = new(); public Dictionary<ChatType, ChatSource> ChatCodes = new();
public bool DisplayUnread = true; public bool DisplayUnread = true;
public bool DisplayTimestamp = true; public bool DisplayTimestamp = true;
public InputChannel? Channel;
[NonSerialized] [NonSerialized]
public uint Unread; public uint Unread;
@@ -56,6 +57,7 @@ internal class Tab {
ChatCodes = this.ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value), ChatCodes = this.ChatCodes.ToDictionary(entry => entry.Key, entry => entry.Value),
DisplayUnread = this.DisplayUnread, DisplayUnread = this.DisplayUnread,
DisplayTimestamp = this.DisplayTimestamp, DisplayTimestamp = this.DisplayTimestamp,
Channel = this.Channel,
}; };
} }
} }
+22 -1
View File
@@ -64,12 +64,14 @@ internal sealed class ChatLog : IUiComponent {
var lineHeight = ImGui.CalcTextSize("A").Y; var lineHeight = ImGui.CalcTextSize("A").Y;
var currentTab = -1;
if (ImGui.BeginTabBar("##chat2-tabs")) { if (ImGui.BeginTabBar("##chat2-tabs")) {
for (var tabI = 0; tabI < this.Ui.Plugin.Config.Tabs.Count; tabI++) { for (var tabI = 0; tabI < this.Ui.Plugin.Config.Tabs.Count; tabI++) {
var tab = this.Ui.Plugin.Config.Tabs[tabI]; var tab = this.Ui.Plugin.Config.Tabs[tabI];
var unread = tabI == this._lastTab || !tab.DisplayUnread || tab.Unread == 0 ? "" : $" ({tab.Unread})"; var unread = tabI == this._lastTab || !tab.DisplayUnread || tab.Unread == 0 ? "" : $" ({tab.Unread})";
if (ImGui.BeginTabItem($"{tab.Name}{unread}###log-tab-{tabI}")) { if (ImGui.BeginTabItem($"{tab.Name}{unread}###log-tab-{tabI}")) {
currentTab = tabI;
var switchedTab = this._lastTab != tabI; var switchedTab = this._lastTab != tabI;
this._lastTab = tabI; this._lastTab = tabI;
tab.Unread = 0; tab.Unread = 0;
@@ -147,19 +149,34 @@ internal sealed class ChatLog : IUiComponent {
ImGui.SetKeyboardFocusHere(); ImGui.SetKeyboardFocusHere();
} }
Tab? activeTab = null;
if (currentTab > -1) {
activeTab = this.Ui.Plugin.Config.Tabs[currentTab];
}
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, Vector2.Zero);
try { try {
if (activeTab is { Channel: { } channel }) {
ImGui.TextUnformatted(channel.ToChatType().Name());
} else {
this.DrawChunks(this.Ui.Plugin.Functions.ChatChannel.name); this.DrawChunks(this.Ui.Plugin.Functions.ChatChannel.name);
}
} finally { } finally {
ImGui.PopStyleVar(); ImGui.PopStyleVar();
} }
var beforeIcon = ImGui.GetCursorPos(); var beforeIcon = ImGui.GetCursorPos();
if (ImGuiUtil.IconButton(FontAwesomeIcon.Comment)) { if (ImGuiUtil.IconButton(FontAwesomeIcon.Comment) && activeTab is not { Channel: { } }) {
ImGui.OpenPopup(ChatChannelPicker); ImGui.OpenPopup(ChatChannelPicker);
} }
if (activeTab is { Channel: { } } && ImGui.IsItemHovered()) {
ImGui.BeginTooltip();
ImGui.TextUnformatted("Disabled for this tab.");
ImGui.EndTooltip();
}
if (ImGui.BeginPopup(ChatChannelPicker)) { if (ImGui.BeginPopup(ChatChannelPicker)) {
foreach (var channel in Enum.GetValues<InputChannel>()) { foreach (var channel in Enum.GetValues<InputChannel>()) {
var name = this.Ui.Plugin.DataManager.GetExcelSheet<LogFilter>()! var name = this.Ui.Plugin.DataManager.GetExcelSheet<LogFilter>()!
@@ -200,6 +217,10 @@ internal sealed class ChatLog : IUiComponent {
this.AddBacklog(trimmed); this.AddBacklog(trimmed);
this._inputBacklogIdx = -1; this._inputBacklogIdx = -1;
if (activeTab is { Channel: { } channel } && !trimmed.StartsWith('/')) {
trimmed = $"{channel.Prefix()} {trimmed}";
}
this.Ui.Plugin.Common.Functions.Chat.SendMessage(trimmed); this.Ui.Plugin.Common.Functions.Chat.SendMessage(trimmed);
} }
+15
View File
@@ -97,6 +97,21 @@ internal sealed class Settings : IUiComponent {
ImGui.Checkbox("Show unread count", ref tab.DisplayUnread); ImGui.Checkbox("Show unread count", ref tab.DisplayUnread);
ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp); ImGui.Checkbox("Show timestamps", ref tab.DisplayTimestamp);
var input = tab.Channel?.ToChatType().Name() ?? "<None>";
if (ImGui.BeginCombo("Input channel", input)) {
if (ImGui.Selectable("<None>", tab.Channel == null)) {
tab.Channel = null;
}
foreach (var channel in Enum.GetValues<InputChannel>()) {
if (ImGui.Selectable(channel.ToChatType().Name() ?? "???", tab.Channel == channel)) {
tab.Channel = channel;
}
}
ImGui.EndCombo();
}
if (ImGui.TreeNodeEx("Channels")) { if (ImGui.TreeNodeEx("Channels")) {
foreach (var type in Enum.GetValues<ChatType>()) { foreach (var type in Enum.GetValues<ChatType>()) {
var enabled = tab.ChatCodes.ContainsKey(type); var enabled = tab.ChatCodes.ContainsKey(type);