diff --git a/cockatrice/src/client/tabs/tab_game.cpp b/cockatrice/src/client/tabs/tab_game.cpp index 7f5aa6394..c4a505ee5 100644 --- a/cockatrice/src/client/tabs/tab_game.cpp +++ b/cockatrice/src/client/tabs/tab_game.cpp @@ -97,7 +97,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, : Tab(_tabSupervisor), userListProxy(_tabSupervisor->getUserListManager()) { // THIS CTOR IS USED ON GAMES - game = new Game(_clients, event, _roomGameTypes); + game = new Game(this, _clients, event, _roomGameTypes); createCardInfoDock(); createPlayerListDock(); diff --git a/cockatrice/src/game/board/abstract_counter.cpp b/cockatrice/src/game/board/abstract_counter.cpp index 2da571df5..d13203f8d 100644 --- a/cockatrice/src/game/board/abstract_counter.cpp +++ b/cockatrice/src/game/board/abstract_counter.cpp @@ -172,7 +172,7 @@ void AbstractCounter::incrementCounter() void AbstractCounter::setCounter() { dialogSemaphore = true; - AbstractCounterDialog dialog(name, QString::number(value) /*, game */); + AbstractCounterDialog dialog(name, QString::number(value), player->getGame()->getTab()); const int ok = dialog.exec(); if (deleteAfterDialog) { diff --git a/cockatrice/src/game/game.cpp b/cockatrice/src/game/game.cpp index ad919940b..6c4ac2e46 100644 --- a/cockatrice/src/game/game.cpp +++ b/cockatrice/src/game/game.cpp @@ -2,7 +2,11 @@ #include "pb/event_game_joined.pb.h" -Game::Game(QList &_clients, const Event_GameJoined &event, const QMap &_roomGameTypes) +Game::Game(TabGame *_tab, + QList &_clients, + const Event_GameJoined &event, + const QMap &_roomGameTypes) + : tab(_tab) { gameMetaInfo = new GameMetaInfo(this); gameMetaInfo->setFromProto(event.game_info()); diff --git a/cockatrice/src/game/game.h b/cockatrice/src/game/game.h index 60d8141d3..82a098e7a 100644 --- a/cockatrice/src/game/game.h +++ b/cockatrice/src/game/game.h @@ -11,19 +11,29 @@ class CardItem; class GameMetaInfo; +class TabGame; class Game : public QObject { Q_OBJECT public: - Game(QList &_clients, const Event_GameJoined &event, const QMap &_roomGameTypes); + Game(TabGame *tab, + QList &_clients, + const Event_GameJoined &event, + const QMap &_roomGameTypes); + TabGame *tab; GameMetaInfo *gameMetaInfo; GameState *gameState; GameEventHandler *gameEventHandler; PlayerManager *playerManager; CardItem *activeCard; + TabGame *getTab() const + { + return tab; + } + GameMetaInfo *getGameMetaInfo() { return gameMetaInfo; diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index 37d2b4b5e..553cf8c5f 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -147,7 +147,7 @@ void PlayerActions::actViewTopCards() int deckSize = player->getDeckZone()->getCards().size(); bool ok; // TODO: Signal this - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("View top cards of library"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("View top cards of library"), tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1, deckSize, 1, &ok); if (ok) { @@ -160,7 +160,7 @@ void PlayerActions::actViewBottomCards() { int deckSize = player->getDeckZone()->getCards().size(); bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("View bottom cards of library"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("View bottom cards of library"), tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberBottomCards, 1, deckSize, 1, &ok); if (ok) { @@ -233,7 +233,7 @@ void PlayerActions::actShuffleTop() } bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Shuffle top cards of library"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Shuffle top cards of library"), tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1, maxCards, 1, &ok); if (!ok) { @@ -262,7 +262,7 @@ void PlayerActions::actShuffleBottom() } bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Shuffle bottom cards of library"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Shuffle bottom cards of library"), tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1, maxCards, 1, &ok); if (!ok) { @@ -296,7 +296,7 @@ void PlayerActions::actMulligan() int handSize = player->getHandZone()->getCards().size(); int deckSize = player->getDeckZone()->getCards().size() + handSize; // hand is shuffled back into the deck bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Draw hand"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Draw hand"), tr("Number of cards: (max. %1)").arg(deckSize) + '\n' + tr("0 and lower are in comparison to current hand size"), startSize, -handSize, deckSize, 1, &ok); @@ -322,7 +322,7 @@ void PlayerActions::actDrawCards() { int deckSize = player->getDeckZone()->getCards().size(); bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Draw cards"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Draw cards"), tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1, deckSize, 1, &ok); if (ok) { @@ -394,7 +394,7 @@ void PlayerActions::actMoveTopCardsToGrave() } bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Move top cards to grave"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move top cards to grave"), tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1, maxCards, 1, &ok); if (!ok) { @@ -426,7 +426,7 @@ void PlayerActions::actMoveTopCardsToExile() } bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Move top cards to exile"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move top cards to exile"), tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1, maxCards, 1, &ok); if (!ok) { @@ -454,7 +454,7 @@ void PlayerActions::actMoveTopCardsUntil() { stopMoveTopCardsUntil(); - DlgMoveTopCardsUntil dlg(/* player->getGame() */ nullptr, movingCardsUntilExprs, movingCardsUntilNumberOfHits, + DlgMoveTopCardsUntil dlg(player->getGame()->getTab(), movingCardsUntilExprs, movingCardsUntilNumberOfHits, movingCardsUntilAutoPlay); if (!dlg.exec()) { return; @@ -598,7 +598,7 @@ void PlayerActions::actMoveBottomCardsToGrave() } bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Move bottom cards to grave"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move bottom cards to grave"), tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1, maxCards, 1, &ok); if (!ok) { @@ -630,7 +630,7 @@ void PlayerActions::actMoveBottomCardsToExile() } bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Move bottom cards to exile"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move bottom cards to exile"), tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1, maxCards, 1, &ok); if (!ok) { @@ -747,7 +747,7 @@ void PlayerActions::actDrawBottomCards() } bool ok; - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Draw bottom cards"), + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Draw bottom cards"), tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1, maxCards, 1, &ok); if (!ok) { @@ -821,7 +821,7 @@ void PlayerActions::actUntapAll() void PlayerActions::actRollDie() { - DlgRollDice dlg(/* player->getGame() */ nullptr); + DlgRollDice dlg(player->getGame()->getTab()); if (!dlg.exec()) { return; } @@ -834,7 +834,7 @@ void PlayerActions::actRollDie() void PlayerActions::actCreateToken() { - DlgCreateToken dlg(player->getPlayerMenu()->getPredefinedTokens(), /* player->getGame() */ nullptr); + DlgCreateToken dlg(player->getPlayerMenu()->getPredefinedTokens(), player->getGame()->getTab()); if (!dlg.exec()) { return; } @@ -1022,7 +1022,7 @@ bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, const if (cardRelation->getIsVariable()) { bool ok; player->setDialogSemaphore(true); - int count = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Create tokens"), tr("Number:"), + int count = QInputDialog::getInt(player->getGame()->getTab(), tr("Create tokens"), tr("Number:"), cardRelation->getDefaultCount(), 1, MAX_TOKENS_PER_DIALOG, 1, &ok); player->setDialogSemaphore(false); if (!ok) { @@ -1188,7 +1188,7 @@ void PlayerActions::actMoveCardXCardsFromTop() int deckSize = player->getDeckZone()->getCards().size() + 1; // add the card to move to the deck bool ok; int number = - QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Place card X cards from top of library"), + QInputDialog::getInt(player->getGame()->getTab(), tr("Place card X cards from top of library"), tr("Which position should this card be placed:") + "\n" + tr("(max. %1)").arg(deckSize), defaultNumberTopCardsToPlaceBelow, 1, deckSize, 1, &ok); number -= 1; // indexes start at 0 @@ -1348,7 +1348,7 @@ void PlayerActions::actSetPT() } bool ok; player->setDialogSemaphore(true); - QString pt = getTextWithMax(/* player->getGame() */ nullptr, tr("Change power/toughness"), tr("Change stats to:"), + QString pt = getTextWithMax(player->getGame()->getTab(), tr("Change power/toughness"), tr("Change stats to:"), QLineEdit::Normal, oldPT, &ok); player->setDialogSemaphore(false); if (player->clearCardsToDelete() || !ok) { @@ -1466,7 +1466,7 @@ void PlayerActions::actSetAnnotation() } player->setDialogSemaphore(true); - AnnotationDialog *dialog = new AnnotationDialog(/* player->getGame() */); + AnnotationDialog *dialog = new AnnotationDialog(player->getGame()->getTab()); dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput); dialog->setWindowTitle(tr("Set annotation")); dialog->setLabelText(tr("Please enter the new annotation:")); @@ -1562,8 +1562,8 @@ void PlayerActions::actCardCounterTrigger() auto *card = static_cast(player->getGameScene()->selectedItems().first()); oldValue = card->getCounters().value(counterId, 0); } - int number = QInputDialog::getInt(/* player->getGame() */ nullptr, tr("Set counters"), tr("Number:"), - oldValue, 0, MAX_COUNTERS_ON_CARD, 1, &ok); + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Set counters"), tr("Number:"), oldValue, + 0, MAX_COUNTERS_ON_CARD, 1, &ok); player->setDialogSemaphore(false); if (player->clearCardsToDelete() || !ok) { return; diff --git a/cockatrice/src/game/player/player_menu.cpp b/cockatrice/src/game/player/player_menu.cpp index 03a55ab90..2b2cb325c 100644 --- a/cockatrice/src/game/player/player_menu.cpp +++ b/cockatrice/src/game/player/player_menu.cpp @@ -1202,8 +1202,7 @@ void PlayerMenu::setShortcutsActive() if (!player->getGame()->getGameState()->getIsLocalGame()) { // unattach action is only active in card menu if the active card is attached. // make unattach shortcut always active so that it consistently works when multiple cards are selected. - // TODO: Signal this - // player->getGame()->addAction(aUnattach); + player->getGame()->getTab()->addAction(aUnattach); } }