From cce6a9d6639d9b8cc94ab752b9a17ec6a55f41a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20Br=C3=BCbach?= Date: Fri, 12 Sep 2025 00:37:17 +0200 Subject: [PATCH] Refactor player menus into helper classes. Took 2 hours 6 minutes Took 11 minutes --- cockatrice/CMakeLists.txt | 7 +- cockatrice/src/game/player/player.cpp | 1 - cockatrice/src/game/player/player.h | 2 +- cockatrice/src/game/player/player_actions.cpp | 4 +- .../game/player/player_menu/grave_menu.cpp | 88 +++ .../src/game/player/player_menu/grave_menu.h | 33 ++ .../src/game/player/player_menu/hand_menu.cpp | 90 +++ .../src/game/player/player_menu/hand_menu.h | 44 ++ .../game/player/player_menu/library_menu.cpp | 284 +++++++++ .../game/player/player_menu/library_menu.h | 89 +++ .../player/{ => player_menu}/player_menu.cpp | 553 ++---------------- .../player/{ => player_menu}/player_menu.h | 56 +- .../src/game/player/player_menu/pt_menu.cpp | 76 +++ .../src/game/player/player_menu/pt_menu.h | 29 + .../src/game/player/player_menu/rfg_menu.cpp | 67 +++ .../src/game/player/player_menu/rfg_menu.h | 30 + 16 files changed, 893 insertions(+), 560 deletions(-) create mode 100644 cockatrice/src/game/player/player_menu/grave_menu.cpp create mode 100644 cockatrice/src/game/player/player_menu/grave_menu.h create mode 100644 cockatrice/src/game/player/player_menu/hand_menu.cpp create mode 100644 cockatrice/src/game/player/player_menu/hand_menu.h create mode 100644 cockatrice/src/game/player/player_menu/library_menu.cpp create mode 100644 cockatrice/src/game/player/player_menu/library_menu.h rename cockatrice/src/game/player/{ => player_menu}/player_menu.cpp (55%) rename cockatrice/src/game/player/{ => player_menu}/player_menu.h (55%) create mode 100644 cockatrice/src/game/player/player_menu/pt_menu.cpp create mode 100644 cockatrice/src/game/player/player_menu/pt_menu.h create mode 100644 cockatrice/src/game/player/player_menu/rfg_menu.cpp create mode 100644 cockatrice/src/game/player/player_menu/rfg_menu.h diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index dfe40b03d..9a8b6a301 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -232,8 +232,13 @@ set(cockatrice_SOURCES src/game/player/player_info.cpp src/game/player/player_list_widget.cpp src/game/player/player_manager.cpp - src/game/player/player_menu.cpp src/game/player/player_target.cpp + src/game/player/player_menu/grave_menu.cpp + src/game/player/player_menu/hand_menu.cpp + src/game/player/player_menu/library_menu.cpp + src/game/player/player_menu/player_menu.cpp + src/game/player/player_menu/pt_menu.cpp + src/game/player/player_menu/rfg_menu.cpp src/game/replay.cpp src/game/zones/card_zone.cpp src/game/zones/hand_zone.cpp diff --git a/cockatrice/src/game/player/player.cpp b/cockatrice/src/game/player/player.cpp index 17cc27a26..d176e9371 100644 --- a/cockatrice/src/game/player/player.cpp +++ b/cockatrice/src/game/player/player.cpp @@ -42,7 +42,6 @@ Player::Player(const ServerInfo_User &info, int _id, bool _local, bool _judge, A connect(this, &Player::activeChanged, graphicsItem, &PlayerGraphicsItem::onPlayerActiveChanged); - connect(this, &Player::deckChanged, playerMenu, &PlayerMenu::enableOpenInDeckEditorAction); connect(this, &Player::deckChanged, playerMenu, &PlayerMenu::populatePredefinedTokensMenu); connect(this, &Player::openDeckEditor, game->getTab(), &TabGame::openDeckEditor); diff --git a/cockatrice/src/game/player/player.h b/cockatrice/src/game/player/player.h index cd7d3f818..289f0a879 100644 --- a/cockatrice/src/game/player/player.h +++ b/cockatrice/src/game/player/player.h @@ -13,7 +13,7 @@ #include "player_event_handler.h" #include "player_graphics_item.h" #include "player_info.h" -#include "player_menu.h" +#include "player_menu/player_menu.h" #include #include diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index 6c723805f..6c63e2ef3 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -172,7 +172,7 @@ void PlayerActions::actAlwaysRevealTopCard() { Command_ChangeZoneProperties cmd; cmd.set_zone_name("deck"); - cmd.set_always_reveal_top_card(player->getPlayerMenu()->isAlwaysRevealTopCardChecked()); + cmd.set_always_reveal_top_card(player->getPlayerMenu()->getLibraryMenu()->isAlwaysRevealTopCardChecked()); sendGameCommand(cmd); } @@ -181,7 +181,7 @@ void PlayerActions::actAlwaysLookAtTopCard() { Command_ChangeZoneProperties cmd; cmd.set_zone_name("deck"); - cmd.set_always_look_at_top_card(player->getPlayerMenu()->isAlwaysLookAtTopCardChecked()); + cmd.set_always_look_at_top_card(player->getPlayerMenu()->getLibraryMenu()->isAlwaysLookAtTopCardChecked()); sendGameCommand(cmd); } diff --git a/cockatrice/src/game/player/player_menu/grave_menu.cpp b/cockatrice/src/game/player/player_menu/grave_menu.cpp new file mode 100644 index 000000000..24ca9c824 --- /dev/null +++ b/cockatrice/src/game/player/player_menu/grave_menu.cpp @@ -0,0 +1,88 @@ +#include "grave_menu.h" + +#include "../player.h" +#include "../player_actions.h" + +GraveyardMenu::GraveyardMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player) +{ + createMoveActions(); + createViewActions(); + + addAction(aViewGraveyard); + + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + mRevealRandomGraveyardCard = addMenu(QString()); + QAction *newAction = mRevealRandomGraveyardCard->addAction(QString()); + newAction->setData(-1); + connect(newAction, &QAction::triggered, player->getPlayerActions(), + &PlayerActions::actRevealRandomGraveyardCard); + // allPlayersActions.append(newAction); + mRevealRandomGraveyardCard->addSeparator(); + + addSeparator(); + moveGraveMenu = addTearOffMenu(QString()); + moveGraveMenu->addAction(aMoveGraveToTopLibrary); + moveGraveMenu->addAction(aMoveGraveToBottomLibrary); + moveGraveMenu->addSeparator(); + moveGraveMenu->addAction(aMoveGraveToHand); + moveGraveMenu->addSeparator(); + moveGraveMenu->addAction(aMoveGraveToRfg); + } + + retranslateUi(); +} + +void GraveyardMenu::createMoveActions() +{ + auto grave = player->getGraveZone(); + + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + aMoveGraveToTopLibrary = new QAction(this); + aMoveGraveToTopLibrary->setData(QList() << "deck" << 0); + aMoveGraveToBottomLibrary = new QAction(this); + aMoveGraveToBottomLibrary->setData(QList() << "deck" << -1); + aMoveGraveToHand = new QAction(this); + aMoveGraveToHand->setData(QList() << "hand" << 0); + aMoveGraveToRfg = new QAction(this); + aMoveGraveToRfg->setData(QList() << "rfg" << 0); + + connect(aMoveGraveToTopLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); + connect(aMoveGraveToBottomLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); + connect(aMoveGraveToHand, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); + connect(aMoveGraveToRfg, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); + } +} + +void GraveyardMenu::createViewActions() +{ + PlayerActions *playerActions = player->getPlayerActions(); + + aViewGraveyard = new QAction(this); + connect(aViewGraveyard, &QAction::triggered, playerActions, &PlayerActions::actViewGraveyard); +} + +void GraveyardMenu::retranslateUi() +{ + aViewGraveyard->setText(tr("&View graveyard")); + + if (player->getPlayerInfo()->getLocalOrJudge()) { + moveGraveMenu->setTitle(tr("&Move graveyard to...")); + aMoveGraveToTopLibrary->setText(tr("&Top of library")); + aMoveGraveToBottomLibrary->setText(tr("&Bottom of library")); + aMoveGraveToHand->setText(tr("&Hand")); + aMoveGraveToRfg->setText(tr("&Exile")); + mRevealRandomGraveyardCard->setTitle(tr("Reveal random card to...")); + } +} + +void GraveyardMenu::setShortcutsActive() +{ + ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts(); + + aViewGraveyard->setShortcuts(shortcuts.getShortcut("Player/aViewGraveyard")); +} + +void GraveyardMenu::setShortcutsInactive() +{ + aViewGraveyard->setShortcut(QKeySequence()); +} \ No newline at end of file diff --git a/cockatrice/src/game/player/player_menu/grave_menu.h b/cockatrice/src/game/player/player_menu/grave_menu.h new file mode 100644 index 000000000..d2f7cb4a6 --- /dev/null +++ b/cockatrice/src/game/player/player_menu/grave_menu.h @@ -0,0 +1,33 @@ +#ifndef COCKATRICE_GRAVE_MENU_H +#define COCKATRICE_GRAVE_MENU_H + +#include "../../../client/tearoff_menu.h" + +#include +#include + +class Player; +class GraveyardMenu : public TearOffMenu { + Q_OBJECT +public: + explicit GraveyardMenu(Player* player, QWidget* parent = nullptr); + void createMoveActions(); + void createViewActions(); + void retranslateUi(); + void setShortcutsActive(); + void setShortcutsInactive(); + + QMenu * mRevealRandomGraveyardCard = nullptr; + QMenu* moveGraveMenu = nullptr; + + QAction* aViewGraveyard = nullptr; + QAction* aMoveGraveToTopLibrary = nullptr; + QAction* aMoveGraveToBottomLibrary = nullptr; + QAction* aMoveGraveToHand = nullptr; + QAction* aMoveGraveToRfg = nullptr; + +private: + Player* player; +}; + +#endif // COCKATRICE_GRAVE_MENU_H diff --git a/cockatrice/src/game/player/player_menu/hand_menu.cpp b/cockatrice/src/game/player/player_menu/hand_menu.cpp new file mode 100644 index 000000000..ea2627b1b --- /dev/null +++ b/cockatrice/src/game/player/player_menu/hand_menu.cpp @@ -0,0 +1,90 @@ +#include "hand_menu.h" + +#include "../player.h" +#include "../player_actions.h" + +HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : TearOffMenu(parent), player(_player) +{ + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + aViewHand = new QAction(this); + connect(aViewHand, &QAction::triggered, actions, &PlayerActions::actViewHand); + addAction(aViewHand); + + aSortHand = new QAction(this); + connect(aSortHand, &QAction::triggered, actions, &PlayerActions::actSortHand); + addAction(aSortHand); + } + + mRevealHand = addMenu(QString()); + mRevealRandomHandCard = addMenu(QString()); + addSeparator(); + + aMulligan = new QAction(this); + connect(aMulligan, &QAction::triggered, actions, &PlayerActions::actMulligan); + addAction(aMulligan); + + addSeparator(); + + mMoveHandMenu = addTearOffMenu(QString()); + + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + aMoveHandToTopLibrary = new QAction(this); + aMoveHandToTopLibrary->setData(QList() << "deck" << 0); + aMoveHandToBottomLibrary = new QAction(this); + aMoveHandToBottomLibrary->setData(QList() << "deck" << -1); + aMoveHandToGrave = new QAction(this); + aMoveHandToGrave->setData(QList() << "grave" << 0); + aMoveHandToRfg = new QAction(this); + aMoveHandToRfg->setData(QList() << "rfg" << 0); + + auto hand = player->getHandZone(); + + connect(aMoveHandToTopLibrary, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); + connect(aMoveHandToBottomLibrary, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); + connect(aMoveHandToGrave, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); + connect(aMoveHandToRfg, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); + + mMoveHandMenu->addAction(aMoveHandToTopLibrary); + mMoveHandMenu->addAction(aMoveHandToBottomLibrary); + mMoveHandMenu->addSeparator(); + mMoveHandMenu->addAction(aMoveHandToGrave); + mMoveHandMenu->addSeparator(); + mMoveHandMenu->addAction(aMoveHandToRfg); + } + + retranslateUi(); +} + +void HandMenu::retranslateUi() +{ + if (player->getPlayerInfo()->getLocalOrJudge()) { + aViewHand->setText(tr("&View hand")); + aSortHand->setText(tr("&Sort hand")); + aMulligan->setText(tr("Take &mulligan")); + + mMoveHandMenu->setTitle(tr("&Move hand to...")); + aMoveHandToTopLibrary->setText(tr("&Top of library")); + aMoveHandToBottomLibrary->setText(tr("&Bottom of library")); + aMoveHandToGrave->setText(tr("&Graveyard")); + aMoveHandToRfg->setText(tr("&Exile")); + + mRevealHand->setTitle(tr("&Reveal hand to...")); + mRevealRandomHandCard->setTitle(tr("Reveal r&andom card to...")); + } +} + +void HandMenu::setShortcutsActive() +{ + ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts(); + + aViewHand->setShortcuts(shortcuts.getShortcut("Player/aViewHand")); + aSortHand->setShortcuts(shortcuts.getShortcut("Player/aSortHand")); + aMulligan->setShortcuts(shortcuts.getShortcut("Player/aMulligan")); +} + +void HandMenu::setShortcutsInactive() +{ + aViewHand->setShortcut(QKeySequence()); + aSortHand->setShortcut(QKeySequence()); + aMulligan->setShortcut(QKeySequence()); +} diff --git a/cockatrice/src/game/player/player_menu/hand_menu.h b/cockatrice/src/game/player/player_menu/hand_menu.h new file mode 100644 index 000000000..232f732bb --- /dev/null +++ b/cockatrice/src/game/player/player_menu/hand_menu.h @@ -0,0 +1,44 @@ +#ifndef COCKATRICE_HAND_MENU_H +#define COCKATRICE_HAND_MENU_H + +#include "../../../client/tearoff_menu.h" + +#include +#include + +class Player; +class PlayerActions; + +class HandMenu : public TearOffMenu +{ + Q_OBJECT +public: + explicit HandMenu(Player* player, PlayerActions* actions, QWidget* parent = nullptr); + void retranslateUi(); + void setShortcutsActive(); + void setShortcutsInactive(); + + // expose useful actions/menus if PlayerMenu needs them + QMenu* revealHandMenu() const { return mRevealHand; } + QMenu* revealRandomHandCardMenu() const { return mRevealRandomHandCard; } + QMenu* moveHandMenu() const { return mMoveHandMenu; } + +private: + Player *player; + + QAction* aViewHand = nullptr; + QAction* aSortHand = nullptr; + QAction* aMulligan = nullptr; + + QMenu* mRevealHand = nullptr; + QMenu* mRevealRandomHandCard = nullptr; + QMenu* mMoveHandMenu = nullptr; + + QAction* aMoveHandToTopLibrary = nullptr; + QAction* aMoveHandToBottomLibrary = nullptr; + QAction* aMoveHandToGrave = nullptr; + QAction* aMoveHandToRfg = nullptr; +}; + + +#endif // COCKATRICE_HAND_MENU_H diff --git a/cockatrice/src/game/player/player_menu/library_menu.cpp b/cockatrice/src/game/player/player_menu/library_menu.cpp new file mode 100644 index 000000000..aa4b7b10b --- /dev/null +++ b/cockatrice/src/game/player/player_menu/library_menu.cpp @@ -0,0 +1,284 @@ +#include "library_menu.h" + +#include "../player.h" +#include "../player_actions.h" + +LibraryMenu::LibraryMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player) +{ + createDrawActions(); + createShuffleActions(); + createMoveActions(); + createViewActions(); + + addAction(aDrawCard); + addAction(aDrawCards); + addAction(aUndoDraw); + addSeparator(); + addAction(aShuffle); + addSeparator(); + addAction(aViewLibrary); + addAction(aViewTopCards); + addAction(aViewBottomCards); + addSeparator(); + // playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString())); + mRevealLibrary = addMenu(QString()); + // singlePlayerLists.append(mLendLibrary = libraryMenu->addMenu(QString())); + mLendLibrary = addMenu(QString()); + // playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString())); + mRevealTopCard = addMenu(QString()); + addAction(aAlwaysRevealTopCard); + addAction(aAlwaysLookAtTopCard); + addSeparator(); + topLibraryMenu = addTearOffMenu(QString()); + bottomLibraryMenu = addTearOffMenu(QString()); + addSeparator(); + addAction(aOpenDeckInDeckEditor); + topLibraryMenu->addAction(aMoveTopToPlay); + topLibraryMenu->addAction(aMoveTopToPlayFaceDown); + topLibraryMenu->addAction(aMoveTopCardToBottom); + topLibraryMenu->addSeparator(); + topLibraryMenu->addAction(aMoveTopCardToGraveyard); + topLibraryMenu->addAction(aMoveTopCardsToGraveyard); + topLibraryMenu->addAction(aMoveTopCardToExile); + topLibraryMenu->addAction(aMoveTopCardsToExile); + topLibraryMenu->addAction(aMoveTopCardsUntil); + topLibraryMenu->addSeparator(); + topLibraryMenu->addAction(aShuffleTopCards); + + bottomLibraryMenu->addAction(aDrawBottomCard); + bottomLibraryMenu->addAction(aDrawBottomCards); + bottomLibraryMenu->addSeparator(); + bottomLibraryMenu->addAction(aMoveBottomToPlay); + bottomLibraryMenu->addAction(aMoveBottomToPlayFaceDown); + bottomLibraryMenu->addAction(aMoveBottomCardToTop); + bottomLibraryMenu->addSeparator(); + bottomLibraryMenu->addAction(aMoveBottomCardToGraveyard); + bottomLibraryMenu->addAction(aMoveBottomCardsToGraveyard); + bottomLibraryMenu->addAction(aMoveBottomCardToExile); + bottomLibraryMenu->addAction(aMoveBottomCardsToExile); + bottomLibraryMenu->addSeparator(); + bottomLibraryMenu->addAction(aShuffleBottomCards); + + connect(player, &Player::resetTopCardMenuActions, this, &LibraryMenu::resetTopCardMenuActions); + connect(player, &Player::deckChanged, this, &LibraryMenu::enableOpenInDeckEditorAction); + + retranslateUi(); +} + +void LibraryMenu::enableOpenInDeckEditorAction() const +{ + aOpenDeckInDeckEditor->setEnabled(true); +} + +void LibraryMenu::resetTopCardMenuActions() +{ + aAlwaysRevealTopCard->setChecked(false); + aAlwaysLookAtTopCard->setChecked(false); +} + +void LibraryMenu::createDrawActions() +{ + PlayerActions *playerActions = player->getPlayerActions(); + + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + aDrawCard = new QAction(this); + connect(aDrawCard, &QAction::triggered, playerActions, &PlayerActions::actDrawCard); + aDrawCards = new QAction(this); + connect(aDrawCards, &QAction::triggered, playerActions, &PlayerActions::actDrawCards); + aUndoDraw = new QAction(this); + connect(aUndoDraw, &QAction::triggered, playerActions, &PlayerActions::actUndoDraw); + aDrawBottomCard = new QAction(this); + connect(aDrawBottomCard, &QAction::triggered, playerActions, &PlayerActions::actDrawBottomCard); + aDrawBottomCards = new QAction(this); + connect(aDrawBottomCards, &QAction::triggered, playerActions, &PlayerActions::actDrawBottomCards); + } +} + +void LibraryMenu::createShuffleActions() +{ + PlayerActions *playerActions = player->getPlayerActions(); + + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + aShuffle = new QAction(this); + connect(aShuffle, &QAction::triggered, playerActions, &PlayerActions::actShuffle); + aShuffleTopCards = new QAction(this); + connect(aShuffleTopCards, &QAction::triggered, playerActions, &PlayerActions::actShuffleTop); + aShuffleBottomCards = new QAction(this); + connect(aShuffleBottomCards, &QAction::triggered, playerActions, &PlayerActions::actShuffleBottom); + } +} + +void LibraryMenu::createMoveActions() +{ + PlayerActions *playerActions = player->getPlayerActions(); + + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + aMoveTopToPlay = new QAction(this); + connect(aMoveTopToPlay, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToPlay); + aMoveTopToPlayFaceDown = new QAction(this); + connect(aMoveTopToPlayFaceDown, &QAction::triggered, playerActions, + &PlayerActions::actMoveTopCardToPlayFaceDown); + aMoveTopCardToGraveyard = new QAction(this); + connect(aMoveTopCardToGraveyard, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToGrave); + aMoveTopCardToExile = new QAction(this); + connect(aMoveTopCardToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToExile); + aMoveTopCardsToGraveyard = new QAction(this); + connect(aMoveTopCardsToGraveyard, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsToGrave); + aMoveTopCardsToExile = new QAction(this); + connect(aMoveTopCardsToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsToExile); + aMoveTopCardsUntil = new QAction(this); + connect(aMoveTopCardsUntil, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsUntil); + aMoveTopCardToBottom = new QAction(this); + connect(aMoveTopCardToBottom, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToBottom); + + aMoveBottomToPlay = new QAction(this); + connect(aMoveBottomToPlay, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToPlay); + aMoveBottomToPlayFaceDown = new QAction(this); + connect(aMoveBottomToPlayFaceDown, &QAction::triggered, playerActions, + &PlayerActions::actMoveBottomCardToPlayFaceDown); + aMoveBottomCardToGraveyard = new QAction(this); + connect(aMoveBottomCardToGraveyard, &QAction::triggered, playerActions, + &PlayerActions::actMoveBottomCardToGrave); + aMoveBottomCardToExile = new QAction(this); + connect(aMoveBottomCardToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToExile); + aMoveBottomCardsToGraveyard = new QAction(this); + connect(aMoveBottomCardsToGraveyard, &QAction::triggered, playerActions, + &PlayerActions::actMoveBottomCardsToGrave); + aMoveBottomCardsToExile = new QAction(this); + connect(aMoveBottomCardsToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardsToExile); + aMoveBottomCardToTop = new QAction(this); + connect(aMoveBottomCardToTop, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToTop); + } +} + +void LibraryMenu::createViewActions() +{ + PlayerActions *playerActions = player->getPlayerActions(); + + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + aViewLibrary = new QAction(this); + connect(aViewLibrary, &QAction::triggered, playerActions, &PlayerActions::actViewLibrary); + + aViewTopCards = new QAction(this); + connect(aViewTopCards, &QAction::triggered, playerActions, &PlayerActions::actViewTopCards); + aViewBottomCards = new QAction(this); + connect(aViewBottomCards, &QAction::triggered, playerActions, &PlayerActions::actViewBottomCards); + aAlwaysRevealTopCard = new QAction(this); + aAlwaysRevealTopCard->setCheckable(true); + connect(aAlwaysRevealTopCard, &QAction::triggered, playerActions, &PlayerActions::actAlwaysRevealTopCard); + aAlwaysLookAtTopCard = new QAction(this); + aAlwaysLookAtTopCard->setCheckable(true); + connect(aAlwaysLookAtTopCard, &QAction::triggered, playerActions, &PlayerActions::actAlwaysLookAtTopCard); + aOpenDeckInDeckEditor = new QAction(this); + aOpenDeckInDeckEditor->setEnabled(false); + connect(aOpenDeckInDeckEditor, &QAction::triggered, playerActions, &PlayerActions::actOpenDeckInDeckEditor); + } +} + +void LibraryMenu::retranslateUi() +{ + if (player->getPlayerInfo()->getLocalOrJudge()) { + aViewLibrary->setText(tr("&View library")); + aViewTopCards->setText(tr("View &top cards of library...")); + aViewBottomCards->setText(tr("View bottom cards of library...")); + mRevealLibrary->setTitle(tr("Reveal &library to...")); + mLendLibrary->setTitle(tr("Lend library to...")); + mRevealTopCard->setTitle(tr("Reveal &top cards to...")); + topLibraryMenu->setTitle(tr("&Top of library...")); + bottomLibraryMenu->setTitle(tr("&Bottom of library...")); + aAlwaysRevealTopCard->setText(tr("&Always reveal top card")); + aAlwaysLookAtTopCard->setText(tr("&Always look at top card")); + aOpenDeckInDeckEditor->setText(tr("&Open deck in deck editor")); + + aDrawCard->setText(tr("&Draw card")); + aDrawCards->setText(tr("D&raw cards...")); + aUndoDraw->setText(tr("&Undo last draw")); + + aShuffle->setText(tr("Shuffle")); + + aMoveTopToPlay->setText(tr("&Play top card")); + aMoveTopToPlayFaceDown->setText(tr("Play top card &face down")); + aMoveTopCardToBottom->setText(tr("Put top card on &bottom")); + aMoveTopCardToGraveyard->setText(tr("Move top card to grave&yard")); + aMoveTopCardToExile->setText(tr("Move top card to e&xile")); + aMoveTopCardsToGraveyard->setText(tr("Move top cards to &graveyard...")); + aMoveTopCardsToExile->setText(tr("Move top cards to &exile...")); + aMoveTopCardsUntil->setText(tr("Put top cards on stack &until...")); + aShuffleTopCards->setText(tr("Shuffle top cards...")); + + aDrawBottomCard->setText(tr("&Draw bottom card")); + aDrawBottomCards->setText(tr("D&raw bottom cards...")); + aMoveBottomToPlay->setText(tr("&Play bottom card")); + aMoveBottomToPlayFaceDown->setText(tr("Play bottom card &face down")); + aMoveBottomCardToGraveyard->setText(tr("Move bottom card to grave&yard")); + aMoveBottomCardToExile->setText(tr("Move bottom card to e&xile")); + aMoveBottomCardsToGraveyard->setText(tr("Move bottom cards to &graveyard...")); + aMoveBottomCardsToExile->setText(tr("Move bottom cards to &exile...")); + aMoveBottomCardToTop->setText(tr("Put bottom card on &top")); + aShuffleBottomCards->setText(tr("Shuffle bottom cards...")); + } +} + +void LibraryMenu::setShortcutsActive() +{ + ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts(); + + aViewLibrary->setShortcuts(shortcuts.getShortcut("Player/aViewLibrary")); + aViewTopCards->setShortcuts(shortcuts.getShortcut("Player/aViewTopCards")); + aViewBottomCards->setShortcuts(shortcuts.getShortcut("Player/aViewBottomCards")); + aDrawCard->setShortcuts(shortcuts.getShortcut("Player/aDrawCard")); + aDrawCards->setShortcuts(shortcuts.getShortcut("Player/aDrawCards")); + aUndoDraw->setShortcuts(shortcuts.getShortcut("Player/aUndoDraw")); + aShuffle->setShortcuts(shortcuts.getShortcut("Player/aShuffle")); + aShuffleTopCards->setShortcuts(shortcuts.getShortcut("Player/aShuffleTopCards")); + aShuffleBottomCards->setShortcuts(shortcuts.getShortcut("Player/aShuffleBottomCards")); + aAlwaysRevealTopCard->setShortcuts(shortcuts.getShortcut("Player/aAlwaysRevealTopCard")); + aAlwaysLookAtTopCard->setShortcuts(shortcuts.getShortcut("Player/aAlwaysLookAtTopCard")); + aMoveTopToPlay->setShortcuts(shortcuts.getShortcut("Player/aMoveTopToPlay")); + aMoveTopToPlayFaceDown->setShortcuts(shortcuts.getShortcut("Player/aMoveTopToPlayFaceDown")); + aMoveTopCardToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardToGraveyard")); + aMoveTopCardsToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardsToGraveyard")); + aMoveTopCardToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardToExile")); + aMoveTopCardsToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardsToExile")); + aMoveTopCardsUntil->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardsUntil")); + aMoveTopCardToBottom->setShortcuts(shortcuts.getShortcut("Player/aMoveTopCardToBottom")); + aDrawBottomCard->setShortcuts(shortcuts.getShortcut("Player/aDrawBottomCard")); + aDrawBottomCards->setShortcuts(shortcuts.getShortcut("Player/aDrawBottomCards")); + aMoveBottomToPlay->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomToPlay")); + aMoveBottomToPlayFaceDown->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomToPlayFaceDown")); + aMoveBottomCardToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardToGrave")); + aMoveBottomCardsToGraveyard->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardsToGrave")); + aMoveBottomCardToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardToExile")); + aMoveBottomCardsToExile->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardsToExile")); + aMoveBottomCardToTop->setShortcuts(shortcuts.getShortcut("Player/aMoveBottomCardToTop")); +} + +void LibraryMenu::setShortcutsInactive() +{ + aViewLibrary->setShortcut(QKeySequence()); + aViewTopCards->setShortcut(QKeySequence()); + aViewBottomCards->setShortcut(QKeySequence()); + aDrawCard->setShortcut(QKeySequence()); + aDrawCards->setShortcut(QKeySequence()); + aUndoDraw->setShortcut(QKeySequence()); + aShuffle->setShortcut(QKeySequence()); + aShuffleTopCards->setShortcut(QKeySequence()); + aShuffleBottomCards->setShortcut(QKeySequence()); + aAlwaysRevealTopCard->setShortcut(QKeySequence()); + aAlwaysLookAtTopCard->setShortcut(QKeySequence()); + aMoveTopToPlay->setShortcut(QKeySequence()); + aMoveTopToPlayFaceDown->setShortcut(QKeySequence()); + aMoveTopCardToGraveyard->setShortcut(QKeySequence()); + aMoveTopCardsToGraveyard->setShortcut(QKeySequence()); + aMoveTopCardToExile->setShortcut(QKeySequence()); + aMoveTopCardsToExile->setShortcut(QKeySequence()); + aMoveTopCardsUntil->setShortcut(QKeySequence()); + aDrawBottomCard->setShortcut(QKeySequence()); + aDrawBottomCards->setShortcut(QKeySequence()); + aMoveBottomToPlay->setShortcut(QKeySequence()); + aMoveBottomToPlayFaceDown->setShortcut(QKeySequence()); + aMoveBottomCardToGraveyard->setShortcut(QKeySequence()); + aMoveBottomCardsToGraveyard->setShortcut(QKeySequence()); + aMoveBottomCardToExile->setShortcut(QKeySequence()); + aMoveBottomCardsToExile->setShortcut(QKeySequence()); +} \ No newline at end of file diff --git a/cockatrice/src/game/player/player_menu/library_menu.h b/cockatrice/src/game/player/player_menu/library_menu.h new file mode 100644 index 000000000..75fd4d28f --- /dev/null +++ b/cockatrice/src/game/player/player_menu/library_menu.h @@ -0,0 +1,89 @@ +#ifndef COCKATRICE_LIBRARY_MENU_H +#define COCKATRICE_LIBRARY_MENU_H + +#include "../../../client/tearoff_menu.h" + +#include +#include + +class Player; +class PlayerActions; + +class LibraryMenu : public TearOffMenu +{ + Q_OBJECT +public slots: + void enableOpenInDeckEditorAction() const; + void resetTopCardMenuActions(); + +public: + LibraryMenu(Player *player, QWidget *parent = nullptr); + void createDrawActions(); + void createShuffleActions(); + void createMoveActions(); + void createViewActions(); + void retranslateUi(); + void setShortcutsActive(); + void setShortcutsInactive(); + + [[nodiscard]] bool isAlwaysRevealTopCardChecked() const + { + return aAlwaysRevealTopCard->isChecked(); + } + + [[nodiscard]] bool isAlwaysLookAtTopCardChecked() const + { + return aAlwaysLookAtTopCard->isChecked(); + } + + // expose useful actions/menus if PlayerMenu needs them + QMenu* revealLibrary() const { return mRevealLibrary; } + QMenu* lendLibraryMenu() const { return mLendLibrary; } + QMenu* revealTopCardMenu() const { return mRevealTopCard; } + + QMenu *topLibraryMenu = nullptr; + QMenu *bottomLibraryMenu = nullptr; + + // Expose submenus that PlayerMenu tracks in its lists + QMenu *mRevealLibrary = nullptr; + QMenu *mLendLibrary = nullptr; + QMenu *mRevealTopCard = nullptr; + + QAction *aDrawCard = nullptr; + QAction *aDrawCards = nullptr; + QAction *aUndoDraw = nullptr; + + QAction *aShuffle = nullptr; + QAction *aViewLibrary = nullptr; + QAction *aViewTopCards = nullptr; + QAction *aViewBottomCards = nullptr; + QAction *aAlwaysRevealTopCard = nullptr; + QAction *aAlwaysLookAtTopCard = nullptr; + QAction *aOpenDeckInDeckEditor = nullptr; + + QAction *aMoveTopToPlay = nullptr; + QAction *aMoveTopToPlayFaceDown = nullptr; + QAction *aMoveTopCardToBottom = nullptr; + QAction *aMoveTopCardToGraveyard = nullptr; + QAction *aMoveTopCardToExile = nullptr; + QAction *aMoveTopCardsToGraveyard = nullptr; + QAction *aMoveTopCardsToExile = nullptr; + QAction *aMoveTopCardsUntil = nullptr; + QAction *aShuffleTopCards = nullptr; + + QAction *aDrawBottomCard = nullptr; + QAction *aDrawBottomCards = nullptr; + QAction *aMoveBottomToPlay = nullptr; + QAction *aMoveBottomToPlayFaceDown = nullptr; + QAction *aMoveBottomCardToTop = nullptr; + QAction *aMoveBottomCardToGraveyard = nullptr; + QAction *aMoveBottomCardToExile = nullptr; + QAction *aMoveBottomCardsToGraveyard = nullptr; + QAction *aMoveBottomCardsToExile = nullptr; + QAction *aShuffleBottomCards = nullptr; + +private: + Player *player; +}; + +#endif // COCKATRICE_LIBRARY_MENU_H diff --git a/cockatrice/src/game/player/player_menu.cpp b/cockatrice/src/game/player/player_menu/player_menu.cpp similarity index 55% rename from cockatrice/src/game/player/player_menu.cpp rename to cockatrice/src/game/player/player_menu/player_menu.cpp index 0c7588824..1e40b16db 100644 --- a/cockatrice/src/game/player/player_menu.cpp +++ b/cockatrice/src/game/player/player_menu/player_menu.cpp @@ -1,14 +1,16 @@ #include "player_menu.h" +#include "../../../client/tabs/tab_game.h" #include "../../../common/pb/command_reveal_cards.pb.h" -#include "../../client/tabs/tab_game.h" -#include "../../settings/card_counter_settings.h" -#include "../board/card_item.h" -#include "../cards/card_database_manager.h" -#include "../zones/hand_zone.h" -#include "../zones/logic/view_zone_logic.h" -#include "card_menu_action_type.h" -#include "player_actions.h" +#include "../../../settings/card_counter_settings.h" +#include "../../board/card_item.h" +#include "../../cards/card_database_manager.h" +#include "../../zones/hand_zone.h" +#include "../../zones/logic/view_zone_logic.h" +#include "../card_menu_action_type.h" +#include "../player_actions.h" +#include "hand_menu.h" +#include "pt_menu.h" PlayerMenu::PlayerMenu(Player *_player) : player(_player) { @@ -25,112 +27,27 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player) PlayerActions *playerActions = player->getPlayerActions(); - createDrawActions(); - createShuffleActions(); - createMoveActions(); createViewActions(); playerMenu = new TearOffMenu(); if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { - handMenu = playerMenu->addTearOffMenu(QString()); - handMenu->addAction(aViewHand); - handMenu->addAction(aSortHand); - playerLists.append(mRevealHand = handMenu->addMenu(QString())); - playerLists.append(mRevealRandomHandCard = handMenu->addMenu(QString())); - handMenu->addSeparator(); - handMenu->addAction(aMulligan); - handMenu->addSeparator(); - moveHandMenu = handMenu->addTearOffMenu(QString()); - moveHandMenu->addAction(aMoveHandToTopLibrary); - moveHandMenu->addAction(aMoveHandToBottomLibrary); - moveHandMenu->addSeparator(); - moveHandMenu->addAction(aMoveHandToGrave); - moveHandMenu->addSeparator(); - moveHandMenu->addAction(aMoveHandToRfg); + handMenu = new HandMenu(player, player->getPlayerActions(), playerMenu); + playerMenu->addMenu(handMenu); + /*playerLists.append(mRevealHand = handMenu->addMenu(QString())); + playerLists.append(mRevealRandomHandCard = handMenu->addMenu(QString()));*/ - libraryMenu = playerMenu->addTearOffMenu(QString()); - libraryMenu->addAction(aDrawCard); - libraryMenu->addAction(aDrawCards); - libraryMenu->addAction(aUndoDraw); - libraryMenu->addSeparator(); - libraryMenu->addAction(aShuffle); - libraryMenu->addSeparator(); - libraryMenu->addAction(aViewLibrary); - libraryMenu->addAction(aViewTopCards); - libraryMenu->addAction(aViewBottomCards); - libraryMenu->addSeparator(); - playerLists.append(mRevealLibrary = libraryMenu->addMenu(QString())); - singlePlayerLists.append(mLendLibrary = libraryMenu->addMenu(QString())); - playerLists.append(mRevealTopCard = libraryMenu->addMenu(QString())); - libraryMenu->addAction(aAlwaysRevealTopCard); - libraryMenu->addAction(aAlwaysLookAtTopCard); - libraryMenu->addSeparator(); - topLibraryMenu = libraryMenu->addTearOffMenu(QString()); - bottomLibraryMenu = libraryMenu->addTearOffMenu(QString()); - libraryMenu->addSeparator(); - libraryMenu->addAction(aOpenDeckInDeckEditor); - topLibraryMenu->addAction(aMoveTopToPlay); - topLibraryMenu->addAction(aMoveTopToPlayFaceDown); - topLibraryMenu->addAction(aMoveTopCardToBottom); - topLibraryMenu->addSeparator(); - topLibraryMenu->addAction(aMoveTopCardToGraveyard); - topLibraryMenu->addAction(aMoveTopCardsToGraveyard); - topLibraryMenu->addAction(aMoveTopCardToExile); - topLibraryMenu->addAction(aMoveTopCardsToExile); - topLibraryMenu->addAction(aMoveTopCardsUntil); - topLibraryMenu->addSeparator(); - topLibraryMenu->addAction(aShuffleTopCards); - - bottomLibraryMenu->addAction(aDrawBottomCard); - bottomLibraryMenu->addAction(aDrawBottomCards); - bottomLibraryMenu->addSeparator(); - bottomLibraryMenu->addAction(aMoveBottomToPlay); - bottomLibraryMenu->addAction(aMoveBottomToPlayFaceDown); - bottomLibraryMenu->addAction(aMoveBottomCardToTop); - bottomLibraryMenu->addSeparator(); - bottomLibraryMenu->addAction(aMoveBottomCardToGraveyard); - bottomLibraryMenu->addAction(aMoveBottomCardsToGraveyard); - bottomLibraryMenu->addAction(aMoveBottomCardToExile); - bottomLibraryMenu->addAction(aMoveBottomCardsToExile); - bottomLibraryMenu->addSeparator(); - bottomLibraryMenu->addAction(aShuffleBottomCards); + libraryMenu = new LibraryMenu(player, playerMenu); + playerMenu->addMenu(libraryMenu); } - graveMenu = playerMenu->addTearOffMenu(QString()); - graveMenu->addAction(aViewGraveyard); + graveMenu = new GraveyardMenu(player, playerMenu); + playerMenu->addMenu(graveMenu); + + rfgMenu = new RfgMenu(player, playerMenu); + playerMenu->addMenu(rfgMenu); if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { - mRevealRandomGraveyardCard = graveMenu->addMenu(QString()); - QAction *newAction = mRevealRandomGraveyardCard->addAction(QString()); - newAction->setData(-1); - connect(newAction, &QAction::triggered, playerActions, &PlayerActions::actRevealRandomGraveyardCard); - allPlayersActions.append(newAction); - mRevealRandomGraveyardCard->addSeparator(); - } - - rfgMenu = playerMenu->addTearOffMenu(QString()); - rfgMenu->addAction(aViewRfg); - - if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { - graveMenu->addSeparator(); - moveGraveMenu = graveMenu->addTearOffMenu(QString()); - moveGraveMenu->addAction(aMoveGraveToTopLibrary); - moveGraveMenu->addAction(aMoveGraveToBottomLibrary); - moveGraveMenu->addSeparator(); - moveGraveMenu->addAction(aMoveGraveToHand); - moveGraveMenu->addSeparator(); - moveGraveMenu->addAction(aMoveGraveToRfg); - - rfgMenu->addSeparator(); - moveRfgMenu = rfgMenu->addTearOffMenu(QString()); - moveRfgMenu->addAction(aMoveRfgToTopLibrary); - moveRfgMenu->addAction(aMoveRfgToBottomLibrary); - moveRfgMenu->addSeparator(); - moveRfgMenu->addAction(aMoveRfgToHand); - moveRfgMenu->addSeparator(); - moveRfgMenu->addAction(aMoveRfgToGrave); - sbMenu = playerMenu->addMenu(QString()); sbMenu->addAction(aViewSideboard); @@ -200,73 +117,14 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player) createPredefinedTokenMenu = nullptr; aIncrementAllCardCounters = nullptr; mCardCounters = nullptr; - moveHandMenu = nullptr; - aMoveHandToTopLibrary = nullptr; - aMoveHandToBottomLibrary = nullptr; - aMoveHandToGrave = nullptr; - aMoveHandToRfg = nullptr; - moveGraveMenu = nullptr; - aMoveGraveToTopLibrary = nullptr; - aMoveGraveToBottomLibrary = nullptr; - aMoveGraveToHand = nullptr; - aMoveGraveToRfg = nullptr; - - moveRfgMenu = nullptr; - aMoveRfgToTopLibrary = nullptr; - aMoveRfgToBottomLibrary = nullptr; - aMoveRfgToHand = nullptr; - aMoveRfgToGrave = nullptr; - - aViewLibrary = nullptr; - aViewHand = nullptr; - aSortHand = nullptr; - aViewTopCards = nullptr; - aViewBottomCards = nullptr; - mRevealLibrary = nullptr; - mLendLibrary = nullptr; - mRevealTopCard = nullptr; - topLibraryMenu = nullptr; - bottomLibraryMenu = nullptr; - aAlwaysRevealTopCard = nullptr; - aAlwaysLookAtTopCard = nullptr; - aOpenDeckInDeckEditor = nullptr; aViewSideboard = nullptr; - aDrawCard = nullptr; - aDrawCards = nullptr; - aUndoDraw = nullptr; - aMulligan = nullptr; - - aShuffle = nullptr; - aMoveTopToPlay = nullptr; - aMoveTopToPlayFaceDown = nullptr; - aMoveTopCardToBottom = nullptr; - aMoveTopCardToGraveyard = nullptr; - aMoveTopCardToExile = nullptr; - aMoveTopCardsToGraveyard = nullptr; - aMoveTopCardsToExile = nullptr; - aMoveTopCardsUntil = nullptr; - aShuffleTopCards = nullptr; - - aDrawBottomCard = nullptr; - aDrawBottomCards = nullptr; - aMoveBottomToPlay = nullptr; - aMoveBottomToPlayFaceDown = nullptr; - aMoveBottomCardToGraveyard = nullptr; - aMoveBottomCardToExile = nullptr; - aMoveBottomCardsToGraveyard = nullptr; - aMoveBottomCardsToExile = nullptr; - aMoveBottomCardToTop = nullptr; - aShuffleBottomCards = nullptr; - handMenu = nullptr; - mRevealHand = nullptr; - mRevealRandomHandCard = nullptr; - mRevealRandomGraveyardCard = nullptr; sbMenu = nullptr; libraryMenu = nullptr; - countersMenu = nullptr; - mCustomZones = nullptr; + + aUntapAll = nullptr; + aRollDie = nullptr; } aTap = new QAction(this); @@ -281,26 +139,6 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player) connect(aUnattach, &QAction::triggered, playerActions, &PlayerActions::actUnattach); aDrawArrow = new QAction(this); connect(aDrawArrow, &QAction::triggered, playerActions, &PlayerActions::actDrawArrow); - aIncP = new QAction(this); - connect(aIncP, &QAction::triggered, playerActions, &PlayerActions::actIncP); - aDecP = new QAction(this); - connect(aDecP, &QAction::triggered, playerActions, &PlayerActions::actDecP); - aIncT = new QAction(this); - connect(aIncT, &QAction::triggered, playerActions, &PlayerActions::actIncT); - aDecT = new QAction(this); - connect(aDecT, &QAction::triggered, playerActions, &PlayerActions::actDecT); - aIncPT = new QAction(this); - connect(aIncPT, &QAction::triggered, playerActions, [playerActions] { playerActions->actIncPT(); }); - aDecPT = new QAction(this); - connect(aDecPT, &QAction::triggered, playerActions, &PlayerActions::actDecPT); - aFlowP = new QAction(this); - connect(aFlowP, &QAction::triggered, playerActions, &PlayerActions::actFlowP); - aFlowT = new QAction(this); - connect(aFlowT, &QAction::triggered, playerActions, &PlayerActions::actFlowT); - aSetPT = new QAction(this); - connect(aSetPT, &QAction::triggered, playerActions, &PlayerActions::actSetPT); - aResetPT = new QAction(this); - connect(aResetPT, &QAction::triggered, playerActions, &PlayerActions::actResetPT); aSetAnnotation = new QAction(this); connect(aSetAnnotation, &QAction::triggered, playerActions, &PlayerActions::actSetAnnotation); aFlip = new QAction(this); @@ -366,7 +204,6 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player) connect(player, &Player::clearCustomZonesMenu, this, &PlayerMenu::clearCustomZonesMenu); connect(player, &Player::addViewCustomZoneActionToCustomZoneMenu, this, &PlayerMenu::addViewCustomZoneActionToCustomZoneMenu); - connect(player, &Player::resetTopCardMenuActions, this, &PlayerMenu::resetTopCardMenuActions); retranslateUi(); } @@ -374,172 +211,22 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player) void PlayerMenu::setMenusForGraphicItems() { player->getGraphicsItem()->getTableZoneGraphicsItem()->setMenu(playerMenu); - player->getGraphicsItem()->getGraveyardZoneGraphicsItem()->setMenu(graveMenu, aViewGraveyard); - player->getGraphicsItem()->getRfgZoneGraphicsItem()->setMenu(rfgMenu, aViewRfg); + //player->getGraphicsItem()->getGraveyardZoneGraphicsItem()->setMenu(graveMenu, aViewGraveyard); + //player->getGraphicsItem()->getRfgZoneGraphicsItem()->setMenu(rfgMenu, aViewRfg); if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { player->getGraphicsItem()->getHandZoneGraphicsItem()->setMenu(handMenu); - player->getGraphicsItem()->getDeckZoneGraphicsItem()->setMenu(libraryMenu, aDrawCard); + // player->getGraphicsItem()->getDeckZoneGraphicsItem()->setMenu(libraryMenu, aDrawCard); player->getGraphicsItem()->getSideboardZoneGraphicsItem()->setMenu(sbMenu); } } -void PlayerMenu::createDrawActions() -{ - PlayerActions *playerActions = player->getPlayerActions(); - - if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { - aDrawCard = new QAction(this); - connect(aDrawCard, &QAction::triggered, playerActions, &PlayerActions::actDrawCard); - aDrawCards = new QAction(this); - connect(aDrawCards, &QAction::triggered, playerActions, &PlayerActions::actDrawCards); - aUndoDraw = new QAction(this); - connect(aUndoDraw, &QAction::triggered, playerActions, &PlayerActions::actUndoDraw); - aMulligan = new QAction(this); - connect(aMulligan, &QAction::triggered, playerActions, &PlayerActions::actMulligan); - aDrawBottomCard = new QAction(this); - connect(aDrawBottomCard, &QAction::triggered, playerActions, &PlayerActions::actDrawBottomCard); - aDrawBottomCards = new QAction(this); - connect(aDrawBottomCards, &QAction::triggered, playerActions, &PlayerActions::actDrawBottomCards); - } -} - -void PlayerMenu::createShuffleActions() -{ - PlayerActions *playerActions = player->getPlayerActions(); - - if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { - aShuffle = new QAction(this); - connect(aShuffle, &QAction::triggered, playerActions, &PlayerActions::actShuffle); - aShuffleTopCards = new QAction(this); - connect(aShuffleTopCards, &QAction::triggered, playerActions, &PlayerActions::actShuffleTop); - aShuffleBottomCards = new QAction(this); - connect(aShuffleBottomCards, &QAction::triggered, playerActions, &PlayerActions::actShuffleBottom); - } -} - -void PlayerMenu::createMoveActions() -{ - PlayerActions *playerActions = player->getPlayerActions(); - - if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { - aMoveHandToTopLibrary = new QAction(this); - aMoveHandToTopLibrary->setData(QList() << "deck" << 0); - aMoveHandToBottomLibrary = new QAction(this); - aMoveHandToBottomLibrary->setData(QList() << "deck" << -1); - aMoveHandToGrave = new QAction(this); - aMoveHandToGrave->setData(QList() << "grave" << 0); - aMoveHandToRfg = new QAction(this); - aMoveHandToRfg->setData(QList() << "rfg" << 0); - - auto hand = player->getHandZone(); - auto grave = player->getGraveZone(); - auto rfg = player->getRfgZone(); - - connect(aMoveHandToTopLibrary, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); - connect(aMoveHandToBottomLibrary, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); - connect(aMoveHandToGrave, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); - connect(aMoveHandToRfg, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); - - aMoveGraveToTopLibrary = new QAction(this); - aMoveGraveToTopLibrary->setData(QList() << "deck" << 0); - aMoveGraveToBottomLibrary = new QAction(this); - aMoveGraveToBottomLibrary->setData(QList() << "deck" << -1); - aMoveGraveToHand = new QAction(this); - aMoveGraveToHand->setData(QList() << "hand" << 0); - aMoveGraveToRfg = new QAction(this); - aMoveGraveToRfg->setData(QList() << "rfg" << 0); - - connect(aMoveGraveToTopLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); - connect(aMoveGraveToBottomLibrary, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); - connect(aMoveGraveToHand, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); - connect(aMoveGraveToRfg, &QAction::triggered, grave, &PileZoneLogic::moveAllToZone); - - aMoveRfgToTopLibrary = new QAction(this); - aMoveRfgToTopLibrary->setData(QList() << "deck" << 0); - aMoveRfgToBottomLibrary = new QAction(this); - aMoveRfgToBottomLibrary->setData(QList() << "deck" << -1); - aMoveRfgToHand = new QAction(this); - aMoveRfgToHand->setData(QList() << "hand" << 0); - aMoveRfgToGrave = new QAction(this); - aMoveRfgToGrave->setData(QList() << "grave" << 0); - - connect(aMoveRfgToTopLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); - connect(aMoveRfgToBottomLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); - connect(aMoveRfgToHand, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); - connect(aMoveRfgToGrave, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); - - aMoveTopToPlay = new QAction(this); - connect(aMoveTopToPlay, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToPlay); - aMoveTopToPlayFaceDown = new QAction(this); - connect(aMoveTopToPlayFaceDown, &QAction::triggered, playerActions, - &PlayerActions::actMoveTopCardToPlayFaceDown); - aMoveTopCardToGraveyard = new QAction(this); - connect(aMoveTopCardToGraveyard, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToGrave); - aMoveTopCardToExile = new QAction(this); - connect(aMoveTopCardToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToExile); - aMoveTopCardsToGraveyard = new QAction(this); - connect(aMoveTopCardsToGraveyard, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsToGrave); - aMoveTopCardsToExile = new QAction(this); - connect(aMoveTopCardsToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsToExile); - aMoveTopCardsUntil = new QAction(this); - connect(aMoveTopCardsUntil, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsUntil); - aMoveTopCardToBottom = new QAction(this); - connect(aMoveTopCardToBottom, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToBottom); - - aMoveBottomToPlay = new QAction(this); - connect(aMoveBottomToPlay, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToPlay); - aMoveBottomToPlayFaceDown = new QAction(this); - connect(aMoveBottomToPlayFaceDown, &QAction::triggered, playerActions, - &PlayerActions::actMoveBottomCardToPlayFaceDown); - aMoveBottomCardToGraveyard = new QAction(this); - connect(aMoveBottomCardToGraveyard, &QAction::triggered, playerActions, - &PlayerActions::actMoveBottomCardToGrave); - aMoveBottomCardToExile = new QAction(this); - connect(aMoveBottomCardToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToExile); - aMoveBottomCardsToGraveyard = new QAction(this); - connect(aMoveBottomCardsToGraveyard, &QAction::triggered, playerActions, - &PlayerActions::actMoveBottomCardsToGrave); - aMoveBottomCardsToExile = new QAction(this); - connect(aMoveBottomCardsToExile, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardsToExile); - aMoveBottomCardToTop = new QAction(this); - connect(aMoveBottomCardToTop, &QAction::triggered, playerActions, &PlayerActions::actMoveBottomCardToTop); - } -} - void PlayerMenu::createViewActions() { PlayerActions *playerActions = player->getPlayerActions(); - aViewGraveyard = new QAction(this); - connect(aViewGraveyard, &QAction::triggered, playerActions, &PlayerActions::actViewGraveyard); - - aViewRfg = new QAction(this); - connect(aViewRfg, &QAction::triggered, playerActions, &PlayerActions::actViewRfg); - if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { - aViewLibrary = new QAction(this); - connect(aViewLibrary, &QAction::triggered, playerActions, &PlayerActions::actViewLibrary); aViewSideboard = new QAction(this); connect(aViewSideboard, &QAction::triggered, playerActions, &PlayerActions::actViewSideboard); - - aViewHand = new QAction(this); - connect(aViewHand, &QAction::triggered, playerActions, &PlayerActions::actViewHand); - aSortHand = new QAction(this); - connect(aSortHand, &QAction::triggered, playerActions, &PlayerActions::actSortHand); - - aViewTopCards = new QAction(this); - connect(aViewTopCards, &QAction::triggered, playerActions, &PlayerActions::actViewTopCards); - aViewBottomCards = new QAction(this); - connect(aViewBottomCards, &QAction::triggered, playerActions, &PlayerActions::actViewBottomCards); - aAlwaysRevealTopCard = new QAction(this); - aAlwaysRevealTopCard->setCheckable(true); - connect(aAlwaysRevealTopCard, &QAction::triggered, playerActions, &PlayerActions::actAlwaysRevealTopCard); - aAlwaysLookAtTopCard = new QAction(this); - aAlwaysLookAtTopCard->setCheckable(true); - connect(aAlwaysLookAtTopCard, &QAction::triggered, playerActions, &PlayerActions::actAlwaysLookAtTopCard); - aOpenDeckInDeckEditor = new QAction(this); - aOpenDeckInDeckEditor->setEnabled(false); - connect(aOpenDeckInDeckEditor, &QAction::triggered, playerActions, &PlayerActions::actOpenDeckInDeckEditor); } } @@ -616,10 +303,10 @@ void PlayerMenu::playerListActionTriggered() cmd.set_player_id(otherPlayerId); } - if (menu == mRevealLibrary || menu == mLendLibrary) { + if (menu == libraryMenu->revealLibrary() || menu == libraryMenu->lendLibraryMenu()) { cmd.set_zone_name("deck"); - cmd.set_grant_write_access(menu == mLendLibrary); - } else if (menu == mRevealTopCard) { + cmd.set_grant_write_access(menu == libraryMenu->lendLibraryMenu()); + } else if (menu == libraryMenu->revealTopCardMenu()) { int deckSize = player->getDeckZone()->getCards().size(); bool ok; int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Reveal top cards of library"), @@ -632,9 +319,9 @@ void PlayerMenu::playerListActionTriggered() cmd.add_card_id(0); // defaultNumberTopCards = number; } - } else if (menu == mRevealHand) { + } else if (menu == handMenu->revealHandMenu()) { cmd.set_zone_name("hand"); - } else if (menu == mRevealRandomHandCard) { + } else if (menu == handMenu->revealRandomHandCardMenu()) { cmd.set_zone_name("hand"); cmd.add_card_id(PlayerActions::RANDOM_CARD_FROM_ZONE); } else { @@ -719,7 +406,7 @@ QMenu *PlayerMenu::createCardMenu(const CardItem *card) } cardMenu->addAction(aDrawArrow); cardMenu->addSeparator(); - cardMenu->addMenu(createPtMenu()); + cardMenu->addMenu(new PtMenu(player)); cardMenu->addAction(aSetAnnotation); cardMenu->addSeparator(); cardMenu->addAction(aClone); @@ -865,25 +552,6 @@ QMenu *PlayerMenu::updateCardMenu(const CardItem *card) return menu; } -QMenu *PlayerMenu::createPtMenu() const -{ - QMenu *ptMenu = new QMenu(tr("Power / toughness")); - ptMenu->addAction(aIncP); - ptMenu->addAction(aDecP); - ptMenu->addAction(aFlowP); - ptMenu->addSeparator(); - ptMenu->addAction(aIncT); - ptMenu->addAction(aDecT); - ptMenu->addAction(aFlowT); - ptMenu->addSeparator(); - ptMenu->addAction(aIncPT); - ptMenu->addAction(aDecPT); - ptMenu->addSeparator(); - ptMenu->addAction(aSetPT); - ptMenu->addAction(aResetPT); - return ptMenu; -} - QMenu *PlayerMenu::createMoveMenu() const { QMenu *moveMenu = new QMenu(tr("Move to")); @@ -1054,91 +722,18 @@ void PlayerMenu::populatePredefinedTokensMenu() } } -void PlayerMenu::enableOpenInDeckEditorAction() const -{ - aOpenDeckInDeckEditor->setEnabled(true); -} -void PlayerMenu::resetTopCardMenuActions() -{ - aAlwaysRevealTopCard->setChecked(false); - aAlwaysLookAtTopCard->setChecked(false); -} void PlayerMenu::retranslateUi() { - aViewGraveyard->setText(tr("&View graveyard")); - aViewRfg->setText(tr("&View exile")); - playerMenu->setTitle(tr("Player \"%1\"").arg(player->getPlayerInfo()->getName())); graveMenu->setTitle(tr("&Graveyard")); rfgMenu->setTitle(tr("&Exile")); if (player->getPlayerInfo()->getLocalOrJudge()) { - moveHandMenu->setTitle(tr("&Move hand to...")); - aMoveHandToTopLibrary->setText(tr("&Top of library")); - aMoveHandToBottomLibrary->setText(tr("&Bottom of library")); - aMoveHandToGrave->setText(tr("&Graveyard")); - aMoveHandToRfg->setText(tr("&Exile")); - - moveGraveMenu->setTitle(tr("&Move graveyard to...")); - aMoveGraveToTopLibrary->setText(tr("&Top of library")); - aMoveGraveToBottomLibrary->setText(tr("&Bottom of library")); - aMoveGraveToHand->setText(tr("&Hand")); - aMoveGraveToRfg->setText(tr("&Exile")); - - moveRfgMenu->setTitle(tr("&Move exile to...")); - aMoveRfgToTopLibrary->setText(tr("&Top of library")); - aMoveRfgToBottomLibrary->setText(tr("&Bottom of library")); - aMoveRfgToHand->setText(tr("&Hand")); - aMoveRfgToGrave->setText(tr("&Graveyard")); - - aViewLibrary->setText(tr("&View library")); - aViewHand->setText(tr("&View hand")); - aSortHand->setText(tr("&Sort hand")); - aViewTopCards->setText(tr("View &top cards of library...")); - aViewBottomCards->setText(tr("View bottom cards of library...")); - mRevealLibrary->setTitle(tr("Reveal &library to...")); - mLendLibrary->setTitle(tr("Lend library to...")); - mRevealTopCard->setTitle(tr("Reveal &top cards to...")); - topLibraryMenu->setTitle(tr("&Top of library...")); - bottomLibraryMenu->setTitle(tr("&Bottom of library...")); - aAlwaysRevealTopCard->setText(tr("&Always reveal top card")); - aAlwaysLookAtTopCard->setText(tr("&Always look at top card")); - aOpenDeckInDeckEditor->setText(tr("&Open deck in deck editor")); aViewSideboard->setText(tr("&View sideboard")); - aDrawCard->setText(tr("&Draw card")); - aDrawCards->setText(tr("D&raw cards...")); - aUndoDraw->setText(tr("&Undo last draw")); - aMulligan->setText(tr("Take &mulligan")); - - aShuffle->setText(tr("Shuffle")); - - aMoveTopToPlay->setText(tr("&Play top card")); - aMoveTopToPlayFaceDown->setText(tr("Play top card &face down")); - aMoveTopCardToBottom->setText(tr("Put top card on &bottom")); - aMoveTopCardToGraveyard->setText(tr("Move top card to grave&yard")); - aMoveTopCardToExile->setText(tr("Move top card to e&xile")); - aMoveTopCardsToGraveyard->setText(tr("Move top cards to &graveyard...")); - aMoveTopCardsToExile->setText(tr("Move top cards to &exile...")); - aMoveTopCardsUntil->setText(tr("Put top cards on stack &until...")); - aShuffleTopCards->setText(tr("Shuffle top cards...")); - - aDrawBottomCard->setText(tr("&Draw bottom card")); - aDrawBottomCards->setText(tr("D&raw bottom cards...")); - aMoveBottomToPlay->setText(tr("&Play bottom card")); - aMoveBottomToPlayFaceDown->setText(tr("Play bottom card &face down")); - aMoveBottomCardToGraveyard->setText(tr("Move bottom card to grave&yard")); - aMoveBottomCardToExile->setText(tr("Move bottom card to e&xile")); - aMoveBottomCardsToGraveyard->setText(tr("Move bottom cards to &graveyard...")); - aMoveBottomCardsToExile->setText(tr("Move bottom cards to &exile...")); - aMoveBottomCardToTop->setText(tr("Put bottom card on &top")); - aShuffleBottomCards->setText(tr("Shuffle bottom cards...")); handMenu->setTitle(tr("&Hand")); - mRevealHand->setTitle(tr("&Reveal hand to...")); - mRevealRandomHandCard->setTitle(tr("Reveal r&andom card to...")); - mRevealRandomGraveyardCard->setTitle(tr("Reveal random card to...")); sbMenu->setTitle(tr("&Sideboard")); libraryMenu->setTitle(tr("&Library")); countersMenu->setTitle(tr("&Counters")); @@ -1185,16 +780,6 @@ void PlayerMenu::retranslateUi() aAttach->setText(tr("Attac&h to card...")); aUnattach->setText(tr("Unattac&h")); aDrawArrow->setText(tr("&Draw arrow...")); - aIncP->setText(tr("&Increase power")); - aDecP->setText(tr("&Decrease power")); - aIncT->setText(tr("I&ncrease toughness")); - aDecT->setText(tr("D&ecrease toughness")); - aIncPT->setText(tr("In&crease power and toughness")); - aDecPT->setText(tr("Dec&rease power and toughness")); - aFlowP->setText(tr("Increase power and decrease toughness")); - aFlowT->setText(tr("Decrease power and increase toughness")); - aSetPT->setText(tr("Set &power and toughness...")); - aResetPT->setText(tr("Reset p&ower and toughness")); aSetAnnotation->setText(tr("&Set annotation...")); auto &cardCounterSettings = SettingsCache::instance().cardCounters(); @@ -1246,23 +831,12 @@ void PlayerMenu::setShortcutsActive() setShortcutIfItExists(aAttach, shortcuts.getShortcut("Player/aAttach")); setShortcutIfItExists(aUnattach, shortcuts.getShortcut("Player/aUnattach")); setShortcutIfItExists(aDrawArrow, shortcuts.getShortcut("Player/aDrawArrow")); - setShortcutIfItExists(aIncP, shortcuts.getShortcut("Player/aIncP")); - setShortcutIfItExists(aDecP, shortcuts.getShortcut("Player/aDecP")); - setShortcutIfItExists(aIncT, shortcuts.getShortcut("Player/aIncT")); - setShortcutIfItExists(aDecT, shortcuts.getShortcut("Player/aDecT")); - setShortcutIfItExists(aIncPT, shortcuts.getShortcut("Player/aIncPT")); - setShortcutIfItExists(aDecPT, shortcuts.getShortcut("Player/aDecPT")); - setShortcutIfItExists(aFlowP, shortcuts.getShortcut("Player/aFlowP")); - setShortcutIfItExists(aFlowT, shortcuts.getShortcut("Player/aFlowT")); - setShortcutIfItExists(aSetPT, shortcuts.getShortcut("Player/aSetPT")); - setShortcutIfItExists(aResetPT, shortcuts.getShortcut("Player/aResetPT")); setShortcutIfItExists(aSetAnnotation, shortcuts.getShortcut("Player/aSetAnnotation")); setShortcutIfItExists(aMoveToTopLibrary, shortcuts.getShortcut("Player/aMoveToTopLibrary")); setShortcutIfItExists(aMoveToBottomLibrary, shortcuts.getShortcut("Player/aMoveToBottomLibrary")); setShortcutIfItExists(aMoveToHand, shortcuts.getShortcut("Player/aMoveToHand")); setShortcutIfItExists(aMoveToGraveyard, shortcuts.getShortcut("Player/aMoveToGraveyard")); setShortcutIfItExists(aMoveToExile, shortcuts.getShortcut("Player/aMoveToExile")); - setShortcutIfItExists(aSortHand, shortcuts.getShortcut("Player/aSortHand")); setShortcutIfItExists(aSelectAll, shortcuts.getShortcut("Player/aSelectAll")); setShortcutIfItExists(aSelectRow, shortcuts.getShortcut("Player/aSelectRow")); @@ -1282,41 +856,10 @@ void PlayerMenu::setShortcutsActive() setShortcutIfItExists(aIncrementAllCardCounters, shortcuts.getShortcut("Player/aIncrementAllCardCounters")); setShortcutIfItExists(aViewSideboard, shortcuts.getShortcut("Player/aViewSideboard")); - setShortcutIfItExists(aViewLibrary, shortcuts.getShortcut("Player/aViewLibrary")); - setShortcutIfItExists(aViewHand, shortcuts.getShortcut("Player/aViewHand")); - setShortcutIfItExists(aViewTopCards, shortcuts.getShortcut("Player/aViewTopCards")); - setShortcutIfItExists(aViewBottomCards, shortcuts.getShortcut("Player/aViewBottomCards")); - setShortcutIfItExists(aViewGraveyard, shortcuts.getShortcut("Player/aViewGraveyard")); - setShortcutIfItExists(aDrawCard, shortcuts.getShortcut("Player/aDrawCard")); - setShortcutIfItExists(aDrawCards, shortcuts.getShortcut("Player/aDrawCards")); - setShortcutIfItExists(aUndoDraw, shortcuts.getShortcut("Player/aUndoDraw")); - setShortcutIfItExists(aMulligan, shortcuts.getShortcut("Player/aMulligan")); - setShortcutIfItExists(aShuffle, shortcuts.getShortcut("Player/aShuffle")); - setShortcutIfItExists(aShuffleTopCards, shortcuts.getShortcut("Player/aShuffleTopCards")); - setShortcutIfItExists(aShuffleBottomCards, shortcuts.getShortcut("Player/aShuffleBottomCards")); setShortcutIfItExists(aUntapAll, shortcuts.getShortcut("Player/aUntapAll")); setShortcutIfItExists(aRollDie, shortcuts.getShortcut("Player/aRollDie")); setShortcutIfItExists(aCreateToken, shortcuts.getShortcut("Player/aCreateToken")); setShortcutIfItExists(aCreateAnotherToken, shortcuts.getShortcut("Player/aCreateAnotherToken")); - setShortcutIfItExists(aAlwaysRevealTopCard, shortcuts.getShortcut("Player/aAlwaysRevealTopCard")); - setShortcutIfItExists(aAlwaysLookAtTopCard, shortcuts.getShortcut("Player/aAlwaysLookAtTopCard")); - setShortcutIfItExists(aMoveTopToPlay, shortcuts.getShortcut("Player/aMoveTopToPlay")); - setShortcutIfItExists(aMoveTopToPlayFaceDown, shortcuts.getShortcut("Player/aMoveTopToPlayFaceDown")); - setShortcutIfItExists(aMoveTopCardToGraveyard, shortcuts.getShortcut("Player/aMoveTopCardToGraveyard")); - setShortcutIfItExists(aMoveTopCardsToGraveyard, shortcuts.getShortcut("Player/aMoveTopCardsToGraveyard")); - setShortcutIfItExists(aMoveTopCardToExile, shortcuts.getShortcut("Player/aMoveTopCardToExile")); - setShortcutIfItExists(aMoveTopCardsToExile, shortcuts.getShortcut("Player/aMoveTopCardsToExile")); - setShortcutIfItExists(aMoveTopCardsUntil, shortcuts.getShortcut("Player/aMoveTopCardsUntil")); - setShortcutIfItExists(aMoveTopCardToBottom, shortcuts.getShortcut("Player/aMoveTopCardToBottom")); - setShortcutIfItExists(aDrawBottomCard, shortcuts.getShortcut("Player/aDrawBottomCard")); - setShortcutIfItExists(aDrawBottomCards, shortcuts.getShortcut("Player/aDrawBottomCards")); - setShortcutIfItExists(aMoveBottomToPlay, shortcuts.getShortcut("Player/aMoveBottomToPlay")); - setShortcutIfItExists(aMoveBottomToPlayFaceDown, shortcuts.getShortcut("Player/aMoveBottomToPlayFaceDown")); - setShortcutIfItExists(aMoveBottomCardToGraveyard, shortcuts.getShortcut("Player/aMoveBottomCardToGrave")); - setShortcutIfItExists(aMoveBottomCardsToGraveyard, shortcuts.getShortcut("Player/aMoveBottomCardsToGrave")); - setShortcutIfItExists(aMoveBottomCardToExile, shortcuts.getShortcut("Player/aMoveBottomCardToExile")); - setShortcutIfItExists(aMoveBottomCardsToExile, shortcuts.getShortcut("Player/aMoveBottomCardsToExile")); - setShortcutIfItExists(aMoveBottomCardToTop, shortcuts.getShortcut("Player/aMoveBottomCardToTop")); setShortcutIfItExists(aPlayFacedown, shortcuts.getShortcut("Player/aPlayFacedown")); setShortcutIfItExists(aPlay, shortcuts.getShortcut("Player/aPlay")); @@ -1334,41 +877,11 @@ void PlayerMenu::setShortcutsInactive() shortcutsActive = false; clearShortcutIfItExists(aViewSideboard); - clearShortcutIfItExists(aViewLibrary); - clearShortcutIfItExists(aViewHand); - clearShortcutIfItExists(aViewTopCards); - clearShortcutIfItExists(aViewBottomCards); - clearShortcutIfItExists(aViewGraveyard); - clearShortcutIfItExists(aDrawCard); - clearShortcutIfItExists(aDrawCards); - clearShortcutIfItExists(aUndoDraw); - clearShortcutIfItExists(aMulligan); - clearShortcutIfItExists(aShuffle); - clearShortcutIfItExists(aShuffleTopCards); - clearShortcutIfItExists(aShuffleBottomCards); clearShortcutIfItExists(aUntapAll); clearShortcutIfItExists(aRollDie); clearShortcutIfItExists(aCreateToken); clearShortcutIfItExists(aCreateAnotherToken); - clearShortcutIfItExists(aAlwaysRevealTopCard); - clearShortcutIfItExists(aAlwaysLookAtTopCard); - clearShortcutIfItExists(aMoveTopToPlay); - clearShortcutIfItExists(aMoveTopToPlayFaceDown); - clearShortcutIfItExists(aMoveTopCardToGraveyard); - clearShortcutIfItExists(aMoveTopCardsToGraveyard); - clearShortcutIfItExists(aMoveTopCardToExile); - clearShortcutIfItExists(aMoveTopCardsToExile); - clearShortcutIfItExists(aMoveTopCardsUntil); - clearShortcutIfItExists(aDrawBottomCard); - clearShortcutIfItExists(aDrawBottomCards); - clearShortcutIfItExists(aMoveBottomToPlay); - clearShortcutIfItExists(aMoveBottomToPlayFaceDown); - clearShortcutIfItExists(aMoveBottomCardToGraveyard); - clearShortcutIfItExists(aMoveBottomCardsToGraveyard); - clearShortcutIfItExists(aMoveBottomCardToExile); - clearShortcutIfItExists(aMoveBottomCardsToExile); clearShortcutIfItExists(aIncrementAllCardCounters); - clearShortcutIfItExists(aSortHand); QMapIterator counterIterator(player->getCounters()); while (counterIterator.hasNext()) { diff --git a/cockatrice/src/game/player/player_menu.h b/cockatrice/src/game/player/player_menu/player_menu.h similarity index 55% rename from cockatrice/src/game/player/player_menu.h rename to cockatrice/src/game/player/player_menu/player_menu.h index 644fbc76e..1a1f286c3 100644 --- a/cockatrice/src/game/player/player_menu.h +++ b/cockatrice/src/game/player/player_menu/player_menu.h @@ -1,8 +1,12 @@ #ifndef COCKATRICE_PLAYER_MENU_H #define COCKATRICE_PLAYER_MENU_H -#include "../../client/tearoff_menu.h" -#include "player.h" +#include "../../../client/tearoff_menu.h" +#include "../player.h" +#include "grave_menu.h" +#include "hand_menu.h" +#include "library_menu.h" +#include "rfg_menu.h" #include #include @@ -15,9 +19,7 @@ signals: void cardMenuUpdated(QMenu *cardMenu); public slots: - QMenu *createPtMenu() const; QMenu *createMoveMenu() const; - void enableOpenInDeckEditorAction() const; void populatePredefinedTokensMenu(); void setMenusForGraphicItems(); @@ -28,13 +30,9 @@ private slots: void refreshShortcuts(); void clearCustomZonesMenu(); void addViewCustomZoneActionToCustomZoneMenu(QString zoneName); - void resetTopCardMenuActions(); public: PlayerMenu(Player *player); - void createDrawActions(); - void createShuffleActions(); - void createMoveActions(); void createViewActions(); void retranslateUi(); @@ -59,16 +57,6 @@ public: return predefinedTokens; } - [[nodiscard]] bool isAlwaysRevealTopCardChecked() - { - return aAlwaysRevealTopCard->isChecked(); - } - - [[nodiscard]] bool isAlwaysLookAtTopCardChecked() - { - return aAlwaysLookAtTopCard->isChecked(); - } - [[nodiscard]] QMenu *getPlayerMenu() const { return playerMenu; @@ -79,6 +67,11 @@ public: return countersMenu; } + [[nodiscard]] LibraryMenu *getLibraryMenu() const + { + return libraryMenu; + } + bool getShortcutsActive() const { return shortcutsActive; @@ -91,30 +84,23 @@ public: private: Player *player; - QMenu *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu, *mRevealLibrary, *mLendLibrary, *mRevealTopCard, - *mRevealHand, *mRevealRandomHandCard, *mRevealRandomGraveyardCard, *mCustomZones, *mCardCounters; - TearOffMenu *moveGraveMenu, *moveRfgMenu, *graveMenu, *moveHandMenu, *handMenu, *libraryMenu, *topLibraryMenu, - *bottomLibraryMenu, *rfgMenu, *playerMenu; + QMenu *sbMenu, *countersMenu, *sayMenu, *createPredefinedTokenMenu, *mCustomZones, + *mCardCounters; + HandMenu *handMenu; + LibraryMenu *libraryMenu; + GraveyardMenu *graveMenu; + RfgMenu *rfgMenu; + TearOffMenu *playerMenu; QList playerLists; QList singlePlayerLists; QList allPlayersActions; QList> playersInfo; - QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aMoveHandToGrave, *aMoveHandToRfg, - *aMoveGraveToTopLibrary, *aMoveGraveToBottomLibrary, *aMoveGraveToHand, *aMoveGraveToRfg, *aMoveRfgToTopLibrary, - *aMoveRfgToBottomLibrary, *aMoveRfgToHand, *aMoveRfgToGrave, *aViewHand, *aViewLibrary, *aViewTopCards, - *aViewBottomCards, *aAlwaysRevealTopCard, *aAlwaysLookAtTopCard, *aOpenDeckInDeckEditor, - *aMoveTopCardToGraveyard, *aMoveTopCardToExile, *aMoveTopCardsToGraveyard, *aMoveTopCardsToExile, - *aMoveTopCardsUntil, *aMoveTopCardToBottom, *aViewGraveyard, *aViewRfg, *aViewSideboard, *aDrawCard, - *aDrawCards, *aUndoDraw, *aMulligan, *aShuffle, *aShuffleTopCards, *aShuffleBottomCards, *aMoveTopToPlay, - *aMoveTopToPlayFaceDown, *aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken, *aMoveBottomToPlay, - *aMoveBottomToPlayFaceDown, *aMoveBottomCardToTop, *aMoveBottomCardToGraveyard, *aMoveBottomCardToExile, - *aMoveBottomCardsToGraveyard, *aMoveBottomCardsToExile, *aDrawBottomCard, *aDrawBottomCards; + QAction *aViewSideboard, *aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken; QList aAddCounter, aSetCounter, aRemoveCounter; - QAction *aPlay, *aPlayFacedown, *aHide, *aTap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetPT, *aResetPT, - *aIncP, *aDecP, *aIncT, *aDecT, *aIncPT, *aDecPT, *aFlowP, *aFlowT, *aSetAnnotation, *aFlip, *aPeek, *aClone, + QAction *aPlay, *aPlayFacedown, *aHide, *aTap, *aDoesntUntap, *aAttach, *aUnattach, *aDrawArrow, *aSetAnnotation, *aFlip, *aPeek, *aClone, *aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToHand, *aMoveToGraveyard, *aMoveToExile, - *aMoveToXfromTopOfLibrary, *aSelectAll, *aSelectRow, *aSelectColumn, *aSortHand, *aIncrementAllCardCounters; + *aMoveToXfromTopOfLibrary, *aSelectAll, *aSelectRow, *aSelectColumn, *aIncrementAllCardCounters; bool shortcutsActive; QStringList predefinedTokens; diff --git a/cockatrice/src/game/player/player_menu/pt_menu.cpp b/cockatrice/src/game/player/player_menu/pt_menu.cpp new file mode 100644 index 000000000..1693298b5 --- /dev/null +++ b/cockatrice/src/game/player/player_menu/pt_menu.cpp @@ -0,0 +1,76 @@ +#include "pt_menu.h" + +#include "../player.h" +#include "../player_actions.h" + +PtMenu::PtMenu(Player *player) : QMenu(tr("Power / toughness")) +{ + PlayerActions *playerActions = player->getPlayerActions(); + + aIncP = new QAction(this); + connect(aIncP, &QAction::triggered, playerActions, &PlayerActions::actIncP); + aDecP = new QAction(this); + connect(aDecP, &QAction::triggered, playerActions, &PlayerActions::actDecP); + aIncT = new QAction(this); + connect(aIncT, &QAction::triggered, playerActions, &PlayerActions::actIncT); + aDecT = new QAction(this); + connect(aDecT, &QAction::triggered, playerActions, &PlayerActions::actDecT); + aIncPT = new QAction(this); + connect(aIncPT, &QAction::triggered, playerActions, [playerActions] { playerActions->actIncPT(); }); + aDecPT = new QAction(this); + connect(aDecPT, &QAction::triggered, playerActions, &PlayerActions::actDecPT); + aFlowP = new QAction(this); + connect(aFlowP, &QAction::triggered, playerActions, &PlayerActions::actFlowP); + aFlowT = new QAction(this); + connect(aFlowT, &QAction::triggered, playerActions, &PlayerActions::actFlowT); + aSetPT = new QAction(this); + connect(aSetPT, &QAction::triggered, playerActions, &PlayerActions::actSetPT); + aResetPT = new QAction(this); + connect(aResetPT, &QAction::triggered, playerActions, &PlayerActions::actResetPT); + + addAction(aIncP); + addAction(aDecP); + addAction(aFlowP); + addSeparator(); + addAction(aIncT); + addAction(aDecT); + addAction(aFlowT); + addSeparator(); + addAction(aIncPT); + addAction(aDecPT); + addSeparator(); + addAction(aSetPT); + addAction(aResetPT); + + retranslateUi(); +} + +void PtMenu::retranslateUi() +{ + aIncP->setText(tr("&Increase power")); + aDecP->setText(tr("&Decrease power")); + aIncT->setText(tr("I&ncrease toughness")); + aDecT->setText(tr("D&ecrease toughness")); + aIncPT->setText(tr("In&crease power and toughness")); + aDecPT->setText(tr("Dec&rease power and toughness")); + aFlowP->setText(tr("Increase power and decrease toughness")); + aFlowT->setText(tr("Decrease power and increase toughness")); + aSetPT->setText(tr("Set &power and toughness...")); + aResetPT->setText(tr("Reset p&ower and toughness")); +} + +void PtMenu::setShortcutsActive() +{ + ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts(); + + aIncP->setShortcuts(shortcuts.getShortcut("Player/aIncP")); + aDecP->setShortcuts(shortcuts.getShortcut("Player/aDecP")); + aIncT->setShortcuts(shortcuts.getShortcut("Player/aIncT")); + aDecT->setShortcuts(shortcuts.getShortcut("Player/aDecT")); + aIncPT->setShortcuts(shortcuts.getShortcut("Player/aIncPT")); + aDecPT->setShortcuts(shortcuts.getShortcut("Player/aDecPT")); + aFlowP->setShortcuts(shortcuts.getShortcut("Player/aFlowP")); + aFlowT->setShortcuts(shortcuts.getShortcut("Player/aFlowT")); + aSetPT->setShortcuts(shortcuts.getShortcut("Player/aSetPT")); + aResetPT->setShortcuts(shortcuts.getShortcut("Player/aResetPT")); +} \ No newline at end of file diff --git a/cockatrice/src/game/player/player_menu/pt_menu.h b/cockatrice/src/game/player/player_menu/pt_menu.h new file mode 100644 index 000000000..591fa6c14 --- /dev/null +++ b/cockatrice/src/game/player/player_menu/pt_menu.h @@ -0,0 +1,29 @@ +#ifndef COCKATRICE_PT_MENU_H +#define COCKATRICE_PT_MENU_H +#include + +class Player; +class PtMenu : public QMenu { + + Q_OBJECT + +public: + explicit PtMenu(Player *player); + void retranslateUi(); + void setShortcutsActive(); + + QAction *aIncP = nullptr; + QAction *aDecP = nullptr; + QAction *aFlowP = nullptr; + QAction *aIncT = nullptr; + QAction *aDecT = nullptr; + QAction *aFlowT = nullptr; + + QAction *aIncPT = nullptr; + QAction *aDecPT = nullptr; + QAction *aSetPT = nullptr; + QAction *aResetPT = nullptr; + +}; + +#endif // COCKATRICE_PT_MENU_H diff --git a/cockatrice/src/game/player/player_menu/rfg_menu.cpp b/cockatrice/src/game/player/player_menu/rfg_menu.cpp new file mode 100644 index 000000000..8608dc575 --- /dev/null +++ b/cockatrice/src/game/player/player_menu/rfg_menu.cpp @@ -0,0 +1,67 @@ +#include "rfg_menu.h" + +#include "../player.h" +#include "../player_actions.h" + +RfgMenu::RfgMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player) +{ + createMoveActions(); + createViewActions(); + + addAction(aViewRfg); + + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + addSeparator(); + moveRfgMenu = addTearOffMenu(QString()); + moveRfgMenu->addAction(aMoveRfgToTopLibrary); + moveRfgMenu->addAction(aMoveRfgToBottomLibrary); + moveRfgMenu->addSeparator(); + moveRfgMenu->addAction(aMoveRfgToHand); + moveRfgMenu->addSeparator(); + moveRfgMenu->addAction(aMoveRfgToGrave); + } + + retranslateUi(); +} + +void RfgMenu::createMoveActions() +{ + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { + auto rfg = player->getRfgZone(); + + aMoveRfgToTopLibrary = new QAction(this); + aMoveRfgToTopLibrary->setData(QList() << "deck" << 0); + aMoveRfgToBottomLibrary = new QAction(this); + aMoveRfgToBottomLibrary->setData(QList() << "deck" << -1); + aMoveRfgToHand = new QAction(this); + aMoveRfgToHand->setData(QList() << "hand" << 0); + aMoveRfgToGrave = new QAction(this); + aMoveRfgToGrave->setData(QList() << "grave" << 0); + + connect(aMoveRfgToTopLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); + connect(aMoveRfgToBottomLibrary, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); + connect(aMoveRfgToHand, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); + connect(aMoveRfgToGrave, &QAction::triggered, rfg, &PileZoneLogic::moveAllToZone); + } +} + +void RfgMenu::createViewActions() +{ + PlayerActions *playerActions = player->getPlayerActions(); + + aViewRfg = new QAction(this); + connect(aViewRfg, &QAction::triggered, playerActions, &PlayerActions::actViewRfg); +} + +void RfgMenu::retranslateUi() +{ + aViewRfg->setText(tr("&View exile")); + + if (player->getPlayerInfo()->getLocalOrJudge()) { + moveRfgMenu->setTitle(tr("&Move exile to...")); + aMoveRfgToTopLibrary->setText(tr("&Top of library")); + aMoveRfgToBottomLibrary->setText(tr("&Bottom of library")); + aMoveRfgToHand->setText(tr("&Hand")); + aMoveRfgToGrave->setText(tr("&Graveyard")); + } +} \ No newline at end of file diff --git a/cockatrice/src/game/player/player_menu/rfg_menu.h b/cockatrice/src/game/player/player_menu/rfg_menu.h new file mode 100644 index 000000000..7c1a1b742 --- /dev/null +++ b/cockatrice/src/game/player/player_menu/rfg_menu.h @@ -0,0 +1,30 @@ +#ifndef COCKATRICE_RFG_MENU_H +#define COCKATRICE_RFG_MENU_H + +#include "../../../client/tearoff_menu.h" + +#include +#include + +class Player; +class RfgMenu : public TearOffMenu { + Q_OBJECT +public: + explicit RfgMenu(Player* player, QWidget* parent = nullptr); + void createMoveActions(); + void createViewActions(); + void retranslateUi(); + + QMenu * moveRfgMenu = nullptr; + + QAction* aViewRfg = nullptr; + QAction* aMoveRfgToTopLibrary = nullptr; + QAction* aMoveRfgToBottomLibrary = nullptr; + QAction* aMoveRfgToHand = nullptr; + QAction* aMoveRfgToGrave = nullptr; + +private: + Player* player; +}; + +#endif // COCKATRICE_RFG_MENU_H