diff options
author | Karol Baraniecki <karol@baraniecki.eu> | 2023-03-08 21:57:17 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2023-03-13 06:43:59 +0000 |
commit | ddac8192e34d4a74104618246db8857872a80e7a (patch) | |
tree | 5b3f648c11920a9a56fa62a9016b9b7b4bce13b3 /Userland/Games | |
parent | a3375576588b5c2fbb55788175c87fd2daed3930 (diff) | |
download | serenity-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.cpp | 9 | ||||
-rw-r--r-- | Userland/Games/BrickGame/BrickGame.h | 1 | ||||
-rw-r--r-- | 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<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(); |