diff --git a/cockatrice/src/gamescene.cpp b/cockatrice/src/gamescene.cpp index e2684480..23057db3 100644 --- a/cockatrice/src/gamescene.cpp +++ b/cockatrice/src/gamescene.cpp @@ -11,9 +11,13 @@ #include #include #include +#include GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent) - : QGraphicsScene(parent), phasesToolbar(_phasesToolbar), viewSize(QSize()) + : QGraphicsScene(parent), + phasesToolbar(_phasesToolbar), + viewSize(QSize()), + playerRotation(0) { animationTimer = new QBasicTimer; addItem(phasesToolbar); @@ -35,7 +39,7 @@ void GameScene::retranslateUi() void GameScene::addPlayer(Player *player) { - qDebug("GameScene::addPlayer"); + qDebug() << "GameScene::addPlayer name=" << player->getName(); players << player; addItem(player); connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange())); @@ -44,39 +48,63 @@ void GameScene::addPlayer(Player *player) void GameScene::removePlayer(Player *player) { - qDebug("GameScene::removePlayer"); + qDebug() << "GameScene::removePlayer name=" << player->getName(); players.removeAt(players.indexOf(player)); removeItem(player); rearrange(); } +void GameScene::adjustPlayerRotation(int rotationAdjustment) +{ + playerRotation += rotationAdjustment; + rearrange(); +} + void GameScene::rearrange() { playersByColumn.clear(); + // Create the list of players playing, noting the first player's index. QList playersPlaying; - int firstPlayer = -1; - for (int i = 0; i < players.size(); ++i) - if (!players[i]->getConceded()) { - playersPlaying.append(players[i]); - if ((firstPlayer == -1) && (players[i]->getLocal())) - firstPlayer = playersPlaying.size() - 1; + int firstPlayerIndex = 0; + bool firstPlayerFound = false; + QListIterator playersIter(players); + while (playersIter.hasNext()) { + Player *p = playersIter.next(); + if (!p->getConceded()) { + playersPlaying.append(p); + if (!firstPlayerFound && (p->getLocal())) { + firstPlayerIndex = playersPlaying.size() - 1; + firstPlayerFound = true; + } } - if (firstPlayer == -1) - firstPlayer = 0; + } + + // Rotate the players playing list so that first player is first, then + // adjust by the additional rotation setting. + if (!playersPlaying.isEmpty()) { + int totalRotation = firstPlayerIndex + playerRotation; + while (totalRotation < 0) + totalRotation += playersPlaying.size(); + for (int i = 0; i < totalRotation; ++i) { + playersPlaying.append(playersPlaying.takeFirst()); + } + } + const int playersCount = playersPlaying.size(); const int columns = playersCount < settingsCache->getMinPlayersForMultiColumnLayout() ? 1 : 2; const int rows = ceil((qreal) playersCount / columns); qreal sceneHeight = 0, sceneWidth = -playerAreaSpacing; QList columnWidth; - int firstPlayerOfColumn = firstPlayer; + + QListIterator playersPlayingIter(playersPlaying); for (int col = 0; col < columns; ++col) { playersByColumn.append(QList()); columnWidth.append(0); qreal thisColumnHeight = -playerAreaSpacing; const int rowsInColumn = rows - (playersCount % columns) * col; // only correct for max. 2 cols for (int j = 0; j < rowsInColumn; ++j) { - Player *player = playersPlaying[(firstPlayerOfColumn + j) % playersCount]; + Player *player = playersPlayingIter.next(); if (col == 0) playersByColumn[col].prepend(player); else @@ -88,8 +116,6 @@ void GameScene::rearrange() if (thisColumnHeight > sceneHeight) sceneHeight = thisColumnHeight; sceneWidth += columnWidth[col] + playerAreaSpacing; - - firstPlayerOfColumn += rowsInColumn; } phasesToolbar->setHeight(sceneHeight); diff --git a/cockatrice/src/gamescene.h b/cockatrice/src/gamescene.h index b542f0ec..6ac014cd 100644 --- a/cockatrice/src/gamescene.h +++ b/cockatrice/src/gamescene.h @@ -28,6 +28,7 @@ private: QPointer hoveredCard; QBasicTimer *animationTimer; QSet cardsToAnimate; + int playerRotation; void updateHover(const QPointF &scenePos); public: GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = 0); @@ -51,6 +52,7 @@ public slots: void removePlayer(Player *player); void clearViews(); void closeMostRecentZoneView(); + void adjustPlayerRotation(int rotationAdjustment); void rearrange(); protected: bool event(QEvent *event); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 828f6674..ef51d82a 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -345,6 +345,8 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay) aNextPhase = 0; aNextTurn = 0; aRemoveLocalArrows = 0; + aRotateViewCW = 0; + aRotateViewCCW = 0; aGameInfo = 0; aConcede = 0; aLeaveGame = 0; @@ -450,6 +452,10 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_client connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn())); aRemoveLocalArrows = new QAction(this); connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows())); + aRotateViewCW = new QAction(this); + connect(aRotateViewCW, SIGNAL(triggered()), this, SLOT(actRotateViewCW())); + aRotateViewCCW = new QAction(this); + connect(aRotateViewCCW, SIGNAL(triggered()), this, SLOT(actRotateViewCCW())); aGameInfo = new QAction(this); connect(aGameInfo, SIGNAL(triggered()), this, SLOT(actGameInfo())); aConcede = new QAction(this); @@ -483,6 +489,8 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_client gameMenu->addAction(aNextTurn); gameMenu->addSeparator(); gameMenu->addAction(aRemoveLocalArrows); + gameMenu->addAction(aRotateViewCW); + gameMenu->addAction(aRotateViewCCW); gameMenu->addSeparator(); gameMenu->addAction(aGameInfo); gameMenu->addAction(aConcede); @@ -547,6 +555,14 @@ void TabGame::retranslateUi() aRemoveLocalArrows->setText(tr("&Remove all local arrows")); aRemoveLocalArrows->setShortcut(QKeySequence("Ctrl+R")); } + if (aRotateViewCW) { + aRotateViewCW->setText(tr("Rotate View Cl&ockwise")); + aRotateViewCW->setShortcut(QKeySequence("Ctrl+]")); + } + if (aRotateViewCCW) { + aRotateViewCCW->setText(tr("Rotate View Co&unterclockwise")); + aRotateViewCCW->setShortcut(QKeySequence("Ctrl+[")); + } if (aGameInfo) aGameInfo->setText(tr("Game &information")); if (aConcede) { @@ -713,6 +729,16 @@ void TabGame::actRemoveLocalArrows() } } +void TabGame::actRotateViewCW() +{ + scene->adjustPlayerRotation(-1); +} + +void TabGame::actRotateViewCCW() +{ + scene->adjustPlayerRotation(1); +} + Player *TabGame::addPlayer(int playerId, const ServerInfo_User &info) { bool local = ((clients.size() > 1) || (playerId == localPlayerId)); diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index d6a18c0c..e704b569 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -141,7 +141,7 @@ private: QAction *playersSeparator; QMenu *gameMenu; QMenu *phasesMenu; - QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; + QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows, *aRotateViewCW, *aRotateViewCCW; QList phaseActions; Player *addPlayer(int playerId, const ServerInfo_User &info); @@ -190,6 +190,8 @@ private slots: void actConcede(); void actLeaveGame(); void actRemoveLocalArrows(); + void actRotateViewCW(); + void actRotateViewCCW(); void actSay(); void actPhaseAction(); void actNextPhase();