[Game][Player] Move dialog creation out of player_actions and into player_dialogs (#6946)
Some checks are pending
Build Desktop / Configure (push) Waiting to run
Build Desktop / Debian 13 (push) Blocked by required conditions
Build Desktop / Debian 12 (push) Blocked by required conditions
Build Desktop / Fedora 44 (push) Blocked by required conditions
Build Desktop / Fedora 43 (push) Blocked by required conditions
Build Desktop / Servatrice_Debian 12 (push) Blocked by required conditions
Build Desktop / Ubuntu 26.04 (push) Blocked by required conditions
Build Desktop / Ubuntu 24.04 (push) Blocked by required conditions
Build Desktop / Arch (push) Blocked by required conditions
Build Desktop / macOS 14 (push) Blocked by required conditions
Build Desktop / macOS 15 (push) Blocked by required conditions
Build Desktop / macOS 13 Intel (push) Blocked by required conditions
Build Desktop / macOS 15 Debug (push) Blocked by required conditions
Build Desktop / Windows 10 (push) Blocked by required conditions
Build Docker Image / amd64 & arm64 (push) Waiting to run

* [Game][Player] Split Player into PlayerLogic/PlayerGraphicsItem

Took 4 minutes

Took 48 seconds

Took 2 minutes

* Drop early return.

Took 1 hour 13 minutes


Took 2 minutes

Took 1 minute

Took 24 seconds

* [Game][Player] Split Player into PlayerLogic/PlayerGraphicsItem

Took 4 minutes

Took 58 seconds

* [Game][Menus] Make Menus accept PlayerGraphicsItem instead of PlayerLogic

Took 7 minutes

Took 4 minutes

Took 9 seconds

Took 2 minutes


Took 5 minutes

Took 58 seconds

* [Game][Player] Split Player into PlayerLogic/PlayerGraphicsItem

Took 4 minutes

Took 2 minutes

* [Game][Menus] Make Menus accept PlayerGraphicsItem instead of PlayerLogic

Took 7 minutes


Took 1 minute

Took 57 seconds

* [Game][Player] Move dialog creation out of player_actions and into player_dialogs

Took 3 minutes

Took 1 second

* Fix typo.

Took 5 minutes

* Addressed comments.

Took 16 minutes

Took 11 seconds

* Reintroduce clearCardsToDelete check.

Took 3 minutes

* Capture cards before semaphore.

Took 1 minute

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2026-06-09 08:22:59 +02:00 committed by GitHub
parent 487bb84b6f
commit cbfd286908
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 664 additions and 231 deletions

View file

@ -5,7 +5,6 @@
#include "../../interface/widgets/tabs/tab_game.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_move_top_cards_until.h"
#include "../dialogs/dlg_roll_dice.h"
#include "../zones/view_zone_logic.h"
@ -175,30 +174,26 @@ void PlayerActions::actSortHand()
emit requestSortHand(sortOptions + defaultOptions);
}
void PlayerActions::actViewTopCards()
void PlayerActions::actRequestViewTopCardsDialog()
{
int deckSize = player->getDeckZone()->getCards().size();
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("View top cards of library"),
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1,
deckSize, 1, &ok);
if (ok) {
defaultNumberTopCards = number;
emit requestZoneViewToggle(ZoneNames::DECK, number);
}
emit requestViewTopCardsDialog(defaultNumberTopCards, player->getDeckZone()->getCards().size());
}
void PlayerActions::actViewBottomCards()
void PlayerActions::actViewTopCards(int number)
{
int deckSize = player->getDeckZone()->getCards().size();
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("View bottom cards of library"),
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberBottomCards, 1,
deckSize, 1, &ok);
if (ok) {
defaultNumberBottomCards = number;
emit requestZoneViewToggle(ZoneNames::DECK, number, true);
}
defaultNumberTopCards = number;
emit requestZoneViewToggle(ZoneNames::DECK, number);
}
void PlayerActions::actRequestViewBottomCardsDialog()
{
emit requestViewBottomCardsDialog(defaultNumberBottomCards, player->getDeckZone()->getCards().size());
}
void PlayerActions::actViewBottomCards(int number)
{
defaultNumberBottomCards = number;
emit requestZoneViewToggle(ZoneNames::DECK, number, true);
}
void PlayerActions::actAlwaysRevealTopCard(bool alwaysRevealTopCard)
@ -244,18 +239,20 @@ void PlayerActions::actShuffle()
sendGameCommand(Command_Shuffle());
}
void PlayerActions::actShuffleTop()
void PlayerActions::actRequestShuffleTopDialog()
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Shuffle top cards of library"),
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
maxCards, 1, &ok);
if (!ok) {
emit requestShuffleTopDialog(defaultNumberTopCards, maxCards);
}
void PlayerActions::actShuffleTop(int number)
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
@ -273,18 +270,20 @@ void PlayerActions::actShuffleTop()
sendGameCommand(cmd);
}
void PlayerActions::actShuffleBottom()
void PlayerActions::actRequestShuffleBottomDialog()
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Shuffle bottom cards of library"),
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
maxCards, 1, &ok);
if (!ok) {
emit requestShuffleBottomDialog(defaultNumberBottomCards, maxCards);
}
void PlayerActions::actShuffleBottom(int number)
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
@ -309,21 +308,18 @@ void PlayerActions::actDrawCard()
sendGameCommand(cmd);
}
void PlayerActions::actMulligan()
void PlayerActions::actRequestMulliganDialog()
{
int startSize = SettingsCache::instance().getStartingHandSize();
int handSize = player->getHandZone()->getCards().size();
int deckSize = player->getDeckZone()->getCards().size() + handSize;
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Draw hand"),
tr("Number of cards: (max. %1)").arg(deckSize) + '\n' +
tr("0 and lower are in comparison to current hand size"),
startSize, -handSize, deckSize, 1, &ok);
emit requestMulliganDialog(startSize, handSize, deckSize);
}
if (!ok) {
return;
}
void PlayerActions::actMulligan(int number)
{
int handSize = player->getHandZone()->getCards().size();
if (number < 1) {
number = handSize + number;
@ -357,19 +353,19 @@ void PlayerActions::doMulligan(int number)
sendGameCommand(cmd);
}
void PlayerActions::actDrawCards()
void PlayerActions::actRequestDrawCardsDialog()
{
int deckSize = player->getDeckZone()->getCards().size();
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Draw cards"),
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1,
deckSize, 1, &ok);
if (ok) {
defaultNumberTopCards = number;
Command_DrawCards cmd;
cmd.set_number(static_cast<google::protobuf::uint32>(number));
sendGameCommand(cmd);
}
emit requestDrawCardsDialog(defaultNumberTopCards, deckSize);
}
void PlayerActions::actDrawCards(int number)
{
defaultNumberTopCards = number;
Command_DrawCards cmd;
cmd.set_number(static_cast<google::protobuf::uint32>(number));
sendGameCommand(cmd);
}
void PlayerActions::actUndoDraw()
@ -427,36 +423,40 @@ void PlayerActions::actMoveTopCardToExile()
void PlayerActions::actMoveTopCardsToGrave()
{
moveTopCardsTo(ZoneNames::GRAVE, tr("grave"), false);
actRequestMoveTopCardsToDialog(ZoneNames::GRAVE, tr("grave"), false);
}
void PlayerActions::actMoveTopCardsToGraveFaceDown()
{
moveTopCardsTo(ZoneNames::GRAVE, tr("grave"), true);
actRequestMoveTopCardsToDialog(ZoneNames::GRAVE, tr("grave"), true);
}
void PlayerActions::actMoveTopCardsToExile()
{
moveTopCardsTo(ZoneNames::EXILE, tr("exile"), false);
actRequestMoveTopCardsToDialog(ZoneNames::EXILE, tr("exile"), false);
}
void PlayerActions::actMoveTopCardsToExileFaceDown()
{
moveTopCardsTo(ZoneNames::EXILE, tr("exile"), true);
actRequestMoveTopCardsToDialog(ZoneNames::EXILE, tr("exile"), true);
}
void PlayerActions::moveTopCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown)
void PlayerActions::actRequestMoveTopCardsToDialog(const QString &targetZone,
const QString &zoneDisplayName,
bool faceDown)
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move top cards to %1").arg(zoneDisplayName),
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1,
maxCards, 1, &ok);
if (!ok) {
emit requestMoveTopCardsToDialog(defaultNumberTopCards, maxCards, targetZone, zoneDisplayName, faceDown);
}
void PlayerActions::moveTopCardsTo(int number, const QString &targetZone, bool faceDown)
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
@ -483,17 +483,16 @@ void PlayerActions::moveTopCardsTo(const QString &targetZone, const QString &zon
sendGameCommand(cmd);
}
void PlayerActions::actMoveTopCardsUntil()
void PlayerActions::actRequestMoveTopCardsUntilDialog()
{
stopMoveTopCardsUntil();
DlgMoveTopCardsUntil dlg(player->getGame()->getTab(), movingCardsUntilOptions);
if (!dlg.exec()) {
return;
}
emit requestMoveTopCardsUntilDialog(movingCardsUntilOptions);
}
auto expr = dlg.getExpr();
movingCardsUntilOptions = dlg.getOptions();
void PlayerActions::moveTopCardsUntil(const QString &expr, MoveTopCardsUntilOptions options)
{
movingCardsUntilOptions = options;
if (player->getDeckZone()->getCards().empty()) {
stopMoveTopCardsUntil();
@ -622,36 +621,40 @@ void PlayerActions::actMoveBottomCardToExile()
void PlayerActions::actMoveBottomCardsToGrave()
{
moveBottomCardsTo(ZoneNames::GRAVE, tr("grave"), false);
actRequestMoveBottomCardsToDialog(ZoneNames::GRAVE, tr("grave"), false);
}
void PlayerActions::actMoveBottomCardsToGraveFaceDown()
{
moveBottomCardsTo(ZoneNames::GRAVE, tr("grave"), true);
actRequestMoveBottomCardsToDialog(ZoneNames::GRAVE, tr("grave"), true);
}
void PlayerActions::actMoveBottomCardsToExile()
{
moveBottomCardsTo(ZoneNames::EXILE, tr("exile"), false);
actRequestMoveBottomCardsToDialog(ZoneNames::EXILE, tr("exile"), false);
}
void PlayerActions::actMoveBottomCardsToExileFaceDown()
{
moveBottomCardsTo(ZoneNames::EXILE, tr("exile"), true);
actRequestMoveBottomCardsToDialog(ZoneNames::EXILE, tr("exile"), true);
}
void PlayerActions::moveBottomCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown)
void PlayerActions::actRequestMoveBottomCardsToDialog(const QString &targetZone,
const QString &zoneDisplayName,
bool faceDown)
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move bottom cards to %1").arg(zoneDisplayName),
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
maxCards, 1, &ok);
if (!ok) {
emit requestMoveBottomCardsToDialog(defaultNumberBottomCards, maxCards, targetZone, zoneDisplayName, faceDown);
}
void PlayerActions::moveBottomCardsTo(int number, const QString &targetZone, bool faceDown)
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
@ -763,20 +766,24 @@ void PlayerActions::actDrawBottomCard()
sendGameCommand(cmd);
}
void PlayerActions::actDrawBottomCards()
void PlayerActions::actRequestDrawBottomCardsDialog()
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
}
bool ok;
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Draw bottom cards"),
tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1,
maxCards, 1, &ok);
if (!ok) {
emit requestDrawBottomCardsDialog(defaultNumberBottomCards, maxCards);
}
void PlayerActions::actDrawBottomCards(int number)
{
const int maxCards = player->getDeckZone()->getCards().size();
if (maxCards == 0) {
return;
} else if (number > maxCards) {
}
if (number > maxCards) {
number = maxCards;
}
defaultNumberBottomCards = number;
@ -843,16 +850,16 @@ void PlayerActions::actUntapAll()
sendGameCommand(cmd);
}
void PlayerActions::actRollDie()
void PlayerActions::actRequestRollDieDialog()
{
DlgRollDice dlg(player->getGame()->getTab());
if (!dlg.exec()) {
return;
}
emit requestRollDieDialog();
}
void PlayerActions::actRollDie(int sides, int count)
{
Command_RollDie cmd;
cmd.set_sides(dlg.getDieSideCount());
cmd.set_count(dlg.getDiceToRollCount());
cmd.set_sides(sides);
cmd.set_count(count);
sendGameCommand(cmd);
}
@ -864,14 +871,14 @@ void PlayerActions::actFlipCoin()
sendGameCommand(cmd);
}
void PlayerActions::actCreateToken(const QStringList &predefinedTokens)
void PlayerActions::actRequestCreateTokenDialog(const QStringList &predefinedTokens)
{
DlgCreateToken dlg(predefinedTokens, player->getGame()->getTab());
if (!dlg.exec()) {
return;
}
emit requestCreateTokenDialog(predefinedTokens);
}
lastTokenInfo = dlg.getTokenInfo();
void PlayerActions::actCreateToken(TokenInfo tokenToCreate)
{
lastTokenInfo = tokenToCreate;
ExactCard correctedCard = CardDatabaseManager::query()->guessCard({lastTokenInfo.name, lastTokenInfo.providerId});
if (correctedCard) {
@ -951,23 +958,17 @@ void PlayerActions::actCreatePredefinedToken()
void PlayerActions::actCreateRelatedCard()
{
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());
/*
* If we make a token via "Token: TokenName"
* then let's allow it to be created via "create another token"
*/
if (createRelatedFromRelation(sourceCard, cardRelation) && cardRelation->getCanCreateAnother()) {
ExactCard relatedCard = CardDatabaseManager::query()->getCardFromSameSet(cardRelation->getName(),
sourceCard->getCard().getPrinting());
setLastToken(relatedCard.getCardPtr());
}
CardRelation *cardRelation = relatedCards.at(action->data().toInt());
actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation);
}
void PlayerActions::actCreateAllRelatedCards()
@ -987,7 +988,9 @@ void PlayerActions::actCreateAllRelatedCards()
if (relatedCards.length() == 1) {
cardRelation = relatedCards.at(0);
if (createRelatedFromRelation(sourceCard, cardRelation)) {
lastRelatedCreationSucceeded = false; // reset before emit
actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation);
if (lastRelatedCreationSucceeded) {
++tokensTypesCreated;
}
} else {
@ -999,15 +1002,18 @@ void PlayerActions::actCreateAllRelatedCards()
}
}
switch (nonExcludedRelatedCards.length()) {
case 1: // if nonExcludedRelatedCards == 1
case 1:
cardRelation = nonExcludedRelatedCards.at(0);
if (createRelatedFromRelation(sourceCard, cardRelation)) {
lastRelatedCreationSucceeded = false; // reset before emit
actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation);
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();
@ -1050,50 +1057,83 @@ void PlayerActions::actCreateAllRelatedCards()
}
}
bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation)
void PlayerActions::actRequestCreateRelatedFromRelationDialog(const CardItem *sourceCard,
const CardRelation *cardRelation)
{
emit requestCreateRelatedFromRelationDialog(sourceCard, cardRelation);
}
bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard,
const CardRelation *cardRelation,
int variableCount)
{
if (sourceCard == nullptr || cardRelation == nullptr) {
return false;
}
QString dbName = cardRelation->getName();
bool persistent = cardRelation->getIsPersistent();
const QString dbName = cardRelation->getName();
const bool persistent = cardRelation->getIsPersistent();
// Variable relations always use DoesNotAttach, regardless of the count the user
// entered.
if (cardRelation->getIsVariable()) {
bool ok;
player->setDialogSemaphore(true);
int count = QInputDialog::getInt(player->getGame()->getTab(), tr("Create tokens"), tr("Number:"),
cardRelation->getDefaultCount(), 1, MAX_TOKENS_PER_DIALOG, 1, &ok);
player->setDialogSemaphore(false);
if (!ok) {
if (variableCount <= 0) {
return false;
}
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);
}
} else if (cardRelation->getDefaultCount() > 1) {
for (int i = 0; i < cardRelation->getDefaultCount(); ++i) {
createCard(sourceCard, dbName, CardRelationType::DoesNotAttach, persistent);
}
} else {
CardRelationType attachType;
// do not attempt to attach to another player's cards, this causes the card to attempt to attach to the same
// cardid on the local player's field instead, which is an entirely different card!
if (player->getPlayerInfo()->getLocalOrJudge()) {
attachType = cardRelation->getAttachType();
} else {
attachType = CardRelationType::DoesNotAttach;
}
// move card onto table first if attaching from some other zone
// we only do this for AttachTo because cross-zone TransformInto is already handled server-side
if (attachType == CardRelationType::AttachTo && sourceCard->getZone()->getName() != ZoneNames::TABLE) {
playCardToTable(sourceCard, false);
}
createCard(sourceCard, dbName, attachType, persistent);
return true;
}
CardRelationType attachType;
// do not attempt to attach to another player's cards, this causes the card to attempt to attach to the same
// cardid on the local player's field instead, which is an entirely different card!
if (player->getPlayerInfo()->getLocalOrJudge()) {
attachType = cardRelation->getAttachType();
} else {
attachType = CardRelationType::DoesNotAttach;
}
// move card onto table first if attaching from some other zone
// we only do this for AttachTo because cross-zone TransformInto is already handled server-side
if (attachType == CardRelationType::AttachTo && sourceCard->getZone()->getName() != ZoneNames::TABLE) {
playCardToTable(sourceCard, false);
}
createCard(sourceCard, dbName, attachType, persistent);
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"
*/
if (!cardRelation->getCanCreateAnother()) {
return;
}
ExactCard relatedCard =
CardDatabaseManager::query()->getCardFromSameSet(cardRelation->getName(), sourceCard->getCard().getPrinting());
setLastToken(relatedCard.getCardPtr());
}
void PlayerActions::createCard(const CardItem *sourceCard,
const QString &dbCardName,
CardRelationType attachType,
@ -1171,35 +1211,29 @@ void PlayerActions::actSayMessage()
sendGameCommand(cmd);
}
void PlayerActions::actMoveCardXCardsFromTop(QList<CardItem *> selectedCards)
void PlayerActions::actRequestMoveCardXCardsFromTopDialog()
{
int deckSize = player->getDeckZone()->getCards().size() + 1; // add the card to move to the deck
bool ok;
int number =
QInputDialog::getInt(player->getGame()->getTab(), tr("Place card X cards from top of library"),
tr("Which position should this card be placed:") + "\n" + tr("(max. %1)").arg(deckSize),
defaultNumberTopCardsToPlaceBelow, 1, deckSize, 1, &ok);
number -= 1; // indexes start at 0
if (!ok) {
return;
}
emit requestMoveCardXCardsFromTopDialog(defaultNumberTopCardsToPlaceBelow, deckSize);
}
void PlayerActions::actMoveCardXCardsFromTop(QList<CardItem *> selectedCards, int number)
{
defaultNumberTopCardsToPlaceBelow = number;
QList<CardItem *> cardList = selectedCards;
if (cardList.isEmpty()) {
if (selectedCards.isEmpty()) {
return;
}
QList<const ::google::protobuf::Message *> commandList;
ListOfCardsToMove idList;
for (const auto &i : cardList) {
for (const auto &i : selectedCards) {
idList.add_card()->set_card_id(i->getId());
}
int startPlayerId = cardList[0]->getZone()->getPlayer()->getPlayerInfo()->getId();
QString startZone = cardList[0]->getZone()->getName();
int startPlayerId = selectedCards[0]->getZone()->getPlayer()->getPlayerInfo()->getId();
QString startZone = selectedCards[0]->getZone()->getName();
auto *cmd = new Command_MoveCard;
cmd->set_start_player_id(startPlayerId);
@ -1284,24 +1318,22 @@ void PlayerActions::actResetPT(QList<CardItem *> selectedCards)
}
}
void PlayerActions::actSetPT(QList<CardItem *> selectedCards)
void PlayerActions::actRequestSetPTDialog(QList<CardItem *> selectedCards)
{
QString oldPT;
int playerid = player->getPlayerInfo()->getId();
for (auto card : selectedCards) {
if (!card->getPT().isEmpty()) {
oldPT = card->getPT();
}
}
bool ok;
player->setDialogSemaphore(true);
QString pt = getTextWithMax(player->getGame()->getTab(), tr("Change power/toughness"), tr("Change stats to:"),
QLineEdit::Normal, oldPT, &ok);
player->setDialogSemaphore(false);
if (player->clearCardsToDelete() || !ok) {
return;
}
emit requestSetPTDialog(oldPT);
}
void PlayerActions::actSetPT(QList<CardItem *> selectedCards, const QString &pt)
{
int playerid = player->getPlayerInfo()->getId();
const auto ptList = CardItem::parsePT(pt);
bool empty = ptList.isEmpty();
@ -1426,7 +1458,7 @@ void AnnotationDialog::keyPressEvent(QKeyEvent *event)
QInputDialog::keyPressEvent(event);
}
void PlayerActions::actSetAnnotation(QList<CardItem *> selectedCards)
void PlayerActions::actRequestSetAnnotationDialog(QList<CardItem *> selectedCards)
{
QString oldAnnotation;
for (auto card : selectedCards) {
@ -1435,19 +1467,11 @@ void PlayerActions::actSetAnnotation(QList<CardItem *> selectedCards)
}
}
player->setDialogSemaphore(true);
AnnotationDialog *dialog = new AnnotationDialog(player->getGame()->getTab());
dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput);
dialog->setWindowTitle(tr("Set annotation"));
dialog->setLabelText(tr("Please enter the new annotation:"));
dialog->setTextValue(oldAnnotation);
bool ok = dialog->exec();
player->setDialogSemaphore(false);
if (player->clearCardsToDelete() || !ok) {
return;
}
QString annotation = dialog->textValue().left(MAX_NAME_LENGTH);
emit requestSetAnnotationDialog(oldAnnotation);
}
void PlayerActions::actSetAnnotation(QList<CardItem *> selectedCards, const QString &annotation)
{
QList<const ::google::protobuf::Message *> commandList;
for (auto card : selectedCards) {
auto *cmd = new Command_SetCardAttr;
@ -1519,10 +1543,8 @@ void PlayerActions::offsetCardCounter(QList<CardItem *> selectedCards, int count
sendGameCommand(prepareGameCommand(commandList));
}
void PlayerActions::actSetCardCounter(QList<CardItem *> selectedCards, int counterId)
void PlayerActions::actRequestSetCardCounterDialog(QList<CardItem *> selectedCards, int counterId)
{
player->setDialogSemaphore(true);
// If a single card is selected, we show the old value in the dialog. Otherwise, we show "x"
QString oldValueForDlg = "x";
if (selectedCards.size() == 1) {
@ -1530,22 +1552,16 @@ void PlayerActions::actSetCardCounter(QList<CardItem *> selectedCards, int count
oldValueForDlg = QString::number(card->getCounters().value(counterId, 0));
}
auto &cardCounterSettings = SettingsCache::instance().cardCounters();
QString counterName = cardCounterSettings.displayName(counterId);
AbstractCounterDialog dialog(counterName, oldValueForDlg, player->getGame()->getTab());
int ok = dialog.exec();
player->setDialogSemaphore(false);
if (player->clearCardsToDelete() || !ok) {
return;
}
emit requestSetCardCounterDialog(counterId, oldValueForDlg);
}
void PlayerActions::actSetCardCounter(QList<CardItem *> selectedCards, int counterId, const QString &counterValue)
{
QList<const ::google::protobuf::Message *> commandList;
for (auto card : selectedCards) {
int oldValue = card->getCounters().value(counterId, 0);
Expression exp(oldValue);
double parsed = exp.parse(dialog.textValue());
double parsed = exp.parse(counterValue);
// Clamp in double precision first to avoid UB, then cast
int number = static_cast<int>(qBound(0.0, parsed, static_cast<double>(MAX_COUNTERS_ON_CARD)));