add action to select all cards in column (#5277)

* add action to select all cards in column

* change default shortcut to Ctrl+Shift+C
This commit is contained in:
RickyRister 2024-12-19 19:39:17 -08:00 committed by GitHub
parent 3514699f5b
commit a54a424f84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 7 deletions

View file

@ -516,6 +516,8 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, T
aSelectAll = new QAction(this); aSelectAll = new QAction(this);
connect(aSelectAll, SIGNAL(triggered()), this, SLOT(actSelectAll())); connect(aSelectAll, SIGNAL(triggered()), this, SLOT(actSelectAll()));
aSelectColumn = new QAction(this);
connect(aSelectColumn, SIGNAL(triggered()), this, SLOT(actSelectColumn()));
aPlay = new QAction(this); aPlay = new QAction(this);
connect(aPlay, SIGNAL(triggered()), this, SLOT(actPlay())); connect(aPlay, SIGNAL(triggered()), this, SLOT(actPlay()));
@ -841,6 +843,7 @@ void Player::retranslateUi()
} }
aSelectAll->setText(tr("&Select All")); aSelectAll->setText(tr("&Select All"));
aSelectColumn->setText(tr("S&elect Column"));
aPlay->setText(tr("&Play")); aPlay->setText(tr("&Play"));
aHide->setText(tr("&Hide")); aHide->setText(tr("&Hide"));
@ -930,6 +933,7 @@ void Player::setShortcutsActive()
aMoveToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveToExile")); aMoveToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveToExile"));
aSelectAll->setShortcuts(shortcuts.getShortcut("Player/aSelectAll")); aSelectAll->setShortcuts(shortcuts.getShortcut("Player/aSelectAll"));
aSelectColumn->setShortcuts(shortcuts.getShortcut("Player/aSelectColumn"));
QList<QKeySequence> addCCShortCuts; QList<QKeySequence> addCCShortCuts;
addCCShortCuts.append(shortcuts.getSingleShortcut("Player/aCCRed")); addCCShortCuts.append(shortcuts.getSingleShortcut("Player/aCCRed"));
@ -1565,6 +1569,27 @@ void Player::actMoveBottomCardToTop()
sendGameCommand(cmd); sendGameCommand(cmd);
} }
/**
* Selects all cards in the given zone.
*
* @param zone The zone to select from
* @param filter A predicate to filter which cards are selected. Defaults to always returning true.
*/
static void selectCardsInZone(
const CardZone *zone,
std::function<bool(const CardItem *)> filter = [](const CardItem *) { return true; })
{
if (!zone) {
return;
}
for (auto &cardItem : zone->getCards()) {
if (cardItem && filter(cardItem)) {
cardItem->setSelected(true);
}
}
}
void Player::actSelectAll() void Player::actSelectAll()
{ {
const CardItem *card = game->getActiveCard(); const CardItem *card = game->getActiveCard();
@ -1572,13 +1597,18 @@ void Player::actSelectAll()
return; return;
} }
if (const auto *zone = card->getZone()) { selectCardsInZone(card->getZone());
for (auto &cardItem : zone->getCards()) { }
if (cardItem) {
cardItem->setSelected(true); void Player::actSelectColumn()
} {
} const CardItem *card = game->getActiveCard();
if (!card) {
return;
} }
auto isSameColumn = [card](const CardItem *cardItem) { return cardItem->x() == card->x(); };
selectCardsInZone(card->getZone(), isSameColumn);
} }
void Player::actDrawBottomCard() void Player::actDrawBottomCard()
@ -3656,6 +3686,7 @@ void Player::updateCardMenu(const CardItem *card)
cardMenu->addAction(aClone); cardMenu->addAction(aClone);
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aSelectAll); cardMenu->addAction(aSelectAll);
cardMenu->addAction(aSelectColumn);
addRelatedCardView(card, cardMenu); addRelatedCardView(card, cardMenu);
} else if (writeableCard) { } else if (writeableCard) {
if (moveMenu->isEmpty()) { if (moveMenu->isEmpty()) {
@ -3747,6 +3778,7 @@ void Player::updateCardMenu(const CardItem *card)
cardMenu->addMenu(moveMenu); cardMenu->addMenu(moveMenu);
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aSelectAll); cardMenu->addAction(aSelectAll);
cardMenu->addAction(aSelectColumn);
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aAttach); cardMenu->addAction(aAttach);
@ -3776,6 +3808,9 @@ void Player::updateCardMenu(const CardItem *card)
cardMenu->addSeparator(); cardMenu->addSeparator();
cardMenu->addAction(aSelectAll); cardMenu->addAction(aSelectAll);
if (card->getZone()->getIsView()) {
cardMenu->addAction(aSelectColumn);
}
addRelatedCardView(card, cardMenu); addRelatedCardView(card, cardMenu);
} }

View file

@ -186,6 +186,7 @@ public slots:
void actMoveBottomCardToTop(); void actMoveBottomCardToTop();
void actSelectAll(); void actSelectAll();
void actSelectColumn();
void actViewLibrary(); void actViewLibrary();
void actViewHand(); void actViewHand();
@ -266,7 +267,7 @@ private:
QAction *aPlay, *aPlayFacedown, *aHide, *aTap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aResetPT, QAction *aPlay, *aPlayFacedown, *aHide, *aTap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aResetPT,
*aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aFlowP, *aFlowT, *aSetAnnotation, *aFlip, *aPeek, *aClone, *aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aFlowP, *aFlowT, *aSetAnnotation, *aFlip, *aPeek, *aClone,
*aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToExile, *aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToExile,
*aMoveToXfromTopOfLibrary, *aSelectAll; *aMoveToXfromTopOfLibrary, *aSelectAll, *aSelectColumn;
bool movingCardsUntil; bool movingCardsUntil;
QTimer *moveTopCardTimer; QTimer *moveTopCardTimer;

View file

@ -456,6 +456,9 @@ private:
{"Player/aSelectAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Select All Cards in Zone"), {"Player/aSelectAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Select All Cards in Zone"),
parseSequenceString("Ctrl+A"), parseSequenceString("Ctrl+A"),
ShortcutGroup::Playing_Area)}, ShortcutGroup::Playing_Area)},
{"Player/aSelectColumn", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Select All Cards in Column"),
parseSequenceString("Ctrl+Shift+C"),
ShortcutGroup::Playing_Area)},
{"Player/aMoveToBottomLibrary", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Bottom of Library"), {"Player/aMoveToBottomLibrary", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Bottom of Library"),
parseSequenceString("Ctrl+B"), parseSequenceString("Ctrl+B"),
ShortcutGroup::Move_selected)}, ShortcutGroup::Move_selected)},