1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

Snake: Remember if game was paused when picking color

If we were paused before, don't start the game after closing the dialog.
This commit is contained in:
Sam Atkins 2023-03-16 11:00:00 +00:00 committed by Andreas Kling
parent 4f496e97fe
commit 3ce87ea5f9
2 changed files with 6 additions and 1 deletions

View file

@ -20,6 +20,7 @@ public:
virtual ~Game() override = default; virtual ~Game() override = default;
bool is_paused() const { return !has_timer(); }
void start(); void start();
void pause(); void pause();
void reset(); void reset();

View file

@ -94,10 +94,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}))); })));
TRY(game_menu->try_add_action(GUI::Action::create("&Change snake color", TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/color-chooser.png"sv)), [&](auto&) { TRY(game_menu->try_add_action(GUI::Action::create("&Change snake color", TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/color-chooser.png"sv)), [&](auto&) {
game.pause(); game.pause();
auto was_paused = game.is_paused();
if (!was_paused)
game.pause();
auto dialog = GUI::ColorPicker::construct(Gfx::Color::White, window); auto dialog = GUI::ColorPicker::construct(Gfx::Color::White, window);
if (dialog->exec() == GUI::Dialog::ExecResult::OK) if (dialog->exec() == GUI::Dialog::ExecResult::OK)
game.set_snake_base_color(dialog->color()); game.set_snake_base_color(dialog->color());
game.start(); if (!was_paused)
game.start();
}))); })));
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&) {