diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index ca0967636..a44c28d40 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -3,6 +3,7 @@ #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/hand_zone.h" @@ -27,6 +28,7 @@ #include #include #include +#include #include #include @@ -1572,23 +1574,34 @@ void PlayerActions::actCardCounterTrigger() break; } case 11: { // set counter with dialog - bool ok; player->setDialogSemaphore(true); - int oldValue = 0; - if (player->getGameScene()->selectedItems().size() == 1) { - auto *card = static_cast(player->getGameScene()->selectedItems().first()); - oldValue = card->getCounters().value(counterId, 0); + // If a single card is selected, we show the old value in the dialog. Otherwise, we show "x" + QList sel = player->getGameScene()->selectedItems(); + QString oldValueForDlg = "x"; + if (sel.size() == 1) { + auto *card = dynamic_cast(sel.first()); + oldValueForDlg = QString::number(card->getCounters().value(counterId, 0)); } - int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Set counters"), tr("Number:"), oldValue, - 0, MAX_COUNTERS_ON_CARD, 1, &ok); + + 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; } - for (const auto &item : player->getGameScene()->selectedItems()) { - auto *card = static_cast(item); + for (const auto &item : sel) { + auto *card = dynamic_cast(item); + + int oldValue = card->getCounters().value(counterId, 0); + Expression exp(oldValue); + int number = static_cast(exp.parse(dialog.textValue())); + auto *cmd = new Command_SetCardCounter; cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_card_id(card->getId());