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

View File

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

View File

@ -20,6 +20,7 @@ internal class Tab {
public Dictionary<ChatType, ChatSource> 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,
};
}
}

View File

@ -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<InputChannel>()) {
var name = this.Ui.Plugin.DataManager.GetExcelSheet<LogFilter>()!
@ -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);
}

View File

@ -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() ?? "<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")) {
foreach (var type in Enum.GetValues<ChatType>()) {
var enabled = tab.ChatCodes.ContainsKey(type);