From f2c132c7d8723c93b53008afa0866076136fb44d Mon Sep 17 00:00:00 2001 From: Haselnussbomber Date: Thu, 9 Jan 2025 22:15:14 +0100 Subject: [PATCH] Allow setting a DisplayOrder on commands (#2162) * Allow setting a DisplayOrder on commands * Linq on demand * Sort commands in /help alphabetically * note default in xmldoc --------- Co-authored-by: goat <16760685+goaaats@users.noreply.github.com> --- Dalamud/Game/Command/CommandInfo.cs | 10 +++++++++- Dalamud/Interface/Internal/DalamudCommands.cs | 2 +- .../Windows/PluginInstaller/PluginInstallerWindow.cs | 7 ++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Dalamud/Game/Command/CommandInfo.cs b/Dalamud/Game/Command/CommandInfo.cs index 8aed817d0..16462a831 100644 --- a/Dalamud/Game/Command/CommandInfo.cs +++ b/Dalamud/Game/Command/CommandInfo.cs @@ -11,7 +11,7 @@ public interface IReadOnlyCommandInfo /// The command itself. /// The arguments supplied to the command, ready for parsing. public delegate void HandlerDelegate(string command, string arguments); - + /// /// Gets a which will be called when the command is dispatched. /// @@ -26,6 +26,11 @@ public interface IReadOnlyCommandInfo /// Gets a value indicating whether if this command should be shown in the help output. /// bool ShowInHelp { get; } + + /// + /// Gets the display order of this command. Defaults to alphabetical ordering. + /// + int DisplayOrder { get; } } /// @@ -51,4 +56,7 @@ public sealed class CommandInfo : IReadOnlyCommandInfo /// public bool ShowInHelp { get; set; } = true; + + /// + public int DisplayOrder { get; set; } = -1; } diff --git a/Dalamud/Interface/Internal/DalamudCommands.cs b/Dalamud/Interface/Internal/DalamudCommands.cs index 00997c1d5..636f71bfa 100644 --- a/Dalamud/Interface/Internal/DalamudCommands.cs +++ b/Dalamud/Interface/Internal/DalamudCommands.cs @@ -178,7 +178,7 @@ internal class DalamudCommands : IServiceType if (arguments.IsNullOrWhitespace()) { chatGui.Print(Loc.Localize("DalamudCmdHelpAvailable", "Available commands:")); - foreach (var cmd in commandManager.Commands) + foreach (var cmd in commandManager.Commands.OrderBy(cInfo => cInfo.Key)) { if (!cmd.Value.ShowInHelp) continue; diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 4e60d4be8..3abb1bb39 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -2762,13 +2762,14 @@ internal class PluginInstallerWindow : Window, IDisposable var commands = commandManager.Commands .Where(cInfo => cInfo.Value is { ShowInHelp: true } && - commandManager.GetHandlerAssemblyName(cInfo.Key, cInfo.Value) == plugin.Manifest.InternalName) - .ToArray(); + commandManager.GetHandlerAssemblyName(cInfo.Key, cInfo.Value) == plugin.Manifest.InternalName); if (commands.Any()) { ImGui.Dummy(ImGuiHelpers.ScaledVector2(10f, 10f)); - foreach (var command in commands) + foreach (var command in commands + .OrderBy(cInfo => cInfo.Value.DisplayOrder) + .ThenBy(cInfo => cInfo.Key)) { ImGuiHelpers.SafeTextWrapped($"{command.Key} → {command.Value.HelpMessage}"); }