summaryrefslogtreecommitdiff
path: root/Userland/Games
diff options
context:
space:
mode:
authorKarol Baraniecki <karol@baraniecki.eu>2023-03-08 21:57:17 +0100
committerBrian Gianforcaro <b.gianfo@gmail.com>2023-03-13 06:43:59 +0000
commitddac8192e34d4a74104618246db8857872a80e7a (patch)
tree5b3f648c11920a9a56fa62a9016b9b7b4bce13b3 /Userland/Games
parenta3375576588b5c2fbb55788175c87fd2daed3930 (diff)
downloadserenity-ddac8192e34d4a74104618246db8857872a80e7a.zip
BrickGame: Add a "Pause" option to the Game menu
This is how the menu looks like after this commit: β”Œβ”€β”€β”€β”€β” β”‚Gameβ”‚ Help β”œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ New game F2 β”‚ β”‚ Toggle pause P β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ Quit Alt+F4 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Diffstat (limited to 'Userland/Games')
-rw-r--r--Userland/Games/BrickGame/BrickGame.cpp9
-rw-r--r--Userland/Games/BrickGame/BrickGame.h1
-rw-r--r--Userland/Games/BrickGame/main.cpp3
3 files changed, 11 insertions, 2 deletions
diff --git a/Userland/Games/BrickGame/BrickGame.cpp b/Userland/Games/BrickGame/BrickGame.cpp
index 1bf2faa8ac..c951b9d881 100644
--- a/Userland/Games/BrickGame/BrickGame.cpp
+++ b/Userland/Games/BrickGame/BrickGame.cpp
@@ -446,6 +446,12 @@ void BrickGame::reset()
update();
}
+void BrickGame::toggle_pause()
+{
+ m_brick_game->toggle_pause();
+ update();
+}
+
void BrickGame::timer_event(Core::TimerEvent&)
{
switch (m_brick_game->state()) {
@@ -466,8 +472,7 @@ void BrickGame::keydown_event(GUI::KeyEvent& event)
switch (event.key()) {
case KeyCode::Key_Escape:
case KeyCode::Key_P:
- m_brick_game->toggle_pause();
- update();
+ toggle_pause();
return;
default:
break;
diff --git a/Userland/Games/BrickGame/BrickGame.h b/Userland/Games/BrickGame/BrickGame.h
index 0a60d3eae3..6e9c30cf28 100644
--- a/Userland/Games/BrickGame/BrickGame.h
+++ b/Userland/Games/BrickGame/BrickGame.h
@@ -18,6 +18,7 @@ public:
virtual ~BrickGame() override = default;
void reset();
+ void toggle_pause();
private:
BrickGame(StringView app_name);
diff --git a/Userland/Games/BrickGame/main.cpp b/Userland/Games/BrickGame/main.cpp
index 3c81af6de0..bd14504bc8 100644
--- a/Userland/Games/BrickGame/main.cpp
+++ b/Userland/Games/BrickGame/main.cpp
@@ -56,6 +56,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
game->reset();
})));
+ TRY(game_menu->try_add_action(GUI::Action::create("Toggle &pause", { Mod_None, Key_P }, [&](auto&) {
+ game->toggle_pause();
+ })));
TRY(game_menu->try_add_separator());
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();