Pass KeyInput to OnKey functions

This commit is contained in:
Abdurrahmaan Iqbal
2021-06-29 20:43:03 +01:00
committed by Paul Chote
parent 2742985520
commit 6967c1fff3
15 changed files with 31 additions and 31 deletions

View File

@@ -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;

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Widgets
public int LeftMargin = 5;
public int RightMargin = 5;
public Action OnEscKey = () => { };
public Action<KeyInput> OnEscKey = _ => { };
public Action OnLoseFocus = () => { };
public Func<bool> IsDisabled = () => false;
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets
switch (e.Key)
{
case Keycode.ESCAPE:
OnEscKey();
OnEscKey(e);
break;
default:

View File

@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
filenameInput.OnTextEdited = () => ApplyFilter();
filenameInput.OnEscKey = filenameInput.YieldKeyboardFocus;
filenameInput.OnEscKey = _ => filenameInput.YieldKeyboardFocus();
var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
if (frameContainer != null)

View File

@@ -118,8 +118,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
passwordField.IsVisible = () => orderManager.AuthenticationFailed;
var passwordLabel = widget.Get<LabelWidget>("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;

View File

@@ -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;

View File

@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Panel.Layout = new GridLayout(Panel);
SearchTextField = widget.Get<TextFieldWidget>("SEARCH_TEXTFIELD");
SearchTextField.OnEscKey = () =>
SearchTextField.OnEscKey = _ =>
{
SearchTextField.Text = "";
SearchTextField.YieldKeyboardFocus();

View File

@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
chatText = chatChrome.Get<TextFieldWidget>("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();

View File

@@ -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;

View File

@@ -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<ScrollPanelWidget>("CHAT_DISPLAY");
chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE");

View File

@@ -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;

View File

@@ -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;

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var serverName = panel.Get<TextFieldWidget>("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);

View File

@@ -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;

View File

@@ -186,7 +186,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY");
hotkeyEntryWidget.IsValid = () => isHotkeyValid;
hotkeyEntryWidget.OnLoseFocus = ValidateHotkey;
hotkeyEntryWidget.OnEscKey = () =>
hotkeyEntryWidget.OnEscKey = _ =>
{
hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
};

View File

@@ -55,9 +55,9 @@ namespace OpenRA.Mods.Common.Widgets
}
}
public Func<bool> OnEnterKey = () => false;
public Func<bool> OnTabKey = () => false;
public Func<bool> OnEscKey = () => false;
public Func<KeyInput, bool> OnEnterKey = _ => false;
public Func<KeyInput, bool> OnTabKey = _ => false;
public Func<KeyInput, bool> OnEscKey = _ => false;
public Func<bool> 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;