From a42f05ee557798e22abd734fdeaee3174423f02f Mon Sep 17 00:00:00 2001 From: Anna Clemens Date: Sun, 16 Jan 2022 00:03:32 -0500 Subject: [PATCH] feat: show colour for leading text command --- ChatTwo/Code/InputChannelExt.cs | 50 ++++++++++++++++++++++++++++++++- ChatTwo/Ui/ChatLog.cs | 15 ++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/ChatTwo/Code/InputChannelExt.cs b/ChatTwo/Code/InputChannelExt.cs index b379efd..0a3161d 100755 --- a/ChatTwo/Code/InputChannelExt.cs +++ b/ChatTwo/Code/InputChannelExt.cs @@ -1,4 +1,7 @@ -namespace ChatTwo.Code; +using Dalamud.Data; +using Lumina.Excel.GeneratedSheets; + +namespace ChatTwo.Code; internal static class InputChannelExt { internal static ChatType ToChatType(this InputChannel input) => input switch { @@ -78,4 +81,49 @@ internal static class InputChannelExt { InputChannel.Linkshell8 => "/linkshell8", _ => "", }; + + public static IEnumerable? TextCommands(this InputChannel channel, DataManager data) { + var ids = channel switch { + InputChannel.Tell => new uint[] { 104, 118 }, + InputChannel.Say => new uint[] { 102 }, + InputChannel.Party => new uint[] { 105 }, + InputChannel.Alliance => new uint[] { 119 }, + InputChannel.Yell => new uint[] { 117 }, + InputChannel.Shout => new uint[] { 103 }, + InputChannel.FreeCompany => new uint[] { 115 }, + InputChannel.PvpTeam => new uint[] { 91 }, + InputChannel.NoviceNetwork => new uint[] { 224 }, + InputChannel.CrossLinkshell1 => new uint[] { 13 }, + InputChannel.CrossLinkshell2 => new uint[] { 14 }, + InputChannel.CrossLinkshell3 => new uint[] { 15 }, + InputChannel.CrossLinkshell4 => new uint[] { 16 }, + InputChannel.CrossLinkshell5 => new uint[] { 17 }, + InputChannel.CrossLinkshell6 => new uint[] { 18 }, + InputChannel.CrossLinkshell7 => new uint[] { 19 }, + InputChannel.CrossLinkshell8 => new uint[] { 20 }, + InputChannel.Linkshell1 => new uint[] { 107 }, + InputChannel.Linkshell2 => new uint[] { 108 }, + InputChannel.Linkshell3 => new uint[] { 109 }, + InputChannel.Linkshell4 => new uint[] { 110 }, + InputChannel.Linkshell5 => new uint[] { 111 }, + InputChannel.Linkshell6 => new uint[] { 112 }, + InputChannel.Linkshell7 => new uint[] { 113 }, + InputChannel.Linkshell8 => new uint[] { 114 }, + _ => Array.Empty(), + }; + + if (ids.Length == 0) { + return null; + } + + var cmds = data.GetExcelSheet(); + if (cmds == null) { + return null; + } + + return ids + .Select(id => cmds.GetRow(id)) + .Where(id => id != null) + .Cast(); + } } diff --git a/ChatTwo/Ui/ChatLog.cs b/ChatTwo/Ui/ChatLog.cs index d07d580..f409c7d 100755 --- a/ChatTwo/Ui/ChatLog.cs +++ b/ChatTwo/Ui/ChatLog.cs @@ -182,6 +182,21 @@ internal sealed class ChatLog : IUiComponent { var inputWidth = ImGui.GetContentRegionAvail().X - buttonWidth; var inputType = activeTab?.Channel?.ToChatType() ?? this.Ui.Plugin.Functions.Chat.Channel.channel.ToChatType(); + if (this.Chat.Trim().StartsWith('/')) { + var command = this.Chat.Split(' ')[0]; + foreach (var input in Enum.GetValues()) { + var anyMatches = input.TextCommands(this.Ui.Plugin.DataManager) + ?.Any(cmd => cmd.Command == command || cmd.ShortCommand == command || cmd.Alias == command || cmd.ShortAlias == command) + ?? false; + if (!anyMatches) { + continue; + } + + inputType = input.ToChatType(); + break; + } + } + var inputColour = this.Ui.Plugin.Config.ChatColours.TryGetValue(inputType, out var inputCol) ? inputCol : inputType.DefaultColour();