[Game] Populate playerLists for menus in their aboutToShow … (#6214)

* Populate playerLists for menus in their aboutToShow so they are always current and do not rely on playerMenu manually tracking them. Also add playerActions for previous playerListActions.

Took 1 hour 35 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
BruebachL 2025-10-03 15:21:22 +02:00 committed by GitHub
parent 015570c833
commit 30e6b52783
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 313 additions and 159 deletions

View file

@ -1,7 +1,12 @@
#include "grave_menu.h"
#include "../../abstract_game.h"
#include "../player.h"
#include "../player_actions.h"
#include "grave_menu.h"
#include <QAction>
#include <QMenu>
GraveyardMenu::GraveyardMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
{
@ -12,14 +17,11 @@ GraveyardMenu::GraveyardMenu(Player *_player, QWidget *parent) : TearOffMenu(par
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();
connect(mRevealRandomGraveyardCard, &QMenu::aboutToShow, this,
&GraveyardMenu::populateRevealRandomMenuWithActivePlayers);
addSeparator();
moveGraveMenu = addTearOffMenu(QString());
moveGraveMenu->addAction(aMoveGraveToTopLibrary);
moveGraveMenu->addAction(aMoveGraveToBottomLibrary);
@ -39,10 +41,13 @@ void GraveyardMenu::createMoveActions()
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);
@ -61,6 +66,33 @@ void GraveyardMenu::createViewActions()
connect(aViewGraveyard, &QAction::triggered, playerActions, &PlayerActions::actViewGraveyard);
}
void GraveyardMenu::populateRevealRandomMenuWithActivePlayers()
{
mRevealRandomGraveyardCard->clear();
QAction *allPlayers = mRevealRandomGraveyardCard->addAction(tr("&All players"));
allPlayers->setData(-1);
connect(allPlayers, &QAction::triggered, this, &GraveyardMenu::onRevealRandomTriggered);
mRevealRandomGraveyardCard->addSeparator();
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
continue;
QAction *a = mRevealRandomGraveyardCard->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &GraveyardMenu::onRevealRandomTriggered);
}
}
void GraveyardMenu::onRevealRandomTriggered()
{
if (auto *a = qobject_cast<QAction *>(sender())) {
player->getPlayerActions()->actRevealRandomGraveyardCard(a->data().toInt());
}
}
void GraveyardMenu::retranslateUi()
{
setTitle(tr("&Graveyard"));
@ -73,6 +105,7 @@ void GraveyardMenu::retranslateUi()
aMoveGraveToBottomLibrary->setText(tr("&Bottom of library"));
aMoveGraveToHand->setText(tr("&Hand"));
aMoveGraveToRfg->setText(tr("&Exile"));
mRevealRandomGraveyardCard->setTitle(tr("Reveal random card to..."));
}
}
@ -80,11 +113,10 @@ void GraveyardMenu::retranslateUi()
void GraveyardMenu::setShortcutsActive()
{
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
aViewGraveyard->setShortcuts(shortcuts.getShortcut("Player/aViewGraveyard"));
}
void GraveyardMenu::setShortcutsInactive()
{
aViewGraveyard->setShortcut(QKeySequence());
}
}