From c4eb7ba6cf44385f0594c416ad7477c286ed638b Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Fri, 30 Dec 2011 22:29:57 +0100 Subject: [PATCH] PB: more client files compile --- cockatrice/src/carddragitem.cpp | 1 + cockatrice/src/carditem.cpp | 1 - cockatrice/src/cardzone.cpp | 4 +-- cockatrice/src/cardzone.h | 1 - cockatrice/src/gameselector.cpp | 34 +++++++++--------- cockatrice/src/gameselector.h | 9 ++--- cockatrice/src/gamesmodel.cpp | 54 ++++++++++++----------------- cockatrice/src/gamesmodel.h | 6 ++-- cockatrice/src/messagelogwidget.cpp | 15 ++++---- cockatrice/src/messagelogwidget.h | 3 +- cockatrice/src/playerlistwidget.cpp | 40 ++++++++++----------- cockatrice/src/playerlistwidget.h | 4 +-- cockatrice/src/selectzone.cpp | 2 ++ cockatrice/src/tab_deck_storage.cpp | 38 ++++++++++---------- cockatrice/src/tab_deck_storage.h | 14 ++++---- cockatrice/src/window_main.cpp | 12 +++---- cockatrice/src/window_main.h | 4 +-- common/server.h | 2 +- 18 files changed, 120 insertions(+), 124 deletions(-) diff --git a/cockatrice/src/carddragitem.cpp b/cockatrice/src/carddragitem.cpp index df0e52bc..8df7790b 100644 --- a/cockatrice/src/carddragitem.cpp +++ b/cockatrice/src/carddragitem.cpp @@ -1,4 +1,5 @@ #include "carddragitem.h" +#include "carditem.h" #include "cardzone.h" #include "tablezone.h" #include "zoneviewzone.h" diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index 61bd9a0f..a0590188 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -12,7 +12,6 @@ #include "player.h" #include "arrowitem.h" #include "main.h" -#include "protocol_datastructures.h" #include "settingscache.h" #include "tab_game.h" diff --git a/cockatrice/src/cardzone.cpp b/cockatrice/src/cardzone.cpp index 663b02f4..284e6696 100644 --- a/cockatrice/src/cardzone.cpp +++ b/cockatrice/src/cardzone.cpp @@ -6,8 +6,8 @@ #include "carditem.h" #include "player.h" #include "zoneviewzone.h" -#include "protocol_datastructures.h" #include "pb/command_move_card.pb.h" +#include "pb/serverinfo_user.pb.h" CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool isView) : AbstractGraphicsItem(parent), player(_p), name(_name), cards(_contentsKnown), view(NULL), menu(NULL), doubleClickAction(0), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable) @@ -47,7 +47,7 @@ void CardZone::clearContents() QString CardZone::getTranslatedName(bool hisOwn, GrammaticalCase gc) const { QString ownerName = player->getName(); - bool female = player->getUserInfo()->getGender() == ServerInfo_User::Female; + bool female = player->getUserInfo()->gender() == ServerInfo_User::Female; if (name == "hand") switch (gc) { case CaseNominative: return female ? (hisOwn ? tr("her hand", "nominative, female owner") : tr("%1's hand", "nominative, female owner").arg(ownerName)) : (hisOwn ? tr("his hand", "nominative, male owner") : tr("%1's hand", "nominative, male owner").arg(ownerName)); diff --git a/cockatrice/src/cardzone.h b/cockatrice/src/cardzone.h index 31955b15..1f2ddfee 100644 --- a/cockatrice/src/cardzone.h +++ b/cockatrice/src/cardzone.h @@ -3,7 +3,6 @@ #include #include "cardlist.h" -#include "carditem.h" #include "abstractgraphicsitem.h" #include "translation.h" diff --git a/cockatrice/src/gameselector.cpp b/cockatrice/src/gameselector.cpp index 858f3e99..f1f6877e 100644 --- a/cockatrice/src/gameselector.cpp +++ b/cockatrice/src/gameselector.cpp @@ -10,9 +10,10 @@ #include "dlg_creategame.h" #include "gameselector.h" #include "gamesmodel.h" - +#include "tab_room.h" #include "pending_command.h" #include "pb/room_commands.pb.h" +#include "pb/serverinfo_game.pb.h" GameSelector::GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap &_rooms, const QMap &_gameTypes, QWidget *parent) : QGroupBox(parent), client(_client), tabSupervisor(_tabSupervisor), room(_room) @@ -89,7 +90,7 @@ void GameSelector::actCreate() dlg.exec(); } -void GameSelector::checkResponse(ResponseCode response) +void GameSelector::checkResponse(Response::ResponseCode response) { if (createButton) createButton->setEnabled(true); @@ -97,14 +98,14 @@ void GameSelector::checkResponse(ResponseCode response) spectateButton->setEnabled(true); switch (response) { - case RespNotInRoom: QMessageBox::critical(this, tr("Error"), tr("Please join the appropriate room first.")); break; - case RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Wrong password.")); break; - case RespSpectatorsNotAllowed: QMessageBox::critical(this, tr("Error"), tr("Spectators are not allowed in this game.")); break; - case RespGameFull: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break; - case RespNameNotFound: QMessageBox::critical(this, tr("Error"), tr("The game does not exist any more.")); break; - case RespUserLevelTooLow: QMessageBox::critical(this, tr("Error"), tr("This game is only open to registered users.")); break; - case RespOnlyBuddies: QMessageBox::critical(this, tr("Error"), tr("This game is only open to its creator's buddies.")); break; - case RespInIgnoreList: QMessageBox::critical(this, tr("Error"), tr("You are being ignored by the creator of this game.")); break; + case Response::RespNotInRoom: QMessageBox::critical(this, tr("Error"), tr("Please join the appropriate room first.")); break; + case Response::RespWrongPassword: QMessageBox::critical(this, tr("Error"), tr("Wrong password.")); break; + case Response::RespSpectatorsNotAllowed: QMessageBox::critical(this, tr("Error"), tr("Spectators are not allowed in this game.")); break; + case Response::RespGameFull: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break; + case Response::RespNameNotFound: QMessageBox::critical(this, tr("Error"), tr("The game does not exist any more.")); break; + case Response::RespUserLevelTooLow: QMessageBox::critical(this, tr("Error"), tr("This game is only open to registered users.")); break; + case Response::RespOnlyBuddies: QMessageBox::critical(this, tr("Error"), tr("This game is only open to its creator's buddies.")); break; + case Response::RespInIgnoreList: QMessageBox::critical(this, tr("Error"), tr("You are being ignored by the creator of this game.")); break; default: ; } } @@ -116,10 +117,10 @@ void GameSelector::actJoin() QModelIndex ind = gameListView->currentIndex(); if (!ind.isValid()) return; - ServerInfo_Game *game = gameListModel->getGame(ind.data(Qt::UserRole).toInt()); + const ServerInfo_Game &game = gameListModel->getGame(ind.data(Qt::UserRole).toInt()); bool overrideRestrictions = !tabSupervisor->getAdminLocked(); QString password; - if (game->getHasPassword() && !(spectator && !game->getSpectatorsNeedPassword()) && !overrideRestrictions) { + if (game.with_password() && !(spectator && !game.spectators_need_password()) && !overrideRestrictions) { bool ok; password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok); if (!ok) @@ -127,19 +128,19 @@ void GameSelector::actJoin() } Command_JoinGame cmd; - cmd.set_game_id(game->getGameId()); + cmd.set_game_id(game.game_id()); cmd.set_password(password.toStdString()); cmd.set_spectator(spectator); cmd.set_override_restrictions(overrideRestrictions); - TabRoom *r = tabSupervisor->getRoomTabs().value(game->getRoomId()); + TabRoom *r = tabSupervisor->getRoomTabs().value(game.room_id()); if (!r) { QMessageBox::critical(this, tr("Error"), tr("Please join the respective room first.")); return; } PendingCommand *pend = r->prepareRoomCommand(cmd); - connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode))); + connect(pend, SIGNAL(finished(Response::ResponseCode)), this, SLOT(checkResponse(Response::ResponseCode))); r->sendRoomCommand(pend); if (createButton) @@ -159,8 +160,7 @@ void GameSelector::retranslateUi() spectateButton->setText(tr("J&oin as spectator")); } -void GameSelector::processGameInfo(ServerInfo_Game *info) +void GameSelector::processGameInfo(const ServerInfo_Game &info) { gameListModel->updateGameList(info); } - diff --git a/cockatrice/src/gameselector.h b/cockatrice/src/gameselector.h index 16fc2d7d..797243d2 100644 --- a/cockatrice/src/gameselector.h +++ b/cockatrice/src/gameselector.h @@ -2,9 +2,9 @@ #define GAMESELECTOR_H #include -#include "protocol_datastructures.h" -#include "tab_room.h" +//#include "tab_room.h" #include "gametypemap.h" +#include "pb/response.pb.h" class QTreeView; class GamesModel; @@ -14,6 +14,7 @@ class QCheckBox; class AbstractClient; class TabSupervisor; class TabRoom; +class ServerInfo_Game; class GameSelector : public QGroupBox { Q_OBJECT @@ -22,7 +23,7 @@ private slots: void showRunningGamesChanged(int state); void actCreate(); void actJoin(); - void checkResponse(ResponseCode response); + void checkResponse(Response::ResponseCode response); signals: void gameJoined(int gameId); private: @@ -38,7 +39,7 @@ private: public: GameSelector(AbstractClient *_client, TabSupervisor *_tabSupervisor, TabRoom *_room, const QMap &_rooms, const QMap &_gameTypes, QWidget *parent = 0); void retranslateUi(); - void processGameInfo(ServerInfo_Game *info); + void processGameInfo(const ServerInfo_Game &info); }; #endif \ No newline at end of file diff --git a/cockatrice/src/gamesmodel.cpp b/cockatrice/src/gamesmodel.cpp index 031c4207..cd893746 100644 --- a/cockatrice/src/gamesmodel.cpp +++ b/cockatrice/src/gamesmodel.cpp @@ -1,5 +1,6 @@ #include "gamesmodel.h" -#include "protocol_datastructures.h" +#include "pb/serverinfo_game.pb.h" +#include GamesModel::GamesModel(const QMap &_rooms, const QMap &_gameTypes, QObject *parent) : QAbstractTableModel(parent), rooms(_rooms), gameTypes(_gameTypes) @@ -10,8 +11,6 @@ GamesModel::~GamesModel() { if (!gameList.isEmpty()) { beginRemoveRows(QModelIndex(), 0, gameList.size() - 1); - for (int i = 0; i < gameList.size(); ++i) - delete gameList[i]; gameList.clear(); endRemoveRows(); } @@ -28,30 +27,29 @@ QVariant GamesModel::data(const QModelIndex &index, int role) const if ((index.row() >= gameList.size()) || (index.column() >= columnCount())) return QVariant(); - ServerInfo_Game *g = gameList[index.row()]; + const ServerInfo_Game &g = gameList[index.row()]; switch (index.column()) { - case 0: return g->getDescription(); - case 1: return rooms.value(g->getRoomId()); - case 2: return g->getCreatorInfo()->getName(); + case 0: return QString::fromStdString(g.description()); + case 1: return rooms.value(g.room_id()); + case 2: return QString::fromStdString(g.creator_info().name()); case 3: { QStringList result; - QList gameTypeList = g->getGameTypes(); - GameTypeMap gameTypeMap = gameTypes.value(g->getRoomId()); - for (int i = 0; i < gameTypeList.size(); ++i) - result.append(gameTypeMap.value(gameTypeList[i]->getData())); + GameTypeMap gameTypeMap = gameTypes.value(g.room_id()); + for (int i = g.game_types_size() - 1; i >= 0; --i) + result.append(gameTypeMap.value(g.game_types(i))); return result.join(", "); } - case 4: return g->getHasPassword() ? (g->getSpectatorsNeedPassword() ? tr("yes") : tr("yes, free for spectators")) : tr("no"); + case 4: return g.with_password() ? (g.spectators_need_password() ? tr("yes") : tr("yes, free for spectators")) : tr("no"); case 5: { QStringList result; - if (g->getOnlyBuddies()) + if (g.only_buddies()) result.append(tr("buddies only")); - if (g->getOnlyRegistered()) + if (g.only_registered()) result.append(tr("reg. users only")); return result.join(", "); } - case 6: return QString("%1/%2").arg(g->getPlayerCount()).arg(g->getMaxPlayers()); - case 7: return g->getSpectatorsAllowed() ? QVariant(g->getSpectatorCount()) : QVariant(tr("not allowed")); + case 6: return QString("%1/%2").arg(g.player_count()).arg(g.max_players()); + case 7: return g.spectators_allowed() ? QVariant(g.spectators_count()) : QVariant(tr("not allowed")); default: return QVariant(); } } @@ -73,33 +71,27 @@ QVariant GamesModel::headerData(int section, Qt::Orientation orientation, int ro } } -ServerInfo_Game *GamesModel::getGame(int row) +const ServerInfo_Game &GamesModel::getGame(int row) { Q_ASSERT(row < gameList.size()); return gameList[row]; } -void GamesModel::updateGameList(ServerInfo_Game *_game) +void GamesModel::updateGameList(const ServerInfo_Game &game) { - QList gameTypeList, oldGameTypeList = _game->getGameTypes(); - for (int i = 0; i < oldGameTypeList.size(); ++i) - gameTypeList.append(new GameTypeId(oldGameTypeList[i]->getData())); - - ServerInfo_Game *game = new ServerInfo_Game(_game->getRoomId(), _game->getGameId(), _game->getDescription(), _game->getHasPassword(), _game->getPlayerCount(), _game->getMaxPlayers(), _game->getStarted(), gameTypeList, new ServerInfo_User(_game->getCreatorInfo()), _game->getOnlyBuddies(), _game->getOnlyRegistered(), _game->getSpectatorsAllowed(), _game->getSpectatorsNeedPassword(), _game->getSpectatorCount()); for (int i = 0; i < gameList.size(); i++) - if (gameList[i]->getGameId() == game->getGameId()) { - if (game->getPlayerCount() == 0) { + if (gameList[i].game_id() == game.game_id()) { + if (!game.has_player_count()) { beginRemoveRows(QModelIndex(), i, i); - delete gameList.takeAt(i); + gameList.removeAt(i); endRemoveRows(); } else { - delete gameList[i]; gameList[i] = game; emit dataChanged(index(i, 0), index(i, 7)); } return; } - if (game->getPlayerCount() == 0) + if (game.player_count() <= 0) return; beginInsertRows(QModelIndex(), gameList.size(), gameList.size()); gameList.append(game); @@ -130,10 +122,10 @@ bool GamesProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &/*sourc if (!model) return false; - ServerInfo_Game *game = model->getGame(sourceRow); - if ((game->getPlayerCount() == game->getMaxPlayers()) && !fullGamesVisible) + const ServerInfo_Game &game = model->getGame(sourceRow); + if ((game.player_count() == game.max_players()) && !fullGamesVisible) return false; - if (game->getStarted() && !runningGamesVisible) + if (game.started() && !runningGamesVisible) return false; return true; diff --git a/cockatrice/src/gamesmodel.h b/cockatrice/src/gamesmodel.h index 8461faf6..059d257e 100644 --- a/cockatrice/src/gamesmodel.h +++ b/cockatrice/src/gamesmodel.h @@ -11,7 +11,7 @@ class ServerInfo_Game; class GamesModel : public QAbstractTableModel { Q_OBJECT private: - QList gameList; + QList gameList; QMap rooms; QMap gameTypes; public: @@ -22,8 +22,8 @@ public: QVariant data(const QModelIndex &index, int role) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; - ServerInfo_Game *getGame(int row); - void updateGameList(ServerInfo_Game *game); + const ServerInfo_Game &getGame(int row); + void updateGameList(const ServerInfo_Game &game); }; class GamesProxyModel : public QSortFilterProxyModel { diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index 9fa1518a..df8a82a0 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -1,8 +1,10 @@ #include "messagelogwidget.h" #include "player.h" #include "cardzone.h" -#include "protocol_items.h" #include "soundengine.h" +#include "pb/serverinfo_user.pb.h" +#include "pb/context_move_card.pb.h" +#include "pb/context_mulligan.pb.h" #include QString MessageLogWidget::sanitizeHtml(QString dirty) const @@ -15,7 +17,7 @@ QString MessageLogWidget::sanitizeHtml(QString dirty) const bool MessageLogWidget::isFemale(Player *player) const { - return player->getUserInfo()->getGender() == ServerInfo_User::Female; + return player->getUserInfo()->gender() == ServerInfo_User::Female; } void MessageLogWidget::logGameJoined(int gameId) @@ -728,14 +730,15 @@ void MessageLogWidget::logSetActivePhase(int phase) appendHtml("" + tr("It is now the %1.").arg(phaseName) + ""); } -void MessageLogWidget::containerProcessingStarted(GameEventContext *_context) +void MessageLogWidget::containerProcessingStarted(const GameEventContext &_context) { - if (qobject_cast(_context)) + if (_context.HasExtension(Context_MoveCard::ext)) currentContext = MessageContext_MoveCard; - else if (qobject_cast(_context)) { + else if (_context.HasExtension(Context_Mulligan::ext)) { + const Context_Mulligan &contextMulligan = _context.GetExtension(Context_Mulligan::ext); currentContext = MessageContext_Mulligan; mulliganPlayer = 0; - mulliganNumber = static_cast(_context)->getNumber(); + mulliganNumber = contextMulligan.number(); } } diff --git a/cockatrice/src/messagelogwidget.h b/cockatrice/src/messagelogwidget.h index b472dbd4..0d5ac7ef 100644 --- a/cockatrice/src/messagelogwidget.h +++ b/cockatrice/src/messagelogwidget.h @@ -4,7 +4,6 @@ #include "chatview.h" #include #include "translation.h" -#include "protocol_datastructures.h" class Player; class CardZone; @@ -78,7 +77,7 @@ public slots: void logRevealCards(Player *player, CardZone *zone, int cardId, QString cardName, Player *otherPlayer); void logSetActivePlayer(Player *player); void logSetActivePhase(int phase); - void containerProcessingStarted(GameEventContext *context); + void containerProcessingStarted(const GameEventContext &context); void containerProcessingDone(); public: void connectToPlayer(Player *player); diff --git a/cockatrice/src/playerlistwidget.cpp b/cockatrice/src/playerlistwidget.cpp index 1e0a4b7d..ea04668a 100644 --- a/cockatrice/src/playerlistwidget.cpp +++ b/cockatrice/src/playerlistwidget.cpp @@ -1,12 +1,10 @@ #include #include "playerlistwidget.h" -#include "protocol_datastructures.h" #include "pixmapgenerator.h" #include "abstractclient.h" #include "tab_game.h" #include "tab_supervisor.h" #include "tab_userlists.h" -#include "protocol_items.h" #include "userlist.h" #include "userinfobox.h" #include @@ -15,6 +13,7 @@ #include "pb/session_commands.pb.h" #include "pb/command_kick_from_game.pb.h" +#include "pb/serverinfo_playerproperties.pb.h" PlayerListItemDelegate::PlayerListItemDelegate(QObject *const parent) : QStyledItemDelegate(parent) @@ -73,34 +72,35 @@ void PlayerListWidget::retranslateUi() { } -void PlayerListWidget::addPlayer(ServerInfo_PlayerProperties *player) +void PlayerListWidget::addPlayer(const ServerInfo_PlayerProperties &player) { QTreeWidgetItem *newPlayer = new PlayerListTWI; - players.insert(player->getPlayerId(), newPlayer); + players.insert(player.player_id(), newPlayer); updatePlayerProperties(player); addTopLevelItem(newPlayer); sortItems(1, Qt::AscendingOrder); } -void PlayerListWidget::updatePlayerProperties(ServerInfo_PlayerProperties *prop) +void PlayerListWidget::updatePlayerProperties(const ServerInfo_PlayerProperties &prop) { - QTreeWidgetItem *player = players.value(prop->getPlayerId(), 0); + QTreeWidgetItem *player = players.value(prop.player_id(), 0); if (!player) return; - player->setIcon(1, prop->getSpectator() ? spectatorIcon : playerIcon); - player->setData(1, Qt::UserRole, !prop->getSpectator()); - player->setData(2, Qt::UserRole, prop->getConceded()); - player->setData(2, Qt::UserRole + 1, prop->getReadyStart()); - player->setIcon(2, gameStarted ? (prop->getConceded() ? concededIcon : QIcon()) : (prop->getReadyStart() ? readyIcon : notReadyIcon)); - player->setData(3, Qt::UserRole, prop->getUserInfo()->getUserLevel()); - player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, prop->getUserInfo()->getUserLevel()))); - player->setText(4, prop->getUserInfo()->getName()); - if (!prop->getUserInfo()->getCountry().isEmpty()) - player->setIcon(4, QIcon(CountryPixmapGenerator::generatePixmap(12, prop->getUserInfo()->getCountry()))); - player->setData(4, Qt::UserRole, prop->getUserInfo()->getName()); - player->setData(4, Qt::UserRole + 1, prop->getPlayerId()); - player->setText(5, prop->getDeckHash()); + player->setIcon(1, prop.spectator() ? spectatorIcon : playerIcon); + player->setData(1, Qt::UserRole, !prop.spectator()); + player->setData(2, Qt::UserRole, prop.conceded()); + player->setData(2, Qt::UserRole + 1, prop.ready_start()); + player->setIcon(2, gameStarted ? (prop.conceded() ? concededIcon : QIcon()) : (prop.ready_start() ? readyIcon : notReadyIcon)); + player->setData(3, Qt::UserRole, prop.user_info().user_level()); + player->setIcon(3, QIcon(UserLevelPixmapGenerator::generatePixmap(12, prop.user_info().user_level()))); + player->setText(4, QString::fromStdString(prop.user_info().name())); + const QString country = QString::fromStdString(prop.user_info().country()); + if (!country.isEmpty()) + player->setIcon(4, QIcon(CountryPixmapGenerator::generatePixmap(12, country))); + player->setData(4, Qt::UserRole, QString::fromStdString(prop.user_info().name())); + player->setData(4, Qt::UserRole + 1, prop.player_id()); + player->setText(5, QString::fromStdString(prop.deck_hash())); } void PlayerListWidget::removePlayer(int playerId) @@ -185,7 +185,7 @@ void PlayerListWidget::showContextMenu(const QPoint &pos, const QModelIndex &ind menu->addSeparator(); menu->addAction(aKick); } - if (userName == game->getTabSupervisor()->getUserInfo()->getName()) { + if (userName == QString::fromStdString(game->getTabSupervisor()->getUserInfo()->name())) { aChat->setEnabled(false); aAddToBuddyList->setEnabled(false); aRemoveFromBuddyList->setEnabled(false); diff --git a/cockatrice/src/playerlistwidget.h b/cockatrice/src/playerlistwidget.h index d2d956d8..dc25404b 100644 --- a/cockatrice/src/playerlistwidget.h +++ b/cockatrice/src/playerlistwidget.h @@ -38,11 +38,11 @@ signals: public: PlayerListWidget(TabSupervisor *_tabSupervisor, AbstractClient *_client, TabGame *_game, QWidget *parent = 0); void retranslateUi(); - void addPlayer(ServerInfo_PlayerProperties *player); + void addPlayer(const ServerInfo_PlayerProperties &player); void removePlayer(int playerId); void setActivePlayer(int playerId); void updatePing(int playerId, int pingTime); - void updatePlayerProperties(ServerInfo_PlayerProperties *prop); + void updatePlayerProperties(const ServerInfo_PlayerProperties &prop); void setGameStarted(bool _gameStarted, bool resuming); void showContextMenu(const QPoint &pos, const QModelIndex &index); }; diff --git a/cockatrice/src/selectzone.cpp b/cockatrice/src/selectzone.cpp index 729dfcc4..f7168b2e 100644 --- a/cockatrice/src/selectzone.cpp +++ b/cockatrice/src/selectzone.cpp @@ -1,7 +1,9 @@ #include #include "selectzone.h" #include "gamescene.h" +#include "carditem.h" #include + SelectZone::SelectZone(Player *_player, const QString &_name, bool _hasCardAttr, bool _isShufflable, bool _contentsKnown, QGraphicsItem *parent, bool isView) : CardZone(_player, _name, _hasCardAttr, _isShufflable, _contentsKnown, parent, isView) { diff --git a/cockatrice/src/tab_deck_storage.cpp b/cockatrice/src/tab_deck_storage.cpp index 5a027d7b..38259714 100644 --- a/cockatrice/src/tab_deck_storage.cpp +++ b/cockatrice/src/tab_deck_storage.cpp @@ -13,11 +13,11 @@ #include "remotedecklist_treewidget.h" #include "abstractclient.h" #include "decklist.h" -#include "protocol_items.h" #include "window_deckeditor.h" #include "settingscache.h" #include "pending_command.h" +#include "pb/response.pb.h" #include "pb/command_deck_upload.pb.h" #include "pb/command_deck_download.pb.h" #include "pb/command_deck_new_dir.pb.h" @@ -173,15 +173,15 @@ void TabDeckStorage::actUpload() client->sendCommand(pend); } -void TabDeckStorage::uploadFinished(ProtocolResponse *r) +void TabDeckStorage::uploadFinished(const Response &r) { - Response_DeckUpload *resp = qobject_cast(r); +/* Response_DeckUpload *resp = qobject_cast(r); if (!resp) return; const Command_DeckUpload &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_DeckUpload::ext)); serverDirView->addFileToTree(resp->getFile(), serverDirView->getNodeByPath(QString::fromStdString(cmd.path()))); -} +*/} void TabDeckStorage::actOpenRemoteDeck() { @@ -197,16 +197,16 @@ void TabDeckStorage::actOpenRemoteDeck() client->sendCommand(pend); } -void TabDeckStorage::openRemoteDeckFinished(ProtocolResponse *r) +void TabDeckStorage::openRemoteDeckFinished(const Response &r) { - Response_DeckDownload *resp = qobject_cast(r); +/* Response_DeckDownload *resp = qobject_cast(r); if (!resp) return; WndDeckEditor *deckEditor = new WndDeckEditor; deckEditor->setDeck(new DeckList(resp->getDeck())); deckEditor->show(); -} +*/} void TabDeckStorage::actDownload() { @@ -234,16 +234,16 @@ void TabDeckStorage::actDownload() client->sendCommand(pend); } -void TabDeckStorage::downloadFinished(ProtocolResponse *r) +void TabDeckStorage::downloadFinished(const Response &r) { - Response_DeckDownload *resp = qobject_cast(r); +/* Response_DeckDownload *resp = qobject_cast(r); if (!resp) return; PendingCommand *pend = static_cast(sender()); QString filePath = pend->getExtraData().toString(); resp->getDeck()->saveToFile(filePath, DeckList::CockatriceFormat); -} +*/} void TabDeckStorage::actNewFolder() { @@ -265,13 +265,13 @@ void TabDeckStorage::actNewFolder() cmd.set_dir_name(folderName.toStdString()); PendingCommand *pend = client->prepareSessionCommand(cmd); - connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(newFolderFinished(ResponseCode))); + connect(pend, SIGNAL(finished(Response::ResponseCode)), this, SLOT(newFolderFinished(Response::ResponseCode))); client->sendCommand(pend); } -void TabDeckStorage::newFolderFinished(ResponseCode resp) +void TabDeckStorage::newFolderFinished(Response::ResponseCode resp) { - if (resp != RespOk) + if (resp != Response::RespOk) return; const Command_DeckNewDir &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_DeckNewDir::ext)); @@ -292,20 +292,20 @@ void TabDeckStorage::actDelete() Command_DeckDelDir cmd; cmd.set_path(path.toStdString()); pend = client->prepareSessionCommand(cmd); - connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(deleteFolderFinished(ResponseCode))); + connect(pend, SIGNAL(finished(Response::ResponseCode)), this, SLOT(deleteFolderFinished(Response::ResponseCode))); } else { Command_DeckDel cmd; cmd.set_deck_id(dynamic_cast(curRight)->getId()); pend = client->prepareSessionCommand(cmd); - connect(pend, SIGNAL(finished(ResponseCode)), this, SLOT(deleteDeckFinished(ResponseCode))); + connect(pend, SIGNAL(finished(Response::ResponseCode)), this, SLOT(deleteDeckFinished(Response::ResponseCode))); } client->sendCommand(pend); } -void TabDeckStorage::deleteDeckFinished(ResponseCode resp) +void TabDeckStorage::deleteDeckFinished(Response::ResponseCode resp) { - if (resp != RespOk) + if (resp != Response::RespOk) return; const Command_DeckDel &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_DeckDel::ext)); @@ -314,9 +314,9 @@ void TabDeckStorage::deleteDeckFinished(ResponseCode resp) serverDirView->removeNode(toDelete); } -void TabDeckStorage::deleteFolderFinished(ResponseCode resp) +void TabDeckStorage::deleteFolderFinished(Response::ResponseCode resp) { - if (resp != RespOk) + if (resp != Response::RespOk) return; const Command_DeckDelDir &cmd = static_cast(static_cast(sender())->getCommandContainer().session_command(0).GetExtension(Command_DeckDelDir::ext)); diff --git a/cockatrice/src/tab_deck_storage.h b/cockatrice/src/tab_deck_storage.h index ac579724..88101981 100644 --- a/cockatrice/src/tab_deck_storage.h +++ b/cockatrice/src/tab_deck_storage.h @@ -2,7 +2,7 @@ #define TAB_DECK_STORAGE_H #include "tab.h" -#include "protocol.h" +#include "pb/response.pb.h" class AbstractClient; class QTreeView; @@ -31,20 +31,20 @@ private slots: void actOpenLocalDeck(); void actUpload(); - void uploadFinished(ProtocolResponse *r); + void uploadFinished(const Response &r); void actOpenRemoteDeck(); - void openRemoteDeckFinished(ProtocolResponse *r); + void openRemoteDeckFinished(const Response &r); void actDownload(); - void downloadFinished(ProtocolResponse *r); + void downloadFinished(const Response &r); void actNewFolder(); - void newFolderFinished(ResponseCode resp); + void newFolderFinished(Response::ResponseCode resp); void actDelete(); - void deleteFolderFinished(ResponseCode resp); - void deleteDeckFinished(ResponseCode resp); + void deleteFolderFinished(Response::ResponseCode resp); + void deleteDeckFinished(Response::ResponseCode resp); public: TabDeckStorage(TabSupervisor *_tabSupervisor, AbstractClient *_client); void retranslateUi(); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 0b2c7502..2a217524 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -37,6 +37,8 @@ #include "localclient.h" #include "pb/room_commands.pb.h" +#include "pb/event_connection_closed.pb.h" +#include "pb/event_server_shutdown.pb.h" const QString MainWindow::appName = "Cockatrice"; @@ -49,9 +51,9 @@ void MainWindow::updateTabMenu(QMenu *menu) menuBar()->insertMenu(helpMenu->menuAction(), menu); } -void MainWindow::processConnectionClosedEvent(Event_ConnectionClosed *event) +void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &event) { -/* QString reason = event->getReason(); + QString reason = QString::fromStdString(event.reason()); client->disconnectFromServer(); QString reasonStr; if (reason == "too_many_connections") @@ -63,13 +65,11 @@ void MainWindow::processConnectionClosedEvent(Event_ConnectionClosed *event) else reasonStr = tr("Unknown reason."); QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr)); -*/ } -void MainWindow::processServerShutdownEvent(Event_ServerShutdown *event) +void MainWindow::processServerShutdownEvent(const Event_ServerShutdown &event) { -/* QMessageBox::information(this, tr("Scheduled server shutdown"), tr("The server is going to be restarted in %n minute(s).\nAll running games will be lost.\nReason for shutdown: %1", "", event->getMinutes()).arg(event->getReason())); - * */ + QMessageBox::information(this, tr("Scheduled server shutdown"), tr("The server is going to be restarted in %n minute(s).\nAll running games will be lost.\nReason for shutdown: %1", "", event.minutes()).arg(QString::fromStdString(event.reason()))); } void MainWindow::statusChanged(ClientStatus _status) diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index 3acf6650..e2dad1cb 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -35,8 +35,8 @@ class MainWindow : public QMainWindow { private slots: void updateTabMenu(QMenu *menu); void statusChanged(ClientStatus _status); - void processConnectionClosedEvent(Event_ConnectionClosed *event); - void processServerShutdownEvent(Event_ServerShutdown *event); + void processConnectionClosedEvent(const Event_ConnectionClosed &event); + void processServerShutdownEvent(const Event_ServerShutdown &event); void serverTimeout(); void serverError(Response::ResponseCode r); void socketError(const QString &errorStr); diff --git a/common/server.h b/common/server.h index 92288bf5..6bda9fb5 100644 --- a/common/server.h +++ b/common/server.h @@ -5,11 +5,11 @@ #include #include #include +#include "pb/serverinfo_user.pb.h" class Server_Game; class Server_Room; class Server_ProtocolHandler; -class ServerInfo_User; enum AuthenticationResult { PasswordWrong = 0, PasswordRight = 1, UnknownUser = 2, WouldOverwriteOldSession = 3 };