Merge pull request #1179 from mildmongrel/feature-player-rotation
Added ability to rotate player positions in the local game view.
This commit is contained in:
commit
f733daf18a
4 changed files with 72 additions and 16 deletions
|
@ -11,9 +11,13 @@
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QBasicTimer>
|
#include <QBasicTimer>
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
|
GameScene::GameScene(PhasesToolbar *_phasesToolbar, QObject *parent)
|
||||||
: QGraphicsScene(parent), phasesToolbar(_phasesToolbar), viewSize(QSize())
|
: QGraphicsScene(parent),
|
||||||
|
phasesToolbar(_phasesToolbar),
|
||||||
|
viewSize(QSize()),
|
||||||
|
playerRotation(0)
|
||||||
{
|
{
|
||||||
animationTimer = new QBasicTimer;
|
animationTimer = new QBasicTimer;
|
||||||
addItem(phasesToolbar);
|
addItem(phasesToolbar);
|
||||||
|
@ -35,7 +39,7 @@ void GameScene::retranslateUi()
|
||||||
|
|
||||||
void GameScene::addPlayer(Player *player)
|
void GameScene::addPlayer(Player *player)
|
||||||
{
|
{
|
||||||
qDebug("GameScene::addPlayer");
|
qDebug() << "GameScene::addPlayer name=" << player->getName();
|
||||||
players << player;
|
players << player;
|
||||||
addItem(player);
|
addItem(player);
|
||||||
connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
||||||
|
@ -44,39 +48,63 @@ void GameScene::addPlayer(Player *player)
|
||||||
|
|
||||||
void GameScene::removePlayer(Player *player)
|
void GameScene::removePlayer(Player *player)
|
||||||
{
|
{
|
||||||
qDebug("GameScene::removePlayer");
|
qDebug() << "GameScene::removePlayer name=" << player->getName();
|
||||||
players.removeAt(players.indexOf(player));
|
players.removeAt(players.indexOf(player));
|
||||||
removeItem(player);
|
removeItem(player);
|
||||||
rearrange();
|
rearrange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameScene::adjustPlayerRotation(int rotationAdjustment)
|
||||||
|
{
|
||||||
|
playerRotation += rotationAdjustment;
|
||||||
|
rearrange();
|
||||||
|
}
|
||||||
|
|
||||||
void GameScene::rearrange()
|
void GameScene::rearrange()
|
||||||
{
|
{
|
||||||
playersByColumn.clear();
|
playersByColumn.clear();
|
||||||
|
|
||||||
|
// Create the list of players playing, noting the first player's index.
|
||||||
QList<Player *> playersPlaying;
|
QList<Player *> playersPlaying;
|
||||||
int firstPlayer = -1;
|
int firstPlayerIndex = 0;
|
||||||
for (int i = 0; i < players.size(); ++i)
|
bool firstPlayerFound = false;
|
||||||
if (!players[i]->getConceded()) {
|
QListIterator<Player *> playersIter(players);
|
||||||
playersPlaying.append(players[i]);
|
while (playersIter.hasNext()) {
|
||||||
if ((firstPlayer == -1) && (players[i]->getLocal()))
|
Player *p = playersIter.next();
|
||||||
firstPlayer = playersPlaying.size() - 1;
|
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 playersCount = playersPlaying.size();
|
||||||
const int columns = playersCount < settingsCache->getMinPlayersForMultiColumnLayout() ? 1 : 2;
|
const int columns = playersCount < settingsCache->getMinPlayersForMultiColumnLayout() ? 1 : 2;
|
||||||
const int rows = ceil((qreal) playersCount / columns);
|
const int rows = ceil((qreal) playersCount / columns);
|
||||||
qreal sceneHeight = 0, sceneWidth = -playerAreaSpacing;
|
qreal sceneHeight = 0, sceneWidth = -playerAreaSpacing;
|
||||||
QList<int> columnWidth;
|
QList<int> columnWidth;
|
||||||
int firstPlayerOfColumn = firstPlayer;
|
|
||||||
|
QListIterator<Player *> playersPlayingIter(playersPlaying);
|
||||||
for (int col = 0; col < columns; ++col) {
|
for (int col = 0; col < columns; ++col) {
|
||||||
playersByColumn.append(QList<Player *>());
|
playersByColumn.append(QList<Player *>());
|
||||||
columnWidth.append(0);
|
columnWidth.append(0);
|
||||||
qreal thisColumnHeight = -playerAreaSpacing;
|
qreal thisColumnHeight = -playerAreaSpacing;
|
||||||
const int rowsInColumn = rows - (playersCount % columns) * col; // only correct for max. 2 cols
|
const int rowsInColumn = rows - (playersCount % columns) * col; // only correct for max. 2 cols
|
||||||
for (int j = 0; j < rowsInColumn; ++j) {
|
for (int j = 0; j < rowsInColumn; ++j) {
|
||||||
Player *player = playersPlaying[(firstPlayerOfColumn + j) % playersCount];
|
Player *player = playersPlayingIter.next();
|
||||||
if (col == 0)
|
if (col == 0)
|
||||||
playersByColumn[col].prepend(player);
|
playersByColumn[col].prepend(player);
|
||||||
else
|
else
|
||||||
|
@ -88,8 +116,6 @@ void GameScene::rearrange()
|
||||||
if (thisColumnHeight > sceneHeight)
|
if (thisColumnHeight > sceneHeight)
|
||||||
sceneHeight = thisColumnHeight;
|
sceneHeight = thisColumnHeight;
|
||||||
sceneWidth += columnWidth[col] + playerAreaSpacing;
|
sceneWidth += columnWidth[col] + playerAreaSpacing;
|
||||||
|
|
||||||
firstPlayerOfColumn += rowsInColumn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
phasesToolbar->setHeight(sceneHeight);
|
phasesToolbar->setHeight(sceneHeight);
|
||||||
|
|
|
@ -28,6 +28,7 @@ private:
|
||||||
QPointer<CardItem> hoveredCard;
|
QPointer<CardItem> hoveredCard;
|
||||||
QBasicTimer *animationTimer;
|
QBasicTimer *animationTimer;
|
||||||
QSet<CardItem *> cardsToAnimate;
|
QSet<CardItem *> cardsToAnimate;
|
||||||
|
int playerRotation;
|
||||||
void updateHover(const QPointF &scenePos);
|
void updateHover(const QPointF &scenePos);
|
||||||
public:
|
public:
|
||||||
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = 0);
|
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = 0);
|
||||||
|
@ -51,6 +52,7 @@ public slots:
|
||||||
void removePlayer(Player *player);
|
void removePlayer(Player *player);
|
||||||
void clearViews();
|
void clearViews();
|
||||||
void closeMostRecentZoneView();
|
void closeMostRecentZoneView();
|
||||||
|
void adjustPlayerRotation(int rotationAdjustment);
|
||||||
void rearrange();
|
void rearrange();
|
||||||
protected:
|
protected:
|
||||||
bool event(QEvent *event);
|
bool event(QEvent *event);
|
||||||
|
|
|
@ -345,6 +345,8 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, GameReplay *_replay)
|
||||||
aNextPhase = 0;
|
aNextPhase = 0;
|
||||||
aNextTurn = 0;
|
aNextTurn = 0;
|
||||||
aRemoveLocalArrows = 0;
|
aRemoveLocalArrows = 0;
|
||||||
|
aRotateViewCW = 0;
|
||||||
|
aRotateViewCCW = 0;
|
||||||
aGameInfo = 0;
|
aGameInfo = 0;
|
||||||
aConcede = 0;
|
aConcede = 0;
|
||||||
aLeaveGame = 0;
|
aLeaveGame = 0;
|
||||||
|
@ -450,6 +452,10 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
|
||||||
connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn()));
|
connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn()));
|
||||||
aRemoveLocalArrows = new QAction(this);
|
aRemoveLocalArrows = new QAction(this);
|
||||||
connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows()));
|
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);
|
aGameInfo = new QAction(this);
|
||||||
connect(aGameInfo, SIGNAL(triggered()), this, SLOT(actGameInfo()));
|
connect(aGameInfo, SIGNAL(triggered()), this, SLOT(actGameInfo()));
|
||||||
aConcede = new QAction(this);
|
aConcede = new QAction(this);
|
||||||
|
@ -483,6 +489,8 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList<AbstractClient *> &_client
|
||||||
gameMenu->addAction(aNextTurn);
|
gameMenu->addAction(aNextTurn);
|
||||||
gameMenu->addSeparator();
|
gameMenu->addSeparator();
|
||||||
gameMenu->addAction(aRemoveLocalArrows);
|
gameMenu->addAction(aRemoveLocalArrows);
|
||||||
|
gameMenu->addAction(aRotateViewCW);
|
||||||
|
gameMenu->addAction(aRotateViewCCW);
|
||||||
gameMenu->addSeparator();
|
gameMenu->addSeparator();
|
||||||
gameMenu->addAction(aGameInfo);
|
gameMenu->addAction(aGameInfo);
|
||||||
gameMenu->addAction(aConcede);
|
gameMenu->addAction(aConcede);
|
||||||
|
@ -547,6 +555,14 @@ void TabGame::retranslateUi()
|
||||||
aRemoveLocalArrows->setText(tr("&Remove all local arrows"));
|
aRemoveLocalArrows->setText(tr("&Remove all local arrows"));
|
||||||
aRemoveLocalArrows->setShortcut(QKeySequence("Ctrl+R"));
|
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)
|
if (aGameInfo)
|
||||||
aGameInfo->setText(tr("Game &information"));
|
aGameInfo->setText(tr("Game &information"));
|
||||||
if (aConcede) {
|
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)
|
Player *TabGame::addPlayer(int playerId, const ServerInfo_User &info)
|
||||||
{
|
{
|
||||||
bool local = ((clients.size() > 1) || (playerId == localPlayerId));
|
bool local = ((clients.size() > 1) || (playerId == localPlayerId));
|
||||||
|
|
|
@ -141,7 +141,7 @@ private:
|
||||||
QAction *playersSeparator;
|
QAction *playersSeparator;
|
||||||
QMenu *gameMenu;
|
QMenu *gameMenu;
|
||||||
QMenu *phasesMenu;
|
QMenu *phasesMenu;
|
||||||
QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
|
QAction *aGameInfo, *aConcede, *aLeaveGame, *aCloseReplay, *aNextPhase, *aNextTurn, *aRemoveLocalArrows, *aRotateViewCW, *aRotateViewCCW;
|
||||||
QList<QAction *> phaseActions;
|
QList<QAction *> phaseActions;
|
||||||
|
|
||||||
Player *addPlayer(int playerId, const ServerInfo_User &info);
|
Player *addPlayer(int playerId, const ServerInfo_User &info);
|
||||||
|
@ -190,6 +190,8 @@ private slots:
|
||||||
void actConcede();
|
void actConcede();
|
||||||
void actLeaveGame();
|
void actLeaveGame();
|
||||||
void actRemoveLocalArrows();
|
void actRemoveLocalArrows();
|
||||||
|
void actRotateViewCW();
|
||||||
|
void actRotateViewCCW();
|
||||||
void actSay();
|
void actSay();
|
||||||
void actPhaseAction();
|
void actPhaseAction();
|
||||||
void actNextPhase();
|
void actNextPhase();
|
||||||
|
|
Loading…
Reference in a new issue