[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) {
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<QAction *>(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;
}

View file

@ -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<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()); });
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);
}
}