mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 01:08:11 +00:00
Spider: Highlight valid target stack when hovering over it
This is largely copied and pasted from Solitaire. Moving this into LibCards somehow would be nice but I can't think of a nice way to do so right now.
This commit is contained in:
parent
e193679352
commit
80c7ac0d0e
2 changed files with 27 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<CardStack> m_hovered_stack;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue