Fix tab completion to work for all available commands.

Commands are registered in WorldLoaded event handlers, and IngameChatLogic takes all registered commands and provides tab completion. However IngameChatLogic is also created during WorldLoaded via LoadWidgetAtGameStart. No initialization order is enforced between commands and LoadWidgetAtGameStart, so they can appear in any order.

If a command gets registered before LoadWidgetAtGameStart runs, then it will get tab completion. If it gets registered after then no tab completion is available, even though the command can still be used and appears when using '/help'.

To fix this, we allow the tab completion to check for available commands lazily, meaning it will check for available commands every time the tab key is pressed. This means it will always have the full list of commands available regardless of the initialization order.
This commit is contained in:
RoosterDragon
2022-07-25 20:03:47 +01:00
committed by abcdefg30
parent 999af0c05b
commit 8dec998d8f
2 changed files with 2 additions and 2 deletions

View File

@@ -57,7 +57,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var disableTeamChat = alwaysDisabled || (world.LocalPlayer != null && !players.Any(p => p.IsAlliedWith(world.LocalPlayer)));
var teamChat = !disableTeamChat;
tabCompletion.Commands = chatTraits.OfType<ChatCommands>().SelectMany(x => x.Commands.Keys).ToList();
tabCompletion.Commands = chatTraits.OfType<ChatCommands>().ToArray().SelectMany(x => x.Commands.Keys);
tabCompletion.Names = orderManager.LobbyInfo.Clients.Select(c => c.Name).Distinct().ToList();
if (logicArgs.TryGetValue("Templates", out var templateIds))

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
string prefix;
string suffix;
public IList<string> Commands { get; set; }
public IEnumerable<string> Commands { get; set; }
public IList<string> Names { get; set; }