diff --git a/Userland/Games/Spider/Game.cpp b/Userland/Games/Spider/Game.cpp index 6473b31c7b..ad246b9f9c 100644 --- a/Userland/Games/Spider/Game.cpp +++ b/Userland/Games/Spider/Game.cpp @@ -299,6 +299,7 @@ void Game::move_focused_cards(CardStack& stack) void Game::mouseup_event(GUI::MouseEvent& event) { GUI::Frame::mouseup_event(event); + clear_hovered_stack(); if (!is_moving_cards() || m_new_game_animation || m_draw_animation) return; @@ -346,6 +347,18 @@ void Game::mousemove_event(GUI::MouseEvent& event) int dx = click_location.dx_relative_to(m_mouse_down_location); int dy = click_location.dy_relative_to(m_mouse_down_location); + if (auto target_stack = find_stack_to_drop_on(Cards::CardStack::MovementRule::Any)) { + if (target_stack != m_hovered_stack) { + clear_hovered_stack(); + + m_hovered_stack = move(target_stack); + m_hovered_stack->set_highlighted(true); + update(m_hovered_stack->bounding_box()); + } + } else { + clear_hovered_stack(); + } + for (auto& to_intersect : moving_cards()) { mark_intersecting_stacks_dirty(to_intersect); to_intersect.rect().translate_by(dx, dy); @@ -417,4 +430,15 @@ void Game::timer_event(Core::TimerEvent&) } } } + +void Game::clear_hovered_stack() +{ + if (!m_hovered_stack) + return; + + m_hovered_stack->set_highlighted(false); + update(m_hovered_stack->bounding_box()); + m_hovered_stack = nullptr; +} + } diff --git a/Userland/Games/Spider/Game.h b/Userland/Games/Spider/Game.h index b89c2d508e..50f84c7892 100644 --- a/Userland/Games/Spider/Game.h +++ b/Userland/Games/Spider/Game.h @@ -91,6 +91,7 @@ private: void detect_full_stacks(); void detect_victory(); void move_focused_cards(CardStack& stack); + void clear_hovered_stack(); void paint_event(GUI::PaintEvent&) override; void mousedown_event(GUI::MouseEvent&) override; @@ -117,6 +118,8 @@ private: Gfx::IntRect m_original_stock_rect; uint32_t m_score { 500 }; + + RefPtr m_hovered_stack; }; }