From 4d652210dc63a7e4b3e56febd7003783a1f534e3 Mon Sep 17 00:00:00 2001 From: RickyRister <42636155+RickyRister@users.noreply.github.com> Date: Sun, 9 Nov 2025 03:34:09 -0800 Subject: [PATCH] Support shortcut for hand reveal actions (#6297) * Support shortcut for hand reveal actions * add docs --- .../src/client/settings/shortcuts_settings.h | 10 +++++++ cockatrice/src/game/player/menu/card_menu.cpp | 25 ++++++++++++----- cockatrice/src/game/player/menu/card_menu.h | 3 ++- cockatrice/src/game/player/menu/hand_menu.cpp | 27 ++++++++++++++----- cockatrice/src/game/player/menu/hand_menu.h | 3 +++ 5 files changed, 55 insertions(+), 13 deletions(-) diff --git a/cockatrice/src/client/settings/shortcuts_settings.h b/cockatrice/src/client/settings/shortcuts_settings.h index a1bdfd870..31e90bdc7 100644 --- a/cockatrice/src/client/settings/shortcuts_settings.h +++ b/cockatrice/src/client/settings/shortcuts_settings.h @@ -543,6 +543,9 @@ private: {"Player/aSelectColumn", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Select All Cards in Column"), parseSequenceString("Ctrl+Shift+C"), ShortcutGroup::Playing_Area)}, + {"Player/aRevealToAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Reveal Selected Cards to All Players"), + parseSequenceString(""), + ShortcutGroup::Playing_Area)}, {"Player/aMoveToBottomLibrary", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Bottom of Library"), parseSequenceString("Ctrl+B"), ShortcutGroup::Move_selected)}, @@ -681,6 +684,13 @@ private: {"Player/aSortHandByManaValue", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Sort Hand by Mana Value"), parseSequenceString(""), ShortcutGroup::Hand)}, + {"Player/aRevealHandToAll", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Reveal Hand to All Players"), + parseSequenceString(""), + ShortcutGroup::Hand)}, + {"Player/aRevealRandomHandCardToAll", + ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Reveal Random Card to All Players"), + parseSequenceString(""), + ShortcutGroup::Hand)}, {"Player/aRotateViewCW", ShortcutKey(QT_TRANSLATE_NOOP("shortcutsTab", "Rotate View Clockwise"), parseSequenceString(""), ShortcutGroup::Gameplay)}, diff --git a/cockatrice/src/game/player/menu/card_menu.cpp b/cockatrice/src/game/player/menu/card_menu.cpp index ed7854df2..ddf0a55f3 100644 --- a/cockatrice/src/game/player/menu/card_menu.cpp +++ b/cockatrice/src/game/player/menu/card_menu.cpp @@ -66,6 +66,8 @@ CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive aPlayFacedown = new QAction(this); connect(aPlayFacedown, &QAction::triggered, playerActions, &PlayerActions::actPlayFacedown); + aRevealToAll = new QAction(this); + mCardCounters = new QMenu; for (int i = 0; i < 6; ++i) { @@ -274,7 +276,7 @@ void CardMenu::createHandOrCustomZoneMenu() QMenu *revealMenu = addMenu(tr("Re&veal to...")); - initContextualPlayersMenu(revealMenu); + initContextualPlayersMenu(revealMenu, aRevealToAll); connect(revealMenu, &QMenu::triggered, player->getPlayerActions(), &PlayerActions::actReveal); @@ -301,9 +303,19 @@ void CardMenu::createHandOrCustomZoneMenu() } } -void CardMenu::initContextualPlayersMenu(QMenu *menu) +/** + * @brief Populates the menu with an action for each active player. + * + * The "all players" action is created separately, so it has to be passed into this function. + * It will be put at the top of the menu. + * + * @param menu The menu to add the player actions to. + * @param allPlayersAction The action for "all players". + */ +void CardMenu::initContextualPlayersMenu(QMenu *menu, QAction *allPlayersAction) { - menu->addAction(tr("&All players"))->setData(-1); + allPlayersAction->setData(-1); + menu->addAction(allPlayersAction); menu->addSeparator(); for (const auto &playerInfo : playersInfo) { @@ -431,6 +443,7 @@ void CardMenu::retranslateUi() aPlay->setText(tr("&Play")); aHide->setText(tr("&Hide")); aPlayFacedown->setText(tr("Play &Face Down")); + aRevealToAll->setText(tr("&All players")); //: Turn sideways or back again aTap->setText(tr("&Tap / Untap")); aDoesntUntap->setText(tr("Toggle &normal untapping")); @@ -466,6 +479,9 @@ void CardMenu::setShortcutsActive() aHide->setShortcuts(shortcuts.getShortcut("Player/aHide")); aPlay->setShortcuts(shortcuts.getShortcut("Player/aPlay")); + aPlayFacedown->setShortcuts(shortcuts.getShortcut("Player/aPlayFacedown")); + aRevealToAll->setShortcuts(shortcuts.getShortcut("Player/aRevealToAll")); + aTap->setShortcuts(shortcuts.getShortcut("Player/aTap")); aDoesntUntap->setShortcuts(shortcuts.getShortcut("Player/aDoesntUntap")); aFlip->setShortcuts(shortcuts.getShortcut("Player/aFlip")); @@ -480,9 +496,6 @@ void CardMenu::setShortcutsActive() aSelectRow->setShortcuts(shortcuts.getShortcut("Player/aSelectRow")); aSelectColumn->setShortcuts(shortcuts.getShortcut("Player/aSelectColumn")); - aPlayFacedown->setShortcuts(shortcuts.getShortcut("Player/aPlayFacedown")); - aPlay->setShortcuts(shortcuts.getShortcut("Player/aPlay")); - static const QStringList colorWords = {"Red", "Yellow", "Green", "Cyan", "Purple", "Magenta"}; for (int i = 0; i < aAddCounter.size(); i++) { aAddCounter[i]->setShortcuts(shortcuts.getShortcut("Player/aCC" + colorWords[i])); diff --git a/cockatrice/src/game/player/menu/card_menu.h b/cockatrice/src/game/player/menu/card_menu.h index d42cda5fb..afe24da62 100644 --- a/cockatrice/src/game/player/menu/card_menu.h +++ b/cockatrice/src/game/player/menu/card_menu.h @@ -26,6 +26,7 @@ public: QMenu *mCardCounters; QAction *aPlay, *aPlayFacedown; + QAction *aRevealToAll; QAction *aHide; QAction *aClone; QAction *aSelectAll, *aSelectRow, *aSelectColumn; @@ -45,7 +46,7 @@ private: void addRelatedCardActions(); void retranslateUi(); - void initContextualPlayersMenu(QMenu *menu); + void initContextualPlayersMenu(QMenu *menu, QAction *allPlayersAction); void setShortcutsActive(); void addRelatedCardView(); }; diff --git a/cockatrice/src/game/player/menu/hand_menu.cpp b/cockatrice/src/game/player/menu/hand_menu.cpp index e8554499a..e193d2e4a 100644 --- a/cockatrice/src/game/player/menu/hand_menu.cpp +++ b/cockatrice/src/game/player/menu/hand_menu.cpp @@ -38,10 +38,22 @@ HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : T mRevealHand = addMenu(QString()); connect(mRevealHand, &QMenu::aboutToShow, this, &HandMenu::populateRevealHandMenuWithActivePlayers); + aRevealHandToAll = new QAction(this); + aRevealHandToAll->setData(-1); + connect(aRevealHandToAll, &QAction::triggered, this, &HandMenu::onRevealHandTriggered); + mRevealRandomHandCard = addMenu(QString()); connect(mRevealRandomHandCard, &QMenu::aboutToShow, this, &HandMenu::populateRevealRandomHandCardMenuWithActivePlayers); + aRevealRandomHandCardToAll = new QAction(this); + aRevealRandomHandCardToAll->setData(-1); + connect(aRevealRandomHandCardToAll, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered); + + // We still need to add these actions to menu here so that the shortcuts are active right away + mRevealHand->addAction(aRevealHandToAll); + mRevealRandomHandCard->addAction(aRevealRandomHandCardToAll); + addSeparator(); aMulligan = new QAction(this); @@ -101,7 +113,10 @@ void HandMenu::retranslateUi() aMoveHandToRfg->setText(tr("&Exile")); mRevealHand->setTitle(tr("&Reveal hand to...")); + aRevealHandToAll->setText(tr("All players")); + mRevealRandomHandCard->setTitle(tr("Reveal r&andom card to...")); + aRevealRandomHandCardToAll->setText(tr("All players")); } } @@ -113,6 +128,8 @@ void HandMenu::setShortcutsActive() aSortHandByType->setShortcuts(shortcuts.getShortcut("Player/aSortHandByType")); aSortHandByManaValue->setShortcuts(shortcuts.getShortcut("Player/aSortHandByManaValue")); aMulligan->setShortcuts(shortcuts.getShortcut("Player/aMulligan")); + aRevealHandToAll->setShortcuts(shortcuts.getShortcut("Player/aRevealHandToAll")); + aRevealRandomHandCardToAll->setShortcuts(shortcuts.getShortcut("Player/aRevealRandomHandCardToAll")); } void HandMenu::setShortcutsInactive() @@ -122,15 +139,15 @@ void HandMenu::setShortcutsInactive() aSortHandByType->setShortcut(QKeySequence()); aSortHandByManaValue->setShortcut(QKeySequence()); aMulligan->setShortcut(QKeySequence()); + aRevealHandToAll->setShortcut(QKeySequence()); + aRevealRandomHandCardToAll->setShortcut(QKeySequence()); } void HandMenu::populateRevealHandMenuWithActivePlayers() { mRevealHand->clear(); - QAction *allPlayers = mRevealHand->addAction(tr("&All players")); - allPlayers->setData(-1); - connect(allPlayers, &QAction::triggered, this, &HandMenu::onRevealHandTriggered); + mRevealHand->addAction(aRevealHandToAll); mRevealHand->addSeparator(); @@ -148,9 +165,7 @@ void HandMenu::populateRevealRandomHandCardMenuWithActivePlayers() { mRevealRandomHandCard->clear(); - QAction *allPlayers = mRevealRandomHandCard->addAction(tr("&All players")); - allPlayers->setData(-1); - connect(allPlayers, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered); + mRevealRandomHandCard->addAction(aRevealRandomHandCardToAll); mRevealRandomHandCard->addSeparator(); diff --git a/cockatrice/src/game/player/menu/hand_menu.h b/cockatrice/src/game/player/menu/hand_menu.h index d20fc7cd4..2c776b857 100644 --- a/cockatrice/src/game/player/menu/hand_menu.h +++ b/cockatrice/src/game/player/menu/hand_menu.h @@ -53,7 +53,10 @@ private: QAction *aSortHandByManaValue = nullptr; QMenu *mRevealHand = nullptr; + QAction *aRevealHandToAll = nullptr; + QMenu *mRevealRandomHandCard = nullptr; + QAction *aRevealRandomHandCardToAll = nullptr; QMenu *mMoveHandMenu = nullptr; QAction *aMoveHandToTopLibrary = nullptr;