- 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)
+7 -7
View File
@@ -4,15 +4,15 @@ using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using Dalamud.Utility;
using Dalamud.Bindings.ImGui;
using Lumina.Excel.Sheets;
using Lumina.Text.ReadOnly;
namespace ChatTwo.Ui;
public class CommandHelpWindow : Window {
private ChatLogWindow LogWindow { get; }
private TextCommand? Command { get; set; }
private ReadOnlySeString? CommandDescription { get; set; }
internal CommandHelpWindow(ChatLogWindow logWindow) : base($"command help##chat2-commandhelp")
internal CommandHelpWindow(ChatLogWindow logWindow) : base("command help##chat2-commandhelp")
{
LogWindow = logWindow;
@@ -24,9 +24,9 @@ public class CommandHelpWindow : Window {
}
// Sets IsOpen to true if it should be drawn
public void UpdateContent(TextCommand command)
public void UpdateContent(ReadOnlySeString commandDesc)
{
Command = command;
CommandDescription = commandDesc;
var width = 350;
var scaledWidth = width * ImGuiHelpers.GlobalScale;
@@ -56,9 +56,9 @@ public class CommandHelpWindow : Window {
public override void Draw()
{
if (Command == null)
if (CommandDescription == null)
return;
LogWindow.DrawChunks(ChunkUtil.ToChunks(Command.Value.Description.ToDalamudString(), ChunkSource.None, null).ToList());
LogWindow.DrawChunks(ChunkUtil.ToChunks(CommandDescription.Value.ToDalamudString(), ChunkSource.None, null).ToList());
}
}
+1 -1
View File
@@ -33,7 +33,7 @@ internal sealed class About : ISettingsTab
public void Draw(bool changed)
{
using var wrap = ImGuiUtil.TextWrapPos();
using var wrap = ImRaii.TextWrapPos(0.0f);
ImGui.TextUnformatted(string.Format(Language.Options_About_Opening, Plugin.PluginName));
+1 -1
View File
@@ -18,7 +18,7 @@ internal sealed class Changelog : ISettingsTab
public void Draw(bool changed)
{
using var wrap = ImGuiUtil.TextWrapPos();
using var wrap = ImRaii.TextWrapPos(0.0f);
ImGui.TextUnformatted(Language.Options_Warning_NotImplemented);
ImGuiUtil.OptionCheckbox(ref Mutable.PrintChangelog, Language.Options_PrintChangelog_Name, Language.Options_PrintChangelog_Description);
+1 -1
View File
@@ -21,7 +21,7 @@ internal sealed class ChatLog : ISettingsTab
public void Draw(bool changed)
{
using (ImGuiUtil.TextWrapPos())
using (ImRaii.TextWrapPos(0.0f))
{
ImGuiUtil.OptionCheckbox(ref Mutable.KeepInputFocus, Language.Options_KeepInputFocus_Name, Language.Options_KeepInputFocus_Description);
ImGui.Spacing();
+1 -1
View File
@@ -138,7 +138,7 @@ internal sealed class Database : ISettingsTab
return;
using var treeNode = ImRaii.TreeNode(Language.Options_Database_Advanced);
using var wrap = ImGuiUtil.TextWrapPos();
using var wrap = ImRaii.TextWrapPos(0.0f);
ImGuiUtil.WarningText(Language.Options_Database_Advanced_Warning);
if (ImGuiUtil.CtrlShiftButton("Perform maintenance", "Ctrl+Shift: MessageManager.Store.PerformMaintenance()"))
+1 -1
View File
@@ -19,7 +19,7 @@ internal sealed class Display : ISettingsTab
public void Draw(bool changed)
{
using var wrap = ImGuiUtil.TextWrapPos();
using var wrap = ImRaii.TextWrapPos(0.0f);
ImGuiUtil.OptionCheckbox(ref Mutable.HideChat, Language.Options_HideChat_Name, Language.Options_HideChat_Description);
ImGui.Spacing();
+1 -1
View File
@@ -38,7 +38,7 @@ internal sealed class Emote : ISettingsTab
public void Draw(bool changed)
{
using var wrap = ImGuiUtil.TextWrapPos();
using var wrap = ImRaii.TextWrapPos(0.0f);
ImGuiUtil.OptionCheckbox(ref Mutable.ShowEmotes, Language.Options_ShowEmotes_Name, Language.Options_ShowEmotes_Desc);
ImGui.Spacing();
+2 -1
View File
@@ -3,6 +3,7 @@ using ChatTwo.Util;
using Dalamud;
using Dalamud.Interface.FontIdentifier;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility.Raii;
namespace ChatTwo.Ui.SettingsTabs;
@@ -19,7 +20,7 @@ public class Fonts : ISettingsTab
public void Draw(bool _)
{
using var wrap = ImGuiUtil.TextWrapPos();
using var wrap = ImRaii.TextWrapPos(0.0f);
ImGui.Checkbox(Language.Options_FontsEnabled, ref Mutable.FontsEnabled);
ImGui.Spacing();
+2 -1
View File
@@ -1,6 +1,7 @@
using ChatTwo.Resources;
using ChatTwo.Util;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility.Raii;
namespace ChatTwo.Ui.SettingsTabs;
@@ -17,7 +18,7 @@ internal sealed class Preview : ISettingsTab
public void Draw(bool changed)
{
using var wrap = ImGuiUtil.TextWrapPos();
using var wrap = ImRaii.TextWrapPos(0.0f);
using (var combo = ImGuiUtil.BeginComboVertical(Language.Options_Preview_Name, Mutable.PreviewPosition.Name()))
{
+1 -1
View File
@@ -138,7 +138,7 @@ internal sealed class Webinterface(Plugin plugin, Configuration mutable) : ISett
clicked |= ImGuiUtil.IconButton(FontAwesomeIcon.ExternalLinkAlt, "urlOpen");
if (clicked)
WrapperUtil.TryOpenURI(uri);
WrapperUtil.TryOpenUri(uri);
}
else
{