From d974d14d1e0fb59066207e32c8fe780b32c6ddfd Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sat, 17 Dec 2022 14:24:51 +0530 Subject: [PATCH] accelerator keys --- src/gui/EndGameGui.hx | 1 + src/gui/ExitGameDlg.hx | 2 ++ src/gui/GuiButton.hx | 7 +++++++ src/gui/HelpCreditsGui.hx | 1 + src/gui/MessageBoxOkDlg.hx | 1 + src/gui/MessageBoxYesNoDlg.hx | 2 ++ 6 files changed, 14 insertions(+) diff --git a/src/gui/EndGameGui.hx b/src/gui/EndGameGui.hx index c9d5c9bb..db2aeb82 100644 --- a/src/gui/EndGameGui.hx +++ b/src/gui/EndGameGui.hx @@ -42,6 +42,7 @@ class EndGameGui extends GuiControl { continueButton.vertSizing = Bottom; continueButton.position = new Vector(333, 386); continueButton.extent = new Vector(113, 47); + continueButton.accelerator = hxd.Key.ENTER; continueButton.pressedAction = continueFunc; var restartButton = new GuiButton(loadButtonImages("data/ui/endgame/replay")); diff --git a/src/gui/ExitGameDlg.hx b/src/gui/ExitGameDlg.hx index f8952ac4..bd9393e3 100644 --- a/src/gui/ExitGameDlg.hx +++ b/src/gui/ExitGameDlg.hx @@ -47,12 +47,14 @@ class ExitGameDlg extends GuiControl { yesButton.vertSizing = Bottom; yesButton.horizSizing = Right; yesButton.pressedAction = yesFunc; + yesButton.accelerator = hxd.Key.ENTER; var noButton = new GuiButton(loadButtonImages("data/ui/common/no")); noButton.position = new Vector(151, 107); noButton.extent = new Vector(83, 55); noButton.vertSizing = Bottom; noButton.horizSizing = Right; + noButton.accelerator = hxd.Key.ESCAPE; noButton.pressedAction = noFunc; var restartButton = new GuiButton(loadButtonImages("data/ui/common/restart")); diff --git a/src/gui/GuiButton.hx b/src/gui/GuiButton.hx index c656d0be..8732eb74 100644 --- a/src/gui/GuiButton.hx +++ b/src/gui/GuiButton.hx @@ -27,6 +27,8 @@ class GuiButton extends GuiAnim { public var buttonSounds:Bool = true; + public var accelerator:Int = 0; + public function new(anim:Array) { super(anim); } @@ -67,6 +69,11 @@ class GuiButton extends GuiAnim { } } } + if (!disabled && accelerator != 0 && hxd.Key.isReleased(accelerator)) { + if (this.pressedAction != null) { + this.pressedAction(new GuiEvent(this)); + } + } super.update(dt, mouseState); } diff --git a/src/gui/HelpCreditsGui.hx b/src/gui/HelpCreditsGui.hx index 26a08b2a..a408f252 100644 --- a/src/gui/HelpCreditsGui.hx +++ b/src/gui/HelpCreditsGui.hx @@ -70,6 +70,7 @@ class HelpCreditsGui extends GuiImage { var homeButton = new GuiButton(loadButtonImages("data/ui/play/back")); homeButton.position = new Vector(278, 378); homeButton.extent = new Vector(79, 61); + homeButton.accelerator = hxd.Key.ESCAPE; homeButton.pressedAction = (sender) -> { MarbleGame.canvas.setContent(new MainMenuGui()); } diff --git a/src/gui/MessageBoxOkDlg.hx b/src/gui/MessageBoxOkDlg.hx index 6689b838..37164050 100644 --- a/src/gui/MessageBoxOkDlg.hx +++ b/src/gui/MessageBoxOkDlg.hx @@ -46,6 +46,7 @@ class MessageBoxOkDlg extends GuiControl { okButton.position = new Vector(117, 85); okButton.extent = new Vector(78, 59); okButton.vertSizing = Top; + okButton.accelerator = hxd.Key.ENTER; okButton.pressedAction = (sender) -> { MarbleGame.canvas.popDialog(this); } diff --git a/src/gui/MessageBoxYesNoDlg.hx b/src/gui/MessageBoxYesNoDlg.hx index 73bbc958..d5a19e84 100644 --- a/src/gui/MessageBoxYesNoDlg.hx +++ b/src/gui/MessageBoxYesNoDlg.hx @@ -46,6 +46,7 @@ class MessageBoxYesNoDlg extends GuiControl { yesButton.position = new Vector(44, 94); yesButton.extent = new Vector(82, 47); yesButton.vertSizing = Top; + yesButton.accelerator = hxd.Key.ENTER; yesButton.pressedAction = (sender) -> { MarbleGame.canvas.popDialog(this); yesFunc(); @@ -56,6 +57,7 @@ class MessageBoxYesNoDlg extends GuiControl { noButton.position = new Vector(151, 94); noButton.extent = new Vector(75, 47); noButton.vertSizing = Top; + noButton.accelerator = hxd.Key.ESCAPE; noButton.pressedAction = (sender) -> { MarbleGame.canvas.popDialog(this); noFunc();