diff --git a/cockatrice/CMakeLists.txt b/cockatrice/CMakeLists.txt index f0e363e18..028161ee0 100644 --- a/cockatrice/CMakeLists.txt +++ b/cockatrice/CMakeLists.txt @@ -100,7 +100,6 @@ set(cockatrice_SOURCES src/game/player/menu/utility_menu.cpp src/game/player/player_actions.cpp src/game/player/player_area.cpp - src/game/player/player_dialogs.cpp src/game/player/player_event_handler.cpp src/game/player/player_graphics_item.cpp src/game/player/player_info.cpp diff --git a/cockatrice/src/game/board/abstract_card_item.h b/cockatrice/src/game/board/abstract_card_item.h index 863954b73..ed545e1ab 100644 --- a/cockatrice/src/game/board/abstract_card_item.h +++ b/cockatrice/src/game/board/abstract_card_item.h @@ -44,11 +44,6 @@ signals: void deleteCardInfoPopup(QString cardName); void sigPixmapUpdated(); void cardShiftClicked(QString cardName); - void rightClicked(AbstractCardItem *card, QPoint screenPos); - void playSelected(AbstractCardItem *card); - void playSelectedFaceDown(AbstractCardItem *card); - void hideSelected(AbstractCardItem *card); - void selectionChanged(AbstractCardItem *card, bool selected); public: enum diff --git a/cockatrice/src/game/board/card_item.cpp b/cockatrice/src/game/board/card_item.cpp index 029822805..a08194540 100644 --- a/cockatrice/src/game/board/card_item.cpp +++ b/cockatrice/src/game/board/card_item.cpp @@ -40,7 +40,7 @@ void CardItem::prepareDelete() { if (owner != nullptr) { if (owner->getGame()->getActiveCard() == this) { - emit owner->requestCardMenuUpdate(nullptr); + owner->getPlayerMenu()->updateCardMenu(nullptr); owner->getGame()->setActiveCard(nullptr); } owner = nullptr; @@ -399,11 +399,8 @@ void CardItem::playCard(bool faceDown) emit tz->toggleTapped(); } else { if (SettingsCache::instance().getClickPlaysAllSelected()) { - if (faceDown) { - emit playSelectedFaceDown(this); - } else { - emit playSelected(this); - } + faceDown ? state->getZone()->getPlayer()->getPlayerActions()->actPlayFacedown() + : state->getZone()->getPlayer()->getPlayerActions()->actPlay(); } else { state->getZone()->getPlayer()->getPlayerActions()->playCard(this, faceDown); } @@ -463,7 +460,7 @@ void CardItem::handleClickedToPlay(bool shiftHeld) { if (isUnwritableRevealZone(state->getZone())) { if (SettingsCache::instance().getClickPlaysAllSelected()) { - emit hideSelected(this); + state->getZone()->getPlayer()->getPlayerActions()->actHide(); } else { state->getZone()->removeCard(this); } @@ -474,12 +471,17 @@ void CardItem::handleClickedToPlay(bool shiftHeld) void CardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::RightButton && owner != nullptr) { - emit rightClicked(this, event->screenPos()); - return; - } - if ((event->modifiers() != Qt::AltModifier) && (event->button() == Qt::LeftButton) && - (!SettingsCache::instance().getDoubleClickToPlay())) { + if (event->button() == Qt::RightButton) { + + if (owner != nullptr) { + owner->getGame()->setActiveCard(this); + if (QMenu *cardMenu = owner->getPlayerMenu()->updateCardMenu(this)) { + cardMenu->popup(event->screenPos()); + return; + } + } + } else if ((event->modifiers() != Qt::AltModifier) && (event->button() == Qt::LeftButton) && + (!SettingsCache::instance().getDoubleClickToPlay())) { handleClickedToPlay(event->modifiers().testFlag(Qt::ShiftModifier)); } @@ -529,14 +531,14 @@ bool CardItem::animationEvent() QVariant CardItem::itemChange(GraphicsItemChange change, const QVariant &value) { if ((change == ItemSelectedHasChanged) && owner != nullptr) { - bool selected = value.toBool(); - - if (selected) { + if (value == true) { owner->getGame()->setActiveCard(this); + owner->getPlayerMenu()->updateCardMenu(this); + } else if (owner->getGameScene()->selectedItems().isEmpty()) { + + owner->getGame()->setActiveCard(nullptr); + owner->getPlayerMenu()->updateCardMenu(nullptr); } - - emit selectionChanged(this, selected); } - return AbstractCardItem::itemChange(change, value); } diff --git a/cockatrice/src/game/game_scene.cpp b/cockatrice/src/game/game_scene.cpp index dc55ecfe9..867869a3f 100644 --- a/cockatrice/src/game/game_scene.cpp +++ b/cockatrice/src/game/game_scene.cpp @@ -4,10 +4,8 @@ #include "../game_graphics/zones/select_zone.h" #include "../game_graphics/zones/view_zone.h" #include "../game_graphics/zones/view_zone_widget.h" -#include "abstract_game.h" #include "board/card_item.h" #include "phases_toolbar.h" -#include "player/player_actions.h" #include "player/player_graphics_item.h" #include "player/player_logic.h" @@ -74,80 +72,6 @@ QList GameScene::selectedCards() const return selectedCards; } -void GameScene::onCardSelectionChanged(AbstractCardItem *abstractCard, bool selected) -{ - CardItem *card = qobject_cast(abstractCard); - if (!card || !card->getOwner()) { - return; - } - - auto *owner = card->getOwner(); - - if (selected) { - owner->requestCardMenuUpdate(card); - return; - } - - if (selectedItems().isEmpty()) { - owner->getGame()->setActiveCard(nullptr); - owner->requestCardMenuUpdate(nullptr); - } -} - -void GameScene::onCardRightClicked(AbstractCardItem *abstractCard, QPoint screenPos) -{ - auto *card = qobject_cast(abstractCard); - if (!card) { - return; - } - if (!card->getOwner()) { - return; - } - auto *view = playerViews.value(card->getOwner()->getPlayerInfo()->getId()); - if (!view) { - return; - } - - card->getOwner()->getGame()->setActiveCard(card); - - if (auto *menu = view->getPlayerMenu()->updateCardMenu(card)) { - menu->popup(screenPos); - } -} - -void GameScene::playSelected(AbstractCardItem *card) -{ - if (!card) { - return; - } - if (!card->getOwner()) { - return; - } - card->getOwner()->getPlayerActions()->actPlay(selectedCards()); -} - -void GameScene::playSelectedFaceDown(AbstractCardItem *card) -{ - if (!card) { - return; - } - if (!card->getOwner()) { - return; - } - card->getOwner()->getPlayerActions()->actPlayFacedown(selectedCards()); -} - -void GameScene::hideSelected(AbstractCardItem *card) -{ - if (!card) { - return; - } - if (!card->getOwner()) { - return; - } - card->getOwner()->getPlayerActions()->actHide(selectedCards()); -} - /** * @brief Adds a player to the scene and stores their graphics item. * @param player Player to add. @@ -158,11 +82,9 @@ void GameScene::addPlayer(PlayerLogic *player) { qCInfo(GameScenePlayerAdditionRemovalLog) << "GameScene::addPlayer name=" << player->getPlayerInfo()->getName(); - auto *view = new PlayerGraphicsItem(player); - - playerViews.insert(player->getPlayerInfo()->getId(), view); - addItem(view); - connect(view, &PlayerGraphicsItem::sizeChanged, this, &GameScene::rearrange); + playerViews.insert(player->getPlayerInfo()->getId(), player->getGraphicsItem()); + addItem(player->getGraphicsItem()); + connect(player->getGraphicsItem(), &PlayerGraphicsItem::sizeChanged, this, &GameScene::rearrange); connect(player, &PlayerLogic::concededChanged, this, [this](int id, bool conceded) { if (conceded) { @@ -171,8 +93,6 @@ void GameScene::addPlayer(PlayerLogic *player) rearrange(); }); - connect(player, &PlayerLogic::requestZoneViewToggle, this, &GameScene::toggleZoneView); - connect(player, &PlayerLogic::requestRevealedZoneView, this, &GameScene::addRevealedZoneView); connect(player, &PlayerLogic::arrowDeleted, this, &GameScene::deleteArrow); connect(player, &PlayerLogic::arrowCreateRequested, this, &GameScene::addArrow); connect(player, &PlayerLogic::arrowDeleteRequested, this, &GameScene::requestArrowDeletion); @@ -203,7 +123,6 @@ void GameScene::removePlayer(PlayerLogic *player) } auto *view = playerViews.take(player->getPlayerInfo()->getId()); removeItem(view); - view->deleteLater(); rearrange(); } @@ -285,7 +204,7 @@ QList GameScene::collectActivePlayers(int &firstPlayerIndex) cons bool firstPlayerFound = false; for (auto *pgItem : playerViews.values()) { - PlayerLogic *p = pgItem->getLogic(); + PlayerLogic *p = pgItem->getPlayer(); if (p && !p->getConceded()) { activePlayers.append(p); if (!firstPlayerFound && p->getPlayerInfo()->getLocal()) { @@ -356,12 +275,12 @@ QSizeF GameScene::computeSceneSizeAndPlayerLayout(const QList &pl for (int j = 0; j < rowsInColumn; ++j) { PlayerLogic *player = playersIter.next(); if (col == 0) { - playersByColumn[col].prepend(playerViews.value(player->getPlayerInfo()->getId())); + playersByColumn[col].prepend(player->getGraphicsItem()); } else { - playersByColumn[col].append(playerViews.value(player->getPlayerInfo()->getId())); + playersByColumn[col].append(player->getGraphicsItem()); } - auto *pgItem = playerViews.value(player->getPlayerInfo()->getId()); + auto *pgItem = player->getGraphicsItem(); thisColumnHeight += pgItem->boundingRect().height() + playerAreaSpacing; columnWidth[col] = std::max(columnWidth[col], (int)pgItem->boundingRect().width()); } @@ -456,8 +375,7 @@ void GameScene::addArrow(QSharedPointer data) return; } - PlayerLogic *startLogic = startView->getLogic(); - auto *startZone = startLogic->getZones().value(data->startZone); + auto *startZone = startView->getPlayer()->getZones().value(data->startZone); if (!startZone) { return; } @@ -471,8 +389,7 @@ void GameScene::addArrow(QSharedPointer data) if (data->isPlayerTargeted()) { targetItem = targetView->getPlayerTarget(); } else { - auto *zone = targetView->getLogic()->getZones().value(data->targetZone); - if (zone) { + if (auto *zone = targetView->getPlayer()->getZones().value(data->targetZone)) { targetItem = zone->getCard(data->targetCardId); } } diff --git a/cockatrice/src/game/game_scene.h b/cockatrice/src/game/game_scene.h index 0587566d0..567089fc0 100644 --- a/cockatrice/src/game/game_scene.h +++ b/cockatrice/src/game/game_scene.h @@ -97,16 +97,6 @@ public: */ void removePlayer(PlayerLogic *player); - QMap getPlayers() const - { - return playerViews; - } - - PlayerGraphicsItem *viewForPlayer(int playerId) - { - return playerViews.value(playerId); - } - /** * @brief Adjusts the global rotation offset for player layout. * @param rotationAdjustment Number of positions to rotate. @@ -192,11 +182,6 @@ public: void stopRubberBand(); public slots: - void onCardSelectionChanged(AbstractCardItem *card, bool selected); - void onCardRightClicked(AbstractCardItem *card, QPoint screenPos); - void playSelected(AbstractCardItem *card); - void playSelectedFaceDown(AbstractCardItem *card); - void hideSelected(AbstractCardItem *card); /** @brief Toggles a zone view for a player. */ void toggleZoneView(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed = false); diff --git a/cockatrice/src/game/player/menu/card_menu.cpp b/cockatrice/src/game/player/menu/card_menu.cpp index c1c33e37d..3b866d4e0 100644 --- a/cockatrice/src/game/player/menu/card_menu.cpp +++ b/cockatrice/src/game/player/menu/card_menu.cpp @@ -6,7 +6,6 @@ #include "../../zones/view_zone_logic.h" #include "../card_menu_action_type.h" #include "../player_actions.h" -#include "../player_graphics_item.h" #include "../player_logic.h" #include "move_menu.h" #include "pt_menu.h" @@ -32,92 +31,93 @@ static QIcon createCircleIcon(const QColor &color) return QIcon(pixmap); } -template -static QAction *makeAction(QObject *parent, Slot &&slot, bool checkable = false, bool checked = false) -{ - auto *a = new QAction(parent); - a->setCheckable(checkable); - if (checkable) { - a->setChecked(checked); - } - QObject::connect(a, &QAction::triggered, parent, std::forward(slot)); - return a; -} - -CardMenu::CardMenu(PlayerGraphicsItem *_player, const CardItem *_card, bool _shortcutsActive) +CardMenu::CardMenu(PlayerLogic *_player, const CardItem *_card, bool _shortcutsActive) : player(_player), card(_card), shortcutsActive(_shortcutsActive) { - const QList &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values(); + auto playerActions = player->getPlayerActions(); + + const QList &players = player->getGame()->getPlayerManager()->getPlayers().values(); for (auto playerToAdd : players) { - if (playerToAdd == player->getLogic()) { + if (playerToAdd == player) { continue; } playersInfo.append(qMakePair(playerToAdd->getPlayerInfo()->getName(), playerToAdd->getPlayerInfo()->getId())); } - connect(player->getLogic()->getGame()->getPlayerManager(), &PlayerManager::playerRemoved, this, - &CardMenu::removePlayer); + connect(player->getGame()->getPlayerManager(), &PlayerManager::playerRemoved, this, &CardMenu::removePlayer); - auto *actions = player->getLogic()->getPlayerActions(); - auto *gameScene = player->getGameScene(); - - // Single selection resolver used by all lambdas — called at trigger time - auto sel = [gameScene]() { return gameScene->selectedCards(); }; - - // Unified dispatcher for card menu actions - auto invoke = [actions, sel](CardMenuActionType type) { - return [actions, sel, type]() { actions->cardMenuAction(sel(), type); }; - }; - - // Actions using invoke (type dispatch, need selection) - aTap = makeAction(this, invoke(cmTap)); - aDoesntUntap = makeAction(this, invoke(cmDoesntUntap), /*checkable=*/true, card && card->getDoesntUntap()); - aFlip = makeAction(this, invoke(cmFlip)); - aPeek = makeAction(this, invoke(cmPeek)); - aClone = makeAction(this, invoke(cmClone)); - - // Actions using selection directly - aUnattach = makeAction(this, [actions, sel]() { actions->actUnattach(sel()); }); - aSetAnnotation = makeAction(this, [actions, sel]() { actions->actRequestSetAnnotationDialog(sel()); }); - aPlay = makeAction(this, [actions, sel]() { actions->actPlay(sel()); }); - aPlayFacedown = makeAction(this, [actions, sel]() { actions->actPlayFacedown(sel()); }); - aHide = makeAction(this, [actions, sel]() { actions->actHide(sel()); }); - aReduceLifeByPower = makeAction(this, [actions, sel]() { actions->actReduceLifeByPower(sel()); }); - - // Actions that use activeCard, not selection — direct connection + aTap = new QAction(this); + aTap->setData(cmTap); + connect(aTap, &QAction::triggered, playerActions, &PlayerActions::cardMenuAction); + aDoesntUntap = new QAction(this); + aDoesntUntap->setData(cmDoesntUntap); + aDoesntUntap->setCheckable(true); + aDoesntUntap->setChecked(card != nullptr && card->getDoesntUntap()); + connect(aDoesntUntap, &QAction::triggered, playerActions, &PlayerActions::cardMenuAction); aAttach = new QAction(this); + connect(aAttach, &QAction::triggered, playerActions, &PlayerActions::actAttach); + aUnattach = new QAction(this); + connect(aUnattach, &QAction::triggered, playerActions, &PlayerActions::actUnattach); aDrawArrow = new QAction(this); + connect(aDrawArrow, &QAction::triggered, playerActions, &PlayerActions::actDrawArrow); + aSetAnnotation = new QAction(this); + connect(aSetAnnotation, &QAction::triggered, playerActions, &PlayerActions::actSetAnnotation); + aFlip = new QAction(this); + aFlip->setData(cmFlip); + connect(aFlip, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); + aPeek = new QAction(this); + aPeek->setData(cmPeek); + connect(aPeek, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); + aClone = new QAction(this); + aClone->setData(cmClone); + connect(aClone, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); aSelectAll = new QAction(this); + connect(aSelectAll, &QAction::triggered, playerActions, &PlayerActions::actSelectAll); aSelectRow = new QAction(this); + connect(aSelectRow, &QAction::triggered, playerActions, &PlayerActions::actSelectRow); aSelectColumn = new QAction(this); + connect(aSelectColumn, &QAction::triggered, playerActions, &PlayerActions::actSelectColumn); - connect(aAttach, &QAction::triggered, actions, &PlayerActions::actAttach); - connect(aDrawArrow, &QAction::triggered, actions, &PlayerActions::actDrawArrow); - connect(aSelectAll, &QAction::triggered, actions, &PlayerActions::actSelectAll); - connect(aSelectRow, &QAction::triggered, actions, &PlayerActions::actSelectRow); - connect(aSelectColumn, &QAction::triggered, actions, &PlayerActions::actSelectColumn); + aReduceLifeByPower = new QAction(this); + connect(aReduceLifeByPower, &QAction::triggered, playerActions, &PlayerActions::actReduceLifeByPower); + + aPlay = new QAction(this); + connect(aPlay, &QAction::triggered, playerActions, &PlayerActions::actPlay); + aHide = new QAction(this); + connect(aHide, &QAction::triggered, playerActions, &PlayerActions::actHide); + aPlayFacedown = new QAction(this); + connect(aPlayFacedown, &QAction::triggered, playerActions, &PlayerActions::actPlayFacedown); aRevealToAll = new QAction(this); mCardCounters = new QMenu; - // Card counters for (int i = 0; i < 6; ++i) { QColor color = SettingsCache::instance().cardCounters().color(i); QIcon circleIcon = createCircleIcon(color); - auto *addAction = makeAction(this, [actions, sel, i]() { actions->actAddCardCounter(sel(), i); }); - addAction->setIcon(circleIcon); - aAddCounter.append(addAction); + auto *tempAddCounter = new QAction(this); + tempAddCounter->setIconVisibleInMenu(true); + tempAddCounter->setIcon(circleIcon); - auto *removeAction = makeAction(this, [actions, sel, i]() { actions->actRemoveCardCounter(sel(), i); }); - removeAction->setIcon(circleIcon); - aRemoveCounter.append(removeAction); + auto *tempRemoveCounter = new QAction(this); + tempRemoveCounter->setIconVisibleInMenu(true); + tempRemoveCounter->setIcon(circleIcon); - auto *setAction = makeAction(this, [actions, sel, i]() { actions->actRequestSetCardCounterDialog(sel(), i); }); - setAction->setIcon(circleIcon); - aSetCounter.append(setAction); + auto *tempSetCounter = new QAction(this); + tempSetCounter->setIconVisibleInMenu(true); + tempSetCounter->setIcon(circleIcon); + + aAddCounter.append(tempAddCounter); + aRemoveCounter.append(tempRemoveCounter); + aSetCounter.append(tempSetCounter); + connect(tempAddCounter, &QAction::triggered, playerActions, + [playerActions, i] { playerActions->actAddCardCounter(i); }); + connect(tempRemoveCounter, &QAction::triggered, playerActions, + [playerActions, i] { playerActions->actRemoveCardCounter(i); }); + connect(tempSetCounter, &QAction::triggered, playerActions, + [playerActions, i] { playerActions->actSetCardCounter(i); }); } setShortcutsActive(); @@ -129,7 +129,7 @@ CardMenu::CardMenu(PlayerGraphicsItem *_player, const CardItem *_card, bool _sho } bool revealedCard = false; - bool writeableCard = player->getLogic()->getPlayerInfo()->getLocalOrJudge(); + bool writeableCard = player->getPlayerInfo()->getLocalOrJudge(); if (auto *view = qobject_cast(card->getZone())) { if (view->getRevealZone()) { if (view->getWriteableRevealZone()) { @@ -313,9 +313,7 @@ void CardMenu::createHandOrCustomZoneMenu(bool canModifyCard) initContextualPlayersMenu(revealMenu, aRevealToAll); - connect(revealMenu, &QMenu::triggered, this, [this](QAction *action) { - player->getLogic()->getPlayerActions()->actReveal(player->getGameScene()->selectedCards(), action); - }); + connect(revealMenu, &QMenu::triggered, player->getPlayerActions(), &PlayerActions::actReveal); addSeparator(); addAction(aClone); @@ -400,7 +398,8 @@ void CardMenu::addRelatedCardView() QAction *viewCard = viewRelatedCards->addAction(relatedCardName); Q_UNUSED(viewCard); - connect(viewCard, &QAction::triggered, this, [this, cardRef] { emit cardInfoRequested(cardRef); }); + connect(viewCard, &QAction::triggered, player->getGame(), + [this, cardRef] { player->getGame()->getTab()->viewCardInfo(cardRef); }); } } @@ -462,8 +461,7 @@ void CardMenu::addRelatedCardActions() auto *createRelated = new QAction(text, this); createRelated->setData(QVariant(index++)); - connect(createRelated, &QAction::triggered, player->getLogic()->getPlayerActions(), - &PlayerActions::actCreateRelatedCard); + connect(createRelated, &QAction::triggered, player->getPlayerActions(), &PlayerActions::actCreateRelatedCard); addAction(createRelated); } @@ -472,7 +470,7 @@ void CardMenu::addRelatedCardActions() createRelatedCards->setShortcuts( SettingsCache::instance().shortcuts().getShortcut("Player/aCreateRelatedTokens")); } - connect(createRelatedCards, &QAction::triggered, player->getLogic()->getPlayerActions(), + connect(createRelatedCards, &QAction::triggered, player->getPlayerActions(), &PlayerActions::actCreateAllRelatedCards); addAction(createRelatedCards); } diff --git a/cockatrice/src/game/player/menu/card_menu.h b/cockatrice/src/game/player/menu/card_menu.h index d67ef3876..ad3962caf 100644 --- a/cockatrice/src/game/player/menu/card_menu.h +++ b/cockatrice/src/game/player/menu/card_menu.h @@ -8,20 +8,15 @@ #define COCKATRICE_CARD_MENU_H #include -#include class CardItem; -class PlayerGraphicsItem; class PlayerLogic; class CardMenu : public QMenu { Q_OBJECT -signals: - void cardInfoRequested(const CardRef &cardRef); - public: - explicit CardMenu(PlayerGraphicsItem *player, const CardItem *card, bool shortcutsActive); + explicit CardMenu(PlayerLogic *player, const CardItem *card, bool shortcutsActive); void removePlayer(PlayerLogic *playerToRemove); void createTableMenu(bool canModifyCard); void createStackMenu(bool canModifyCard); @@ -46,7 +41,7 @@ public: QList aAddCounter, aSetCounter, aRemoveCounter; private: - PlayerGraphicsItem *player; + PlayerLogic *player; const CardItem *card; QList> playersInfo; bool shortcutsActive; diff --git a/cockatrice/src/game/player/menu/custom_zone_menu.cpp b/cockatrice/src/game/player/menu/custom_zone_menu.cpp index 106e646d9..88b7f3710 100644 --- a/cockatrice/src/game/player/menu/custom_zone_menu.cpp +++ b/cockatrice/src/game/player/menu/custom_zone_menu.cpp @@ -2,12 +2,12 @@ #include "../player_logic.h" -CustomZoneMenu::CustomZoneMenu(PlayerGraphicsItem *_player) : player(_player) +CustomZoneMenu::CustomZoneMenu(PlayerLogic *_player) : player(_player) { menuAction()->setVisible(false); - connect(player->getLogic(), &PlayerLogic::clearCustomZonesMenu, this, &CustomZoneMenu::clearCustomZonesMenu); - connect(player->getLogic(), &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this, + connect(player, &PlayerLogic::clearCustomZonesMenu, this, &CustomZoneMenu::clearCustomZonesMenu); + connect(player, &PlayerLogic::addViewCustomZoneActionToCustomZoneMenu, this, &CustomZoneMenu::addViewCustomZoneActionToCustomZoneMenu); retranslateUi(); @@ -17,7 +17,7 @@ void CustomZoneMenu::retranslateUi() { setTitle(tr("C&ustom Zones")); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { for (auto aViewZone : actions()) { aViewZone->setText(tr("View custom zone '%1'").arg(aViewZone->data().toString())); @@ -37,5 +37,5 @@ void CustomZoneMenu::addViewCustomZoneActionToCustomZoneMenu(QString zoneName) QAction *aViewZone = addAction(tr("View custom zone '%1'").arg(zoneName)); aViewZone->setData(zoneName); connect(aViewZone, &QAction::triggered, this, - [zoneName, this]() { player->getGameScene()->toggleZoneView(player->getLogic(), zoneName, -1); }); + [zoneName, this]() { player->getGameScene()->toggleZoneView(player, zoneName, -1); }); } \ No newline at end of file diff --git a/cockatrice/src/game/player/menu/custom_zone_menu.h b/cockatrice/src/game/player/menu/custom_zone_menu.h index 46dd58db6..e10f6a4f0 100644 --- a/cockatrice/src/game/player/menu/custom_zone_menu.h +++ b/cockatrice/src/game/player/menu/custom_zone_menu.h @@ -11,12 +11,12 @@ #include -class PlayerGraphicsItem; +class PlayerLogic; class CustomZoneMenu : public QMenu, public AbstractPlayerComponent { Q_OBJECT public: - explicit CustomZoneMenu(PlayerGraphicsItem *player); + explicit CustomZoneMenu(PlayerLogic *player); void retranslateUi() override; void setShortcutsActive() override { @@ -26,7 +26,7 @@ public: } private: - PlayerGraphicsItem *player; + PlayerLogic *player; private slots: void clearCustomZonesMenu(); void addViewCustomZoneActionToCustomZoneMenu(QString zoneName); diff --git a/cockatrice/src/game/player/menu/grave_menu.cpp b/cockatrice/src/game/player/menu/grave_menu.cpp index 45762e900..16a5858ca 100644 --- a/cockatrice/src/game/player/menu/grave_menu.cpp +++ b/cockatrice/src/game/player/menu/grave_menu.cpp @@ -8,14 +8,14 @@ #include #include -GraveyardMenu::GraveyardMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(parent), player(_player) +GraveyardMenu::GraveyardMenu(PlayerLogic *_player, QWidget *parent) : TearOffMenu(parent), player(_player) { createMoveActions(); createViewActions(); addAction(aViewGraveyard); - if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) { + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { mRevealRandomGraveyardCard = addMenu(QString()); connect(mRevealRandomGraveyardCard, &QMenu::aboutToShow, this, &GraveyardMenu::populateRevealRandomMenuWithActivePlayers); @@ -36,9 +36,9 @@ GraveyardMenu::GraveyardMenu(PlayerGraphicsItem *_player, QWidget *parent) : Tea void GraveyardMenu::createMoveActions() { - auto grave = player->getLogic()->getGraveZone(); + auto grave = player->getGraveZone(); - if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) { + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { aMoveGraveToTopLibrary = new QAction(this); aMoveGraveToTopLibrary->setData(QList() << ZoneNames::DECK << 0); @@ -60,7 +60,7 @@ void GraveyardMenu::createMoveActions() void GraveyardMenu::createViewActions() { - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); + PlayerActions *playerActions = player->getPlayerActions(); aViewGraveyard = new QAction(this); connect(aViewGraveyard, &QAction::triggered, playerActions, &PlayerActions::actViewGraveyard); @@ -76,9 +76,9 @@ void GraveyardMenu::populateRevealRandomMenuWithActivePlayers() mRevealRandomGraveyardCard->addSeparator(); - const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values(); + const auto &players = player->getGame()->getPlayerManager()->getPlayers().values(); for (auto *other : players) { - if (other == player->getLogic()) { + if (other == player) { continue; } QAction *a = mRevealRandomGraveyardCard->addAction(other->getPlayerInfo()->getName()); @@ -90,7 +90,7 @@ void GraveyardMenu::populateRevealRandomMenuWithActivePlayers() void GraveyardMenu::onRevealRandomTriggered() { if (auto *a = qobject_cast(sender())) { - player->getLogic()->getPlayerActions()->actRevealRandomGraveyardCard(a->data().toInt()); + player->getPlayerActions()->actRevealRandomGraveyardCard(a->data().toInt()); } } @@ -100,7 +100,7 @@ void GraveyardMenu::retranslateUi() aViewGraveyard->setText(tr("&View graveyard")); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { moveGraveMenu->setTitle(tr("&Move graveyard to...")); aMoveGraveToTopLibrary->setText(tr("&Top of library")); aMoveGraveToBottomLibrary->setText(tr("&Bottom of library")); diff --git a/cockatrice/src/game/player/menu/grave_menu.h b/cockatrice/src/game/player/menu/grave_menu.h index 116261e9b..d3d98802d 100644 --- a/cockatrice/src/game/player/menu/grave_menu.h +++ b/cockatrice/src/game/player/menu/grave_menu.h @@ -13,7 +13,7 @@ #include #include -class PlayerGraphicsItem; +class PlayerLogic; class GraveyardMenu : public TearOffMenu, public AbstractPlayerComponent { Q_OBJECT @@ -21,7 +21,7 @@ signals: void newPlayerActionCreated(QAction *action); public: - explicit GraveyardMenu(PlayerGraphicsItem *player, QWidget *parent = nullptr); + explicit GraveyardMenu(PlayerLogic *player, QWidget *parent = nullptr); void createMoveActions(); void createViewActions(); void populateRevealRandomMenuWithActivePlayers(); @@ -40,7 +40,7 @@ public: QAction *aMoveGraveToRfg = nullptr; private: - PlayerGraphicsItem *player; + PlayerLogic *player; }; #endif // COCKATRICE_GRAVE_MENU_H diff --git a/cockatrice/src/game/player/menu/hand_menu.cpp b/cockatrice/src/game/player/menu/hand_menu.cpp index 64a8c5754..6ff177655 100644 --- a/cockatrice/src/game/player/menu/hand_menu.cpp +++ b/cockatrice/src/game/player/menu/hand_menu.cpp @@ -5,20 +5,16 @@ #include "../../../game_graphics/zones/hand_zone.h" #include "../../abstract_game.h" #include "../player_actions.h" -#include "../player_graphics_item.h" #include "../player_logic.h" #include #include #include -HandMenu::HandMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(parent), player(_player) +HandMenu::HandMenu(PlayerLogic *_player, PlayerActions *actions, QWidget *parent) : TearOffMenu(parent), player(_player) { - auto *actions = player->getLogic()->getPlayerActions(); - - if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) { + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { aViewHand = new QAction(this); - connect(aViewHand, &QAction::triggered, actions, &PlayerActions::actViewHand); addAction(aViewHand); @@ -62,7 +58,7 @@ HandMenu::HandMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(p addSeparator(); aMulligan = new QAction(this); - connect(aMulligan, &QAction::triggered, actions, &PlayerActions::actRequestMulliganDialog); + connect(aMulligan, &QAction::triggered, actions, &PlayerActions::actMulligan); addAction(aMulligan); // Mulligan same size @@ -79,7 +75,7 @@ HandMenu::HandMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(p mMoveHandMenu = addTearOffMenu(QString()); - if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) { + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { aMoveHandToTopLibrary = new QAction(this); aMoveHandToTopLibrary->setData(QList() << ZoneNames::DECK << 0); aMoveHandToBottomLibrary = new QAction(this); @@ -89,7 +85,7 @@ HandMenu::HandMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(p aMoveHandToRfg = new QAction(this); aMoveHandToRfg->setData(QList() << ZoneNames::EXILE << 0); - auto hand = player->getLogic()->getHandZone(); + auto hand = player->getHandZone(); connect(aMoveHandToTopLibrary, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); connect(aMoveHandToBottomLibrary, &QAction::triggered, hand, &HandZoneLogic::moveAllToZone); @@ -111,7 +107,7 @@ void HandMenu::retranslateUi() { setTitle(tr("&Hand")); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { aViewHand->setText(tr("&View hand")); mSortHand->setTitle(tr("Sort hand by...")); @@ -170,9 +166,9 @@ void HandMenu::populateRevealHandMenuWithActivePlayers() mRevealHand->addSeparator(); - const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values(); + const auto &players = player->getGame()->getPlayerManager()->getPlayers().values(); for (auto *other : players) { - if (other == player->getLogic()) { + if (other == player) { continue; } QAction *a = mRevealHand->addAction(other->getPlayerInfo()->getName()); @@ -189,9 +185,9 @@ void HandMenu::populateRevealRandomHandCardMenuWithActivePlayers() mRevealRandomHandCard->addSeparator(); - const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values(); + const auto &players = player->getGame()->getPlayerManager()->getPlayers().values(); for (auto *other : players) { - if (other == player->getLogic()) { + if (other == player) { continue; } QAction *a = mRevealRandomHandCard->addAction(other->getPlayerInfo()->getName()); @@ -208,7 +204,7 @@ void HandMenu::onRevealHandTriggered() } const int targetId = action->data().toInt(); - player->getLogic()->getPlayerActions()->actRevealHand(targetId); + player->getPlayerActions()->actRevealHand(targetId); } void HandMenu::onRevealRandomHandCardTriggered() @@ -219,5 +215,5 @@ void HandMenu::onRevealRandomHandCardTriggered() } const int targetId = action->data().toInt(); - player->getLogic()->getPlayerActions()->actRevealRandomHandCard(targetId); + player->getPlayerActions()->actRevealRandomHandCard(targetId); } diff --git a/cockatrice/src/game/player/menu/hand_menu.h b/cockatrice/src/game/player/menu/hand_menu.h index d5204612b..1e2ddd95a 100644 --- a/cockatrice/src/game/player/menu/hand_menu.h +++ b/cockatrice/src/game/player/menu/hand_menu.h @@ -13,7 +13,7 @@ #include #include -class PlayerGraphicsItem; +class PlayerLogic; class PlayerActions; class HandMenu : public TearOffMenu, public AbstractPlayerComponent @@ -21,7 +21,7 @@ class HandMenu : public TearOffMenu, public AbstractPlayerComponent Q_OBJECT public: - HandMenu(PlayerGraphicsItem *player, QWidget *parent = nullptr); + HandMenu(PlayerLogic *player, PlayerActions *actions, QWidget *parent = nullptr); QMenu *revealHandMenu() const { @@ -43,7 +43,7 @@ private slots: void onRevealRandomHandCardTriggered(); private: - PlayerGraphicsItem *player; + PlayerLogic *player; QAction *aViewHand = nullptr; QAction *aMulligan = nullptr; diff --git a/cockatrice/src/game/player/menu/library_menu.cpp b/cockatrice/src/game/player/menu/library_menu.cpp index 00ab4592f..8449af05a 100644 --- a/cockatrice/src/game/player/menu/library_menu.cpp +++ b/cockatrice/src/game/player/menu/library_menu.cpp @@ -8,10 +8,9 @@ #include "../player_logic.h" #include -#include #include -LibraryMenu::LibraryMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(parent), player(_player) +LibraryMenu::LibraryMenu(PlayerLogic *_player, QWidget *parent) : TearOffMenu(parent), player(_player) { createDrawActions(); createShuffleActions(); @@ -76,8 +75,8 @@ LibraryMenu::LibraryMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOff bottomLibraryMenu->addSeparator(); bottomLibraryMenu->addAction(aShuffleBottomCards); - connect(player->getLogic(), &PlayerLogic::resetTopCardMenuActions, this, &LibraryMenu::resetTopCardMenuActions); - connect(player->getLogic(), &PlayerLogic::deckChanged, this, &LibraryMenu::enableOpenInDeckEditorAction); + connect(player, &PlayerLogic::resetTopCardMenuActions, this, &LibraryMenu::resetTopCardMenuActions); + connect(player, &PlayerLogic::deckChanged, this, &LibraryMenu::enableOpenInDeckEditorAction); retranslateUi(); } @@ -95,41 +94,41 @@ void LibraryMenu::resetTopCardMenuActions() void LibraryMenu::createDrawActions() { - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); + PlayerActions *playerActions = player->getPlayerActions(); - if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) { + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { aDrawCard = new QAction(this); connect(aDrawCard, &QAction::triggered, playerActions, &PlayerActions::actDrawCard); aDrawCards = new QAction(this); - connect(aDrawCards, &QAction::triggered, playerActions, &PlayerActions::actRequestDrawCardsDialog); + connect(aDrawCards, &QAction::triggered, playerActions, &PlayerActions::actDrawCards); aUndoDraw = new QAction(this); connect(aUndoDraw, &QAction::triggered, playerActions, &PlayerActions::actUndoDraw); aDrawBottomCard = new QAction(this); connect(aDrawBottomCard, &QAction::triggered, playerActions, &PlayerActions::actDrawBottomCard); aDrawBottomCards = new QAction(this); - connect(aDrawBottomCards, &QAction::triggered, playerActions, &PlayerActions::actRequestDrawBottomCardsDialog); + connect(aDrawBottomCards, &QAction::triggered, playerActions, &PlayerActions::actDrawBottomCards); } } void LibraryMenu::createShuffleActions() { - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); + PlayerActions *playerActions = player->getPlayerActions(); - if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) { + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { aShuffle = new QAction(this); connect(aShuffle, &QAction::triggered, playerActions, &PlayerActions::actShuffle); aShuffleTopCards = new QAction(this); - connect(aShuffleTopCards, &QAction::triggered, playerActions, &PlayerActions::actRequestShuffleTopDialog); + connect(aShuffleTopCards, &QAction::triggered, playerActions, &PlayerActions::actShuffleTop); aShuffleBottomCards = new QAction(this); - connect(aShuffleBottomCards, &QAction::triggered, playerActions, &PlayerActions::actRequestShuffleBottomDialog); + connect(aShuffleBottomCards, &QAction::triggered, playerActions, &PlayerActions::actShuffleBottom); } } void LibraryMenu::createMoveActions() { - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); + PlayerActions *playerActions = player->getPlayerActions(); - if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) { + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { aMoveTopToPlay = new QAction(this); connect(aMoveTopToPlay, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToPlay); aMoveTopToPlayFaceDown = new QAction(this); @@ -150,8 +149,7 @@ void LibraryMenu::createMoveActions() connect(aMoveTopCardsToExileFaceDown, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsToExileFaceDown); aMoveTopCardsUntil = new QAction(this); - connect(aMoveTopCardsUntil, &QAction::triggered, playerActions, - &PlayerActions::actRequestMoveTopCardsUntilDialog); + connect(aMoveTopCardsUntil, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardsUntil); aMoveTopCardToBottom = new QAction(this); connect(aMoveTopCardToBottom, &QAction::triggered, playerActions, &PlayerActions::actMoveTopCardToBottom); @@ -183,16 +181,16 @@ void LibraryMenu::createMoveActions() void LibraryMenu::createViewActions() { - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); + PlayerActions *playerActions = player->getPlayerActions(); - if (player->getLogic()->getPlayerInfo()->local || player->getLogic()->getPlayerInfo()->judge) { + if (player->getPlayerInfo()->local || player->getPlayerInfo()->judge) { aViewLibrary = new QAction(this); connect(aViewLibrary, &QAction::triggered, playerActions, &PlayerActions::actViewLibrary); aViewTopCards = new QAction(this); - connect(aViewTopCards, &QAction::triggered, playerActions, &PlayerActions::actRequestViewTopCardsDialog); + connect(aViewTopCards, &QAction::triggered, playerActions, &PlayerActions::actViewTopCards); aViewBottomCards = new QAction(this); - connect(aViewBottomCards, &QAction::triggered, playerActions, &PlayerActions::actRequestViewBottomCardsDialog); + connect(aViewBottomCards, &QAction::triggered, playerActions, &PlayerActions::actViewBottomCards); aAlwaysRevealTopCard = new QAction(this); aAlwaysRevealTopCard->setCheckable(true); connect(aAlwaysRevealTopCard, &QAction::triggered, playerActions, &PlayerActions::actAlwaysRevealTopCard); @@ -209,7 +207,7 @@ void LibraryMenu::retranslateUi() { setTitle(tr("&Library")); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { aViewLibrary->setText(tr("&View library")); aViewTopCards->setText(tr("View &top cards of library...")); aViewBottomCards->setText(tr("View bottom cards of library...")); @@ -265,9 +263,9 @@ void LibraryMenu::populateRevealLibraryMenuWithActivePlayers() mRevealLibrary->addSeparator(); - const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values(); + const auto &players = player->getGame()->getPlayerManager()->getPlayers().values(); for (auto *other : players) { - if (other == player->getLogic()) { + if (other == player) { continue; } QAction *a = mRevealLibrary->addAction(other->getPlayerInfo()->getName()); @@ -280,9 +278,9 @@ void LibraryMenu::populateLendLibraryMenuWithActivePlayers() { mLendLibrary->clear(); - const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values(); + const auto &players = player->getGame()->getPlayerManager()->getPlayers().values(); for (auto *other : players) { - if (other == player->getLogic()) { + if (other == player) { continue; } QAction *a = mLendLibrary->addAction(other->getPlayerInfo()->getName()); @@ -301,9 +299,9 @@ void LibraryMenu::populateRevealTopCardMenuWithActivePlayers() mRevealTopCard->addSeparator(); - const auto &players = player->getLogic()->getGame()->getPlayerManager()->getPlayers().values(); + const auto &players = player->getGame()->getPlayerManager()->getPlayers().values(); for (auto *other : players) { - if (other == player->getLogic()) { + if (other == player) { continue; } QAction *a = mRevealTopCard->addAction(other->getPlayerInfo()->getName()); @@ -315,33 +313,27 @@ void LibraryMenu::populateRevealTopCardMenuWithActivePlayers() void LibraryMenu::onRevealLibraryTriggered() { if (auto *a = qobject_cast(sender())) { - player->getLogic()->getPlayerActions()->actRevealLibrary(a->data().toInt()); + player->getPlayerActions()->actRevealLibrary(a->data().toInt()); } } void LibraryMenu::onLendLibraryTriggered() { if (auto *a = qobject_cast(sender())) { - player->getLogic()->getPlayerActions()->actLendLibrary(a->data().toInt()); + player->getPlayerActions()->actLendLibrary(a->data().toInt()); } } void LibraryMenu::onRevealTopCardTriggered() { - QWidget *parent = nullptr; - if (auto *view = player->scene() ? player->scene()->views().value(0) : nullptr) { - parent = view->window(); - } if (auto *a = qobject_cast(sender())) { - - int deckSize = player->getLogic()->getDeckZone()->getCards().size(); - bool ok = true; - int number = QInputDialog::getInt(parent, tr("Reveal top cards of library"), + 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->getLogic()->getPlayerActions()->actRevealTopCards(a->data().toInt(), number); + player->getPlayerActions()->actRevealTopCards(a->data().toInt(), number); defaultNumberTopCards = number; } } diff --git a/cockatrice/src/game/player/menu/library_menu.h b/cockatrice/src/game/player/menu/library_menu.h index bc0e6fb8e..a941c54b1 100644 --- a/cockatrice/src/game/player/menu/library_menu.h +++ b/cockatrice/src/game/player/menu/library_menu.h @@ -13,7 +13,6 @@ #include #include -class PlayerGraphicsItem; class PlayerLogic; class PlayerActions; @@ -25,7 +24,7 @@ public slots: void resetTopCardMenuActions(); public: - LibraryMenu(PlayerGraphicsItem *player, QWidget *parent = nullptr); + LibraryMenu(PlayerLogic *player, QWidget *parent = nullptr); void createDrawActions(); void createShuffleActions(); void createMoveActions(); @@ -112,7 +111,7 @@ public: int defaultNumberTopCards = 1; private: - PlayerGraphicsItem *player; + PlayerLogic *player; }; #endif // COCKATRICE_LIBRARY_MENU_H diff --git a/cockatrice/src/game/player/menu/move_menu.cpp b/cockatrice/src/game/player/menu/move_menu.cpp index 9997aecf3..3a5ad4da3 100644 --- a/cockatrice/src/game/player/menu/move_menu.cpp +++ b/cockatrice/src/game/player/menu/move_menu.cpp @@ -4,7 +4,7 @@ #include "../player_actions.h" #include "../player_logic.h" -MoveMenu::MoveMenu(PlayerGraphicsItem *player) : QMenu(tr("Move to")) +MoveMenu::MoveMenu(PlayerLogic *player) : QMenu(tr("Move to")) { aMoveToTopLibrary = new QAction(this); aMoveToTopLibrary->setData(cmMoveToTopLibrary); @@ -20,22 +20,14 @@ MoveMenu::MoveMenu(PlayerGraphicsItem *player) : QMenu(tr("Move to")) aMoveToExile = new QAction(this); aMoveToExile->setData(cmMoveToExile); - auto *actions = player->getLogic()->getPlayerActions(); - - auto invoke = [player](CardMenuActionType type) { - return [type, player]() { - player->getLogic()->getPlayerActions()->cardMenuAction(player->getGameScene()->selectedCards(), type); - }; - }; - - connect(aMoveToTopLibrary, &QAction::triggered, actions, invoke(cmMoveToTopLibrary)); - connect(aMoveToBottomLibrary, &QAction::triggered, actions, invoke(cmMoveToBottomLibrary)); - connect(aMoveToXfromTopOfLibrary, &QAction::triggered, actions, - &PlayerActions::actRequestMoveCardXCardsFromTopDialog); - connect(aMoveToTable, &QAction::triggered, actions, invoke(cmMoveToTable)); - connect(aMoveToHand, &QAction::triggered, actions, invoke(cmMoveToHand)); - connect(aMoveToGraveyard, &QAction::triggered, actions, invoke(cmMoveToGraveyard)); - connect(aMoveToExile, &QAction::triggered, actions, invoke(cmMoveToExile)); + connect(aMoveToTopLibrary, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); + connect(aMoveToBottomLibrary, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); + connect(aMoveToXfromTopOfLibrary, &QAction::triggered, player->getPlayerActions(), + &PlayerActions::actMoveCardXCardsFromTop); + connect(aMoveToTable, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); + connect(aMoveToHand, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); + connect(aMoveToGraveyard, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); + connect(aMoveToExile, &QAction::triggered, player->getPlayerActions(), &PlayerActions::cardMenuAction); addAction(aMoveToTopLibrary); addAction(aMoveToXfromTopOfLibrary); diff --git a/cockatrice/src/game/player/menu/move_menu.h b/cockatrice/src/game/player/menu/move_menu.h index 150bdbd3c..4e257b7fb 100644 --- a/cockatrice/src/game/player/menu/move_menu.h +++ b/cockatrice/src/game/player/menu/move_menu.h @@ -8,13 +8,13 @@ #define COCKATRICE_MOVE_MENU_H #include -class PlayerGraphicsItem; +class PlayerLogic; class MoveMenu : public QMenu { Q_OBJECT public: - explicit MoveMenu(PlayerGraphicsItem *player); + explicit MoveMenu(PlayerLogic *player); void setShortcutsActive(); void retranslateUi(); diff --git a/cockatrice/src/game/player/menu/player_menu.cpp b/cockatrice/src/game/player/menu/player_menu.cpp index 041b41052..9e7b91923 100644 --- a/cockatrice/src/game/player/menu/player_menu.cpp +++ b/cockatrice/src/game/player/menu/player_menu.cpp @@ -10,15 +10,12 @@ #include -PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_player) +PlayerMenu::PlayerMenu(PlayerLogic *_player) : QObject(_player), player(_player) { - connect(player->getLogic(), &PlayerLogic::requestCardMenuUpdate, this, &PlayerMenu::updateCardMenu); - connect(this, &PlayerMenu::cardInfoRequested, player, &PlayerGraphicsItem::cardInfoRequested); - playerMenu = new TearOffMenu(); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { - handMenu = addManagedMenu(player, playerMenu); + if (player->getPlayerInfo()->getLocalOrJudge()) { + handMenu = addManagedMenu(player, player->getPlayerActions(), playerMenu); libraryMenu = addManagedMenu(player, playerMenu); } else { handMenu = nullptr; @@ -28,7 +25,7 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_ graveMenu = addManagedMenu(player, playerMenu); rfgMenu = addManagedMenu(player, playerMenu); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { sideboardMenu = addManagedMenu(player, playerMenu); customZonesMenu = addManagedMenu(player); playerMenu->addSeparator(); @@ -43,7 +40,7 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_ utilityMenu = nullptr; } - if (player->getLogic()->getPlayerInfo()->getLocal()) { + if (player->getPlayerInfo()->getLocal()) { sayMenu = addManagedMenu(player); } else { sayMenu = nullptr; @@ -58,13 +55,13 @@ PlayerMenu::PlayerMenu(PlayerGraphicsItem *_player) : QObject(_player), player(_ void PlayerMenu::setMenusForGraphicItems() { - player->getTableZoneGraphicsItem()->setMenu(playerMenu); - player->getGraveyardZoneGraphicsItem()->setMenu(graveMenu, graveMenu->aViewGraveyard); - player->getRfgZoneGraphicsItem()->setMenu(rfgMenu, rfgMenu->aViewRfg); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { - player->getHandZoneGraphicsItem()->setMenu(handMenu); - player->getDeckZoneGraphicsItem()->setMenu(libraryMenu, libraryMenu->aDrawCard); - player->getSideboardZoneGraphicsItem()->setMenu(sideboardMenu); + player->getGraphicsItem()->getTableZoneGraphicsItem()->setMenu(playerMenu); + player->getGraphicsItem()->getGraveyardZoneGraphicsItem()->setMenu(graveMenu, graveMenu->aViewGraveyard); + player->getGraphicsItem()->getRfgZoneGraphicsItem()->setMenu(rfgMenu, rfgMenu->aViewRfg); + if (player->getPlayerInfo()->getLocalOrJudge()) { + player->getGraphicsItem()->getHandZoneGraphicsItem()->setMenu(handMenu); + player->getGraphicsItem()->getDeckZoneGraphicsItem()->setMenu(libraryMenu, libraryMenu->aDrawCard); + player->getGraphicsItem()->getSideboardZoneGraphicsItem()->setMenu(sideboardMenu); } } @@ -77,14 +74,12 @@ QMenu *PlayerMenu::updateCardMenu(const CardItem *card) // If is spectator (as spectators don't need card menus), return // only update the menu if the card is actually selected - if ((player->getLogic()->getGame()->getPlayerManager()->isSpectator() && - !player->getLogic()->getGame()->getPlayerManager()->isJudge()) || - player->getLogic()->getGame()->getActiveCard() != card) { + if ((player->getGame()->getPlayerManager()->isSpectator() && !player->getGame()->getPlayerManager()->isJudge()) || + player->getGame()->getActiveCard() != card) { return nullptr; } - CardMenu *menu = new CardMenu(player, card, shortcutsActive); - connect(menu, &CardMenu::cardInfoRequested, this, &PlayerMenu::cardInfoRequested); + QMenu *menu = new CardMenu(player, card, shortcutsActive); emit cardMenuUpdated(menu); return menu; @@ -92,7 +87,7 @@ QMenu *PlayerMenu::updateCardMenu(const CardItem *card) void PlayerMenu::retranslateUi() { - playerMenu->setTitle(tr("Player \"%1\"").arg(player->getLogic()->getPlayerInfo()->getName())); + playerMenu->setTitle(tr("Player \"%1\"").arg(player->getPlayerInfo()->getName())); for (auto *component : managedComponents) { component->retranslateUi(); @@ -109,8 +104,7 @@ void PlayerMenu::refreshShortcuts() { if (shortcutsActive) { // Judges get access to every player's menus but only want shortcuts to be set for their own. - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge() && - !player->getLogic()->getPlayerInfo()->getLocal()) { + if (player->getPlayerInfo()->getLocalOrJudge() && !player->getPlayerInfo()->getLocal()) { setShortcutsInactive(); } else { setShortcutsActive(); diff --git a/cockatrice/src/game/player/menu/player_menu.h b/cockatrice/src/game/player/menu/player_menu.h index 62ba66df7..d5c19df58 100644 --- a/cockatrice/src/game/player/menu/player_menu.h +++ b/cockatrice/src/game/player/menu/player_menu.h @@ -8,6 +8,7 @@ #define COCKATRICE_PLAYER_MENU_H #include "../../../interface/widgets/menus/tearoff_menu.h" +#include "../player_logic.h" #include "custom_zone_menu.h" #include "grave_menu.h" #include "hand_menu.h" @@ -22,31 +23,29 @@ #include class CardItem; -class CardMenu; -class PlayerGraphicsItem; class PlayerMenu : public QObject { Q_OBJECT signals: - void cardMenuUpdated(CardMenu *cardMenu); - void cardInfoRequested(const CardRef &cardRef); + void cardMenuUpdated(QMenu *cardMenu); void shortcutsActivated(); void shortcutsDeactivated(); void retranslateRequested(); public slots: void setMenusForGraphicItems(); - QMenu *updateCardMenu(const CardItem *card); private slots: void refreshShortcuts(); public: - explicit PlayerMenu(PlayerGraphicsItem *player); + explicit PlayerMenu(PlayerLogic *player); /** @brief Retranslate all user-visible strings. Called on language change. */ void retranslateUi(); + QMenu *updateCardMenu(const CardItem *card); + [[nodiscard]] QMenu *getPlayerMenu() const { return playerMenu; @@ -78,7 +77,7 @@ public: void setShortcutsInactive(); private: - PlayerGraphicsItem *player; + PlayerLogic *player; TearOffMenu *playerMenu; QMenu *countersMenu; HandMenu *handMenu; diff --git a/cockatrice/src/game/player/menu/pt_menu.cpp b/cockatrice/src/game/player/menu/pt_menu.cpp index 011271385..7dc3035c1 100644 --- a/cockatrice/src/game/player/menu/pt_menu.cpp +++ b/cockatrice/src/game/player/menu/pt_menu.cpp @@ -3,40 +3,30 @@ #include "../player_actions.h" #include "../player_logic.h" -PtMenu::PtMenu(PlayerGraphicsItem *player) : QMenu(tr("Power / toughness")) +PtMenu::PtMenu(PlayerLogic *player) : QMenu(tr("Power / toughness")) { - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); + PlayerActions *playerActions = player->getPlayerActions(); aIncP = new QAction(this); - connect(aIncP, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actIncP(player->getGameScene()->selectedCards()); }); + connect(aIncP, &QAction::triggered, playerActions, &PlayerActions::actIncP); aDecP = new QAction(this); - connect(aDecP, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actDecP(player->getGameScene()->selectedCards()); }); + connect(aDecP, &QAction::triggered, playerActions, &PlayerActions::actDecP); aIncT = new QAction(this); - connect(aIncT, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actIncT(player->getGameScene()->selectedCards()); }); + connect(aIncT, &QAction::triggered, playerActions, &PlayerActions::actIncT); aDecT = new QAction(this); - connect(aDecT, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actDecT(player->getGameScene()->selectedCards()); }); + connect(aDecT, &QAction::triggered, playerActions, &PlayerActions::actDecT); aIncPT = new QAction(this); - connect(aIncPT, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actIncPT(player->getGameScene()->selectedCards()); }); + connect(aIncPT, &QAction::triggered, playerActions, [playerActions] { playerActions->actIncPT(); }); aDecPT = new QAction(this); - connect(aDecPT, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actDecPT(player->getGameScene()->selectedCards()); }); + connect(aDecPT, &QAction::triggered, playerActions, &PlayerActions::actDecPT); aFlowP = new QAction(this); - connect(aFlowP, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actFlowP(player->getGameScene()->selectedCards()); }); + connect(aFlowP, &QAction::triggered, playerActions, &PlayerActions::actFlowP); aFlowT = new QAction(this); - connect(aFlowT, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actFlowT(player->getGameScene()->selectedCards()); }); + connect(aFlowT, &QAction::triggered, playerActions, &PlayerActions::actFlowT); aSetPT = new QAction(this); - connect(aSetPT, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actRequestSetPTDialog(player->getGameScene()->selectedCards()); }); + connect(aSetPT, &QAction::triggered, playerActions, &PlayerActions::actSetPT); aResetPT = new QAction(this); - connect(aResetPT, &QAction::triggered, playerActions, - [player, playerActions] { playerActions->actResetPT(player->getGameScene()->selectedCards()); }); + connect(aResetPT, &QAction::triggered, playerActions, &PlayerActions::actResetPT); addAction(aIncP); addAction(aDecP); diff --git a/cockatrice/src/game/player/menu/pt_menu.h b/cockatrice/src/game/player/menu/pt_menu.h index 72f828801..645449586 100644 --- a/cockatrice/src/game/player/menu/pt_menu.h +++ b/cockatrice/src/game/player/menu/pt_menu.h @@ -8,14 +8,14 @@ #define COCKATRICE_PT_MENU_H #include -class PlayerGraphicsItem; +class PlayerLogic; class PtMenu : public QMenu { Q_OBJECT public: - explicit PtMenu(PlayerGraphicsItem *player); + explicit PtMenu(PlayerLogic *player); void retranslateUi(); void setShortcutsActive(); diff --git a/cockatrice/src/game/player/menu/rfg_menu.cpp b/cockatrice/src/game/player/menu/rfg_menu.cpp index 79fdebf48..e8aca00cb 100644 --- a/cockatrice/src/game/player/menu/rfg_menu.cpp +++ b/cockatrice/src/game/player/menu/rfg_menu.cpp @@ -5,14 +5,14 @@ #include -RfgMenu::RfgMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(parent), player(_player) +RfgMenu::RfgMenu(PlayerLogic *_player, QWidget *parent) : TearOffMenu(parent), player(_player) { createMoveActions(); createViewActions(); addAction(aViewRfg); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { addSeparator(); moveRfgMenu = addTearOffMenu(QString()); moveRfgMenu->addAction(aMoveRfgToTopLibrary); @@ -28,8 +28,8 @@ RfgMenu::RfgMenu(PlayerGraphicsItem *_player, QWidget *parent) : TearOffMenu(par void RfgMenu::createMoveActions() { - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { - auto rfg = player->getLogic()->getRfgZone(); + if (player->getPlayerInfo()->getLocalOrJudge()) { + auto rfg = player->getRfgZone(); aMoveRfgToTopLibrary = new QAction(this); aMoveRfgToTopLibrary->setData(QList() << ZoneNames::DECK << 0); @@ -49,7 +49,7 @@ void RfgMenu::createMoveActions() void RfgMenu::createViewActions() { - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); + PlayerActions *playerActions = player->getPlayerActions(); aViewRfg = new QAction(this); connect(aViewRfg, &QAction::triggered, playerActions, &PlayerActions::actViewRfg); @@ -61,7 +61,7 @@ void RfgMenu::retranslateUi() aViewRfg->setText(tr("&View exile")); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { moveRfgMenu->setTitle(tr("&Move exile to...")); aMoveRfgToTopLibrary->setText(tr("&Top of library")); aMoveRfgToBottomLibrary->setText(tr("&Bottom of library")); diff --git a/cockatrice/src/game/player/menu/rfg_menu.h b/cockatrice/src/game/player/menu/rfg_menu.h index f5dd888e4..9e179f8fd 100644 --- a/cockatrice/src/game/player/menu/rfg_menu.h +++ b/cockatrice/src/game/player/menu/rfg_menu.h @@ -13,12 +13,12 @@ #include #include -class PlayerGraphicsItem; +class PlayerLogic; class RfgMenu : public TearOffMenu, public AbstractPlayerComponent { Q_OBJECT public: - explicit RfgMenu(PlayerGraphicsItem *player, QWidget *parent = nullptr); + explicit RfgMenu(PlayerLogic *player, QWidget *parent = nullptr); void createMoveActions(); void createViewActions(); void retranslateUi() override; @@ -38,7 +38,7 @@ public: QAction *aMoveRfgToGrave = nullptr; private: - PlayerGraphicsItem *player; + PlayerLogic *player; }; #endif // COCKATRICE_RFG_MENU_H diff --git a/cockatrice/src/game/player/menu/say_menu.cpp b/cockatrice/src/game/player/menu/say_menu.cpp index 58bbd33aa..a2d5ab982 100644 --- a/cockatrice/src/game/player/menu/say_menu.cpp +++ b/cockatrice/src/game/player/menu/say_menu.cpp @@ -4,7 +4,7 @@ #include "../player_actions.h" #include "../player_logic.h" -SayMenu::SayMenu(PlayerGraphicsItem *_player) : player(_player) +SayMenu::SayMenu(PlayerLogic *_player) : player(_player) { connect(&SettingsCache::instance().messages(), &MessageSettings::messageMacrosChanged, this, &SayMenu::initSayMenu); initSayMenu(); @@ -44,7 +44,7 @@ void SayMenu::initSayMenu() for (int i = 0; i < count; ++i) { auto *newAction = new QAction(SettingsCache::instance().messages().getMessageAt(i), this); - connect(newAction, &QAction::triggered, player->getLogic()->getPlayerActions(), &PlayerActions::actSayMessage); + connect(newAction, &QAction::triggered, player->getPlayerActions(), &PlayerActions::actSayMessage); addAction(newAction); } diff --git a/cockatrice/src/game/player/menu/say_menu.h b/cockatrice/src/game/player/menu/say_menu.h index 3ff160d05..3de70e85c 100644 --- a/cockatrice/src/game/player/menu/say_menu.h +++ b/cockatrice/src/game/player/menu/say_menu.h @@ -11,12 +11,12 @@ #include -class PlayerGraphicsItem; +class PlayerLogic; class SayMenu : public QMenu, public AbstractPlayerComponent { Q_OBJECT public: - explicit SayMenu(PlayerGraphicsItem *player); + explicit SayMenu(PlayerLogic *player); void retranslateUi() override; void setShortcutsActive() override; @@ -26,7 +26,7 @@ private slots: void initSayMenu(); private: - PlayerGraphicsItem *player; + PlayerLogic *player; bool shortcutsActive = false; }; diff --git a/cockatrice/src/game/player/menu/sideboard_menu.cpp b/cockatrice/src/game/player/menu/sideboard_menu.cpp index 27b50b570..f88625a1f 100644 --- a/cockatrice/src/game/player/menu/sideboard_menu.cpp +++ b/cockatrice/src/game/player/menu/sideboard_menu.cpp @@ -3,13 +3,12 @@ #include "../player_actions.h" #include "../player_logic.h" -SideboardMenu::SideboardMenu(PlayerGraphicsItem *player, QMenu *playerMenu) : QMenu(playerMenu) +SideboardMenu::SideboardMenu(PlayerLogic *player, QMenu *playerMenu) : QMenu(playerMenu) { aViewSideboard = new QAction(this); - connect(aViewSideboard, &QAction::triggered, player->getLogic()->getPlayerActions(), - &PlayerActions::actViewSideboard); + connect(aViewSideboard, &QAction::triggered, player->getPlayerActions(), &PlayerActions::actViewSideboard); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { addAction(aViewSideboard); } diff --git a/cockatrice/src/game/player/menu/sideboard_menu.h b/cockatrice/src/game/player/menu/sideboard_menu.h index b3b547291..20a206782 100644 --- a/cockatrice/src/game/player/menu/sideboard_menu.h +++ b/cockatrice/src/game/player/menu/sideboard_menu.h @@ -11,19 +11,19 @@ #include -class PlayerGraphicsItem; +class PlayerLogic; class SideboardMenu : public QMenu, public AbstractPlayerComponent { Q_OBJECT public: - explicit SideboardMenu(PlayerGraphicsItem *player, QMenu *playerMenu); + explicit SideboardMenu(PlayerLogic *player, QMenu *playerMenu); void retranslateUi() override; void setShortcutsActive() override; void setShortcutsInactive() override; private: - PlayerGraphicsItem *player; + PlayerLogic *player; QAction *aViewSideboard; }; diff --git a/cockatrice/src/game/player/menu/utility_menu.cpp b/cockatrice/src/game/player/menu/utility_menu.cpp index 9769a029e..6b33d7bde 100644 --- a/cockatrice/src/game/player/menu/utility_menu.cpp +++ b/cockatrice/src/game/player/menu/utility_menu.cpp @@ -8,41 +8,34 @@ #include #include -UtilityMenu::UtilityMenu(PlayerGraphicsItem *_player, QMenu *playerMenu) : QMenu(playerMenu), player(_player) +UtilityMenu::UtilityMenu(PlayerLogic *_player, QMenu *playerMenu) : QMenu(playerMenu), player(_player) { - PlayerActions *playerActions = player->getLogic()->getPlayerActions(); - connect(playerActions, &PlayerActions::requestEnableAndSetCreateAnotherTokenAction, this, - &UtilityMenu::setAndEnableCreateAnotherTokenAction); - connect(playerActions, &PlayerActions::requestSetLastToken, this, &UtilityMenu::setLastToken); + PlayerActions *playerActions = player->getPlayerActions(); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { aUntapAll = new QAction(this); connect(aUntapAll, &QAction::triggered, playerActions, &PlayerActions::actUntapAll); aRollDie = new QAction(this); - connect(aRollDie, &QAction::triggered, playerActions, &PlayerActions::actRequestRollDieDialog); + connect(aRollDie, &QAction::triggered, playerActions, &PlayerActions::actRollDie); aFlipCoin = new QAction(this); connect(aFlipCoin, &QAction::triggered, playerActions, &PlayerActions::actFlipCoin); aCreateToken = new QAction(this); - connect(aCreateToken, &QAction::triggered, playerActions, [this]() { - player->getLogic()->getPlayerActions()->actRequestCreateTokenDialog(getPredefinedTokens()); - }); + connect(aCreateToken, &QAction::triggered, playerActions, &PlayerActions::actCreateToken); aCreateAnotherToken = new QAction(this); connect(aCreateAnotherToken, &QAction::triggered, playerActions, &PlayerActions::actCreateAnotherToken); aCreateAnotherToken->setEnabled(false); aIncrementAllCardCounters = new QAction(this); - connect(aIncrementAllCardCounters, &QAction::triggered, playerActions, [this]() { - player->getLogic()->getPlayerActions()->actIncrementAllCardCounters( - player->getGameScene()->selectedCards()); - }); + connect(aIncrementAllCardCounters, &QAction::triggered, playerActions, + &PlayerActions::actIncrementAllCardCounters); createPredefinedTokenMenu = new QMenu(QString()); createPredefinedTokenMenu->setEnabled(false); - connect(player->getLogic(), &PlayerLogic::deckChanged, this, &UtilityMenu::populatePredefinedTokensMenu); + connect(player, &PlayerLogic::deckChanged, this, &UtilityMenu::populatePredefinedTokensMenu); playerMenu->addAction(aIncrementAllCardCounters); playerMenu->addSeparator(); @@ -73,7 +66,7 @@ void UtilityMenu::populatePredefinedTokensMenu() clear(); setEnabled(false); predefinedTokens.clear(); - const DeckList &deckList = player->getLogic()->getDeck(); + const DeckList &deckList = player->getDeck(); if (deckList.isEmpty()) { return; @@ -91,24 +84,14 @@ void UtilityMenu::populatePredefinedTokensMenu() if (i < 10) { a->setShortcut(QKeySequence("Alt+" + QString::number((i + 1) % 10))); } - connect(a, &QAction::triggered, player->getLogic()->getPlayerActions(), - &PlayerActions::actCreatePredefinedToken); + connect(a, &QAction::triggered, player->getPlayerActions(), &PlayerActions::actCreatePredefinedToken); } } } -void UtilityMenu::setLastToken(CardInfoPtr lastToken) -{ - if (!createAnotherTokenActionExists()) { - return; - } - - player->getLogic()->getPlayerActions()->setLastTokenInfo(lastToken); -} - void UtilityMenu::retranslateUi() { - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { aIncrementAllCardCounters->setText(tr("Increment all card counters")); aUntapAll->setText(tr("&Untap all permanents")); aRollDie->setText(tr("R&oll die...")); @@ -123,7 +106,7 @@ void UtilityMenu::setShortcutsActive() { ShortcutsSettings &shortcuts = SettingsCache::instance().shortcuts(); - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { aIncrementAllCardCounters->setShortcuts(shortcuts.getShortcut("Player/aIncrementAllCardCounters")); aUntapAll->setShortcuts(shortcuts.getShortcut("Player/aUntapAll")); aRollDie->setShortcuts(shortcuts.getShortcut("Player/aRollDie")); @@ -135,7 +118,7 @@ void UtilityMenu::setShortcutsActive() void UtilityMenu::setShortcutsInactive() { - if (player->getLogic()->getPlayerInfo()->getLocalOrJudge()) { + if (player->getPlayerInfo()->getLocalOrJudge()) { aUntapAll->setShortcut(QKeySequence()); aRollDie->setShortcut(QKeySequence()); aFlipCoin->setShortcut(QKeySequence()); diff --git a/cockatrice/src/game/player/menu/utility_menu.h b/cockatrice/src/game/player/menu/utility_menu.h index bdc2a81a5..fab3211ca 100644 --- a/cockatrice/src/game/player/menu/utility_menu.h +++ b/cockatrice/src/game/player/menu/utility_menu.h @@ -10,21 +10,19 @@ #include "abstract_player_component.h" #include -#include -class PlayerGraphicsItem; +class PlayerLogic; class UtilityMenu : public QMenu, public AbstractPlayerComponent { Q_OBJECT public slots: void populatePredefinedTokensMenu(); - void setLastToken(CardInfoPtr lastToken); void retranslateUi() override; void setShortcutsActive() override; void setShortcutsInactive() override; public: - explicit UtilityMenu(PlayerGraphicsItem *player, QMenu *playerMenu); + explicit UtilityMenu(PlayerLogic *player, QMenu *playerMenu); [[nodiscard]] bool createAnotherTokenActionExists() const { @@ -33,7 +31,7 @@ public: void setAndEnableCreateAnotherTokenAction(QString text) { - aCreateAnotherToken->setText(tr("C&reate another %1 token").arg(text)); + aCreateAnotherToken->setText(text); aCreateAnotherToken->setEnabled(true); } @@ -43,7 +41,7 @@ public: } private: - PlayerGraphicsItem *player; + PlayerLogic *player; QStringList predefinedTokens; QMenu *createPredefinedTokenMenu; diff --git a/cockatrice/src/game/player/player_actions.cpp b/cockatrice/src/game/player/player_actions.cpp index 2b0428dd8..1706c44dc 100644 --- a/cockatrice/src/game/player/player_actions.cpp +++ b/cockatrice/src/game/player/player_actions.cpp @@ -5,6 +5,7 @@ #include "../../interface/widgets/tabs/tab_game.h" #include "../../interface/widgets/utility/get_text_with_max.h" #include "../board/card_item.h" +#include "../client/settings/card_counter_settings.h" #include "../dialogs/dlg_move_top_cards_until.h" #include "../dialogs/dlg_roll_dice.h" #include "../zones/view_zone_logic.h" @@ -38,8 +39,6 @@ static constexpr int MOVE_TOP_CARD_UNTIL_INTERVAL = 100; PlayerActions::PlayerActions(PlayerLogic *_player) : QObject(_player), player(_player), lastTokenTableRow(0), movingCardsUntil(false) { - connect(this, &PlayerActions::requestZoneViewToggle, player, &PlayerLogic::onRequestZoneViewToggle); - moveTopCardTimer = new QTimer(this); moveTopCardTimer->setInterval(MOVE_TOP_CARD_UNTIL_INTERVAL); moveTopCardTimer->setSingleShot(true); @@ -134,12 +133,12 @@ void PlayerActions::playCardToTable(const CardItem *card, bool faceDown) void PlayerActions::actViewLibrary() { - emit requestZoneViewToggle(ZoneNames::DECK, -1); + player->getGameScene()->toggleZoneView(player, ZoneNames::DECK, -1); } void PlayerActions::actViewHand() { - emit requestZoneViewToggle(ZoneNames::HAND, -1); + player->getGameScene()->toggleZoneView(player, ZoneNames::HAND, -1); } /** @@ -171,45 +170,49 @@ void PlayerActions::actSortHand() static QList defaultOptions = {CardList::SortByName, CardList::SortByPrinting}; - emit requestSortHand(sortOptions + defaultOptions); + player->getGraphicsItem()->getHandZoneGraphicsItem()->sortHand(sortOptions + defaultOptions); } -void PlayerActions::actRequestViewTopCardsDialog() +void PlayerActions::actViewTopCards() { - emit requestViewTopCardsDialog(defaultNumberTopCards, player->getDeckZone()->getCards().size()); + int deckSize = player->getDeckZone()->getCards().size(); + bool ok; + 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) { + defaultNumberTopCards = number; + player->getGameScene()->toggleZoneView(player, ZoneNames::DECK, number); + } } -void PlayerActions::actViewTopCards(int number) +void PlayerActions::actViewBottomCards() { - defaultNumberTopCards = number; - emit requestZoneViewToggle(ZoneNames::DECK, number); + int deckSize = player->getDeckZone()->getCards().size(); + bool ok; + 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) { + defaultNumberBottomCards = number; + player->getGameScene()->toggleZoneView(player, ZoneNames::DECK, number, true); + } } -void PlayerActions::actRequestViewBottomCardsDialog() -{ - emit requestViewBottomCardsDialog(defaultNumberBottomCards, player->getDeckZone()->getCards().size()); -} - -void PlayerActions::actViewBottomCards(int number) -{ - defaultNumberBottomCards = number; - emit requestZoneViewToggle(ZoneNames::DECK, number, true); -} - -void PlayerActions::actAlwaysRevealTopCard(bool alwaysRevealTopCard) +void PlayerActions::actAlwaysRevealTopCard() { Command_ChangeZoneProperties cmd; cmd.set_zone_name(ZoneNames::DECK); - cmd.set_always_reveal_top_card(alwaysRevealTopCard); + cmd.set_always_reveal_top_card(player->getPlayerMenu()->getLibraryMenu()->isAlwaysRevealTopCardChecked()); sendGameCommand(cmd); } -void PlayerActions::actAlwaysLookAtTopCard(bool alwaysRevealTopCard) +void PlayerActions::actAlwaysLookAtTopCard() { Command_ChangeZoneProperties cmd; cmd.set_zone_name(ZoneNames::DECK); - cmd.set_always_look_at_top_card(alwaysRevealTopCard); + cmd.set_always_look_at_top_card(player->getPlayerMenu()->getLibraryMenu()->isAlwaysLookAtTopCardChecked()); sendGameCommand(cmd); } @@ -221,17 +224,17 @@ void PlayerActions::actOpenDeckInDeckEditor() void PlayerActions::actViewGraveyard() { - emit requestZoneViewToggle(ZoneNames::GRAVE, -1); + player->getGameScene()->toggleZoneView(player, ZoneNames::GRAVE, -1); } void PlayerActions::actViewRfg() { - emit requestZoneViewToggle(ZoneNames::EXILE, -1); + player->getGameScene()->toggleZoneView(player, ZoneNames::EXILE, -1); } void PlayerActions::actViewSideboard() { - emit requestZoneViewToggle(ZoneNames::SIDEBOARD, -1); + player->getGameScene()->toggleZoneView(player, ZoneNames::SIDEBOARD, -1); } void PlayerActions::actShuffle() @@ -239,20 +242,18 @@ void PlayerActions::actShuffle() sendGameCommand(Command_Shuffle()); } -void PlayerActions::actRequestShuffleTopDialog() +void PlayerActions::actShuffleTop() { const int maxCards = player->getDeckZone()->getCards().size(); if (maxCards == 0) { return; } - emit requestShuffleTopDialog(defaultNumberTopCards, maxCards); -} - -void PlayerActions::actShuffleTop(int number) -{ - const int maxCards = player->getDeckZone()->getCards().size(); - if (maxCards == 0) { + bool ok; + 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) { return; } @@ -270,20 +271,18 @@ void PlayerActions::actShuffleTop(int number) sendGameCommand(cmd); } -void PlayerActions::actRequestShuffleBottomDialog() +void PlayerActions::actShuffleBottom() { const int maxCards = player->getDeckZone()->getCards().size(); if (maxCards == 0) { return; } - emit requestShuffleBottomDialog(defaultNumberBottomCards, maxCards); -} - -void PlayerActions::actShuffleBottom(int number) -{ - const int maxCards = player->getDeckZone()->getCards().size(); - if (maxCards == 0) { + bool ok; + 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) { return; } @@ -308,18 +307,21 @@ void PlayerActions::actDrawCard() sendGameCommand(cmd); } -void PlayerActions::actRequestMulliganDialog() +void PlayerActions::actMulligan() { int startSize = SettingsCache::instance().getStartingHandSize(); int handSize = player->getHandZone()->getCards().size(); int deckSize = player->getDeckZone()->getCards().size() + handSize; - emit requestMulliganDialog(startSize, handSize, deckSize); -} + bool ok; + 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); -void PlayerActions::actMulligan(int number) -{ - int handSize = player->getHandZone()->getCards().size(); + if (!ok) { + return; + } if (number < 1) { number = handSize + number; @@ -353,19 +355,19 @@ void PlayerActions::doMulligan(int number) sendGameCommand(cmd); } -void PlayerActions::actRequestDrawCardsDialog() +void PlayerActions::actDrawCards() { int deckSize = player->getDeckZone()->getCards().size(); - - emit requestDrawCardsDialog(defaultNumberTopCards, deckSize); -} - -void PlayerActions::actDrawCards(int number) -{ - defaultNumberTopCards = number; - Command_DrawCards cmd; - cmd.set_number(static_cast(number)); - sendGameCommand(cmd); + bool ok; + 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) { + defaultNumberTopCards = number; + Command_DrawCards cmd; + cmd.set_number(static_cast(number)); + sendGameCommand(cmd); + } } void PlayerActions::actUndoDraw() @@ -423,40 +425,36 @@ void PlayerActions::actMoveTopCardToExile() void PlayerActions::actMoveTopCardsToGrave() { - actRequestMoveTopCardsToDialog(ZoneNames::GRAVE, tr("grave"), false); + moveTopCardsTo(ZoneNames::GRAVE, tr("grave"), false); } void PlayerActions::actMoveTopCardsToGraveFaceDown() { - actRequestMoveTopCardsToDialog(ZoneNames::GRAVE, tr("grave"), true); + moveTopCardsTo(ZoneNames::GRAVE, tr("grave"), true); } void PlayerActions::actMoveTopCardsToExile() { - actRequestMoveTopCardsToDialog(ZoneNames::EXILE, tr("exile"), false); + moveTopCardsTo(ZoneNames::EXILE, tr("exile"), false); } void PlayerActions::actMoveTopCardsToExileFaceDown() { - actRequestMoveTopCardsToDialog(ZoneNames::EXILE, tr("exile"), true); + moveTopCardsTo(ZoneNames::EXILE, tr("exile"), true); } -void PlayerActions::actRequestMoveTopCardsToDialog(const QString &targetZone, - const QString &zoneDisplayName, - bool faceDown) +void PlayerActions::moveTopCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown) { const int maxCards = player->getDeckZone()->getCards().size(); if (maxCards == 0) { return; } - emit requestMoveTopCardsToDialog(defaultNumberTopCards, maxCards, targetZone, zoneDisplayName, faceDown); -} - -void PlayerActions::moveTopCardsTo(int number, const QString &targetZone, bool faceDown) -{ - const int maxCards = player->getDeckZone()->getCards().size(); - if (maxCards == 0) { + bool ok; + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move top cards to %1").arg(zoneDisplayName), + tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1, + maxCards, 1, &ok); + if (!ok) { return; } @@ -483,16 +481,17 @@ void PlayerActions::moveTopCardsTo(int number, const QString &targetZone, bool f sendGameCommand(cmd); } -void PlayerActions::actRequestMoveTopCardsUntilDialog() +void PlayerActions::actMoveTopCardsUntil() { stopMoveTopCardsUntil(); - emit requestMoveTopCardsUntilDialog(movingCardsUntilOptions); -} + DlgMoveTopCardsUntil dlg(player->getGame()->getTab(), movingCardsUntilOptions); + if (!dlg.exec()) { + return; + } -void PlayerActions::moveTopCardsUntil(const QString &expr, MoveTopCardsUntilOptions options) -{ - movingCardsUntilOptions = options; + auto expr = dlg.getExpr(); + movingCardsUntilOptions = dlg.getOptions(); if (player->getDeckZone()->getCards().empty()) { stopMoveTopCardsUntil(); @@ -621,40 +620,36 @@ void PlayerActions::actMoveBottomCardToExile() void PlayerActions::actMoveBottomCardsToGrave() { - actRequestMoveBottomCardsToDialog(ZoneNames::GRAVE, tr("grave"), false); + moveBottomCardsTo(ZoneNames::GRAVE, tr("grave"), false); } void PlayerActions::actMoveBottomCardsToGraveFaceDown() { - actRequestMoveBottomCardsToDialog(ZoneNames::GRAVE, tr("grave"), true); + moveBottomCardsTo(ZoneNames::GRAVE, tr("grave"), true); } void PlayerActions::actMoveBottomCardsToExile() { - actRequestMoveBottomCardsToDialog(ZoneNames::EXILE, tr("exile"), false); + moveBottomCardsTo(ZoneNames::EXILE, tr("exile"), false); } void PlayerActions::actMoveBottomCardsToExileFaceDown() { - actRequestMoveBottomCardsToDialog(ZoneNames::EXILE, tr("exile"), true); + moveBottomCardsTo(ZoneNames::EXILE, tr("exile"), true); } -void PlayerActions::actRequestMoveBottomCardsToDialog(const QString &targetZone, - const QString &zoneDisplayName, - bool faceDown) +void PlayerActions::moveBottomCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown) { const int maxCards = player->getDeckZone()->getCards().size(); if (maxCards == 0) { return; } - emit requestMoveBottomCardsToDialog(defaultNumberBottomCards, maxCards, targetZone, zoneDisplayName, faceDown); -} - -void PlayerActions::moveBottomCardsTo(int number, const QString &targetZone, bool faceDown) -{ - const int maxCards = player->getDeckZone()->getCards().size(); - if (maxCards == 0) { + bool ok; + int number = QInputDialog::getInt(player->getGame()->getTab(), tr("Move bottom cards to %1").arg(zoneDisplayName), + tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1, + maxCards, 1, &ok); + if (!ok) { return; } @@ -766,24 +761,20 @@ void PlayerActions::actDrawBottomCard() sendGameCommand(cmd); } -void PlayerActions::actRequestDrawBottomCardsDialog() +void PlayerActions::actDrawBottomCards() { const int maxCards = player->getDeckZone()->getCards().size(); if (maxCards == 0) { return; } - emit requestDrawBottomCardsDialog(defaultNumberBottomCards, maxCards); -} - -void PlayerActions::actDrawBottomCards(int number) -{ - const int maxCards = player->getDeckZone()->getCards().size(); - if (maxCards == 0) { + bool ok; + 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) { return; - } - - if (number > maxCards) { + } else if (number > maxCards) { number = maxCards; } defaultNumberBottomCards = number; @@ -850,16 +841,16 @@ void PlayerActions::actUntapAll() sendGameCommand(cmd); } -void PlayerActions::actRequestRollDieDialog() +void PlayerActions::actRollDie() { - emit requestRollDieDialog(); -} + DlgRollDice dlg(player->getGame()->getTab()); + if (!dlg.exec()) { + return; + } -void PlayerActions::actRollDie(int sides, int count) -{ Command_RollDie cmd; - cmd.set_sides(sides); - cmd.set_count(count); + cmd.set_sides(dlg.getDieSideCount()); + cmd.set_count(dlg.getDiceToRollCount()); sendGameCommand(cmd); } @@ -871,14 +862,14 @@ void PlayerActions::actFlipCoin() sendGameCommand(cmd); } -void PlayerActions::actRequestCreateTokenDialog(const QStringList &predefinedTokens) +void PlayerActions::actCreateToken() { - emit requestCreateTokenDialog(predefinedTokens); -} + DlgCreateToken dlg(player->getPlayerMenu()->getUtilityMenu()->getPredefinedTokens(), player->getGame()->getTab()); + if (!dlg.exec()) { + return; + } -void PlayerActions::actCreateToken(TokenInfo tokenToCreate) -{ - lastTokenInfo = tokenToCreate; + lastTokenInfo = dlg.getTokenInfo(); ExactCard correctedCard = CardDatabaseManager::query()->guessCard({lastTokenInfo.name, lastTokenInfo.providerId}); if (correctedCard) { @@ -889,7 +880,8 @@ void PlayerActions::actCreateToken(TokenInfo tokenToCreate) } } - emit requestEnableAndSetCreateAnotherTokenAction(lastTokenInfo.name); + player->getPlayerMenu()->getUtilityMenu()->setAndEnableCreateAnotherTokenAction( + tr("C&reate another %1 token").arg(lastTokenInfo.name)); actCreateAnotherToken(); } @@ -920,12 +912,8 @@ void PlayerActions::setLastToken(CardInfoPtr cardInfo) return; } - emit requestSetLastToken(cardInfo); -} - -void PlayerActions::setLastTokenInfo(CardInfoPtr cardInfo) -{ - if (cardInfo == nullptr) { + UtilityMenu *utilityMenu = player->getPlayerMenu()->getUtilityMenu(); + if (utilityMenu == nullptr || !utilityMenu->createAnotherTokenActionExists()) { return; } @@ -939,7 +927,7 @@ void PlayerActions::setLastTokenInfo(CardInfoPtr cardInfo) lastTokenTableRow = TableZone::tableRowToGridY(cardInfo->getUiAttributes().tableRow); - emit requestEnableAndSetCreateAnotherTokenAction(lastTokenInfo.name); + utilityMenu->setAndEnableCreateAnotherTokenAction(tr("C&reate another %1 token").arg(lastTokenInfo.name)); } void PlayerActions::actCreatePredefinedToken() @@ -958,17 +946,23 @@ void PlayerActions::actCreatePredefinedToken() void PlayerActions::actCreateRelatedCard() { const CardItem *sourceCard = player->getGame()->getActiveCard(); - if (!sourceCard) { return; } - auto *action = static_cast(sender()); // If there is a better way of passing a CardRelation through a QAction, please add it here. auto relatedCards = sourceCard->getCardInfo().getAllRelatedCards(); - CardRelation *cardRelation = relatedCards.at(action->data().toInt()); - actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation); + + /* + * If we make a token via "Token: TokenName" + * then let's allow it to be created via "create another token" + */ + if (createRelatedFromRelation(sourceCard, cardRelation) && cardRelation->getCanCreateAnother()) { + ExactCard relatedCard = CardDatabaseManager::query()->getCardFromSameSet(cardRelation->getName(), + sourceCard->getCard().getPrinting()); + setLastToken(relatedCard.getCardPtr()); + } } void PlayerActions::actCreateAllRelatedCards() @@ -988,9 +982,7 @@ void PlayerActions::actCreateAllRelatedCards() if (relatedCards.length() == 1) { cardRelation = relatedCards.at(0); - lastRelatedCreationSucceeded = false; // reset before emit - actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation); - if (lastRelatedCreationSucceeded) { + if (createRelatedFromRelation(sourceCard, cardRelation)) { ++tokensTypesCreated; } } else { @@ -1002,18 +994,15 @@ void PlayerActions::actCreateAllRelatedCards() } } switch (nonExcludedRelatedCards.length()) { - case 1: + case 1: // if nonExcludedRelatedCards == 1 cardRelation = nonExcludedRelatedCards.at(0); - lastRelatedCreationSucceeded = false; // reset before emit - actRequestCreateRelatedFromRelationDialog(sourceCard, cardRelation); - if (lastRelatedCreationSucceeded) { + if (createRelatedFromRelation(sourceCard, cardRelation)) { ++tokensTypesCreated; } break; - // If all are marked "Exclude", then treat the situation as if none of them are. // We won't accept "garbage in, garbage out", here. - case 0: + case 0: // else if nonExcludedRelatedCards == 0 for (CardRelation *cardRelationAll : relatedCards) { if (!cardRelationAll->getDoesAttach() && !cardRelationAll->getIsVariable()) { dbName = cardRelationAll->getName(); @@ -1028,8 +1017,7 @@ void PlayerActions::actCreateAllRelatedCards() } } break; - - default: + default: // else for (CardRelation *cardRelationNotExcluded : nonExcludedRelatedCards) { if (!cardRelationNotExcluded->getDoesAttach() && !cardRelationNotExcluded->getIsVariable()) { dbName = cardRelationNotExcluded->getName(); @@ -1057,83 +1045,50 @@ void PlayerActions::actCreateAllRelatedCards() } } -void PlayerActions::actRequestCreateRelatedFromRelationDialog(const CardItem *sourceCard, - const CardRelation *cardRelation) -{ - emit requestCreateRelatedFromRelationDialog(sourceCard, cardRelation); -} - -bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, - const CardRelation *cardRelation, - int variableCount) +bool PlayerActions::createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation) { if (sourceCard == nullptr || cardRelation == nullptr) { return false; } - - const QString dbName = cardRelation->getName(); - const bool persistent = cardRelation->getIsPersistent(); - - // Variable relations always use DoesNotAttach, regardless of the count the user - // entered. + QString dbName = cardRelation->getName(); + bool persistent = cardRelation->getIsPersistent(); if (cardRelation->getIsVariable()) { - if (variableCount <= 0) { + bool ok; + player->setDialogSemaphore(true); + 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) { return false; } - for (int i = 0; i < variableCount; ++i) { - createCard(sourceCard, dbName, CardRelationType::DoesNotAttach, persistent); - } - return true; - } - - const int count = cardRelation->getDefaultCount(); - - if (count > 1) { for (int i = 0; i < count; ++i) { createCard(sourceCard, dbName, CardRelationType::DoesNotAttach, persistent); } - return true; - } - - CardRelationType attachType; - // do not attempt to attach to another player's cards, this causes the card to attempt to attach to the same - // cardid on the local player's field instead, which is an entirely different card! - if (player->getPlayerInfo()->getLocalOrJudge()) { - attachType = cardRelation->getAttachType(); + } else if (cardRelation->getDefaultCount() > 1) { + for (int i = 0; i < cardRelation->getDefaultCount(); ++i) { + createCard(sourceCard, dbName, CardRelationType::DoesNotAttach, persistent); + } } else { - attachType = CardRelationType::DoesNotAttach; - } + CardRelationType attachType; + // do not attempt to attach to another player's cards, this causes the card to attempt to attach to the same + // cardid on the local player's field instead, which is an entirely different card! + if (player->getPlayerInfo()->getLocalOrJudge()) { + attachType = cardRelation->getAttachType(); + } else { + attachType = CardRelationType::DoesNotAttach; + } - // move card onto table first if attaching from some other zone - // we only do this for AttachTo because cross-zone TransformInto is already handled server-side - if (attachType == CardRelationType::AttachTo && sourceCard->getZone()->getName() != ZoneNames::TABLE) { - playCardToTable(sourceCard, false); - } + // move card onto table first if attaching from some other zone + // we only do this for AttachTo because cross-zone TransformInto is already handled server-side + if (attachType == CardRelationType::AttachTo && sourceCard->getZone()->getName() != ZoneNames::TABLE) { + playCardToTable(sourceCard, false); + } - createCard(sourceCard, dbName, attachType, persistent); + createCard(sourceCard, dbName, attachType, persistent); + } return true; } -void PlayerActions::onRelatedCardCreated(const CardItem *sourceCard, const CardRelation *cardRelation) -{ - if (sourceCard == nullptr || cardRelation == nullptr) { - return; - } - - /* - * If we make a token via "Token: TokenName" - * then let's allow it to be created via "create another token" - */ - if (!cardRelation->getCanCreateAnother()) { - return; - } - - ExactCard relatedCard = - CardDatabaseManager::query()->getCardFromSameSet(cardRelation->getName(), sourceCard->getCard().getPrinting()); - - setLastToken(relatedCard.getCardPtr()); -} - void PlayerActions::createCard(const CardItem *sourceCard, const QString &dbCardName, CardRelationType attachType, @@ -1211,29 +1166,35 @@ void PlayerActions::actSayMessage() sendGameCommand(cmd); } -void PlayerActions::actRequestMoveCardXCardsFromTopDialog() +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()->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 - emit requestMoveCardXCardsFromTopDialog(defaultNumberTopCardsToPlaceBelow, deckSize); -} + if (!ok) { + return; + } -void PlayerActions::actMoveCardXCardsFromTop(QList selectedCards, int number) -{ defaultNumberTopCardsToPlaceBelow = number; - if (selectedCards.isEmpty()) { + QList cardList = player->getGameScene()->selectedCards(); + if (cardList.isEmpty()) { return; } QList commandList; ListOfCardsToMove idList; - for (const auto &i : selectedCards) { + for (const auto &i : cardList) { idList.add_card()->set_card_id(i->getId()); } - int startPlayerId = selectedCards[0]->getZone()->getPlayer()->getPlayerInfo()->getId(); - QString startZone = selectedCards[0]->getZone()->getName(); + int startPlayerId = cardList[0]->getZone()->getPlayer()->getPlayerInfo()->getId(); + QString startZone = cardList[0]->getZone()->getName(); auto *cmd = new Command_MoveCard; cmd->set_start_player_id(startPlayerId); @@ -1252,12 +1213,12 @@ void PlayerActions::actMoveCardXCardsFromTop(QList selectedCards, in } } -void PlayerActions::actIncPT(QList selectedCards, int deltaP, int deltaT) +void PlayerActions::actIncPT(int deltaP, int deltaT) { int playerid = player->getPlayerInfo()->getId(); QList commandList; - for (auto card : selectedCards) { + for (auto card : player->getGameScene()->selectedCards()) { QString pt = card->getPT(); const auto ptList = CardItem::parsePT(pt); QString newpt; @@ -1285,11 +1246,11 @@ void PlayerActions::actIncPT(QList selectedCards, int deltaP, int de player->getGame()->getGameEventHandler()->sendGameCommand(prepareGameCommand(commandList), playerid); } -void PlayerActions::actResetPT(QList selectedCards) +void PlayerActions::actResetPT() { int playerid = player->getPlayerInfo()->getId(); QList commandList; - for (auto card : selectedCards) { + for (auto card : player->getGameScene()->selectedCards()) { QString ptString; if (!card->getFaceDown()) { // leave the pt empty if the card is face down ExactCard ec = card->getCard(); @@ -1318,28 +1279,31 @@ void PlayerActions::actResetPT(QList selectedCards) } } -void PlayerActions::actRequestSetPTDialog(QList selectedCards) +void PlayerActions::actSetPT() { QString oldPT; + int playerid = player->getPlayerInfo()->getId(); - for (auto card : selectedCards) { + auto cards = player->getGameScene()->selectedCards(); + for (auto card : cards) { if (!card->getPT().isEmpty()) { oldPT = card->getPT(); } } - - emit requestSetPTDialog(oldPT); -} - -void PlayerActions::actSetPT(QList selectedCards, const QString &pt) -{ - int playerid = player->getPlayerInfo()->getId(); + bool ok; + player->setDialogSemaphore(true); + 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) { + return; + } const auto ptList = CardItem::parsePT(pt); bool empty = ptList.isEmpty(); QList commandList; - for (auto card : selectedCards) { + for (auto card : cards) { auto *cmd = new Command_SetCardAttr; QString newpt = QString(); if (!empty) { @@ -1383,47 +1347,47 @@ void PlayerActions::actDrawArrow() } } -void PlayerActions::actIncP(QList selectedCards) +void PlayerActions::actIncP() { - actIncPT(selectedCards, 1, 0); + actIncPT(1, 0); } -void PlayerActions::actDecP(QList selectedCards) +void PlayerActions::actDecP() { - actIncPT(selectedCards, -1, 0); + actIncPT(-1, 0); } -void PlayerActions::actIncT(QList selectedCards) +void PlayerActions::actIncT() { - actIncPT(selectedCards, 0, 1); + actIncPT(0, 1); } -void PlayerActions::actDecT(QList selectedCards) +void PlayerActions::actDecT() { - actIncPT(selectedCards, 0, -1); + actIncPT(0, -1); } -void PlayerActions::actIncPT(QList selectedCards) +void PlayerActions::actIncPT() { - actIncPT(selectedCards, 1, 1); + actIncPT(1, 1); } -void PlayerActions::actDecPT(QList selectedCards) +void PlayerActions::actDecPT() { - actIncPT(selectedCards, -1, -1); + actIncPT(-1, -1); } -void PlayerActions::actFlowP(QList selectedCards) +void PlayerActions::actFlowP() { - actIncPT(selectedCards, 1, -1); + actIncPT(1, -1); } -void PlayerActions::actFlowT(QList selectedCards) +void PlayerActions::actFlowT() { - actIncPT(selectedCards, -1, 1); + actIncPT(-1, 1); } -void PlayerActions::actReduceLifeByPower(QList selectedCards) +void PlayerActions::actReduceLifeByPower() { // find life counter auto lifeCounter = player->getLifeCounter(); @@ -1431,9 +1395,10 @@ void PlayerActions::actReduceLifeByPower(QList selectedCards) return; } - // calculate total power; + // calculate total power + auto cards = player->getGameScene()->selectedCards(); int total = 0; - for (auto card : selectedCards) { + for (auto card : cards) { QVariantList parsed = CardItem::parsePT(card->getPT()); if (!parsed.isEmpty()) { int power = parsed.first().toInt(); // toInt will default to 0 if it's not an int @@ -1458,22 +1423,31 @@ void AnnotationDialog::keyPressEvent(QKeyEvent *event) QInputDialog::keyPressEvent(event); } -void PlayerActions::actRequestSetAnnotationDialog(QList selectedCards) +void PlayerActions::actSetAnnotation() { QString oldAnnotation; - for (auto card : selectedCards) { + auto cards = player->getGameScene()->selectedCards(); + for (auto card : cards) { if (!card->getAnnotation().isEmpty()) { oldAnnotation = card->getAnnotation(); } } - emit requestSetAnnotationDialog(oldAnnotation); -} + player->setDialogSemaphore(true); + AnnotationDialog *dialog = new AnnotationDialog(player->getGame()->getTab()); + dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput); + dialog->setWindowTitle(tr("Set annotation")); + dialog->setLabelText(tr("Please enter the new annotation:")); + dialog->setTextValue(oldAnnotation); + bool ok = dialog->exec(); + player->setDialogSemaphore(false); + if (player->clearCardsToDelete() || !ok) { + return; + } + QString annotation = dialog->textValue().left(MAX_NAME_LENGTH); -void PlayerActions::actSetAnnotation(QList selectedCards, const QString &annotation) -{ QList commandList; - for (auto card : selectedCards) { + for (auto card : cards) { auto *cmd = new Command_SetCardAttr; cmd->set_zone(card->getZone()->getName().toStdString()); cmd->set_card_id(card->getId()); @@ -1494,10 +1468,10 @@ void PlayerActions::actAttach() card->drawAttachArrow(); } -void PlayerActions::actUnattach(QList selectedCards) +void PlayerActions::actUnattach() { QList commandList; - for (auto card : selectedCards) { + for (auto card : player->getGameScene()->selectedCards()) { if (!card->getAttachedTo()) { continue; } @@ -1510,20 +1484,20 @@ void PlayerActions::actUnattach(QList selectedCards) sendGameCommand(prepareGameCommand(commandList)); } -void PlayerActions::actAddCardCounter(QList selectedCards, int counterId) +void PlayerActions::actAddCardCounter(int counterId) { - offsetCardCounter(selectedCards, counterId, 1); + offsetCardCounter(counterId, 1); } -void PlayerActions::actRemoveCardCounter(QList selectedCards, int counterId) +void PlayerActions::actRemoveCardCounter(int counterId) { - offsetCardCounter(selectedCards, counterId, -1); + offsetCardCounter(counterId, -1); } -void PlayerActions::offsetCardCounter(QList selectedCards, int counterId, int offset) +void PlayerActions::offsetCardCounter(int counterId, int offset) { QList commandList; - for (auto card : selectedCards) { + for (auto card : player->getGameScene()->selectedCards()) { int oldValue = card->getCounters().value(counterId, 0); int newValue = oldValue + offset; @@ -1543,25 +1517,34 @@ void PlayerActions::offsetCardCounter(QList selectedCards, int count sendGameCommand(prepareGameCommand(commandList)); } -void PlayerActions::actRequestSetCardCounterDialog(QList selectedCards, int counterId) +void PlayerActions::actSetCardCounter(int counterId) { + player->setDialogSemaphore(true); + // If a single card is selected, we show the old value in the dialog. Otherwise, we show "x" + QList sel = player->getGameScene()->selectedCards(); QString oldValueForDlg = "x"; - if (selectedCards.size() == 1) { - auto *card = selectedCards.first(); + if (sel.size() == 1) { + auto *card = sel.first(); oldValueForDlg = QString::number(card->getCounters().value(counterId, 0)); } - emit requestSetCardCounterDialog(counterId, oldValueForDlg); -} + auto &cardCounterSettings = SettingsCache::instance().cardCounters(); + QString counterName = cardCounterSettings.displayName(counterId); + + AbstractCounterDialog dialog(counterName, oldValueForDlg, player->getGame()->getTab()); + int ok = dialog.exec(); + + player->setDialogSemaphore(false); + if (player->clearCardsToDelete() || !ok) { + return; + } -void PlayerActions::actSetCardCounter(QList selectedCards, int counterId, const QString &counterValue) -{ QList commandList; - for (auto card : selectedCards) { + for (auto card : sel) { int oldValue = card->getCounters().value(counterId, 0); Expression exp(oldValue); - double parsed = exp.parse(counterValue); + double parsed = exp.parse(dialog.textValue()); // Clamp in double precision first to avoid UB, then cast int number = static_cast(qBound(0.0, parsed, static_cast(MAX_COUNTERS_ON_CARD))); @@ -1576,8 +1559,9 @@ void PlayerActions::actSetCardCounter(QList selectedCards, int count sendGameCommand(prepareGameCommand(commandList)); } -void PlayerActions::actIncrementAllCardCounters(QList cardsToUpdate) +void PlayerActions::actIncrementAllCardCounters() { + auto cardsToUpdate = player->getGameScene()->selectedCards(); if (cardsToUpdate.isEmpty()) { // If no cards selected, update all cards on table cardsToUpdate = static_cast>(player->getTableZone()->getCards()); @@ -1623,8 +1607,10 @@ static bool isUnwritableRevealZone(CardZoneLogic *zone) return false; } -void PlayerActions::playSelectedCards(QList selectedCards, const bool faceDown) +void PlayerActions::playSelectedCards(const bool faceDown) { + QList selectedCards = player->getGameScene()->selectedCards(); + // CardIds will get shuffled downwards when cards leave the deck. // We need to iterate through the cards in reverse order so cardIds don't get changed out from under us as we play // out the cards one-by-one. @@ -1638,19 +1624,19 @@ void PlayerActions::playSelectedCards(QList selectedCards, const boo } } -void PlayerActions::actPlay(QList selectedCards) +void PlayerActions::actPlay() { - playSelectedCards(selectedCards, false); + playSelectedCards(false); } -void PlayerActions::actPlayFacedown(QList selectedCards) +void PlayerActions::actPlayFacedown() { - playSelectedCards(selectedCards, true); + playSelectedCards(true); } -void PlayerActions::actHide(QList selectedCards) +void PlayerActions::actHide() { - for (const auto &item : selectedCards) { + for (const auto &item : player->getGameScene()->selectedCards()) { auto *card = static_cast(item); if (card && isUnwritableRevealZone(card->getZone())) { card->getZone()->removeCard(card); @@ -1658,7 +1644,7 @@ void PlayerActions::actHide(QList selectedCards) } } -void PlayerActions::actReveal(QList selectedCards, QAction *action) +void PlayerActions::actReveal(QAction *action) { const int otherPlayerId = action->data().toInt(); @@ -1667,7 +1653,7 @@ void PlayerActions::actReveal(QList selectedCards, QAction *action) cmd.set_player_id(otherPlayerId); } - for (auto card : selectedCards) { + for (auto card : player->getGameScene()->selectedCards()) { if (!cmd.has_zone_name()) { cmd.set_zone_name(card->getZone()->getName().toStdString()); } @@ -1749,14 +1735,15 @@ void PlayerActions::actRevealRandomGraveyardCard(int revealToPlayerId) sendGameCommand(cmd); } -void PlayerActions::cardMenuAction(QList selectedCards, CardMenuActionType type) +void PlayerActions::cardMenuAction() { - QList cardList = selectedCards; + auto *a = dynamic_cast(sender()); + QList cardList = player->getGameScene()->selectedCards(); QList commandList; - if (type <= cmClone) { + if (a->data().toInt() <= (int)cmClone) { for (const auto &card : cardList) { - switch (type) { + switch (static_cast(a->data().toInt())) { // Leaving both for compatibility with server case cmUntap: // fallthrough @@ -1837,7 +1824,7 @@ void PlayerActions::cardMenuAction(QList selectedCards, CardMenuActi idList.add_card()->set_card_id(i->getId()); } - switch (type) { + switch (static_cast(a->data().toInt())) { case cmMoveToTopLibrary: { auto *cmd = new Command_MoveCard; cmd->set_start_player_id(startPlayerId); diff --git a/cockatrice/src/game/player/player_actions.h b/cockatrice/src/game/player/player_actions.h index 2779fa5aa..3b822b61a 100644 --- a/cockatrice/src/game/player/player_actions.h +++ b/cockatrice/src/game/player/player_actions.h @@ -9,7 +9,6 @@ #define COCKATRICE_PLAYER_ACTIONS_H #include "../dialogs/dlg_create_token.h" #include "../dialogs/dlg_move_top_cards_until.h" -#include "card_menu_action_type.h" #include "event_processing_options.h" #include "player_logic.h" @@ -57,75 +56,30 @@ public: return movingCardsUntil; } -signals: - void requestViewTopCardsDialog(int defaultNumberTopCards, int deckSize); - void requestViewBottomCardsDialog(int defaultNumberBottomCards, int deckSize); - void requestShuffleTopDialog(int defaultNumberTopCards, int maxCards); - void requestShuffleBottomDialog(int defaultNumberBottomCards, int maxCards); - void requestMulliganDialog(int startSize, int handSize, int deckSize); - void requestDrawCardsDialog(int defaultNumberTopCards, int deckSize); - void requestMoveTopCardsToDialog(int defaultNumberTopCards, - int maxCards, - const QString &targetZone, - const QString &zoneDisplayName, - bool faceDown); - void requestMoveTopCardsUntilDialog(MoveTopCardsUntilOptions options); - void requestMoveBottomCardsToDialog(int defaultNumberBottomCards, - int maxCards, - const QString &targetZone, - const QString &zoneDisplayName, - bool faceDown); - void requestDrawBottomCardsDialog(int defaultNumberBottomCards, int maxCards); - void requestRollDieDialog(); - void requestCreateTokenDialog(const QStringList &predefinedTokens); - void requestCreateRelatedFromRelationDialog(const CardItem *sourceCard, const CardRelation *cardRelation); - void requestMoveCardXCardsFromTopDialog(int defaultNumberTopCardsToPlaceBelow, int deckSize); - void requestSetPTDialog(const QString &oldPT); - void requestSetAnnotationDialog(const QString &oldAnnotation); - void requestSetCardCounterDialog(int counterId, const QString &oldValueForDlg); - void requestZoneViewToggle(const QString &zoneName, int numberCards, bool isReversed = false); - void requestSortHand(const QList &options); - void requestEnableAndSetCreateAnotherTokenAction(const QString &lastTokenName); - void requestSetLastToken(CardInfoPtr lastToken); - public slots: void setLastToken(CardInfoPtr cardInfo); - void setLastTokenInfo(CardInfoPtr cardInfo); void playCard(CardItem *c, bool faceDown); void playCardToTable(const CardItem *c, bool faceDown); void actUntapAll(); - void actRequestRollDieDialog(); - void actRollDie(int sides, int count); + void actRollDie(); void actFlipCoin(); - void actRequestCreateTokenDialog(const QStringList &predefinedTokens); - void actCreateToken(TokenInfo tokenToCreate); + void actCreateToken(); void actCreateAnotherToken(); - void actRequestCreateRelatedFromRelationDialog(const CardItem *sourceCard, const CardRelation *cardRelation); - bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation, int variableCount); - void onRelatedCardCreated(const CardItem *sourceCard, const CardRelation *cardRelation); - void setLastRelatedCreationSucceeded(bool succeeded) - { - lastRelatedCreationSucceeded = succeeded; - } void actShuffle(); - void actRequestShuffleTopDialog(); - void actShuffleTop(int number); - void actRequestShuffleBottomDialog(); - void actShuffleBottom(int number); + void actShuffleTop(); + void actShuffleBottom(); void actDrawCard(); - void actRequestDrawCardsDialog(); - void actDrawCards(int number); + void actDrawCards(); void actUndoDraw(); - void actRequestMulliganDialog(); - void actMulligan(int number); + void actMulligan(); void actMulliganSameSize(); void actMulliganMinusOne(); void doMulligan(int number); - void actPlay(QList selectedCards); - void actPlayFacedown(QList selectedCards); - void actHide(QList selectedCards); + void actPlay(); + void actPlayFacedown(); + void actHide(); void actMoveTopCardToPlay(); void actMoveTopCardToPlayFaceDown(); @@ -135,14 +89,10 @@ public slots: void actMoveTopCardsToGraveFaceDown(); void actMoveTopCardsToExile(); void actMoveTopCardsToExileFaceDown(); - void actRequestMoveTopCardsUntilDialog(); - void moveTopCardsUntil(const QString &expr, MoveTopCardsUntilOptions options); + void actMoveTopCardsUntil(); void actMoveTopCardToBottom(); - void actRequestMoveTopCardsToDialog(const QString &targetZone, const QString &zoneDisplayName, bool faceDown); - void moveTopCardsTo(int number, const QString &targetZone, bool faceDown); void actDrawBottomCard(); - void actRequestDrawBottomCardsDialog(); - void actDrawBottomCards(int number); + void actDrawBottomCards(); void actMoveBottomCardToPlay(); void actMoveBottomCardToPlayFaceDown(); void actMoveBottomCardToGrave(); @@ -152,8 +102,6 @@ public slots: void actMoveBottomCardsToExile(); void actMoveBottomCardsToExileFaceDown(); void actMoveBottomCardToTop(); - void actRequestMoveBottomCardsToDialog(const QString &targetZone, const QString &zoneDisplayName, bool faceDown); - void moveBottomCardsTo(int number, const QString &targetZone, bool faceDown); void actSelectAll(); void actSelectRow(); @@ -161,12 +109,10 @@ public slots: void actViewLibrary(); void actViewHand(); - void actRequestViewTopCardsDialog(); - void actViewTopCards(int number); - void actRequestViewBottomCardsDialog(); - void actViewBottomCards(int number); - void actAlwaysRevealTopCard(bool alwaysRevealTopCard); - void actAlwaysLookAtTopCard(bool alwaysRevealTopCard); + void actViewTopCards(); + void actViewBottomCards(); + void actAlwaysRevealTopCard(); + void actAlwaysLookAtTopCard(); void actViewGraveyard(); void actLendLibrary(int lendToPlayerId); void actRevealTopCards(int revealToPlayerId, int amount); @@ -181,41 +127,37 @@ public slots: void actCreateRelatedCard(); void actCreateAllRelatedCards(); - void actRequestMoveCardXCardsFromTopDialog(); - void actMoveCardXCardsFromTop(QList selectedCards, int number); - void actRemoveCardCounter(QList selectedCards, int counterId); - void actAddCardCounter(QList selectedCards, int counterId); - void actRequestSetCardCounterDialog(QList selectedCards, int counterId); - void actSetCardCounter(QList selectedCards, int counterId, const QString &counterValue); - void actIncrementAllCardCounters(QList cardsToUpdate); + void actMoveCardXCardsFromTop(); + void actRemoveCardCounter(int counterId); + void actAddCardCounter(int counterId); + void actSetCardCounter(int counterId); + void actIncrementAllCardCounters(); void actAttach(); - void actUnattach(QList selectedCards); + void actUnattach(); void actDrawArrow(); - void actIncPT(QList selectedCards, int deltaP, int deltaT); - void actResetPT(QList selectedCards); - void actRequestSetPTDialog(QList selectedCards); - void actSetPT(QList selectedCards, const QString &pt); - void actIncP(QList selectedCards); - void actDecP(QList selectedCards); - void actIncT(QList selectedCards); - void actDecT(QList selectedCards); - void actIncPT(QList selectedCards); - void actDecPT(QList selectedCards); - void actFlowP(QList selectedCards); - void actFlowT(QList selectedCards); + void actIncPT(int deltaP, int deltaT); + void actResetPT(); + void actSetPT(); + void actIncP(); + void actDecP(); + void actIncT(); + void actDecT(); + void actIncPT(); + void actDecPT(); + void actFlowP(); + void actFlowT(); - void actReduceLifeByPower(QList selectedCards); + void actReduceLifeByPower(); - void actRequestSetAnnotationDialog(QList selectedCards); - void actSetAnnotation(QList selectedCards, const QString &annotation); - void actReveal(QList selectedCards, QAction *action); + void actSetAnnotation(); + void actReveal(QAction *action); void actRevealHand(int revealToPlayerId); void actRevealRandomHandCard(int revealToPlayerId); void actRevealLibrary(int revealToPlayerId); void actSortHand(); - void cardMenuAction(QList selectedCards, CardMenuActionType type); + void cardMenuAction(); private: PlayerLogic *player; @@ -234,19 +176,21 @@ private: int movingCardsUntilCounter = 0; MoveTopCardsUntilOptions movingCardsUntilOptions; - bool lastRelatedCreationSucceeded = false; + void moveTopCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown); + void moveBottomCardsTo(const QString &targetZone, const QString &zoneDisplayName, bool faceDown); void createCard(const CardItem *sourceCard, const QString &dbCardName, CardRelationType attach = CardRelationType::DoesNotAttach, bool persistent = false); + bool createRelatedFromRelation(const CardItem *sourceCard, const CardRelation *cardRelation); - void playSelectedCards(QList selectedCards, bool faceDown = false); + void playSelectedCards(bool faceDown = false); void cmdSetTopCard(Command_MoveCard &cmd); void cmdSetBottomCard(Command_MoveCard &cmd); - void offsetCardCounter(QList selectedCards, int counterId, int offset); + void offsetCardCounter(int counterId, int offset); }; #endif // COCKATRICE_PLAYER_ACTIONS_H diff --git a/cockatrice/src/game/player/player_dialogs.cpp b/cockatrice/src/game/player/player_dialogs.cpp deleted file mode 100644 index 3c26ae1fe..000000000 --- a/cockatrice/src/game/player/player_dialogs.cpp +++ /dev/null @@ -1,298 +0,0 @@ -#include "player_dialogs.h" - -#include "../../client/settings/card_counter_settings.h" -#include "../../interface/widgets/utility/get_text_with_max.h" -#include "../board/card_item.h" -#include "../dialogs/dlg_roll_dice.h" -#include "../player/player_graphics_item.h" - -#include -#include - -PlayerDialogs::PlayerDialogs(PlayerGraphicsItem *_player, PlayerActions *_playerActions) - : QObject(_player), player(_player), playerActions(_playerActions) -{ - connect(playerActions, &PlayerActions::requestViewTopCardsDialog, this, - &PlayerDialogs::onViewTopCardsDialogRequested); - - connect(playerActions, &PlayerActions::requestViewBottomCardsDialog, this, - &PlayerDialogs::onViewBottomCardsDialogRequested); - - connect(playerActions, &PlayerActions::requestShuffleTopDialog, this, &PlayerDialogs::onShuffleTopDialogRequested); - - connect(playerActions, &PlayerActions::requestShuffleBottomDialog, this, - &PlayerDialogs::onShuffleBottomDialogRequested); - - connect(playerActions, &PlayerActions::requestMulliganDialog, this, &PlayerDialogs::onMulliganDialogRequested); - - connect(playerActions, &PlayerActions::requestDrawCardsDialog, this, &PlayerDialogs::onDrawCardsDialogRequested); - - connect(playerActions, &PlayerActions::requestMoveTopCardsToDialog, this, - &PlayerDialogs::onMoveTopCardsToDialogRequested); - - connect(playerActions, &PlayerActions::requestMoveTopCardsUntilDialog, this, - &PlayerDialogs::onMoveTopCardsUntilDialogRequested); - - connect(playerActions, &PlayerActions::requestMoveBottomCardsToDialog, this, - &PlayerDialogs::onMoveBottomCardsToDialogRequested); - - connect(playerActions, &PlayerActions::requestDrawBottomCardsDialog, this, - &PlayerDialogs::onDrawBottomCardsDialogRequested); - - connect(playerActions, &PlayerActions::requestRollDieDialog, this, &PlayerDialogs::onRollDieDialogRequested); - - connect(playerActions, &PlayerActions::requestCreateTokenDialog, this, - &PlayerDialogs::onCreateTokenDialogRequested); - - connect(playerActions, &PlayerActions::requestCreateRelatedFromRelationDialog, this, - &PlayerDialogs::onCreateRelatedFromRelationDialogRequested); - - connect(playerActions, &PlayerActions::requestMoveCardXCardsFromTopDialog, this, - &PlayerDialogs::onMoveCardXCardsFromTopDialogRequested); - - connect(playerActions, &PlayerActions::requestSetPTDialog, this, &PlayerDialogs::onSetPTDialogRequested); - - connect(playerActions, &PlayerActions::requestSetAnnotationDialog, this, - &PlayerDialogs::onSetAnnotationDialogRequested); - - connect(playerActions, &PlayerActions::requestSetCardCounterDialog, this, - &PlayerDialogs::onSetCardCounterDialogRequested); -} - -void PlayerDialogs::onViewTopCardsDialogRequested(int defaultNumberTopCards, int deckSize) -{ - bool ok; - int number = QInputDialog::getInt(dialogParent(), tr("View top cards of library"), - tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberTopCards, 1, - deckSize, 1, &ok); - if (ok) { - playerActions->actViewTopCards(number); - } -} - -void PlayerDialogs::onViewBottomCardsDialogRequested(int defaultNumberBottomCards, int deckSize) -{ - bool ok; - int number = QInputDialog::getInt(dialogParent(), tr("View bottom cards of library"), - tr("Number of cards: (max. %1)").arg(deckSize), defaultNumberBottomCards, 1, - deckSize, 1, &ok); - if (ok) { - playerActions->actViewBottomCards(number); - } -} - -void PlayerDialogs::onShuffleTopDialogRequested(int defaultNumberTopCards, int maxCards) -{ - bool ok; - int number = QInputDialog::getInt(dialogParent(), tr("Shuffle top cards of library"), - tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1, - maxCards, 1, &ok); - if (ok) { - playerActions->actShuffleTop(number); - } -} - -void PlayerDialogs::onShuffleBottomDialogRequested(int defaultNumberBottomCards, int maxCards) -{ - bool ok; - int number = QInputDialog::getInt(dialogParent(), tr("Shuffle bottom cards of library"), - tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1, - maxCards, 1, &ok); - if (ok) { - playerActions->actShuffleBottom(number); - } -} - -void PlayerDialogs::onMulliganDialogRequested(int startSize, int handSize, int deckSize) -{ - bool ok; - int number = QInputDialog::getInt(dialogParent(), 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); - - if (ok) { - playerActions->actMulligan(number); - } -} - -void PlayerDialogs::onDrawCardsDialogRequested(int defaultNumberTopCards, int deckSize) -{ - bool ok; - int number = QInputDialog::getInt(dialogParent(), tr("Draw cards"), tr("Number of cards: (max. %1)").arg(deckSize), - defaultNumberTopCards, 1, deckSize, 1, &ok); - - if (ok) { - playerActions->actDrawCards(number); - } -} - -void PlayerDialogs::onMoveTopCardsToDialogRequested(int defaultNumberTopCards, - int maxCards, - const QString &targetZone, - const QString &zoneDisplayName, - bool faceDown) -{ - bool ok; - int number = QInputDialog::getInt(dialogParent(), tr("Move top cards to %1").arg(zoneDisplayName), - tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberTopCards, 1, - maxCards, 1, &ok); - if (ok) { - playerActions->moveTopCardsTo(number, targetZone, faceDown); - } -} - -void PlayerDialogs::onMoveTopCardsUntilDialogRequested(MoveTopCardsUntilOptions options) -{ - DlgMoveTopCardsUntil dlg(dialogParent(), options); - if (!dlg.exec()) { - return; - } - playerActions->moveTopCardsUntil(dlg.getExpr(), dlg.getOptions()); -} - -void PlayerDialogs::onMoveBottomCardsToDialogRequested(int defaultNumberBottomCards, - int maxCards, - const QString &targetZone, - const QString &zoneDisplayName, - bool faceDown) -{ - bool ok; - int number = QInputDialog::getInt(dialogParent(), tr("Move bottom cards to %1").arg(zoneDisplayName), - tr("Number of cards: (max. %1)").arg(maxCards), defaultNumberBottomCards, 1, - maxCards, 1, &ok); - if (ok) { - playerActions->moveBottomCardsTo(number, targetZone, faceDown); - } -} - -void PlayerDialogs::onDrawBottomCardsDialogRequested(int defaultNumberBottomCards, int maxCards) -{ - bool ok; - int number = - QInputDialog::getInt(dialogParent(), tr("Draw bottom cards"), tr("Number of cards: (max. %1)").arg(maxCards), - defaultNumberBottomCards, 1, maxCards, 1, &ok); - if (ok) { - playerActions->actDrawBottomCards(number); - } -} - -void PlayerDialogs::onRollDieDialogRequested() -{ - DlgRollDice dlg(dialogParent()); - if (!dlg.exec()) { - return; - } - playerActions->actRollDie(dlg.getDieSideCount(), dlg.getDiceToRollCount()); -} - -void PlayerDialogs::onCreateRelatedFromRelationDialogRequested(const CardItem *sourceCard, - const CardRelation *cardRelation) -{ - if (sourceCard == nullptr || cardRelation == nullptr) { - playerActions->setLastRelatedCreationSucceeded(false); - return; - } - - int variableCount = cardRelation->getDefaultCount(); - - if (cardRelation->getIsVariable()) { - bool ok; - - emit requestDialogSemaphore(true); - - variableCount = QInputDialog::getInt(dialogParent(), tr("Create tokens"), tr("Number:"), - cardRelation->getDefaultCount(), 1, MAX_TOKENS_PER_DIALOG, 1, &ok); - - emit requestDialogSemaphore(false); - - if (!ok) { - playerActions->setLastRelatedCreationSucceeded(false); // cancelled - return; - } - } - - const bool succeeded = playerActions->createRelatedFromRelation(sourceCard, cardRelation, variableCount); - - playerActions->setLastRelatedCreationSucceeded(succeeded); - - if (succeeded) { - playerActions->onRelatedCardCreated(sourceCard, cardRelation); // only on confirmed success - } -} - -void PlayerDialogs::onCreateTokenDialogRequested(const QStringList &predefinedTokens) -{ - DlgCreateToken dlg(predefinedTokens, dialogParent()); - if (!dlg.exec()) { - return; - } - - playerActions->actCreateToken(dlg.getTokenInfo()); -} - -void PlayerDialogs::onMoveCardXCardsFromTopDialogRequested(int defaultNumberTopCardsToPlaceBelow, int deckSize) -{ - bool ok; - int number = - QInputDialog::getInt(dialogParent(), 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 - - if (ok) { - playerActions->actMoveCardXCardsFromTop(player->getGameScene()->selectedCards(), number); - } -} - -void PlayerDialogs::onSetPTDialogRequested(const QString &oldPT) -{ - bool ok; - auto cards = player->getGameScene()->selectedCards(); - emit requestDialogSemaphore(true); - QString pt = getTextWithMax(dialogParent(), tr("Change power/toughness"), tr("Change stats to:"), QLineEdit::Normal, - oldPT, &ok); - emit requestDialogSemaphore(false); - - if (!ok || player->getLogic()->clearCardsToDelete()) { - return; - } - - playerActions->actSetPT(cards, pt); -} - -void PlayerDialogs::onSetAnnotationDialogRequested(const QString &oldAnnotation) -{ - auto cards = player->getGameScene()->selectedCards(); - emit requestDialogSemaphore(true); - AnnotationDialog *dialog = new AnnotationDialog(dialogParent()); - dialog->setOptions(QInputDialog::UsePlainTextEditForTextInput); - dialog->setWindowTitle(tr("Set annotation")); - dialog->setLabelText(tr("Please enter the new annotation:")); - dialog->setTextValue(oldAnnotation); - bool ok = dialog->exec(); - emit requestDialogSemaphore(false); - if (!ok || player->getLogic()->clearCardsToDelete()) { - return; - } - QString annotation = dialog->textValue().left(MAX_NAME_LENGTH); - playerActions->actSetAnnotation(cards, annotation); -} - -void PlayerDialogs::onSetCardCounterDialogRequested(int counterId, const QString &oldValueForDlg) -{ - auto cards = player->getGameScene()->selectedCards(); - emit requestDialogSemaphore(true); - - auto &cardCounterSettings = SettingsCache::instance().cardCounters(); - QString counterName = cardCounterSettings.displayName(counterId); - - AbstractCounterDialog dialog(counterName, oldValueForDlg, dialogParent()); - int ok = dialog.exec(); - - emit requestDialogSemaphore(false); - if (!ok || player->getLogic()->clearCardsToDelete()) { - return; - } - playerActions->actSetCardCounter(cards, counterId, dialog.textValue()); -} \ No newline at end of file diff --git a/cockatrice/src/game/player/player_dialogs.h b/cockatrice/src/game/player/player_dialogs.h deleted file mode 100644 index a15c5174f..000000000 --- a/cockatrice/src/game/player/player_dialogs.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef COCKATRICE_PLAYER_DIALOGS_H -#define COCKATRICE_PLAYER_DIALOGS_H -#include "player_actions.h" - -#include -#include - -class PlayerGraphicsItem; -class PlayerDialogs : public QObject -{ - - Q_OBJECT - -public: - explicit PlayerDialogs(PlayerGraphicsItem *player, PlayerActions *playerActions); - -signals: - void requestDialogSemaphore(bool active); - -public slots: - void onViewTopCardsDialogRequested(int defaultNumberTopCards, int deckSize); - void onViewBottomCardsDialogRequested(int defaultNumberBottomCards, int deckSize); - void onShuffleTopDialogRequested(int defaultNumberTopCards, int maxCards); - void onShuffleBottomDialogRequested(int defaultNumberBottomCards, int maxCards); - void onMulliganDialogRequested(int startSize, int handSize, int deckSize); - void onDrawCardsDialogRequested(int defaultNumberTopCards, int deckSize); - void onMoveTopCardsToDialogRequested(int defaultNumberTopCards, - int maxCards, - const QString &targetZone, - const QString &zoneDisplayName, - bool faceDown); - void onMoveTopCardsUntilDialogRequested(MoveTopCardsUntilOptions options); - void onMoveBottomCardsToDialogRequested(int defaultNumberBottomCards, - int maxCards, - const QString &targetZone, - const QString &zoneDisplayName, - bool faceDown); - void onDrawBottomCardsDialogRequested(int defaultNumberBottomCards, int maxCards); - void onRollDieDialogRequested(); - void onCreateRelatedFromRelationDialogRequested(const CardItem *sourceCard, const CardRelation *cardRelation); - void onCreateTokenDialogRequested(const QStringList &predefinedTokens); - void onMoveCardXCardsFromTopDialogRequested(int defaultNumberTopCardsToPlaceBelow, int deckSize); - void onSetPTDialogRequested(const QString &oldPT); - void onSetAnnotationDialogRequested(const QString &oldAnnotation); - void onSetCardCounterDialogRequested(int counterId, const QString &oldValueForDlg); - -private: - PlayerGraphicsItem *player; - PlayerActions *playerActions; - - QWidget *dialogParent() const - { - if (auto *s = player->scene()) { - if (auto *v = s->views().value(0)) { - return v->window(); - } - } - return nullptr; - } -}; - -#endif // COCKATRICE_PLAYER_DIALOGS_H diff --git a/cockatrice/src/game/player/player_event_handler.cpp b/cockatrice/src/game/player/player_event_handler.cpp index aa751170b..debc6c8f7 100644 --- a/cockatrice/src/game/player/player_event_handler.cpp +++ b/cockatrice/src/game/player/player_event_handler.cpp @@ -6,6 +6,7 @@ #include "../board/arrow_item.h" #include "../board/card_item.h" #include "../board/card_list.h" +#include "libcockatrice/utility/color.h" #include "player_actions.h" #include "player_logic.h" @@ -32,12 +33,10 @@ #include #include #include -#include #include PlayerEventHandler::PlayerEventHandler(PlayerLogic *_player) : QObject(_player), player(_player) { - connect(this, &PlayerEventHandler::requestCardMenuUpdate, player, &PlayerLogic::requestCardMenuUpdate); } void PlayerEventHandler::eventGameSay(const Event_GameSay &event) @@ -253,7 +252,7 @@ void PlayerEventHandler::eventSetCardCounter(const Event_SetCardCounter &event) int oldValue = card->getCounters().value(event.counter_id(), 0); card->setCounter(event.counter_id(), event.counter_value()); - emit requestCardMenuUpdate(card); + player->getPlayerMenu()->updateCardMenu(card); emit logSetCardCounter(player, card->getName(), event.counter_id(), event.counter_value(), oldValue); } @@ -371,7 +370,7 @@ void PlayerEventHandler::eventMoveCard(const Event_MoveCard &event, const GameEv targetZone->addCard(card, true, x, y); emit cardZoneChanged(card, startZone == targetZone); - emit requestCardMenuUpdate(card); + player->getPlayerMenu()->updateCardMenu(card); if (player->getPlayerActions()->isMovingCardsUntil() && startZoneString == ZoneNames::DECK && targetZone->getName() == ZoneNames::STACK) { @@ -398,7 +397,7 @@ void PlayerEventHandler::eventFlipCard(const Event_FlipCard &event) emit logFlipCard(player, card->getName(), event.face_down()); card->setFaceDown(event.face_down()); - emit requestCardMenuUpdate(card); + player->getPlayerMenu()->updateCardMenu(card); } void PlayerEventHandler::eventDestroyCard(const Event_DestroyCard &event) @@ -467,7 +466,7 @@ void PlayerEventHandler::eventAttachCard(const Event_AttachCard &event) } else { emit logUnattachCard(player, startCard->getName()); } - emit requestCardMenuUpdate(startCard); + player->getPlayerMenu()->updateCardMenu(startCard); } void PlayerEventHandler::eventDrawCards(const Event_DrawCards &event) @@ -553,7 +552,7 @@ void PlayerEventHandler::eventRevealCards(const Event_RevealCards &event, EventP } if (!options.testFlag(SKIP_REVEAL_WINDOW) && showZoneView && !cardList.isEmpty()) { - emit player->requestRevealedZoneView(player, zone, cardList, event.grant_write_access()); + player->getGameScene()->addRevealedZoneView(player, zone, cardList, event.grant_write_access()); } emit logRevealCards(player, zone, cardId, cardName, otherPlayer, false, diff --git a/cockatrice/src/game/player/player_event_handler.h b/cockatrice/src/game/player/player_event_handler.h index cfd82933f..958dee16b 100644 --- a/cockatrice/src/game/player/player_event_handler.h +++ b/cockatrice/src/game/player/player_event_handler.h @@ -83,7 +83,6 @@ signals: void logAlwaysRevealTopCard(PlayerLogic *player, CardZoneLogic *zone, bool reveal); void logAlwaysLookAtTopCard(PlayerLogic *player, CardZoneLogic *zone, bool reveal); void cardZoneChanged(CardItem *card, bool sameZone); - void requestCardMenuUpdate(const CardItem *card); public: PlayerEventHandler(PlayerLogic *player); diff --git a/cockatrice/src/game/player/player_graphics_item.cpp b/cockatrice/src/game/player/player_graphics_item.cpp index b0a476d5a..0d4f8c3ed 100644 --- a/cockatrice/src/game/player/player_graphics_item.cpp +++ b/cockatrice/src/game/player/player_graphics_item.cpp @@ -8,10 +8,6 @@ #include "../board/abstract_card_item.h" #include "../board/counter_general.h" #include "../hand_counter.h" -#include "player_actions.h" -#include "player_dialogs.h" - -#include PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player) { @@ -20,35 +16,28 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player) connect(&SettingsCache::instance(), &SettingsCache::handJustificationChanged, this, &PlayerGraphicsItem::rearrangeZones); connect(player, &PlayerLogic::rearrangeCounters, this, &PlayerGraphicsItem::rearrangeCounters); - connect(player, &PlayerLogic::activeChanged, this, &PlayerGraphicsItem::onPlayerActiveChanged); connect(player, &PlayerLogic::concededChanged, this, [this](int, bool c) { setVisible(!c); }); connect(player, &PlayerLogic::zoneIdChanged, this, [this](int id) { playerArea->setPlayerZoneId(id); }); connect(player, &PlayerLogic::counterAdded, this, &PlayerGraphicsItem::onCounterAdded); connect(player, &PlayerLogic::counterRemoved, this, &PlayerGraphicsItem::onCounterRemoved); - playerMenu = new PlayerMenu(this); - - connect(playerMenu, &PlayerMenu::shortcutsActivated, this, [this]() { + connect(player->getPlayerMenu(), &PlayerMenu::shortcutsActivated, this, [this]() { for (auto *ctr : counterWidgets) { ctr->setShortcutsActive(); } }); - connect(playerMenu, &PlayerMenu::shortcutsDeactivated, this, [this]() { + connect(player->getPlayerMenu(), &PlayerMenu::shortcutsDeactivated, this, [this]() { for (auto *ctr : counterWidgets) { ctr->setShortcutsInactive(); } }); - connect(playerMenu, &PlayerMenu::retranslateRequested, this, [this]() { + connect(player->getPlayerMenu(), &PlayerMenu::retranslateRequested, this, [this]() { for (auto *ctr : counterWidgets) { ctr->retranslateUi(); } }); - playerDialogs = new PlayerDialogs(this, player->getPlayerActions()); - - connect(playerDialogs, &PlayerDialogs::requestDialogSemaphore, player, &PlayerLogic::setDialogSemaphore); - playerArea = new PlayerArea(this); playerTarget = new PlayerTarget(player, playerArea); @@ -58,8 +47,6 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player) initializeZones(); - playerMenu->setMenusForGraphicItems(); - connect(tableZoneGraphicsItem, &TableZone::sizeChanged, this, &PlayerGraphicsItem::updateBoundingRect); updateBoundingRect(); @@ -70,7 +57,7 @@ PlayerGraphicsItem::PlayerGraphicsItem(PlayerLogic *_player) : player(_player) void PlayerGraphicsItem::retranslateUi() { - playerMenu->retranslateUi(); + player->getPlayerMenu()->retranslateUi(); QMapIterator zoneIterator(player->getZones()); while (zoneIterator.hasNext()) { @@ -106,16 +93,14 @@ void PlayerGraphicsItem::initializeZones() rfgZoneGraphicsItem = new PileZone(player->getRfgZone(), this); rfgZoneGraphicsItem->setPos(base + QPointF(0, 2 * h + h2 + 10)); - tableZoneGraphicsItem = new TableZone(player->getTableZone(), mirrored, this); + tableZoneGraphicsItem = new TableZone(player->getTableZone(), this); connect(tableZoneGraphicsItem, &TableZone::sizeChanged, this, &PlayerGraphicsItem::updateBoundingRect); - connect(this, &PlayerGraphicsItem::mirroredChanged, tableZoneGraphicsItem, &TableZone::setMirrored); stackZoneGraphicsItem = new StackZone(player->getStackZone(), static_cast(tableZoneGraphicsItem->boundingRect().height()), this); handZoneGraphicsItem = new HandZone(player->getHandZone(), static_cast(tableZoneGraphicsItem->boundingRect().height()), this); - connect(player->getPlayerActions(), &PlayerActions::requestSortHand, handZoneGraphicsItem, &HandZone::sortHand); connect(handZoneGraphicsItem->getLogic(), &HandZoneLogic::cardCountChanged, handCounter, &HandCounter::updateNumber); @@ -160,7 +145,6 @@ void PlayerGraphicsItem::setMirrored(bool _mirrored) { if (mirrored != _mirrored) { mirrored = _mirrored; - emit mirroredChanged(mirrored); rearrangeZones(); } } @@ -175,11 +159,11 @@ void PlayerGraphicsItem::onCounterAdded(CounterState *state) } counterWidgets.insert(state->getId(), widget); - if (playerMenu->getCountersMenu() && widget->getMenu()) { - playerMenu->getCountersMenu()->addMenu(widget->getMenu()); + if (player->getPlayerMenu()->getCountersMenu() && widget->getMenu()) { + player->getPlayerMenu()->getCountersMenu()->addMenu(widget->getMenu()); } - if (playerMenu->getShortcutsActive()) { + if (player->getPlayerMenu()->getShortcutsActive()) { widget->setShortcutsActive(); } @@ -192,8 +176,8 @@ void PlayerGraphicsItem::onCounterRemoved(int counterId) if (!widget) { return; } - if (playerMenu->getCountersMenu() && widget->getMenu()) { - playerMenu->getCountersMenu()->removeAction(widget->getMenu()->menuAction()); + if (player->getPlayerMenu()->getCountersMenu() && widget->getMenu()) { + player->getPlayerMenu()->getCountersMenu()->removeAction(widget->getMenu()->menuAction()); } widget->delCounter(); rearrangeCounters(); diff --git a/cockatrice/src/game/player/player_graphics_item.h b/cockatrice/src/game/player/player_graphics_item.h index c1fcb4ed8..e37fe7290 100644 --- a/cockatrice/src/game/player/player_graphics_item.h +++ b/cockatrice/src/game/player/player_graphics_item.h @@ -14,7 +14,6 @@ class HandZone; class PileZone; -class PlayerDialogs; class PlayerTarget; class StackZone; class TableZone; @@ -56,16 +55,11 @@ public: return static_cast(scene()); } - PlayerLogic *getLogic() const + PlayerLogic *getPlayer() const { return player; } - [[nodiscard]] PlayerMenu *getPlayerMenu() const - { - return playerMenu; - } - PlayerArea *getPlayerArea() const { return playerArea; @@ -117,13 +111,9 @@ public slots: signals: void sizeChanged(); void playerCountChanged(); - void mirroredChanged(bool isMirrored); - void cardInfoRequested(const CardRef &cardRef); private: PlayerLogic *player; - PlayerMenu *playerMenu; - PlayerDialogs *playerDialogs; PlayerArea *playerArea; PlayerTarget *playerTarget; QMap counterWidgets; diff --git a/cockatrice/src/game/player/player_logic.cpp b/cockatrice/src/game/player/player_logic.cpp index b748eb19a..0210aa0c6 100644 --- a/cockatrice/src/game/player/player_logic.cpp +++ b/cockatrice/src/game/player/player_logic.cpp @@ -35,6 +35,14 @@ PlayerLogic::PlayerLogic(const ServerInfo_User &info, int _id, bool _local, bool conceded(false), zoneId(0), dialogSemaphore(false) { initializeZones(); + + playerMenu = new PlayerMenu(this); + graphicsItem = new PlayerGraphicsItem(this); + playerMenu->setMenusForGraphicItems(); + + connect(this, &PlayerLogic::activeChanged, graphicsItem, &PlayerGraphicsItem::onPlayerActiveChanged); + + connect(this, &PlayerLogic::openDeckEditor, game->getTab(), &TabGame::openDeckEditor); } void PlayerLogic::initializeZones() @@ -60,6 +68,7 @@ PlayerLogic::~PlayerLogic() } zones.clear(); + delete playerMenu; delete getPlayerInfo()->userInfo; } @@ -317,16 +326,22 @@ void PlayerLogic::setActive(bool _active) active = _active; emit activeChanged(active); } -void PlayerLogic::onRequestZoneViewToggle(const QString &zoneName, int numberCards, bool isReversed) -{ - emit requestZoneViewToggle(this, zoneName, numberCards, isReversed); -} void PlayerLogic::updateZones() { getTableZone()->reorganizeCards(); } +PlayerGraphicsItem *PlayerLogic::getGraphicsItem() +{ + return graphicsItem; +} + +GameScene *PlayerLogic::getGameScene() +{ + return getGraphicsItem()->getGameScene(); +} + void PlayerLogic::setGameStarted() { if (playerInfo->local) { diff --git a/cockatrice/src/game/player/player_logic.h b/cockatrice/src/game/player/player_logic.h index c83892dea..c3508d069 100644 --- a/cockatrice/src/game/player/player_logic.h +++ b/cockatrice/src/game/player/player_logic.h @@ -67,14 +67,8 @@ class PlayerLogic : public QObject signals: void openDeckEditor(const LoadedDeck &deck); - void requestZoneViewToggle(PlayerLogic *player, const QString &zoneName, int numberCards, bool isReversed); - void requestRevealedZoneView(PlayerLogic *player, - CardZoneLogic *zone, - const QList &cardList, - bool withWritePermission); void deckChanged(); void newCardAdded(AbstractCardItem *card); - void requestCardMenuUpdate(const CardItem *card); void counterAdded(CounterState *state); void counterRemoved(int counterId); void rearrangeCounters(); @@ -91,7 +85,6 @@ signals: public slots: void setActive(bool _active); - void onRequestZoneViewToggle(const QString &zoneName, int numberCards, bool isReversed); public: PlayerLogic(const ServerInfo_User &info, int _id, bool _local, bool _judge, AbstractGame *_parent); @@ -119,6 +112,10 @@ public: return game; } + GameScene *getGameScene(); + + [[nodiscard]] PlayerGraphicsItem *getGraphicsItem(); + [[nodiscard]] PlayerActions *getPlayerActions() const { return playerActions; @@ -134,6 +131,11 @@ public: return playerInfo; } + [[nodiscard]] PlayerMenu *getPlayerMenu() const + { + return playerMenu; + } + void setDeck(const DeckList &_deck); [[nodiscard]] const DeckList &getDeck() const @@ -232,6 +234,8 @@ private: PlayerInfo *playerInfo; PlayerEventHandler *playerEventHandler; PlayerActions *playerActions; + PlayerMenu *playerMenu; + PlayerGraphicsItem *graphicsItem; bool active; bool conceded; diff --git a/cockatrice/src/game_graphics/zones/table_zone.cpp b/cockatrice/src/game_graphics/zones/table_zone.cpp index 245de8281..ffb4adf5c 100644 --- a/cockatrice/src/game_graphics/zones/table_zone.cpp +++ b/cockatrice/src/game_graphics/zones/table_zone.cpp @@ -22,8 +22,7 @@ const QColor TableZone::FADE_MASK = QColor(0, 0, 0, 80); const QColor TableZone::GRADIENT_COLOR = QColor(255, 255, 255, 150); const QColor TableZone::GRADIENT_COLORLESS = QColor(255, 255, 255, 0); -TableZone::TableZone(TableZoneLogic *_logic, bool _mirrored, QGraphicsItem *parent) - : SelectZone(_logic, parent), active(false), mirrored(_mirrored) +TableZone::TableZone(TableZoneLogic *_logic, QGraphicsItem *parent) : SelectZone(_logic, parent), active(false) { connect(_logic, &TableZoneLogic::contentSizeChanged, this, &TableZone::resizeToContents); connect(_logic, &TableZoneLogic::toggleTapped, this, &TableZone::toggleTapped); @@ -51,16 +50,12 @@ QRectF TableZone::boundingRect() const return QRectF(0, 0, width, height); } -void TableZone::setMirrored(bool isMirrored) -{ - mirrored = isMirrored; - update(); -} - bool TableZone::isInverted() const { - return ((mirrored && !SettingsCache::instance().getInvertVerticalCoordinate()) || - (!mirrored && SettingsCache::instance().getInvertVerticalCoordinate())); + return ((getLogic()->getPlayer()->getGraphicsItem()->getMirrored() && + !SettingsCache::instance().getInvertVerticalCoordinate()) || + (!getLogic()->getPlayer()->getGraphicsItem()->getMirrored() && + SettingsCache::instance().getInvertVerticalCoordinate())); } void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) diff --git a/cockatrice/src/game_graphics/zones/table_zone.h b/cockatrice/src/game_graphics/zones/table_zone.h index 8a898173b..f46531520 100644 --- a/cockatrice/src/game_graphics/zones/table_zone.h +++ b/cockatrice/src/game_graphics/zones/table_zone.h @@ -82,7 +82,6 @@ private: If this TableZone is currently active */ bool active = false; - bool mirrored = false; [[nodiscard]] bool isInverted() const; @@ -97,7 +96,6 @@ public slots: Reorganizes CardItems in the TableZone */ void reorganizeCards() override; - void setMirrored(bool isMirrored); public: /** @@ -106,7 +104,7 @@ public: @param _p the Player @param parent defaults to null */ - explicit TableZone(TableZoneLogic *_logic, bool mirrored, QGraphicsItem *parent = nullptr); + explicit TableZone(TableZoneLogic *_logic, QGraphicsItem *parent = nullptr); /** @return a QRectF of the TableZone bounding box. diff --git a/cockatrice/src/interface/deck_loader/deck_loader.cpp b/cockatrice/src/interface/deck_loader/deck_loader.cpp index 39a0c1071..e616c5eb5 100644 --- a/cockatrice/src/interface/deck_loader/deck_loader.cpp +++ b/cockatrice/src/interface/deck_loader/deck_loader.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -130,10 +129,7 @@ std::optional DeckLoader::loadFromRemote(const QString &nativeString std::optional DeckLoader::saveToFile(const DeckList &deck, const QString &fileName, DeckFileFormat::Format fmt) { - // Use QSaveFile so that a failed write (e.g. a full disk) leaves the existing deck untouched - // instead of truncating it to a 0-byte file. The target is only replaced once every byte has - // been flushed successfully in commit(). - QSaveFile file(fileName); + QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qCWarning(DeckLoaderLog) << "Could not create or open file:" << fileName; return std::nullopt; @@ -149,19 +145,15 @@ DeckLoader::saveToFile(const DeckList &deck, const QString &fileName, DeckFileFo break; } + file.flush(); + file.close(); + + qCInfo(DeckLoaderLog) << "Saved deck to " << fileName << "with format" << fmt << "-" << success; + if (!success) { - file.cancelWriting(); - qCWarning(DeckLoaderLog) << "Failed to serialize deck for file:" << fileName; return std::nullopt; } - if (!file.commit()) { - qCWarning(DeckLoaderLog) << "Failed to save deck to " << fileName << ":" << file.errorString(); - return std::nullopt; - } - - qCInfo(DeckLoaderLog) << "Saved deck to " << fileName << "with format" << fmt; - LoadedDeck::LoadInfo lastLoadInfo = {fileName, fmt}; return lastLoadInfo; } @@ -204,44 +196,38 @@ bool DeckLoader::updateLastLoadedTimestamp(LoadedDeck &deck) QDateTime originalTimestamp = fileInfo.lastModified(); - // Use QSaveFile so that a failed write (e.g. a full disk) cannot truncate an existing deck to a - // 0-byte file while merely bumping its timestamp. - QSaveFile file(fileName); + // Open the file for writing + QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qCWarning(DeckLoaderLog) << "Failed to open file for writing:" << fileName; return false; } + bool result = false; + // Perform file modifications deck.deckList.setLastLoadedTimestamp(QDateTime::currentDateTime().toString()); + result = deck.deckList.saveToFile_Native(&file); - if (!deck.deckList.saveToFile_Native(&file)) { - file.cancelWriting(); - qCWarning(DeckLoaderLog) << "Failed to serialize deck for file:" << fileName; - return false; + file.close(); // Close the file to ensure changes are flushed + + if (result) { + // Re-open the file and set the original timestamp + if (!file.open(QIODevice::ReadWrite)) { + qCWarning(DeckLoaderLog) << "Failed to re-open file to set timestamp:" << fileName; + return false; + } + + if (!file.setFileTime(originalTimestamp, QFileDevice::FileModificationTime)) { + qCWarning(DeckLoaderLog) << "Failed to set modification time for file:" << fileName; + file.close(); + return false; + } + + file.close(); } - if (!file.commit()) { - qCWarning(DeckLoaderLog) << "Failed to update timestamp for file:" << fileName << ":" << file.errorString(); - return false; - } - - // Re-open the file and restore the original timestamp, so that updating the lastLoadedTimestamp - // does not change the file's modification time. - QFile timestampFile(fileName); - if (!timestampFile.open(QIODevice::ReadWrite)) { - qCWarning(DeckLoaderLog) << "Failed to re-open file to set timestamp:" << fileName; - return false; - } - - if (!timestampFile.setFileTime(originalTimestamp, QFileDevice::FileModificationTime)) { - qCWarning(DeckLoaderLog) << "Failed to set modification time for file:" << fileName; - timestampFile.close(); - return false; - } - - timestampFile.close(); - return true; + return result; } static QString getDomainForWebsite(DeckLoader::DecklistWebsite website) @@ -458,54 +444,51 @@ bool DeckLoader::convertToCockatriceFormat(LoadedDeck &deck) return false; } - // Determine the format before touching any file, so an already-converted or - // unsupported deck never truncates or deletes anything. - switch (DeckFileFormat::getFormatFromName(fileName)) { - case DeckFileFormat::PlainText: - break; - case DeckFileFormat::Cockatrice: - qCInfo(DeckLoaderLog) << "File is already in Cockatrice format. No conversion needed."; - return true; - default: - qCWarning(DeckLoaderLog) << "Unsupported file format for conversion:" << fileName; - return false; - } - // Change the file extension to .cod QFileInfo fileInfo(fileName); QString newFileName = QDir::toNativeSeparators(fileInfo.path() + "/" + fileInfo.completeBaseName() + ".cod"); - // Use QSaveFile so a failed write (e.g. a full disk) cannot leave a 0-byte .cod - // behind and then delete the original deck. - QSaveFile file(newFileName); + // Open the new file for writing + QFile file(newFileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { qCWarning(DeckLoaderLog) << "Failed to open file for writing:" << newFileName; return false; } - if (!deck.deckList.saveToFile_Native(&file)) { - file.cancelWriting(); - qCWarning(DeckLoaderLog) << "Failed to serialize deck for file:" << newFileName; - return false; + bool result = false; + + // Perform file modifications based on the detected format + switch (DeckFileFormat::getFormatFromName(fileName)) { + case DeckFileFormat::PlainText: + // Save in Cockatrice's native format + result = deck.deckList.saveToFile_Native(&file); + break; + case DeckFileFormat::Cockatrice: + qCInfo(DeckLoaderLog) << "File is already in Cockatrice format. No conversion needed."; + result = true; + break; + default: + qCWarning(DeckLoaderLog) << "Unsupported file format for conversion:" << fileName; + result = false; + break; } - if (!file.commit()) { - qCWarning(DeckLoaderLog) << "Failed to convert deck to " << newFileName << ":" << file.errorString(); - return false; + file.close(); + + // Delete the old file if conversion was successful + if (result) { + if (!QFile::remove(fileName)) { + qCWarning(DeckLoaderLog) << "Failed to delete original file:" << fileName; + } else { + qCInfo(DeckLoaderLog) << "Original file deleted successfully:" << fileName; + } + deck.lastLoadInfo = { + .fileName = newFileName, + .fileFormat = DeckFileFormat::Cockatrice, + }; } - // Conversion succeeded: delete the original file. - if (!QFile::remove(fileName)) { - qCWarning(DeckLoaderLog) << "Failed to delete original file:" << fileName; - } else { - qCInfo(DeckLoaderLog) << "Original file deleted successfully:" << fileName; - } - deck.lastLoadInfo = { - .fileName = newFileName, - .fileFormat = DeckFileFormat::Cockatrice, - }; - - return true; + return result; } void DeckLoader::printDeckListNode(QTextCursor *cursor, const InnerDecklistNode *node) diff --git a/cockatrice/src/interface/widgets/tabs/tab_game.cpp b/cockatrice/src/interface/widgets/tabs/tab_game.cpp index 1e2bebd15..c52f73319 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_game.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_game.cpp @@ -1,7 +1,6 @@ #include "tab_game.h" #include "../../../client/settings/cache_settings.h" -#include "../../../game/player/menu/card_menu.h" #include "../game/board/arrow_item.h" #include "../game/board/card_item.h" #include "../game/deckview/deck_view_container.h" @@ -364,10 +363,11 @@ void TabGame::retranslateUi() cardInfoFrameWidget->retranslateUi(); - for (auto playerView : scene->getPlayers().values()) { - playerView->retranslateUi(); - } + QMapIterator i(game->getPlayerManager()->getPlayers()); + while (i.hasNext()) { + i.next().value()->getGraphicsItem()->retranslateUi(); + } QMapIterator j(deckViewContainers); while (j.hasNext()) { j.next().value()->playerDeckView->retranslateUi(); @@ -654,12 +654,8 @@ PlayerLogic *TabGame::addPlayer(PlayerLogic *newPlayer) scene->addPlayer(newPlayer); - auto *view = scene->viewForPlayer(newPlayer->getPlayerInfo()->getId()); - connect(newPlayer, &PlayerLogic::newCardAdded, this, &TabGame::newCardAdded); - connect(newPlayer, &PlayerLogic::openDeckEditor, this, &TabGame::openDeckEditor); - connect(view->getPlayerMenu(), &PlayerMenu::cardMenuUpdated, this, &TabGame::setCardMenu); - connect(view, &PlayerGraphicsItem::cardInfoRequested, this, &TabGame::viewCardInfo); + connect(newPlayer->getPlayerMenu(), &PlayerMenu::cardMenuUpdated, this, &TabGame::setCardMenu); messageLog->connectToPlayerEventHandler(newPlayer->getPlayerEventHandler()); @@ -672,7 +668,7 @@ PlayerLogic *TabGame::addPlayer(PlayerLogic *newPlayer) addLocalPlayer(newPlayer, newPlayer->getPlayerInfo()->getId()); } - gameMenu->insertMenu(playersSeparator, view->getPlayerMenu()->getPlayerMenu()); + gameMenu->insertMenu(playersSeparator, newPlayer->getPlayerMenu()->getPlayerMenu()); createZoneForPlayer(newPlayer, newPlayer->getPlayerInfo()->getId()); @@ -682,7 +678,7 @@ PlayerLogic *TabGame::addPlayer(PlayerLogic *newPlayer) void TabGame::addLocalPlayer(PlayerLogic *newPlayer, int playerId) { if (game->getGameState()->getClients().size() == 1) { - scene->viewForPlayer(playerId)->getPlayerMenu()->setShortcutsActive(); + newPlayer->getPlayerMenu()->setShortcutsActive(); } auto *deckView = new TabbedDeckViewContainer(playerId, this); @@ -702,24 +698,27 @@ void TabGame::addLocalPlayer(PlayerLogic *newPlayer, int playerId) void TabGame::processPlayerLeave(PlayerLogic *leavingPlayer) { - removePlayerFromAutoCompleteList("@" + leavingPlayer->getPlayerInfo()->getName()); + QString playerName = "@" + leavingPlayer->getPlayerInfo()->getName(); + removePlayerFromAutoCompleteList(playerName); + + scene->removePlayer(leavingPlayer); // When we inserted the playerMenu into the gameMenu earlier, Qt wrapped the playerMenu into a QAction*, which lives // independently and does not get cleaned up when the source menu gets destroyed. We have to manually clean here. - auto *view = scene->viewForPlayer(leavingPlayer->getPlayerInfo()->getId()); - if (view) { - // Find and remove the QAction pointing to this menu - QMenu *menu = view->getPlayerMenu()->getPlayerMenu(); - for (QAction *act : gameMenu->actions()) { - if (act->menu() == menu) { - gameMenu->removeAction(act); - delete act; - break; + if (leavingPlayer->getPlayerMenu()) { + QMenu *menu = leavingPlayer->getPlayerMenu()->getPlayerMenu(); + if (menu) { + // Find and remove the QAction pointing to this menu + QList actions = gameMenu->actions(); + for (QAction *act : actions) { + if (act->menu() == menu) { + gameMenu->removeAction(act); + delete act; // deletes the QAction wrapper around the submenu + break; + } } } } - - scene->removePlayer(leavingPlayer); } void TabGame::processRemotePlayerDeckSelect(QString deckList, int playerId, QString playerName) @@ -870,12 +869,12 @@ PlayerLogic *TabGame::setActivePlayer(int id) if (i.value() == player) { i.value()->setActive(true); if (game->getGameState()->getClients().size() > 1) { - scene->viewForPlayer(i.value()->getPlayerInfo()->getId())->getPlayerMenu()->setShortcutsActive(); + i.value()->getPlayerMenu()->setShortcutsActive(); } } else { i.value()->setActive(false); if (game->getGameState()->getClients().size() > 1) { - scene->viewForPlayer(i.value()->getPlayerInfo()->getId())->getPlayerMenu()->setShortcutsInactive(); + i.value()->getPlayerMenu()->setShortcutsInactive(); } } } @@ -891,13 +890,8 @@ void TabGame::setActivePhase(int phase) void TabGame::newCardAdded(AbstractCardItem *card) { - connect(card, &AbstractCardItem::rightClicked, scene, &GameScene::onCardRightClicked); - connect(card, &AbstractCardItem::playSelected, scene, &GameScene::playSelected); - connect(card, &AbstractCardItem::playSelectedFaceDown, scene, &GameScene::playSelectedFaceDown); - connect(card, &AbstractCardItem::hideSelected, scene, &GameScene::hideSelected); connect(card, &AbstractCardItem::hovered, cardInfoFrameWidget, qOverload(&CardInfoFrameWidget::setCard)); - connect(card, &AbstractCardItem::selectionChanged, scene, &GameScene::onCardSelectionChanged); connect(card, &AbstractCardItem::showCardInfoPopup, this, &TabGame::showCardInfoPopup); connect(card, SIGNAL(deleteCardInfoPopup(QString)), this, SLOT(deleteCardInfoPopup(QString))); connect(card, &AbstractCardItem::cardShiftClicked, this, &TabGame::linkCardToChat); @@ -941,7 +935,7 @@ QString TabGame::getTabText() const /** * @param menu The menu to set. Pass in nullptr to set the menu to empty. */ -void TabGame::setCardMenu(CardMenu *menu) +void TabGame::setCardMenu(QMenu *menu) { if (!aCardMenu) { return; diff --git a/cockatrice/src/interface/widgets/tabs/tab_game.h b/cockatrice/src/interface/widgets/tabs/tab_game.h index ddda4d9b9..7f9392034 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_game.h +++ b/cockatrice/src/interface/widgets/tabs/tab_game.h @@ -141,7 +141,7 @@ signals: private slots: void adminLockChanged(bool lock); void newCardAdded(AbstractCardItem *card); - void setCardMenu(CardMenu *menu); + void setCardMenu(QMenu *menu); void actGameInfo(); void actConcede();