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:
Sam Atkins 2022-09-28 17:47:19 +01:00 committed by Sam Atkins
parent ef8b1e25aa
commit 5186e617bd
Notes: sideshowbarker 2024-07-17 06:05:36 +09:00
3 changed files with 2 additions and 10 deletions

View File

@ -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.
// 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()) {
if (stack.is_focused())
if (stack == moving_cards_source_stack())
continue;
if (stack.is_allowed_to_push(moving_cards().at(0), moving_cards().size(), Cards::CardStack::MovementRule::Any) && !stack.is_empty()) {

View File

@ -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)
{
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.set_focused(true);
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;
for (auto const& stack : stacks()) {
if (stack.is_focused())
if (stack == moving_cards_source_stack())
continue;
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()
{
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.clear();
}

View File

@ -34,7 +34,6 @@ public:
CardStack(Gfx::IntPoint const& position, Type type, RefPtr<CardStack> covered_stack = nullptr);
bool is_empty() const { return m_stack.is_empty(); }
bool is_focused() const { return m_focused; }
Type type() const { return m_type; }
NonnullRefPtrVector<Card> const& stack() const { return m_stack; }
size_t count() const { return m_stack.size(); }
@ -42,7 +41,6 @@ public:
Card& peek() { return m_stack.last(); }
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.
void push(NonnullRefPtr<Card> card);
@ -93,7 +91,6 @@ private:
Gfx::IntRect m_bounding_box;
Type m_type { Type::Invalid };
StackRules m_rules;
bool m_focused { false };
Gfx::IntRect m_base;
};