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;
bool is_paused() const { return !has_timer(); }
void start();
void pause();
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&) {
game.pause();
auto was_paused = game.is_paused();
if (!was_paused)
game.pause();
auto dialog = GUI::ColorPicker::construct(Gfx::Color::White, window);
if (dialog->exec() == GUI::Dialog::ExecResult::OK)
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_action(GUI::CommonActions::make_quit_action([](auto&) {