[Refactor] Pass the target card into PlayerActions instead of reading activeCard (#7415)

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-10-31 18:44:08 +01:00 • committed by GitHub
parent 93c5d85996
commit 94b91be5a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 30 deletions

View file

@ -757,9 +757,8 @@ static void selectCardsInZone(
} }
} }
void PlayerActions::actSelectAll() void PlayerActions::actSelectAll(const CardItem *card)
{ {
const CardItem *card = player->getGame()->getActiveCard();
if (!card) { if (!card) {
return; return;
} }
@ -767,9 +766,8 @@ void PlayerActions::actSelectAll()
selectCardsInZone(card->getZone()); selectCardsInZone(card->getZone());
} }
void PlayerActions::actSelectRow() void PlayerActions::actSelectRow(const CardItem *card)
{ {
const CardItem *card = player->getGame()->getActiveCard();
if (!card) { if (!card) {
return; return;
} }
@ -780,9 +778,8 @@ void PlayerActions::actSelectRow()
selectCardsInZone(card->getZone(), isSameRow); selectCardsInZone(card->getZone(), isSameRow);
} }
void PlayerActions::actSelectColumn() void PlayerActions::actSelectColumn(const CardItem *card)
{ {
const CardItem *card = player->getGame()->getActiveCard();
if (!card) { if (!card) {
return; return;
} }
@ -996,25 +993,20 @@ void PlayerActions::actCreatePredefinedToken()
actCreateAnotherToken(); actCreateAnotherToken();
} }
void PlayerActions::actCreateRelatedCard() void PlayerActions::actCreateRelatedCard(const CardItem *sourceCard, int index)
{ {
const CardItem *sourceCard = player->getGame()->getActiveCard();
if (!sourceCard) { if (!sourceCard) {
return; return;
} }
auto *action = static_cast<QAction *>(sender());
// If there is a better way of passing a CardRelation through a QAction, please add it here.
auto relatedCards = sourceCard->getCardInfo().getAllRelatedCards(); auto relatedCards = sourceCard->getCardInfo().getAllRelatedCards();
CardRelation *cardRelation = relatedCards.at(action->data().toInt()); CardRelation *cardRelation = relatedCards.at(index);
actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation); actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation);
} }
void PlayerActions::actCreateAllRelatedCards() void PlayerActions::actCreateAllRelatedCards(const CardItem *sourceCard)
{ {
const CardItem *sourceCard = player->getGame()->getActiveCard();
if (!sourceCard) { if (!sourceCard) {
return; return;
} }

View file

@ -164,9 +164,9 @@ public slots:
void actRequestMoveBottomCardsToDialog(const QString &targetZone, const QString &zoneDisplayName, bool faceDown); void actRequestMoveBottomCardsToDialog(const QString &targetZone, const QString &zoneDisplayName, bool faceDown);
void moveBottomCardsTo(int number, const QString &targetZone, bool faceDown); void moveBottomCardsTo(int number, const QString &targetZone, bool faceDown);
void actSelectAll(); void actSelectAll(const CardItem *card);
void actSelectRow(); void actSelectRow(const CardItem *card);
void actSelectColumn(); void actSelectColumn(const CardItem *card);
void actViewLibrary(); void actViewLibrary();
void actViewHand(); void actViewHand();
@ -187,8 +187,8 @@ public slots:
void actOpenDeckInDeckEditor(); void actOpenDeckInDeckEditor();
void actCreatePredefinedToken(); void actCreatePredefinedToken();
void actCreateRelatedCard(); void actCreateRelatedCard(const CardItem *sourceCard, int index);
void actCreateAllRelatedCards(); void actCreateAllRelatedCards(const CardItem *sourceCard);
void actRequestMoveCardXCardsFromTopDialog(); void actRequestMoveCardXCardsFromTopDialog();
void actMoveCardXCardsFromTop(QList<CardItem *> selectedCards, int number); void actMoveCardXCardsFromTop(QList<CardItem *> selectedCards, int number);

View file

@ -108,20 +108,18 @@ CardMenu::CardMenu(PlayerGraphicsItem *_player, CardItem *_card, bool _shortcuts
aHide = makeAction(this, [actions, sel]() { actions->actHide(sel()); }); aHide = makeAction(this, [actions, sel]() { actions->actHide(sel()); });
aReduceLifeByPower = makeAction(this, [actions, sel]() { actions->actReduceLifeByPower(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); aAttach = new QAction(this);
aDrawArrow = new QAction(this); aDrawArrow = new QAction(this);
// Actions that use activeCard, not selection — direct connection
aSelectAll = new QAction(this); aSelectAll = new QAction(this);
aSelectRow = new QAction(this); aSelectRow = new QAction(this);
aSelectColumn = new QAction(this); aSelectColumn = new QAction(this);
connect(aAttach, &QAction::triggered, this, &CardMenu::attachCard); connect(aAttach, &QAction::triggered, this, &CardMenu::attachCard);
connect(aDrawArrow, &QAction::triggered, this, &CardMenu::drawArrow); connect(aDrawArrow, &QAction::triggered, this, &CardMenu::drawArrow);
connect(aSelectAll, &QAction::triggered, actions, &PlayerActions::actSelectAll); connect(aSelectAll, &QAction::triggered, this, [this, actions]() { actions->actSelectAll(card); });
connect(aSelectRow, &QAction::triggered, actions, &PlayerActions::actSelectRow); connect(aSelectRow, &QAction::triggered, this, [this, actions]() { actions->actSelectRow(card); });
connect(aSelectColumn, &QAction::triggered, actions, &PlayerActions::actSelectColumn); connect(aSelectColumn, &QAction::triggered, this, [this, actions]() { actions->actSelectColumn(card); });
aRevealToAll = new QAction(this); aRevealToAll = new QAction(this);
@ -443,6 +441,7 @@ void CardMenu::addRelatedCardActions()
if (relatedCards.isEmpty()) { if (relatedCards.isEmpty()) {
return; return;
} }
auto *playerActions = player->getLogic()->getPlayerActions();
addSeparator(); addSeparator();
int index = 0; int index = 0;
@ -486,9 +485,9 @@ void CardMenu::addRelatedCardActions()
} }
auto *createRelated = new QAction(text, this); auto *createRelated = new QAction(text, this);
createRelated->setData(QVariant(index++)); const int relatedIndex = index++;
connect(createRelated, &QAction::triggered, player->getLogic()->getPlayerActions(), connect(createRelated, &QAction::triggered, this,
&PlayerActions::actCreateRelatedCard); [this, playerActions, relatedIndex] { playerActions->actCreateRelatedCard(card, relatedIndex); });
addAction(createRelated); addAction(createRelated);
} }
@ -497,8 +496,8 @@ void CardMenu::addRelatedCardActions()
createRelatedCards->setShortcuts( createRelatedCards->setShortcuts(
SettingsCache::instance().shortcuts().getShortcut("Player/aCreateRelatedTokens")); SettingsCache::instance().shortcuts().getShortcut("Player/aCreateRelatedTokens"));
} }
connect(createRelatedCards, &QAction::triggered, player->getLogic()->getPlayerActions(), connect(createRelatedCards, &QAction::triggered, this,
&PlayerActions::actCreateAllRelatedCards); [this, playerActions] { playerActions->actCreateAllRelatedCards(card); });
addAction(createRelatedCards); addAction(createRelatedCards);
} }
} }