summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2023-01-04 18:44:22 -0500
committerSam Atkins <atkinssj@gmail.com>2023-01-05 13:05:13 +0000
commita2277655c062de36020d441f245aca933e8c855f (patch)
treee29601ccb5ef3515b7f8f10e1b814db4c7595e1e /Userland
parent2a09807f2e26f402d929925622ed27d9967c475b (diff)
downloadserenity-a2277655c062de36020d441f245aca933e8c855f.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Games/Solitaire/Game.cpp23
-rw-r--r--Userland/Games/Solitaire/Game.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp
index 113f606726..cc9cfb5bf6 100644
--- a/Userland/Games/Solitaire/Game.cpp
+++ b/Userland/Games/Solitaire/Game.cpp
@@ -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;
+}
+
}
diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h
index 14831881b7..9e2f1e87a0 100644
--- a/Userland/Games/Solitaire/Game.h
+++ b/Userland/Games/Solitaire/Game.h
@@ -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;
};
}