diff --git a/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs index 334b3af385..a2b195e780 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/IngameChatLogic.cs @@ -190,10 +190,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic } else { - var oneWord = chatText.Text.Contains(' '); + var oneWord = !chatText.Text.Contains(' '); var toComplete = oneWord - ? chatText.Text.Substring(chatText.Text.LastIndexOf(' ') + 1) - : chatText.Text; + ? chatText.Text + : chatText.Text.Substring(chatText.Text.LastIndexOf(' ') + 1); suggestion = playerNames.FirstOrDefault(x => x.StartsWith(toComplete, StringComparison.InvariantCultureIgnoreCase)); if (suggestion == null) diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs index 900c0a7049..4aa5882d42 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyLogic.cs @@ -35,18 +35,23 @@ namespace OpenRA.Mods.RA.Widgets.Logic enum PanelType { Players, Options, Kick, ForceStart } PanelType panel = PanelType.Players; - Widget lobby; + readonly Widget lobby; + readonly Widget editablePlayerTemplate; + readonly Widget nonEditablePlayerTemplate; + readonly Widget emptySlotTemplate; + readonly Widget editableSpectatorTemplate; + readonly Widget nonEditableSpectatorTemplate; + readonly Widget newSpectatorTemplate; - Widget editablePlayerTemplate, nonEditablePlayerTemplate, emptySlotTemplate, - editableSpectatorTemplate, nonEditableSpectatorTemplate, newSpectatorTemplate; + readonly ScrollPanelWidget chatPanel; + readonly Widget chatTemplate; - ScrollPanelWidget chatPanel; - Widget chatTemplate; + readonly ScrollPanelWidget players; + readonly Dictionary countryNames; - ScrollPanelWidget players; - Dictionary countryNames; + readonly ColorPreviewManagerWidget colorPreview; - ColorPreviewManagerWidget colorPreview; + List playerNames; // Listen for connection failures void ConnectionStateChanged(OrderManager om) @@ -498,13 +503,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic chatTextField.Text = ""; return true; }; - - chatTextField.OnTabKey = () => + chatTextField.OnAltKey = () => { teamChat ^= true; chatLabel.Text = teamChat ? "Team:" : "Chat:"; return true; }; + chatTextField.OnTabKey = AutoCompleteText; chatPanel = lobby.Get("CHAT_DISPLAY"); chatTemplate = chatPanel.Get("CHAT_TEMPLATE"); @@ -764,6 +769,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic while (players.Children.Count > idx) players.RemoveChild(players.Children[idx]); + + playerNames = GetPlayerNames().ToList(); } void OnGameStart() @@ -772,6 +779,53 @@ namespace OpenRA.Mods.RA.Widgets.Logic onStart(); } + IEnumerable GetPlayerNames() + { + foreach (var container in players.Children) + { + if (container.Id == "TEMPLATE_EDITABLE_PLAYER") + { + var textWidget = container.Children.FirstOrDefault(x => x.Id == "NAME") as TextFieldWidget; + if (textWidget == null) + continue; + yield return textWidget.Text; + } + else if (container.Id == "TEMPLATE_NONEDITABLE_PLAYER") + { + var labelWidget = container.Children.FirstOrDefault(x => x.Id == "NAME") as LabelWidget; + if (labelWidget == null) + continue; + yield return labelWidget.GetText(); + } + } + } + + bool AutoCompleteText() + { + var chatText = lobby.Get("CHAT_TEXTFIELD"); + if (chatText == null || string.IsNullOrEmpty(chatText.Text)) + return false; + + var suggestion = ""; + var oneWord = !chatText.Text.Contains(' '); + var toComplete = oneWord + ? chatText.Text + : chatText.Text.Substring(chatText.Text.LastIndexOf(' ') + 1); + + suggestion = playerNames.FirstOrDefault(x => x.StartsWith(toComplete, StringComparison.InvariantCultureIgnoreCase)); + if (suggestion == null) + return false; + + if (oneWord) + suggestion += ": "; + else + suggestion = chatText.Text.Substring(0, chatText.Text.Length - toComplete.Length) + suggestion; + + chatText.Text = suggestion; + chatText.CursorPosition = chatText.Text.Length; + return true; + } + class DropDownOption { public string Title;