diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index 8afcb6d4d6..c4b0fe0051 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -108,9 +108,29 @@ namespace OpenRA.Mods.Common.Widgets.Logic panel.Get("COLORBLOCK").GetColor = () => Game.Settings.Player.Color.RGB; } + Action closeAssetBrowser = () => + { + if (isVideoLoaded) + player.Stop(); + Ui.CloseWindow(); + onExit(); + }; + filenameInput = panel.Get("FILENAME_INPUT"); + filenameInput.TakeKeyboardFocus(); filenameInput.OnTextEdited = () => ApplyFilter(filenameInput.Text); - filenameInput.OnEscKey = filenameInput.YieldKeyboardFocus; + filenameInput.OnEscKey = () => + { + if (filenameInput.Text.Length == 0) + closeAssetBrowser(); + else + { + filenameInput.Text = ""; + filenameInput.OnTextEdited(); + } + + return true; + }; var frameContainer = panel.GetOrNull("FRAME_SELECTOR"); if (frameContainer != null) @@ -218,13 +238,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var closeButton = panel.GetOrNull("CLOSE_BUTTON"); if (closeButton != null) - closeButton.OnClick = () => - { - if (isVideoLoaded) - player.Stop(); - Ui.CloseWindow(); - onExit(); - }; + closeButton.OnClick = closeAssetBrowser; } void SelectNextFrame() diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index f9b886e897..b4d03cc9fd 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -523,9 +523,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatLabel = lobby.Get("LABEL_CHATTYPE"); var chatTextField = lobby.Get("CHAT_TEXTFIELD"); - chatTextField.TakeKeyboardFocus(); - chatTextField.OnEnterKey = () => { if (chatTextField.Text.Length == 0) @@ -538,6 +536,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatTextField.Text = ""; return true; }; + chatTextField.OnTabKey = () => { var previousText = chatTextField.Text; @@ -550,6 +549,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; }; + chatTextField.OnEscKey = () => { chatTextField.Text = ""; return true; }; + chatPanel = lobby.Get("CHAT_DISPLAY"); chatTemplate = chatPanel.Get("CHAT_TEMPLATE"); chatPanel.RemoveChildren(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 0e7eb4bb27..dbe46ed3a4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -257,23 +257,35 @@ namespace OpenRA.Mods.Common.Widgets.Logic name.IsDisabled = () => orderManager.LocalClient.IsReady; name.Text = c.Name; + var escPressed = false; name.OnLoseFocus = () => { + if (escPressed) + { + escPressed = false; + return; + } + name.Text = name.Text.Trim(); if (name.Text.Length == 0) name.Text = c.Name; - - if (name.Text == c.Name) - return; - - name.Text = Settings.SanitizedPlayerName(name.Text); - - orderManager.IssueOrder(Order.Command("name " + name.Text)); - Game.Settings.Player.Name = name.Text; - Game.Settings.Save(); + else if (name.Text != c.Name) + { + name.Text = Settings.SanitizedPlayerName(name.Text); + orderManager.IssueOrder(Order.Command("name " + name.Text)); + Game.Settings.Player.Name = name.Text; + Game.Settings.Save(); + } }; 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) diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 1621475f14..e197554663 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -191,14 +191,30 @@ namespace OpenRA.Mods.Common.Widgets.Logic var frameLimitTextfield = panel.Get("FRAME_LIMIT_TEXTFIELD"); frameLimitTextfield.Text = ds.MaxFramerate.ToString(); + var escPressed = false; frameLimitTextfield.OnLoseFocus = () => { + if (escPressed) + { + escPressed = false; + return; + } + int fps; Exts.TryParseIntegerInvariant(frameLimitTextfield.Text, out fps); ds.MaxFramerate = fps.Clamp(1, 1000); frameLimitTextfield.Text = ds.MaxFramerate.ToString(); }; + frameLimitTextfield.OnEnterKey = () => { frameLimitTextfield.YieldKeyboardFocus(); return true; }; + frameLimitTextfield.OnEscKey = () => + { + frameLimitTextfield.Text = ds.MaxFramerate.ToString(); + escPressed = true; + frameLimitTextfield.YieldKeyboardFocus(); + return true; + }; + frameLimitTextfield.IsDisabled = () => !ds.CapFramerate; // Player profile @@ -207,11 +223,31 @@ namespace OpenRA.Mods.Common.Widgets.Logic var nameTextfield = panel.Get("PLAYERNAME"); nameTextfield.IsDisabled = () => worldRenderer.World.Type != WorldType.Shellmap; nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name); - nameTextfield.OnEnterKey = () => { nameTextfield.YieldKeyboardFocus(); return true; }; nameTextfield.OnLoseFocus = () => { - nameTextfield.Text = Settings.SanitizedPlayerName(nameTextfield.Text); - ps.Name = nameTextfield.Text; + if (escPressed) + { + escPressed = false; + return; + } + + nameTextfield.Text = nameTextfield.Text.Trim(); + if (nameTextfield.Text.Length == 0) + nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name); + else + { + nameTextfield.Text = Settings.SanitizedPlayerName(nameTextfield.Text); + ps.Name = nameTextfield.Text; + } + }; + + nameTextfield.OnEnterKey = () => { nameTextfield.YieldKeyboardFocus(); return true; }; + nameTextfield.OnEscKey = () => + { + nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name); + escPressed = true; + nameTextfield.YieldKeyboardFocus(); + return true; }; var colorPreview = panel.Get("COLOR_MANAGER"); @@ -477,16 +513,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic BindHotkeyPref(kv, ks, developerTemplate, hotkeyList); } - return () => - { - // Remove focus from the selected hotkey widget - // This is a bit of a hack, but works - if (Ui.KeyboardFocusWidget != null && panel.GetOrNull(Ui.KeyboardFocusWidget.Id) != null) - { - Ui.KeyboardFocusWidget.YieldKeyboardFocus(); - Ui.KeyboardFocusWidget = null; - } - }; + return () => { }; } Action ResetInputPanel(Widget panel) diff --git a/OpenRA.Mods.Common/Widgets/TextFieldWidget.cs b/OpenRA.Mods.Common/Widgets/TextFieldWidget.cs index 40b62ecb2a..f48c3d7ed5 100644 --- a/OpenRA.Mods.Common/Widgets/TextFieldWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TextFieldWidget.cs @@ -222,7 +222,7 @@ namespace OpenRA.Mods.Common.Widgets bool wasDisabled; public override void Tick() { - // Remove the blicking cursor when disabled + // Remove the blinking cursor when disabled var isDisabled = IsDisabled(); if (isDisabled != wasDisabled) {