diff options
author | Thitat Auareesuksakul <thitat@fluxthitat.me> | 2021-08-27 00:49:05 +0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-06 21:39:24 +0200 |
commit | 95ff65e211bae8c57b06765b431bed7053f3c3e4 (patch) | |
tree | aba4c2731bfe6b4f6a528b0d492acb4173a6246a /Userland | |
parent | d4e425e52ee27b8cdeb689e6f6a63156f51b397e (diff) | |
download | serenity-95ff65e211bae8c57b06765b431bed7053f3c3e4.zip |
Solitaire: Add Auto-Collect gameplay option
Add the option for players to enable automatic collection of eligible
cards to their foundation pile with a single click of that card.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Games/Solitaire/Game.cpp | 3 | ||||
-rw-r--r-- | Userland/Games/Solitaire/Game.h | 5 | ||||
-rw-r--r-- | Userland/Games/Solitaire/main.cpp | 11 |
3 files changed, 19 insertions, 0 deletions
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp index eb4c30e431..d9cf5404d5 100644 --- a/Userland/Games/Solitaire/Game.cpp +++ b/Userland/Games/Solitaire/Game.cpp @@ -260,6 +260,9 @@ void Game::mousedown_event(GUI::MouseEvent& event) remember_flip_for_undo(top_card); } } else if (m_focused_cards.is_empty()) { + if (is_auto_collecting() && attempt_to_move_card_to_foundations(to_check)) + break; + to_check.add_all_grabbed_cards(click_location, m_focused_cards); m_mouse_down_location = click_location; to_check.set_focused(true); diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h index ce28cf3709..d4391e8b84 100644 --- a/Userland/Games/Solitaire/Game.h +++ b/Userland/Games/Solitaire/Game.h @@ -40,6 +40,9 @@ public: void setup(Mode); void perform_undo(); + bool is_auto_collecting() const { return m_auto_collect; } + void set_auto_collect(bool collect) { m_auto_collect = collect; } + Function<void(uint32_t)> on_score_update; Function<void()> on_game_start; Function<void(GameOverReason, uint32_t)> on_game_end; @@ -208,6 +211,8 @@ private: uint32_t m_score { 0 }; uint8_t m_passes_left_before_punishment { 0 }; + + bool m_auto_collect { false }; }; } diff --git a/Userland/Games/Solitaire/main.cpp b/Userland/Games/Solitaire/main.cpp index 54c9d82e67..5c43930fed 100644 --- a/Userland/Games/Solitaire/main.cpp +++ b/Userland/Games/Solitaire/main.cpp @@ -186,6 +186,15 @@ int main(int argc, char** argv) three_card_draw_action->set_status_tip("Draw three cards at a time"); draw_setting_actions.add_action(three_card_draw_action); + game.set_auto_collect(Config::read_bool("Solitaire", "Settings", "AutoCollect", false)); + auto toggle_auto_collect_action = GUI::Action::create_checkable("Auto-&Collect", [&](auto& action) { + auto checked = action.is_checked(); + game.set_auto_collect(checked); + Config::write_bool("Solitaire", "Settings", "AutoCollect", checked); + }); + toggle_auto_collect_action->set_checked(game.is_auto_collecting()); + toggle_auto_collect_action->set_status_tip("Auto-collect to foundation piles"); + auto& game_menu = window->add_menu("&Game"); game_menu.add_action(GUI::Action::create("&New Game", { Mod_None, Key_F2 }, [&](auto&) { @@ -201,6 +210,8 @@ int main(int argc, char** argv) game_menu.add_action(single_card_draw_action); game_menu.add_action(three_card_draw_action); game_menu.add_separator(); + game_menu.add_action(toggle_auto_collect_action); + game_menu.add_separator(); game_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); auto& help_menu = window->add_menu("&Help"); |