mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
LibCards+Games: Remove concept of a CardStack being focused
This was only used for asking the stack if it is the one we are moving cards from. We now have a better way to do that, by comparing against `CardGame::moving_cards_source_stack()`, which doesn't require manually telling a stack that it is/isn't focused.
This commit is contained in:
parent
ef8b1e25aa
commit
5186e617bd
Notes:
sideshowbarker
2024-07-17 06:05:36 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/5186e617bd Pull-request: https://github.com/SerenityOS/serenity/pull/15388
@ -257,7 +257,7 @@ void Game::mouseup_event(GUI::MouseEvent& event)
|
|||||||
// This enables the game to move the focused cards to the first possible stack excluding empty stacks.
|
// This enables the game to move the focused cards to the first possible stack excluding empty stacks.
|
||||||
// NOTE: This ignores empty stacks, as the game has no undo button, and a card, which has been moved to an empty stack without any other possibilities is not reversible.
|
// NOTE: This ignores empty stacks, as the game has no undo button, and a card, which has been moved to an empty stack without any other possibilities is not reversible.
|
||||||
for (auto& stack : stacks()) {
|
for (auto& stack : stacks()) {
|
||||||
if (stack.is_focused())
|
if (stack == moving_cards_source_stack())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (stack.is_allowed_to_push(moving_cards().at(0), moving_cards().size(), Cards::CardStack::MovementRule::Any) && !stack.is_empty()) {
|
if (stack.is_allowed_to_push(moving_cards().at(0), moving_cards().size(), Cards::CardStack::MovementRule::Any) && !stack.is_empty()) {
|
||||||
|
@ -45,10 +45,7 @@ Gfx::IntRect CardGame::moving_cards_bounds() const
|
|||||||
|
|
||||||
void CardGame::pick_up_cards_from_stack(Cards::CardStack& stack, Gfx::IntPoint click_location, CardStack::MovementRule movement_rule)
|
void CardGame::pick_up_cards_from_stack(Cards::CardStack& stack, Gfx::IntPoint click_location, CardStack::MovementRule movement_rule)
|
||||||
{
|
{
|
||||||
if (m_moving_cards_source_stack)
|
|
||||||
m_moving_cards_source_stack->set_focused(false);
|
|
||||||
stack.add_all_grabbed_cards(click_location, m_moving_cards, movement_rule);
|
stack.add_all_grabbed_cards(click_location, m_moving_cards, movement_rule);
|
||||||
stack.set_focused(true);
|
|
||||||
m_moving_cards_source_stack = stack;
|
m_moving_cards_source_stack = stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +57,7 @@ RefPtr<CardStack> CardGame::find_stack_to_drop_on(CardStack::MovementRule moveme
|
|||||||
float closest_distance = FLT_MAX;
|
float closest_distance = FLT_MAX;
|
||||||
|
|
||||||
for (auto const& stack : stacks()) {
|
for (auto const& stack : stacks()) {
|
||||||
if (stack.is_focused())
|
if (stack == moving_cards_source_stack())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (stack.bounding_box().intersects(bounds_to_check)
|
if (stack.bounding_box().intersects(bounds_to_check)
|
||||||
@ -92,8 +89,6 @@ void CardGame::drop_cards_on_stack(Cards::CardStack& stack, CardStack::MovementR
|
|||||||
|
|
||||||
void CardGame::clear_moving_cards()
|
void CardGame::clear_moving_cards()
|
||||||
{
|
{
|
||||||
if (!m_moving_cards_source_stack.is_null())
|
|
||||||
m_moving_cards_source_stack->set_focused(false);
|
|
||||||
m_moving_cards_source_stack.clear();
|
m_moving_cards_source_stack.clear();
|
||||||
m_moving_cards.clear();
|
m_moving_cards.clear();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,6 @@ public:
|
|||||||
CardStack(Gfx::IntPoint const& position, Type type, RefPtr<CardStack> covered_stack = nullptr);
|
CardStack(Gfx::IntPoint const& position, Type type, RefPtr<CardStack> covered_stack = nullptr);
|
||||||
|
|
||||||
bool is_empty() const { return m_stack.is_empty(); }
|
bool is_empty() const { return m_stack.is_empty(); }
|
||||||
bool is_focused() const { return m_focused; }
|
|
||||||
Type type() const { return m_type; }
|
Type type() const { return m_type; }
|
||||||
NonnullRefPtrVector<Card> const& stack() const { return m_stack; }
|
NonnullRefPtrVector<Card> const& stack() const { return m_stack; }
|
||||||
size_t count() const { return m_stack.size(); }
|
size_t count() const { return m_stack.size(); }
|
||||||
@ -42,7 +41,6 @@ public:
|
|||||||
Card& peek() { return m_stack.last(); }
|
Card& peek() { return m_stack.last(); }
|
||||||
Gfx::IntRect const& bounding_box() const { return m_bounding_box; }
|
Gfx::IntRect const& bounding_box() const { return m_bounding_box; }
|
||||||
|
|
||||||
void set_focused(bool focused) { m_focused = focused; }
|
|
||||||
bool make_top_card_visible(); // Returns true if the card was flipped.
|
bool make_top_card_visible(); // Returns true if the card was flipped.
|
||||||
|
|
||||||
void push(NonnullRefPtr<Card> card);
|
void push(NonnullRefPtr<Card> card);
|
||||||
@ -93,7 +91,6 @@ private:
|
|||||||
Gfx::IntRect m_bounding_box;
|
Gfx::IntRect m_bounding_box;
|
||||||
Type m_type { Type::Invalid };
|
Type m_type { Type::Invalid };
|
||||||
StackRules m_rules;
|
StackRules m_rules;
|
||||||
bool m_focused { false };
|
|
||||||
Gfx::IntRect m_base;
|
Gfx::IntRect m_base;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user