mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-18 00:12:15 -07:00
Set active shortcuts, move player info stuff to card menu.
Took 25 minutes Took 18 seconds
This commit is contained in:
parent
a19229d0c7
commit
8bc2127b4d
6 changed files with 69 additions and 65 deletions
|
|
@ -11,14 +11,22 @@
|
||||||
#include "move_menu.h"
|
#include "move_menu.h"
|
||||||
#include "pt_menu.h"
|
#include "pt_menu.h"
|
||||||
|
|
||||||
CardMenu::CardMenu(Player *_player,
|
CardMenu::CardMenu(Player *_player, const CardItem *_card, bool _shortcutsActive)
|
||||||
const CardItem *_card,
|
: player(_player), card(_card), shortcutsActive(_shortcutsActive)
|
||||||
QList<QPair<QString, int>> _playersInfo,
|
|
||||||
bool _shortcutsActive)
|
|
||||||
: player(_player), card(_card), playersInfo(_playersInfo), shortcutsActive(_shortcutsActive)
|
|
||||||
{
|
{
|
||||||
auto playerActions = player->getPlayerActions();
|
auto playerActions = player->getPlayerActions();
|
||||||
|
|
||||||
|
const QList<Player *> &players = player->getGame()->getPlayerManager()->getPlayers().values();
|
||||||
|
|
||||||
|
for (auto playerToAdd : players) {
|
||||||
|
if (playerToAdd == player) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
playersInfo.append(qMakePair(playerToAdd->getPlayerInfo()->getName(), playerToAdd->getPlayerInfo()->getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(player->getGame()->getPlayerManager(), &PlayerManager::playerRemoved, this, &CardMenu::removePlayer);
|
||||||
|
|
||||||
aTap = new QAction(this);
|
aTap = new QAction(this);
|
||||||
aTap->setData(cmTap);
|
aTap->setData(cmTap);
|
||||||
connect(aTap, &QAction::triggered, playerActions, &PlayerActions::cardMenuAction);
|
connect(aTap, &QAction::triggered, playerActions, &PlayerActions::cardMenuAction);
|
||||||
|
|
@ -73,6 +81,8 @@ CardMenu::CardMenu(Player *_player,
|
||||||
connect(tempSetCounter, &QAction::triggered, playerActions, &PlayerActions::actCardCounterTrigger);
|
connect(tempSetCounter, &QAction::triggered, playerActions, &PlayerActions::actCardCounterTrigger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setShortcutsActive();
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
|
|
||||||
if (card == nullptr) {
|
if (card == nullptr) {
|
||||||
|
|
@ -127,6 +137,17 @@ CardMenu::CardMenu(Player *_player,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardMenu::removePlayer(Player *playerToRemove)
|
||||||
|
{
|
||||||
|
for (auto it = playersInfo.begin(); it != playersInfo.end();) {
|
||||||
|
if (it->second == playerToRemove->getPlayerInfo()->getId()) {
|
||||||
|
it = playersInfo.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CardMenu::createTableMenu()
|
void CardMenu::createTableMenu()
|
||||||
{
|
{
|
||||||
// Card is on the battlefield
|
// Card is on the battlefield
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ class CardMenu : public QMenu
|
||||||
public:
|
public:
|
||||||
explicit CardMenu(Player *player,
|
explicit CardMenu(Player *player,
|
||||||
const CardItem *card,
|
const CardItem *card,
|
||||||
QList<QPair<QString, int>> playersInfo,
|
|
||||||
bool shortcutsActive);
|
bool shortcutsActive);
|
||||||
|
void removePlayer(Player *playerToRemove);
|
||||||
void createTableMenu();
|
void createTableMenu();
|
||||||
void createStackMenu();
|
void createStackMenu();
|
||||||
void createGraveyardOrExileMenu();
|
void createGraveyardOrExileMenu();
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,8 @@ MoveMenu::MoveMenu(Player *player) : QMenu(tr("Move to"))
|
||||||
addSeparator();
|
addSeparator();
|
||||||
addAction(aMoveToExile);
|
addAction(aMoveToExile);
|
||||||
|
|
||||||
|
setShortcutsActive();
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,11 +25,9 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
|
|
||||||
PlayerActions *playerActions = player->getPlayerActions();
|
PlayerActions *playerActions = player->getPlayerActions();
|
||||||
|
|
||||||
createViewActions();
|
|
||||||
|
|
||||||
playerMenu = new TearOffMenu();
|
playerMenu = new TearOffMenu();
|
||||||
|
|
||||||
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
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(mRevealHand = handMenu->addMenu(QString()));
|
/*playerLists.append(mRevealHand = handMenu->addMenu(QString()));
|
||||||
|
|
@ -37,6 +35,9 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
|
|
||||||
libraryMenu = new LibraryMenu(player, playerMenu);
|
libraryMenu = new LibraryMenu(player, playerMenu);
|
||||||
playerMenu->addMenu(libraryMenu);
|
playerMenu->addMenu(libraryMenu);
|
||||||
|
} else {
|
||||||
|
handMenu = nullptr;
|
||||||
|
libraryMenu = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
graveMenu = new GraveyardMenu(player, playerMenu);
|
graveMenu = new GraveyardMenu(player, playerMenu);
|
||||||
|
|
@ -45,8 +46,12 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
rfgMenu = new RfgMenu(player, playerMenu);
|
rfgMenu = new RfgMenu(player, playerMenu);
|
||||||
playerMenu->addMenu(rfgMenu);
|
playerMenu->addMenu(rfgMenu);
|
||||||
|
|
||||||
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||||
sbMenu = playerMenu->addMenu(QString());
|
sbMenu = playerMenu->addMenu(QString());
|
||||||
|
|
||||||
|
aViewSideboard = new QAction(this);
|
||||||
|
connect(aViewSideboard, &QAction::triggered, playerActions, &PlayerActions::actViewSideboard);
|
||||||
|
|
||||||
sbMenu->addAction(aViewSideboard);
|
sbMenu->addAction(aViewSideboard);
|
||||||
|
|
||||||
mCustomZones = playerMenu->addMenu(QString());
|
mCustomZones = playerMenu->addMenu(QString());
|
||||||
|
|
@ -83,16 +88,30 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
playerMenu->addAction(aCreateAnotherToken);
|
playerMenu->addAction(aCreateAnotherToken);
|
||||||
playerMenu->addMenu(createPredefinedTokenMenu);
|
playerMenu->addMenu(createPredefinedTokenMenu);
|
||||||
playerMenu->addSeparator();
|
playerMenu->addSeparator();
|
||||||
|
} else {
|
||||||
|
countersMenu = nullptr;
|
||||||
|
sbMenu = nullptr;
|
||||||
|
mCustomZones = nullptr;
|
||||||
|
aCreateToken = nullptr;
|
||||||
|
aCreateAnotherToken = nullptr;
|
||||||
|
createPredefinedTokenMenu = nullptr;
|
||||||
|
aIncrementAllCardCounters = nullptr;
|
||||||
|
|
||||||
|
aViewSideboard = nullptr;
|
||||||
|
sbMenu = nullptr;
|
||||||
|
|
||||||
|
aUntapAll = nullptr;
|
||||||
|
aRollDie = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->getPlayerInfo()->local) {
|
if (player->getPlayerInfo()->getLocal()) {
|
||||||
sayMenu = playerMenu->addMenu(QString());
|
sayMenu = playerMenu->addMenu(QString());
|
||||||
connect(&SettingsCache::instance().messages(), &MessageSettings::messageMacrosChanged, this,
|
connect(&SettingsCache::instance().messages(), &MessageSettings::messageMacrosChanged, this,
|
||||||
&PlayerMenu::initSayMenu);
|
&PlayerMenu::initSayMenu);
|
||||||
initSayMenu();
|
initSayMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||||
|
|
||||||
for (auto &playerList : playerLists) {
|
for (auto &playerList : playerLists) {
|
||||||
QAction *newAction = playerList->addAction(QString());
|
QAction *newAction = playerList->addAction(QString());
|
||||||
|
|
@ -103,25 +122,6 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have to explicitly not-instantiate a bunch of things if we are not local or a judge or else we have to
|
|
||||||
// consider it everywhere instead of just null-checking
|
|
||||||
if (!player->getPlayerInfo()->local && !player->getPlayerInfo()->judge) {
|
|
||||||
countersMenu = nullptr;
|
|
||||||
sbMenu = nullptr;
|
|
||||||
mCustomZones = nullptr;
|
|
||||||
aCreateAnotherToken = nullptr;
|
|
||||||
createPredefinedTokenMenu = nullptr;
|
|
||||||
aIncrementAllCardCounters = nullptr;
|
|
||||||
|
|
||||||
aViewSideboard = nullptr;
|
|
||||||
handMenu = nullptr;
|
|
||||||
sbMenu = nullptr;
|
|
||||||
libraryMenu = nullptr;
|
|
||||||
|
|
||||||
aUntapAll = nullptr;
|
|
||||||
aRollDie = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
connect(&SettingsCache::instance().shortcuts(), &ShortcutsSettings::shortCutChanged, this,
|
||||||
&PlayerMenu::refreshShortcuts);
|
&PlayerMenu::refreshShortcuts);
|
||||||
refreshShortcuts();
|
refreshShortcuts();
|
||||||
|
|
@ -136,25 +136,15 @@ PlayerMenu::PlayerMenu(Player *_player) : player(_player)
|
||||||
void PlayerMenu::setMenusForGraphicItems()
|
void PlayerMenu::setMenusForGraphicItems()
|
||||||
{
|
{
|
||||||
player->getGraphicsItem()->getTableZoneGraphicsItem()->setMenu(playerMenu);
|
player->getGraphicsItem()->getTableZoneGraphicsItem()->setMenu(playerMenu);
|
||||||
// player->getGraphicsItem()->getGraveyardZoneGraphicsItem()->setMenu(graveMenu, aViewGraveyard);
|
player->getGraphicsItem()->getGraveyardZoneGraphicsItem()->setMenu(graveMenu, graveMenu->aViewGraveyard);
|
||||||
// player->getGraphicsItem()->getRfgZoneGraphicsItem()->setMenu(rfgMenu, aViewRfg);
|
player->getGraphicsItem()->getRfgZoneGraphicsItem()->setMenu(rfgMenu, rfgMenu->aViewRfg);
|
||||||
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
if (player->getPlayerInfo()->getLocalOrJudge()) {
|
||||||
player->getGraphicsItem()->getHandZoneGraphicsItem()->setMenu(handMenu);
|
player->getGraphicsItem()->getHandZoneGraphicsItem()->setMenu(handMenu);
|
||||||
// player->getGraphicsItem()->getDeckZoneGraphicsItem()->setMenu(libraryMenu, aDrawCard);
|
player->getGraphicsItem()->getDeckZoneGraphicsItem()->setMenu(libraryMenu, libraryMenu->aDrawCard);
|
||||||
player->getGraphicsItem()->getSideboardZoneGraphicsItem()->setMenu(sbMenu);
|
player->getGraphicsItem()->getSideboardZoneGraphicsItem()->setMenu(sbMenu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMenu::createViewActions()
|
|
||||||
{
|
|
||||||
PlayerActions *playerActions = player->getPlayerActions();
|
|
||||||
|
|
||||||
if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) {
|
|
||||||
aViewSideboard = new QAction(this);
|
|
||||||
connect(aViewSideboard, &QAction::triggered, playerActions, &PlayerActions::actViewSideboard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PlayerMenu::refreshShortcuts()
|
void PlayerMenu::refreshShortcuts()
|
||||||
{
|
{
|
||||||
if (shortcutsActive) {
|
if (shortcutsActive) {
|
||||||
|
|
@ -171,11 +161,6 @@ void PlayerMenu::addPlayer(Player *playerToAdd)
|
||||||
for (auto &playerList : playerLists) {
|
for (auto &playerList : playerLists) {
|
||||||
addPlayerToList(playerList, playerToAdd);
|
addPlayerToList(playerList, playerToAdd);
|
||||||
}
|
}
|
||||||
for (auto &playerList : singlePlayerLists) {
|
|
||||||
addPlayerToList(playerList, playerToAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
playersInfo.append(qMakePair(playerToAdd->getPlayerInfo()->getName(), playerToAdd->getPlayerInfo()->getId()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMenu::addPlayerToList(QMenu *playerList, Player *playerToAdd)
|
void PlayerMenu::addPlayerToList(QMenu *playerList, Player *playerToAdd)
|
||||||
|
|
@ -194,17 +179,6 @@ void PlayerMenu::removePlayer(Player *playerToRemove)
|
||||||
for (auto &playerList : playerLists) {
|
for (auto &playerList : playerLists) {
|
||||||
removePlayerFromList(playerList, playerToRemove);
|
removePlayerFromList(playerList, playerToRemove);
|
||||||
}
|
}
|
||||||
for (auto &playerList : singlePlayerLists) {
|
|
||||||
removePlayerFromList(playerList, playerToRemove);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto it = playersInfo.begin(); it != playersInfo.end();) {
|
|
||||||
if (it->second == playerToRemove->getPlayerInfo()->getId()) {
|
|
||||||
it = playersInfo.erase(it);
|
|
||||||
} else {
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerMenu::removePlayerFromList(QMenu *playerList, Player *player)
|
void PlayerMenu::removePlayerFromList(QMenu *playerList, Player *player)
|
||||||
|
|
@ -270,7 +244,7 @@ QMenu *PlayerMenu::updateCardMenu(const CardItem *card)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenu *menu = new CardMenu(player, card, playersInfo, shortcutsActive);
|
QMenu *menu = new CardMenu(player, card, shortcutsActive);
|
||||||
emit cardMenuUpdated(menu);
|
emit cardMenuUpdated(menu);
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
|
|
@ -375,6 +349,14 @@ void PlayerMenu::setShortcutsActive()
|
||||||
shortcutsActive = true;
|
shortcutsActive = true;
|
||||||
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts();
|
||||||
|
|
||||||
|
if (handMenu) {
|
||||||
|
handMenu->setShortcutsActive();
|
||||||
|
}
|
||||||
|
if (libraryMenu) {
|
||||||
|
libraryMenu->setShortcutsActive();
|
||||||
|
}
|
||||||
|
graveMenu->setShortcutsActive();
|
||||||
|
|
||||||
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
QMapIterator<int, AbstractCounter *> counterIterator(player->getCounters());
|
||||||
while (counterIterator.hasNext()) {
|
while (counterIterator.hasNext()) {
|
||||||
counterIterator.next().value()->setShortcutsActive();
|
counterIterator.next().value()->setShortcutsActive();
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ private slots:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PlayerMenu(Player *player);
|
PlayerMenu(Player *player);
|
||||||
void createViewActions();
|
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
||||||
void addPlayerToList(QMenu *playerList, Player *playerToAdd);
|
void addPlayerToList(QMenu *playerList, Player *playerToAdd);
|
||||||
|
|
@ -90,9 +89,7 @@ private:
|
||||||
RfgMenu *rfgMenu;
|
RfgMenu *rfgMenu;
|
||||||
TearOffMenu *playerMenu;
|
TearOffMenu *playerMenu;
|
||||||
QList<QMenu *> playerLists;
|
QList<QMenu *> playerLists;
|
||||||
QList<QMenu *> singlePlayerLists;
|
|
||||||
QList<QAction *> allPlayersActions;
|
QList<QAction *> allPlayersActions;
|
||||||
QList<QPair<QString, int>> playersInfo;
|
|
||||||
QAction *aViewSideboard, *aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken;
|
QAction *aViewSideboard, *aUntapAll, *aRollDie, *aCreateToken, *aCreateAnotherToken;
|
||||||
|
|
||||||
QAction *aIncrementAllCardCounters;
|
QAction *aIncrementAllCardCounters;
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,8 @@ PtMenu::PtMenu(Player *player) : QMenu(tr("Power / toughness"))
|
||||||
addAction(aSetPT);
|
addAction(aSetPT);
|
||||||
addAction(aResetPT);
|
addAction(aResetPT);
|
||||||
|
|
||||||
|
setShortcutsActive();
|
||||||
|
|
||||||
retranslateUi();
|
retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue