From 431c4165b50f5f456d0fc07d48abb3f2946a308d Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 13 Jan 2023 14:15:25 +0000 Subject: [PATCH] Spider: Confirm ending the current game in more situations As for Solitaire, we previously had a warning when trying to exit Spider 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 suits. When changing the number of suits, we do apply the setting, so it will take effect for the next game that is started. --- Userland/Games/Spider/main.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/Userland/Games/Spider/main.cpp b/Userland/Games/Spider/main.cpp index 65b2603202..1ec566e70e 100644 --- a/Userland/Games/Spider/main.cpp +++ b/Userland/Games/Spider/main.cpp @@ -195,22 +195,25 @@ ErrorOr 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? Doing so will count as a loss."sv, + "A game is still in progress, are you sure you would like to end it? Doing so will count as a loss."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; }; window->on_close = [&]() { game.on_game_end(Spider::GameOverReason::Quit, 0); @@ -221,6 +224,10 @@ ErrorOr serenity_main(Main::Arguments arguments) auto single_suit_action = GUI::Action::create_checkable("&Single Suit", [&](auto&) { update_mode(Spider::Mode::SingleSuit); + + if (!confirm_end_current_game()) + return; + reset_statistic_status(); game.setup(mode); }); @@ -229,6 +236,10 @@ ErrorOr serenity_main(Main::Arguments arguments) auto two_suit_action = GUI::Action::create_checkable("&Two Suit", [&](auto&) { update_mode(Spider::Mode::TwoSuit); + + if (!confirm_end_current_game()) + return; + reset_statistic_status(); game.setup(mode); }); @@ -237,6 +248,9 @@ ErrorOr 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());