mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 15:43:54 -07:00
Consider removed cards.
Took 14 minutes
This commit is contained in:
parent
0cfffdf9df
commit
815baa1ffd
8 changed files with 39 additions and 7 deletions
|
|
@ -15,6 +15,17 @@ void CardState::prepareDelete()
|
||||||
attachedCards.first()->setZone(nullptr); // so that it won't try to call reorganizeCards()
|
attachedCards.first()->setZone(nullptr); // so that it won't try to call reorganizeCards()
|
||||||
attachedCards.first()->setAttachedTo(nullptr);
|
attachedCards.first()->setAttachedTo(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getAttachedTo() != nullptr) {
|
||||||
|
getAttachedTo()->removeAttachedCard(this);
|
||||||
|
setAttachedTo(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CardState::deleteLater()
|
||||||
|
{
|
||||||
|
prepareDelete();
|
||||||
|
QObject::deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardState::processCardInfo(const ServerInfo_Card &_info)
|
void CardState::processCardInfo(const ServerInfo_Card &_info)
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,9 @@ signals:
|
||||||
void zoneChanged(CardState *changedCard, CardZoneLogic *newZone);
|
void zoneChanged(CardState *changedCard, CardZoneLogic *newZone);
|
||||||
void visibleChanged(bool visible);
|
void visibleChanged(bool visible);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void deleteLater();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CardState(PlayerLogic *_owner, const CardRef &cardRef = {}, int _id = -1, CardZoneLogic *_zone = nullptr);
|
explicit CardState(PlayerLogic *_owner, const CardRef &cardRef = {}, int _id = -1, CardZoneLogic *_zone = nullptr);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -90,6 +90,8 @@ CardState *CardZoneLogic::takeCard(int position, int cardId, bool toNewZone)
|
||||||
|
|
||||||
c->setId(cardId);
|
c->setId(cardId);
|
||||||
|
|
||||||
|
emit cardRemoved(c, c->getGridPos().x(), c->getGridPos().y());
|
||||||
|
|
||||||
emit reorganizeCards();
|
emit reorganizeCards();
|
||||||
emit cardCountChanged();
|
emit cardCountChanged();
|
||||||
return c;
|
return c;
|
||||||
|
|
@ -120,6 +122,8 @@ void CardZoneLogic::removeCard(CardState *card)
|
||||||
|
|
||||||
cards.removeOne(card);
|
cards.removeOne(card);
|
||||||
|
|
||||||
|
emit cardRemoved(card, card->getGridPos().x(), card->getGridPos().y());
|
||||||
|
|
||||||
emit reorganizeCards();
|
emit reorganizeCards();
|
||||||
emit cardCountChanged();
|
emit cardCountChanged();
|
||||||
player->deleteCard(card);
|
player->deleteCard(card);
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ class CardZoneLogic : public QObject
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void cardAdded(CardState *addedCard, int x, int y);
|
void cardAdded(CardState *addedCard, int x, int y);
|
||||||
|
void cardRemoved(CardState *removedCard, int x, int y);
|
||||||
void cardCountChanged();
|
void cardCountChanged();
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void updateGraphics();
|
void updateGraphics();
|
||||||
|
|
|
||||||
|
|
@ -41,13 +41,6 @@ void CardItem::prepareDelete()
|
||||||
}
|
}
|
||||||
owner = nullptr;
|
owner = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->prepareDelete();
|
|
||||||
|
|
||||||
if (state->getAttachedTo() != nullptr) {
|
|
||||||
state->getAttachedTo()->removeAttachedCard(getState());
|
|
||||||
state->setAttachedTo(nullptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::deleteLater()
|
void CardItem::deleteLater()
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,10 @@ QMenu *PlayerMenu::updateCardMenu(const CardState *card)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!player->getLogic()->getGame()->getActiveCard()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
// If is spectator (as spectators don't need card menus), return
|
// If is spectator (as spectators don't need card menus), return
|
||||||
// only update the menu if the card is actually selected
|
// only update the menu if the card is actually selected
|
||||||
if ((player->getLogic()->getGame()->getPlayerManager()->isSpectator() &&
|
if ((player->getLogic()->getGame()->getPlayerManager()->isSpectator() &&
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ CardZone::CardZone(CardZoneLogic *_logic, QGraphicsItem *parent)
|
||||||
{
|
{
|
||||||
connect(logic, &CardZoneLogic::retranslateUi, this, &CardZone::retranslateUi);
|
connect(logic, &CardZoneLogic::retranslateUi, this, &CardZone::retranslateUi);
|
||||||
connect(logic, &CardZoneLogic::cardAdded, this, &CardZone::onCardAdded);
|
connect(logic, &CardZoneLogic::cardAdded, this, &CardZone::onCardAdded);
|
||||||
|
connect(logic, &CardZoneLogic::cardRemoved, this, &CardZone::onCardRemoved);
|
||||||
connect(logic, &CardZoneLogic::setGraphicsVisibility, this, [this](bool v) { this->setVisible(v); });
|
connect(logic, &CardZoneLogic::setGraphicsVisibility, this, [this](bool v) { this->setVisible(v); });
|
||||||
connect(logic, &CardZoneLogic::updateGraphics, this, [this]() { update(); });
|
connect(logic, &CardZoneLogic::updateGraphics, this, [this]() { update(); });
|
||||||
connect(logic, &CardZoneLogic::reorganizeCards, this, &CardZone::reorganizeCards);
|
connect(logic, &CardZoneLogic::reorganizeCards, this, &CardZone::reorganizeCards);
|
||||||
|
|
@ -27,6 +28,20 @@ void CardZone::onCardAdded(CardState *toAdd, int /*x*/, int /*y*/)
|
||||||
emit cardItemAdded(addedCard);
|
emit cardItemAdded(addedCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardZone::onCardRemoved(CardState *toRemove, int /*x*/, int /*y*/)
|
||||||
|
{
|
||||||
|
CardItem *removedCard = getCardItemForId(toRemove->getId());
|
||||||
|
if (!removedCard) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (cards.contains(removedCard)) {
|
||||||
|
cards.remove(cards.indexOf(removedCard));
|
||||||
|
}
|
||||||
|
removedCard->setVisible(false);
|
||||||
|
removedCard->setParentItem(nullptr);
|
||||||
|
removedCard->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
void CardZone::retranslateUi()
|
void CardZone::retranslateUi()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < cards.size(); ++i) {
|
for (int i = 0; i < cards.size(); ++i) {
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ public slots:
|
||||||
* connection in CardZone's constructor dispatches through the vtable.
|
* connection in CardZone's constructor dispatches through the vtable.
|
||||||
*/
|
*/
|
||||||
virtual void onCardAdded(CardState *addedCard, int x, int y);
|
virtual void onCardAdded(CardState *addedCard, int x, int y);
|
||||||
|
void onCardRemoved(CardState *toAdd, int x, int y);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void cardItemAdded(CardItem *added);
|
void cardItemAdded(CardItem *added);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue