Improves player name text field in game lobby.
Esc key resets text field to unmodified value and yields focus.
This commit is contained in:
@@ -257,23 +257,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
name.IsDisabled = () => orderManager.LocalClient.IsReady;
|
name.IsDisabled = () => orderManager.LocalClient.IsReady;
|
||||||
|
|
||||||
name.Text = c.Name;
|
name.Text = c.Name;
|
||||||
|
var escPressed = false;
|
||||||
name.OnLoseFocus = () =>
|
name.OnLoseFocus = () =>
|
||||||
{
|
{
|
||||||
|
if (escPressed)
|
||||||
|
{
|
||||||
|
escPressed = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
name.Text = name.Text.Trim();
|
name.Text = name.Text.Trim();
|
||||||
if (name.Text.Length == 0)
|
if (name.Text.Length == 0)
|
||||||
name.Text = c.Name;
|
name.Text = c.Name;
|
||||||
|
else if (name.Text != c.Name)
|
||||||
if (name.Text == c.Name)
|
{
|
||||||
return;
|
name.Text = Settings.SanitizedPlayerName(name.Text);
|
||||||
|
orderManager.IssueOrder(Order.Command("name " + name.Text));
|
||||||
name.Text = Settings.SanitizedPlayerName(name.Text);
|
Game.Settings.Player.Name = name.Text;
|
||||||
|
Game.Settings.Save();
|
||||||
orderManager.IssueOrder(Order.Command("name " + name.Text));
|
}
|
||||||
Game.Settings.Player.Name = name.Text;
|
|
||||||
Game.Settings.Save();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
name.OnEnterKey = () => { name.YieldKeyboardFocus(); return true; };
|
name.OnEnterKey = () => { name.YieldKeyboardFocus(); return true; };
|
||||||
|
name.OnEscKey = () =>
|
||||||
|
{
|
||||||
|
name.Text = c.Name;
|
||||||
|
escPressed = true;
|
||||||
|
name.YieldKeyboardFocus();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SetupNameWidget(Widget parent, Session.Slot s, Session.Client c)
|
public static void SetupNameWidget(Widget parent, Session.Slot s, Session.Client c)
|
||||||
|
|||||||
Reference in New Issue
Block a user