From ced59fb3a065360fdd97a62b945069627748cdd7 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Sat, 28 Jan 2023 17:47:33 +0000 Subject: [PATCH] Spider: Make double-click skip the new-game animation --- Userland/Games/Spider/Game.cpp | 74 +++++++++++++++++++++------------- Userland/Games/Spider/Game.h | 12 +++--- 2 files changed, 52 insertions(+), 34 deletions(-) diff --git a/Userland/Games/Spider/Game.cpp b/Userland/Games/Spider/Game.cpp index a4bc704fa0..0c624db7bd 100644 --- a/Userland/Games/Spider/Game.cpp +++ b/Userland/Games/Spider/Game.cpp @@ -368,6 +368,50 @@ void Game::mousemove_event(GUI::MouseEvent& event) m_mouse_down_location = click_location; } +void Game::doubleclick_event(GUI::MouseEvent& event) +{ + GUI::Frame::doubleclick_event(event); + + if (m_state == State::NewGameAnimation) { + while (m_state == State::NewGameAnimation) + deal_next_card(); + return; + } +} + +void Game::deal_next_card() +{ + auto& current_pile = stack_at_location(piles.at(m_new_game_animation_pile)); + + // for first 4 piles, draw 6 cards + // for last 6 piles, draw 5 cards + size_t cards_to_draw = m_new_game_animation_pile < 4 ? 6 : 5; + + if (current_pile.count() < (cards_to_draw - 1)) { + auto card = m_new_deck.take_last(); + card->set_upside_down(true); + current_pile.push(card).release_value_but_fixme_should_propagate_errors(); + } else { + current_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors(); + ++m_new_game_animation_pile; + } + + update(current_pile.bounding_box()); + + if (m_new_game_animation_pile == piles.size()) { + VERIFY(m_new_deck.size() == 50); + + auto& stock_pile = stack_at_location(Stock); + while (!m_new_deck.is_empty()) + stock_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors(); + + update(stock_pile.bounding_box()); + + m_state = State::WaitingForNewGame; + stop_timer(); + } +} + void Game::timer_event(Core::TimerEvent&) { if (m_state == State::NewGameAnimation) { @@ -375,35 +419,7 @@ void Game::timer_event(Core::TimerEvent&) ++m_new_game_animation_delay; } else { m_new_game_animation_delay = 0; - auto& current_pile = stack_at_location(piles.at(m_new_game_animation_pile)); - - // for first 4 piles, draw 6 cards - // for last 6 piles, draw 5 cards - size_t cards_to_draw = m_new_game_animation_pile < 4 ? 6 : 5; - - if (current_pile.count() < (cards_to_draw - 1)) { - auto card = m_new_deck.take_last(); - card->set_upside_down(true); - current_pile.push(card).release_value_but_fixme_should_propagate_errors(); - } else { - current_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors(); - ++m_new_game_animation_pile; - } - - update(current_pile.bounding_box()); - - if (m_new_game_animation_pile == piles.size()) { - VERIFY(m_new_deck.size() == 50); - - auto& stock_pile = stack_at_location(Stock); - while (!m_new_deck.is_empty()) - stock_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors(); - - update(stock_pile.bounding_box()); - - m_state = State::WaitingForNewGame; - stop_timer(); - } + deal_next_card(); } } else if (m_state == State::DrawAnimation) { if (m_draw_animation_delay < draw_animation_delay) { diff --git a/Userland/Games/Spider/Game.h b/Userland/Games/Spider/Game.h index 2fc3aeaa66..cdf6d9bd61 100644 --- a/Userland/Games/Spider/Game.h +++ b/Userland/Games/Spider/Game.h @@ -92,12 +92,14 @@ private: void detect_victory(); void move_focused_cards(CardStack& stack); void clear_hovered_stack(); + void deal_next_card(); - void paint_event(GUI::PaintEvent&) override; - void mousedown_event(GUI::MouseEvent&) override; - void mouseup_event(GUI::MouseEvent&) override; - void mousemove_event(GUI::MouseEvent&) override; - void timer_event(Core::TimerEvent&) override; + virtual void paint_event(GUI::PaintEvent&) override; + virtual void mousedown_event(GUI::MouseEvent&) override; + virtual void mouseup_event(GUI::MouseEvent&) override; + virtual void mousemove_event(GUI::MouseEvent&) override; + virtual void doubleclick_event(GUI::MouseEvent&) override; + virtual void timer_event(Core::TimerEvent&) override; Mode m_mode { Mode::SingleSuit };