Pass KeyInput to OnKey functions
This commit is contained in:
committed by
Paul Chote
parent
2742985520
commit
6967c1fff3
@@ -113,7 +113,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
var isValid = false;
|
var isValid = false;
|
||||||
input.Text = initialText;
|
input.Text = initialText;
|
||||||
input.IsValid = () => isValid;
|
input.IsValid = () => isValid;
|
||||||
input.OnEnterKey = () =>
|
input.OnEnterKey = _ =>
|
||||||
{
|
{
|
||||||
if (acceptButton.IsDisabled())
|
if (acceptButton.IsDisabled())
|
||||||
return false;
|
return false;
|
||||||
@@ -121,7 +121,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
acceptButton.OnClick();
|
acceptButton.OnClick();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
input.OnEscKey = () =>
|
input.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
if (cancelButton.IsDisabled())
|
if (cancelButton.IsDisabled())
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public int LeftMargin = 5;
|
public int LeftMargin = 5;
|
||||||
public int RightMargin = 5;
|
public int RightMargin = 5;
|
||||||
|
|
||||||
public Action OnEscKey = () => { };
|
public Action<KeyInput> OnEscKey = _ => { };
|
||||||
public Action OnLoseFocus = () => { };
|
public Action OnLoseFocus = () => { };
|
||||||
|
|
||||||
public Func<bool> IsDisabled = () => false;
|
public Func<bool> IsDisabled = () => false;
|
||||||
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
switch (e.Key)
|
switch (e.Key)
|
||||||
{
|
{
|
||||||
case Keycode.ESCAPE:
|
case Keycode.ESCAPE:
|
||||||
OnEscKey();
|
OnEscKey(e);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
|
filenameInput = panel.Get<TextFieldWidget>("FILENAME_INPUT");
|
||||||
filenameInput.OnTextEdited = () => ApplyFilter();
|
filenameInput.OnTextEdited = () => ApplyFilter();
|
||||||
filenameInput.OnEscKey = filenameInput.YieldKeyboardFocus;
|
filenameInput.OnEscKey = _ => filenameInput.YieldKeyboardFocus();
|
||||||
|
|
||||||
var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
|
var frameContainer = panel.GetOrNull("FRAME_SELECTOR");
|
||||||
if (frameContainer != null)
|
if (frameContainer != null)
|
||||||
|
|||||||
@@ -118,8 +118,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
passwordField.IsVisible = () => orderManager.AuthenticationFailed;
|
passwordField.IsVisible = () => orderManager.AuthenticationFailed;
|
||||||
var passwordLabel = widget.Get<LabelWidget>("PASSWORD_LABEL");
|
var passwordLabel = widget.Get<LabelWidget>("PASSWORD_LABEL");
|
||||||
passwordLabel.IsVisible = passwordField.IsVisible;
|
passwordLabel.IsVisible = passwordField.IsVisible;
|
||||||
passwordField.OnEnterKey = () => { retryButton.OnClick(); return true; };
|
passwordField.OnEnterKey = _ => { retryButton.OnClick(); return true; };
|
||||||
passwordField.OnEscKey = () => { abortButton.OnClick(); return true; };
|
passwordField.OnEscKey = _ => { abortButton.OnClick(); return true; };
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordOffsetAdjusted = false;
|
passwordOffsetAdjusted = false;
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
&& editor.CurrentBrush == editor.DefaultBrush
|
&& editor.CurrentBrush == editor.DefaultBrush
|
||||||
&& Game.RunTime > lastScrollTime + scrollVisibleTimeout;
|
&& Game.RunTime > lastScrollTime + scrollVisibleTimeout;
|
||||||
|
|
||||||
actorIDField.OnEscKey = () =>
|
actorIDField.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
actorIDField.YieldKeyboardFocus();
|
actorIDField.YieldKeyboardFocus();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Panel.Layout = new GridLayout(Panel);
|
Panel.Layout = new GridLayout(Panel);
|
||||||
|
|
||||||
SearchTextField = widget.Get<TextFieldWidget>("SEARCH_TEXTFIELD");
|
SearchTextField = widget.Get<TextFieldWidget>("SEARCH_TEXTFIELD");
|
||||||
SearchTextField.OnEscKey = () =>
|
SearchTextField.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
SearchTextField.Text = "";
|
SearchTextField.Text = "";
|
||||||
SearchTextField.YieldKeyboardFocus();
|
SearchTextField.YieldKeyboardFocus();
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
chatText = chatChrome.Get<TextFieldWidget>("CHAT_TEXTFIELD");
|
chatText = chatChrome.Get<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||||
chatText.MaxLength = UnitOrders.ChatMessageMaxLength;
|
chatText.MaxLength = UnitOrders.ChatMessageMaxLength;
|
||||||
chatText.OnEnterKey = () =>
|
chatText.OnEnterKey = _ =>
|
||||||
{
|
{
|
||||||
var team = teamChat && !disableTeamChat;
|
var team = teamChat && !disableTeamChat;
|
||||||
if (chatText.Text != "")
|
if (chatText.Text != "")
|
||||||
@@ -135,7 +135,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
chatText.OnTabKey = () =>
|
chatText.OnTabKey = _ =>
|
||||||
{
|
{
|
||||||
var previousText = chatText.Text;
|
var previousText = chatText.Text;
|
||||||
chatText.Text = tabCompletion.Complete(chatText.Text);
|
chatText.Text = tabCompletion.Complete(chatText.Text);
|
||||||
@@ -147,7 +147,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
chatText.OnEscKey = () =>
|
chatText.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
if (!isMenuChat)
|
if (!isMenuChat)
|
||||||
CloseChat();
|
CloseChat();
|
||||||
|
|||||||
@@ -55,8 +55,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
nameTextfield.OnEnterKey = () => { nameTextfield.YieldKeyboardFocus(); return true; };
|
nameTextfield.OnEnterKey = _ => { nameTextfield.YieldKeyboardFocus(); return true; };
|
||||||
nameTextfield.OnEscKey = () =>
|
nameTextfield.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
||||||
escPressed = true;
|
escPressed = true;
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
chatTextField.MaxLength = UnitOrders.ChatMessageMaxLength;
|
chatTextField.MaxLength = UnitOrders.ChatMessageMaxLength;
|
||||||
|
|
||||||
chatTextField.TakeKeyboardFocus();
|
chatTextField.TakeKeyboardFocus();
|
||||||
chatTextField.OnEnterKey = () =>
|
chatTextField.OnEnterKey = _ =>
|
||||||
{
|
{
|
||||||
if (chatTextField.Text.Length == 0)
|
if (chatTextField.Text.Length == 0)
|
||||||
return true;
|
return true;
|
||||||
@@ -423,7 +423,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
chatTextField.OnTabKey = () =>
|
chatTextField.OnTabKey = _ =>
|
||||||
{
|
{
|
||||||
var previousText = chatTextField.Text;
|
var previousText = chatTextField.Text;
|
||||||
chatTextField.Text = tabCompletion.Complete(chatTextField.Text);
|
chatTextField.Text = tabCompletion.Complete(chatTextField.Text);
|
||||||
@@ -435,7 +435,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
chatTextField.OnEscKey = () => { chatTextField.Text = ""; return true; };
|
chatTextField.OnEscKey = _ => { chatTextField.Text = ""; return true; };
|
||||||
|
|
||||||
lobbyChatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
|
lobbyChatPanel = lobby.Get<ScrollPanelWidget>("CHAT_DISPLAY");
|
||||||
chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE");
|
chatTemplate = lobbyChatPanel.Get("CHAT_TEMPLATE");
|
||||||
|
|||||||
@@ -409,8 +409,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
name.OnEnterKey = () => { name.YieldKeyboardFocus(); return true; };
|
name.OnEnterKey = _ => { name.YieldKeyboardFocus(); return true; };
|
||||||
name.OnEscKey = () =>
|
name.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
name.Text = c.Name;
|
name.Text = c.Name;
|
||||||
escPressed = true;
|
escPressed = true;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
if (mapFilterInput != null)
|
if (mapFilterInput != null)
|
||||||
{
|
{
|
||||||
mapFilterInput.TakeKeyboardFocus();
|
mapFilterInput.TakeKeyboardFocus();
|
||||||
mapFilterInput.OnEscKey = () =>
|
mapFilterInput.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
if (mapFilterInput.Text.Length == 0)
|
if (mapFilterInput.Text.Length == 0)
|
||||||
canceling();
|
canceling();
|
||||||
@@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
mapFilterInput.OnEnterKey = () => { approving(); return true; };
|
mapFilterInput.OnEnterKey = _ => { approving(); return true; };
|
||||||
mapFilterInput.OnTextEdited = () =>
|
mapFilterInput.OnTextEdited = () =>
|
||||||
{
|
{
|
||||||
mapFilter = mapFilterInput.Text;
|
mapFilter = mapFilterInput.Text;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
var serverName = panel.Get<TextFieldWidget>("SERVER_NAME");
|
var serverName = panel.Get<TextFieldWidget>("SERVER_NAME");
|
||||||
serverName.Text = Settings.SanitizedServerName(settings.Server.Name);
|
serverName.Text = Settings.SanitizedServerName(settings.Server.Name);
|
||||||
serverName.OnEnterKey = () => { serverName.YieldKeyboardFocus(); return true; };
|
serverName.OnEnterKey = _ => { serverName.YieldKeyboardFocus(); return true; };
|
||||||
serverName.OnLoseFocus = () =>
|
serverName.OnLoseFocus = () =>
|
||||||
{
|
{
|
||||||
serverName.Text = Settings.SanitizedServerName(serverName.Text);
|
serverName.Text = Settings.SanitizedServerName(serverName.Text);
|
||||||
|
|||||||
@@ -171,8 +171,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
nameTextfield.OnEnterKey = () => { nameTextfield.YieldKeyboardFocus(); return true; };
|
nameTextfield.OnEnterKey = _ => { nameTextfield.YieldKeyboardFocus(); return true; };
|
||||||
nameTextfield.OnEscKey = () =>
|
nameTextfield.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
nameTextfield.Text = Settings.SanitizedPlayerName(ps.Name);
|
||||||
escPressed = true;
|
escPressed = true;
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY");
|
hotkeyEntryWidget = panel.Get<HotkeyEntryWidget>("HOTKEY_ENTRY");
|
||||||
hotkeyEntryWidget.IsValid = () => isHotkeyValid;
|
hotkeyEntryWidget.IsValid = () => isHotkeyValid;
|
||||||
hotkeyEntryWidget.OnLoseFocus = ValidateHotkey;
|
hotkeyEntryWidget.OnLoseFocus = ValidateHotkey;
|
||||||
hotkeyEntryWidget.OnEscKey = () =>
|
hotkeyEntryWidget.OnEscKey = _ =>
|
||||||
{
|
{
|
||||||
hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
|
hotkeyEntryWidget.Key = modData.Hotkeys[selectedHotkeyDefinition.Name].GetValue();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,9 +55,9 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Func<bool> OnEnterKey = () => false;
|
public Func<KeyInput, bool> OnEnterKey = _ => false;
|
||||||
public Func<bool> OnTabKey = () => false;
|
public Func<KeyInput, bool> OnTabKey = _ => false;
|
||||||
public Func<bool> OnEscKey = () => false;
|
public Func<KeyInput, bool> OnEscKey = _ => false;
|
||||||
public Func<bool> OnAltKey = () => false;
|
public Func<bool> OnAltKey = () => false;
|
||||||
public Action OnLoseFocus = () => { };
|
public Action OnLoseFocus = () => { };
|
||||||
public Action OnTextEdited = () => { };
|
public Action OnTextEdited = () => { };
|
||||||
@@ -226,18 +226,18 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
case Keycode.RETURN:
|
case Keycode.RETURN:
|
||||||
case Keycode.KP_ENTER:
|
case Keycode.KP_ENTER:
|
||||||
if (OnEnterKey())
|
if (OnEnterKey(e))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.TAB:
|
case Keycode.TAB:
|
||||||
if (OnTabKey())
|
if (OnTabKey(e))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Keycode.ESCAPE:
|
case Keycode.ESCAPE:
|
||||||
ClearSelection();
|
ClearSelection();
|
||||||
if (OnEscKey())
|
if (OnEscKey(e))
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user