mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:07:34 +00:00
Solitaire: Highlight cards beneath dragged cards that are valid targets
If the card beneath the card currently being dragged is a valid drop target, we will highlight it to indicate this to the user.
This commit is contained in:
parent
2a09807f2e
commit
a2277655c0
2 changed files with 26 additions and 0 deletions
|
@ -272,6 +272,7 @@ void Game::mousedown_event(GUI::MouseEvent& event)
|
|||
void Game::mouseup_event(GUI::MouseEvent& event)
|
||||
{
|
||||
GUI::Frame::mouseup_event(event);
|
||||
clear_hovered_card();
|
||||
|
||||
if (!is_moving_cards() || m_game_over_animation || m_new_game_animation)
|
||||
return;
|
||||
|
@ -312,6 +313,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::Alternating); target_stack && !target_stack->is_empty()) {
|
||||
if (auto& top_card = target_stack->peek(); top_card != m_hovered_card) {
|
||||
clear_hovered_card();
|
||||
m_hovered_card = top_card;
|
||||
|
||||
m_hovered_card->set_highlighted(true);
|
||||
update(m_hovered_card->rect());
|
||||
}
|
||||
} else {
|
||||
clear_hovered_card();
|
||||
}
|
||||
|
||||
for (auto& to_intersect : moving_cards()) {
|
||||
mark_intersecting_stacks_dirty(to_intersect);
|
||||
to_intersect.rect().translate_by(dx, dy);
|
||||
|
@ -619,4 +632,14 @@ void Game::perform_undo()
|
|||
invalidate_layout();
|
||||
}
|
||||
|
||||
void Game::clear_hovered_card()
|
||||
{
|
||||
if (!m_hovered_card)
|
||||
return;
|
||||
|
||||
m_hovered_card->set_highlighted(false);
|
||||
update(m_hovered_card->rect());
|
||||
m_hovered_card = nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -174,6 +174,7 @@ private:
|
|||
void create_new_animation_card();
|
||||
void set_background_fill_enabled(bool);
|
||||
void check_for_game_over();
|
||||
void clear_hovered_card();
|
||||
|
||||
virtual void paint_event(GUI::PaintEvent&) override;
|
||||
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||
|
@ -203,6 +204,8 @@ private:
|
|||
uint8_t m_passes_left_before_punishment { 0 };
|
||||
|
||||
bool m_auto_collect { false };
|
||||
|
||||
RefPtr<Card> m_hovered_card;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue