summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2023-01-13 14:14:11 +0000
committerTim Flynn <trflynn89@pm.me>2023-01-15 11:59:59 -0500
commit8b59517ff29029588547b4cdd8cd43fb76382c44 (patch)
tree65f99b653a42d1926d5dc53d202e44b31e8d071e /Userland
parentc0ada49a24531ca8a165284ffaae05f49ad62c19 (diff)
downloadserenity-8b59517ff29029588547b4cdd8cd43fb76382c44.zip
Solitaire: Confirm ending the current game in more situations
We previously had a warning when trying to exit Solitaire while a game was in progress. This adds the same functionality to other actions that would end the current game: Starting a new one, or changing the number of cards drawn. When changing the number of cards drawn, we do apply the setting, so it will take effect for the next game that is started.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Games/Solitaire/main.cpp28
1 files changed, 21 insertions, 7 deletions
diff --git a/Userland/Games/Solitaire/main.cpp b/Userland/Games/Solitaire/main.cpp
index d56a978870..6d7500b053 100644
--- a/Userland/Games/Solitaire/main.cpp
+++ b/Userland/Games/Solitaire/main.cpp
@@ -145,22 +145,25 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
statusbar.set_text(2, "Timer starts after your first move");
};
- window->on_close_request = [&]() {
+ auto confirm_end_current_game = [&]() {
auto game_in_progress = timer->is_active();
if (game_in_progress) {
auto result = GUI::MessageBox::show(window,
- "A game is still in progress, are you sure you would like to quit?"sv,
+ "A game is still in progress, are you sure you would like to end it?"sv,
"Game in progress"sv,
GUI::MessageBox::Type::Warning,
GUI::MessageBox::InputType::YesNo);
- if (result == GUI::MessageBox::ExecResult::Yes)
- return GUI::Window::CloseRequestDecision::Close;
- else
- return GUI::Window::CloseRequestDecision::StayOpen;
+ return result == GUI::MessageBox::ExecResult::Yes;
}
- return GUI::Window::CloseRequestDecision::Close;
+ return true;
+ };
+
+ window->on_close_request = [&]() {
+ if (confirm_end_current_game())
+ return GUI::Window::CloseRequestDecision::Close;
+ return GUI::Window::CloseRequestDecision::StayOpen;
};
GUI::ActionGroup draw_setting_actions;
@@ -168,6 +171,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto single_card_draw_action = GUI::Action::create_checkable("&Single Card Draw", [&](auto&) {
update_mode(Solitaire::Mode::SingleCardDraw);
+
+ if (!confirm_end_current_game())
+ return;
+
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", high_score()));
game.setup(mode);
});
@@ -177,6 +184,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto three_card_draw_action = GUI::Action::create_checkable("&Three Card Draw", [&](auto&) {
update_mode(Solitaire::Mode::ThreeCardDraw);
+
+ if (!confirm_end_current_game())
+ return;
+
statusbar.set_text(1, DeprecatedString::formatted("High Score: {}", high_score()));
game.setup(mode);
});
@@ -196,6 +207,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
auto game_menu = TRY(window->try_add_menu("&Game"));
TRY(game_menu->try_add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/reload.png"sv)), [&](auto&) {
+ if (!confirm_end_current_game())
+ return;
+
game.setup(mode);
})));
TRY(game_menu->try_add_separator());