From 122f8ea916bb8a79869b7e48d096424daa488ad8 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sat, 28 Nov 2009 18:35:48 +0100 Subject: [PATCH] game menu --- cockatrice/cockatrice.pro | 1 + cockatrice/src/cardzone.cpp | 8 ++++---- cockatrice/src/tab.h | 18 ++++++++++++++++++ cockatrice/src/tab_chatchannel.cpp | 2 +- cockatrice/src/tab_chatchannel.h | 4 ++-- cockatrice/src/tab_deck_storage.cpp | 2 +- cockatrice/src/tab_deck_storage.h | 6 +++--- cockatrice/src/tab_game.cpp | 23 ++++++++++++++--------- cockatrice/src/tab_game.h | 7 ++++--- cockatrice/src/tab_server.cpp | 2 +- cockatrice/src/tab_server.h | 3 ++- cockatrice/src/tab_supervisor.cpp | 9 +++++++++ cockatrice/src/tab_supervisor.h | 4 ++++ cockatrice/src/window_main.cpp | 17 +++++++++-------- cockatrice/src/window_main.h | 4 ++-- 15 files changed, 75 insertions(+), 35 deletions(-) create mode 100644 cockatrice/src/tab.h diff --git a/cockatrice/cockatrice.pro b/cockatrice/cockatrice.pro index 67cf0d9f..c21a733b 100644 --- a/cockatrice/cockatrice.pro +++ b/cockatrice/cockatrice.pro @@ -41,6 +41,7 @@ HEADERS += src/counter.h \ src/phasestoolbar.h \ src/gamescene.h \ src/arrowitem.h \ + src/tab.h \ src/tab_server.h \ src/tab_chatchannel.h \ src/tab_game.h \ diff --git a/cockatrice/src/cardzone.cpp b/cockatrice/src/cardzone.cpp index b6f65122..d2bffb35 100644 --- a/cockatrice/src/cardzone.cpp +++ b/cockatrice/src/cardzone.cpp @@ -2,8 +2,8 @@ #include "cardzone.h" #include "carditem.h" #include "player.h" -#include "client.h" #include "zoneviewzone.h" +#include "protocol_items.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) @@ -128,9 +128,9 @@ CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName, void CardZone::setCardAttr(int cardId, const QString &aname, const QString &avalue) { -/* if (hasCardAttr) - player->client->setCardAttr(name, cardId, aname, avalue); -*/} + if (hasCardAttr) + player->sendGameCommand(new Command_SetCardAttr(-1, name, cardId, aname, avalue)); +} void CardZone::moveAllToZone() { diff --git a/cockatrice/src/tab.h b/cockatrice/src/tab.h new file mode 100644 index 00000000..445dc9b7 --- /dev/null +++ b/cockatrice/src/tab.h @@ -0,0 +1,18 @@ +#ifndef TAB_H +#define TAB_H + +#include + +class QMenu; + +class Tab : public QWidget { + Q_OBJECT +protected: + QMenu *tabMenu; +public: + Tab(QWidget *parent = 0) + : QWidget(parent), tabMenu(0) { } + QMenu *getTabMenu() const { return tabMenu; } +}; + +#endif diff --git a/cockatrice/src/tab_chatchannel.cpp b/cockatrice/src/tab_chatchannel.cpp index c5557677..786b295f 100644 --- a/cockatrice/src/tab_chatchannel.cpp +++ b/cockatrice/src/tab_chatchannel.cpp @@ -4,7 +4,7 @@ #include "protocol_items.h" TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName) - : QWidget(), client(_client), channelName(_channelName) + : Tab(), client(_client), channelName(_channelName) { playerList = new QListWidget; playerList->setFixedWidth(150); diff --git a/cockatrice/src/tab_chatchannel.h b/cockatrice/src/tab_chatchannel.h index 52d7d3fd..bba40c63 100644 --- a/cockatrice/src/tab_chatchannel.h +++ b/cockatrice/src/tab_chatchannel.h @@ -1,7 +1,7 @@ #ifndef TAB_CHATCHANNEL_H #define TAB_CHATCHANNEL_H -#include +#include "tab.h" class Client; class QListWidget; @@ -13,7 +13,7 @@ class Event_ChatJoinChannel; class Event_ChatLeaveChannel; class Event_ChatSay; -class TabChatChannel : public QWidget { +class TabChatChannel : public Tab { Q_OBJECT private: Client *client; diff --git a/cockatrice/src/tab_deck_storage.cpp b/cockatrice/src/tab_deck_storage.cpp index 3a05c1e9..e8d3c803 100644 --- a/cockatrice/src/tab_deck_storage.cpp +++ b/cockatrice/src/tab_deck_storage.cpp @@ -7,7 +7,7 @@ #include "protocol_items.h" TabDeckStorage::TabDeckStorage(Client *_client) - : QWidget(), client(_client) + : Tab(), client(_client) { localDirModel = new QFileSystemModel(this); QSettings settings; diff --git a/cockatrice/src/tab_deck_storage.h b/cockatrice/src/tab_deck_storage.h index d2c7555d..7ebb6156 100644 --- a/cockatrice/src/tab_deck_storage.h +++ b/cockatrice/src/tab_deck_storage.h @@ -1,8 +1,8 @@ #ifndef TAB_DECK_STORAGE_H #define TAB_DECK_STORAGE_H -#include -#include "protocol_datastructures.h" +#include "tab.h" +#include "protocol.h" class Client; class QTreeView; @@ -15,7 +15,7 @@ class QGroupBox; class ProtocolResponse; class RemoteDeckList_TreeWidget; -class TabDeckStorage : public QWidget { +class TabDeckStorage : public Tab { Q_OBJECT private: Client *client; diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 97c7dbe7..96171dc1 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -21,7 +21,7 @@ #include "main.h" TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator) - : client(_client), gameId(_gameId), localPlayerId(_localPlayerId), spectator(_spectator), started(false), currentPhase(-1) + : Tab(), client(_client), gameId(_gameId), localPlayerId(_localPlayerId), spectator(_spectator), started(false), currentPhase(-1) { zoneLayout = new ZoneViewLayout; scene = new GameScene(zoneLayout, this); @@ -61,8 +61,8 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat QVBoxLayout *verticalLayout = new QVBoxLayout; verticalLayout->addWidget(cardInfo); - verticalLayout->addWidget(playerListWidget); - verticalLayout->addWidget(messageLog); + verticalLayout->addWidget(playerListWidget, 1); + verticalLayout->addWidget(messageLog, 3); verticalLayout->addLayout(hLayout); QHBoxLayout *mainLayout = new QHBoxLayout; @@ -89,11 +89,12 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat aRemoveLocalArrows = new QAction(this); connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows())); - gameMenu = new QMenu(this); - gameMenu->addAction(aNextPhase); - gameMenu->addAction(aNextTurn); - gameMenu->addSeparator(); - gameMenu->addAction(aRemoveLocalArrows); + tabMenu = new QMenu(this); + playersSeparator = tabMenu->addSeparator(); + tabMenu->addAction(aNextPhase); + tabMenu->addAction(aNextTurn); + tabMenu->addSeparator(); + tabMenu->addAction(aRemoveLocalArrows); retranslateUi(); setLayout(mainLayout); @@ -103,7 +104,7 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat void TabGame::retranslateUi() { - gameMenu->setTitle(tr("&Game")); + tabMenu->setTitle(tr("&Game")); aNextPhase->setText(tr("Next &phase")); aNextPhase->setShortcut(tr("Ctrl+Space")); aNextTurn->setText(tr("Next &turn")); @@ -167,8 +168,12 @@ Player *TabGame::addPlayer(int playerId, const QString &playerName) scene->addPlayer(newPlayer); connect(newPlayer, SIGNAL(newCardAdded(CardItem *)), this, SLOT(newCardAdded(CardItem *))); + connect(newPlayer, SIGNAL(toggleZoneView(Player *, QString, int)), zoneLayout, SLOT(toggleZoneView(Player *, QString, int))); + connect(newPlayer, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *))); messageLog->connectToPlayer(newPlayer); + tabMenu->insertMenu(playersSeparator, newPlayer->getPlayerMenu()); + players.insert(playerId, newPlayer); emit playerAdded(newPlayer); diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index 82890e5c..8f1476ca 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -1,8 +1,8 @@ #ifndef TAB_GAME_H #define TAB_GAME_H -#include #include +#include "tab.h" class Client; class CardDatabase; @@ -34,7 +34,7 @@ class Player; class CardZone; class CardItem; -class TabGame : public QWidget { +class TabGame : public Tab { Q_OBJECT private: Client *client; @@ -58,9 +58,10 @@ private: DeckView *deckView; QWidget *deckViewContainer; ZoneViewLayout *zoneLayout; + QAction *playersSeparator; + QMenu *playersMenu; QAction *aCloseMostRecentZoneView, *aNextPhase, *aNextTurn, *aRemoveLocalArrows; - QMenu *gameMenu; Player *addPlayer(int playerId, const QString &playerName); diff --git a/cockatrice/src/tab_server.cpp b/cockatrice/src/tab_server.cpp index d3e13eb3..1da2f25b 100644 --- a/cockatrice/src/tab_server.cpp +++ b/cockatrice/src/tab_server.cpp @@ -225,7 +225,7 @@ void ServerMessageLog::processServerMessageEvent(Event_ServerMessage *event) } TabServer::TabServer(Client *_client, QWidget *parent) - : QWidget(parent), client(_client) + : Tab(parent), client(_client) { gameSelector = new GameSelector(client); chatChannelSelector = new ChatChannelSelector(client); diff --git a/cockatrice/src/tab_server.h b/cockatrice/src/tab_server.h index 446a45bc..2695a314 100644 --- a/cockatrice/src/tab_server.h +++ b/cockatrice/src/tab_server.h @@ -2,6 +2,7 @@ #define TAB_SERVER_H #include +#include "tab.h" #include "protocol_datastructures.h" class Client; @@ -71,7 +72,7 @@ public: void retranslateUi(); }; -class TabServer : public QWidget { +class TabServer : public Tab { Q_OBJECT signals: void chatChannelJoined(const QString &channelName); diff --git a/cockatrice/src/tab_supervisor.cpp b/cockatrice/src/tab_supervisor.cpp index 5f16898f..51fd481c 100644 --- a/cockatrice/src/tab_supervisor.cpp +++ b/cockatrice/src/tab_supervisor.cpp @@ -11,6 +11,7 @@ TabSupervisor:: TabSupervisor(QWidget *parent) : QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0) { setIconSize(QSize(15, 15)); + connect(this, SIGNAL(currentChanged(int)), this, SLOT(updateMenu(int))); } void TabSupervisor::retranslateUi() @@ -131,3 +132,11 @@ void TabSupervisor::processGameEvent(GameEvent *event) } else qDebug() << "gameEvent: invalid gameId"; } + +void TabSupervisor::updateMenu(int index) +{ + if (index != -1) + emit setMenu(static_cast(widget(index))->getTabMenu()); + else + emit setMenu(0); +} diff --git a/cockatrice/src/tab_supervisor.h b/cockatrice/src/tab_supervisor.h index 427c4cf1..521478a5 100644 --- a/cockatrice/src/tab_supervisor.h +++ b/cockatrice/src/tab_supervisor.h @@ -4,6 +4,7 @@ #include #include +class QMenu; class Client; class TabServer; class TabChatChannel; @@ -26,7 +27,10 @@ public: void retranslateUi(); void start(Client *_client); void stop(); +signals: + void setMenu(QMenu *menu); private slots: + void updateMenu(int index); void updatePingTime(int value, int max); void gameJoined(Event_GameJoined *event); void addChatChannelTab(const QString &channelName); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 4e91dcad..4482b93a 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -18,7 +18,6 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include -//#include #include "window_main.h" #include "dlg_connect.h" @@ -26,14 +25,15 @@ #include "window_deckeditor.h" #include "tab_supervisor.h" -/* -void MainWindow::playerAdded(Player *player) +void MainWindow::updateTabMenu(QMenu *menu) { - 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 *))); + if (tabMenu) + menuBar()->removeAction(tabMenu->menuAction()); + tabMenu = menu; + if (menu) + menuBar()->addMenu(menu); } -*/ + void MainWindow::statusChanged(ClientStatus _status) { switch (_status) { @@ -207,12 +207,13 @@ void MainWindow::createMenus() } MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent) + : QMainWindow(parent), tabMenu(0) { QPixmapCache::setCacheLimit(200000); client = new Client(this); tabSupervisor = new TabSupervisor; + connect(tabSupervisor, SIGNAL(setMenu(QMenu *)), this, SLOT(updateTabMenu(QMenu *))); setCentralWidget(tabSupervisor); /* diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index c45c86aa..9816012f 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -28,7 +28,7 @@ class TabSupervisor; class MainWindow : public QMainWindow { Q_OBJECT private slots: -// void playerAdded(Player *player); + void updateTabMenu(QMenu *menu); void statusChanged(ClientStatus _status); void serverTimeout(); @@ -46,7 +46,7 @@ private: void retranslateUi(); void createActions(); void createMenus(); - QMenu *cockatriceMenu; + QMenu *cockatriceMenu, *tabMenu; QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit; TabSupervisor *tabSupervisor;