mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-28 17:43:54 -07:00
[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:
parent
015570c833
commit
30e6b52783
10 changed files with 313 additions and 159 deletions
|
|
@ -1,7 +1,12 @@
|
||||||
#include "grave_menu.h"
|
#include "grave_menu.h"
|
||||||
|
|
||||||
|
#include "../../abstract_game.h"
|
||||||
#include "../player.h"
|
#include "../player.h"
|
||||||
#include "../player_actions.h"
|
#include "../player_actions.h"
|
||||||
|
#include "grave_menu.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
GraveyardMenu::GraveyardMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
|
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) {
|
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
||||||
mRevealRandomGraveyardCard = addMenu(QString());
|
mRevealRandomGraveyardCard = addMenu(QString());
|
||||||
QAction *newAction = mRevealRandomGraveyardCard->addAction(QString());
|
connect(mRevealRandomGraveyardCard, &QMenu::aboutToShow, this,
|
||||||
newAction->setData(-1);
|
&GraveyardMenu::populateRevealRandomMenuWithActivePlayers);
|
||||||
connect(newAction, &QAction::triggered, player->getPlayerActions(),
|
|
||||||
&PlayerActions::actRevealRandomGraveyardCard);
|
|
||||||
emit newPlayerActionCreated(newAction);
|
|
||||||
mRevealRandomGraveyardCard->addSeparator();
|
|
||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
moveGraveMenu = addTearOffMenu(QString());
|
moveGraveMenu = addTearOffMenu(QString());
|
||||||
moveGraveMenu->addAction(aMoveGraveToTopLibrary);
|
moveGraveMenu->addAction(aMoveGraveToTopLibrary);
|
||||||
moveGraveMenu->addAction(aMoveGraveToBottomLibrary);
|
moveGraveMenu->addAction(aMoveGraveToBottomLibrary);
|
||||||
|
|
@ -39,10 +41,13 @@ void GraveyardMenu::createMoveActions()
|
||||||
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
||||||
aMoveGraveToTopLibrary = new QAction(this);
|
aMoveGraveToTopLibrary = new QAction(this);
|
||||||
aMoveGraveToTopLibrary->setData(QList<QVariant>() << "deck" << 0);
|
aMoveGraveToTopLibrary->setData(QList<QVariant>() << "deck" << 0);
|
||||||
|
|
||||||
aMoveGraveToBottomLibrary = new QAction(this);
|
aMoveGraveToBottomLibrary = new QAction(this);
|
||||||
aMoveGraveToBottomLibrary->setData(QList<QVariant>() << "deck" << -1);
|
aMoveGraveToBottomLibrary->setData(QList<QVariant>() << "deck" << -1);
|
||||||
|
|
||||||
aMoveGraveToHand = new QAction(this);
|
aMoveGraveToHand = new QAction(this);
|
||||||
aMoveGraveToHand->setData(QList<QVariant>() << "hand" << 0);
|
aMoveGraveToHand->setData(QList<QVariant>() << "hand" << 0);
|
||||||
|
|
||||||
aMoveGraveToRfg = new QAction(this);
|
aMoveGraveToRfg = new QAction(this);
|
||||||
aMoveGraveToRfg->setData(QList<QVariant>() << "rfg" << 0);
|
aMoveGraveToRfg->setData(QList<QVariant>() << "rfg" << 0);
|
||||||
|
|
||||||
|
|
@ -61,6 +66,33 @@ void GraveyardMenu::createViewActions()
|
||||||
connect(aViewGraveyard, &QAction::triggered, playerActions, &PlayerActions::actViewGraveyard);
|
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()
|
void GraveyardMenu::retranslateUi()
|
||||||
{
|
{
|
||||||
setTitle(tr("&Graveyard"));
|
setTitle(tr("&Graveyard"));
|
||||||
|
|
@ -73,6 +105,7 @@ void GraveyardMenu::retranslateUi()
|
||||||
aMoveGraveToBottomLibrary->setText(tr("&Bottom of library"));
|
aMoveGraveToBottomLibrary->setText(tr("&Bottom of library"));
|
||||||
aMoveGraveToHand->setText(tr("&Hand"));
|
aMoveGraveToHand->setText(tr("&Hand"));
|
||||||
aMoveGraveToRfg->setText(tr("&Exile"));
|
aMoveGraveToRfg->setText(tr("&Exile"));
|
||||||
|
|
||||||
mRevealRandomGraveyardCard->setTitle(tr("Reveal random card to..."));
|
mRevealRandomGraveyardCard->setTitle(tr("Reveal random card to..."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -80,11 +113,10 @@ void GraveyardMenu::retranslateUi()
|
||||||
void GraveyardMenu::setShortcutsActive()
|
void GraveyardMenu::setShortcutsActive()
|
||||||
{
|
{
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
|
|
||||||
aViewGraveyard->setShortcuts(shortcuts.getShortcut("Player/aViewGraveyard"));
|
aViewGraveyard->setShortcuts(shortcuts.getShortcut("Player/aViewGraveyard"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraveyardMenu::setShortcutsInactive()
|
void GraveyardMenu::setShortcutsInactive()
|
||||||
{
|
{
|
||||||
aViewGraveyard->setShortcut(QKeySequence());
|
aViewGraveyard->setShortcut(QKeySequence());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ public:
|
||||||
explicit GraveyardMenu(Player *player, QWidget *parent = nullptr);
|
explicit GraveyardMenu(Player *player, QWidget *parent = nullptr);
|
||||||
void createMoveActions();
|
void createMoveActions();
|
||||||
void createViewActions();
|
void createViewActions();
|
||||||
|
void populateRevealRandomMenuWithActivePlayers();
|
||||||
|
void onRevealRandomTriggered();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
void setShortcutsActive();
|
void setShortcutsActive();
|
||||||
void setShortcutsInactive();
|
void setShortcutsInactive();
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
#include "hand_menu.h"
|
#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.h"
|
||||||
#include "../player_actions.h"
|
#include "../player_actions.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : TearOffMenu(parent), player(_player)
|
HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : TearOffMenu(parent), player(_player)
|
||||||
{
|
{
|
||||||
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
||||||
|
|
@ -16,7 +23,12 @@ HandMenu::HandMenu(Player *_player, PlayerActions *actions, QWidget *parent) : T
|
||||||
}
|
}
|
||||||
|
|
||||||
mRevealHand = addMenu(QString());
|
mRevealHand = addMenu(QString());
|
||||||
|
connect(mRevealHand, &QMenu::aboutToShow, this, &HandMenu::populateRevealHandMenuWithActivePlayers);
|
||||||
|
|
||||||
mRevealRandomHandCard = addMenu(QString());
|
mRevealRandomHandCard = addMenu(QString());
|
||||||
|
connect(mRevealRandomHandCard, &QMenu::aboutToShow, this,
|
||||||
|
&HandMenu::populateRevealRandomHandCardMenuWithActivePlayers);
|
||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
aMulligan = new QAction(this);
|
aMulligan = new QAction(this);
|
||||||
|
|
@ -78,7 +90,6 @@ void HandMenu::retranslateUi()
|
||||||
void HandMenu::setShortcutsActive()
|
void HandMenu::setShortcutsActive()
|
||||||
{
|
{
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
|
|
||||||
aViewHand->setShortcuts(shortcuts.getShortcut("Player/aViewHand"));
|
aViewHand->setShortcuts(shortcuts.getShortcut("Player/aViewHand"));
|
||||||
aSortHand->setShortcuts(shortcuts.getShortcut("Player/aSortHand"));
|
aSortHand->setShortcuts(shortcuts.getShortcut("Player/aSortHand"));
|
||||||
aMulligan->setShortcuts(shortcuts.getShortcut("Player/aMulligan"));
|
aMulligan->setShortcuts(shortcuts.getShortcut("Player/aMulligan"));
|
||||||
|
|
@ -90,3 +101,63 @@ void HandMenu::setShortcutsInactive()
|
||||||
aSortHand->setShortcut(QKeySequence());
|
aSortHand->setShortcut(QKeySequence());
|
||||||
aMulligan->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);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,10 @@ class PlayerActions;
|
||||||
class HandMenu : public TearOffMenu
|
class HandMenu : public TearOffMenu
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
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
|
public:
|
||||||
|
HandMenu(Player *player, PlayerActions *actions, QWidget *parent = nullptr);
|
||||||
|
|
||||||
QMenu *revealHandMenu() const
|
QMenu *revealHandMenu() const
|
||||||
{
|
{
|
||||||
return mRevealHand;
|
return mRevealHand;
|
||||||
|
|
@ -33,10 +30,16 @@ public:
|
||||||
{
|
{
|
||||||
return mRevealRandomHandCard;
|
return mRevealRandomHandCard;
|
||||||
}
|
}
|
||||||
QMenu *moveHandMenu() const
|
|
||||||
{
|
void retranslateUi();
|
||||||
return mMoveHandMenu;
|
void setShortcutsActive();
|
||||||
}
|
void setShortcutsInactive();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void populateRevealHandMenuWithActivePlayers();
|
||||||
|
void populateRevealRandomHandCardMenuWithActivePlayers();
|
||||||
|
void onRevealHandTriggered();
|
||||||
|
void onRevealRandomHandCardTriggered();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Player *player;
|
Player *player;
|
||||||
|
|
@ -47,8 +50,8 @@ private:
|
||||||
|
|
||||||
QMenu *mRevealHand = nullptr;
|
QMenu *mRevealHand = nullptr;
|
||||||
QMenu *mRevealRandomHandCard = nullptr;
|
QMenu *mRevealRandomHandCard = nullptr;
|
||||||
QMenu *mMoveHandMenu = nullptr;
|
|
||||||
|
|
||||||
|
QMenu *mMoveHandMenu = nullptr;
|
||||||
QAction *aMoveHandToTopLibrary = nullptr;
|
QAction *aMoveHandToTopLibrary = nullptr;
|
||||||
QAction *aMoveHandToBottomLibrary = nullptr;
|
QAction *aMoveHandToBottomLibrary = nullptr;
|
||||||
QAction *aMoveHandToGrave = nullptr;
|
QAction *aMoveHandToGrave = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,15 @@
|
||||||
#include "library_menu.h"
|
#include "library_menu.h"
|
||||||
|
|
||||||
|
#include "../../../settings/cache_settings.h"
|
||||||
|
#include "../../../settings/shortcuts_settings.h"
|
||||||
|
#include "../../../tabs/tab_game.h"
|
||||||
|
#include "../../abstract_game.h"
|
||||||
#include "../player.h"
|
#include "../player.h"
|
||||||
#include "../player_actions.h"
|
#include "../player_actions.h"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
LibraryMenu::LibraryMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
|
LibraryMenu::LibraryMenu(Player *_player, QWidget *parent) : TearOffMenu(parent), player(_player)
|
||||||
{
|
{
|
||||||
createDrawActions();
|
createDrawActions();
|
||||||
|
|
@ -20,9 +27,16 @@ LibraryMenu::LibraryMenu(Player *_player, QWidget *parent) : TearOffMenu(parent)
|
||||||
addAction(aViewTopCards);
|
addAction(aViewTopCards);
|
||||||
addAction(aViewBottomCards);
|
addAction(aViewBottomCards);
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
mRevealLibrary = addMenu(QString());
|
mRevealLibrary = addMenu(QString());
|
||||||
|
connect(mRevealLibrary, &QMenu::aboutToShow, this, &LibraryMenu::populateRevealLibraryMenuWithActivePlayers);
|
||||||
|
|
||||||
mLendLibrary = addMenu(QString());
|
mLendLibrary = addMenu(QString());
|
||||||
|
connect(mLendLibrary, &QMenu::aboutToShow, this, &LibraryMenu::populateLendLibraryMenuWithActivePlayers);
|
||||||
|
|
||||||
mRevealTopCard = addMenu(QString());
|
mRevealTopCard = addMenu(QString());
|
||||||
|
connect(mRevealTopCard, &QMenu::aboutToShow, this, &LibraryMenu::populateRevealTopCardMenuWithActivePlayers);
|
||||||
|
|
||||||
addAction(aAlwaysRevealTopCard);
|
addAction(aAlwaysRevealTopCard);
|
||||||
addAction(aAlwaysLookAtTopCard);
|
addAction(aAlwaysLookAtTopCard);
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
@ -30,6 +44,7 @@ LibraryMenu::LibraryMenu(Player *_player, QWidget *parent) : TearOffMenu(parent)
|
||||||
bottomLibraryMenu = addTearOffMenu(QString());
|
bottomLibraryMenu = addTearOffMenu(QString());
|
||||||
addSeparator();
|
addSeparator();
|
||||||
addAction(aOpenDeckInDeckEditor);
|
addAction(aOpenDeckInDeckEditor);
|
||||||
|
|
||||||
topLibraryMenu->addAction(aMoveTopToPlay);
|
topLibraryMenu->addAction(aMoveTopToPlay);
|
||||||
topLibraryMenu->addAction(aMoveTopToPlayFaceDown);
|
topLibraryMenu->addAction(aMoveTopToPlayFaceDown);
|
||||||
topLibraryMenu->addAction(aMoveTopCardToBottom);
|
topLibraryMenu->addAction(aMoveTopCardToBottom);
|
||||||
|
|
@ -218,6 +233,89 @@ void LibraryMenu::retranslateUi()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LibraryMenu::populateRevealLibraryMenuWithActivePlayers()
|
||||||
|
{
|
||||||
|
mRevealLibrary->clear();
|
||||||
|
|
||||||
|
QAction *allPlayers = mRevealLibrary->addAction(tr("&All players"));
|
||||||
|
allPlayers->setData(-1);
|
||||||
|
connect(allPlayers, &QAction::triggered, this, &LibraryMenu::onRevealLibraryTriggered);
|
||||||
|
|
||||||
|
mRevealLibrary->addSeparator();
|
||||||
|
|
||||||
|
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||||
|
for (auto *other : players) {
|
||||||
|
if (other == player)
|
||||||
|
continue;
|
||||||
|
QAction *a = mRevealLibrary->addAction(other->getPlayerInfo()->getName());
|
||||||
|
a->setData(other->getPlayerInfo()->getId());
|
||||||
|
connect(a, &QAction::triggered, this, &LibraryMenu::onRevealLibraryTriggered);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryMenu::populateLendLibraryMenuWithActivePlayers()
|
||||||
|
{
|
||||||
|
mLendLibrary->clear();
|
||||||
|
|
||||||
|
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||||
|
for (auto *other : players) {
|
||||||
|
if (other == player)
|
||||||
|
continue;
|
||||||
|
QAction *a = mLendLibrary->addAction(other->getPlayerInfo()->getName());
|
||||||
|
a->setData(other->getPlayerInfo()->getId());
|
||||||
|
connect(a, &QAction::triggered, this, &LibraryMenu::onLendLibraryTriggered);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryMenu::populateRevealTopCardMenuWithActivePlayers()
|
||||||
|
{
|
||||||
|
mRevealTopCard->clear();
|
||||||
|
|
||||||
|
QAction *allPlayers = mRevealTopCard->addAction(tr("&All players"));
|
||||||
|
allPlayers->setData(-1);
|
||||||
|
connect(allPlayers, &QAction::triggered, this, &LibraryMenu::onRevealTopCardTriggered);
|
||||||
|
|
||||||
|
mRevealTopCard->addSeparator();
|
||||||
|
|
||||||
|
const auto &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||||
|
for (auto *other : players) {
|
||||||
|
if (other == player)
|
||||||
|
continue;
|
||||||
|
QAction *a = mRevealTopCard->addAction(other->getPlayerInfo()->getName());
|
||||||
|
a->setData(other->getPlayerInfo()->getId());
|
||||||
|
connect(a, &QAction::triggered, this, &LibraryMenu::onRevealTopCardTriggered);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryMenu::onRevealLibraryTriggered()
|
||||||
|
{
|
||||||
|
if (auto *a = qobject_cast<QAction *>(sender())) {
|
||||||
|
player->getPlayerActions()->actRevealLibrary(a->data().toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryMenu::onLendLibraryTriggered()
|
||||||
|
{
|
||||||
|
if (auto *a = qobject_cast<QAction *>(sender())) {
|
||||||
|
player->getPlayerActions()->actLendLibrary(a->data().toInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryMenu::onRevealTopCardTriggered()
|
||||||
|
{
|
||||||
|
if (auto *a = qobject_cast<QAction *>(sender())) {
|
||||||
|
int deckSize = player->getDeckZone()->getCards().size();
|
||||||
|
bool ok;
|
||||||
|
int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Reveal top cards of library"),
|
||||||
|
tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1,
|
||||||
|
deckSize, 1, &ok);
|
||||||
|
if (ok) {
|
||||||
|
player->getPlayerActions()->actRevealTopCards(a->data().toInt(), number);
|
||||||
|
defaultNumberTopCards = number;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LibraryMenu::setShortcutsActive()
|
void LibraryMenu::setShortcutsActive()
|
||||||
{
|
{
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
|
|
@ -280,4 +378,4 @@ void LibraryMenu::setShortcutsInactive()
|
||||||
aMoveBottomCardsToGraveyard->setShortcut(QKeySequence());
|
aMoveBottomCardsToGraveyard->setShortcut(QKeySequence());
|
||||||
aMoveBottomCardToExile->setShortcut(QKeySequence());
|
aMoveBottomCardToExile->setShortcut(QKeySequence());
|
||||||
aMoveBottomCardsToExile->setShortcut(QKeySequence());
|
aMoveBottomCardsToExile->setShortcut(QKeySequence());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,12 @@ public:
|
||||||
void createMoveActions();
|
void createMoveActions();
|
||||||
void createViewActions();
|
void createViewActions();
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
void populateRevealLibraryMenuWithActivePlayers();
|
||||||
|
void populateLendLibraryMenuWithActivePlayers();
|
||||||
|
void populateRevealTopCardMenuWithActivePlayers();
|
||||||
|
void onRevealLibraryTriggered();
|
||||||
|
void onLendLibraryTriggered();
|
||||||
|
void onRevealTopCardTriggered();
|
||||||
void setShortcutsActive();
|
void setShortcutsActive();
|
||||||
void setShortcutsInactive();
|
void setShortcutsInactive();
|
||||||
|
|
||||||
|
|
@ -97,6 +103,8 @@ public:
|
||||||
QAction *aMoveBottomCardsToExile = nullptr;
|
QAction *aMoveBottomCardsToExile = nullptr;
|
||||||
QAction *aShuffleBottomCards = nullptr;
|
QAction *aShuffleBottomCards = nullptr;
|
||||||
|
|
||||||
|
int defaultNumberTopCards = 1;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Player *player;
|
Player *player;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,29 +12,13 @@
|
||||||
|
|
||||||
PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
|
||||||
connect(player->getGame()->getPlayerManager(), &PlayerManager::playerAdded, this, &PlayerMenu::addPlayer);
|
|
||||||
connect(player->getGame()->getPlayerManager(), &PlayerManager::playerRemoved, this, &PlayerMenu::removePlayer);
|
|
||||||
}
|
|
||||||
|
|
||||||
const QList<Player *> &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
|
||||||
for (const auto playerToAdd : players) {
|
|
||||||
addPlayer(playerToAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
playerMenu = new TearOffMenu();
|
playerMenu = new TearOffMenu();
|
||||||
|
|
||||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||||
handMenu = new HandMenu(player, player->getPlayerActions(), playerMenu);
|
handMenu = new HandMenu(player, player->getPlayerActions(), playerMenu);
|
||||||
playerMenu->addMenu(handMenu);
|
playerMenu->addMenu(handMenu);
|
||||||
playerLists.append(handMenu->revealHandMenu());
|
|
||||||
playerLists.append(handMenu->revealRandomHandCardMenu());
|
|
||||||
|
|
||||||
libraryMenu = new LibraryMenu(player, playerMenu);
|
libraryMenu = new LibraryMenu(player, playerMenu);
|
||||||
playerLists.append(libraryMenu->revealLibrary());
|
|
||||||
playerLists.append(libraryMenu->lendLibraryMenu());
|
|
||||||
playerLists.append(libraryMenu->revealTopCardMenu());
|
|
||||||
playerMenu->addMenu(libraryMenu);
|
playerMenu->addMenu(libraryMenu);
|
||||||
} else {
|
} else {
|
||||||
handMenu = nullptr;
|
handMenu = nullptr;
|
||||||
|
|
@ -42,7 +26,6 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
}
|
}
|
||||||
|
|
||||||
graveMenu = new GraveyardMenu(player, playerMenu);
|
graveMenu = new GraveyardMenu(player, playerMenu);
|
||||||
connect(graveMenu, &GraveyardMenu::newPlayerActionCreated, this, &PlayerMenu::onNewPlayerListActionCreated);
|
|
||||||
playerMenu->addMenu(graveMenu);
|
playerMenu->addMenu(graveMenu);
|
||||||
|
|
||||||
rfgMenu = new RfgMenu(player, playerMenu);
|
rfgMenu = new RfgMenu(player, playerMenu);
|
||||||
|
|
@ -73,17 +56,6 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
sayMenu = nullptr;
|
sayMenu = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
|
||||||
|
|
||||||
for (auto &playerList : playerLists) {
|
|
||||||
QAction *newAction = playerList->addAction(QString());
|
|
||||||
newAction->setData(-1);
|
|
||||||
connect(newAction, &QAction::triggered, this, &PlayerMenu::playerListActionTriggered);
|
|
||||||
allPlayersActions.append(newAction);
|
|
||||||
playerList->addSeparator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||||
&PlayerMenu::refreshShortcuts);
|
&PlayerMenu::refreshShortcuts);
|
||||||
refreshShortcuts();
|
refreshShortcuts();
|
||||||
|
|
@ -103,89 +75,6 @@ void PlayerMenu::setMenusForGraphicItems()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMenu::addPlayer(Player *playerToAdd)
|
|
||||||
{
|
|
||||||
if (playerToAdd == nullptr || playerToAdd == player) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &playerList : playerLists) {
|
|
||||||
addPlayerToList(playerList, playerToAdd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerMenu::addPlayerToList(QMenu *playerList, Player *playerToAdd)
|
|
||||||
{
|
|
||||||
QAction *newAction = playerList->addAction(playerToAdd->getPlayerInfo()->getName());
|
|
||||||
newAction->setData(playerToAdd->getPlayerInfo()->getId());
|
|
||||||
connect(newAction, &QAction::triggered, this, &PlayerMenu::playerListActionTriggered);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerMenu::removePlayer(Player *playerToRemove)
|
|
||||||
{
|
|
||||||
if (playerToRemove == nullptr) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &playerList : playerLists) {
|
|
||||||
removePlayerFromList(playerList, playerToRemove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerMenu::removePlayerFromList(QMenu *playerList, Player *player)
|
|
||||||
{
|
|
||||||
QList<QAction *> actionList = playerList->actions();
|
|
||||||
for (auto &j : actionList)
|
|
||||||
if (j->data().toInt() == player->getPlayerInfo()->getId()) {
|
|
||||||
playerList->removeAction(j);
|
|
||||||
j->deleteLater();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerMenu::playerListActionTriggered()
|
|
||||||
{
|
|
||||||
auto *action = static_cast<QAction *>(sender());
|
|
||||||
auto *menu = static_cast<QMenu *>(action->parent());
|
|
||||||
|
|
||||||
Command_RevealCards cmd;
|
|
||||||
const int otherPlayerId = action->data().toInt();
|
|
||||||
if (otherPlayerId != -1) {
|
|
||||||
cmd.set_player_id(otherPlayerId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (menu == libraryMenu->revealLibrary() || menu == libraryMenu->lendLibraryMenu()) {
|
|
||||||
cmd.set_zone_name("deck");
|
|
||||||
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"),
|
|
||||||
tr("Number of cards: (max. %1)").arg(deckSize), /* defaultNumberTopCards */ 1,
|
|
||||||
1, deckSize, 1, &ok);
|
|
||||||
if (ok) {
|
|
||||||
cmd.set_zone_name("deck");
|
|
||||||
cmd.set_top_cards(number);
|
|
||||||
// backward compatibility: servers before #1051 only permits to reveal the first card
|
|
||||||
cmd.add_card_id(0);
|
|
||||||
// defaultNumberTopCards = number;
|
|
||||||
}
|
|
||||||
} else if (menu == handMenu->revealHandMenu()) {
|
|
||||||
cmd.set_zone_name("hand");
|
|
||||||
} else if (menu == handMenu->revealRandomHandCardMenu()) {
|
|
||||||
cmd.set_zone_name("hand");
|
|
||||||
cmd.add_card_id(PlayerActions::RANDOM_CARD_FROM_ZONE);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
player->getPlayerActions()->sendGameCommand(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerMenu::onNewPlayerListActionCreated(QAction *action)
|
|
||||||
{
|
|
||||||
allPlayersActions.append(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
QMenu *PlayerMenu::updateCardMenu(const CardItem *card)
|
QMenu *PlayerMenu::updateCardMenu(const CardItem *card)
|
||||||
{
|
{
|
||||||
if (!card) {
|
if (!card) {
|
||||||
|
|
@ -241,10 +130,6 @@ void PlayerMenu::retranslateUi()
|
||||||
utilityMenu->retranslateUi();
|
utilityMenu->retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &allPlayersAction : allPlayersActions) {
|
|
||||||
allPlayersAction->setText(tr("&All players"));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sayMenu) {
|
if (sayMenu) {
|
||||||
sayMenu->setTitle(tr("S&ay"));
|
sayMenu->setTitle(tr("S&ay"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,19 +33,12 @@ public slots:
|
||||||
void setMenusForGraphicItems();
|
void setMenusForGraphicItems();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void addPlayer(Player *playerToAdd);
|
|
||||||
void removePlayer(Player *playerToRemove);
|
|
||||||
void playerListActionTriggered();
|
|
||||||
void onNewPlayerListActionCreated(QAction *action);
|
|
||||||
void refreshShortcuts();
|
void refreshShortcuts();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlayerMenu(Player *player);
|
PlayerMenu(Player *player);
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
||||||
void addPlayerToList(QMenu *playerList, Player *playerToAdd);
|
|
||||||
static void removePlayerFromList(QMenu *playerList, Player *player);
|
|
||||||
|
|
||||||
QMenu *updateCardMenu(const CardItem *card);
|
QMenu *updateCardMenu(const CardItem *card);
|
||||||
|
|
||||||
[[nodiscard]] QMenu *getPlayerMenu() const
|
[[nodiscard]] QMenu *getPlayerMenu() const
|
||||||
|
|
@ -88,8 +81,6 @@ private:
|
||||||
UtilityMenu *utilityMenu;
|
UtilityMenu *utilityMenu;
|
||||||
SayMenu *sayMenu;
|
SayMenu *sayMenu;
|
||||||
CustomZoneMenu *customZonesMenu;
|
CustomZoneMenu *customZonesMenu;
|
||||||
QList<QMenu *> playerLists;
|
|
||||||
QList<QAction *> allPlayersActions;
|
|
||||||
|
|
||||||
bool shortcutsActive;
|
bool shortcutsActive;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -197,19 +197,6 @@ void PlayerActions::actViewGraveyard()
|
||||||
player->getGameScene()->toggleZoneView(player, "grave", -1);
|
player->getGameScene()->toggleZoneView(player, "grave", -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerActions::actRevealRandomGraveyardCard()
|
|
||||||
{
|
|
||||||
Command_RevealCards cmd;
|
|
||||||
auto *action = dynamic_cast<QAction *>(sender());
|
|
||||||
const int otherPlayerId = action->data().toInt();
|
|
||||||
if (otherPlayerId != -1) {
|
|
||||||
cmd.set_player_id(otherPlayerId);
|
|
||||||
}
|
|
||||||
cmd.set_zone_name("grave");
|
|
||||||
cmd.add_card_id(RANDOM_CARD_FROM_ZONE);
|
|
||||||
sendGameCommand(cmd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerActions::actViewRfg()
|
void PlayerActions::actViewRfg()
|
||||||
{
|
{
|
||||||
player->getGameScene()->toggleZoneView(player, "rfg", -1);
|
player->getGameScene()->toggleZoneView(player, "rfg", -1);
|
||||||
|
|
@ -1662,6 +1649,78 @@ void PlayerActions::actReveal(QAction *action)
|
||||||
sendGameCommand(cmd);
|
sendGameCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlayerActions::actRevealHand(int revealToPlayerId)
|
||||||
|
{
|
||||||
|
Command_RevealCards cmd;
|
||||||
|
if (revealToPlayerId != -1) {
|
||||||
|
cmd.set_player_id(revealToPlayerId);
|
||||||
|
}
|
||||||
|
cmd.set_zone_name("hand");
|
||||||
|
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerActions::actRevealRandomHandCard(int revealToPlayerId)
|
||||||
|
{
|
||||||
|
Command_RevealCards cmd;
|
||||||
|
if (revealToPlayerId != -1) {
|
||||||
|
cmd.set_player_id(revealToPlayerId);
|
||||||
|
}
|
||||||
|
cmd.set_zone_name("hand");
|
||||||
|
cmd.add_card_id(RANDOM_CARD_FROM_ZONE);
|
||||||
|
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerActions::actRevealLibrary(int revealToPlayerId)
|
||||||
|
{
|
||||||
|
Command_RevealCards cmd;
|
||||||
|
if (revealToPlayerId != -1) {
|
||||||
|
cmd.set_player_id(revealToPlayerId);
|
||||||
|
}
|
||||||
|
cmd.set_zone_name("deck");
|
||||||
|
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerActions::actLendLibrary(int lendToPlayerId)
|
||||||
|
{
|
||||||
|
Command_RevealCards cmd;
|
||||||
|
if (lendToPlayerId != -1) {
|
||||||
|
cmd.set_player_id(lendToPlayerId);
|
||||||
|
}
|
||||||
|
cmd.set_zone_name("deck");
|
||||||
|
cmd.set_grant_write_access(true);
|
||||||
|
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerActions::actRevealTopCards(int revealToPlayerId, int amount)
|
||||||
|
{
|
||||||
|
Command_RevealCards cmd;
|
||||||
|
if (revealToPlayerId != -1) {
|
||||||
|
cmd.set_player_id(revealToPlayerId);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.set_zone_name("deck");
|
||||||
|
cmd.set_top_cards(amount);
|
||||||
|
// backward compatibility: servers before #1051 only permits to reveal the first card
|
||||||
|
cmd.add_card_id(0);
|
||||||
|
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlayerActions::actRevealRandomGraveyardCard(int revealToPlayerId)
|
||||||
|
{
|
||||||
|
Command_RevealCards cmd;
|
||||||
|
if (revealToPlayerId != -1) {
|
||||||
|
cmd.set_player_id(revealToPlayerId);
|
||||||
|
}
|
||||||
|
cmd.set_zone_name("grave");
|
||||||
|
cmd.add_card_id(RANDOM_CARD_FROM_ZONE);
|
||||||
|
sendGameCommand(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
void PlayerActions::cardMenuAction()
|
void PlayerActions::cardMenuAction()
|
||||||
{
|
{
|
||||||
auto *a = dynamic_cast<QAction *>(sender());
|
auto *a = dynamic_cast<QAction *>(sender());
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,9 @@ public slots:
|
||||||
void actAlwaysRevealTopCard();
|
void actAlwaysRevealTopCard();
|
||||||
void actAlwaysLookAtTopCard();
|
void actAlwaysLookAtTopCard();
|
||||||
void actViewGraveyard();
|
void actViewGraveyard();
|
||||||
void actRevealRandomGraveyardCard();
|
void actLendLibrary(int lendToPlayerId);
|
||||||
|
void actRevealTopCards(int revealToPlayerId, int amount);
|
||||||
|
void actRevealRandomGraveyardCard(int revealToPlayerId);
|
||||||
void actViewRfg();
|
void actViewRfg();
|
||||||
void actViewSideboard();
|
void actViewSideboard();
|
||||||
|
|
||||||
|
|
@ -145,6 +147,9 @@ public slots:
|
||||||
void actFlowT();
|
void actFlowT();
|
||||||
void actSetAnnotation();
|
void actSetAnnotation();
|
||||||
void actReveal(QAction *action);
|
void actReveal(QAction *action);
|
||||||
|
void actRevealHand(int revealToPlayerId);
|
||||||
|
void actRevealRandomHandCard(int revealToPlayerId);
|
||||||
|
void actRevealLibrary(int revealToPlayerId);
|
||||||
|
|
||||||
void actSortHand();
|
void actSortHand();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue