mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-13 05:20:00 -08:00
[Refactor] Give graphics zones a card item cache and own card placement
This commit is contained in:
parent
8347258075
commit
cea80b0898
18 changed files with 111 additions and 74 deletions
|
|
@ -5,9 +5,9 @@ namespace CardZoneAlgorithms
|
|||
{
|
||||
|
||||
/**
|
||||
* Shared insertion logic for zones where cards become visible on add and follow
|
||||
* the standard pattern: clamp index, insert, clear identity if contents unknown,
|
||||
* reset state, show card.
|
||||
* Shared insertion logic for zones where cards follow the standard pattern:
|
||||
* clamp index, insert, clear identity if contents unknown, reset state.
|
||||
* Visibility and parenting are handled by the graphics zone's onCardAdded().
|
||||
*
|
||||
* Zones with different post-add behavior (signal connections, positional resets,
|
||||
* hidden cards, or coordinate-based placement) should NOT use this — implement
|
||||
|
|
@ -18,8 +18,7 @@ namespace CardZoneAlgorithms
|
|||
*
|
||||
* @tparam CardList Must provide: size() -> int, insert(int, CardType*),
|
||||
* getContentsKnown() -> bool
|
||||
* @tparam CardType Must provide: setId(int), setCardRef(CardRefType),
|
||||
* resetState(bool), setVisible(bool)
|
||||
* @tparam CardType Must provide: setId(int), setCardRef(CardRefType), resetState(bool)
|
||||
* @param keepAnnotations Forwarded to card->resetState(). Stack-like zones preserve
|
||||
* annotations across zone transitions; hand-like zones clear them.
|
||||
*/
|
||||
|
|
@ -37,7 +36,6 @@ void addCardToList(CardList &cards, CardType *card, int x, bool keepAnnotations)
|
|||
}
|
||||
|
||||
card->resetState(keepAnnotations);
|
||||
card->setVisible(true);
|
||||
}
|
||||
|
||||
} // namespace CardZoneAlgorithms
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ public:
|
|||
void rawInsertCard(CardItem *card, int index)
|
||||
{
|
||||
cards.insert(index, card);
|
||||
emit cardCountChanged();
|
||||
}
|
||||
|
||||
[[nodiscard]] const CardList &getCards() const
|
||||
|
|
@ -63,6 +64,7 @@ public:
|
|||
void sortCards(const QList<CardList::SortOption> &options)
|
||||
{
|
||||
cards.sortBy(options);
|
||||
emit cardCountChanged();
|
||||
}
|
||||
[[nodiscard]] QString getName() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,13 +18,12 @@ PileZoneLogic::PileZoneLogic(PlayerLogic *_player,
|
|||
|
||||
void PileZoneLogic::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||
{
|
||||
connect(card, &CardItem::sigPixmapUpdated, this, &PileZoneLogic::callUpdate);
|
||||
connect(card->getState(), &CardState::cardPixmapUpdated, this, &PileZoneLogic::callUpdate);
|
||||
// if x is negative set it to add at end
|
||||
if (x < 0 || x >= cards.size()) {
|
||||
x = cards.size();
|
||||
}
|
||||
cards.insert(x, card);
|
||||
card->setPos(0, 0);
|
||||
if (!contentsKnown()) {
|
||||
card->setCardRef({});
|
||||
card->setId(-1);
|
||||
|
|
@ -33,6 +32,5 @@ void PileZoneLogic::addCardImpl(CardItem *card, int x, int /*y*/)
|
|||
cards.at(x + 1)->setCardRef({});
|
||||
}
|
||||
}
|
||||
card->setVisible(false);
|
||||
card->resetState();
|
||||
}
|
||||
|
|
@ -29,7 +29,6 @@ void TableZoneLogic::addCardImpl(CardItem *card, int _x, int _y)
|
|||
card->setDoesntUntap(true);
|
||||
}
|
||||
card->setGridPoint(QPoint(_x, _y));
|
||||
card->setVisible(true);
|
||||
}
|
||||
|
||||
CardItem *TableZoneLogic::takeCard(int position, int cardId, bool toNewZone)
|
||||
|
|
|
|||
|
|
@ -168,6 +168,7 @@ void ZoneViewZoneLogic::clearCards()
|
|||
card->deleteLater();
|
||||
}
|
||||
cards.clear();
|
||||
emit cardCountChanged();
|
||||
}
|
||||
|
||||
void ZoneViewZoneLogic::setWriteableRevealZone(bool _writeableRevealZone)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue