Change Widget key support: Move (unused) Widget.OnKeyPress hook onto ButtonWidget; Buttons will respond to keys with modifiers.
This commit is contained in:
@@ -25,12 +25,14 @@ namespace OpenRA.Widgets
|
||||
public Func<string> GetText;
|
||||
public Func<bool> IsDisabled = () => false;
|
||||
public Action OnClick = () => {};
|
||||
public Action<KeyInput> OnKeyPress = _ => {};
|
||||
|
||||
public ButtonWidget()
|
||||
: base()
|
||||
{
|
||||
GetText = () => { return Text; };
|
||||
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
|
||||
OnKeyPress = _ => OnClick();
|
||||
}
|
||||
|
||||
protected ButtonWidget(ButtonWidget widget)
|
||||
@@ -42,6 +44,7 @@ namespace OpenRA.Widgets
|
||||
VisualHeight = widget.VisualHeight;
|
||||
GetText = widget.GetText;
|
||||
OnMouseUp = mi => { if (!IsDisabled()) OnClick(); return true; };
|
||||
OnKeyPress = _ => OnClick();
|
||||
}
|
||||
|
||||
public override bool LoseFocus(MouseInput mi)
|
||||
@@ -52,11 +55,12 @@ namespace OpenRA.Widgets
|
||||
|
||||
public override bool HandleKeyPressInner(KeyInput e)
|
||||
{
|
||||
if (e.KeyName != Key || e.Modifiers != Modifiers.None || e.Event != KeyInputEvent.Down)
|
||||
if (e.KeyName != Key || e.Event != KeyInputEvent.Down)
|
||||
return false;
|
||||
|
||||
if (!IsDisabled())
|
||||
OnClick();
|
||||
OnKeyPress(e);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ namespace OpenRA.Widgets
|
||||
public Func<MouseInput, bool> OnMouseDown = mi => false;
|
||||
public Func<MouseInput, bool> OnMouseUp = mi => false;
|
||||
public Action<MouseInput> OnMouseMove = mi => { };
|
||||
public Func<KeyInput, bool> OnKeyPress = e => false;
|
||||
|
||||
public Func<bool> IsVisible;
|
||||
|
||||
@@ -70,7 +69,6 @@ namespace OpenRA.Widgets
|
||||
OnMouseDown = widget.OnMouseDown;
|
||||
OnMouseUp = widget.OnMouseUp;
|
||||
OnMouseMove = widget.OnMouseMove;
|
||||
OnKeyPress = widget.OnKeyPress;
|
||||
|
||||
IsVisible = widget.IsVisible;
|
||||
|
||||
@@ -252,9 +250,6 @@ namespace OpenRA.Widgets
|
||||
// Do any widgety behavior (enter text etc)
|
||||
var handled = HandleKeyPressInner(e);
|
||||
|
||||
// Apply any special logic added by event handlers; they return true if they caught the input
|
||||
if (OnKeyPress(e)) return true;
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user