minor fixes; added round clock

This commit is contained in:
Max-Wilhelm Bruker 2011-01-08 14:22:41 +01:00
parent 02f2fb9764
commit 5544de3213
9 changed files with 28 additions and 8 deletions

View file

@ -67,9 +67,6 @@ void HandZone::reorganizeCards()
qreal totalWidth = boundingRect().width() - 2 * xPadding; qreal totalWidth = boundingRect().width() - 2 * xPadding;
qreal cardWidth = cards.at(0)->boundingRect().width(); qreal cardWidth = cards.at(0)->boundingRect().width();
if (cardWidth * cardCount < totalWidth)
cardWidth += 5;
for (int i = 0; i < cardCount; i++) { for (int i = 0; i < cardCount; i++) {
CardItem *c = cards.at(i); CardItem *c = cards.at(i);

View file

@ -38,7 +38,8 @@ void SelectZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
selectionOrigin = event->pos(); selectionOrigin = event->pos();
static_cast<GameScene *>(scene())->startRubberBand(event->scenePos()); static_cast<GameScene *>(scene())->startRubberBand(event->scenePos());
event->accept(); event->accept();
} } else
CardZone::mousePressEvent(event);
} }
void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void SelectZone::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)

View file

@ -169,6 +169,8 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
cardInfo = new CardInfoWidget(CardInfoWidget::ModeGameTab); cardInfo = new CardInfoWidget(CardInfoWidget::ModeGameTab);
playerListWidget = new PlayerListWidget; playerListWidget = new PlayerListWidget;
playerListWidget->setFocusPolicy(Qt::NoFocus); playerListWidget->setFocusPolicy(Qt::NoFocus);
timeElapsedLabel = new QLabel;
timeElapsedLabel->setAlignment(Qt::AlignCenter);
messageLog = new MessageLogWidget; messageLog = new MessageLogWidget;
connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfo, SLOT(setCard(QString))); connect(messageLog, SIGNAL(cardNameHovered(QString)), cardInfo, SLOT(setCard(QString)));
connect(messageLog, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString))); connect(messageLog, SIGNAL(showCardInfoPopup(QPoint, QString)), this, SLOT(showCardInfoPopup(QPoint, QString)));
@ -190,6 +192,7 @@ TabGame::TabGame(QList<AbstractClient *> &_clients, int _gameId, const QString &
QVBoxLayout *verticalLayout = new QVBoxLayout; QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(cardInfo); verticalLayout->addWidget(cardInfo);
verticalLayout->addWidget(playerListWidget, 1); verticalLayout->addWidget(playerListWidget, 1);
verticalLayout->addWidget(timeElapsedLabel);
verticalLayout->addWidget(messageLog, 5); verticalLayout->addWidget(messageLog, 5);
verticalLayout->addLayout(hLayout); verticalLayout->addLayout(hLayout);
@ -651,6 +654,13 @@ void TabGame::eventPing(Event_Ping *event, GameEventContext * /*context*/)
const QList<ServerInfo_PlayerPing *> &pingList = event->getPingList(); const QList<ServerInfo_PlayerPing *> &pingList = event->getPingList();
for (int i = 0; i < pingList.size(); ++i) for (int i = 0; i < pingList.size(); ++i)
playerListWidget->updatePing(pingList[i]->getPlayerId(), pingList[i]->getPingTime()); 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) void TabGame::newCardAdded(AbstractCardItem *card)

View file

@ -99,6 +99,7 @@ private:
CardInfoWidget *infoPopup; CardInfoWidget *infoPopup;
CardInfoWidget *cardInfo; CardInfoWidget *cardInfo;
PlayerListWidget *playerListWidget; PlayerListWidget *playerListWidget;
QLabel *timeElapsedLabel;
MessageLogWidget *messageLog; MessageLogWidget *messageLog;
QLabel *sayLabel; QLabel *sayLabel;
QLineEdit *sayEdit; QLineEdit *sayEdit;

View file

@ -414,9 +414,10 @@ Event_PlayerPropertiesChanged::Event_PlayerPropertiesChanged(int _playerId, Serv
insertItem(_properties); insertItem(_properties);
} }
Event_Ping::Event_Ping(const QList<ServerInfo_PlayerPing *> &_pingList) Event_Ping::Event_Ping(int _secondsElapsed, const QList<ServerInfo_PlayerPing *> &_pingList)
: GameEvent("ping", -1) : GameEvent("ping", -1)
{ {
insertItem(new SerializableItem_Int("seconds_elapsed", _secondsElapsed));
for (int i = 0; i < _pingList.size(); ++i) for (int i = 0; i < _pingList.size(); ++i)
itemList.append(_pingList[i]); itemList.append(_pingList[i]);
} }

View file

@ -399,9 +399,10 @@ public:
class Event_Ping : public GameEvent { class Event_Ping : public GameEvent {
Q_OBJECT Q_OBJECT
public: public:
Event_Ping(const QList<ServerInfo_PlayerPing *> &_pingList = QList<ServerInfo_PlayerPing *>()); Event_Ping(int _secondsElapsed = -1, const QList<ServerInfo_PlayerPing *> &_pingList = QList<ServerInfo_PlayerPing *>());
static SerializableItem *newItem() { return new Event_Ping; } static SerializableItem *newItem() { return new Event_Ping; }
int getItemId() const { return ItemId_Event_Ping; } int getItemId() const { return ItemId_Event_Ping; }
int getSecondsElapsed() const { return static_cast<SerializableItem_Int *>(itemMap.value("seconds_elapsed"))->getData(); }
QList<ServerInfo_PlayerPing *> getPingList() const { return typecastItemList<ServerInfo_PlayerPing *>(); } QList<ServerInfo_PlayerPing *> getPingList() const { return typecastItemList<ServerInfo_PlayerPing *>(); }
}; };

View file

@ -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 bool Server_CardZone::isColumnStacked(int x, int y) const
{ {
if (!has_coords)
return false;
QMap<int, Server_Card *> coordMap; QMap<int, Server_Card *> coordMap;
for (int i = 0; i < cards.size(); ++i) for (int i = 0; i < cards.size(); ++i)
if (cards[i]->getY() == y) 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 bool Server_CardZone::isColumnEmpty(int x, int y) const
{ {
if (!has_coords)
return true;
QMap<int, Server_Card *> coordMap; QMap<int, Server_Card *> coordMap;
for (int i = 0; i < cards.size(); ++i) for (int i = 0; i < cards.size(); ++i)
if (cards[i]->getY() == y) if (cards[i]->getY() == y)

View file

@ -29,7 +29,7 @@
#include <QDebug> #include <QDebug>
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) 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); addPlayer(_creator, false, false);
@ -56,6 +56,8 @@ Server_Game::~Server_Game()
void Server_Game::pingClockTimeout() void Server_Game::pingClockTimeout()
{ {
++secondsElapsed;
QDateTime now = QDateTime::currentDateTime(); QDateTime now = QDateTime::currentDateTime();
QList<ServerInfo_PlayerPing *> pingList; QList<ServerInfo_PlayerPing *> pingList;
QMapIterator<int, Server_Player *> playerIterator(players); QMapIterator<int, Server_Player *> playerIterator(players);
@ -70,7 +72,7 @@ void Server_Game::pingClockTimeout()
pingTime = -1; pingTime = -1;
pingList.append(new ServerInfo_PlayerPing(player->getPlayerId(), pingTime)); pingList.append(new ServerInfo_PlayerPing(player->getPlayerId(), pingTime));
} }
sendGameEvent(new Event_Ping(pingList)); sendGameEvent(new Event_Ping(secondsElapsed, pingList));
const int maxTime = static_cast<Server_Room *>(parent())->getServer()->getMaxGameInactivityTime(); const int maxTime = static_cast<Server_Room *>(parent())->getServer()->getMaxGameInactivityTime();
if (allPlayersInactive) { if (allPlayersInactive) {

View file

@ -46,6 +46,7 @@ private:
bool spectatorsCanTalk; bool spectatorsCanTalk;
bool spectatorsSeeEverything; bool spectatorsSeeEverything;
int inactivityCounter; int inactivityCounter;
int secondsElapsed;
QTimer *pingClock; QTimer *pingClock;
signals: signals:
void gameClosing(); void gameClosing();