diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index 1bb461c3d..2b0428dd8 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -988,8 +988,11 @@ void PlayerActions::actCreateAllRelatedCards() if (relatedCards.length() == 1) { cardRelation = relatedCards.at(0); + lastRelatedCreationSucceeded = false; // reset before emit actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation); - ++tokensTypesCreated; + if (lastRelatedCreationSucceeded) { + ++tokensTypesCreated; + } } else { QList nonExcludedRelatedCards; QString dbName; @@ -999,15 +1002,18 @@ void PlayerActions::actCreateAllRelatedCards() } } switch (nonExcludedRelatedCards.length()) { - case 1: // if nonExcludedRelatedCards == 1 + case 1: cardRelation = nonExcludedRelatedCards.at(0); + lastRelatedCreationSucceeded = false; // reset before emit actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation); - ++tokensTypesCreated; - + if (lastRelatedCreationSucceeded) { + ++tokensTypesCreated; + } break; + // If all are marked "Exclude", then treat the situation as if none of them are. // We won't accept "garbage in, garbage out", here. - case 0: // else if nonExcludedRelatedCards == 0 + case 0: for (CardRelation *cardRelationAll : relatedCards) { if (!cardRelationAll->getDoesAttach() && !cardRelationAll->getIsVariable()) { dbName = cardRelationAll->getName(); @@ -1022,7 +1028,8 @@ void PlayerActions::actCreateAllRelatedCards() } } break; - default: // else + + default: for (CardRelation *cardRelationNotExcluded : nonExcludedRelatedCards) { if (!cardRelationNotExcluded->getDoesAttach() && !cardRelationNotExcluded->getIsVariable()) { dbName = cardRelationNotExcluded->getName(); @@ -1056,33 +1063,36 @@ void PlayerActions::actRequestCreateRelatedFromRelationDialog(const CardItem *so emit requestCreateRelatedFromRelationDialog(sourceCard, cardRelation); } -void PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, +bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation, int variableCount) { if (sourceCard == nullptr || cardRelation == nullptr) { - return; + return false; } const QString dbName = cardRelation->getName(); const bool persistent = cardRelation->getIsPersistent(); - int count = 1; - + // Variable relations always use DoesNotAttach, regardless of the count the user + // entered. if (cardRelation->getIsVariable()) { - count = variableCount; - if (count <= 0) { - return; + if (variableCount <= 0) { + return false; } - } else { - count = cardRelation->getDefaultCount(); + for (int i = 0; i < variableCount; ++i) { + createCard(sourceCard, dbName, CardRelationType::DoesNotAttach, persistent); + } + return true; } + const int count = cardRelation->getDefaultCount(); + if (count > 1) { for (int i = 0; i < count; ++i) { createCard(sourceCard, dbName, CardRelationType::DoesNotAttach, persistent); } - return; + return true; } CardRelationType attachType; @@ -1101,11 +1111,15 @@ void PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, } createCard(sourceCard, dbName, attachType, persistent); - return; + return true; } void PlayerActions::onRelatedCardCreated(const CardItem *sourceCard, const CardRelation *cardRelation) { + if (sourceCard == nullptr || cardRelation == nullptr) { + return; + } + /* * If we make a token via "Token: TokenName" * then let's allow it to be created via "create another token" diff --git a/cockatrice/src/game/player/player_actions.h b/cockatrice/src/game/player/player_actions.h index 1ecf642d3..2779fa5aa 100644 --- a/cockatrice/src/game/player/player_actions.h +++ b/cockatrice/src/game/player/player_actions.h @@ -102,8 +102,12 @@ public slots: void actCreateToken(TokenInfo tokenToCreate); void actCreateAnotherToken(); void actRequestCreateRelatedFromRelationDialog(const CardItem *sourceCard, const CardRelation *cardRelation); - void createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation, int variableCount); + bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation, int variableCount); void onRelatedCardCreated(const CardItem *sourceCard, const CardRelation *cardRelation); + void setLastRelatedCreationSucceeded(bool succeeded) + { + lastRelatedCreationSucceeded = succeeded; + } void actShuffle(); void actRequestShuffleTopDialog(); void actShuffleTop(int number); @@ -230,6 +234,8 @@ private: int movingCardsUntilCounter = 0; MoveTopCardsUntilOptions movingCardsUntilOptions; + bool lastRelatedCreationSucceeded = false; + void createCard(const CardItem *sourceCard, const QString &dbCardName, CardRelationType attach = CardRelationType::DoesNotAttach, diff --git a/cockatrice/src/game/player/player_dialogs.cpp b/cockatrice/src/game/player/player_dialogs.cpp index ba2753aaa..3a78fad1f 100644 --- a/cockatrice/src/game/player/player_dialogs.cpp +++ b/cockatrice/src/game/player/player_dialogs.cpp @@ -1,8 +1,8 @@ #include "player_dialogs.h" +#include "../../client/settings/card_counter_settings.h" #include "../../interface/widgets/utility/get_text_with_max.h" #include "../board/card_item.h" -#include "../client/settings/card_counter_settings.h" #include "../dialogs/dlg_roll_dice.h" #include "../player/player_graphics_item.h" @@ -190,6 +190,7 @@ void PlayerDialogs::onCreateRelatedFromRelationDialogRequested(const CardItem *s const CardRelation *cardRelation) { if (sourceCard == nullptr || cardRelation == nullptr) { + playerActions->setLastRelatedCreationSucceeded(false); return; } @@ -206,13 +207,18 @@ void PlayerDialogs::onCreateRelatedFromRelationDialogRequested(const CardItem *s emit requestDialogSemaphore(false); if (!ok) { + playerActions->setLastRelatedCreationSucceeded(false); // cancelled return; } } - playerActions->createRelatedFromRelation(sourceCard, cardRelation, variableCount); + const bool succeeded = playerActions->createRelatedFromRelation(sourceCard, cardRelation, variableCount); - playerActions->onRelatedCardCreated(sourceCard, cardRelation); + playerActions->setLastRelatedCreationSucceeded(succeeded); + + if (succeeded) { + playerActions->onRelatedCardCreated(sourceCard, cardRelation); // only on confirmed success + } } void PlayerDialogs::onCreateTokenDialogRequested(const QStringList &predefinedTokens)