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

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.
This commit is contained in:
Sam Atkins 2023-01-13 14:15:25 +00:00 committed by Tim Flynn
parent 8b59517ff2
commit 431c4165b5

View file

@ -195,22 +195,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? 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<int> 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<int> 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<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());