- Check auto translation for commands and execute them instead of sending

- Plugin commands trigger the command helper window now
- Fix auto translation with empty text appearing
- Switch up all dalamud payload usage to ROSS if possible
- Prepare 7.5 changes
- Cleanup
This commit is contained in:
Infi
2026-04-08 21:15:28 +02:00
parent 9f7a6267f6
commit c424311b24
52 changed files with 614 additions and 423 deletions
+46 -30
View File
@@ -20,6 +20,7 @@ using Dalamud.Memory;
using FFXIVClientStructs.FFXIV.Client.UI;
using Dalamud.Bindings.ImGui;
using Lumina.Excel.Sheets;
using Lumina.Extensions;
namespace ChatTwo.Ui;
@@ -68,7 +69,7 @@ public sealed class ChatLogWindow : Window
public PayloadHandler PayloadHandler { get; }
internal Lender<PayloadHandler> HandlerLender { get; }
private Dictionary<string, ChatType> TextCommandChannels { get; } = new();
private HashSet<string> AllCommands { get; } = [];
private Dictionary<string, TextCommand> AllCommands { get; } = [];
private const uint ChatOpenSfx = 35u;
private const uint ChatCloseSfx = 3u;
@@ -238,7 +239,7 @@ public sealed class ChatLogWindow : Window
private bool IsValidCommand(string command)
{
return Plugin.CommandManager.Commands.ContainsKey(command) || AllCommands.Contains(command);
return Plugin.CommandManager.Commands.ContainsKey(command) || AllCommands.ContainsKey(command);
}
private void ClearLog(string command, string arguments)
@@ -288,7 +289,7 @@ public sealed class ChatLogWindow : Window
foreach (var input in Enum.GetValues<InputChannel>())
{
var commands = input.TextCommands(Plugin.DataManager);
var commands = input.TextCommands();
if (commands == null)
continue;
@@ -297,11 +298,8 @@ public sealed class ChatLogWindow : Window
AddTextCommandChannel(command, type);
}
if (Sheets.TextCommandSheet.HasRow(116))
{
var echo = Sheets.TextCommandSheet.GetRow(116);
AddTextCommandChannel(echo, ChatType.Echo);
}
if (Sheets.TextCommandSheet.TryGetRow(116, out var row))
AddTextCommandChannel(row, ChatType.Echo);
}
private void AddTextCommandChannel(TextCommand command, ChatType type)
@@ -314,19 +312,20 @@ public sealed class ChatLogWindow : Window
private void SetUpAllCommands()
{
if (Plugin.DataManager.GetExcelSheet<TextCommand>() is not { } commands)
return;
var commandNames = commands.SelectMany(cmd => new[]
foreach (var command in Sheets.TextCommandSheet)
{
cmd.Command.ExtractText(),
cmd.ShortCommand.ExtractText(),
cmd.Alias.ExtractText(),
cmd.ShortAlias.ExtractText(),
});
if (!command.Command.IsEmpty)
AllCommands.TryAdd(command.Command.ToString(), command);
foreach (var command in commandNames)
AllCommands.Add(command);
if (!command.ShortCommand.IsEmpty)
AllCommands.TryAdd(command.ShortCommand.ToString(), command);
if (!command.Alias.IsEmpty)
AllCommands.TryAdd(command.Alias.ToString(), command);
if (!command.ShortAlias.IsEmpty)
AllCommands.TryAdd(command.ShortAlias.ToString(), command);
}
}
private void AddBacklog(string message)
@@ -736,7 +735,7 @@ public sealed class ChatLogWindow : Window
if (!channel.IsValid())
continue;
var name = Sheets.LogFilterSheet.FirstOrNull(row => row.LogKind == (byte) channel.ToChatType())?.Name.ExtractText() ?? channel.ToChatType().Name();
var name = Sheets.LogFilterSheet.FirstOrNull(row => row.LogKind == (byte) channel.ToChatType())?.Name.ToString() ?? channel.ToChatType().Name();
if (channel.IsLinkshell())
{
var lsName = Plugin.Functions.Chat.GetLinkshellName(channel.LinkshellIndex());
@@ -933,13 +932,19 @@ public sealed class ChatLogWindow : Window
AddBacklog(trimmed);
InputBacklogIdx = -1;
if (HasTranslationCommand(trimmed))
{
activeTab.CurrentChannel.ResetTempChannel();
Chat = string.Empty;
return;
}
if (TellSpecial)
{
var tellBytes = Encoding.UTF8.GetBytes(trimmed);
AutoTranslate.ReplaceWithPayload(ref tellBytes);
Plugin.Functions.Chat.SendTellUsingCommandInner(tellBytes);
TellSpecial = false;
activeTab.CurrentChannel.ResetTempChannel();
@@ -1000,6 +1005,18 @@ public sealed class ChatLogWindow : Window
Chat = string.Empty;
}
private bool HasTranslationCommand(string trimmed)
{
var messageBytes = Encoding.UTF8.GetBytes(trimmed);
if (AutoTranslate.StartsWithCommand(ref messageBytes))
{
ChatBox.SendMessageUnsafe(messageBytes);
return true;
}
return false;
}
internal void UserHide()
{
CurrentHideState = HideState.User;
@@ -1492,10 +1509,11 @@ public sealed class ChatLogWindow : Window
var button = (i + 1) % 10;
var text = string.Format(Language.AutoTranslate_Completion_Key, button);
var size = ImGui.CalcTextSize(text);
ImGui.SameLine(ImGui.GetContentRegionAvail().X - size.X);
ImGui.PushStyleColor(ImGuiCol.Text, *ImGui.GetStyleColorVec4(ImGuiCol.TextDisabled));
ImGui.TextUnformatted(text);
ImGui.PopStyleColor();
using (ImRaii.PushColor(ImGuiCol.Text, ImGui.GetStyle().Colors[(int)ImGuiCol.TextDisabled]))
ImGui.TextUnformatted(text);
}
if (!clicked)
@@ -1632,12 +1650,10 @@ public sealed class ChatLogWindow : Window
if (text.StartsWith('/'))
{
var command = text.Split(' ')[0];
var cmd = Sheets.TextCommandSheet.FirstOrNull(cmd =>
cmd.Command.ExtractText() == command || cmd.Alias.ExtractText() == command ||
cmd.ShortCommand.ExtractText() == command || cmd.ShortAlias.ExtractText() == command);
if (cmd != null)
Plugin.CommandHelpWindow.UpdateContent(cmd.Value);
if (AllCommands.TryGetValue(command, out var textCommand))
Plugin.CommandHelpWindow.UpdateContent(textCommand.Description);
else if (Plugin.CommandManager.Commands.TryGetValue(command, out var info) && info.ShowInHelp)
Plugin.CommandHelpWindow.UpdateContent(info.HelpMessage);
}
if (data.EventFlag != ImGuiInputTextFlags.CallbackHistory)