Refactor player menus into helper classes (#6121)

* Refactor player menus into helper classes.

Took 2 hours 6 minutes


Took 11 minutes

* Lint.

Took 6 minutes

Took 22 seconds

* Refactor card and move menu.

Took 1 hour 6 minutes

Took 36 seconds

Took 52 seconds

* Set active shortcuts, move player info stuff to card menu.

Took 25 minutes


Took 18 seconds

* Refactor say and utility menu.

Took 54 minutes

Took 2 minutes

Took 5 minutes

Took 11 minutes

* Rename folder.

Took 24 minutes

Took 6 minutes

* Refactor sideboard menu.

Took 26 minutes

* Remove unused variable in constructor.

Took 42 seconds

* Lint.

Took 11 minutes

* Nullptr check

Took 8 minutes

* Use localOrJudge check

Took 6 minutes

* Fix the build.

Took 7 minutes

Took 35 seconds

* PlayerList things.

Took 16 minutes

* Retranslate and set shortcuts for everything.

Took 10 minutes

* Correctly nullptr out sayMenu if not local

Took 3 minutes

* Don't check playerInfo in sbMenu shortcutsActive

Took 3 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-09-12 19:52:05 +02:00 committed by GitHub
parent ff7ce39841
commit fb23cc8c7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 2242 additions and 1536 deletions

View file

@ -0,0 +1,90 @@
#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);
emit newPlayerActionCreated(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<QVariant>() << "deck" << 0);
aMoveGraveToBottomLibrary = new QAction(this);
aMoveGraveToBottomLibrary->setData(QList<QVariant>() << "deck" << -1);
aMoveGraveToHand = new QAction(this);
aMoveGraveToHand->setData(QList<QVariant>() << "hand" << 0);
aMoveGraveToRfg = new QAction(this);
aMoveGraveToRfg->setData(QList<QVariant>() << "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()
{
setTitle(tr("&Graveyard"));
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());
}