From 0150ae4bbdb328f9d2b447e51995bded5f66cd07 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Thu, 15 Jul 2021 16:02:42 +0100 Subject: [PATCH] Solitaire: Reduce overdraw when drawing initial cards --- Userland/Games/Solitaire/Game.cpp | 56 ++++++++++++++++--------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp index e43a9bb1e54..c85940c4244 100644 --- a/Userland/Games/Solitaire/Game.cpp +++ b/Userland/Games/Solitaire/Game.cpp @@ -61,7 +61,35 @@ void Game::timer_event(Core::TimerEvent&) if (m_animation.tick()) update(m_animation.card()->rect()); } else if (m_new_game_animation) { - update(); + if (m_new_game_animation_delay < new_game_animation_delay) { + ++m_new_game_animation_delay; + } else { + m_new_game_animation_delay = 0; + auto& current_pile = stack(piles.at(m_new_game_animation_pile)); + + if (current_pile.count() < m_new_game_animation_pile) { + auto card = m_new_deck.take_last(); + card->set_upside_down(true); + current_pile.push(card); + } else { + current_pile.push(m_new_deck.take_last()); + ++m_new_game_animation_pile; + } + + update(current_pile.bounding_box()); + + if (m_new_game_animation_pile == piles.size()) { + auto& stock_pile = stack(Stock); + while (!m_new_deck.is_empty()) + stock_pile.push(m_new_deck.take_last()); + + update(stock_pile.bounding_box()); + + m_new_game_animation = false; + m_waiting_for_new_game = true; + stop_timer(); + } + } } } @@ -523,32 +551,6 @@ void Game::paint_event(GUI::PaintEvent& event) return; } - if (m_new_game_animation) { - if (m_new_game_animation_delay < new_game_animation_delay) { - ++m_new_game_animation_delay; - } else { - m_new_game_animation_delay = 0; - auto& current_pile = stack(piles.at(m_new_game_animation_pile)); - - if (current_pile.count() < m_new_game_animation_pile) { - auto card = m_new_deck.take_last(); - card->set_upside_down(true); - current_pile.push(card); - } else { - current_pile.push(m_new_deck.take_last()); - ++m_new_game_animation_pile; - } - - if (m_new_game_animation_pile == piles.size()) { - while (!m_new_deck.is_empty()) - stack(Stock).push(m_new_deck.take_last()); - m_new_game_animation = false; - m_waiting_for_new_game = true; - stop_timer(); - } - } - } - if (!m_focused_cards.is_empty()) { for (auto& focused_card : m_focused_cards) focused_card.clear(painter, s_background_color);