From ddac8192e34d4a74104618246db8857872a80e7a Mon Sep 17 00:00:00 2001 From: Karol Baraniecki Date: Wed, 8 Mar 2023 21:57:17 +0100 Subject: [PATCH] BrickGame: Add a "Pause" option to the Game menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is how the menu looks like after this commit: ┌────┐ │Game│ Help ├────┴─────────────────────────────┐ │ New game F2 │ │ Toggle pause P │ ├──────────────────────────────────┤ │ Quit Alt+F4 │ └──────────────────────────────────┘ --- Userland/Games/BrickGame/BrickGame.cpp | 9 +++++++-- Userland/Games/BrickGame/BrickGame.h | 1 + Userland/Games/BrickGame/main.cpp | 3 +++ 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 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();