Fine, the game can remember the tab.

Took 10 minutes

Took 21 seconds

Took 9 seconds
This commit is contained in:
Lukas Brübach 2025-09-10 02:58:21 +02:00
parent cba5ab2847
commit 270bdefd87
6 changed files with 39 additions and 26 deletions

View file

@ -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();

View file

@ -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) {

View file

@ -2,7 +2,11 @@
#include "pb/event_game_joined.pb.h"
Game::Game(QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes)
Game::Game(TabGame *_tab,
QList<AbstractClient *> &_clients,
const Event_GameJoined &event,
const QMap<int, QString> &_roomGameTypes)
: tab(_tab)
{
gameMetaInfo = new GameMetaInfo(this);
gameMetaInfo->setFromProto(event.game_info());

View file

@ -11,19 +11,29 @@
class CardItem;
class GameMetaInfo;
class TabGame;
class Game : public QObject
{
Q_OBJECT
public:
Game(QList<AbstractClient *> &_clients, const Event_GameJoined &event, const QMap<int, QString> &_roomGameTypes);
Game(TabGame *tab,
QList<AbstractClient *> &_clients,
const Event_GameJoined &event,
const QMap<int, QString> &_roomGameTypes);
TabGame *tab;
GameMetaInfo *gameMetaInfo;
GameState *gameState;
GameEventHandler *gameEventHandler;
PlayerManager *playerManager;
CardItem *activeCard;
TabGame *getTab() const
{
return tab;
}
GameMetaInfo *getGameMetaInfo()
{
return gameMetaInfo;

View file

@ -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<CardItem *>(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;

View file

@ -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);
}
}