Added tab completion to lobby chat.
Also fixes accidental reversion of one word logic during cleanup. Fields that could be readonly are now readonly.
This commit is contained in:
@@ -190,10 +190,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var oneWord = chatText.Text.Contains(' ');
|
var oneWord = !chatText.Text.Contains(' ');
|
||||||
var toComplete = oneWord
|
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));
|
suggestion = playerNames.FirstOrDefault(x => x.StartsWith(toComplete, StringComparison.InvariantCultureIgnoreCase));
|
||||||
if (suggestion == null)
|
if (suggestion == null)
|
||||||
|
|||||||
@@ -35,18 +35,23 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
enum PanelType { Players, Options, Kick, ForceStart }
|
enum PanelType { Players, Options, Kick, ForceStart }
|
||||||
PanelType panel = PanelType.Players;
|
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,
|
readonly ScrollPanelWidget chatPanel;
|
||||||
editableSpectatorTemplate, nonEditableSpectatorTemplate, newSpectatorTemplate;
|
readonly Widget chatTemplate;
|
||||||
|
|
||||||
ScrollPanelWidget chatPanel;
|
readonly ScrollPanelWidget players;
|
||||||
Widget chatTemplate;
|
readonly Dictionary<string, string> countryNames;
|
||||||
|
|
||||||
ScrollPanelWidget players;
|
readonly ColorPreviewManagerWidget colorPreview;
|
||||||
Dictionary<string, string> countryNames;
|
|
||||||
|
|
||||||
ColorPreviewManagerWidget colorPreview;
|
List<string> playerNames;
|
||||||
|
|
||||||
// Listen for connection failures
|
// Listen for connection failures
|
||||||
void ConnectionStateChanged(OrderManager om)
|
void ConnectionStateChanged(OrderManager om)
|
||||||
@@ -498,13 +503,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
chatTextField.Text = "";
|
chatTextField.Text = "";
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
chatTextField.OnAltKey = () =>
|
||||||
chatTextField.OnTabKey = () =>
|
|
||||||
{
|
{
|
||||||
teamChat ^= true;
|
teamChat ^= true;
|
||||||
chatLabel.Text = teamChat ? "Team:" : "Chat:";
|
chatLabel.Text = teamChat ? "Team:" : "Chat:";
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
chatTextField.OnTabKey = AutoCompleteText;
|
||||||
|
|
||||||
chatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
|
chatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
|
||||||
chatTemplate = chatPanel.Get("CHAT_TEMPLATE");
|
chatTemplate = chatPanel.Get("CHAT_TEMPLATE");
|
||||||
@@ -764,6 +769,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
while (players.Children.Count > idx)
|
while (players.Children.Count > idx)
|
||||||
players.RemoveChild(players.Children[idx]);
|
players.RemoveChild(players.Children[idx]);
|
||||||
|
|
||||||
|
playerNames = GetPlayerNames().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnGameStart()
|
void OnGameStart()
|
||||||
@@ -772,6 +779,53 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
onStart();
|
onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEnumerable<string> 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<TextFieldWidget>("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
|
class DropDownOption
|
||||||
{
|
{
|
||||||
public string Title;
|
public string Title;
|
||||||
|
|||||||
Reference in New Issue
Block a user