From 890740bcc95c05b822fa98fd393b5ed01518ca1d Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 21 Sep 2009 20:21:11 +0200 Subject: [PATCH] protocol changes, menu cleanups, phase button speed improvement --- cockatrice/src/client.cpp | 8 +- cockatrice/src/game.cpp | 184 ++++++--------------- cockatrice/src/game.h | 24 ++- cockatrice/src/gamesmodel.cpp | 16 +- cockatrice/src/messagelogwidget.cpp | 12 ++ cockatrice/src/messagelogwidget.h | 2 + cockatrice/src/phasestoolbar.cpp | 45 +++--- cockatrice/src/phasestoolbar.h | 3 + cockatrice/src/player.cpp | 114 +++++++++++++ cockatrice/src/player.h | 15 +- cockatrice/src/serverplayer.h | 6 +- cockatrice/src/window_main.cpp | 78 ++++----- cockatrice/src/window_main.h | 5 +- cockatrice/translations/cockatrice_de.ts | 193 ++++++++++++---------- cockatrice/translations/cockatrice_en.ts | 195 +++++++++++++---------- servatrice/src/servergame.cpp | 25 +-- servatrice/src/servergame.h | 4 +- servatrice/src/serversocket.cpp | 22 +-- servatrice/src/serversocket.h | 5 +- 19 files changed, 514 insertions(+), 442 deletions(-) diff --git a/cockatrice/src/client.cpp b/cockatrice/src/client.cpp index 2e07d54a..c16b68e3 100644 --- a/cockatrice/src/client.cpp +++ b/cockatrice/src/client.cpp @@ -158,7 +158,7 @@ void Client::readLine() // XXX Parametergültigkeit überprüfen if (prefix == "list_players") - playerlist << new ServerPlayer(val[0].toInt(), val[1]); + playerlist << new ServerPlayer(val[0].toInt(), val[1], val[2].toInt()); else if (prefix == "list_counters") { } else if (prefix == "list_zones") @@ -185,10 +185,10 @@ void Client::readLine() void Client::setStatus(const ProtocolStatus _status) { - ProtocolStatus oldStatus = status; - status = _status; - if (oldStatus != _status) + if (_status != status) { + status = _status; emit statusChanged(_status); + } } void Client::msg(const QString &s) diff --git a/cockatrice/src/game.cpp b/cockatrice/src/game.cpp index 2b1df0cb..0461a8ab 100644 --- a/cockatrice/src/game.cpp +++ b/cockatrice/src/game.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -13,51 +14,16 @@ #include "counter.h" #include "gamescene.h" -Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent) - : QObject(parent), actionsMenu(_actionsMenu), cardMenu(_cardMenu), db(_db), client(_client), scene(_scene), started(false), currentPhase(-1) +Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent) + : QObject(parent), db(_db), client(_client), scene(_scene), started(false), currentPhase(-1) { - localPlayer = addPlayer(playerId, playerName, true); - connect(client, SIGNAL(gameEvent(const ServerEventData &)), this, SLOT(gameEvent(const ServerEventData &))); connect(client, SIGNAL(playerListReceived(QList)), this, SLOT(playerListReceived(QList))); - aUntapAll = new QAction(this); - connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll())); - - aDecLife = new QAction(this); - connect(aDecLife, SIGNAL(triggered()), this, SLOT(actDecLife())); - aIncLife = new QAction(this); - connect(aIncLife, SIGNAL(triggered()), this, SLOT(actIncLife())); - aSetLife = new QAction(this); - connect(aSetLife, SIGNAL(triggered()), this, SLOT(actSetLife())); - - aRollDie = new QAction(this); - connect(aRollDie, SIGNAL(triggered()), this, SLOT(actRollDie())); - - aCreateToken = new QAction(this); - connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken())); - aNextPhase = new QAction(this); connect(aNextPhase, SIGNAL(triggered()), this, SLOT(actNextPhase())); aNextTurn = new QAction(this); connect(aNextTurn, SIGNAL(triggered()), this, SLOT(actNextTurn())); - - actionsMenu->addAction(aNextPhase); - actionsMenu->addAction(aNextTurn); - actionsMenu->addSeparator(); - actionsMenu->addAction(aUntapAll); - actionsMenu->addSeparator(); - actionsMenu->addAction(aDecLife); - actionsMenu->addAction(aIncLife); - actionsMenu->addAction(aSetLife); - actionsMenu->addSeparator(); - actionsMenu->addAction(aRollDie); - actionsMenu->addSeparator(); - actionsMenu->addAction(aCreateToken); - actionsMenu->addSeparator(); - sayMenu = actionsMenu->addMenu(QString()); - initSayMenu(); - aTap = new QAction(this); aUntap = new QAction(this); aDoesntUntap = new QAction(this); @@ -71,6 +37,11 @@ Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenu *_action aMoveToGraveyard = new QAction(this); aMoveToExile = new QAction(this); + gameMenu = menuBar->addMenu(QString()); + gameMenu->addAction(aNextPhase); + gameMenu->addAction(aNextTurn); + + cardMenu = menuBar->addMenu(QString()); cardMenu->addAction(aTap); cardMenu->addAction(aUntap); cardMenu->addAction(aDoesntUntap); @@ -110,6 +81,8 @@ Game::Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenu *_action connect(dlgStartGame, SIGNAL(finished(int)), this, SLOT(readyStart())); retranslateUi(); + + client->listPlayers(); } Game::~Game() @@ -119,29 +92,19 @@ Game::~Game() emit playerRemoved(players.at(i)); delete players.at(i); } + delete gameMenu; + delete cardMenu; } void Game::retranslateUi() { - aUntapAll->setText(tr("&Untap all permanents")); - aUntapAll->setShortcut(tr("Ctrl+U")); - aDecLife->setText(tr("&Decrement life")); - aDecLife->setShortcut(tr("F11")); - aIncLife->setText(tr("&Increment life")); - aIncLife->setShortcut(tr("F12")); - aSetLife->setText(tr("&Set life")); - aSetLife->setShortcut(tr("Ctrl+L")); - aRollDie->setText(tr("R&oll die...")); - aRollDie->setShortcut(tr("Ctrl+I")); - aCreateToken->setText(tr("&Create token...")); - aCreateToken->setShortcut(tr("Ctrl+T")); + gameMenu->setTitle(tr("&Game")); aNextPhase->setText(tr("Next &phase")); aNextPhase->setShortcut(tr("Ctrl+Space")); aNextTurn->setText(tr("Next &turn")); aNextTurn->setShortcuts(QList() << QKeySequence(tr("Ctrl+Return")) << QKeySequence(tr("Ctrl+Enter"))); - sayMenu->setTitle(tr("S&ay")); - + cardMenu->setTitle(tr("C&ard")); aTap->setText(tr("&Tap")); aUntap->setText(tr("&Untap")); aDoesntUntap->setText(tr("Toggle &normal untapping")); @@ -161,30 +124,6 @@ void Game::retranslateUi() players[i]->retranslateUi(); } -void Game::initSayMenu() -{ - sayMenu->clear(); - - QSettings settings; - settings.beginGroup("messages"); - int count = settings.value("count", 0).toInt(); - for (int i = 0; i < count; i++) { - QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this); - QString shortcut; - switch (i) { - case 0: shortcut = tr("F5"); break; - case 1: shortcut = tr("F6"); break; - case 2: shortcut = tr("F7"); break; - case 3: shortcut = tr("F8"); break; - case 4: shortcut = tr("F9"); break; - case 5: shortcut = tr("F10"); break; - } - newAction->setShortcut(shortcut); - connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage())); - sayMenu->addAction(newAction); - } -} - Player *Game::addPlayer(int playerId, const QString &playerName, bool local) { Player *newPlayer = new Player(playerName, playerId, local, db, client, this); @@ -213,8 +152,7 @@ void Game::playerListReceived(QList playerList) nameList << temp->getName(); int id = temp->getPlayerId(); - if (id != localPlayer->getId()) - addPlayer(id, temp->getName(), false); + addPlayer(id, temp->getName(), temp->getLocal()); delete temp; } @@ -235,10 +173,12 @@ void Game::restartGameDialog() void Game::gameEvent(const ServerEventData &msg) { qDebug(QString("game::gameEvent: public=%1, player=%2, name=%3, type=%4, data=%5").arg(msg.getPublic()).arg(msg.getPlayerId()).arg(msg.getPlayerName()).arg(msg.getEventType()).arg(msg.getEventData().join("/")).toLatin1()); - if (!msg.getPublic()) - localPlayer->gameEvent(msg); - else { - Player *p = players.findPlayer(msg.getPlayerId()); + Player *p = players.findPlayer(msg.getPlayerId()); + if (!msg.getPublic()) { + if (!p) + return; + p->gameEvent(msg); + } else { if ((!p) && (msg.getEventType() != eventJoin)) { // XXX } @@ -248,14 +188,32 @@ void Game::gameEvent(const ServerEventData &msg) emit logSay(p, msg.getEventData()[0]); break; case eventJoin: { - Player *newPlayer = addPlayer(msg.getPlayerId(), msg.getPlayerName(), false); - emit logJoin(newPlayer); + const QStringList &data = msg.getEventData(); + if (data.size() != 1) + return; + bool spectator = data[0].toInt(); + if (spectator) { + spectatorList << msg.getPlayerName(); + emit logJoinSpectator(msg.getPlayerName()); + } else { + Player *newPlayer = addPlayer(msg.getPlayerId(), msg.getPlayerName(), false); + emit logJoin(newPlayer); + } break; } - case eventLeave: - emit logLeave(p); - // XXX Spieler natürlich noch rauswerfen + case eventLeave: { + if (p) + emit logLeave(p); + // XXX Spieler natürlich noch rauswerfen + else { + int spectatorIndex = spectatorList.indexOf(msg.getPlayerName()); + if (spectatorIndex != -1) { + spectatorList.removeAt(spectatorIndex); + emit logLeaveSpectator(msg.getPlayerName()); + } + } break; + } case eventReadyStart: if (started) { started = false; @@ -335,16 +293,14 @@ void Game::gameEvent(const ServerEventData &msg) break; } case eventMoveCard: { - if (msg.getPlayerId() == localPlayer->getId()) - break; - p->gameEvent(msg); + if (!p->getLocal()) + p->gameEvent(msg); break; } case eventDraw: { emit logDraw(p, msg.getEventData()[0].toInt()); - if (msg.getPlayerId() == localPlayer->getId()) - break; - p->gameEvent(msg); + if (!p->getLocal()) + p->gameEvent(msg); break; } case eventInvalid: { @@ -369,44 +325,6 @@ void Game::actNextTurn() client->nextTurn(); } -void Game::actUntapAll() -{ - client->setCardAttr("table", -1, "tapped", "false"); -} - -void Game::actIncLife() -{ - client->incCounter("life", 1); -} - -void Game::actDecLife() -{ - client->incCounter("life", -1); -} - -void Game::actSetLife() -{ - bool ok; - int life = QInputDialog::getInteger(0, tr("Set life"), tr("New life total:"), localPlayer->getCounter("life")->getValue(), 0, 2000000000, 1, &ok); - if (ok) - client->setCounter("life", life); -} - -void Game::actRollDie() -{ - bool ok; - int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok); - if (ok) - client->rollDie(sides); -} - -void Game::actCreateToken() -{ - QString cardname = QInputDialog::getText(0, tr("Create token"), tr("Name:")); - if (!cardname.isEmpty()) - client->createToken("table", cardname, QString(), 0, 0); -} - void Game::showCardMenu(QPoint p) { cardMenu->exec(p); @@ -501,12 +419,6 @@ void Game::actMoveToExile(CardItem *card) client->moveCard(card->getId(), startZone->getName(), "rfg", 0, 0, false); } -void Game::actSayMessage() -{ - QAction *a = qobject_cast(sender()); - client->say(a->text()); -} - void Game::hoverCardEvent(CardItem *card) { emit hoverCard(card->getName()); diff --git a/cockatrice/src/game.h b/cockatrice/src/game.h index d6075394..2e02c149 100644 --- a/cockatrice/src/game.h +++ b/cockatrice/src/game.h @@ -2,6 +2,7 @@ #define GAME_H #include +#include #include "playerlist.h" class ServerPlayer; @@ -12,6 +13,7 @@ class ServerEventData; class CardDatabase; class DlgStartGame; class CardItem; +class QMenuBar; class Game : public QObject { Q_OBJECT @@ -21,30 +23,22 @@ private: typedef void (Game::*CardMenuHandler)(CardItem *card); QHash cardMenuHandlers; - QMenu *actionsMenu, *sayMenu, *cardMenu, *moveMenu; + QMenu *gameMenu, *cardMenu, *moveMenu; QAction *aTap, *aUntap, *aDoesntUntap, *aFlip, *aAddCounter, *aRemoveCounter, *aSetCounters, *aMoveToTopLibrary, *aMoveToBottomLibrary, *aMoveToGraveyard, *aMoveToExile, - *aNextPhase, *aNextTurn, *aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aRollDie, *aCreateToken; + *aNextPhase, *aNextTurn; DlgStartGame *dlgStartGame; CardDatabase *db; Client *client; GameScene *scene; + QStringList spectatorList; PlayerList players; - Player *localPlayer; bool started; int currentPhase; - Player *addPlayer(int playerId, const QString &playerName, bool local); - void initSayMenu(); public slots: void actNextPhase(); void actNextTurn(); - void actUntapAll(); - void actIncLife(); - void actDecLife(); - void actSetLife(); - void actRollDie(); - void actCreateToken(); private slots: void cardMenuAction(); @@ -60,8 +54,6 @@ private slots: void actMoveToBottomLibrary(CardItem *card); void actMoveToGraveyard(CardItem *card); void actMoveToExile(CardItem *card); - - void actSayMessage(); void gameEvent(const ServerEventData &msg); void playerListReceived(QList playerList); @@ -76,6 +68,8 @@ signals: void logPlayerListReceived(QStringList players); void logJoin(Player *player); void logLeave(Player *player); + void logJoinSpectator(QString playerName); + void logLeaveSpectator(QString playerName); void logReadyStart(Player *player); void logGameStart(); void logSay(Player *player, QString text); @@ -93,12 +87,12 @@ signals: void logSetActivePlayer(Player *player); void setActivePhase(int phase); public: - Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenu *_actionsMenu, QMenu *_cardMenu, int playerId, const QString &playerName, QObject *parent = 0); + Game(CardDatabase *_db, Client *_client, GameScene *_scene, QMenuBar *menuBar, QObject *parent = 0); ~Game(); - Player *getLocalPlayer() const { return localPlayer; } void retranslateUi(); void restartGameDialog(); void hoverCardEvent(CardItem *card); + Player *addPlayer(int playerId, const QString &playerName, bool local); }; #endif diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index b07e67b6..a9cc6ff0 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -15,11 +15,11 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const ServerGame *g = gameList.at(index.row()); switch (index.column()) { - case 0: return g->getGameId(); + case 0: return g->getDescription(); case 1: return g->getCreator(); - case 2: return g->getDescription(); - case 3: return QString(g->getHasPassword() ? tr("yes") : tr("no")); - case 4: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers()); + case 2: return g->getHasPassword() ? tr("yes") : tr("no"); + case 3: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers()); + case 4: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorsCount()) : QVariant(tr("not allowed")); default: return QVariant(); } } @@ -29,11 +29,11 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro if ((role != Qt::DisplayRole) || (orientation != Qt::Horizontal)) return QVariant(); switch (section) { - case 0: return tr("Game ID"); + case 0: return tr("Description"); case 1: return tr("Creator"); - case 2: return tr("Description"); - case 3: return tr("Password"); - case 4: return tr("Players"); + case 2: return tr("Password"); + case 3: return tr("Players"); + case 4: return tr("Spectators"); default: return QVariant(); } } diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index 34d6f03e..95a75963 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -64,6 +64,16 @@ void MessageLogWidget::logLeave(Player *player) append(tr("%1 has left the game").arg(sanitizeHtml(player->getName()))); } +void MessageLogWidget::logJoinSpectator(QString name) +{ + append(tr("%1 is now watching the game.").arg(sanitizeHtml(name))); +} + +void MessageLogWidget::logLeaveSpectator(QString name) +{ + append(tr("%1 is not watching the game any more.").arg(sanitizeHtml(name))); +} + void MessageLogWidget::logReadyStart(Player *player) { append(tr("%1 is ready to start a new game.").arg(sanitizeHtml(player->getName()))); @@ -249,6 +259,8 @@ void MessageLogWidget::connectToGame(Game *game) connect(game, SIGNAL(logPlayerListReceived(QStringList)), this, SLOT(logPlayerListReceived(QStringList))); connect(game, SIGNAL(logJoin(Player *)), this, SLOT(logJoin(Player *))); connect(game, SIGNAL(logLeave(Player *)), this, SLOT(logLeave(Player *))); + connect(game, SIGNAL(logJoinSpectator(QString)), this, SLOT(logJoinSpectator(QString))); + connect(game, SIGNAL(logLeaveSpectator(QString)), this, SLOT(logLeaveSpectator(QString))); connect(game, SIGNAL(logReadyStart(Player *)), this, SLOT(logReadyStart(Player *))); connect(game, SIGNAL(logGameStart()), this, SLOT(logGameStart())); connect(game, SIGNAL(logSay(Player *, QString)), this, SLOT(logSay(Player *, QString))); diff --git a/cockatrice/src/messagelogwidget.h b/cockatrice/src/messagelogwidget.h index 78dca0e4..9f9e9b15 100644 --- a/cockatrice/src/messagelogwidget.h +++ b/cockatrice/src/messagelogwidget.h @@ -26,6 +26,8 @@ private slots: void logPlayerListReceived(QStringList players); void logJoin(Player *player); void logLeave(Player *player); + void logJoinSpectator(QString name); + void logLeaveSpectator(QString name); void logReadyStart(Player *player); void logGameStart(); void logSay(Player *player, QString message); diff --git a/cockatrice/src/phasestoolbar.cpp b/cockatrice/src/phasestoolbar.cpp index 894bd349..bda11c2c 100644 --- a/cockatrice/src/phasestoolbar.cpp +++ b/cockatrice/src/phasestoolbar.cpp @@ -5,30 +5,37 @@ #include PhaseButton::PhaseButton(const QIcon &icon, QAction *_doubleClickAction) - : QPushButton(icon, QString()), active(false), doubleClickAction(_doubleClickAction) + : QPushButton(icon, QString()), active(false), doubleClickAction(_doubleClickAction), activePixmap(50, 50), inactivePixmap(50, 50) { setFixedSize(50, 50); + + updatePixmap(activePixmap, true); + updatePixmap(inactivePixmap, false); } -void PhaseButton::paintEvent(QPaintEvent *event) +void PhaseButton::updatePixmap(QPixmap &pixmap, bool active) { - QPushButton::paintEvent(event); - if (active) { - QPainter painter(this); - int height = size().height(); - int width = size().width(); + pixmap.fill(Qt::transparent); + + QPainter painter(&pixmap); + int height = pixmap.height(); + int width = pixmap.width(); - painter.setPen(QPen(Qt::transparent)); + if (active) + painter.setBrush(Qt::red); + painter.setPen(Qt::gray); + painter.drawRect(1, 1, width - 2, height - 2); - QRadialGradient grad(QPointF(0.5, 0.5), 0.5); - grad.setCoordinateMode(QGradient::ObjectBoundingMode); - grad.setColorAt(0, QColor(180, 0, 0, 0)); - grad.setColorAt(0.8, QColor(180, 0, 0, 0)); - grad.setColorAt(1, QColor(180, 0, 0, 255)); - painter.setBrush(QBrush(grad)); + icon().paint(&painter, 5, 5, width - 10, height - 10); +} - painter.drawRect(2, 2, width - 4, height - 4); - } +void PhaseButton::paintEvent(QPaintEvent */*event*/) +{ + QPainter painter(this); + if (active) + painter.drawPixmap(0, 0, size().width(), size().height(), activePixmap); + else + painter.drawPixmap(0, 0, size().width(), size().height(), inactivePixmap); } void PhaseButton::setPhaseText(const QString &_phaseText) @@ -67,13 +74,11 @@ PhasesToolbar::PhasesToolbar(QWidget *parent) << combatAttackersButton << combatBlockersButton << combatDamageButton << combatEndButton << main2Button << cleanupButton; - for (int i = 0; i < buttonList.size(); ++i) { - buttonList[i]->setIconSize(QSize(36, 36)); + for (int i = 0; i < buttonList.size(); ++i) connect(buttonList[i], SIGNAL(clicked()), this, SLOT(phaseButtonClicked())); - } QPushButton *nextTurnButton = new QPushButton(QIcon(":/resources/icon_nextturn.svg"), QString()); - nextTurnButton->setIconSize(QSize(36, 36)); + nextTurnButton->setIconSize(QSize(40, 40)); nextTurnButton->setFixedSize(50, 50); connect(nextTurnButton, SIGNAL(clicked()), this, SIGNAL(signalNextTurn())); diff --git a/cockatrice/src/phasestoolbar.h b/cockatrice/src/phasestoolbar.h index 1c247c02..824916d6 100644 --- a/cockatrice/src/phasestoolbar.h +++ b/cockatrice/src/phasestoolbar.h @@ -13,6 +13,9 @@ private: QString phaseText; bool active; QAction *doubleClickAction; + QPixmap activePixmap, inactivePixmap; + + void updatePixmap(QPixmap &pixmap, bool active); public: PhaseButton(const QIcon &icon, QAction *_doubleClickAction = 0); void setPhaseText(const QString &_phaseText); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 319a016d..5bd78b0f 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -112,6 +112,37 @@ Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Cl sbMenu = playerMenu->addMenu(QString()); sbMenu->addAction(aViewSideboard); sb->setMenu(sbMenu, aViewSideboard); + + aUntapAll = new QAction(this); + connect(aUntapAll, SIGNAL(triggered()), this, SLOT(actUntapAll())); + + aDecLife = new QAction(this); + connect(aDecLife, SIGNAL(triggered()), this, SLOT(actDecLife())); + aIncLife = new QAction(this); + connect(aIncLife, SIGNAL(triggered()), this, SLOT(actIncLife())); + aSetLife = new QAction(this); + connect(aSetLife, SIGNAL(triggered()), this, SLOT(actSetLife())); + + aRollDie = new QAction(this); + connect(aRollDie, SIGNAL(triggered()), this, SLOT(actRollDie())); + + aCreateToken = new QAction(this); + connect(aCreateToken, SIGNAL(triggered()), this, SLOT(actCreateToken())); + + playerMenu->addSeparator(); + playerMenu->addAction(aUntapAll); + playerMenu->addSeparator(); + playerMenu->addAction(aDecLife); + playerMenu->addAction(aIncLife); + playerMenu->addAction(aSetLife); + playerMenu->addSeparator(); + playerMenu->addAction(aRollDie); + playerMenu->addSeparator(); + playerMenu->addAction(aCreateToken); + playerMenu->addSeparator(); + sayMenu = playerMenu->addMenu(QString()); + initSayMenu(); + } else sbMenu = 0; @@ -126,6 +157,7 @@ Player::~Player() delete zones.at(i); clearCounters(); + delete playerMenu; } void Player::updateBoundingRect() @@ -160,6 +192,44 @@ void Player::retranslateUi() handMenu->setTitle(tr("&Hand")); sbMenu->setTitle(tr("&Sideboard")); libraryMenu->setTitle(tr("&Library")); + + aUntapAll->setText(tr("&Untap all permanents")); + aUntapAll->setShortcut(tr("Ctrl+U")); + aDecLife->setText(tr("&Decrement life")); + aDecLife->setShortcut(tr("F11")); + aIncLife->setText(tr("&Increment life")); + aIncLife->setShortcut(tr("F12")); + aSetLife->setText(tr("&Set life")); + aSetLife->setShortcut(tr("Ctrl+L")); + aRollDie->setText(tr("R&oll die...")); + aRollDie->setShortcut(tr("Ctrl+I")); + aCreateToken->setText(tr("&Create token...")); + aCreateToken->setShortcut(tr("Ctrl+T")); + sayMenu->setTitle(tr("S&ay")); + } +} + +void Player::initSayMenu() +{ + sayMenu->clear(); + + QSettings settings; + settings.beginGroup("messages"); + int count = settings.value("count", 0).toInt(); + for (int i = 0; i < count; i++) { + QAction *newAction = new QAction(settings.value(QString("msg%1").arg(i)).toString(), this); + QString shortcut; + switch (i) { + case 0: shortcut = tr("F5"); break; + case 1: shortcut = tr("F6"); break; + case 2: shortcut = tr("F7"); break; + case 3: shortcut = tr("F8"); break; + case 4: shortcut = tr("F9"); break; + case 5: shortcut = tr("F10"); break; + } + newAction->setShortcut(shortcut); + connect(newAction, SIGNAL(triggered()), this, SLOT(actSayMessage())); + sayMenu->addAction(newAction); } } @@ -220,6 +290,50 @@ void Player::actDrawCards() client->drawCards(number); } +void Player::actUntapAll() +{ + client->setCardAttr("table", -1, "tapped", "false"); +} + +void Player::actIncLife() +{ + client->incCounter("life", 1); +} + +void Player::actDecLife() +{ + client->incCounter("life", -1); +} + +void Player::actSetLife() +{ + bool ok; + int life = QInputDialog::getInteger(0, tr("Set life"), tr("New life total:"), getCounter("life")->getValue(), 0, 2000000000, 1, &ok); + if (ok) + client->setCounter("life", life); +} + +void Player::actRollDie() +{ + bool ok; + int sides = QInputDialog::getInteger(0, tr("Roll die"), tr("Number of sides:"), 20, 2, 1000, 1, &ok); + if (ok) + client->rollDie(sides); +} + +void Player::actCreateToken() +{ + QString cardname = QInputDialog::getText(0, tr("Create token"), tr("Name:")); + if (!cardname.isEmpty()) + client->createToken("table", cardname, QString(), 0, 0); +} + +void Player::actSayMessage() +{ + QAction *a = qobject_cast(sender()); + client->say(a->text()); +} + void Player::addZone(CardZone *z) { zones << z; diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index ffcb45e1..e41f30a0 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -33,6 +33,15 @@ signals: void logSetDoesntUntap(Player *player, QString cardName, bool doesntUntap); void sizeChanged(); +public slots: + void actUntapAll(); + void actIncLife(); + void actDecLife(); + void actSetLife(); + void actRollDie(); + void actCreateToken(); + + void actSayMessage(); private slots: void updateBoundingRect(); @@ -49,10 +58,11 @@ private slots: void actViewRfg(); void actViewSideboard(); private: - QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu; + QMenu *playerMenu, *handMenu, *graveMenu, *rfgMenu, *libraryMenu, *sbMenu, *sayMenu; QAction *aMoveHandToTopLibrary, *aMoveHandToBottomLibrary, *aViewLibrary, *aViewTopCards, *aViewGraveyard, *aViewRfg, *aViewSideboard, - *aDrawCard, *aDrawCards, *aShuffle; + *aDrawCard, *aDrawCards, *aShuffle, + *aUntapAll, *aDecLife, *aIncLife, *aSetLife, *aRollDie, *aCreateToken; int defaultNumberTopCards; QString name; @@ -72,6 +82,7 @@ private: QList counterList; void rearrangeCounters(); + void initSayMenu(); public: enum { Type = typeOther }; int type() const { return Type; } diff --git a/cockatrice/src/serverplayer.h b/cockatrice/src/serverplayer.h index 99cd8714..820f9bda 100644 --- a/cockatrice/src/serverplayer.h +++ b/cockatrice/src/serverplayer.h @@ -7,11 +7,13 @@ class ServerPlayer { private: int PlayerId; QString name; + bool local; public: - ServerPlayer(int _PlayerId, const QString &_name) - : PlayerId(_PlayerId), name(_name) { } + ServerPlayer(int _PlayerId, const QString &_name, bool _local) + : PlayerId(_PlayerId), name(_name), local(_local) { } int getPlayerId() const { return PlayerId; } QString getName() const { return name; } + bool getLocal() const { return local; } }; #endif diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index b1ce55f4..62cb19dd 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -38,11 +38,6 @@ #include "zoneviewlayout.h" #include "chatwidget.h" -void MainWindow::hoverCard(QString name) -{ - cardInfo->setCard(name); -} - void MainWindow::playerAdded(Player *player) { menuBar()->addMenu(player->getPlayerMenu()); @@ -50,11 +45,6 @@ void MainWindow::playerAdded(Player *player) connect(player, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *))); } -void MainWindow::playerRemoved(Player *player) -{ - menuBar()->removeAction(player->getPlayerMenu()->menuAction()); -} - void MainWindow::statusChanged(ProtocolStatus _status) { switch (_status) { @@ -95,11 +85,22 @@ void MainWindow::statusChanged(ProtocolStatus _status) chatWidget->enableChat(); break; } - case StatusPlaying: + case StatusPlaying: { chatWidget->disableChat(); + + game = new Game(db, client, scene, menuBar(), this); + connect(game, SIGNAL(hoverCard(QString)), cardInfo, SLOT(setCard(const QString &))); + connect(game, SIGNAL(playerAdded(Player *)), this, SLOT(playerAdded(Player *))); + connect(game, SIGNAL(playerRemoved(Player *)), scene, SLOT(removePlayer(Player *))); + connect(game, SIGNAL(setActivePhase(int)), phasesToolbar, SLOT(setActivePhase(int))); + messageLog->connectToGame(game); + aRestartGame->setEnabled(true); + aLeaveGame->setEnabled(true); + phasesToolbar->show(); view->show(); break; + } default: break; } @@ -164,24 +165,6 @@ void MainWindow::actSay() sayEdit->clear(); } -void MainWindow::playerIdReceived(int id, QString name) -{ - game = new Game(db, client, scene, actionsMenu, cardMenu, id, name, this); - connect(game, SIGNAL(hoverCard(QString)), this, SLOT(hoverCard(QString))); - connect(game, SIGNAL(playerAdded(Player *)), this, SLOT(playerAdded(Player *))); - connect(game, SIGNAL(playerRemoved(Player *)), this, SLOT(playerRemoved(Player *))); - connect(game, SIGNAL(playerRemoved(Player *)), scene, SLOT(removePlayer(Player *))); - connect(game, SIGNAL(setActivePhase(int)), phasesToolbar, SLOT(setActivePhase(int))); - connect(phasesToolbar, SIGNAL(signalUntapAll()), game, SLOT(actUntapAll())); - playerAdded(game->getLocalPlayer()); - - messageLog->connectToGame(game); - aRestartGame->setEnabled(true); - aLeaveGame->setEnabled(true); - - client->listPlayers(); -} - void MainWindow::serverTimeout() { QMessageBox::critical(this, tr("Error"), tr("Server timeout")); @@ -204,9 +187,7 @@ void MainWindow::retranslateUi() aCloseMostRecentZoneView->setText(tr("Close most recent zone view")); aCloseMostRecentZoneView->setShortcut(tr("Esc")); - gameMenu->setTitle(tr("&Game")); - actionsMenu->setTitle(tr("&Actions")); - cardMenu->setTitle(tr("&Card")); + cockatriceMenu->setTitle(tr("&Cockatrice")); sayLabel->setText(tr("&Say:")); @@ -248,24 +229,20 @@ void MainWindow::createActions() void MainWindow::createMenus() { - gameMenu = menuBar()->addMenu(QString()); - gameMenu->addAction(aConnect); - gameMenu->addAction(aDisconnect); - gameMenu->addSeparator(); - gameMenu->addAction(aRestartGame); - gameMenu->addAction(aLeaveGame); - gameMenu->addSeparator(); - gameMenu->addAction(aDeckEditor); - gameMenu->addSeparator(); - gameMenu->addAction(aFullScreen); - gameMenu->addSeparator(); - gameMenu->addAction(aSettings); - gameMenu->addSeparator(); - gameMenu->addAction(aExit); - - actionsMenu = menuBar()->addMenu(QString()); - - cardMenu = menuBar()->addMenu(QString()); + cockatriceMenu = menuBar()->addMenu(QString()); + cockatriceMenu->addAction(aConnect); + cockatriceMenu->addAction(aDisconnect); + cockatriceMenu->addSeparator(); + cockatriceMenu->addAction(aRestartGame); + cockatriceMenu->addAction(aLeaveGame); + cockatriceMenu->addSeparator(); + cockatriceMenu->addAction(aDeckEditor); + cockatriceMenu->addSeparator(); + cockatriceMenu->addAction(aFullScreen); + cockatriceMenu->addSeparator(); + cockatriceMenu->addAction(aSettings); + cockatriceMenu->addSeparator(); + cockatriceMenu->addAction(aExit); } MainWindow::MainWindow(QTranslator *_translator, QWidget *parent) @@ -323,7 +300,6 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent) connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout())); connect(client, SIGNAL(statusChanged(ProtocolStatus)), this, SLOT(statusChanged(ProtocolStatus))); - connect(client, SIGNAL(playerIdReceived(int, QString)), this, SLOT(playerIdReceived(int, QString))); connect(this, SIGNAL(logConnecting(QString)), messageLog, SLOT(logConnecting(QString))); connect(client, SIGNAL(welcomeMsgReceived(QString)), messageLog, SLOT(logConnected(QString))); diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index 7c2e2287..693e4905 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -46,11 +46,8 @@ class ChatWidget; class MainWindow : public QMainWindow { Q_OBJECT private slots: - void hoverCard(QString name); void playerAdded(Player *player); - void playerRemoved(Player *player); void statusChanged(ProtocolStatus _status); - void playerIdReceived(int id, QString name); void serverTimeout(); void actSay(); @@ -70,7 +67,7 @@ private: void retranslateUi(); void createActions(); void createMenus(); - QMenu *gameMenu, *actionsMenu, *cardMenu; + QMenu *cockatriceMenu; QAction *aConnect, *aDisconnect, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aSettings, *aExit; QAction *aCloseMostRecentZoneView; QVBoxLayout *viewLayout; diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index 5eee6e8d..4a96809e 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -368,33 +368,38 @@ &Spieler: - + + &Spectators allowed + &Zuschauer zugelassen + + + &OK &OK - + &Cancel &Abbruch - + Create game Spiel erstellen - - + + Error Fehler - + Invalid number of players. Ungültige Anzahl an Spielern. - + XXX XXX @@ -691,12 +696,12 @@ F10 - + Set life Setze Leben - + New life total: Neues Leben insgesammt: @@ -705,7 +710,7 @@ Würfeln - + Number of sides: Anzahl der Seiten: @@ -714,12 +719,12 @@ Karten ziehen - + Number: Anzahl: - + Create token Token erstellen @@ -729,17 +734,17 @@ &Würfeln... - + Roll die Würfeln - + Name: Name: - + Set counters Setze Zählmarke @@ -747,35 +752,40 @@ GameSelector - + C&reate Spiel e&rstellen - + &Join &Teilnehmen - + Error Fehler - + XXX XXX - + Join game Spiel beitreten - + Password: Passwort: + + + J&oin as spectator + &Zuschauen + GamesModel @@ -973,37 +983,36 @@ Verbinde zu %1... - Connected. - Verbunden. + Verbunden. - + Disconnected from server. Verbindung zum Server getrennt. - + Invalid password. Ungültiges Passwort. - + You have joined the game. Player list: Du bist dem Spiel beigetreten. Spielerliste: - + %1 has joined the game %1 ist dem Spiel beigetreten - + %1 has left the game %1 hat das Spiel verlassen - + %1 is ready to start a new game. %1 ist bereit ein neues Spiel zu starten. @@ -1028,7 +1037,7 @@ %1 zieht %2 Karten - + a card eine Karte @@ -1085,12 +1094,12 @@ %1s Sideboard - + The game has started. Das Spiel hat begonnen. - + %1 shuffles his library. %1 mischt seine Bibliothek. @@ -1099,117 +1108,137 @@ %1 würfelt eine %2 mit einem %3-seitigen Würfel. - + + Connected: %1 + Verbunden: %1 + + + + Protocol version mismatch. + Protokollversion stimmt nicht überein. + + + + %1 is now watching the game. + %1 schaut nun dem Spiel zu. + + + + %1 is not watching the game any more. + %1 schaut dem Spiel nicht mehr zu. + + + %1 rolls a %2 with a %3-sided die. %1 würfelt eine %2 mit einem %3-seitigen Würfel. - + %1 draws a card. %1 zieht eine Karte. - + %1 draws %2 cards. %1 zieht %2 Karten. - + from table vom Spielfeld - + from graveyard aus dem Friedhof - + from exile aus dem Exil - + from hand von der Hand - + the bottom card of his library die unterste Karte seiner Bibliothek - + from the bottom of his library , die unterste Karte seiner Bibliothek, - + the top card of his library die oberste Karte seiner Bibliothek - + from the top of his library , die oberste Karte seiner Bibliothek, - + from library aus der Bibliothek - + from sideboard aus dem Sideboard - + %1 puts %2 into play%3. %1 bringt %2%3 ins Spiel. - + %1 puts %2%3 into graveyard. %1 legt %2%3 auf den Friedhof. - + %1 exiles %2%3. %1 schickt %2%3 ins Exil. - + %1 moves %2%3 to hand. %1 nimmt %2%3 auf die Hand. - + %1 puts %2%3 into his library. %1 legt %2%3 in seine Bibliothek. - + %1 puts %2%3 on bottom of his library. %1 legt %2%3 unter seine Bibliothek. - + %1 puts %2%3 on top of his library. %1 legt %2%3 auf die Bibliothek. - + %1 puts %2%3 into his library at position %4. %1 legt %2%3 in seine Bibliothek an %4. Stelle. - + %1 moves %2%3 to sideboard. %1 legt %2%3 in sein Sideboard. - + %1 is looking at the top %2 cards %3. %1 sieht sich die obersten %2 Karten %3 an. @@ -1294,27 +1323,27 @@ %1 legt %2%3in sein Sideboard. - + %1 creates token: %2. %1 erstellt Token: %2. - + %1 places %2 counters on %3 (now %4). %1 legt %2 Zählmarken auf %3 (jetzt %4). - + %1 removes %2 counters from %3 (now %4). %1 entfernt %2 Zählmarken von %3 (jetzt %4). - + %1 %2 %3. %1 %2 %3. - + %1 sets counter "%2" to %3 (%4%5). %1 setzt Zählmarke "%2" auf %3 (%4%5). @@ -1323,17 +1352,17 @@ %1 sieht sich die obersten %2 Karten %3 an. - + %1 is looking at %2. %1 sieht sich %2 an. - + %1 stops looking at %2. %1 sieht sich %2 nicht mehr an. - + ending phase die Zugendphase @@ -1362,57 +1391,57 @@ %1 sieht sich %2s %3 nicht mehr an - + It is now %1's turn. %1 ist am Zug. - + untap step das Enttappsegment - + upkeep step das Versorgungssegment - + draw step das Ziehsegment - + first main phase die erste Hauptphase - + beginning of combat step das Anfangssegment der Kampfphase - + declare attackers step das Angreifer-Deklarieren-Segment - + declare blockers step das Blocker-Deklarieren-Segment - + combat damage step das Kampfschadenssegment - + end of combat step das Endsegment der Kampfphase - + second main phase die zweite Hauptphase @@ -1421,7 +1450,7 @@ das Ende-des-Zuges-Segment - + It is now the %1. Es ist nun %1. @@ -1430,12 +1459,12 @@ %1 bewegt %2 %3 nach %4 - + taps tappt - + untaps enttappt @@ -1460,7 +1489,7 @@ %1 entfernt %2 Zählmarken von %3 (jetzt %4) - + his permanents seine bleibenden Karten @@ -1473,12 +1502,12 @@ %1 setzt Zähler "%2" auf %3 (%4%5) - + %1 sets %2 to not untap normally. %1 setzt %2 auf explizites Enttappen. - + %1 sets %2 to untap normally. %1 setzt %2 auf normales Enttappen. @@ -1907,12 +1936,12 @@ Willst du die Änderungen speichern? ZoneViewWidget - + sort alphabetically alphabetisch sortieren - + shuffle when closing beim Schließen mischen diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index 3fc86aff..217b2e83 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -333,33 +333,38 @@ - + + &Spectators allowed + + + + &OK - + &Cancel - + Create game - - + + Error - + Invalid number of players. - + XXX @@ -593,27 +598,27 @@ - + Set life - + New life total: - + Number of sides: - + Number: - + Create token @@ -623,17 +628,17 @@ - + Roll die - + Name: - + Set counters @@ -641,35 +646,40 @@ GameSelector - + C&reate - + &Join - + Error - + XXX - + Join game - + Password: + + + J&oin as spectator + + GamesModel @@ -867,292 +877,307 @@ - - Connected. - - - - + Disconnected from server. - + Invalid password. - + + Protocol version mismatch. + + + + You have joined the game. Player list: - + %1 has joined the game - + %1 has left the game - + + %1 is now watching the game. + + + + + %1 is not watching the game any more. + + + + %1 is ready to start a new game. - + %1 rolls a %2 with a %3-sided die. - + from table - + from graveyard - + from exile - + from hand - + the bottom card of his library - + from the bottom of his library - + the top card of his library - + from the top of his library - + from library - + from sideboard - + %1 puts %2 into play%3. - + %1 puts %2%3 into graveyard. - + %1 exiles %2%3. - + %1 moves %2%3 to hand. - + %1 puts %2%3 into his library. - + %1 puts %2%3 on bottom of his library. - + %1 puts %2%3 on top of his library. - + %1 puts %2%3 into his library at position %4. - + %1 moves %2%3 to sideboard. - + a card - + %1 is looking at the top %2 cards %3. - + The game has started. - + %1 draws a card. - + %1 draws %2 cards. - + %1 creates token: %2. - + %1 places %2 counters on %3 (now %4). - + %1 removes %2 counters from %3 (now %4). - + %1 %2 %3. - + %1 sets counter "%2" to %3 (%4%5). - + %1 is looking at %2. - + %1 stops looking at %2. - + ending phase - + It is now %1's turn. - + + Connected: %1 + + + + %1 shuffles his library. - + untap step - + upkeep step - + draw step - + first main phase - + beginning of combat step - + declare attackers step - + declare blockers step - + combat damage step - + end of combat step - + second main phase - + It is now the %1. - + taps - + untaps - + %1 sets %2 to not untap normally. - + %1 sets %2 to untap normally. - + his permanents @@ -1552,12 +1577,12 @@ Do you want to save the changes? ZoneViewWidget - + sort alphabetically - + shuffle when closing diff --git a/servatrice/src/servergame.cpp b/servatrice/src/servergame.cpp index bfb3f7b3..f9936a87 100644 --- a/servatrice/src/servergame.cpp +++ b/servatrice/src/servergame.cpp @@ -44,27 +44,16 @@ QString ServerGame::getGameListLine() const .arg(players.size()) .arg(maxPlayers) .arg(creator->getPlayerName()) - .arg(spectatorsAllowed ? 0 : 1) + .arg(spectatorsAllowed ? 1 : 0) .arg(spectators.size()); } -QStringList ServerGame::getPlayerNames() const -{ - QStringList result; - QListIterator i(players); - while (i.hasNext()) { - ServerSocket *tmp = i.next(); - result << QString("%1|%2").arg(tmp->getPlayerId()).arg(tmp->getPlayerName()); - } - return result; -} - -ServerSocket *ServerGame::getPlayer(int player_id) +ServerSocket *ServerGame::getPlayer(int playerId) { QListIterator i(players); while (i.hasNext()) { ServerSocket *tmp = i.next(); - if (tmp->getPlayerId() == player_id) + if (tmp->getPlayerId() == playerId) return tmp; } return NULL; @@ -72,9 +61,10 @@ ServerSocket *ServerGame::getPlayer(int player_id) void ServerGame::msg(const QString &s) { - QListIterator i(players); - while (i.hasNext()) - i.next()->msg(s); + for (int i = 0; i < players.size(); ++i) + players[i]->msg(s); + for (int i = 0; i < spectators.size(); ++i) + spectators[i]->msg(s); } void ServerGame::broadcastEvent(const QString &cmd, ServerSocket *player) @@ -139,7 +129,6 @@ void ServerGame::addPlayer(ServerSocket *player, bool spectator) max = tmp; } player->setPlayerId(max + 1); - player->msg(QString("private|||player_id|%1|%2").arg(max + 1).arg(player->getPlayerName())); } else player->setPlayerId(-1); diff --git a/servatrice/src/servergame.h b/servatrice/src/servergame.h index 21c13c3c..f7f02953 100644 --- a/servatrice/src/servergame.h +++ b/servatrice/src/servergame.h @@ -48,14 +48,14 @@ public: ServerSocket *getCreator() const { return creator; } bool getGameStarted() const { return gameStarted; } int getPlayerCount() const { return players.size(); } + const QList &getPlayers() const { return players; } int getGameId() const { return gameId; } QString getDescription() const { return description; } QString getPassword() const { return password; } int getMaxPlayers() const { return maxPlayers; } bool getSpectatorsAllowed() const { return spectatorsAllowed; } QString getGameListLine() const; - QStringList getPlayerNames() const; - ServerSocket *getPlayer(int player_id); + ServerSocket *getPlayer(int playerId); ReturnMessage::ReturnCode checkJoin(const QString &_password, bool spectator); void addPlayer(ServerSocket *player, bool spectator); void removePlayer(ServerSocket *player); diff --git a/servatrice/src/serversocket.cpp b/servatrice/src/serversocket.cpp index 99ef1bc8..d9928628 100644 --- a/servatrice/src/serversocket.cpp +++ b/servatrice/src/serversocket.cpp @@ -353,7 +353,12 @@ ReturnMessage::ReturnCode ServerSocket::cmdLeaveGame(const QList &/*pa ReturnMessage::ReturnCode ServerSocket::cmdListPlayers(const QList &/*params*/) { - remsg->sendList(game->getPlayerNames()); + QStringList result; + const QList &players = game->getPlayers(); + for (int i = 0; i < players.size(); ++i) + result << QString("%1|%2|%3").arg(players[i]->getPlayerId()).arg(players[i]->getPlayerName()).arg(players[i] == this ? 1 : 0); + + remsg->sendList(result); return ReturnMessage::ReturnOk; } @@ -398,7 +403,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdDrawCards(const QList ¶ Card *card = deck->cards.first(); deck->cards.removeFirst(); hand->cards.append(card); - msg(QString("private|||draw|%1|%2").arg(card->getId()).arg(card->getName())); + privateEvent(QString("draw|%1|%2").arg(card->getId()).arg(card->getName())); } emit broadcastEvent(QString("draw|%1").arg(number), this); @@ -467,7 +472,7 @@ ReturnMessage::ReturnCode ServerSocket::cmdMoveCard(const QList ¶m privateCardId = QString(); privateCardName = QString(); } - msg(QString("private|||move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(privateCardId) + privateEvent(QString("move_card|%1|%2|%3|%4|%5|%6|%7|%8").arg(privateCardId) .arg(privateCardName) .arg(startzone->getName()) .arg(position) @@ -773,14 +778,9 @@ bool ServerSocket::parseCommand(QString line) return remsg->send(ReturnMessage::ReturnSyntaxError); } -PlayerStatusEnum ServerSocket::getStatus() +void ServerSocket::privateEvent(const QString &line) { - return PlayerStatus; -} - -void ServerSocket::setStatus(PlayerStatusEnum status) -{ - PlayerStatus = status; + msg(QString("private|%1|%2|%3").arg(playerId).arg(playerName).arg(line)); } void ServerSocket::setGame(ServerGame *g) @@ -812,7 +812,7 @@ QStringList ServerSocket::listZones() const void ServerSocket::msg(const QString &s) { - qDebug(QString(">>> %1").arg(s).toLatin1()); + qDebug(QString("OUT id=%1 name=%2 >>> %3").arg(playerId).arg(playerName).arg(s).toLatin1()); QTextStream stream(this); stream.setCodec("UTF-8"); stream << s << endl; diff --git a/servatrice/src/serversocket.h b/servatrice/src/serversocket.h index 7d4ebaee..f1e504a3 100644 --- a/servatrice/src/serversocket.h +++ b/servatrice/src/serversocket.h @@ -107,6 +107,7 @@ private: void clearZones(); void leaveGame(); bool parseCommand(QString line); + void privateEvent(const QString &line); PlayerStatusEnum PlayerStatus; ReturnMessage *remsg; AuthenticationResult authState; @@ -117,8 +118,8 @@ public: ~ServerSocket(); void msg(const QString &s); void setGame(ServerGame *g); - PlayerStatusEnum getStatus(); - void setStatus(PlayerStatusEnum status); + PlayerStatusEnum getStatus() { return PlayerStatus; } + void setStatus(PlayerStatusEnum _status) { PlayerStatus = _status; } void initConnection(); int getPlayerId() const { return playerId; } void setPlayerId(int _id) { playerId = _id; }