some gui code

This commit is contained in:
Max-Wilhelm Bruker
2009-11-16 17:18:13 +01:00
parent cb9a2bf23a
commit 77f5ec29eb
37 changed files with 260 additions and 282 deletions

View File

@@ -8,9 +8,10 @@
#include "player.h" #include "player.h"
#include "game.h" #include "game.h"
#include "arrowitem.h" #include "arrowitem.h"
#include "main.h"
CardItem::CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphicsItem *parent) CardItem::CardItem(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) : 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); setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable); setFlag(ItemIsSelectable);

View File

@@ -23,7 +23,6 @@ enum CardItemType {
class CardItem : public QObject, public AbstractGraphicsItem { class CardItem : public QObject, public AbstractGraphicsItem {
Q_OBJECT Q_OBJECT
private: private:
CardDatabase *db;
CardInfo *info; CardInfo *info;
QString name; QString name;
int id; int id;
@@ -40,7 +39,7 @@ private slots:
public: public:
enum { Type = typeCard }; enum { Type = typeCard };
int type() const { return Type; } 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(); ~CardItem();
QRectF boundingRect() const; QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

View File

@@ -84,7 +84,7 @@ void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
{ {
if (view) if (view)
if ((x <= view->getCards().size()) || (view->getNumberCards() == -1)) 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); addCardImpl(card, x, y);

View File

@@ -288,23 +288,24 @@ void Client::processProtocolItem(ProtocolItem *item)
case ItemId_Event_ListGames: emit listGamesEventReceived(qobject_cast<Event_ListGames *>(item)); break; case ItemId_Event_ListGames: emit listGamesEventReceived(qobject_cast<Event_ListGames *>(item)); break;
case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(item)); break; case ItemId_Event_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(item)); break;
case ItemId_Event_ListChatChannels: emit listChatChannelsEventReceived(qobject_cast<Event_ListChatChannels *>(item)); break; case ItemId_Event_ListChatChannels: emit listChatChannelsEventReceived(qobject_cast<Event_ListChatChannels *>(item)); break;
case ItemId_Event_GameJoined: emit gameJoinedEventReceived(qobject_cast<Event_GameJoined *>(item)); break;
} }
delete genericEvent; delete genericEvent;
return; return;
} }
/* GameEvent *gameEvent = qobject_cast<GameEvent *>(item); GameEvent *gameEvent = qobject_cast<GameEvent *>(item);
if (gameEvent) { if (gameEvent) {
emit gameEventReceived(gameEvent); emit gameEventReceived(gameEvent);
delete gameEvent; delete gameEvent;
return; return;
} }
*/
ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item); ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item);
if (chatEvent) { if (chatEvent) {
qDebug() << "chatEventReceived()";
emit chatEventReceived(chatEvent); emit chatEventReceived(chatEvent);
delete chatEvent; delete chatEvent;
return;
} }
} }

View File

@@ -18,6 +18,7 @@ class GameEvent;
class Event_ListGames; class Event_ListGames;
class Event_ServerMessage; class Event_ServerMessage;
class Event_ListChatChannels; class Event_ListChatChannels;
class Event_GameJoined;
enum ClientStatus { enum ClientStatus {
StatusDisconnected, StatusDisconnected,
@@ -32,7 +33,6 @@ class Client : public QObject {
signals: signals:
void statusChanged(ClientStatus _status); void statusChanged(ClientStatus _status);
// void playerIdReceived(int id, QString name); // void playerIdReceived(int id, QString name);
// void gameEvent(const ServerEventData &msg);
void maxPingTime(int seconds, int maxSeconds); void maxPingTime(int seconds, int maxSeconds);
void serverTimeout(); void serverTimeout();
void logSocketError(const QString &errorString); void logSocketError(const QString &errorString);
@@ -48,6 +48,7 @@ signals:
void listGamesEventReceived(Event_ListGames *event); void listGamesEventReceived(Event_ListGames *event);
void serverMessageEventReceived(Event_ServerMessage *event); void serverMessageEventReceived(Event_ServerMessage *event);
void listChatChannelsEventReceived(Event_ListChatChannels *event); void listChatChannelsEventReceived(Event_ListChatChannels *event);
void gameJoinedEventReceived(Event_GameJoined *event);
private slots: private slots:
void slotConnected(); void slotConnected();

View File

@@ -1,5 +1,6 @@
#include <QtGui> #include <QtGui>
#include "dlg_creategame.h" #include "dlg_creategame.h"
#include "protocol_items.h"
DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent) DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
: QDialog(parent), client(_client) : QDialog(parent), client(_client)
@@ -58,13 +59,15 @@ void DlgCreateGame::actOK()
QMessageBox::critical(this, tr("Error"), tr("Invalid number of players.")); QMessageBox::critical(this, tr("Error"), tr("Invalid number of players."));
return; return;
} }
// PendingCommand *createCommand = client->createGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked()); Command_CreateGame *createCommand = new Command_CreateGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers, spectatorsAllowedCheckBox->isChecked());
// connect(createCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse))); connect(createCommand, SIGNAL(finished(ResponseCode)), this, SLOT(checkResponse(ResponseCode)));
client->sendCommand(createCommand);
okButton->setEnabled(false); okButton->setEnabled(false);
cancelButton->setEnabled(false); cancelButton->setEnabled(false);
} }
/*void DlgCreateGame::checkResponse(ServerResponse response) void DlgCreateGame::checkResponse(ResponseCode response)
{ {
okButton->setEnabled(true); okButton->setEnabled(true);
cancelButton->setEnabled(true); cancelButton->setEnabled(true);
@@ -76,4 +79,3 @@ void DlgCreateGame::actOK()
return; return;
} }
} }
*/

View File

@@ -15,7 +15,7 @@ public:
DlgCreateGame(Client *_client, QWidget *parent = 0); DlgCreateGame(Client *_client, QWidget *parent = 0);
private slots: private slots:
void actOK(); void actOK();
// void checkResponse(ServerResponse response); void checkResponse(ResponseCode response);
private: private:
Client *client; Client *client;
@@ -26,4 +26,3 @@ private:
}; };
#endif #endif

View File

@@ -2,6 +2,7 @@
#include "carddatabase.h" #include "carddatabase.h"
#include "dlg_settings.h" #include "dlg_settings.h"
#include "main.h"
GeneralSettingsPage::GeneralSettingsPage() GeneralSettingsPage::GeneralSettingsPage()
{ {
@@ -397,8 +398,8 @@ void MessagesSettingsPage::retranslateUi()
aRemove->setText(tr("&Remove")); aRemove->setText(tr("&Remove"));
} }
DlgSettings::DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *parent) DlgSettings::DlgSettings(QWidget *parent)
: QDialog(parent), db(_db), translator(_translator) : QDialog(parent)
{ {
contentsWidget = new QListWidget; contentsWidget = new QListWidget;
contentsWidget->setViewMode(QListView::IconMode); contentsWidget->setViewMode(QListView::IconMode);

View File

@@ -4,7 +4,6 @@
#include <QDialog> #include <QDialog>
class CardDatabase; class CardDatabase;
class QTranslator;
class QListWidget; class QListWidget;
class QListWidgetItem; class QListWidgetItem;
class QStackedWidget; class QStackedWidget;
@@ -90,13 +89,11 @@ private:
class DlgSettings : public QDialog { class DlgSettings : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
DlgSettings(CardDatabase *_db, QTranslator *_translator, QWidget *parent = 0); DlgSettings(QWidget *parent = 0);
private slots: private slots:
void changePage(QListWidgetItem *current, QListWidgetItem *previous); void changePage(QListWidgetItem *current, QListWidgetItem *previous);
void changeLanguage(const QString &qmFile); void changeLanguage(const QString &qmFile);
private: private:
CardDatabase *db;
QTranslator *translator;
QListWidget *contentsWidget; QListWidget *contentsWidget;
QStackedWidget *pagesWidget; QStackedWidget *pagesWidget;
QListWidgetItem *generalButton, *appearanceButton, *messagesButton; QListWidgetItem *generalButton, *appearanceButton, *messagesButton;

View File

@@ -135,7 +135,7 @@ void Game::retranslateUi()
Player *Game::addPlayer(int playerId, const QString &playerName, bool local) 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); scene->addPlayer(newPlayer);
connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint))); connect(newPlayer, SIGNAL(sigShowCardMenu(QPoint)), this, SLOT(showCardMenu(QPoint)));

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 <QApplication> #include <QApplication>
#include <QTextCodec> #include <QTextCodec>
#include <QtPlugin> #include <QtPlugin>
@@ -29,10 +28,15 @@
#include <QIcon> #include <QIcon>
#include <stdio.h> #include <stdio.h>
#include "main.h"
#include "window_main.h" #include "window_main.h"
#include "carddatabase.h"
//Q_IMPORT_PLUGIN(qjpeg) //Q_IMPORT_PLUGIN(qjpeg)
CardDatabase *db;
QTranslator *translator;
void myMessageOutput(QtMsgType type, const char *msg) void myMessageOutput(QtMsgType type, const char *msg)
{ {
static FILE *f = NULL; static FILE *f = NULL;
@@ -53,24 +57,26 @@ int main(int argc, char *argv[])
QCoreApplication::setOrganizationDomain("cockatrice.de"); QCoreApplication::setOrganizationDomain("cockatrice.de");
QCoreApplication::setApplicationName("Cockatrice"); QCoreApplication::setApplicationName("Cockatrice");
db = new CardDatabase;
QString localeName;// = QLocale::system().name(); QString localeName;// = QLocale::system().name();
QTranslator qtTranslator; QTranslator qtTranslator;
qtTranslator.load("qt_" + localeName, QLibraryInfo::location(QLibraryInfo::TranslationsPath)); qtTranslator.load("qt_" + localeName, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator); app.installTranslator(&qtTranslator);
QTranslator translator; translator = new QTranslator;
QSettings settings; QSettings settings;
settings.beginGroup("personal"); settings.beginGroup("personal");
QString lang = settings.value("lang").toString(); QString lang = settings.value("lang").toString();
if (lang.isEmpty()) if (lang.isEmpty())
translator.load("cockatrice_" + localeName, ":/translations", QString(), ".qm"); translator->load("cockatrice_" + localeName, ":/translations", QString(), ".qm");
else else
translator.load(lang); translator->load(lang);
app.installTranslator(&translator); app.installTranslator(translator);
qsrand(QDateTime::currentDateTime().toTime_t()); qsrand(QDateTime::currentDateTime().toTime_t());
MainWindow ui(&translator); MainWindow ui;
qDebug("main(): MainWindow constructor finished"); qDebug("main(): MainWindow constructor finished");
QIcon icon(":/resources/icon.svg"); QIcon icon(":/resources/icon.svg");
@@ -81,4 +87,3 @@ int main(int argc, char *argv[])
return app.exec(); return app.exec();
} }

10
cockatrice/src/main.h Normal file
View File

@@ -0,0 +1,10 @@
#ifndef MAIN_H
#define MAIN_H
class CardDatabase;
class QTranslator;
extern CardDatabase *db;
extern QTranslator *translator;
#endif

View File

@@ -14,8 +14,8 @@
#include <QPainter> #include <QPainter>
#include <QMenu> #include <QMenu>
Player::Player(const QString &_name, int _id, bool _local, CardDatabase *_db, Client *_client, Game *_parent) 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), db(_db), client(_client) : QObject(_parent), defaultNumberTopCards(3), name(_name), id(_id), active(false), local(_local), client(_client)
{ {
QSettings settings; QSettings settings;
QString bgPath = settings.value("zonebg/playerarea").toString(); QString bgPath = settings.value("zonebg/playerarea").toString();

View File

@@ -75,7 +75,6 @@ private:
TableZone *table; TableZone *table;
HandZone *hand; HandZone *hand;
CardDatabase *db;
void setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards); void setCardAttrHelper(CardItem *card, const QString &aname, const QString &avalue, bool allCards);
QPixmap bgPixmap; QPixmap bgPixmap;
@@ -104,7 +103,7 @@ public:
Client *client; Client *client;
void addZone(CardZone *z); 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(); ~Player();
void retranslateUi(); void retranslateUi();
QMenu *getPlayerMenu() const { return playerMenu; } QMenu *getPlayerMenu() const { return playerMenu; }
@@ -115,7 +114,6 @@ public:
const QMap<int, ArrowItem *> &getArrows() const { return arrows; } const QMap<int, ArrowItem *> &getArrows() const { return arrows; }
TableZone *getTable() const { return table; } TableZone *getTable() const { return table; }
// void gameEvent(const ServerEventData &event); // void gameEvent(const ServerEventData &event);
CardDatabase *getDb() const { return db; }
void showCardMenu(const QPoint &p); void showCardMenu(const QPoint &p);
bool getActive() const { return active; } bool getActive() const { return active; }
void setActive(bool _active); void setActive(bool _active);

View File

@@ -1 +1,57 @@
#include <QtGui>
#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)
{
}

View File

@@ -1 +1,42 @@
#ifndef TAB_GAME_H
#define TAB_GAME_H
#include <QWidget>
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

View File

@@ -63,7 +63,6 @@ void GameSelector::checkResponse(ResponseCode response)
spectateButton->setEnabled(true); spectateButton->setEnabled(true);
switch (response) { 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 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 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; 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) void ChatChannelSelector::joinChannel(const QString &channelName)
{ {
Command_ChatJoinChannel *command = new Command_ChatJoinChannel(channelName); Command_ChatJoinChannel *command = new Command_ChatJoinChannel(channelName);

View File

@@ -22,6 +22,7 @@ void TabSupervisor::start(Client *_client)
client = _client; client = _client;
connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *))); connect(client, SIGNAL(chatEventReceived(ChatEvent *)), this, SLOT(processChatEvent(ChatEvent *)));
connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *))); connect(client, SIGNAL(gameEventReceived(GameEvent *)), this, SLOT(processGameEvent(GameEvent *)));
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
tabServer = new TabServer(client); tabServer = new TabServer(client);
connect(tabServer, SIGNAL(gameJoined(int)), this, SLOT(addGameTab(int))); connect(tabServer, SIGNAL(gameJoined(int)), this, SLOT(addGameTab(int)));
@@ -34,12 +35,32 @@ void TabSupervisor::start(Client *_client)
void TabSupervisor::stop() void TabSupervisor::stop()
{ {
if (!client)
return;
disconnect(client, 0, this, 0);
clear();
delete tabServer;
tabServer = 0;
QMapIterator<QString, TabChatChannel *> chatChannelIterator(chatChannelTabs);
while (chatChannelIterator.hasNext())
delete chatChannelIterator.next().value();
chatChannelTabs.clear();
QMapIterator<int, TabGame *> 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) void TabSupervisor::addChatChannelTab(const QString &channelName)
@@ -58,5 +79,7 @@ void TabSupervisor::processChatEvent(ChatEvent *event)
void TabSupervisor::processGameEvent(GameEvent *event) void TabSupervisor::processGameEvent(GameEvent *event)
{ {
TabGame *tab = gameTabs.value(event->getGameId());
if (tab)
tab->processGameEvent(event);
} }

View File

@@ -10,6 +10,7 @@ class TabChatChannel;
class TabGame; class TabGame;
class ChatEvent; class ChatEvent;
class GameEvent; class GameEvent;
class Event_GameJoined;
class TabSupervisor : public QTabWidget { class TabSupervisor : public QTabWidget {
Q_OBJECT Q_OBJECT
@@ -24,7 +25,7 @@ public:
void start(Client *_client); void start(Client *_client);
void stop(); void stop();
private slots: private slots:
void addGameTab(int gameId); void gameJoined(Event_GameJoined *event);
void addChatChannelTab(const QString &channelName); void addChatChannelTab(const QString &channelName);
void processChatEvent(ChatEvent *event); void processChatEvent(ChatEvent *event);
void processGameEvent(GameEvent *event); void processGameEvent(GameEvent *event);

View File

@@ -5,6 +5,7 @@
#include "carddatabasemodel.h" #include "carddatabasemodel.h"
#include "decklistmodel.h" #include "decklistmodel.h"
#include "cardinfowidget.h" #include "cardinfowidget.h"
#include "main.h"
void SearchLineEdit::keyPressEvent(QKeyEvent *event) void SearchLineEdit::keyPressEvent(QKeyEvent *event)
{ {
@@ -13,8 +14,8 @@ void SearchLineEdit::keyPressEvent(QKeyEvent *event)
QLineEdit::keyPressEvent(event); QLineEdit::keyPressEvent(event);
} }
WndDeckEditor::WndDeckEditor(CardDatabase *_db, QWidget *parent) WndDeckEditor::WndDeckEditor(QWidget *parent)
: QMainWindow(parent), db(_db) : QMainWindow(parent)
{ {
QLabel *searchLabel = new QLabel(tr("&Search for:")); QLabel *searchLabel = new QLabel(tr("&Search for:"));
searchEdit = new SearchLineEdit; searchEdit = new SearchLineEdit;
@@ -281,7 +282,7 @@ void WndDeckEditor::actPrintDeck()
void WndDeckEditor::actEditSets() void WndDeckEditor::actEditSets()
{ {
WndSets *w = new WndSets(db, this); WndSets *w = new WndSets(this);
w->setWindowModality(Qt::WindowModal); w->setWindowModality(Qt::WindowModal);
w->show(); w->show();
} }

View File

@@ -6,7 +6,6 @@
#include <QLineEdit> #include <QLineEdit>
#include "decklist.h" #include "decklist.h"
class CardDatabase;
class CardDatabaseModel; class CardDatabaseModel;
class CardDatabaseDisplayModel; class CardDatabaseDisplayModel;
class DeckListModel; class DeckListModel;
@@ -54,7 +53,6 @@ private:
QString lastFileName; QString lastFileName;
DeckList::FileFormat lastFileFormat; DeckList::FileFormat lastFileFormat;
CardDatabase *db;
CardDatabaseModel *databaseModel; CardDatabaseModel *databaseModel;
CardDatabaseDisplayModel *databaseDisplayModel; CardDatabaseDisplayModel *databaseDisplayModel;
@@ -71,7 +69,7 @@ private:
QAction *aEditSets; QAction *aEditSets;
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement; QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
public: public:
WndDeckEditor(CardDatabase *_db, QWidget *parent = 0); WndDeckEditor(QWidget *parent = 0);
~WndDeckEditor(); ~WndDeckEditor();
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);

View File

@@ -24,17 +24,6 @@
#include "dlg_connect.h" #include "dlg_connect.h"
#include "dlg_settings.h" #include "dlg_settings.h"
#include "window_deckeditor.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" #include "tab_supervisor.h"
PingWidget::PingWidget(QWidget *parent) 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); color.setHsv(120 * (1.0 - ((double) value / max)), 255, 255);
update(); update();
} }
/*
void MainWindow::playerAdded(Player *player) void MainWindow::playerAdded(Player *player)
{ {
menuBar()->addMenu(player->getPlayerMenu()); menuBar()->addMenu(player->getPlayerMenu());
connect(player, SIGNAL(toggleZoneView(Player *, QString, int)), zoneLayout, SLOT(toggleZoneView(Player *, QString, int))); connect(player, SIGNAL(toggleZoneView(Player *, QString, int)), zoneLayout, SLOT(toggleZoneView(Player *, QString, int)));
connect(player, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *))); connect(player, SIGNAL(closeZoneView(ZoneViewZone *)), zoneLayout, SLOT(removeItem(ZoneViewZone *)));
} }
*/
void MainWindow::statusChanged(ClientStatus _status) void MainWindow::statusChanged(ClientStatus _status)
{ {
switch (_status) { switch (_status) {
@@ -80,16 +69,17 @@ void MainWindow::statusChanged(ClientStatus _status)
emit logConnecting(client->peerName()); emit logConnecting(client->peerName());
break; break;
case StatusDisconnected: case StatusDisconnected:
if (game) { tabSupervisor->stop();
zoneLayout->clear(); // if (game) {
delete game; // zoneLayout->clear();
game = 0; // delete game;
} // game = 0;
// }
// pingWidget->setPercentage(0, -1); // pingWidget->setPercentage(0, -1);
aConnect->setEnabled(true); aConnect->setEnabled(true);
aDisconnect->setEnabled(false); aDisconnect->setEnabled(false);
aRestartGame->setEnabled(false); // aRestartGame->setEnabled(false);
aLeaveGame->setEnabled(false); // aLeaveGame->setEnabled(false);
// phasesToolbar->setActivePhase(-1); // phasesToolbar->setActivePhase(-1);
// phasesToolbar->hide(); // phasesToolbar->hide();
emit logDisconnected(); emit logDisconnected();
@@ -155,7 +145,7 @@ void MainWindow::actDisconnect()
{ {
client->disconnectFromServer(); client->disconnectFromServer();
} }
/*
void MainWindow::actRestartGame() void MainWindow::actRestartGame()
{ {
zoneLayout->clear(); zoneLayout->clear();
@@ -166,10 +156,10 @@ void MainWindow::actLeaveGame()
{ {
client->leaveGame(); client->leaveGame();
} }
*/
void MainWindow::actDeckEditor() void MainWindow::actDeckEditor()
{ {
WndDeckEditor *deckEditor = new WndDeckEditor(db, this); WndDeckEditor *deckEditor = new WndDeckEditor(this);
deckEditor->show(); deckEditor->show();
} }
@@ -183,7 +173,7 @@ void MainWindow::actFullScreen(bool checked)
void MainWindow::actSettings() void MainWindow::actSettings()
{ {
DlgSettings dlg(db, translator, this); DlgSettings dlg(this);
dlg.exec(); dlg.exec();
} }
@@ -191,7 +181,7 @@ void MainWindow::actExit()
{ {
close(); close();
} }
/*
void MainWindow::actSay() void MainWindow::actSay()
{ {
if (sayEdit->text().isEmpty()) if (sayEdit->text().isEmpty())
@@ -200,7 +190,7 @@ void MainWindow::actSay()
client->say(sayEdit->text()); client->say(sayEdit->text());
sayEdit->clear(); sayEdit->clear();
} }
*/
void MainWindow::serverTimeout() void MainWindow::serverTimeout()
{ {
QMessageBox::critical(this, tr("Error"), tr("Server timeout")); QMessageBox::critical(this, tr("Error"), tr("Server timeout"));
@@ -212,9 +202,9 @@ void MainWindow::retranslateUi()
aConnect->setText(tr("&Connect...")); aConnect->setText(tr("&Connect..."));
aDisconnect->setText(tr("&Disconnect")); aDisconnect->setText(tr("&Disconnect"));
aRestartGame->setText(tr("&Restart game...")); // aRestartGame->setText(tr("&Restart game..."));
aRestartGame->setShortcut(tr("F2")); // aRestartGame->setShortcut(tr("F2"));
aLeaveGame->setText(tr("&Leave game")); // aLeaveGame->setText(tr("&Leave game"));
aDeckEditor->setText(tr("&Deck editor")); aDeckEditor->setText(tr("&Deck editor"));
aFullScreen->setText(tr("&Full screen")); aFullScreen->setText(tr("&Full screen"));
aFullScreen->setShortcut(tr("Ctrl+F")); aFullScreen->setShortcut(tr("Ctrl+F"));
@@ -242,13 +232,13 @@ void MainWindow::createActions()
aDisconnect = new QAction(this); aDisconnect = new QAction(this);
aDisconnect->setEnabled(false); aDisconnect->setEnabled(false);
connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect())); connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect()));
aRestartGame = new QAction(this); /* aRestartGame = new QAction(this);
aRestartGame->setEnabled(false); aRestartGame->setEnabled(false);
connect(aRestartGame, SIGNAL(triggered()), this, SLOT(actRestartGame())); connect(aRestartGame, SIGNAL(triggered()), this, SLOT(actRestartGame()));
aLeaveGame = new QAction(this); aLeaveGame = new QAction(this);
aLeaveGame->setEnabled(false); aLeaveGame->setEnabled(false);
connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame())); connect(aLeaveGame, SIGNAL(triggered()), this, SLOT(actLeaveGame()));
aDeckEditor = new QAction(this); */ aDeckEditor = new QAction(this);
connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor())); connect(aDeckEditor, SIGNAL(triggered()), this, SLOT(actDeckEditor()));
aFullScreen = new QAction(this); aFullScreen = new QAction(this);
aFullScreen->setCheckable(true); aFullScreen->setCheckable(true);
@@ -269,9 +259,6 @@ void MainWindow::createMenus()
cockatriceMenu->addAction(aConnect); cockatriceMenu->addAction(aConnect);
cockatriceMenu->addAction(aDisconnect); cockatriceMenu->addAction(aDisconnect);
cockatriceMenu->addSeparator(); cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aRestartGame);
cockatriceMenu->addAction(aLeaveGame);
cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aDeckEditor); cockatriceMenu->addAction(aDeckEditor);
cockatriceMenu->addSeparator(); cockatriceMenu->addSeparator();
cockatriceMenu->addAction(aFullScreen); cockatriceMenu->addAction(aFullScreen);
@@ -281,67 +268,17 @@ void MainWindow::createMenus()
cockatriceMenu->addAction(aExit); cockatriceMenu->addAction(aExit);
} }
MainWindow::MainWindow(QTranslator *_translator, QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), game(NULL), translator(_translator) : QMainWindow(parent)
{ {
QPixmapCache::setCacheLimit(200000); QPixmapCache::setCacheLimit(200000);
db = new CardDatabase(this);
client = new Client(this); client = new Client(this);
tabSupervisor = new TabSupervisor; tabSupervisor = new TabSupervisor;
setCentralWidget(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(logConnecting(QString)), messageLog, SLOT(logConnecting(QString)));
connect(this, SIGNAL(logConnected()), messageLog, SLOT(logConnected())); connect(this, SIGNAL(logConnected()), messageLog, SLOT(logConnected()));
connect(this, SIGNAL(logDisconnected()), messageLog, SLOT(logDisconnected())); 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(serverError(ResponseCode)), messageLog, SLOT(logServerError(ResponseCode)));
connect(client, SIGNAL(protocolVersionMismatch(int, int)), messageLog, SLOT(logProtocolVersionMismatch(int, int))); connect(client, SIGNAL(protocolVersionMismatch(int, int)), messageLog, SLOT(logProtocolVersionMismatch(int, int)));
connect(client, SIGNAL(protocolError()), messageLog, SLOT(logProtocolError())); 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(serverTimeout()), this, SLOT(serverTimeout()));
connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus))); connect(client, SIGNAL(statusChanged(ClientStatus)), this, SLOT(statusChanged(ClientStatus)));
@@ -365,7 +300,7 @@ MainWindow::MainWindow(QTranslator *_translator, QWidget *parent)
void MainWindow::closeEvent(QCloseEvent */*event*/) void MainWindow::closeEvent(QCloseEvent */*event*/)
{ {
delete game; delete tabSupervisor;
} }
void MainWindow::changeEvent(QEvent *event) void MainWindow::changeEvent(QEvent *event)

View File

@@ -23,26 +23,6 @@
#include <QMainWindow> #include <QMainWindow>
#include "client.h" #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 TabSupervisor;
class PingWidget : public QWidget { class PingWidget : public QWidget {
@@ -61,16 +41,12 @@ public slots:
class MainWindow : public QMainWindow { class MainWindow : public QMainWindow {
Q_OBJECT Q_OBJECT
private slots: private slots:
void playerAdded(Player *player); // void playerAdded(Player *player);
void statusChanged(ClientStatus _status); void statusChanged(ClientStatus _status);
void serverTimeout(); void serverTimeout();
void actSay();
void actConnect(); void actConnect();
void actDisconnect(); void actDisconnect();
void actRestartGame();
void actLeaveGame();
void actDeckEditor(); void actDeckEditor();
void actFullScreen(bool checked); void actFullScreen(bool checked);
void actSettings(); void actSettings();
@@ -84,29 +60,15 @@ private:
void createActions(); void createActions();
void createMenus(); void createMenus();
QMenu *cockatriceMenu; QMenu *cockatriceMenu;
QAction *aConnect, *aDisconnect, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aSettings, *aExit; QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
QAction *aCloseMostRecentZoneView; QAction *aCloseMostRecentZoneView;
TabSupervisor *tabSupervisor; TabSupervisor *tabSupervisor;
QVBoxLayout *viewLayout;
PingWidget *pingWidget; PingWidget *pingWidget;
CardInfoWidget *cardInfo;
MessageLogWidget *messageLog;
QLabel *sayLabel;
QLineEdit *sayEdit;
PhasesToolbar *phasesToolbar;
GameSelector *gameSelector;
ChatWidget *chatWidget;
Client *client; Client *client;
GameScene *scene;
GameView *view;
Game *game;
CardDatabase *db;
ZoneViewLayout *zoneLayout;
QTranslator *translator;
public: public:
MainWindow(QTranslator *_translator, QWidget *parent = 0); MainWindow(QWidget *parent = 0);
protected: protected:
void closeEvent(QCloseEvent *event); void closeEvent(QCloseEvent *event);
void changeEvent(QEvent *event); void changeEvent(QEvent *event);

View File

@@ -1,11 +1,12 @@
#include "window_sets.h" #include "window_sets.h"
#include "setsmodel.h" #include "setsmodel.h"
#include "main.h"
#include <QtGui> #include <QtGui>
WndSets::WndSets(CardDatabase *_db, QWidget *parent) WndSets::WndSets(QWidget *parent)
: QMainWindow(parent) : QMainWindow(parent)
{ {
model = new SetsModel(_db, this); model = new SetsModel(db, this);
view = new QTreeView; view = new QTreeView;
view->setModel(model); view->setModel(model);
view->setAlternatingRowColors(true); view->setAlternatingRowColors(true);

View File

@@ -13,7 +13,7 @@ private:
SetsModel *model; SetsModel *model;
QTreeView *view; QTreeView *view;
public: public:
WndSets(CardDatabase *_db, QWidget *parent = 0); WndSets(QWidget *parent = 0);
~WndSets(); ~WndSets();
}; };

View File

@@ -3,8 +3,8 @@
#include "zoneviewzone.h" #include "zoneviewzone.h"
#include "player.h" #include "player.h"
ZoneViewLayout::ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent) ZoneViewLayout::ZoneViewLayout(QGraphicsItem *parent)
: QGraphicsWidget(parent), db(_db) : QGraphicsWidget(parent)
{ {
resize(0, 0); 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); views.append(item);
connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeItem(ZoneViewWidget *))); connect(item, SIGNAL(closePressed(ZoneViewWidget *)), this, SLOT(removeItem(ZoneViewWidget *)));
connect(item, SIGNAL(sizeChanged()), this, SLOT(reorganize())); connect(item, SIGNAL(sizeChanged()), this, SLOT(reorganize()));

View File

@@ -3,7 +3,6 @@
#include <QGraphicsWidget> #include <QGraphicsWidget>
class CardDatabase;
class ZoneViewWidget; class ZoneViewWidget;
class ZoneViewZone; class ZoneViewZone;
class Player; class Player;
@@ -14,9 +13,8 @@ signals:
void sizeChanged(); void sizeChanged();
private: private:
QList<ZoneViewWidget *> views; QList<ZoneViewWidget *> views;
CardDatabase *db;
public: public:
ZoneViewLayout(CardDatabase *_db, QGraphicsItem *parent = 0); ZoneViewLayout(QGraphicsItem *parent = 0);
void retranslateUi(); void retranslateUi();
public slots: public slots:
void toggleZoneView(Player *player, const QString &zoneName, int numberCards = 0); void toggleZoneView(Player *player, const QString &zoneName, int numberCards = 0);

View File

@@ -7,8 +7,8 @@
#include "client.h" #include "client.h"
#include "gamescene.h" #include "gamescene.h"
ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent) ZoneViewWidget::ZoneViewWidget(Player *_player, CardZone *_origZone, int numberCards, QGraphicsItem *parent)
: QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), db(_db), player(_player) : QGraphicsWidget(parent, Qt::Tool | Qt::CustomizeWindowHint | Qt::WindowSystemMenuHint | Qt::WindowTitleHint/* | Qt::WindowCloseButtonHint*/), player(_player)
{ {
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);

View File

@@ -20,7 +20,6 @@ private:
QScrollBar *scrollBar; QScrollBar *scrollBar;
QCheckBox *sortCheckBox, *shuffleCheckBox; QCheckBox *sortCheckBox, *shuffleCheckBox;
CardDatabase *db;
Player *player; Player *player;
signals: signals:
void closePressed(ZoneViewWidget *zv); void closePressed(ZoneViewWidget *zv);
@@ -28,7 +27,7 @@ signals:
private slots: private slots:
void resizeToZoneContents(); void resizeToZoneContents();
public: 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; } ZoneViewZone *getZone() const { return zone; }
void retranslateUi(); void retranslateUi();
protected: protected:

View File

@@ -34,7 +34,7 @@ void ZoneViewZone::initializeCards()
int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size()); int number = numberCards == -1 ? c.size() : (numberCards < c.size() ? numberCards : c.size());
for (int i = 0; i < number; i++) { for (int i = 0; i < number; i++) {
CardItem *card = c.at(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(); emit contentsChanged();
reorganizeCards(); reorganizeCards();
@@ -44,7 +44,7 @@ void ZoneViewZone::initializeCards()
void ZoneViewZone::zoneDumpReceived(QList<ServerZoneCard> cards) void ZoneViewZone::zoneDumpReceived(QList<ServerZoneCard> cards)
{ {
for (int i = 0; i < cards.size(); i++) { 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); addCard(card, false, i);
} }

View File

@@ -51,8 +51,9 @@ ItemId_Event_SetActivePhase = 1049,
ItemId_Event_DumpZone = 1050, ItemId_Event_DumpZone = 1050,
ItemId_Event_StopDumpZone = 1051, ItemId_Event_StopDumpZone = 1051,
ItemId_Event_ServerMessage = 1052, ItemId_Event_ServerMessage = 1052,
ItemId_Event_ChatJoinChannel = 1053, ItemId_Event_GameJoined = 1053,
ItemId_Event_ChatLeaveChannel = 1054, ItemId_Event_ChatJoinChannel = 1054,
ItemId_Event_ChatSay = 1055, ItemId_Event_ChatLeaveChannel = 1055,
ItemId_Other = 1056 ItemId_Event_ChatSay = 1056,
ItemId_Other = 1057
}; };

View File

@@ -561,6 +561,18 @@ void Event_ServerMessage::extractParameters()
GenericEvent::extractParameters(); GenericEvent::extractParameters();
message = parameters["message"]; 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) Event_ChatJoinChannel::Event_ChatJoinChannel(const QString &_channel, const QString &_playerName)
: ChatEvent("chat_join_channel", _channel), playerName(_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_eventdump_zone", Event_DumpZone::newItem);
itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem); itemNameHash.insert("game_eventstop_dump_zone", Event_StopDumpZone::newItem);
itemNameHash.insert("generic_eventserver_message", Event_ServerMessage::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_join_channel", Event_ChatJoinChannel::newItem);
itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem); itemNameHash.insert("chat_eventchat_leave_channel", Event_ChatLeaveChannel::newItem);
itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem); itemNameHash.insert("chat_eventchat_say", Event_ChatSay::newItem);

View File

@@ -50,6 +50,7 @@
3:dump_zone:i,zone_owner_id:s,zone:i,number_cards 3:dump_zone:i,zone_owner_id:s,zone:i,number_cards
3:stop_dump_zone:i,zone_owner_id:s,zone 3:stop_dump_zone:i,zone_owner_id:s,zone
4:server_message:s,message 4:server_message:s,message
4:game_joined:i,game_id:b,spectator
5:chat_join_channel:s,player_name 5:chat_join_channel:s,player_name
5:chat_leave_channel:s,player_name 5:chat_leave_channel:s,player_name
5:chat_say:s,player_name:s,message 5:chat_say:s,player_name:s,message

View File

@@ -697,6 +697,20 @@ public:
protected: protected:
void extractParameters(); 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 { class Event_ChatJoinChannel : public ChatEvent {
Q_OBJECT Q_OBJECT
private: private:

View File

@@ -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) 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) : 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() Server_Game::~Server_Game()
@@ -90,7 +90,7 @@ ResponseCode Server_Game::checkJoin(const QString &_password, bool spectator)
return RespOk; 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; int playerId;
if (!spectator) { if (!spectator) {
@@ -113,6 +113,7 @@ Server_Player *Server_Game::addPlayer(Server_ProtocolHandler *handler, bool spec
else else
players.insert(playerId, newPlayer); players.insert(playerId, newPlayer);
if (broadcastUpdate)
qobject_cast<Server *>(parent())->broadcastGameListUpdate(this); qobject_cast<Server *>(parent())->broadcastGameListUpdate(this);
return newPlayer; return newPlayer;

View File

@@ -57,7 +57,7 @@ public:
int getMaxPlayers() const { return maxPlayers; } int getMaxPlayers() const { return maxPlayers; }
bool getSpectatorsAllowed() const { return spectatorsAllowed; } bool getSpectatorsAllowed() const { return spectatorsAllowed; }
ResponseCode checkJoin(const QString &_password, bool spectator); 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 removePlayer(Server_Player *player);
void startGameIfReady(); void startGameIfReady();
int getActivePlayer() const { return activePlayer; } int getActivePlayer() const { return activePlayer; }

View File

@@ -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); Server_Game *game = server->createGame(cmd->getDescription(), cmd->getPassword(), cmd->getMaxPlayers(), cmd->getSpectatorsAllowed(), this);
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, game->getCreator())); games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(game, game->getCreator()));
enqueueProtocolItem(new Event_GameJoined(game->getGameId(), false));
return RespOk; return RespOk;
} }
@@ -212,6 +213,7 @@ ResponseCode Server_ProtocolHandler::cmdJoinGame(Command_JoinGame *cmd)
Server_Player *player = g->addPlayer(this, cmd->getSpectator()); Server_Player *player = g->addPlayer(this, cmd->getSpectator());
games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player)); games.insert(cmd->getGameId(), QPair<Server_Game *, Server_Player *>(g, player));
} }
enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), cmd->getSpectator()));
return result; return result;
} }