diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index 060f5ca6e..d8c02396e 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -757,9 +757,8 @@ static void selectCardsInZone( } } -void PlayerActions::actSelectAll() +void PlayerActions::actSelectAll(const CardItem *card) { - const CardItem *card = player->getGame()->getActiveCard(); if (!card) { return; } @@ -767,9 +766,8 @@ void PlayerActions::actSelectAll() selectCardsInZone(card->getZone()); } -void PlayerActions::actSelectRow() +void PlayerActions::actSelectRow(const CardItem *card) { - const CardItem *card = player->getGame()->getActiveCard(); if (!card) { return; } @@ -780,9 +778,8 @@ void PlayerActions::actSelectRow() selectCardsInZone(card->getZone(), isSameRow); } -void PlayerActions::actSelectColumn() +void PlayerActions::actSelectColumn(const CardItem *card) { - const CardItem *card = player->getGame()->getActiveCard(); if (!card) { return; } @@ -996,25 +993,20 @@ void PlayerActions::actCreatePredefinedToken() actCreateAnotherToken(); } -void PlayerActions::actCreateRelatedCard() +void PlayerActions::actCreateRelatedCard(const CardItem *sourceCard, int index) { - const CardItem *sourceCard = player->getGame()->getActiveCard(); - if (!sourceCard) { return; } - auto *action = static_cast(sender()); - // If there is a better way of passing a CardRelation through a QAction, please add it here. auto relatedCards = sourceCard->getCardInfo().getAllRelatedCards(); - CardRelation *cardRelation = relatedCards.at(action->data().toInt()); + CardRelation *cardRelation = relatedCards.at(index); actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation); } -void PlayerActions::actCreateAllRelatedCards() +void PlayerActions::actCreateAllRelatedCards(const CardItem *sourceCard) { - const CardItem *sourceCard = player->getGame()->getActiveCard(); if (!sourceCard) { return; } diff --git a/cockatrice/src/game/player/player_actions.h b/cockatrice/src/game/player/player_actions.h index e0b1c461f..427fd8f66 100644 --- a/cockatrice/src/game/player/player_actions.h +++ b/cockatrice/src/game/player/player_actions.h @@ -164,9 +164,9 @@ public slots: void actRequestMoveBottomCardsToDialog(const QString &targetZone, const QString &zoneDisplayName, bool faceDown); void moveBottomCardsTo(int number, const QString &targetZone, bool faceDown); - void actSelectAll(); - void actSelectRow(); - void actSelectColumn(); + void actSelectAll(const CardItem *card); + void actSelectRow(const CardItem *card); + void actSelectColumn(const CardItem *card); void actViewLibrary(); void actViewHand(); @@ -187,8 +187,8 @@ public slots: void actOpenDeckInDeckEditor(); void actCreatePredefinedToken(); - void actCreateRelatedCard(); - void actCreateAllRelatedCards(); + void actCreateRelatedCard(const CardItem *sourceCard, int index); + void actCreateAllRelatedCards(const CardItem *sourceCard); void actRequestMoveCardXCardsFromTopDialog(); void actMoveCardXCardsFromTop(QList selectedCards, int number); diff --git a/cockatrice/src/game_graphics/player/menu/card_menu.cpp b/cockatrice/src/game_graphics/player/menu/card_menu.cpp index 769bdd53a..d384f5521 100644 --- a/cockatrice/src/game_graphics/player/menu/card_menu.cpp +++ b/cockatrice/src/game_graphics/player/menu/card_menu.cpp @@ -108,20 +108,18 @@ CardMenu::CardMenu(PlayerGraphicsItem *_player, CardItem *_card, bool _shortcuts aHide = makeAction(this, [actions, sel]() { actions->actHide(sel()); }); aReduceLifeByPower = makeAction(this, [actions, sel]() { actions->actReduceLifeByPower(sel()); }); - // Actions bound to the card this menu was opened for + // Actions bound to the card this menu was opened for, not to the current selection aAttach = new QAction(this); aDrawArrow = new QAction(this); - - // Actions that use activeCard, not selection — direct connection aSelectAll = new QAction(this); aSelectRow = new QAction(this); aSelectColumn = new QAction(this); connect(aAttach, &QAction::triggered, this, &CardMenu::attachCard); connect(aDrawArrow, &QAction::triggered, this, &CardMenu::drawArrow); - connect(aSelectAll, &QAction::triggered, actions, &PlayerActions::actSelectAll); - connect(aSelectRow, &QAction::triggered, actions, &PlayerActions::actSelectRow); - connect(aSelectColumn, &QAction::triggered, actions, &PlayerActions::actSelectColumn); + connect(aSelectAll, &QAction::triggered, this, [this, actions]() { actions->actSelectAll(card); }); + connect(aSelectRow, &QAction::triggered, this, [this, actions]() { actions->actSelectRow(card); }); + connect(aSelectColumn, &QAction::triggered, this, [this, actions]() { actions->actSelectColumn(card); }); aRevealToAll = new QAction(this); @@ -443,6 +441,7 @@ void CardMenu::addRelatedCardActions() if (relatedCards.isEmpty()) { return; } + auto *playerActions = player->getLogic()->getPlayerActions(); addSeparator(); int index = 0; @@ -486,9 +485,9 @@ void CardMenu::addRelatedCardActions() } auto *createRelated = new QAction(text, this); - createRelated->setData(QVariant(index++)); - connect(createRelated, &QAction::triggered, player->getLogic()->getPlayerActions(), - &PlayerActions::actCreateRelatedCard); + const int relatedIndex = index++; + connect(createRelated, &QAction::triggered, this, + [this, playerActions, relatedIndex] { playerActions->actCreateRelatedCard(card, relatedIndex); }); addAction(createRelated); } @@ -497,8 +496,8 @@ void CardMenu::addRelatedCardActions() createRelatedCards->setShortcuts( SettingsCache::instance().shortcuts().getShortcut("Player/aCreateRelatedTokens")); } - connect(createRelatedCards, &QAction::triggered, player->getLogic()->getPlayerActions(), - &PlayerActions::actCreateAllRelatedCards); + connect(createRelatedCards, &QAction::triggered, this, + [this, playerActions] { playerActions->actCreateAllRelatedCards(card); }); addAction(createRelatedCards); } }