mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-14 22:42:14 -07:00
Change menu, update function to handle selected vs non selected cards
This commit is contained in:
parent
13bcaba477
commit
dea771e2f5
1 changed files with 45 additions and 19 deletions
|
|
@ -417,8 +417,8 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T
|
||||||
connect(aCreateAnotherToken, &QAction::triggered, this, &Player::actCreateAnotherToken);
|
connect(aCreateAnotherToken, &QAction::triggered, this, &Player::actCreateAnotherToken);
|
||||||
aCreateAnotherToken->setEnabled(false);
|
aCreateAnotherToken->setEnabled(false);
|
||||||
|
|
||||||
aIncrementAllCardCountersOnTable = new QAction(this);
|
aIncrementAllCardCounters = new QAction(this);
|
||||||
connect(aIncrementAllCardCountersOnTable, &QAction::triggered, this, &Player::incrementAllCardCountersOnTable);
|
connect(aIncrementAllCardCounters, &QAction::triggered, this, &Player::incrementAllCardCounters);
|
||||||
|
|
||||||
createPredefinedTokenMenu = new QMenu(QString());
|
createPredefinedTokenMenu = new QMenu(QString());
|
||||||
createPredefinedTokenMenu->setEnabled(false);
|
createPredefinedTokenMenu->setEnabled(false);
|
||||||
|
|
@ -427,7 +427,7 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T
|
||||||
|
|
||||||
playerMenu->addSeparator();
|
playerMenu->addSeparator();
|
||||||
countersMenu = playerMenu->addMenu(QString());
|
countersMenu = playerMenu->addMenu(QString());
|
||||||
countersMenu->addAction(aIncrementAllCardCountersOnTable);
|
playerMenu->addAction(aIncrementAllCardCounters);
|
||||||
playerMenu->addSeparator();
|
playerMenu->addSeparator();
|
||||||
playerMenu->addAction(aUntapAll);
|
playerMenu->addAction(aUntapAll);
|
||||||
playerMenu->addSeparator();
|
playerMenu->addSeparator();
|
||||||
|
|
@ -914,7 +914,7 @@ void Player::retranslateUi()
|
||||||
aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(cardCounterSettings.displayName(i)));
|
aSetCounter[i]->setText(tr("&Set counters (%1)...").arg(cardCounterSettings.displayName(i)));
|
||||||
}
|
}
|
||||||
|
|
||||||
aIncrementAllCardCountersOnTable->setText(tr("Increment all counters"));
|
aIncrementAllCardCounters->setText(tr("Increment all card counters"));
|
||||||
aMoveToTopLibrary->setText(tr("&Top of library in random order"));
|
aMoveToTopLibrary->setText(tr("&Top of library in random order"));
|
||||||
aMoveToXfromTopOfLibrary->setText(tr("X cards from the top of library..."));
|
aMoveToXfromTopOfLibrary->setText(tr("X cards from the top of library..."));
|
||||||
aMoveToBottomLibrary->setText(tr("&Bottom of library in random order"));
|
aMoveToBottomLibrary->setText(tr("&Bottom of library in random order"));
|
||||||
|
|
@ -1002,8 +1002,7 @@ void Player::setShortcutsActive()
|
||||||
while (counterIterator.hasNext()) {
|
while (counterIterator.hasNext()) {
|
||||||
counterIterator.next().value()->setShortcutsActive();
|
counterIterator.next().value()->setShortcutsActive();
|
||||||
}
|
}
|
||||||
aIncrementAllCardCountersOnTable->setShortcut(
|
aIncrementAllCardCounters->setShortcut(shortcuts.getSingleShortcut("Player/aIncrementAllCardCounters"));
|
||||||
shortcuts.getSingleShortcut("Player/aIncrementAllCardCountersOnTable"));
|
|
||||||
aViewSideboard->setShortcut(shortcuts.getSingleShortcut("Player/aViewSideboard"));
|
aViewSideboard->setShortcut(shortcuts.getSingleShortcut("Player/aViewSideboard"));
|
||||||
aViewLibrary->setShortcut(shortcuts.getSingleShortcut("Player/aViewLibrary"));
|
aViewLibrary->setShortcut(shortcuts.getSingleShortcut("Player/aViewLibrary"));
|
||||||
aViewHand->setShortcut(shortcuts.getSingleShortcut("Player/aViewHand"));
|
aViewHand->setShortcut(shortcuts.getSingleShortcut("Player/aViewHand"));
|
||||||
|
|
@ -1090,7 +1089,7 @@ void Player::setShortcutsInactive()
|
||||||
aMoveBottomCardsToGraveyard->setShortcut(QKeySequence());
|
aMoveBottomCardsToGraveyard->setShortcut(QKeySequence());
|
||||||
aMoveBottomCardToExile->setShortcut(QKeySequence());
|
aMoveBottomCardToExile->setShortcut(QKeySequence());
|
||||||
aMoveBottomCardsToExile->setShortcut(QKeySequence());
|
aMoveBottomCardsToExile->setShortcut(QKeySequence());
|
||||||
aIncrementAllCardCountersOnTable->setShortcut(QKeySequence());
|
aIncrementAllCardCounters->setShortcut(QKeySequence());
|
||||||
|
|
||||||
QMapIterator<int, AbstractCounter *> counterIterator(counters);
|
QMapIterator<int, AbstractCounter *> counterIterator(counters);
|
||||||
while (counterIterator.hasNext()) {
|
while (counterIterator.hasNext()) {
|
||||||
|
|
@ -3045,21 +3044,48 @@ void Player::clearCounters()
|
||||||
counters.clear();
|
counters.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::incrementAllCardCountersOnTable()
|
void Player::incrementAllCardCounters()
|
||||||
{
|
{
|
||||||
// Get all cards on the table
|
QList<CardItem *> cardsToUpdate;
|
||||||
const CardList &tableCards = table->getCards();
|
|
||||||
|
|
||||||
for (CardItem *card : tableCards) {
|
auto selectedItems = scene()->selectedItems();
|
||||||
// Get all counters on this card
|
if (!selectedItems.isEmpty()) {
|
||||||
const QMap<int, int> &cardCounters = card->getCounters();
|
// If cards are selected, only update those
|
||||||
|
for (const auto &item : selectedItems) {
|
||||||
// Increment each existing counter by 1
|
auto *card = static_cast<CardItem *>(item);
|
||||||
for (auto it = cardCounters.begin(); it != cardCounters.end(); ++it) {
|
cardsToUpdate.append(card);
|
||||||
int counterId = it.key();
|
|
||||||
int currentValue = it.value();
|
|
||||||
card->setCounter(counterId, currentValue + 1);
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// If no cards selected, update all cards on table
|
||||||
|
const CardList &tableCards = table->getCards();
|
||||||
|
cardsToUpdate = tableCards;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<const ::google::protobuf::Message *> commandList;
|
||||||
|
|
||||||
|
for (const auto *card : cardsToUpdate) {
|
||||||
|
const auto &cardCounters = card->getCounters();
|
||||||
|
|
||||||
|
QMapIterator<int, int> counterIterator(cardCounters);
|
||||||
|
while (counterIterator.hasNext()) {
|
||||||
|
counterIterator.next();
|
||||||
|
int counterId = counterIterator.key();
|
||||||
|
int currentValue = counterIterator.value();
|
||||||
|
if (currentValue >= MAX_COUNTERS_ON_CARD) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto cmd = std::make_unique<Command_SetCardCounter>();
|
||||||
|
cmd->set_zone(card->getZone()->getName().toStdString());
|
||||||
|
cmd->set_card_id(card->getId());
|
||||||
|
cmd->set_counter_id(counterId);
|
||||||
|
cmd->set_counter_value(currentValue + 1);
|
||||||
|
commandList.append(cmd.release());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!commandList.isEmpty()) {
|
||||||
|
sendGameCommand(prepareGameCommand(commandList));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue