From 6967c1fff3daa1992563a0ce25c5ae2afd423db4 Mon Sep 17 00:00:00 2001 From: Abdurrahmaan Iqbal Date: Tue, 29 Jun 2021 20:43:03 +0100 Subject: [PATCH] Pass KeyInput to OnKey functions --- OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs | 4 ++-- OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs | 4 ++-- .../Widgets/Logic/AssetBrowserLogic.cs | 2 +- OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs | 4 ++-- .../Widgets/Logic/Editor/ActorEditLogic.cs | 2 +- .../Widgets/Logic/Editor/CommonSelectorLogic.cs | 2 +- .../Widgets/Logic/Ingame/IngameChatLogic.cs | 6 +++--- .../Widgets/Logic/IntroductionPromptLogic.cs | 4 ++-- OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs | 6 +++--- OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs | 4 ++-- OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs | 4 ++-- .../Widgets/Logic/ServerCreationLogic.cs | 2 +- .../Widgets/Logic/Settings/DisplaySettingsLogic.cs | 4 ++-- .../Widgets/Logic/Settings/HotkeysSettingsLogic.cs | 2 +- OpenRA.Mods.Common/Widgets/TextFieldWidget.cs | 12 ++++++------ 15 files changed, 31 insertions(+), 31 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs b/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs index e2e92494b4..bbc810e0c3 100644 --- a/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs +++ b/OpenRA.Mods.Common/Widgets/ConfirmationDialogs.cs @@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Widgets var isValid = false; input.Text = initialText; input.IsValid = () => isValid; - input.OnEnterKey = () => + input.OnEnterKey = _ => { if (acceptButton.IsDisabled()) return false; @@ -121,7 +121,7 @@ namespace OpenRA.Mods.Common.Widgets acceptButton.OnClick(); return true; }; - input.OnEscKey = () => + input.OnEscKey = _ => { if (cancelButton.IsDisabled()) return false; diff --git a/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs b/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs index cf15cd3de6..e17fc21313 100644 --- a/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs +++ b/OpenRA.Mods.Common/Widgets/HotkeyEntryWidget.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Widgets public int LeftMargin = 5; public int RightMargin = 5; - public Action OnEscKey = () => { }; + public Action OnEscKey = _ => { }; public Action OnLoseFocus = () => { }; public Func IsDisabled = () => false; @@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets switch (e.Key) { case Keycode.ESCAPE: - OnEscKey(); + OnEscKey(e); break; default: diff --git a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs index db4e5211bf..7628997294 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/AssetBrowserLogic.cs @@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic filenameInput = panel.Get("FILENAME_INPUT"); filenameInput.OnTextEdited = () => ApplyFilter(); - filenameInput.OnEscKey = filenameInput.YieldKeyboardFocus; + filenameInput.OnEscKey = _ => filenameInput.YieldKeyboardFocus(); var frameContainer = panel.GetOrNull("FRAME_SELECTOR"); if (frameContainer != null) diff --git a/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs index 7d7c1987a6..148f09fba4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ConnectionLogic.cs @@ -118,8 +118,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic passwordField.IsVisible = () => orderManager.AuthenticationFailed; var passwordLabel = widget.Get("PASSWORD_LABEL"); passwordLabel.IsVisible = passwordField.IsVisible; - passwordField.OnEnterKey = () => { retryButton.OnClick(); return true; }; - passwordField.OnEscKey = () => { abortButton.OnClick(); return true; }; + passwordField.OnEnterKey = _ => { retryButton.OnClick(); return true; }; + passwordField.OnEscKey = _ => { abortButton.OnClick(); return true; }; } passwordOffsetAdjusted = false; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs index 8581c625f7..cd28f2fada 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorEditLogic.cs @@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic && editor.CurrentBrush == editor.DefaultBrush && Game.RunTime > lastScrollTime + scrollVisibleTimeout; - actorIDField.OnEscKey = () => + actorIDField.OnEscKey = _ => { actorIDField.YieldKeyboardFocus(); return true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs index a52d2697d3..e9ae902509 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs @@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic Panel.Layout = new GridLayout(Panel); SearchTextField = widget.Get("SEARCH_TEXTFIELD"); - SearchTextField.OnEscKey = () => + SearchTextField.OnEscKey = _ => { SearchTextField.Text = ""; SearchTextField.YieldKeyboardFocus(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index 10c99da014..dc08c74fde 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatText = chatChrome.Get("CHAT_TEXTFIELD"); chatText.MaxLength = UnitOrders.ChatMessageMaxLength; - chatText.OnEnterKey = () => + chatText.OnEnterKey = _ => { var team = teamChat && !disableTeamChat; if (chatText.Text != "") @@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; }; - chatText.OnTabKey = () => + chatText.OnTabKey = _ => { var previousText = chatText.Text; chatText.Text = tabCompletion.Complete(chatText.Text); @@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; }; - chatText.OnEscKey = () => + chatText.OnEscKey = _ => { if (!isMenuChat) CloseChat(); diff --git a/OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs index 2a47b5de20..716f220f13 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs @@ -55,8 +55,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } }; - nameTextfield.OnEnterKey = () => { nameTextfield.YieldKeyboardFocus(); return true; }; - nameTextfield.OnEscKey = () => + nameTextfield.OnEnterKey = _ => { nameTextfield.YieldKeyboardFocus(); return true; }; + nameTextfield.OnEscKey = _ => { nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name); escPressed = true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 38b7a1f792..d9a42f1b8e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -406,7 +406,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatTextField.MaxLength = UnitOrders.ChatMessageMaxLength; chatTextField.TakeKeyboardFocus(); - chatTextField.OnEnterKey = () => + chatTextField.OnEnterKey = _ => { if (chatTextField.Text.Length == 0) return true; @@ -423,7 +423,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; }; - chatTextField.OnTabKey = () => + chatTextField.OnTabKey = _ => { var previousText = chatTextField.Text; chatTextField.Text = tabCompletion.Complete(chatTextField.Text); @@ -435,7 +435,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; }; - chatTextField.OnEscKey = () => { chatTextField.Text = ""; return true; }; + chatTextField.OnEscKey = _ => { chatTextField.Text = ""; return true; }; lobbyChatPanel = lobby.Get("CHAT_DISPLAY"); chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 41bda27bb9..3a0f91c882 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -409,8 +409,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } }; - name.OnEnterKey = () => { name.YieldKeyboardFocus(); return true; }; - name.OnEscKey = () => + name.OnEnterKey = _ => { name.YieldKeyboardFocus(); return true; }; + name.OnEscKey = _ => { name.Text = c.Name; escPressed = true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index a104e1600c..8545ae0312 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (mapFilterInput != null) { mapFilterInput.TakeKeyboardFocus(); - mapFilterInput.OnEscKey = () => + mapFilterInput.OnEscKey = _ => { if (mapFilterInput.Text.Length == 0) canceling(); @@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic return true; }; - mapFilterInput.OnEnterKey = () => { approving(); return true; }; + mapFilterInput.OnEnterKey = _ => { approving(); return true; }; mapFilterInput.OnTextEdited = () => { mapFilter = mapFilterInput.Text; diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs index 386e37217c..e453d9053f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ServerCreationLogic.cs @@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var serverName = panel.Get("SERVER_NAME"); serverName.Text = Settings.SanitizedServerName(settings.Server.Name); - serverName.OnEnterKey = () => { serverName.YieldKeyboardFocus(); return true; }; + serverName.OnEnterKey = _ => { serverName.YieldKeyboardFocus(); return true; }; serverName.OnLoseFocus = () => { serverName.Text = Settings.SanitizedServerName(serverName.Text); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs index 88014f3305..390fc03bc9 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs @@ -171,8 +171,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic } }; - nameTextfield.OnEnterKey = () => { nameTextfield.YieldKeyboardFocus(); return true; }; - nameTextfield.OnEscKey = () => + nameTextfield.OnEnterKey = _ => { nameTextfield.YieldKeyboardFocus(); return true; }; + nameTextfield.OnEscKey = _ => { nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name); escPressed = true; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs index d484bac24f..3dcf55fcc0 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/HotkeysSettingsLogic.cs @@ -186,7 +186,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic hotkeyEntryWidget = panel.Get("HOTKEY_ENTRY"); hotkeyEntryWidget.IsValid = () => isHotkeyValid; hotkeyEntryWidget.OnLoseFocus = ValidateHotkey; - hotkeyEntryWidget.OnEscKey = () => + hotkeyEntryWidget.OnEscKey = _ => { hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue(); }; diff --git a/OpenRA.Mods.Common/Widgets/TextFieldWidget.cs b/OpenRA.Mods.Common/Widgets/TextFieldWidget.cs index cf68f16db9..588aa13b13 100644 --- a/OpenRA.Mods.Common/Widgets/TextFieldWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TextFieldWidget.cs @@ -55,9 +55,9 @@ namespace OpenRA.Mods.Common.Widgets } } - public Func OnEnterKey = () => false; - public Func OnTabKey = () => false; - public Func OnEscKey = () => false; + public Func OnEnterKey = _ => false; + public Func OnTabKey = _ => false; + public Func OnEscKey = _ => false; public Func OnAltKey = () => false; public Action OnLoseFocus = () => { }; public Action OnTextEdited = () => { }; @@ -226,18 +226,18 @@ namespace OpenRA.Mods.Common.Widgets { case Keycode.RETURN: case Keycode.KP_ENTER: - if (OnEnterKey()) + if (OnEnterKey(e)) return true; break; case Keycode.TAB: - if (OnTabKey()) + if (OnTabKey(e)) return true; break; case Keycode.ESCAPE: ClearSelection(); - if (OnEscKey()) + if (OnEscKey(e)) return true; break;