mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 03:23:56 -07:00
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:
parent
ff7ce39841
commit
fb23cc8c7a
30 changed files with 2242 additions and 1536 deletions
117
cockatrice/src/game/player/menu/utility_menu.cpp
Normal file
117
cockatrice/src/game/player/menu/utility_menu.cpp
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#include "utility_menu.h"
|
||||
|
||||
#include "../player.h"
|
||||
#include "../player_actions.h"
|
||||
#include "player_menu.h"
|
||||
|
||||
UtilityMenu::UtilityMenu(Player *_player, QMenu *playerMenu) : QMenu(playerMenu), player(_player)
|
||||
{
|
||||
PlayerActions *playerActions = player->getPlayerActions();
|
||||
|
||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aUntapAll = new QAction(this);
|
||||
connect(aUntapAll, &QAction::triggered, playerActions, &PlayerActions::actUntapAll);
|
||||
|
||||
aRollDie = new QAction(this);
|
||||
connect(aRollDie, &QAction::triggered, playerActions, &PlayerActions::actRollDie);
|
||||
|
||||
aCreateToken = new QAction(this);
|
||||
connect(aCreateToken, &QAction::triggered, playerActions, &PlayerActions::actCreateToken);
|
||||
|
||||
aCreateAnotherToken = new QAction(this);
|
||||
connect(aCreateAnotherToken, &QAction::triggered, playerActions, &PlayerActions::actCreateAnotherToken);
|
||||
aCreateAnotherToken->setEnabled(false);
|
||||
|
||||
aIncrementAllCardCounters = new QAction(this);
|
||||
connect(aIncrementAllCardCounters, &QAction::triggered, player, &Player::incrementAllCardCounters);
|
||||
|
||||
createPredefinedTokenMenu = new QMenu(QString());
|
||||
createPredefinedTokenMenu->setEnabled(false);
|
||||
connect(player, &Player::deckChanged, this, &UtilityMenu::populatePredefinedTokensMenu);
|
||||
|
||||
playerMenu->addAction(aIncrementAllCardCounters);
|
||||
playerMenu->addSeparator();
|
||||
playerMenu->addAction(aUntapAll);
|
||||
playerMenu->addSeparator();
|
||||
playerMenu->addAction(aRollDie);
|
||||
playerMenu->addSeparator();
|
||||
playerMenu->addAction(aCreateToken);
|
||||
playerMenu->addAction(aCreateAnotherToken);
|
||||
playerMenu->addMenu(createPredefinedTokenMenu);
|
||||
playerMenu->addSeparator();
|
||||
} else {
|
||||
aCreateToken = nullptr;
|
||||
aCreateAnotherToken = nullptr;
|
||||
createPredefinedTokenMenu = nullptr;
|
||||
aIncrementAllCardCounters = nullptr;
|
||||
aUntapAll = nullptr;
|
||||
aRollDie = nullptr;
|
||||
}
|
||||
|
||||
retranslateUi();
|
||||
}
|
||||
|
||||
void UtilityMenu::populatePredefinedTokensMenu()
|
||||
{
|
||||
clear();
|
||||
setEnabled(false);
|
||||
predefinedTokens.clear();
|
||||
DeckLoader *_deck = player->getDeck();
|
||||
|
||||
if (!_deck) {
|
||||
return;
|
||||
}
|
||||
|
||||
InnerDecklistNode *tokenZone = dynamic_cast<InnerDecklistNode *>(_deck->getRoot()->findChild(DECK_ZONE_TOKENS));
|
||||
|
||||
if (tokenZone) {
|
||||
if (!tokenZone->empty())
|
||||
setEnabled(true);
|
||||
|
||||
for (int i = 0; i < tokenZone->size(); ++i) {
|
||||
const QString tokenName = tokenZone->at(i)->getName();
|
||||
predefinedTokens.append(tokenName);
|
||||
QAction *a = addAction(tokenName);
|
||||
if (i < 10) {
|
||||
a->setShortcut(QKeySequence("Alt+" + QString::number((i + 1) % 10)));
|
||||
}
|
||||
connect(a, &QAction::triggered, player->getPlayerActions(), &PlayerActions::actCreatePredefinedToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityMenu::retranslateUi()
|
||||
{
|
||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aIncrementAllCardCounters->setText(tr("Increment all card counters"));
|
||||
aUntapAll->setText(tr("&Untap all permanents"));
|
||||
aRollDie->setText(tr("R&oll die..."));
|
||||
aCreateToken->setText(tr("&Create token..."));
|
||||
aCreateAnotherToken->setText(tr("C&reate another token"));
|
||||
createPredefinedTokenMenu->setTitle(tr("Cr&eate predefined token"));
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityMenu::setShortcutsActive()
|
||||
{
|
||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||
|
||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aIncrementAllCardCounters->setShortcuts(shortcuts.getShortcut("Player/aIncrementAllCardCounters"));
|
||||
aUntapAll->setShortcuts(shortcuts.getShortcut("Player/aUntapAll"));
|
||||
aRollDie->setShortcuts(shortcuts.getShortcut("Player/aRollDie"));
|
||||
aCreateToken->setShortcuts(shortcuts.getShortcut("Player/aCreateToken"));
|
||||
aCreateAnotherToken->setShortcuts(shortcuts.getShortcut("Player/aCreateAnotherToken"));
|
||||
}
|
||||
}
|
||||
|
||||
void UtilityMenu::setShortcutsInactive()
|
||||
{
|
||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||
aUntapAll->setShortcut(QKeySequence());
|
||||
aRollDie->setShortcut(QKeySequence());
|
||||
aCreateToken->setShortcut(QKeySequence());
|
||||
aCreateAnotherToken->setShortcut(QKeySequence());
|
||||
aIncrementAllCardCounters->setShortcut(QKeySequence());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue