Add keyboard shortcut support to ButtonWidgets.
Hook up 'escape' and 'return' as appropriate for moving through menus.
This commit is contained in:
@@ -17,6 +17,7 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
public class ButtonWidget : Widget
|
||||
{
|
||||
public string Key = null;
|
||||
public string Text = "";
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = ChromeMetrics.GetInt("ButtonDepth");
|
||||
@@ -49,6 +50,15 @@ namespace OpenRA.Widgets
|
||||
return base.LoseFocus(mi);
|
||||
}
|
||||
|
||||
public override bool HandleKeyPressInner(KeyInput e)
|
||||
{
|
||||
if (e.KeyName != Key || e.Modifiers != Modifiers.None || e.Event != KeyInputEvent.Down)
|
||||
return false;
|
||||
|
||||
OnClick();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool HandleMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Button != MouseButton.Left)
|
||||
|
||||
@@ -245,7 +245,7 @@ namespace OpenRA.Widgets
|
||||
return false;
|
||||
|
||||
// Can any of our children handle this?
|
||||
foreach (var child in Children)
|
||||
foreach (var child in Children.OfType<Widget>().Reverse())
|
||||
if (child.HandleKeyPressOuter(e))
|
||||
return true;
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ Container@CHEATS_PANEL:
|
||||
Text:Show Unit Paths
|
||||
Button@CLOSE_BUTTON:
|
||||
Id:CLOSE_BUTTON
|
||||
Key:escape
|
||||
X:0
|
||||
Y:109
|
||||
Width:140
|
||||
|
||||
@@ -28,6 +28,7 @@ Container@CONNECTING_PANEL:
|
||||
Align:Center
|
||||
Button@ABORT_BUTTON:
|
||||
Id:ABORT_BUTTON
|
||||
Key:escape
|
||||
X:230
|
||||
Y:89
|
||||
Width:140
|
||||
@@ -64,12 +65,14 @@ Container@CONNECTIONFAILED_PANEL:
|
||||
Align:Center
|
||||
Button@RETRY_BUTTON:
|
||||
Id:RETRY_BUTTON
|
||||
Key:return
|
||||
Y:89
|
||||
Width:140
|
||||
Height:35
|
||||
Text:Retry
|
||||
Button@ABORT_BUTTON:
|
||||
Id:ABORT_BUTTON
|
||||
Key:escape
|
||||
X:230
|
||||
Y:89
|
||||
Width:140
|
||||
|
||||
@@ -131,6 +131,7 @@ Container@CREATESERVER_PANEL:
|
||||
Text:1234
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
X:0
|
||||
Y:259
|
||||
Width:140
|
||||
@@ -145,6 +146,7 @@ Container@CREATESERVER_PANEL:
|
||||
Text:Choose Map
|
||||
Button@CREATE_BUTTON:
|
||||
Id:CREATE_BUTTON
|
||||
Key:return
|
||||
X:464
|
||||
Y:259
|
||||
Width:140
|
||||
|
||||
@@ -82,6 +82,7 @@ Container@DIPLOMACY_PANEL:
|
||||
Align:Center
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
Y:299
|
||||
Width:140
|
||||
Height:35
|
||||
|
||||
@@ -46,6 +46,7 @@ Container@DIRECTCONNECT_PANEL:
|
||||
Height:25
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
X:0
|
||||
Y:89
|
||||
Width:140
|
||||
@@ -53,6 +54,7 @@ Container@DIRECTCONNECT_PANEL:
|
||||
Text:Back
|
||||
Button@JOIN_BUTTON:
|
||||
Id:JOIN_BUTTON
|
||||
Key:return
|
||||
X:230
|
||||
Y:89
|
||||
Width:140
|
||||
|
||||
@@ -7,6 +7,7 @@ Background@COLOR_CHOOSER:
|
||||
Children:
|
||||
Button@SAVE_BUTTON:
|
||||
Id:SAVE_BUTTON
|
||||
Key:return
|
||||
X:210
|
||||
Y:90
|
||||
Width:90
|
||||
|
||||
@@ -19,6 +19,7 @@ Container@INGAME_ROOT:
|
||||
Y: 40
|
||||
Button@OPTIONS_BUTTON:
|
||||
Id:OPTIONS_BUTTON
|
||||
Key:escape
|
||||
X:5
|
||||
Y:5
|
||||
Width:140
|
||||
|
||||
@@ -73,6 +73,7 @@ Container@INGAME_MENU:
|
||||
Text:Settings
|
||||
Button@RESUME_BUTTON:
|
||||
Id:RESUME_BUTTON
|
||||
Key:escape
|
||||
X:600
|
||||
Y:0
|
||||
Width:140
|
||||
@@ -107,12 +108,14 @@ Container@INGAME_MENU:
|
||||
Align:Center
|
||||
Button@CANCEL_BUTTON:
|
||||
Id:CANCEL_BUTTON
|
||||
Key:escape
|
||||
Y:89
|
||||
Width:140
|
||||
Height:35
|
||||
Text:Cancel
|
||||
Button@CONFIRM_BUTTON:
|
||||
Id:CONFIRM_BUTTON
|
||||
Key:return
|
||||
X:230
|
||||
Y:89
|
||||
Width:140
|
||||
|
||||
@@ -134,12 +134,14 @@ Container@INSTALL_FROMCD_PANEL:
|
||||
Text:Waiting for CD
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
Y:149
|
||||
Width:140
|
||||
Height:35
|
||||
Text:Back
|
||||
Button@RETRY_BUTTON:
|
||||
Id:RETRY_BUTTON
|
||||
Key:return
|
||||
X:500
|
||||
Y:149
|
||||
Width:140
|
||||
@@ -187,12 +189,14 @@ Container@INSTALL_DOWNLOAD_PANEL:
|
||||
Text:Initialising...
|
||||
Button@CANCEL_BUTTON:
|
||||
Id:CANCEL_BUTTON
|
||||
Key:escape
|
||||
Y:149
|
||||
Width:140
|
||||
Height:35
|
||||
Text:Cancel
|
||||
Button@RETRY_BUTTON:
|
||||
Id:RETRY_BUTTON
|
||||
Key:return
|
||||
X:500
|
||||
Y:149
|
||||
Width:140
|
||||
|
||||
@@ -127,6 +127,7 @@ Container@MENU_BACKGROUND:
|
||||
Text:Direct Connect
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
X:600
|
||||
Y:0
|
||||
Width:140
|
||||
@@ -169,6 +170,7 @@ Container@MENU_BACKGROUND:
|
||||
Text:Preferences
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
X:600
|
||||
Y:0
|
||||
Width:140
|
||||
|
||||
@@ -191,6 +191,7 @@ Container@MAPCHOOSER_PANEL:
|
||||
WordWrap:True
|
||||
Button@BUTTON_CANCEL:
|
||||
Id:BUTTON_CANCEL
|
||||
Key:escape
|
||||
X:0
|
||||
Y:499
|
||||
Width:140
|
||||
@@ -205,6 +206,7 @@ Container@MAPCHOOSER_PANEL:
|
||||
Text:Install Map
|
||||
Button@BUTTON_OK:
|
||||
Id:BUTTON_OK
|
||||
Key:return
|
||||
X:600
|
||||
Y:499
|
||||
Width:140
|
||||
|
||||
@@ -80,6 +80,7 @@ Container@MODS_PANEL:
|
||||
Font:Bold
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
X:0
|
||||
Y:499
|
||||
Width:140
|
||||
@@ -87,6 +88,7 @@ Container@MODS_PANEL:
|
||||
Text:Back
|
||||
Button@LOAD_BUTTON:
|
||||
Id:LOAD_BUTTON
|
||||
Key:return
|
||||
X:600
|
||||
Y:499
|
||||
Width:140
|
||||
|
||||
@@ -186,6 +186,7 @@ Container@MUSIC_PANEL:
|
||||
Text:Loop
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
X:0
|
||||
Y:399
|
||||
Width:140
|
||||
@@ -240,6 +241,7 @@ Container@INSTALL_MUSIC_PANEL:
|
||||
Text:Waiting for file
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
Y:149
|
||||
Width:140
|
||||
Height:35
|
||||
|
||||
@@ -347,6 +347,7 @@ Container@SETTINGS_PANEL:
|
||||
Text:Input
|
||||
Button@CANCEL_BUTTON:
|
||||
Id:CANCEL_BUTTON
|
||||
Key:escape
|
||||
X:450
|
||||
Y:249
|
||||
Width:140
|
||||
@@ -354,6 +355,7 @@ Container@SETTINGS_PANEL:
|
||||
Text:Cancel
|
||||
Button@SAVE_BUTTON:
|
||||
Id:SAVE_BUTTON
|
||||
Key:return
|
||||
X:600
|
||||
Y:249
|
||||
Width:140
|
||||
|
||||
@@ -98,6 +98,7 @@ Container@REPLAYBROWSER_PANEL:
|
||||
Height:20
|
||||
Button@CANCEL_BUTTON:
|
||||
Id:CANCEL_BUTTON
|
||||
Key:escape
|
||||
X:0
|
||||
Y:299
|
||||
Width:140
|
||||
@@ -105,6 +106,7 @@ Container@REPLAYBROWSER_PANEL:
|
||||
Text:Back
|
||||
Button@WATCH_BUTTON:
|
||||
Id:WATCH_BUTTON
|
||||
Key:return
|
||||
X:380
|
||||
Y:299
|
||||
Width:140
|
||||
|
||||
@@ -193,6 +193,7 @@ Container@SERVERBROWSER_PANEL:
|
||||
Height:20
|
||||
Button@BACK_BUTTON:
|
||||
Id:BACK_BUTTON
|
||||
Key:escape
|
||||
X:0
|
||||
Y:499
|
||||
Width:140
|
||||
@@ -207,6 +208,7 @@ Container@SERVERBROWSER_PANEL:
|
||||
Text:Refresh
|
||||
Button@JOIN_BUTTON:
|
||||
Id:JOIN_BUTTON
|
||||
Key:return
|
||||
X:600
|
||||
Y:499
|
||||
Width:140
|
||||
|
||||
Reference in New Issue
Block a user