fix: hide unused ECLS indices from chat selector menu

Checks each ExtraChat channel from 1-8 to see if a matching `/eclX`
command is registered in Dalamud before showing it in the list.
This commit is contained in:
Dean Sheather
2024-04-11 03:40:31 +10:00
parent 85bf359c0a
commit 87e6573e9b
+22 -11
View File
@@ -559,14 +559,15 @@ public sealed class ChatLogWindow : Window, IUiComponent {
name += $": {lsName}"; name += $": {lsName}";
} }
if (channel.IsExtraChatLinkshell() && Plugin.ExtraChat.ChannelNames.Count == 0) { if (channel.IsExtraChatLinkshell()) {
// Sadly the ExtraChat IPC doesn't provide a method to // Check if the linkshell with this index is registered in
// lookup what channel numbers are assigned, or what the // the ExtraChat plugin by seeing if the command is
// channel names are. // registered. The command gets registered only if a
// // linkshell is assigned (and even gets unassigned if the
// Show all ExtraChat options if the user is in at least // index changes!).
// one channel. if (!Plugin.CommandManager.Commands.ContainsKey(channel.Prefix())) {
continue; continue;
}
} }
if (ImGui.Selectable(name)) { if (ImGui.Selectable(name)) {
@@ -702,11 +703,21 @@ public sealed class ChatLogWindow : Window, IUiComponent {
internal void SetChannel(InputChannel? channel) internal void SetChannel(InputChannel? channel)
{ {
channel ??= InputChannel.Say; channel ??= InputChannel.Say;
_tellTarget = null; _tellTarget = null;
// Instead of calling SetChannel(), we ask the ExtraChat plugin to set a
// channel override by just calling the command directly.
if (channel.Value.IsExtraChatLinkshell()) { if (channel.Value.IsExtraChatLinkshell()) {
// Instead of calling SetChannel(), we ask the ExtraChat plugin to // Check that the command is registered in Dalamud so the game code
// set a channel override by just calling the command directly. // never sees the command itself.
if (!Plugin.CommandManager.Commands.ContainsKey(channel.Value.Prefix())) {
return;
}
// Send the command through the game chat. We can't call
// ICommandManager.ProcessCommand() here because ExtraChat only
// registers stub handlers and actually processes its commands in a
// SendMessage detour.
var bytes = Encoding.UTF8.GetBytes(channel.Value.Prefix()); var bytes = Encoding.UTF8.GetBytes(channel.Value.Prefix());
Plugin.Common.Functions.Chat.SendMessageUnsafe(bytes); Plugin.Common.Functions.Chat.SendMessageUnsafe(bytes);
return; return;