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 "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);

View File

@@ -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);

View File

@@ -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);

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_ServerMessage: emit serverMessageEventReceived(qobject_cast<Event_ServerMessage *>(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;
return;
}
/* GameEvent *gameEvent = qobject_cast<GameEvent *>(item);
GameEvent *gameEvent = qobject_cast<GameEvent *>(item);
if (gameEvent) {
emit gameEventReceived(gameEvent);
delete gameEvent;
return;
}
*/
ChatEvent *chatEvent = qobject_cast<ChatEvent *>(item);
if (chatEvent) {
qDebug() << "chatEventReceived()";
emit chatEventReceived(chatEvent);
delete chatEvent;
return;
}
}

View File

@@ -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();

View File

@@ -1,5 +1,6 @@
#include <QtGui>
#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;
}
}
*/

View File

@@ -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

View File

@@ -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);

View File

@@ -4,7 +4,6 @@
#include <QDialog>
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;

View File

@@ -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)));

View File

@@ -18,7 +18,6 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QApplication>
#include <QTextCodec>
#include <QtPlugin>
@@ -29,10 +28,15 @@
#include <QIcon>
#include <stdio.h>
#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;
@@ -53,24 +57,26 @@ int main(int argc, char *argv[])
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();
}

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 <QMenu>
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();

View File

@@ -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<int, ArrowItem *> &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);

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);
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);

View File

@@ -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<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)
@@ -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);
}

View File

@@ -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);

View File

@@ -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();
}

View File

@@ -6,7 +6,6 @@
#include <QLineEdit>
#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);

View File

@@ -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)

View File

@@ -23,26 +23,6 @@
#include <QMainWindow>
#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);

View File

@@ -1,11 +1,12 @@
#include "window_sets.h"
#include "setsmodel.h"
#include "main.h"
#include <QtGui>
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);

View File

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

View File

@@ -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()));

View File

@@ -3,7 +3,6 @@
#include <QGraphicsWidget>
class CardDatabase;
class ZoneViewWidget;
class ZoneViewZone;
class Player;
@@ -14,9 +13,8 @@ signals:
void sizeChanged();
private:
QList<ZoneViewWidget *> 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);

View File

@@ -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);

View File

@@ -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:

View File

@@ -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<ServerZoneCard> 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);
}

View File

@@ -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
};

View File

@@ -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);

View File

@@ -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

View File

@@ -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:

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)
: 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<Server *>(parent())->broadcastGameListUpdate(this);
if (broadcastUpdate)
qobject_cast<Server *>(parent())->broadcastGameListUpdate(this);
return newPlayer;
}

View File

@@ -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; }

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);
games.insert(game->getGameId(), QPair<Server_Game *, Server_Player *>(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<Server_Game *, Server_Player *>(g, player));
}
enqueueProtocolItem(new Event_GameJoined(cmd->getGameId(), cmd->getSpectator()));
return result;
}