diff --git a/cockatrice/src/carditem.cpp b/cockatrice/src/carditem.cpp index 09b405c58..8efac4782 100644 --- a/cockatrice/src/carditem.cpp +++ b/cockatrice/src/carditem.cpp @@ -8,9 +8,10 @@ #include "player.h" #include "game.h" #include "arrowitem.h" +#include "main.h" -CardItem::CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphicsItem *parent) - : AbstractGraphicsItem(parent), db(_db), info(db->getCard(_name)), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL) +CardItem::CardItem(const QString &_name, int _cardid, QGraphicsItem *parent) + : AbstractGraphicsItem(parent), info(db->getCard(_name)), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL) { setCursor(Qt::OpenHandCursor); setFlag(ItemIsSelectable); diff --git a/cockatrice/src/carditem.h b/cockatrice/src/carditem.h index 244de80dd..e19458297 100644 --- a/cockatrice/src/carditem.h +++ b/cockatrice/src/carditem.h @@ -23,7 +23,6 @@ enum CardItemType { class CardItem : public QObject, public AbstractGraphicsItem { Q_OBJECT private: - CardDatabase *db; CardInfo *info; QString name; int id; @@ -40,7 +39,7 @@ private slots: public: enum { Type = typeCard }; int type() const { return Type; } - CardItem(CardDatabase *_db, const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0); + CardItem(const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0); ~CardItem(); QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); diff --git a/cockatrice/src/cardzone.cpp b/cockatrice/src/cardzone.cpp index 525d7fb40..946b89518 100644 --- a/cockatrice/src/cardzone.cpp +++ b/cockatrice/src/cardzone.cpp @@ -84,7 +84,7 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y) { if (view) if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) - view->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y); + view->addCard(new CardItem(card->getName(), card->getId()), reorganize, x, y); addCardImpl(card, x, y); diff --git a/cockatrice/src/client.cpp b/cockatrice/src/client.cpp index e809649df..f7dc0b2f0 100644 --- a/cockatrice/src/client.cpp +++ b/cockatrice/src/client.cpp @@ -288,23 +288,24 @@ void Client::processProtocolItem(ProtocolItem *item) case ItemId_Event_ListGames: emit listGamesEventReceived(qobject_cast(item)); break; case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast(item)); break; case ItemId_Event_ListChatChannels: emit listChatChannelsEventReceived(qobject_cast(item)); break; + case ItemId_Event_GameJoined: emit gameJoinedEventReceived(qobject_cast(item)); break; } delete genericEvent; return; } -/* GameEvent *gameEvent = qobject_cast(item); + GameEvent *gameEvent = qobject_cast(item); if (gameEvent) { emit gameEventReceived(gameEvent); delete gameEvent; return; } -*/ + ChatEvent *chatEvent = qobject_cast(item); if (chatEvent) { - qDebug() << "chatEventReceived()"; emit chatEventReceived(chatEvent); delete chatEvent; + return; } } diff --git a/cockatrice/src/client.h b/cockatrice/src/client.h index 52dd023a4..9fb2206d3 100644 --- a/cockatrice/src/client.h +++ b/cockatrice/src/client.h @@ -18,6 +18,7 @@ class GameEvent; class Event_ListGames; class Event_ServerMessage; class Event_ListChatChannels; +class Event_GameJoined; enum ClientStatus { StatusDisconnected, @@ -32,7 +33,6 @@ class Client : public QObject { signals: void statusChanged(ClientStatus _status); // void playerIdReceived(int id, QString name); -// void gameEvent(const ServerEventData &msg); void maxPingTime(int seconds, int maxSeconds); void serverTimeout(); void logSocketError(const QString &errorString); @@ -48,6 +48,7 @@ signals: void listGamesEventReceived(Event_ListGames *event); void serverMessageEventReceived(Event_ServerMessage *event); void listChatChannelsEventReceived(Event_ListChatChannels *event); + void gameJoinedEventReceived(Event_GameJoined *event); private slots: void slotConnected(); diff --git a/cockatrice/src/dlg_creategame.cpp b/cockatrice/src/dlg_creategame.cpp index 93a2ae27f..76a1ce2e5 100644 --- a/cockatrice/src/dlg_creategame.cpp +++ b/cockatrice/src/dlg_creategame.cpp @@ -1,5 +1,6 @@ #include #include "dlg_creategame.h" +#include "protocol_items.h" DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent) : QDialog(parent), client(_client) @@ -58,13 +59,15 @@ void DlgCreateGame::actOK() QMessageBox::critical(this, tr("Error"), tr("Invalid number of players.")); return; } -// PendingCommand *createCommand = client->createGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked()); -// connect(createCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse))); + Command_CreateGame *createCommand = new Command_CreateGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked()); + connect(createCommand, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode))); + client->sendCommand(createCommand); + okButton->setEnabled(false); cancelButton->setEnabled(false); } -/*void DlgCreateGame::checkResponse(ServerResponse response) +void DlgCreateGame::checkResponse(ResponseCode response) { okButton->setEnabled(true); cancelButton->setEnabled(true); @@ -76,4 +79,3 @@ void DlgCreateGame::actOK() return; } } -*/ \ No newline at end of file diff --git a/cockatrice/src/dlg_creategame.h b/cockatrice/src/dlg_creategame.h index bf7451a56..8ca34b774 100644 --- a/cockatrice/src/dlg_creategame.h +++ b/cockatrice/src/dlg_creategame.h @@ -15,7 +15,7 @@ public: DlgCreateGame(Client *_client, QWidget *parent = 0); private slots: void actOK(); -// void checkResponse(ServerResponse response); + void checkResponse(ResponseCode response); private: Client *client; @@ -26,4 +26,3 @@ private: }; #endif - diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index be7592838..46c948e49 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -2,6 +2,7 @@ #include "carddatabase.h" #include "dlg_settings.h" +#include "main.h" GeneralSettingsPage::GeneralSettingsPage() { @@ -397,8 +398,8 @@ void MessagesSettingsPage::retranslateUi() aRemove->setText(tr("&Remove")); } -DlgSettings::DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *parent) - : QDialog(parent), db(_db), translator(_translator) +DlgSettings::DlgSettings(QWidget *parent) + : QDialog(parent) { contentsWidget = new QListWidget; contentsWidget->setViewMode(QListView::IconMode); diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 496491994..76acd1eb6 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -4,7 +4,6 @@ #include class CardDatabase; -class QTranslator; class QListWidget; class QListWidgetItem; class QStackedWidget; @@ -90,13 +89,11 @@ private: class DlgSettings : public QDialog { Q_OBJECT public: - DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *parent = 0); + DlgSettings(QWidget *parent = 0); private slots: void changePage(QListWidgetItem *current, QListWidgetItem *previous); void changeLanguage(const QString &qmFile); private: - CardDatabase *db; - QTranslator *translator; QListWidget *contentsWidget; QStackedWidget *pagesWidget; QListWidgetItem *generalButton, *appearanceButton, *messagesButton; diff --git a/cockatrice/src/game.cpp b/cockatrice/src/game.cpp index d248d4573..b3b6245df 100644 --- a/cockatrice/src/game.cpp +++ b/cockatrice/src/game.cpp @@ -135,7 +135,7 @@ void Game::retranslateUi() Player *Game::addPlayer(int playerId, const QString &playerName, bool local) { - Player *newPlayer = new Player(playerName, playerId, local, db, client, this); + Player *newPlayer = new Player(playerName, playerId, local, client, this); scene->addPlayer(newPlayer); connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint))); diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index 8a998f423..62a213ad6 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -18,7 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ - #include #include #include @@ -29,10 +28,15 @@ #include #include +#include "main.h" #include "window_main.h" +#include "carddatabase.h" //Q_IMPORT_PLUGIN(qjpeg) +CardDatabase *db; +QTranslator *translator; + void myMessageOutput(QtMsgType type, const char *msg) { static FILE *f = NULL; @@ -52,25 +56,27 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationName("Cockatrice"); QCoreApplication::setOrganizationDomain("cockatrice.de"); QCoreApplication::setApplicationName("Cockatrice"); + + db = new CardDatabase; QString localeName;// = QLocale::system().name(); QTranslator qtTranslator; qtTranslator.load("qt_" + localeName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); app.installTranslator(&qtTranslator); - QTranslator translator; + translator = new QTranslator; QSettings settings; settings.beginGroup("personal"); QString lang = settings.value("lang").toString(); if (lang.isEmpty()) - translator.load("cockatrice_" + localeName, ":/translations", QString(), ".qm"); + translator->load("cockatrice_" + localeName, ":/translations", QString(), ".qm"); else - translator.load(lang); - app.installTranslator(&translator); + translator->load(lang); + app.installTranslator(translator); qsrand(QDateTime::currentDateTime().toTime_t()); - MainWindow ui(&translator); + MainWindow ui; qDebug("main(): MainWindow constructor finished"); QIcon icon(":/resources/icon.svg"); @@ -81,4 +87,3 @@ int main(int argc, char *argv[]) return app.exec(); } - diff --git a/cockatrice/src/main.h b/cockatrice/src/main.h new file mode 100644 index 000000000..19e32b7df --- /dev/null +++ b/cockatrice/src/main.h @@ -0,0 +1,10 @@ +#ifndef MAIN_H +#define MAIN_H + +class CardDatabase; +class QTranslator; + +extern CardDatabase *db; +extern QTranslator *translator; + +#endif diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 8ddbfb3c1..2e76b5a2f 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -14,8 +14,8 @@ #include #include -Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Client *_client, Game *_parent) - : QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), active(false), local(_local), db(_db), client(_client) +Player::Player(const QString &_name, int _id, bool _local, Client *_client, Game *_parent) + : QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), active(false), local(_local), client(_client) { QSettings settings; QString bgPath = settings.value("zonebg/playerarea").toString(); diff --git a/cockatrice/src/player.h b/cockatrice/src/player.h index b0867a079..ed6196747 100644 --- a/cockatrice/src/player.h +++ b/cockatrice/src/player.h @@ -75,7 +75,6 @@ private: TableZone *table; HandZone *hand; - CardDatabase *db; void setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards); QPixmap bgPixmap; @@ -104,7 +103,7 @@ public: Client *client; void addZone(CardZone *z); - Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Client *_client, Game *_parent); + Player(const QString &_name, int _id, bool _local, Client *_client, Game *_parent); ~Player(); void retranslateUi(); QMenu *getPlayerMenu() const { return playerMenu; } @@ -115,7 +114,6 @@ public: const QMap &getArrows() const { return arrows; } TableZone *getTable() const { return table; } // void gameEvent(const ServerEventData &event); - CardDatabase *getDb() const { return db; } void showCardMenu(const QPoint &p); bool getActive() const { return active; } void setActive(bool _active); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 8d1c8b69c..60eff8bb6 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -1 +1,57 @@ - +#include +#include "tab_game.h" +#include "cardinfowidget.h" +#include "messagelogwidget.h" +#include "phasestoolbar.h" +#include "gameview.h" +#include "gamescene.h" +#include "player.h" +#include "game.h" +#include "zoneviewzone.h" +#include "zoneviewwidget.h" +#include "zoneviewlayout.h" +#include "main.h" + +TabGame::TabGame(Client *_client, int _gameId) + : client(_client), gameId(_gameId) +{ + zoneLayout = new ZoneViewLayout; + scene = new GameScene(zoneLayout, this); + view = new GameView(scene); + + cardInfo = new CardInfoWidget(db); + messageLog = new MessageLogWidget; + sayLabel = new QLabel; + sayEdit = new QLineEdit; + sayLabel->setBuddy(sayEdit); + + QHBoxLayout *hLayout = new QHBoxLayout; + hLayout->addWidget(sayLabel); + hLayout->addWidget(sayEdit); + + phasesToolbar = new PhasesToolbar; + + QVBoxLayout *verticalLayout = new QVBoxLayout; + verticalLayout->addWidget(cardInfo); + verticalLayout->addWidget(messageLog); + verticalLayout->addLayout(hLayout); + + QHBoxLayout *mainLayout = new QHBoxLayout; + mainLayout->addWidget(phasesToolbar); + mainLayout->addWidget(view, 10); + mainLayout->addLayout(verticalLayout); + + setLayout(mainLayout); + + connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay())); + +// connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int))); + + connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int))); + connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn())); + +} + +void TabGame::processGameEvent(GameEvent *event) +{ +} diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index 8d1c8b69c..048dde04b 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -1 +1,42 @@ - +#ifndef TAB_GAME_H +#define TAB_GAME_H + +#include + +class Client; +class CardDatabase; +class GameEvent; +class GameView; +class GameScene; +class Game; +class CardInfoWidget; +class MessageLogWidget; +class QLabel; +class QLineEdit; +class QPushButton; +class ZoneViewLayout; +class ZoneViewWidget; +class PhasesToolbar; + +class TabGame : public QWidget { + Q_OBJECT +private: + Client *client; + int gameId; + + CardInfoWidget *cardInfo; + MessageLogWidget *messageLog; + QLabel *sayLabel; + QLineEdit *sayEdit; + PhasesToolbar *phasesToolbar; + GameScene *scene; + GameView *view; + Game *game; + ZoneViewLayout *zoneLayout; +private slots: +public: + TabGame(Client *_client, int _gameId); + void processGameEvent(GameEvent *event); +}; + +#endif diff --git a/cockatrice/src/tab_server.cpp b/cockatrice/src/tab_server.cpp index 879190b63..7c0c52b1d 100644 --- a/cockatrice/src/tab_server.cpp +++ b/cockatrice/src/tab_server.cpp @@ -63,7 +63,6 @@ void GameSelector::checkResponse(ResponseCode response) spectateButton->setEnabled(true); switch (response) { - case RespOk: /* HIER CODE FÜR NEUEN GAME_TAB EINFÜGEN */ 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 RespContextError: QMessageBox::critical(this, tr("Error"), tr("The game is already full.")); break; @@ -172,88 +171,6 @@ void ChatChannelSelector::processListChatChannelsEvent(Event_ListChatChannels *e } } -/* -void ChatWidget::chatEvent(const ChatEventData &data) -{ - const QStringList &msg = data.getEventData(); - switch (data.getEventType()) { - case eventListChatChannels: { - if (msg.size() != 4) - break; - for (int i = 0; i < channelList->topLevelItemCount(); ++i) { - QTreeWidgetItem *twi = channelList->topLevelItem(i); - if (twi->text(0) == msg[0]) { - twi->setToolTip(0, msg[1]); - twi->setText(1, msg[2]); - return; - } - } - QTreeWidgetItem *twi = new QTreeWidgetItem(QStringList() << msg[0] << msg[2]); - twi->setTextAlignment(1, Qt::AlignRight); - twi->setToolTip(0, msg[1]); - channelList->addTopLevelItem(twi); - channelList->resizeColumnToContents(0); - channelList->resizeColumnToContents(1); - if (msg[3] == "1") - joinChannel(msg[0]); - break; - } - case eventChatJoinChannel: { - if (msg.size() != 2) - break; - ChannelWidget *w = getChannel(msg[0]); - if (!w) - break; - w->joinEvent(msg[1]); - break; - } - case eventChatListPlayers: { - if (msg.size() != 2) - break; - ChannelWidget *w = getChannel(msg[0]); - if (!w) - break; - w->listPlayersEvent(msg[1]); - break; - } - case eventChatLeaveChannel: { - if (msg.size() != 2) - break; - ChannelWidget *w = getChannel(msg[0]); - if (!w) - break; - w->leaveEvent(msg[1]); - break; - } - case eventChatSay: { - if (msg.size() != 3) - break; - ChannelWidget *w = getChannel(msg[0]); - if (!w) - break; - w->sayEvent(msg[1], msg[2]); - break; - } - case eventChatServerMessage: { - if (msg.size() != 2) - break; - ChannelWidget *w; - if (msg[0].isEmpty()) { - w = getChannel("Server"); - if (!w) { - w = new ChannelWidget(client, "Server", true, true); - tab->addTab(w, "Server"); - } - } else - w = getChannel(msg[0]); - w->serverMessageEvent(msg[1]); - break; - } - default: { - } - } -} -*/ void ChatChannelSelector::joinChannel(const QString &channelName) { Command_ChatJoinChannel *command = new Command_ChatJoinChannel(channelName); diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index dcc6659ba..b3a2fbb76 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -22,6 +22,7 @@ void TabSupervisor::start(Client *_client) client = _client; connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *))); connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *))); + connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *))); tabServer = new TabServer(client); connect(tabServer, SIGNAL(gameJoined(int)), this, SLOT(addGameTab(int))); @@ -34,12 +35,32 @@ void TabSupervisor::start(Client *_client) void TabSupervisor::stop() { + if (!client) + return; + + disconnect(client, 0, this, 0); + + clear(); + + delete tabServer; + tabServer = 0; + + QMapIterator chatChannelIterator(chatChannelTabs); + while (chatChannelIterator.hasNext()) + delete chatChannelIterator.next().value(); + chatChannelTabs.clear(); + QMapIterator gameIterator(gameTabs); + while (gameIterator.hasNext()) + delete gameIterator.next().value(); + gameTabs.clear(); } -void TabSupervisor::addGameTab(int gameId) +void TabSupervisor::gameJoined(Event_GameJoined *event) { - + TabGame *tab = new TabGame(client, event->getGameId()); + addTab(tab, tr("Game %1").arg(event->getGameId())); + gameTabs.insert(event->getGameId(), tab); } void TabSupervisor::addChatChannelTab(const QString &channelName) @@ -58,5 +79,7 @@ void TabSupervisor::processChatEvent(ChatEvent *event) void TabSupervisor::processGameEvent(GameEvent *event) { - + TabGame *tab = gameTabs.value(event->getGameId()); + if (tab) + tab->processGameEvent(event); } diff --git a/cockatrice/src/tab_supervisor.h b/cockatrice/src/tab_supervisor.h index 5b92d89fe..b8f2e803e 100644 --- a/cockatrice/src/tab_supervisor.h +++ b/cockatrice/src/tab_supervisor.h @@ -10,6 +10,7 @@ class TabChatChannel; class TabGame; class ChatEvent; class GameEvent; +class Event_GameJoined; class TabSupervisor : public QTabWidget { Q_OBJECT @@ -24,7 +25,7 @@ public: void start(Client *_client); void stop(); private slots: - void addGameTab(int gameId); + void gameJoined(Event_GameJoined *event); void addChatChannelTab(const QString &channelName); void processChatEvent(ChatEvent *event); void processGameEvent(GameEvent *event); diff --git a/cockatrice/src/window_deckeditor.cpp b/cockatrice/src/window_deckeditor.cpp index d98e550f1..eb80c0726 100644 --- a/cockatrice/src/window_deckeditor.cpp +++ b/cockatrice/src/window_deckeditor.cpp @@ -5,6 +5,7 @@ #include "carddatabasemodel.h" #include "decklistmodel.h" #include "cardinfowidget.h" +#include "main.h" void SearchLineEdit::keyPressEvent(QKeyEvent *event) { @@ -13,8 +14,8 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event) QLineEdit::keyPressEvent(event); } -WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent) - : QMainWindow(parent), db(_db) +WndDeckEditor::WndDeckEditor(QWidget *parent) + : QMainWindow(parent) { QLabel *searchLabel = new QLabel(tr("&Search for:")); searchEdit = new SearchLineEdit; @@ -281,7 +282,7 @@ void WndDeckEditor::actPrintDeck() void WndDeckEditor::actEditSets() { - WndSets *w = new WndSets(db, this); + WndSets *w = new WndSets(this); w->setWindowModality(Qt::WindowModal); w->show(); } diff --git a/cockatrice/src/window_deckeditor.h b/cockatrice/src/window_deckeditor.h index 2adce4cdc..c7020a912 100644 --- a/cockatrice/src/window_deckeditor.h +++ b/cockatrice/src/window_deckeditor.h @@ -6,7 +6,6 @@ #include #include "decklist.h" -class CardDatabase; class CardDatabaseModel; class CardDatabaseDisplayModel; class DeckListModel; @@ -54,7 +53,6 @@ private: QString lastFileName; DeckList::FileFormat lastFileFormat; - CardDatabase *db; CardDatabaseModel *databaseModel; CardDatabaseDisplayModel *databaseDisplayModel; @@ -71,7 +69,7 @@ private: QAction *aEditSets; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement; public: - WndDeckEditor(CardDatabase *_db, QWidget *parent = 0); + WndDeckEditor(QWidget *parent = 0); ~WndDeckEditor(); protected: void closeEvent(QCloseEvent *event); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 935360c16..4dce89226 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -24,17 +24,6 @@ #include "dlg_connect.h" #include "dlg_settings.h" #include "window_deckeditor.h" -#include "cardinfowidget.h" -#include "messagelogwidget.h" -#include "phasestoolbar.h" -#include "gameview.h" -#include "gamescene.h" -#include "player.h" -#include "game.h" -#include "carddatabase.h" -#include "zoneviewzone.h" -#include "zoneviewwidget.h" -#include "zoneviewlayout.h" #include "tab_supervisor.h" PingWidget::PingWidget(QWidget *parent) @@ -65,14 +54,14 @@ void PingWidget::setPercentage(int value, int max) color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255); update(); } - +/* void MainWindow::playerAdded(Player *player) { menuBar()->addMenu(player->getPlayerMenu()); connect(player, SIGNAL(toggleZoneView(Player *, QString, int)), zoneLayout, SLOT(toggleZoneView(Player *, QString, int))); connect(player, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *))); } - +*/ void MainWindow::statusChanged(ClientStatus _status) { switch (_status) { @@ -80,16 +69,17 @@ void MainWindow::statusChanged(ClientStatus _status) emit logConnecting(client->peerName()); break; case StatusDisconnected: - if (game) { - zoneLayout->clear(); - delete game; - game = 0; - } + tabSupervisor->stop(); +// if (game) { +// zoneLayout->clear(); +// delete game; +// game = 0; +// } // pingWidget->setPercentage(0, -1); aConnect->setEnabled(true); aDisconnect->setEnabled(false); - aRestartGame->setEnabled(false); - aLeaveGame->setEnabled(false); +// aRestartGame->setEnabled(false); +// aLeaveGame->setEnabled(false); // phasesToolbar->setActivePhase(-1); // phasesToolbar->hide(); emit logDisconnected(); @@ -155,7 +145,7 @@ void MainWindow::actDisconnect() { client->disconnectFromServer(); } - +/* void MainWindow::actRestartGame() { zoneLayout->clear(); @@ -166,10 +156,10 @@ void MainWindow::actLeaveGame() { client->leaveGame(); } - +*/ void MainWindow::actDeckEditor() { - WndDeckEditor *deckEditor = new WndDeckEditor(db, this); + WndDeckEditor *deckEditor = new WndDeckEditor(this); deckEditor->show(); } @@ -183,7 +173,7 @@ void MainWindow::actFullScreen(bool checked) void MainWindow::actSettings() { - DlgSettings dlg(db, translator, this); + DlgSettings dlg(this); dlg.exec(); } @@ -191,7 +181,7 @@ void MainWindow::actExit() { close(); } - +/* void MainWindow::actSay() { if (sayEdit->text().isEmpty()) @@ -200,7 +190,7 @@ void MainWindow::actSay() client->say(sayEdit->text()); sayEdit->clear(); } - +*/ void MainWindow::serverTimeout() { QMessageBox::critical(this, tr("Error"), tr("Server timeout")); @@ -212,9 +202,9 @@ void MainWindow::retranslateUi() aConnect->setText(tr("&Connect...")); aDisconnect->setText(tr("&Disconnect")); - aRestartGame->setText(tr("&Restart game...")); - aRestartGame->setShortcut(tr("F2")); - aLeaveGame->setText(tr("&Leave game")); +// aRestartGame->setText(tr("&Restart game...")); +// aRestartGame->setShortcut(tr("F2")); +// aLeaveGame->setText(tr("&Leave game")); aDeckEditor->setText(tr("&Deck editor")); aFullScreen->setText(tr("&Full screen")); aFullScreen->setShortcut(tr("Ctrl+F")); @@ -242,13 +232,13 @@ void MainWindow::createActions() aDisconnect = new QAction(this); aDisconnect->setEnabled(false); connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect())); - aRestartGame = new QAction(this); +/* aRestartGame = new QAction(this); aRestartGame->setEnabled(false); connect(aRestartGame, SIGNAL(triggered()), this, SLOT(actRestartGame())); aLeaveGame = new QAction(this); aLeaveGame->setEnabled(false); connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame())); - aDeckEditor = new QAction(this); +*/ aDeckEditor = new QAction(this); connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor())); aFullScreen = new QAction(this); aFullScreen->setCheckable(true); @@ -269,9 +259,6 @@ void MainWindow::createMenus() cockatriceMenu->addAction(aConnect); cockatriceMenu->addAction(aDisconnect); cockatriceMenu->addSeparator(); - cockatriceMenu->addAction(aRestartGame); - cockatriceMenu->addAction(aLeaveGame); - cockatriceMenu->addSeparator(); cockatriceMenu->addAction(aDeckEditor); cockatriceMenu->addSeparator(); cockatriceMenu->addAction(aFullScreen); @@ -281,67 +268,17 @@ void MainWindow::createMenus() cockatriceMenu->addAction(aExit); } -MainWindow::MainWindow(QTranslator *_translator, QWidget *parent) - : QMainWindow(parent), game(NULL), translator(_translator) +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) { QPixmapCache::setCacheLimit(200000); - db = new CardDatabase(this); client = new Client(this); tabSupervisor = new TabSupervisor; setCentralWidget(tabSupervisor); /* - zoneLayout = new ZoneViewLayout(db); - scene = new GameScene(zoneLayout, this); - view = new GameView(scene); -// view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); - view->hide(); - - cardInfo = new CardInfoWidget(db); - messageLog = new MessageLogWidget; - sayLabel = new QLabel; - sayEdit = new QLineEdit; - sayLabel->setBuddy(sayEdit); - pingWidget = new PingWidget; - - gameSelector = new GameSelector(client); - gameSelector->hide(); - chatWidget = new ChatWidget(client); - chatWidget->hide(); - - QHBoxLayout *hLayout = new QHBoxLayout; - hLayout->addWidget(sayLabel); - hLayout->addWidget(sayEdit); - hLayout->addWidget(pingWidget); - - QVBoxLayout *verticalLayout = new QVBoxLayout; - verticalLayout->addWidget(cardInfo); - verticalLayout->addWidget(messageLog); - verticalLayout->addLayout(hLayout); - - viewLayout = new QVBoxLayout; - viewLayout->addWidget(gameSelector); - viewLayout->addWidget(chatWidget); - viewLayout->addWidget(view); - - phasesToolbar = new PhasesToolbar; - phasesToolbar->hide(); - - QHBoxLayout *mainLayout = new QHBoxLayout; - mainLayout->addWidget(phasesToolbar); - mainLayout->addLayout(viewLayout, 10); - mainLayout->addLayout(verticalLayout); - - QWidget *centralWidget = new QWidget; - centralWidget->setLayout(mainLayout); - setCentralWidget(centralWidget); - - connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay())); - - connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int))); - connect(this, SIGNAL(logConnecting(QString)), messageLog, SLOT(logConnecting(QString))); connect(this, SIGNAL(logConnected()), messageLog, SLOT(logConnected())); connect(this, SIGNAL(logDisconnected()), messageLog, SLOT(logDisconnected())); @@ -349,8 +286,6 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent) connect(client, SIGNAL(serverError(ResponseCode)), messageLog, SLOT(logServerError(ResponseCode))); connect(client, SIGNAL(protocolVersionMismatch(int, int)), messageLog, SLOT(logProtocolVersionMismatch(int, int))); connect(client, SIGNAL(protocolError()), messageLog, SLOT(logProtocolError())); - connect(phasesToolbar, SIGNAL(signalSetPhase(int)), client, SLOT(setActivePhase(int))); - connect(phasesToolbar, SIGNAL(signalNextTurn()), client, SLOT(nextTurn())); */ connect(client, SIGNAL(serverTimeout()), this, SLOT(serverTimeout())); connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus))); @@ -365,7 +300,7 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent) void MainWindow::closeEvent(QCloseEvent */*event*/) { - delete game; + delete tabSupervisor; } void MainWindow::changeEvent(QEvent *event) diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index c1ee0f310..31f049f9d 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -23,26 +23,6 @@ #include #include "client.h" -class GameView; -class GameScene; -class Game; -class CardDatabase; -class Player; - -class QTranslator; -class QVBoxLayout; -class CardInfoWidget; -class MessageLogWidget; -class QLabel; -class QLineEdit; -class QPushButton; -class QTabWidget; -class ServerZoneCard; -class ZoneViewLayout; -class ZoneViewWidget; -class PhasesToolbar; -class GameSelector; -class ChatWidget; class TabSupervisor; class PingWidget : public QWidget { @@ -61,16 +41,12 @@ public slots: class MainWindow : public QMainWindow { Q_OBJECT private slots: - void playerAdded(Player *player); +// void playerAdded(Player *player); void statusChanged(ClientStatus _status); void serverTimeout(); - void actSay(); - void actConnect(); void actDisconnect(); - void actRestartGame(); - void actLeaveGame(); void actDeckEditor(); void actFullScreen(bool checked); void actSettings(); @@ -84,29 +60,15 @@ private: void createActions(); void createMenus(); QMenu *cockatriceMenu; - QAction *aConnect, *aDisconnect, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aSettings, *aExit; + QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit; QAction *aCloseMostRecentZoneView; TabSupervisor *tabSupervisor; - QVBoxLayout *viewLayout; PingWidget *pingWidget; - CardInfoWidget *cardInfo; - MessageLogWidget *messageLog; - QLabel *sayLabel; - QLineEdit *sayEdit; - PhasesToolbar *phasesToolbar; - GameSelector *gameSelector; - ChatWidget *chatWidget; Client *client; - GameScene *scene; - GameView *view; - Game *game; - CardDatabase *db; - ZoneViewLayout *zoneLayout; - QTranslator *translator; public: - MainWindow(QTranslator *_translator, QWidget *parent = 0); + MainWindow(QWidget *parent = 0); protected: void closeEvent(QCloseEvent *event); void changeEvent(QEvent *event); diff --git a/cockatrice/src/window_sets.cpp b/cockatrice/src/window_sets.cpp index ed9098501..45ddcb294 100644 --- a/cockatrice/src/window_sets.cpp +++ b/cockatrice/src/window_sets.cpp @@ -1,11 +1,12 @@ #include "window_sets.h" #include "setsmodel.h" +#include "main.h" #include -WndSets::WndSets(CardDatabase *_db, QWidget *parent) +WndSets::WndSets(QWidget *parent) : QMainWindow(parent) { - model = new SetsModel(_db, this); + model = new SetsModel(db, this); view = new QTreeView; view->setModel(model); view->setAlternatingRowColors(true); diff --git a/cockatrice/src/window_sets.h b/cockatrice/src/window_sets.h index 5a92f4a34..4c10d249a 100644 --- a/cockatrice/src/window_sets.h +++ b/cockatrice/src/window_sets.h @@ -13,7 +13,7 @@ private: SetsModel *model; QTreeView *view; public: - WndSets(CardDatabase *_db, QWidget *parent = 0); + WndSets(QWidget *parent = 0); ~WndSets(); }; diff --git a/cockatrice/src/zoneviewlayout.cpp b/cockatrice/src/zoneviewlayout.cpp index 5a5987c31..7601ec05b 100644 --- a/cockatrice/src/zoneviewlayout.cpp +++ b/cockatrice/src/zoneviewlayout.cpp @@ -3,8 +3,8 @@ #include "zoneviewzone.h" #include "player.h" -ZoneViewLayout::ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent) - : QGraphicsWidget(parent), db(_db) +ZoneViewLayout::ZoneViewLayout(QGraphicsItem *parent) + : QGraphicsWidget(parent) { resize(0, 0); } @@ -45,7 +45,7 @@ void ZoneViewLayout::toggleZoneView(Player *player, const QString &zoneName, int } } - ZoneViewWidget *item = new ZoneViewWidget(db, player, player->getZones().value(zoneName), numberCards, this); + ZoneViewWidget *item = new ZoneViewWidget(player, player->getZones().value(zoneName), numberCards, this); views.append(item); connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeItem(ZoneViewWidget *))); connect(item, SIGNAL(sizeChanged()), this, SLOT(reorganize())); diff --git a/cockatrice/src/zoneviewlayout.h b/cockatrice/src/zoneviewlayout.h index 009cfde8f..e6579271a 100644 --- a/cockatrice/src/zoneviewlayout.h +++ b/cockatrice/src/zoneviewlayout.h @@ -3,7 +3,6 @@ #include -class CardDatabase; class ZoneViewWidget; class ZoneViewZone; class Player; @@ -14,9 +13,8 @@ signals: void sizeChanged(); private: QList views; - CardDatabase *db; public: - ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent = 0); + ZoneViewLayout(QGraphicsItem *parent = 0); void retranslateUi(); public slots: void toggleZoneView(Player *player, const QString &zoneName, int numberCards = 0); diff --git a/cockatrice/src/zoneviewwidget.cpp b/cockatrice/src/zoneviewwidget.cpp index 40279a90b..c92fdde10 100644 --- a/cockatrice/src/zoneviewwidget.cpp +++ b/cockatrice/src/zoneviewwidget.cpp @@ -7,8 +7,8 @@ #include "client.h" #include "gamescene.h" -ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent) - : QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), db(_db), player(_player) +ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent) + : QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player) { setAttribute(Qt::WA_DeleteOnClose); diff --git a/cockatrice/src/zoneviewwidget.h b/cockatrice/src/zoneviewwidget.h index 0ac74e4c8..0250882e5 100644 --- a/cockatrice/src/zoneviewwidget.h +++ b/cockatrice/src/zoneviewwidget.h @@ -20,7 +20,6 @@ private: QScrollBar *scrollBar; QCheckBox *sortCheckBox, *shuffleCheckBox; - CardDatabase *db; Player *player; signals: void closePressed(ZoneViewWidget *zv); @@ -28,7 +27,7 @@ signals: private slots: void resizeToZoneContents(); public: - ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_origZone, int numberCards = 0, QGraphicsItem *parent = 0); + ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards = 0, QGraphicsItem *parent = 0); ZoneViewZone *getZone() const { return zone; } void retranslateUi(); protected: diff --git a/cockatrice/src/zoneviewzone.cpp b/cockatrice/src/zoneviewzone.cpp index 3090aa088..1cd0f87d0 100644 --- a/cockatrice/src/zoneviewzone.cpp +++ b/cockatrice/src/zoneviewzone.cpp @@ -34,7 +34,7 @@ void ZoneViewZone::initializeCards() int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size()); for (int i = 0; i < number; i++) { CardItem *card = c.at(i); - addCard(new CardItem(player->getDb(), card->getName(), card->getId(), this), false, i); + addCard(new CardItem(card->getName(), card->getId(), this), false, i); } emit contentsChanged(); reorganizeCards(); @@ -44,7 +44,7 @@ void ZoneViewZone::initializeCards() void ZoneViewZone::zoneDumpReceived(QList cards) { for (int i = 0; i < cards.size(); i++) { - CardItem *card = new CardItem(player->getDb(), cards[i].getName(), i, this); + CardItem *card = new CardItem(cards[i].getName(), i, this); addCard(card, false, i); } diff --git a/common/protocol_item_ids.h b/common/protocol_item_ids.h index b1eba59ff..34572e77c 100644 --- a/common/protocol_item_ids.h +++ b/common/protocol_item_ids.h @@ -51,8 +51,9 @@ ItemId_Event_SetActivePhase = 1049, ItemId_Event_DumpZone = 1050, ItemId_Event_StopDumpZone = 1051, ItemId_Event_ServerMessage = 1052, -ItemId_Event_ChatJoinChannel = 1053, -ItemId_Event_ChatLeaveChannel = 1054, -ItemId_Event_ChatSay = 1055, -ItemId_Other = 1056 +ItemId_Event_GameJoined = 1053, +ItemId_Event_ChatJoinChannel = 1054, +ItemId_Event_ChatLeaveChannel = 1055, +ItemId_Event_ChatSay = 1056, +ItemId_Other = 1057 }; diff --git a/common/protocol_items.cpp b/common/protocol_items.cpp index 223a04741..85eedd003 100644 --- a/common/protocol_items.cpp +++ b/common/protocol_items.cpp @@ -561,6 +561,18 @@ void Event_ServerMessage::extractParameters() GenericEvent::extractParameters(); message = parameters["message"]; } +Event_GameJoined::Event_GameJoined(int _gameId, bool _spectator) + : GenericEvent("game_joined"), gameId(_gameId), spectator(_spectator) +{ + setParameter("game_id", gameId); + setParameter("spectator", spectator); +} +void Event_GameJoined::extractParameters() +{ + GenericEvent::extractParameters(); + gameId = parameters["game_id"].toInt(); + spectator = (parameters["spectator"] == "1"); +} Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName) : ChatEvent("chat_join_channel", _channel), playerName(_playerName) { @@ -647,6 +659,7 @@ void ProtocolItem::initializeHashAuto() itemNameHash.insert("game_eventdump_zone", Event_DumpZone::newItem); itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem); itemNameHash.insert("generic_eventserver_message", Event_ServerMessage::newItem); + itemNameHash.insert("generic_eventgame_joined", Event_GameJoined::newItem); itemNameHash.insert("chat_eventchat_join_channel", Event_ChatJoinChannel::newItem); itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem); itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem); diff --git a/common/protocol_items.dat b/common/protocol_items.dat index cd53d8512..7eae80d34 100644 --- a/common/protocol_items.dat +++ b/common/protocol_items.dat @@ -50,6 +50,7 @@ 3:dump_zone:i,zone_owner_id:s,zone:i,number_cards 3:stop_dump_zone:i,zone_owner_id:s,zone 4:server_message:s,message +4:game_joined:i,game_id:b,spectator 5:chat_join_channel:s,player_name 5:chat_leave_channel:s,player_name 5:chat_say:s,player_name:s,message \ No newline at end of file diff --git a/common/protocol_items.h b/common/protocol_items.h index 8d41bb46a..e0b7f18f6 100644 --- a/common/protocol_items.h +++ b/common/protocol_items.h @@ -697,6 +697,20 @@ public: protected: void extractParameters(); }; +class Event_GameJoined : public GenericEvent { + Q_OBJECT +private: + int gameId; + bool spectator; +public: + Event_GameJoined(int _gameId = -1, bool _spectator = false); + int getGameId() const { return gameId; } + bool getSpectator() const { return spectator; } + static ProtocolItem *newItem() { return new Event_GameJoined; } + int getItemId() const { return ItemId_Event_GameJoined; } +protected: + void extractParameters(); +}; class Event_ChatJoinChannel : public ChatEvent { Q_OBJECT private: diff --git a/common/server_game.cpp b/common/server_game.cpp index 68faa57c7..2430d7bb9 100644 --- a/common/server_game.cpp +++ b/common/server_game.cpp @@ -26,7 +26,7 @@ Server_Game::Server_Game(Server_ProtocolHandler *_creator, int _gameId, const QString &_description, const QString &_password, int _maxPlayers, bool _spectatorsAllowed, QObject *parent) : QObject(parent), gameStarted(false), gameId(_gameId), description(_description), password(_password), maxPlayers(_maxPlayers), spectatorsAllowed(_spectatorsAllowed) { - creator = addPlayer(_creator, false); + creator = addPlayer(_creator, false, false); } Server_Game::~Server_Game() @@ -90,7 +90,7 @@ ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator) return RespOk; } -Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spectator) +Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate) { int playerId; if (!spectator) { @@ -113,7 +113,8 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec else players.insert(playerId, newPlayer); - qobject_cast(parent())->broadcastGameListUpdate(this); + if (broadcastUpdate) + qobject_cast(parent())->broadcastGameListUpdate(this); return newPlayer; } diff --git a/common/server_game.h b/common/server_game.h index afea31452..c703660e3 100644 --- a/common/server_game.h +++ b/common/server_game.h @@ -57,7 +57,7 @@ public: int getMaxPlayers() const { return maxPlayers; } bool getSpectatorsAllowed() const { return spectatorsAllowed; } ResponseCode checkJoin(const QString &_password, bool spectator); - Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator); + Server_Player *addPlayer(Server_ProtocolHandler *handler, bool spectator, bool broadcastUpdate = true); void removePlayer(Server_Player *player); void startGameIfReady(); int getActivePlayer() const { return activePlayer; } diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 2e0c87a06..3b48e6903 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -198,6 +198,7 @@ ResponseCode Server_ProtocolHandler::cmdCreateGame(Command_CreateGame *cmd) Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this); games.insert(game->getGameId(), QPair(game, game->getCreator())); + enqueueProtocolItem(new Event_GameJoined(game->getGameId(), false)); return RespOk; } @@ -212,6 +213,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd) Server_Player *player = g->addPlayer(this, cmd->getSpectator()); games.insert(cmd->getGameId(), QPair(g, player)); } + enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), cmd->getSpectator())); return result; }