[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,8 +1,15 @@
#include "hand_menu.h"
#include "../../../settings/cache_settings.h"
#include "../../../settings/shortcuts_settings.h"
#include "../../abstract_game.h"
#include "../../zones/hand_zone.h"
#include "../player.h"
#include "../player_actions.h"
#include <QAction>
#include <QMenu>
HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : TearOffMenu(parent), player(_player)
{
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
@ -16,7 +23,12 @@ HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : T
}
mRevealHand = addMenu(QString());
connect(mRevealHand, &QMenu::aboutToShow, this, &HandMenu::populateRevealHandMenuWithActivePlayers);
mRevealRandomHandCard = addMenu(QString());
connect(mRevealRandomHandCard, &QMenu::aboutToShow, this,
&HandMenu::populateRevealRandomHandCardMenuWithActivePlayers);
addSeparator();
aMulligan = new QAction(this);
@ -78,7 +90,6 @@ void HandMenu::retranslateUi()
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"));
@ -90,3 +101,63 @@ void HandMenu::setShortcutsInactive()
aSortHand->setShortcut(QKeySequence());
aMulligan->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->addSeparator();
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
continue;
QAction *a = mRevealHand->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &HandMenu::onRevealHandTriggered);
}
}
void HandMenu::populateRevealRandomHandCardMenuWithActivePlayers()
{
mRevealRandomHandCard->clear();
QAction *allPlayers = mRevealRandomHandCard->addAction(tr("&All players"));
allPlayers->setData(-1);
connect(allPlayers, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered);
mRevealRandomHandCard->addSeparator();
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
for (auto *other : players) {
if (other == player)
continue;
QAction *a = mRevealRandomHandCard->addAction(other->getPlayerInfo()->getName());
a->setData(other->getPlayerInfo()->getId());
connect(a, &QAction::triggered, this, &HandMenu::onRevealRandomHandCardTriggered);
}
}
void HandMenu::onRevealHandTriggered()
{
auto *action = qobject_cast<QAction *>(sender());
if (!action)
return;
const int targetId = action->data().toInt();
player->getPlayerActions()->actRevealHand(targetId);
}
void HandMenu::onRevealRandomHandCardTriggered()
{
auto *action = qobject_cast<QAction *>(sender());
if (!action)
return;
const int targetId = action->data().toInt();
player->getPlayerActions()->actRevealRandomHandCard(targetId);
}