Add keyboard shortcut support to ButtonWidgets.

Hook up 'escape' and 'return' as appropriate for moving through menus.
This commit is contained in:
Paul Chote
2011-05-23 19:38:49 +12:00
parent 124f19f00b
commit 81515705ec
18 changed files with 44 additions and 2 deletions

View File

@@ -17,6 +17,7 @@ namespace OpenRA.Widgets
{ {
public class ButtonWidget : Widget public class ButtonWidget : Widget
{ {
public string Key = null;
public string Text = ""; public string Text = "";
public bool Depressed = false; public bool Depressed = false;
public int VisualHeight = ChromeMetrics.GetInt("ButtonDepth"); public int VisualHeight = ChromeMetrics.GetInt("ButtonDepth");
@@ -48,7 +49,16 @@ namespace OpenRA.Widgets
Depressed = false; Depressed = false;
return base.LoseFocus(mi); 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) public override bool HandleMouseInput(MouseInput mi)
{ {
if (mi.Button != MouseButton.Left) if (mi.Button != MouseButton.Left)

View File

@@ -245,7 +245,7 @@ namespace OpenRA.Widgets
return false; return false;
// Can any of our children handle this? // Can any of our children handle this?
foreach (var child in Children) foreach (var child in Children.OfType<Widget>().Reverse())
if (child.HandleKeyPressOuter(e)) if (child.HandleKeyPressOuter(e))
return true; return true;

View File

@@ -69,6 +69,7 @@ Container@CHEATS_PANEL:
Text:Show Unit Paths Text:Show Unit Paths
Button@CLOSE_BUTTON: Button@CLOSE_BUTTON:
Id:CLOSE_BUTTON Id:CLOSE_BUTTON
Key:escape
X:0 X:0
Y:109 Y:109
Width:140 Width:140

View File

@@ -28,6 +28,7 @@ Container@CONNECTING_PANEL:
Align:Center Align:Center
Button@ABORT_BUTTON: Button@ABORT_BUTTON:
Id:ABORT_BUTTON Id:ABORT_BUTTON
Key:escape
X:230 X:230
Y:89 Y:89
Width:140 Width:140
@@ -64,12 +65,14 @@ Container@CONNECTIONFAILED_PANEL:
Align:Center Align:Center
Button@RETRY_BUTTON: Button@RETRY_BUTTON:
Id:RETRY_BUTTON Id:RETRY_BUTTON
Key:return
Y:89 Y:89
Width:140 Width:140
Height:35 Height:35
Text:Retry Text:Retry
Button@ABORT_BUTTON: Button@ABORT_BUTTON:
Id:ABORT_BUTTON Id:ABORT_BUTTON
Key:escape
X:230 X:230
Y:89 Y:89
Width:140 Width:140

View File

@@ -131,6 +131,7 @@ Container@CREATESERVER_PANEL:
Text:1234 Text:1234
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
X:0 X:0
Y:259 Y:259
Width:140 Width:140
@@ -145,6 +146,7 @@ Container@CREATESERVER_PANEL:
Text:Choose Map Text:Choose Map
Button@CREATE_BUTTON: Button@CREATE_BUTTON:
Id:CREATE_BUTTON Id:CREATE_BUTTON
Key:return
X:464 X:464
Y:259 Y:259
Width:140 Width:140

View File

@@ -82,6 +82,7 @@ Container@DIPLOMACY_PANEL:
Align:Center Align:Center
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
Y:299 Y:299
Width:140 Width:140
Height:35 Height:35

View File

@@ -46,6 +46,7 @@ Container@DIRECTCONNECT_PANEL:
Height:25 Height:25
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
X:0 X:0
Y:89 Y:89
Width:140 Width:140
@@ -53,6 +54,7 @@ Container@DIRECTCONNECT_PANEL:
Text:Back Text:Back
Button@JOIN_BUTTON: Button@JOIN_BUTTON:
Id:JOIN_BUTTON Id:JOIN_BUTTON
Key:return
X:230 X:230
Y:89 Y:89
Width:140 Width:140

View File

@@ -7,6 +7,7 @@ Background@COLOR_CHOOSER:
Children: Children:
Button@SAVE_BUTTON: Button@SAVE_BUTTON:
Id:SAVE_BUTTON Id:SAVE_BUTTON
Key:return
X:210 X:210
Y:90 Y:90
Width:90 Width:90

View File

@@ -19,6 +19,7 @@ Container@INGAME_ROOT:
Y: 40 Y: 40
Button@OPTIONS_BUTTON: Button@OPTIONS_BUTTON:
Id:OPTIONS_BUTTON Id:OPTIONS_BUTTON
Key:escape
X:5 X:5
Y:5 Y:5
Width:140 Width:140

View File

@@ -73,6 +73,7 @@ Container@INGAME_MENU:
Text:Settings Text:Settings
Button@RESUME_BUTTON: Button@RESUME_BUTTON:
Id:RESUME_BUTTON Id:RESUME_BUTTON
Key:escape
X:600 X:600
Y:0 Y:0
Width:140 Width:140
@@ -107,12 +108,14 @@ Container@INGAME_MENU:
Align:Center Align:Center
Button@CANCEL_BUTTON: Button@CANCEL_BUTTON:
Id:CANCEL_BUTTON Id:CANCEL_BUTTON
Key:escape
Y:89 Y:89
Width:140 Width:140
Height:35 Height:35
Text:Cancel Text:Cancel
Button@CONFIRM_BUTTON: Button@CONFIRM_BUTTON:
Id:CONFIRM_BUTTON Id:CONFIRM_BUTTON
Key:return
X:230 X:230
Y:89 Y:89
Width:140 Width:140

View File

@@ -134,12 +134,14 @@ Container@INSTALL_FROMCD_PANEL:
Text:Waiting for CD Text:Waiting for CD
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
Y:149 Y:149
Width:140 Width:140
Height:35 Height:35
Text:Back Text:Back
Button@RETRY_BUTTON: Button@RETRY_BUTTON:
Id:RETRY_BUTTON Id:RETRY_BUTTON
Key:return
X:500 X:500
Y:149 Y:149
Width:140 Width:140
@@ -187,12 +189,14 @@ Container@INSTALL_DOWNLOAD_PANEL:
Text:Initialising... Text:Initialising...
Button@CANCEL_BUTTON: Button@CANCEL_BUTTON:
Id:CANCEL_BUTTON Id:CANCEL_BUTTON
Key:escape
Y:149 Y:149
Width:140 Width:140
Height:35 Height:35
Text:Cancel Text:Cancel
Button@RETRY_BUTTON: Button@RETRY_BUTTON:
Id:RETRY_BUTTON Id:RETRY_BUTTON
Key:return
X:500 X:500
Y:149 Y:149
Width:140 Width:140

View File

@@ -127,6 +127,7 @@ Container@MENU_BACKGROUND:
Text:Direct Connect Text:Direct Connect
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
X:600 X:600
Y:0 Y:0
Width:140 Width:140
@@ -169,6 +170,7 @@ Container@MENU_BACKGROUND:
Text:Preferences Text:Preferences
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
X:600 X:600
Y:0 Y:0
Width:140 Width:140

View File

@@ -191,6 +191,7 @@ Container@MAPCHOOSER_PANEL:
WordWrap:True WordWrap:True
Button@BUTTON_CANCEL: Button@BUTTON_CANCEL:
Id:BUTTON_CANCEL Id:BUTTON_CANCEL
Key:escape
X:0 X:0
Y:499 Y:499
Width:140 Width:140
@@ -205,6 +206,7 @@ Container@MAPCHOOSER_PANEL:
Text:Install Map Text:Install Map
Button@BUTTON_OK: Button@BUTTON_OK:
Id:BUTTON_OK Id:BUTTON_OK
Key:return
X:600 X:600
Y:499 Y:499
Width:140 Width:140

View File

@@ -80,6 +80,7 @@ Container@MODS_PANEL:
Font:Bold Font:Bold
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
X:0 X:0
Y:499 Y:499
Width:140 Width:140
@@ -87,6 +88,7 @@ Container@MODS_PANEL:
Text:Back Text:Back
Button@LOAD_BUTTON: Button@LOAD_BUTTON:
Id:LOAD_BUTTON Id:LOAD_BUTTON
Key:return
X:600 X:600
Y:499 Y:499
Width:140 Width:140

View File

@@ -186,6 +186,7 @@ Container@MUSIC_PANEL:
Text:Loop Text:Loop
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
X:0 X:0
Y:399 Y:399
Width:140 Width:140
@@ -240,6 +241,7 @@ Container@INSTALL_MUSIC_PANEL:
Text:Waiting for file Text:Waiting for file
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
Y:149 Y:149
Width:140 Width:140
Height:35 Height:35

View File

@@ -347,6 +347,7 @@ Container@SETTINGS_PANEL:
Text:Input Text:Input
Button@CANCEL_BUTTON: Button@CANCEL_BUTTON:
Id:CANCEL_BUTTON Id:CANCEL_BUTTON
Key:escape
X:450 X:450
Y:249 Y:249
Width:140 Width:140
@@ -354,6 +355,7 @@ Container@SETTINGS_PANEL:
Text:Cancel Text:Cancel
Button@SAVE_BUTTON: Button@SAVE_BUTTON:
Id:SAVE_BUTTON Id:SAVE_BUTTON
Key:return
X:600 X:600
Y:249 Y:249
Width:140 Width:140

View File

@@ -98,6 +98,7 @@ Container@REPLAYBROWSER_PANEL:
Height:20 Height:20
Button@CANCEL_BUTTON: Button@CANCEL_BUTTON:
Id:CANCEL_BUTTON Id:CANCEL_BUTTON
Key:escape
X:0 X:0
Y:299 Y:299
Width:140 Width:140
@@ -105,6 +106,7 @@ Container@REPLAYBROWSER_PANEL:
Text:Back Text:Back
Button@WATCH_BUTTON: Button@WATCH_BUTTON:
Id:WATCH_BUTTON Id:WATCH_BUTTON
Key:return
X:380 X:380
Y:299 Y:299
Width:140 Width:140

View File

@@ -193,6 +193,7 @@ Container@SERVERBROWSER_PANEL:
Height:20 Height:20
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape
X:0 X:0
Y:499 Y:499
Width:140 Width:140
@@ -207,6 +208,7 @@ Container@SERVERBROWSER_PANEL:
Text:Refresh Text:Refresh
Button@JOIN_BUTTON: Button@JOIN_BUTTON:
Id:JOIN_BUTTON Id:JOIN_BUTTON
Key:return
X:600 X:600
Y:499 Y:499
Width:140 Width:140