mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-08 17:13:57 -07:00
fix multiple selection
This commit is contained in:
parent
bf2634d714
commit
4e34948866
1 changed files with 20 additions and 14 deletions
|
|
@ -1576,38 +1576,44 @@ void PlayerActions::actCardCounterTrigger()
|
||||||
case 11: { // set counter with dialog
|
case 11: { // set counter with dialog
|
||||||
player->setDialogSemaphore(true);
|
player->setDialogSemaphore(true);
|
||||||
|
|
||||||
int oldValue = 0;
|
const auto &cardCounterSettings = SettingsCache::instance().cardCounters();
|
||||||
QString counterName = "";
|
const auto counterName = cardCounterSettings.displayName(counterId);
|
||||||
|
|
||||||
if (auto selectedItems = player->getGameScene()->selectedItems(); selectedItems.size() == 1) {
|
auto selectedItems = player->getGameScene()->selectedItems();
|
||||||
const auto *card = dynamic_cast<CardItem *>(selectedItems.first());
|
|
||||||
const auto &cardCounterSettings = SettingsCache::instance().cardCounters();
|
|
||||||
counterName = cardCounterSettings.displayName(counterId);
|
|
||||||
oldValue = card->getCounters().value(counterId, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
AbstractCounterDialog dialog(counterName, QString::number(oldValue), player->getGame()->getTab());
|
const QString oldValueForDlg = [&selectedItems, &counterId] {
|
||||||
|
// If a single card is selected, we show the old value in the dialog. Otherwise, we show "x"
|
||||||
|
if (selectedItems.size() == 1) {
|
||||||
|
const auto *card = dynamic_cast<CardItem *>(selectedItems.first());
|
||||||
|
return QString::number(card->getCounters().value(counterId, 0));
|
||||||
|
}
|
||||||
|
return QString{"x"};
|
||||||
|
}();
|
||||||
|
|
||||||
|
AbstractCounterDialog dialog(counterName, oldValueForDlg, player->getGame()->getTab());
|
||||||
const int ok = dialog.exec();
|
const int ok = dialog.exec();
|
||||||
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Expression exp(oldValue);
|
|
||||||
const auto number = static_cast<int>(exp.parse(dialog.textValue()));
|
|
||||||
|
|
||||||
player->setDialogSemaphore(false);
|
player->setDialogSemaphore(false);
|
||||||
if (player->clearCardsToDelete() || !ok) {
|
if (player->clearCardsToDelete() || !ok) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &item : player->getGameScene()->selectedItems()) {
|
for (const auto &item : selectedItems) {
|
||||||
const auto *card = dynamic_cast<CardItem *>(item);
|
const auto *card = dynamic_cast<CardItem *>(item);
|
||||||
|
|
||||||
|
const auto oldValue = QString::number(card->getCounters().value(counterId, 0));
|
||||||
|
Expression exp(oldValue.toDouble());
|
||||||
|
const auto newValue = static_cast<int>(exp.parse(dialog.textValue()));
|
||||||
|
|
||||||
auto *cmd = new Command_SetCardCounter;
|
auto *cmd = new Command_SetCardCounter;
|
||||||
cmd->set_zone(card->getZone()->getName().toStdString());
|
cmd->set_zone(card->getZone()->getName().toStdString());
|
||||||
cmd->set_card_id(card->getId());
|
cmd->set_card_id(card->getId());
|
||||||
cmd->set_counter_id(counterId);
|
cmd->set_counter_id(counterId);
|
||||||
cmd->set_counter_value(number);
|
cmd->set_counter_value(newValue);
|
||||||
commandList.append(cmd);
|
commandList.append(cmd);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue