Mulligan crash fix, multi-column screen alignment for multiplayer, Server Win32 compile fix
This commit is contained in:
parent
a03bf8884f
commit
1bc05562cc
8 changed files with 93 additions and 57 deletions
|
@ -3,6 +3,7 @@
|
|||
#include "zoneviewwidget.h"
|
||||
#include "zoneviewzone.h"
|
||||
#include "phasestoolbar.h"
|
||||
#include <math.h>
|
||||
#include <QAction>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QSet>
|
||||
|
@ -31,7 +32,6 @@ void GameScene::addPlayer(Player *player)
|
|||
qDebug("GameScene::addPlayer");
|
||||
players << player;
|
||||
addItem(player);
|
||||
rearrange();
|
||||
connect(player, SIGNAL(sizeChanged()), this, SLOT(rearrange()));
|
||||
connect(player, SIGNAL(gameConceded()), this, SLOT(rearrange()));
|
||||
}
|
||||
|
@ -46,44 +46,63 @@ void GameScene::removePlayer(Player *player)
|
|||
|
||||
void GameScene::rearrange()
|
||||
{
|
||||
struct PlayerProcessor {
|
||||
static void processPlayer(Player *p, qreal &w, QPointF &b, bool singlePlayer)
|
||||
{
|
||||
if (p->getConceded())
|
||||
return;
|
||||
|
||||
const QRectF br = p->boundingRect();
|
||||
if (br.width() > w)
|
||||
w = br.width();
|
||||
p->setPos(b);
|
||||
p->setMirrored((b.y() < playerAreaSpacing) && !singlePlayer);
|
||||
b += QPointF(0, br.height() + playerAreaSpacing);
|
||||
}
|
||||
};
|
||||
|
||||
qreal sceneHeight = -playerAreaSpacing;
|
||||
playersByColumn.clear();
|
||||
|
||||
QList<Player *> playersPlaying;
|
||||
int firstPlayer = -1;
|
||||
for (int i = 0; i < players.size(); ++i)
|
||||
if (!players[i]->getConceded())
|
||||
sceneHeight += players[i]->boundingRect().height() + playerAreaSpacing;
|
||||
if (!players[i]->getConceded()) {
|
||||
playersPlaying.append(players[i]);
|
||||
if ((firstPlayer == -1) && (players[i]->getLocal()))
|
||||
firstPlayer = playersPlaying.size() - 1;
|
||||
}
|
||||
if (firstPlayer == -1)
|
||||
firstPlayer = 0;
|
||||
const int playersCount = playersPlaying.size();
|
||||
const int columns = playersCount < 4 ? 1 : 2;
|
||||
const int rows = ceil((qreal) playersCount / columns);
|
||||
|
||||
qreal sceneHeight = 0, sceneWidth = -playerAreaSpacing;
|
||||
QList<int> columnWidth;
|
||||
int firstPlayerOfColumn = firstPlayer;
|
||||
for (int col = 0; col < columns; ++col) {
|
||||
playersByColumn.append(QList<Player *>());
|
||||
columnWidth.append(0);
|
||||
qreal thisColumnHeight = -playerAreaSpacing;
|
||||
const int rowsInColumn = rows - (playersCount % columns);
|
||||
for (int j = 0; j < rowsInColumn; ++j) {
|
||||
Player *player = playersPlaying[(firstPlayerOfColumn + j) % playersCount];
|
||||
if (col == 0)
|
||||
playersByColumn[col].prepend(player);
|
||||
else
|
||||
playersByColumn[col].append(player);
|
||||
thisColumnHeight += player->boundingRect().height() + playerAreaSpacing;
|
||||
if (player->boundingRect().width() > columnWidth[col])
|
||||
columnWidth[col] = player->boundingRect().width();
|
||||
}
|
||||
if (thisColumnHeight > sceneHeight)
|
||||
sceneHeight = thisColumnHeight;
|
||||
sceneWidth += columnWidth[col] + playerAreaSpacing;
|
||||
|
||||
firstPlayerOfColumn += rowsInColumn;
|
||||
}
|
||||
|
||||
phasesToolbar->setHeight(sceneHeight);
|
||||
qreal phasesWidth = phasesToolbar->getWidth();
|
||||
|
||||
QPointF base(phasesWidth, 0);
|
||||
qreal sceneWidth;
|
||||
QList<Player *> localPlayers;
|
||||
|
||||
for (int i = 0; i < players.size(); ++i)
|
||||
if (!players[i]->getLocal())
|
||||
PlayerProcessor::processPlayer(players[i], sceneWidth, base, players.size() == 1);
|
||||
else
|
||||
localPlayers.append(players[i]);
|
||||
|
||||
for (int i = 0; i < localPlayers.size(); ++i)
|
||||
PlayerProcessor::processPlayer(localPlayers[i], sceneWidth, base, players.size() == 1);
|
||||
|
||||
sceneWidth += phasesWidth;
|
||||
playersRect = QRectF(0, 0, sceneWidth, sceneHeight);
|
||||
|
||||
|
||||
qreal x = phasesWidth;
|
||||
for (int col = 0; col < columns; ++col) {
|
||||
qreal y = 0;
|
||||
for (int row = 0; row < playersByColumn[col].size(); ++row) {
|
||||
Player *player = playersByColumn[col][row];
|
||||
player->setPos(x, y);
|
||||
player->setMirrored(row != rows - 1);
|
||||
y += player->boundingRect().height() + playerAreaSpacing;
|
||||
}
|
||||
x += columnWidth[col] + playerAreaSpacing;
|
||||
}
|
||||
|
||||
setSceneRect(sceneRect().x(), sceneRect().y(), sceneWidth, sceneHeight);
|
||||
processViewSizeChange(viewSize);
|
||||
}
|
||||
|
@ -139,24 +158,33 @@ void GameScene::processViewSizeChange(const QSize &newSize)
|
|||
|
||||
qreal newRatio = ((qreal) newSize.width()) / newSize.height();
|
||||
qreal minWidth = 0;
|
||||
for (int i = 0; i < players.size(); ++i) {
|
||||
qreal w = players[i]->getMinimumWidth();
|
||||
if (w > minWidth)
|
||||
minWidth = w;
|
||||
QList<qreal> minWidthByColumn;
|
||||
for (int col = 0; col < playersByColumn.size(); ++col) {
|
||||
minWidthByColumn.append(0);
|
||||
for (int row = 0; row < playersByColumn[col].size(); ++row) {
|
||||
qreal w = playersByColumn[col][row]->getMinimumWidth();
|
||||
if (w > minWidthByColumn[col])
|
||||
minWidthByColumn[col] = w;
|
||||
}
|
||||
minWidth += minWidthByColumn[col];
|
||||
}
|
||||
minWidth += phasesToolbar->getWidth();
|
||||
|
||||
qreal minRatio = minWidth / sceneRect().height();
|
||||
qreal newWidth;
|
||||
if (minRatio > newRatio) {
|
||||
// Aspect ratio is dominated by table width.
|
||||
setSceneRect(0, 0, minWidth, sceneRect().height());
|
||||
newWidth = minWidth;
|
||||
} else {
|
||||
// Aspect ratio is dominated by window dimensions.
|
||||
setSceneRect(0, 0, newRatio * sceneRect().height(), sceneRect().height());
|
||||
newWidth = newRatio * sceneRect().height();
|
||||
}
|
||||
|
||||
for (int i = 0; i < players.size(); ++i)
|
||||
players[i]->processSceneSizeChange(sceneRect().size() - QSizeF(phasesToolbar->getWidth(), 0));
|
||||
setSceneRect(0, 0, newWidth, sceneRect().height());
|
||||
|
||||
qreal extraWidthPerColumn = (newWidth - minWidth) / playersByColumn.size();
|
||||
for (int col = 0; col < playersByColumn.size(); ++col)
|
||||
for (int row = 0; row < playersByColumn[col].size(); ++row)
|
||||
playersByColumn[col][row]->processSceneSizeChange(minWidthByColumn[col] + extraWidthPerColumn);
|
||||
}
|
||||
|
||||
void GameScene::updateHover(const QPointF &scenePos)
|
||||
|
|
|
@ -22,7 +22,7 @@ private:
|
|||
|
||||
PhasesToolbar *phasesToolbar;
|
||||
QList<Player *> players;
|
||||
QRectF playersRect;
|
||||
QList<QList<Player *> > playersByColumn;
|
||||
QList<ZoneViewWidget *> views;
|
||||
QSize viewSize;
|
||||
QPointer<CardItem> hoveredCard;
|
||||
|
@ -33,7 +33,6 @@ public:
|
|||
GameScene(PhasesToolbar *_phasesToolbar, QObject *parent = 0);
|
||||
~GameScene();
|
||||
void retranslateUi();
|
||||
const QRectF &getPlayersRect() const { return playersRect; }
|
||||
void processViewSizeChange(const QSize &newSize);
|
||||
|
||||
void startRubberBand(const QPointF &selectionOrigin);
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "cardinfowidget.h"
|
||||
#include "protocol_items.h"
|
||||
#include "soundengine.h"
|
||||
#include <QDebug>
|
||||
#include <QMouseEvent>
|
||||
#include <QTextBlock>
|
||||
|
||||
|
@ -264,6 +263,9 @@ void MessageLogWidget::logMoveCard(Player *player, CardItem *card, CardZone *sta
|
|||
|
||||
void MessageLogWidget::logMulligan(Player *player, int number)
|
||||
{
|
||||
if (!player)
|
||||
return;
|
||||
|
||||
if (number > -1)
|
||||
append(tr("%1 takes a mulligan to %n.", "", number).arg(sanitizeHtml(player->getName())));
|
||||
else
|
||||
|
@ -468,6 +470,7 @@ void MessageLogWidget::containerProcessingStarted(GameEventContext *_context)
|
|||
currentContext = MessageContext_MoveCard;
|
||||
else if (qobject_cast<Context_Mulligan *>(_context)) {
|
||||
currentContext = MessageContext_Mulligan;
|
||||
mulliganPlayer = 0;
|
||||
mulliganNumber = static_cast<Context_Mulligan *>(_context)->getNumber();
|
||||
}
|
||||
}
|
||||
|
@ -482,6 +485,7 @@ void MessageLogWidget::containerProcessingDone()
|
|||
moveCardTapped.clear();
|
||||
} else if (currentContext == MessageContext_Mulligan) {
|
||||
logMulligan(mulliganPlayer, mulliganNumber);
|
||||
mulliganPlayer = 0;
|
||||
mulliganNumber = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1007,7 +1007,6 @@ void Player::eventDrawCards(Event_DrawCards *event)
|
|||
|
||||
hand->reorganizeCards();
|
||||
deck->reorganizeCards();
|
||||
|
||||
emit logDrawCards(this, event->getNumberCards());
|
||||
}
|
||||
|
||||
|
@ -1545,12 +1544,9 @@ void Player::setMirrored(bool _mirrored)
|
|||
}
|
||||
}
|
||||
|
||||
void Player::processSceneSizeChange(const QSizeF &newSize)
|
||||
void Player::processSceneSizeChange(int newPlayerWidth)
|
||||
{
|
||||
// This will need to be changed if player areas are displayed side by side (e.g. 2x2 for a 4-player game)
|
||||
qreal fullPlayerWidth = newSize.width();
|
||||
|
||||
qreal tableWidth = fullPlayerWidth - CARD_HEIGHT - 15 - counterAreaWidth - stack->boundingRect().width();
|
||||
qreal tableWidth = newPlayerWidth - CARD_HEIGHT - 15 - counterAreaWidth - stack->boundingRect().width();
|
||||
if (!settingsCache->getHorizontalHand())
|
||||
tableWidth -= hand->boundingRect().width();
|
||||
|
||||
|
|
|
@ -245,7 +245,7 @@ public:
|
|||
|
||||
qreal getMinimumWidth() const;
|
||||
void setMirrored(bool _mirrored);
|
||||
void processSceneSizeChange(const QSizeF &newSize);
|
||||
void processSceneSizeChange(int newPlayerWidth);
|
||||
|
||||
void processPlayerInfo(ServerInfo_Player *info);
|
||||
void processCardAttachment(ServerInfo_Player *info);
|
||||
|
|
|
@ -73,6 +73,7 @@ void myMessageOutput(QtMsgType /*type*/, const char *msg)
|
|||
logger->logMessage(msg);
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void sigSegvHandler(int sig)
|
||||
{
|
||||
if (sig == SIGSEGV)
|
||||
|
@ -82,6 +83,7 @@ void sigSegvHandler(int sig)
|
|||
delete loggerThread;
|
||||
raise(sig);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDateTime>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#ifdef Q_OS_UNIX
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
#endif
|
||||
|
||||
ServerLogger::ServerLogger(const QString &logFileName, QObject *parent)
|
||||
: QObject(parent), flushRunning(false)
|
||||
|
@ -14,9 +16,10 @@ ServerLogger::ServerLogger(const QString &logFileName, QObject *parent)
|
|||
logFile->open(QIODevice::Append);
|
||||
#ifdef Q_OS_UNIX
|
||||
::socketpair(AF_UNIX, SOCK_STREAM, 0, sigHupFD);
|
||||
#endif
|
||||
|
||||
snHup = new QSocketNotifier(sigHupFD[1], QSocketNotifier::Read, this);
|
||||
connect(snHup, SIGNAL(activated(int)), this, SLOT(handleSigHup()));
|
||||
#endif
|
||||
} else
|
||||
logFile = 0;
|
||||
|
||||
|
@ -62,6 +65,7 @@ void ServerLogger::flushBuffer()
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
void ServerLogger::hupSignalHandler(int /*unused*/)
|
||||
{
|
||||
if (!logFile)
|
||||
|
@ -85,6 +89,7 @@ void ServerLogger::handleSigHup()
|
|||
|
||||
snHup->setEnabled(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
QFile *ServerLogger::logFile;
|
||||
int ServerLogger::sigHupFD[2];
|
||||
|
|
|
@ -19,7 +19,9 @@ public:
|
|||
public slots:
|
||||
void logMessage(QString message);
|
||||
private slots:
|
||||
#ifdef Q_OS_UNIX
|
||||
void handleSigHup();
|
||||
#endif
|
||||
void flushBuffer();
|
||||
signals:
|
||||
void sigFlushBuffer();
|
||||
|
|
Loading…
Reference in a new issue