mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:57:35 +00:00
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 │ └──────────────────────────────────┘
This commit is contained in:
parent
a337557658
commit
ddac8192e3
3 changed files with 11 additions and 2 deletions
|
@ -446,6 +446,12 @@ void BrickGame::reset()
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BrickGame::toggle_pause()
|
||||||
|
{
|
||||||
|
m_brick_game->toggle_pause();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void BrickGame::timer_event(Core::TimerEvent&)
|
void BrickGame::timer_event(Core::TimerEvent&)
|
||||||
{
|
{
|
||||||
switch (m_brick_game->state()) {
|
switch (m_brick_game->state()) {
|
||||||
|
@ -466,8 +472,7 @@ void BrickGame::keydown_event(GUI::KeyEvent& event)
|
||||||
switch (event.key()) {
|
switch (event.key()) {
|
||||||
case KeyCode::Key_Escape:
|
case KeyCode::Key_Escape:
|
||||||
case KeyCode::Key_P:
|
case KeyCode::Key_P:
|
||||||
m_brick_game->toggle_pause();
|
toggle_pause();
|
||||||
update();
|
|
||||||
return;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -18,6 +18,7 @@ public:
|
||||||
virtual ~BrickGame() override = default;
|
virtual ~BrickGame() override = default;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
void toggle_pause();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BrickGame(StringView app_name);
|
BrickGame(StringView app_name);
|
||||||
|
|
|
@ -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&) {
|
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();
|
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_separator());
|
||||||
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
TRY(game_menu->try_add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
||||||
GUI::Application::the()->quit();
|
GUI::Application::the()->quit();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue