game menu

This commit is contained in:
Max-Wilhelm Bruker 2009-11-28 18:35:48 +01:00
parent 77015c9ebf
commit 122f8ea916
15 changed files with 75 additions and 35 deletions

View file

@ -41,6 +41,7 @@ HEADERS += src/counter.h \
src/phasestoolbar.h \ src/phasestoolbar.h \
src/gamescene.h \ src/gamescene.h \
src/arrowitem.h \ src/arrowitem.h \
src/tab.h \
src/tab_server.h \ src/tab_server.h \
src/tab_chatchannel.h \ src/tab_chatchannel.h \
src/tab_game.h \ src/tab_game.h \

View file

@ -2,8 +2,8 @@
#include "cardzone.h" #include "cardzone.h"
#include "carditem.h" #include "carditem.h"
#include "player.h" #include "player.h"
#include "client.h"
#include "zoneviewzone.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) 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) : 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) void CardZone::setCardAttr(int cardId, const QString &aname, const QString &avalue)
{ {
/* if (hasCardAttr) if (hasCardAttr)
player->client->setCardAttr(name, cardId, aname, avalue); player->sendGameCommand(new Command_SetCardAttr(-1, name, cardId, aname, avalue));
*/} }
void CardZone::moveAllToZone() void CardZone::moveAllToZone()
{ {

18
cockatrice/src/tab.h Normal file
View file

@ -0,0 +1,18 @@
#ifndef TAB_H
#define TAB_H
#include <QWidget>
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

View file

@ -4,7 +4,7 @@
#include "protocol_items.h" #include "protocol_items.h"
TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName) TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName)
: QWidget(), client(_client), channelName(_channelName) : Tab(), client(_client), channelName(_channelName)
{ {
playerList = new QListWidget; playerList = new QListWidget;
playerList->setFixedWidth(150); playerList->setFixedWidth(150);

View file

@ -1,7 +1,7 @@
#ifndef TAB_CHATCHANNEL_H #ifndef TAB_CHATCHANNEL_H
#define TAB_CHATCHANNEL_H #define TAB_CHATCHANNEL_H
#include <QWidget> #include "tab.h"
class Client; class Client;
class QListWidget; class QListWidget;
@ -13,7 +13,7 @@ class Event_ChatJoinChannel;
class Event_ChatLeaveChannel; class Event_ChatLeaveChannel;
class Event_ChatSay; class Event_ChatSay;
class TabChatChannel : public QWidget { class TabChatChannel : public Tab {
Q_OBJECT Q_OBJECT
private: private:
Client *client; Client *client;

View file

@ -7,7 +7,7 @@
#include "protocol_items.h" #include "protocol_items.h"
TabDeckStorage::TabDeckStorage(Client *_client) TabDeckStorage::TabDeckStorage(Client *_client)
: QWidget(), client(_client) : Tab(), client(_client)
{ {
localDirModel = new QFileSystemModel(this); localDirModel = new QFileSystemModel(this);
QSettings settings; QSettings settings;

View file

@ -1,8 +1,8 @@
#ifndef TAB_DECK_STORAGE_H #ifndef TAB_DECK_STORAGE_H
#define TAB_DECK_STORAGE_H #define TAB_DECK_STORAGE_H
#include <QWidget> #include "tab.h"
#include "protocol_datastructures.h" #include "protocol.h"
class Client; class Client;
class QTreeView; class QTreeView;
@ -15,7 +15,7 @@ class QGroupBox;
class ProtocolResponse; class ProtocolResponse;
class RemoteDeckList_TreeWidget; class RemoteDeckList_TreeWidget;
class TabDeckStorage : public QWidget { class TabDeckStorage : public Tab {
Q_OBJECT Q_OBJECT
private: private:
Client *client; Client *client;

View file

@ -21,7 +21,7 @@
#include "main.h" #include "main.h"
TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectator) 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; zoneLayout = new ZoneViewLayout;
scene = new GameScene(zoneLayout, this); scene = new GameScene(zoneLayout, this);
@ -61,8 +61,8 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
QVBoxLayout *verticalLayout = new QVBoxLayout; QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(cardInfo); verticalLayout->addWidget(cardInfo);
verticalLayout->addWidget(playerListWidget); verticalLayout->addWidget(playerListWidget, 1);
verticalLayout->addWidget(messageLog); verticalLayout->addWidget(messageLog, 3);
verticalLayout->addLayout(hLayout); verticalLayout->addLayout(hLayout);
QHBoxLayout *mainLayout = new QHBoxLayout; QHBoxLayout *mainLayout = new QHBoxLayout;
@ -89,11 +89,12 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
aRemoveLocalArrows = new QAction(this); aRemoveLocalArrows = new QAction(this);
connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows())); connect(aRemoveLocalArrows, SIGNAL(triggered()), this, SLOT(actRemoveLocalArrows()));
gameMenu = new QMenu(this); tabMenu = new QMenu(this);
gameMenu->addAction(aNextPhase); playersSeparator = tabMenu->addSeparator();
gameMenu->addAction(aNextTurn); tabMenu->addAction(aNextPhase);
gameMenu->addSeparator(); tabMenu->addAction(aNextTurn);
gameMenu->addAction(aRemoveLocalArrows); tabMenu->addSeparator();
tabMenu->addAction(aRemoveLocalArrows);
retranslateUi(); retranslateUi();
setLayout(mainLayout); setLayout(mainLayout);
@ -103,7 +104,7 @@ TabGame::TabGame(Client *_client, int _gameId, int _localPlayerId, bool _spectat
void TabGame::retranslateUi() void TabGame::retranslateUi()
{ {
gameMenu->setTitle(tr("&Game")); tabMenu->setTitle(tr("&Game"));
aNextPhase->setText(tr("Next &phase")); aNextPhase->setText(tr("Next &phase"));
aNextPhase->setShortcut(tr("Ctrl+Space")); aNextPhase->setShortcut(tr("Ctrl+Space"));
aNextTurn->setText(tr("Next &turn")); aNextTurn->setText(tr("Next &turn"));
@ -167,8 +168,12 @@ Player *TabGame::addPlayer(int playerId, const QString &playerName)
scene->addPlayer(newPlayer); scene->addPlayer(newPlayer);
connect(newPlayer, SIGNAL(newCardAdded(CardItem *)), this, SLOT(newCardAdded(CardItem *))); 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); messageLog->connectToPlayer(newPlayer);
tabMenu->insertMenu(playersSeparator, newPlayer->getPlayerMenu());
players.insert(playerId, newPlayer); players.insert(playerId, newPlayer);
emit playerAdded(newPlayer); emit playerAdded(newPlayer);

View file

@ -1,8 +1,8 @@
#ifndef TAB_GAME_H #ifndef TAB_GAME_H
#define TAB_GAME_H #define TAB_GAME_H
#include <QWidget>
#include <QMap> #include <QMap>
#include "tab.h"
class Client; class Client;
class CardDatabase; class CardDatabase;
@ -34,7 +34,7 @@ class Player;
class CardZone; class CardZone;
class CardItem; class CardItem;
class TabGame : public QWidget { class TabGame : public Tab {
Q_OBJECT Q_OBJECT
private: private:
Client *client; Client *client;
@ -58,9 +58,10 @@ private:
DeckView *deckView; DeckView *deckView;
QWidget *deckViewContainer; QWidget *deckViewContainer;
ZoneViewLayout *zoneLayout; ZoneViewLayout *zoneLayout;
QAction *playersSeparator;
QMenu *playersMenu;
QAction *aCloseMostRecentZoneView, QAction *aCloseMostRecentZoneView,
*aNextPhase, *aNextTurn, *aRemoveLocalArrows; *aNextPhase, *aNextTurn, *aRemoveLocalArrows;
QMenu *gameMenu;
Player *addPlayer(int playerId, const QString &playerName); Player *addPlayer(int playerId, const QString &playerName);

View file

@ -225,7 +225,7 @@ void ServerMessageLog::processServerMessageEvent(Event_ServerMessage *event)
} }
TabServer::TabServer(Client *_client, QWidget *parent) TabServer::TabServer(Client *_client, QWidget *parent)
: QWidget(parent), client(_client) : Tab(parent), client(_client)
{ {
gameSelector = new GameSelector(client); gameSelector = new GameSelector(client);
chatChannelSelector = new ChatChannelSelector(client); chatChannelSelector = new ChatChannelSelector(client);

View file

@ -2,6 +2,7 @@
#define TAB_SERVER_H #define TAB_SERVER_H
#include <QGroupBox> #include <QGroupBox>
#include "tab.h"
#include "protocol_datastructures.h" #include "protocol_datastructures.h"
class Client; class Client;
@ -71,7 +72,7 @@ public:
void retranslateUi(); void retranslateUi();
}; };
class TabServer : public QWidget { class TabServer : public Tab {
Q_OBJECT Q_OBJECT
signals: signals:
void chatChannelJoined(const QString &channelName); void chatChannelJoined(const QString &channelName);

View file

@ -11,6 +11,7 @@ TabSupervisor:: TabSupervisor(QWidget *parent)
: QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0) : QTabWidget(parent), client(0), tabServer(0), tabDeckStorage(0)
{ {
setIconSize(QSize(15, 15)); setIconSize(QSize(15, 15));
connect(this, SIGNAL(currentChanged(int)), this, SLOT(updateMenu(int)));
} }
void TabSupervisor::retranslateUi() void TabSupervisor::retranslateUi()
@ -131,3 +132,11 @@ void TabSupervisor::processGameEvent(GameEvent *event)
} else } else
qDebug() << "gameEvent: invalid gameId"; qDebug() << "gameEvent: invalid gameId";
} }
void TabSupervisor::updateMenu(int index)
{
if (index != -1)
emit setMenu(static_cast<Tab *>(widget(index))->getTabMenu());
else
emit setMenu(0);
}

View file

@ -4,6 +4,7 @@
#include <QTabWidget> #include <QTabWidget>
#include <QMap> #include <QMap>
class QMenu;
class Client; class Client;
class TabServer; class TabServer;
class TabChatChannel; class TabChatChannel;
@ -26,7 +27,10 @@ public:
void retranslateUi(); void retranslateUi();
void start(Client *_client); void start(Client *_client);
void stop(); void stop();
signals:
void setMenu(QMenu *menu);
private slots: private slots:
void updateMenu(int index);
void updatePingTime(int value, int max); void updatePingTime(int value, int max);
void gameJoined(Event_GameJoined *event); void gameJoined(Event_GameJoined *event);
void addChatChannelTab(const QString &channelName); void addChatChannelTab(const QString &channelName);

View file

@ -18,7 +18,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/ ***************************************************************************/
#include <QtGui> #include <QtGui>
//#include <QtOpenGL>
#include "window_main.h" #include "window_main.h"
#include "dlg_connect.h" #include "dlg_connect.h"
@ -26,14 +25,15 @@
#include "window_deckeditor.h" #include "window_deckeditor.h"
#include "tab_supervisor.h" #include "tab_supervisor.h"
/* void MainWindow::updateTabMenu(QMenu *menu)
void MainWindow::playerAdded(Player *player)
{ {
menuBar()->addMenu(player->getPlayerMenu()); if (tabMenu)
connect(player, SIGNAL(toggleZoneView(Player *, QString, int)), zoneLayout, SLOT(toggleZoneView(Player *, QString, int))); menuBar()->removeAction(tabMenu->menuAction());
connect(player, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *))); tabMenu = menu;
if (menu)
menuBar()->addMenu(menu);
} }
*/
void MainWindow::statusChanged(ClientStatus _status) void MainWindow::statusChanged(ClientStatus _status)
{ {
switch (_status) { switch (_status) {
@ -207,12 +207,13 @@ void MainWindow::createMenus()
} }
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent), tabMenu(0)
{ {
QPixmapCache::setCacheLimit(200000); QPixmapCache::setCacheLimit(200000);
client = new Client(this); client = new Client(this);
tabSupervisor = new TabSupervisor; tabSupervisor = new TabSupervisor;
connect(tabSupervisor, SIGNAL(setMenu(QMenu *)), this, SLOT(updateTabMenu(QMenu *)));
setCentralWidget(tabSupervisor); setCentralWidget(tabSupervisor);
/* /*

View file

@ -28,7 +28,7 @@ class TabSupervisor;
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
private slots: private slots:
// void playerAdded(Player *player); void updateTabMenu(QMenu *menu);
void statusChanged(ClientStatus _status); void statusChanged(ClientStatus _status);
void serverTimeout(); void serverTimeout();
@ -46,7 +46,7 @@ private:
void retranslateUi(); void retranslateUi();
void createActions(); void createActions();
void createMenus(); void createMenus();
QMenu *cockatriceMenu; QMenu *cockatriceMenu, *tabMenu;
QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit; QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
TabSupervisor *tabSupervisor; TabSupervisor *tabSupervisor;