diff --git a/cockatrice/src/game/game_scene.cpp b/cockatrice/src/game/game_scene.cpp index 9f466c2ac..d9ffe3443 100644 --- a/cockatrice/src/game/game_scene.cpp +++ b/cockatrice/src/game/game_scene.cpp @@ -88,16 +88,16 @@ void GameScene::addPlayer(PlayerLogic *player) connect(player, &PlayerLogic::concededChanged, this, [this](int id, bool conceded) { if (conceded) { - clearArrowsForPlayer(id); + requestClearArrowsForPlayer(id); } rearrange(); }); - connect(player, &PlayerLogic::arrowDeleted, this, &GameScene::onArrowDeleted); - connect(player, &PlayerLogic::arrowCreateRequested, this, &GameScene::onArrowCreateRequested); - connect(player, &PlayerLogic::arrowDeleteRequested, this, &GameScene::onArrowDeleteRequested); + connect(player, &PlayerLogic::arrowDeleted, this, &GameScene::deleteArrow); + connect(player, &PlayerLogic::arrowCreateRequested, this, &GameScene::addArrow); + connect(player, &PlayerLogic::arrowDeleteRequested, this, &GameScene::requestArrowDeletion); connect(player, &PlayerLogic::arrowsCleared, this, - [this, id = player->getPlayerInfo()->getId()]() { clearArrowsForPlayer(id); }); + [this, id = player->getPlayerInfo()->getId()]() { requestClearArrowsForPlayer(id); }); connect(player->getPlayerEventHandler(), &PlayerEventHandler::cardZoneChanged, this, &GameScene::onCardZoneChanged); @@ -114,7 +114,7 @@ void GameScene::removePlayer(PlayerLogic *player) { qCInfo(GameScenePlayerAdditionRemovalLog) << "GameScene::removePlayer name=" << player->getPlayerInfo()->getName(); - clearArrowsForPlayer(player->getPlayerInfo()->getId()); + requestClearArrowsForPlayer(player->getPlayerInfo()->getId()); for (ZoneViewWidget *zone : zoneViews) { if (zone->getPlayer() == player) { @@ -367,7 +367,7 @@ void GameScene::resizeColumnsAndPlayers(const QList &minWidthByColumn, qr } } -void GameScene::onArrowCreateRequested(const ArrowData &data) +void GameScene::addArrow(const ArrowData &data) { auto *startView = playerViews.value(data.startPlayerId); auto *targetView = playerViews.value(data.targetPlayerId); @@ -402,20 +402,29 @@ void GameScene::onArrowCreateRequested(const ArrowData &data) auto *arrow = new ArrowItem(startView->getPlayer(), data.id, startCard, targetItem, data.color); addItem(arrow); arrowRegistry.insert(data.id, arrow); - connect(arrow, &ArrowItem::requestDeletion, this, &GameScene::onArrowDeleteRequested); + connect(arrow, &ArrowItem::requestDeletion, this, &GameScene::requestArrowDeletion); } -void GameScene::onArrowDeleted(int arrowId) +void GameScene::deleteArrow(int arrowId) { if (arrowRegistry.contains(arrowId)) { arrowRegistry.take(arrowId)->delArrow(); } } -void GameScene::onArrowDeleteRequested(int arrowId) +void GameScene::requestArrowDeletion(int arrowId) { if (arrowRegistry.contains(arrowId)) { - emit requestArrowDeletion(arrowId); + emit arrowDeletionRequested(arrowId); + } +} + +void GameScene::requestClearArrowsForPlayer(int playerId) +{ + for (auto *arrow : arrowRegistry.values()) { + if (arrow->getPlayer()->getPlayerInfo()->getId() == playerId) { + emit requestArrowDeletion(arrow->getId()); + } } } @@ -432,16 +441,7 @@ void GameScene::onCardZoneChanged(CardItem *card, bool sameZone) } } for (auto *arrow : toDelete) { - onArrowDeleted(arrow->getId()); - } -} - -void GameScene::clearArrowsForPlayer(int playerId) -{ - for (auto *arrow : arrowRegistry.values()) { - if (arrow->getPlayer()->getPlayerInfo()->getId() == playerId) { - emit requestArrowDeletion(arrow->getId()); - } + deleteArrow(arrow->getId()); } } diff --git a/cockatrice/src/game/game_scene.h b/cockatrice/src/game/game_scene.h index 235ce6550..70dbfb3d9 100644 --- a/cockatrice/src/game/game_scene.h +++ b/cockatrice/src/game/game_scene.h @@ -201,11 +201,15 @@ public slots: QTransform getViewTransform() const; QTransform getViewportTransform() const; - void onArrowCreateRequested(const ArrowData &data); - void onArrowDeleted(int arrowId); - void onArrowDeleteRequested(int arrowId); + /// Directly modifies the scene + void addArrow(const ArrowData &data); + void deleteArrow(int arrowId); + + /// Queues up arrow deletion but doesn't directly modify the scene + void requestArrowDeletion(int arrowId); + void requestClearArrowsForPlayer(int playerId); + void onCardZoneChanged(CardItem *card, bool sameZone); - void clearArrowsForPlayer(int playerId); protected: /** @brief Handles hover updates. */ @@ -218,7 +222,7 @@ signals: void sigStartRubberBand(const QPointF &selectionOrigin); void sigResizeRubberBand(const QPointF &cursorPoint, int selectedCount); void sigStopRubberBand(); - void requestArrowDeletion(int arrowId); + void arrowDeletionRequested(int arrowId); }; #endif diff --git a/cockatrice/src/interface/widgets/tabs/tab_game.cpp b/cockatrice/src/interface/widgets/tabs/tab_game.cpp index 3da3685dd..9fc123a8c 100644 --- a/cockatrice/src/interface/widgets/tabs/tab_game.cpp +++ b/cockatrice/src/interface/widgets/tabs/tab_game.cpp @@ -608,7 +608,7 @@ void TabGame::actRemoveLocalArrows() { auto *local = game->getPlayerManager()->getActiveLocalPlayer(game->getGameState()->getActivePlayer()); if (local) { - scene->clearArrowsForPlayer(local->getPlayerInfo()->getId()); + scene->requestClearArrowsForPlayer(local->getPlayerInfo()->getId()); } } @@ -1150,9 +1150,9 @@ void TabGame::createPlayAreaWidget(bool bReplay) scene = new GameScene(phasesToolbar, this); connect(game->getPlayerManager(), &PlayerManager::playerConceded, scene, &GameScene::rearrange); connect(game->getPlayerManager(), &PlayerManager::playerCountChanged, scene, &GameScene::rearrange); - connect(scene, &GameScene::requestArrowDeletion, game->getGameEventHandler(), + connect(scene, &GameScene::arrowDeletionRequested, game->getGameEventHandler(), &GameEventHandler::handleArrowDeletion); - connect(game->getGameEventHandler(), &GameEventHandler::arrowDeleted, scene, &GameScene::onArrowDeleted); + connect(game->getGameEventHandler(), &GameEventHandler::arrowDeleted, scene, &GameScene::deleteArrow); gameView = new GameView(scene); auto gamePlayAreaVBox = new QVBoxLayout;