From 5544de3213c742e19af5f5ac2b89e70b0398920d Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sat, 8 Jan 2011 14:22:41 +0100 Subject: [PATCH] minor fixes; added round clock --- cockatrice/src/handzone.cpp | 3 --- cockatrice/src/selectzone.cpp | 3 ++- cockatrice/src/tab_game.cpp | 10 ++++++++++ cockatrice/src/tab_game.h | 1 + common/protocol.cpp | 3 ++- common/protocol.h | 3 ++- common/server_cardzone.cpp | 6 ++++++ common/server_game.cpp | 6 ++++-- common/server_game.h | 1 + 9 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cockatrice/src/handzone.cpp b/cockatrice/src/handzone.cpp index 1246c969..75b90d28 100644 --- a/cockatrice/src/handzone.cpp +++ b/cockatrice/src/handzone.cpp @@ -67,9 +67,6 @@ void HandZone::reorganizeCards() qreal totalWidth = boundingRect().width() - 2 * xPadding; qreal cardWidth = cards.at(0)->boundingRect().width(); - if (cardWidth * cardCount < totalWidth) - cardWidth += 5; - for (int i = 0; i < cardCount; i++) { CardItem *c = cards.at(i); diff --git a/cockatrice/src/selectzone.cpp b/cockatrice/src/selectzone.cpp index f3bafab1..30156df6 100644 --- a/cockatrice/src/selectzone.cpp +++ b/cockatrice/src/selectzone.cpp @@ -38,7 +38,8 @@ void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event) selectionOrigin = event->pos(); static_cast(scene())->startRubberBand(event->scenePos()); event->accept(); - } + } else + CardZone::mousePressEvent(event); } void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 8d9a9511..13719e78 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -169,6 +169,8 @@ TabGame::TabGame(QList &_clients, int _gameId, const QString & cardInfo = new CardInfoWidget(CardInfoWidget::ModeGameTab); playerListWidget = new PlayerListWidget; playerListWidget->setFocusPolicy(Qt::NoFocus); + timeElapsedLabel = new QLabel; + timeElapsedLabel->setAlignment(Qt::AlignCenter); messageLog = new MessageLogWidget; connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfo, SLOT(setCard(QString))); connect(messageLog, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); @@ -190,6 +192,7 @@ TabGame::TabGame(QList &_clients, int _gameId, const QString & QVBoxLayout *verticalLayout = new QVBoxLayout; verticalLayout->addWidget(cardInfo); verticalLayout->addWidget(playerListWidget, 1); + verticalLayout->addWidget(timeElapsedLabel); verticalLayout->addWidget(messageLog, 5); verticalLayout->addLayout(hLayout); @@ -651,6 +654,13 @@ void TabGame::eventPing(Event_Ping *event, GameEventContext * /*context*/) const QList &pingList = event->getPingList(); for (int i = 0; i < pingList.size(); ++i) playerListWidget->updatePing(pingList[i]->getPlayerId(), pingList[i]->getPingTime()); + + int seconds = event->getSecondsElapsed(); + int minutes = seconds / 60; + seconds -= minutes * 60; + int hours = minutes / 60; + minutes -= hours * 60; + timeElapsedLabel->setText(QString::number(hours).rightJustified(2, '0') + ":" + QString::number(minutes).rightJustified(2, '0') + ":" + QString::number(seconds).rightJustified(2, '0')); } void TabGame::newCardAdded(AbstractCardItem *card) diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index db7ebd0b..0a022adf 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -99,6 +99,7 @@ private: CardInfoWidget *infoPopup; CardInfoWidget *cardInfo; PlayerListWidget *playerListWidget; + QLabel *timeElapsedLabel; MessageLogWidget *messageLog; QLabel *sayLabel; QLineEdit *sayEdit; diff --git a/common/protocol.cpp b/common/protocol.cpp index b6060f2e..b913b5a7 100644 --- a/common/protocol.cpp +++ b/common/protocol.cpp @@ -414,9 +414,10 @@ Event_PlayerPropertiesChanged::Event_PlayerPropertiesChanged(int _playerId, Serv insertItem(_properties); } -Event_Ping::Event_Ping(const QList &_pingList) +Event_Ping::Event_Ping(int _secondsElapsed, const QList &_pingList) : GameEvent("ping", -1) { + insertItem(new SerializableItem_Int("seconds_elapsed", _secondsElapsed)); for (int i = 0; i < _pingList.size(); ++i) itemList.append(_pingList[i]); } diff --git a/common/protocol.h b/common/protocol.h index e882823b..7b7ba5c8 100644 --- a/common/protocol.h +++ b/common/protocol.h @@ -399,9 +399,10 @@ public: class Event_Ping : public GameEvent { Q_OBJECT public: - Event_Ping(const QList &_pingList = QList()); + Event_Ping(int _secondsElapsed = -1, const QList &_pingList = QList()); static SerializableItem *newItem() { return new Event_Ping; } int getItemId() const { return ItemId_Event_Ping; } + int getSecondsElapsed() const { return static_cast(itemMap.value("seconds_elapsed"))->getData(); } QList getPingList() const { return typecastItemList(); } }; diff --git a/common/server_cardzone.cpp b/common/server_cardzone.cpp index 2ea5b8fb..a2ca1a99 100644 --- a/common/server_cardzone.cpp +++ b/common/server_cardzone.cpp @@ -119,6 +119,9 @@ int Server_CardZone::getFreeGridColumn(int x, int y, const QString &cardName) co bool Server_CardZone::isColumnStacked(int x, int y) const { + if (!has_coords) + return false; + QMap coordMap; for (int i = 0; i < cards.size(); ++i) if (cards[i]->getY() == y) @@ -129,6 +132,9 @@ bool Server_CardZone::isColumnStacked(int x, int y) const bool Server_CardZone::isColumnEmpty(int x, int y) const { + if (!has_coords) + return true; + QMap coordMap; for (int i = 0; i < cards.size(); ++i) if (cards[i]->getY() == y) diff --git a/common/server_game.cpp b/common/server_game.cpp index 84a46cc5..d2404706 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -29,7 +29,7 @@ #include Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, bool _spectatorsNeedPassword, bool _spectatorsCanTalk, bool _spectatorsSeeEverything, Server_Room *parent) - : QObject(parent), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0) + : QObject(parent), creatorInfo(new ServerInfo_User(_creator->getUserInfo())), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), activePlayer(-1), activePhase(-1), spectatorsAllowed(_spectatorsAllowed), spectatorsNeedPassword(_spectatorsNeedPassword), spectatorsCanTalk(_spectatorsCanTalk), spectatorsSeeEverything(_spectatorsSeeEverything), inactivityCounter(0), secondsElapsed(0) { addPlayer(_creator, false, false); @@ -56,6 +56,8 @@ Server_Game::~Server_Game() void Server_Game::pingClockTimeout() { + ++secondsElapsed; + QDateTime now = QDateTime::currentDateTime(); QList pingList; QMapIterator playerIterator(players); @@ -70,7 +72,7 @@ void Server_Game::pingClockTimeout() pingTime = -1; pingList.append(new ServerInfo_PlayerPing(player->getPlayerId(), pingTime)); } - sendGameEvent(new Event_Ping(pingList)); + sendGameEvent(new Event_Ping(secondsElapsed, pingList)); const int maxTime = static_cast(parent())->getServer()->getMaxGameInactivityTime(); if (allPlayersInactive) { diff --git a/common/server_game.h b/common/server_game.h index 420847dd..29d2c91a 100644 --- a/common/server_game.h +++ b/common/server_game.h @@ -46,6 +46,7 @@ private: bool spectatorsCanTalk; bool spectatorsSeeEverything; int inactivityCounter; + int secondsElapsed; QTimer *pingClock; signals: void gameClosing();