some changes

This commit is contained in:
Max-Wilhelm Bruker 2009-06-20 13:26:36 +02:00
parent 9b1adf2dc1
commit c8a2ed9415
26 changed files with 243 additions and 613 deletions

View file

@ -14,5 +14,5 @@ QT += network
#QTPLUGIN += qjpeg #QTPLUGIN += qjpeg
# Input # Input
HEADERS += src/counter.h src/dlg_games.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/serverresponse.h src/pendingcommand.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/gravezone.h src/rfgzone.h src/sideboardzone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h HEADERS += src/counter.h src/gameselector.h src/dlg_creategame.h src/dlg_connect.h src/gamesmodel.h src/client.h src/window_main.h src/servergame.h src/servereventdata.h src/zonelist.h src/cardzone.h src/player.h src/cardlist.h src/carditem.h src/tablezone.h src/handzone.h src/playerlist.h src/game.h src/carddatabase.h src/gameview.h src/decklistmodel.h src/dlg_startgame.h src/cardinfowidget.h src/messagelogwidget.h src/serverzonecard.h src/zoneviewzone.h src/zoneviewwidget.h src/libraryzone.h src/pilezone.h src/carddragitem.h src/zoneviewlayout.h src/playerarea.h src/carddatabasemodel.h src/window_deckeditor.h src/decklist.h
SOURCES += src/counter.cpp src/dlg_games.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/gravezone.cpp src/rfgzone.cpp src/sideboardzone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp SOURCES += src/counter.cpp src/gameselector.cpp src/dlg_creategame.cpp src/dlg_connect.cpp src/client.cpp src/main.cpp src/window_main.cpp src/servereventdata.cpp src/gamesmodel.cpp src/player.cpp src/cardzone.cpp src/zonelist.cpp src/cardlist.cpp src/carditem.cpp src/tablezone.cpp src/handzone.cpp src/playerlist.cpp src/game.cpp src/carddatabase.cpp src/gameview.cpp src/decklistmodel.cpp src/dlg_startgame.cpp src/cardinfowidget.cpp src/messagelogwidget.cpp src/zoneviewzone.cpp src/zoneviewwidget.cpp src/libraryzone.cpp src/pilezone.cpp src/carddragitem.cpp src/zoneviewlayout.cpp src/playerarea.cpp src/carddatabasemodel.cpp src/window_deckeditor.cpp src/decklist.cpp

View file

@ -1,12 +1,31 @@
#include <QTimer> #include <QTimer>
#include "client.h" #include "client.h"
PendingCommand::PendingCommand(const QString &_cmd, int _msgid, QObject *parent)
: QObject(parent), cmd(_cmd), msgid(_msgid), time(0)
{
}
void PendingCommand::responseReceived(int _msgid, ServerResponse _resp)
{
if (_msgid == msgid) {
emit finished(_resp);
deleteLater();
}
}
void PendingCommand::checkTimeout()
{
if (++time > 5)
emit timeout();
}
Client::Client(QObject *parent) Client::Client(QObject *parent)
: QObject(parent), status(StatusDisconnected), MsgId(0) : QObject(parent), status(StatusDisconnected), MsgId(0)
{ {
timer = new QTimer(this); timer = new QTimer(this);
timer->setInterval(1000); timer->setInterval(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(checkTimeout())); connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
socket = new QTcpSocket(this); socket = new QTcpSocket(this);
socket->setTextModeEnabled(true); socket->setTextModeEnabled(true);
@ -20,22 +39,10 @@ Client::~Client()
disconnectFromServer(); disconnectFromServer();
} }
void Client::checkTimeout() void Client::timeout()
{ {
bool timeout = false; emit serverTimeout();
QListIterator<PendingCommand *> i(PendingCommands); disconnectFromServer();
while (i.hasNext()) {
PendingCommand *c = i.next();
if (c->timeout()) {
timeout = true;
break;
}
}
if (timeout) {
disconnectFromServer();
emit serverTimeout();
} else
ping();
} }
void Client::slotSocketError(QAbstractSocket::SocketError /*error*/) void Client::slotSocketError(QAbstractSocket::SocketError /*error*/)
@ -50,6 +57,33 @@ void Client::slotConnected()
setStatus(StatusAwaitingWelcome); setStatus(StatusAwaitingWelcome);
} }
void Client::removePendingCommand()
{
PendingCommands.removeAt(PendingCommands.indexOf(static_cast<PendingCommand *>(sender())));
}
void Client::loginResponse(ServerResponse response)
{
if (response == RespOk)
setStatus(StatusIdle);
else {
emit serverError(response);
disconnectFromServer();
}
}
void Client::enterGameResponse(ServerResponse response)
{
if (response == RespOk)
setStatus(StatusPlaying);
}
void Client::leaveGameResponse(ServerResponse response)
{
if (response == RespOk)
setStatus(StatusIdle);
}
void Client::readLine() void Client::readLine()
{ {
while (socket->canReadLine()) { while (socket->canReadLine()) {
@ -57,7 +91,7 @@ void Client::readLine()
if (line.isNull()) if (line.isNull())
break; break;
qDebug(QString("readLine: %1").arg(line).toLatin1()); qDebug(QString("<< %1").arg(line).toLatin1());
QStringList values = line.split("|"); QStringList values = line.split("|");
QString prefix = values.takeFirst(); QString prefix = values.takeFirst();
// prefix is one of {welcome, private, public, resp, list_games, list_players, list_counters, list_zones, dump_zone} // prefix is one of {welcome, private, public, resp, list_games, list_players, list_counters, list_zones, dump_zone}
@ -87,29 +121,14 @@ void Client::readLine()
// XXX // XXX
} }
ok = !values.takeFirst().compare("ok"); ServerResponse resp;
if (values[0] == "ok")
// XXX resp = RespOk;
ServerErrorMessage message = msgNone; else if (values[1] == "password")
resp = RespPassword;
// Update list of pending commands else
QListIterator<PendingCommand *> i(PendingCommands); resp = RespErr;
bool found = false; emit responseReceived(msgid, resp);
PendingCommand *c;
while (i.hasNext()) {
c = i.next();
if (c->getMsgId() == msgid) {
found = true;
break;
}
}
if (found) {
PendingCommands.removeAt(PendingCommands.indexOf(c));
delete c;
} else
qDebug(QString("msgid unknown: %1").arg(msgid).toLatin1());
emit responseReceived(new ServerResponse(msgid, ok, message));
} else if (prefix == "list_games") { } else if (prefix == "list_games") {
emit gameListEvent(new ServerGame(values[0].toInt(), values[5], values[1], values[2].toInt(), values[3].toInt(), values[4].toInt())); emit gameListEvent(new ServerGame(values[0].toInt(), values[5], values[1], values[2].toInt(), values[3].toInt(), values[4].toInt()));
} else if ((prefix == "list_players") || (prefix == "list_counters") || (prefix == "list_zones") || (prefix == "dump_zone") || (prefix == "welcome")) { } else if ((prefix == "list_players") || (prefix == "list_counters") || (prefix == "list_zones") || (prefix == "dump_zone") || (prefix == "welcome")) {
@ -124,29 +143,29 @@ void Client::readLine()
QStringList val = i.next(); QStringList val = i.next();
// XXX Parametergültigkeit überprüfen // XXX Parametergültigkeit überprüfen
if (!prefix.compare("list_players")) if (prefix == "list_players")
playerlist << new ServerPlayer(val[0].toInt(), val[1]); playerlist << new ServerPlayer(val[0].toInt(), val[1]);
else if (!prefix.compare("list_counters")) else if (prefix == "list_counters")
{ } { }
else if (!prefix.compare("list_zones")) else if (prefix == "list_zones")
zonelist << new ServerZone(val[0], val[1] == "1", val[2] == "1", val[3].toInt()); zonelist << new ServerZone(val[0], val[1] == "1", val[2] == "1", val[3].toInt());
else if (!prefix.compare("dump_zone")) else if (prefix == "dump_zone")
zonedump << new ServerZoneCard(val[0].toInt(), val[1], val[2].toInt(), val[3].toInt(), val[4].toInt(), val[5] == "1", val[6]); zonedump << new ServerZoneCard(val[0].toInt(), val[1], val[2].toInt(), val[3].toInt(), val[4].toInt(), val[5] == "1", val[6]);
else if (!prefix.compare("welcome")) else if (prefix == "welcome")
welcomemsg << val[0]; welcomemsg << val[0];
} }
if (!prefix.compare("list_players")) if (prefix == "list_players")
emit playerListReceived(playerlist); emit playerListReceived(playerlist);
else if (!prefix.compare("list_counters")) else if (prefix == "list_counters")
{ } { }
else if (!prefix.compare("list_zones")) else if (prefix == "list_zones")
emit zoneListReceived(cmdid, zonelist); emit zoneListReceived(cmdid, zonelist);
else if (!prefix.compare("dump_zone")) else if (prefix == "dump_zone")
emit zoneDumpReceived(cmdid, zonedump); emit zoneDumpReceived(cmdid, zonedump);
else if (!prefix.compare("welcome")) { else if (prefix == "welcome") {
emit welcomeMsgReceived(welcomemsg); emit welcomeMsgReceived(welcomemsg);
setStatus(StatusConnected); setStatus(StatusLoggingIn);
login(PlayerName, password); login(playerName, password);
} }
msgbuf.clear(); msgbuf.clear();
} else } else
@ -165,23 +184,27 @@ void Client::setStatus(const ProtocolStatus _status)
void Client::msg(const QString &s) void Client::msg(const QString &s)
{ {
qDebug(QString("msg gibt aus: %1").arg(s).toLatin1()); qDebug(QString(">> %1").arg(s).toLatin1());
QTextStream stream(socket); QTextStream stream(socket);
stream.setCodec("UTF-8"); stream.setCodec("UTF-8");
stream << s << endl; stream << s << endl;
stream.flush(); stream.flush();
} }
int Client::cmd(const QString &s) PendingCommand *Client::cmd(const QString &s)
{ {
msg(QString("%1|%2").arg(++MsgId).arg(s)); msg(QString("%1|%2").arg(++MsgId).arg(s));
PendingCommands << new PendingCommand(s, MsgId); PendingCommand *pc = new PendingCommand(s, MsgId, this);
return MsgId; PendingCommands << pc;
connect(this, SIGNAL(responseReceived(int, ServerResponse)), pc, SLOT(responseReceived(int, ServerResponse)));
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(removePendingCommand()));
connect(timer, SIGNAL(timeout()), pc, SLOT(checkTimeout()));
return pc;
} }
void Client::connectToServer(const QString &hostname, unsigned int port, const QString &playername, const QString &_password) void Client::connectToServer(const QString &hostname, unsigned int port, const QString &_playerName, const QString &_password)
{ {
PlayerName = playername; playerName = _playerName;
password = _password; password = _password;
socket->connectToHost(hostname, port); socket->connectToHost(hostname, port);
setStatus(StatusConnecting); setStatus(StatusConnecting);
@ -199,74 +222,82 @@ void Client::disconnectFromServer()
socket->close(); socket->close();
} }
int Client::ping() void Client::ping()
{ {
return cmd("ping"); cmd("ping");
} }
int Client::listGames() PendingCommand *Client::listGames()
{ {
return cmd("list_games"); return cmd("list_games");
} }
int Client::listPlayers() PendingCommand *Client::listPlayers()
{ {
return cmd("list_players"); return cmd("list_players");
} }
int Client::createGame(const QString &description, const QString &password, unsigned int maxPlayers) PendingCommand *Client::createGame(const QString &description, const QString &password, unsigned int maxPlayers)
{ {
return cmd(QString("create_game|%1|%2|%3").arg(description).arg(password).arg(maxPlayers)); PendingCommand *pc = cmd(QString("create_game|%1|%2|%3").arg(description).arg(password).arg(maxPlayers));
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(enterGameResponse(ServerResponse)));
return pc;
} }
int Client::joinGame(int gameId, const QString &password) PendingCommand *Client::joinGame(int gameId, const QString &password)
{ {
return cmd(QString("join_game|%1|%2").arg(gameId).arg(password)); PendingCommand *pc = cmd(QString("join_game|%1|%2").arg(gameId).arg(password));
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(enterGameResponse(ServerResponse)));
return pc;
} }
int Client::leaveGame() PendingCommand *Client::leaveGame()
{ {
return cmd("leave_game"); PendingCommand *pc = cmd("leave_game");
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(leaveGameResponse(ServerResponse)));
return pc;
} }
int Client::login(const QString &name, const QString &pass) PendingCommand *Client::login(const QString &name, const QString &pass)
{ {
return cmd(QString("login|%1|%2").arg(name).arg(pass)); PendingCommand *pc = cmd(QString("login|%1|%2").arg(name).arg(pass));
connect(pc, SIGNAL(finished(ServerResponse)), this, SLOT(loginResponse(ServerResponse)));
return pc;
} }
int Client::say(const QString &s) PendingCommand *Client::say(const QString &s)
{ {
return cmd(QString("say|%1").arg(s)); return cmd(QString("say|%1").arg(s));
} }
int Client::shuffle() PendingCommand *Client::shuffle()
{ {
return cmd("shuffle"); return cmd("shuffle");
} }
int Client::rollDice(unsigned int sides) PendingCommand *Client::rollDice(unsigned int sides)
{ {
return cmd(QString("roll_dice|%1").arg(sides)); return cmd(QString("roll_dice|%1").arg(sides));
} }
int Client::drawCards(unsigned int number) PendingCommand *Client::drawCards(unsigned int number)
{ {
return cmd(QString("draw_cards|%1").arg(number)); return cmd(QString("draw_cards|%1").arg(number));
} }
int Client::moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y, bool faceDown) PendingCommand *Client::moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y, bool faceDown)
{ {
// if startzone is public: cardid is the card's id // if startzone is public: cardid is the card's id
// else: cardid is the position of the card in the zone (e.g. deck) // else: cardid is the position of the card in the zone (e.g. deck)
return cmd(QString("move_card|%1|%2|%3|%4|%5|%6").arg(cardid).arg(startzone).arg(targetzone).arg(x).arg(y).arg(faceDown ? 1 : 0)); return cmd(QString("move_card|%1|%2|%3|%4|%5|%6").arg(cardid).arg(startzone).arg(targetzone).arg(x).arg(y).arg(faceDown ? 1 : 0));
} }
int Client::createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y) PendingCommand *Client::createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y)
{ {
return cmd(QString("create_token|%1|%2|%3|%4|%5").arg(zone).arg(name).arg(powtough).arg(x).arg(y)); return cmd(QString("create_token|%1|%2|%3|%4|%5").arg(zone).arg(name).arg(powtough).arg(x).arg(y));
} }
int Client::setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue) PendingCommand *Client::setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue)
{ {
return cmd(QString("set_card_attr|%1|%2|%3|%4").arg(zone).arg(cardid).arg(aname).arg(avalue)); return cmd(QString("set_card_attr|%1|%2|%3|%4").arg(zone).arg(cardid).arg(aname).arg(avalue));
} }
@ -280,42 +311,42 @@ void Client::submitDeck(const QStringList &deck)
msg("."); msg(".");
} }
int Client::readyStart() PendingCommand *Client::readyStart()
{ {
return cmd("ready_start"); return cmd("ready_start");
} }
int Client::incCounter(const QString &counter, int delta) PendingCommand *Client::incCounter(const QString &counter, int delta)
{ {
return cmd(QString("inc_counter|%1|%2").arg(counter).arg(delta)); return cmd(QString("inc_counter|%1|%2").arg(counter).arg(delta));
} }
int Client::addCounter(const QString &counter, QColor color, int value) PendingCommand *Client::addCounter(const QString &counter, QColor color, int value)
{ {
return cmd(QString("add_counter|%1|%2|%3").arg(counter).arg(color.red() * 65536 + color.green() * 256 + color.blue()).arg(value)); return cmd(QString("add_counter|%1|%2|%3").arg(counter).arg(color.red() * 65536 + color.green() * 256 + color.blue()).arg(value));
} }
int Client::setCounter(const QString &counter, int value) PendingCommand *Client::setCounter(const QString &counter, int value)
{ {
return cmd(QString("set_counter|%1|%2").arg(counter).arg(value)); return cmd(QString("set_counter|%1|%2").arg(counter).arg(value));
} }
int Client::delCounter(const QString &counter) PendingCommand *Client::delCounter(const QString &counter)
{ {
return cmd(QString("del_counter|%1").arg(counter)); return cmd(QString("del_counter|%1").arg(counter));
} }
int Client::setActivePlayer(int player) PendingCommand *Client::setActivePlayer(int player)
{ {
return cmd(QString("set_active_player|%1").arg(player)); return cmd(QString("set_active_player|%1").arg(player));
} }
int Client::setActivePhase(int phase) PendingCommand *Client::setActivePhase(int phase)
{ {
return cmd(QString("set_active_phase|%1").arg(phase)); return cmd(QString("set_active_phase|%1").arg(phase));
} }
int Client::dumpZone(int player, const QString &zone, int numberCards) PendingCommand *Client::dumpZone(int player, const QString &zone, int numberCards)
{ {
return cmd(QString("dump_zone|%1|%2|%3").arg(player).arg(zone).arg(numberCards)); return cmd(QString("dump_zone|%1|%2|%3").arg(player).arg(zone).arg(numberCards));
} }

View file

@ -2,12 +2,10 @@
#define CLIENT_H #define CLIENT_H
#include "servereventdata.h" #include "servereventdata.h"
#include "serverresponse.h"
#include "servergame.h" #include "servergame.h"
#include "serverplayer.h" #include "serverplayer.h"
#include "serverzone.h" #include "serverzone.h"
#include "serverzonecard.h" #include "serverzonecard.h"
#include "pendingcommand.h"
#include <QTcpSocket> #include <QTcpSocket>
#include <QColor> #include <QColor>
@ -19,7 +17,33 @@ class QTimer;
enum ProtocolStatus { StatusDisconnected, enum ProtocolStatus { StatusDisconnected,
StatusConnecting, StatusConnecting,
StatusAwaitingWelcome, StatusAwaitingWelcome,
StatusConnected }; StatusLoggingIn,
StatusIdle,
StatusPlaying };
enum ServerResponse {
RespOk,
RespPassword,
RespErr
};
class PendingCommand : public QObject {
Q_OBJECT
private:
QString cmd;
int msgid;
int time;
signals:
void finished(ServerResponse resp);
public slots:
void responseReceived(int _msgid, ServerResponse _resp);
void checkTimeout();
public:
int getMsgId() const { return msgid; }
QString getCmd() const { return cmd; }
bool timeout() { return ++time > 5; }
PendingCommand(const QString &_cmd, int _msgid, QObject *parent = 0);
};
class Client : public QObject { class Client : public QObject {
Q_OBJECT Q_OBJECT
@ -30,60 +54,62 @@ signals:
void playerListReceived(QList<ServerPlayer *> players); void playerListReceived(QList<ServerPlayer *> players);
void zoneListReceived(int commandId, QList<ServerZone *> zones); void zoneListReceived(int commandId, QList<ServerZone *> zones);
void zoneDumpReceived(int commandId, QList<ServerZoneCard *> cards); void zoneDumpReceived(int commandId, QList<ServerZoneCard *> cards);
void responseReceived(ServerResponse *response); void responseReceived(int msgid, ServerResponse resp);
void playerIdReceived(int id, QString name); void playerIdReceived(int id, QString name);
void gameEvent(const ServerEventData &msg); void gameEvent(const ServerEventData &msg);
void serverTimeout(); void serverTimeout();
void logSocketError(const QString &errorString); void logSocketError(const QString &errorString);
void serverError(ServerResponse resp);
private slots: private slots:
void slotConnected(); void slotConnected();
void readLine(); void readLine();
void checkTimeout(); void timeout();
void slotSocketError(QAbstractSocket::SocketError error); void slotSocketError(QAbstractSocket::SocketError error);
void ping();
void removePendingCommand();
void loginResponse(ServerResponse response);
void enterGameResponse(ServerResponse response);
void leaveGameResponse(ServerResponse response);
private: private:
QTimer *timer; QTimer *timer;
QList<PendingCommand *> PendingCommands; QList<PendingCommand *> PendingCommands;
QTcpSocket *socket; QTcpSocket *socket;
ProtocolStatus status; ProtocolStatus status;
QList<QStringList> msgbuf; QList<QStringList> msgbuf;
QString PlayerName; QString playerName, password;
QString password;
unsigned int MsgId; unsigned int MsgId;
void msg(const QString &s); void msg(const QString &s);
int cmd(const QString &s); PendingCommand *cmd(const QString &s);
void setStatus(const ProtocolStatus _status); void setStatus(const ProtocolStatus _status);
public: public:
Client(QObject *parent = 0); Client(QObject *parent = 0);
~Client(); ~Client();
ProtocolStatus getStatus() const { return status; } ProtocolStatus getStatus() const { return status; }
QString peerName() const { return socket->peerName(); } QString peerName() const { return socket->peerName(); }
void connectToServer(const QString &hostname, unsigned int port, const QString &playername, const QString &password); void connectToServer(const QString &hostname, unsigned int port, const QString &_playerName, const QString &_password);
void disconnectFromServer(); void disconnectFromServer();
int ping(); PendingCommand *listGames();
int listGames(); PendingCommand *listPlayers();
int listPlayers(); PendingCommand *createGame(const QString &description, const QString &password, unsigned int maxPlayers);
int createGame(const QString &description, const QString &password, unsigned int maxPlayers); PendingCommand *joinGame(int gameId, const QString &password);
int joinGame(int gameId, const QString &password); PendingCommand *leaveGame();
int leaveGame(); PendingCommand *login(const QString &name, const QString &pass);
int login(const QString &name, const QString &pass); PendingCommand *say(const QString &s);
int say(const QString &s); PendingCommand *shuffle();
int shuffle(); PendingCommand *rollDice(unsigned int sides);
int rollDice(unsigned int sides); PendingCommand *drawCards(unsigned int number);
int drawCards(unsigned int number); PendingCommand *moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false);
int moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false); PendingCommand *createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y);
int createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y); PendingCommand *setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue);
int setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue); PendingCommand *readyStart();
int readyStart(); PendingCommand *incCounter(const QString &counter, int delta);
int incCounter(const QString &counter, int delta); PendingCommand *addCounter(const QString &counter, QColor color, int value);
int addCounter(const QString &counter, QColor color, int value); PendingCommand *setCounter(const QString &counter, int value);
int setCounter(const QString &counter, int value); PendingCommand *delCounter(const QString &counter);
int delCounter(const QString &counter); PendingCommand *setActivePlayer(int player);
int setActivePlayer(int player); PendingCommand *setActivePhase(int phase);
int setActivePhase(int phase); PendingCommand *dumpZone(int player, const QString &zone, int numberCards);
int dumpZone(int player, const QString &zone, int numberCards);
public slots: public slots:
void submitDeck(const QStringList &deck); void submitDeck(const QStringList &deck);
}; };

View file

@ -15,14 +15,12 @@ QRectF Counter::boundingRect() const
void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{ {
painter->save();
painter->setBrush(QBrush(color)); painter->setBrush(QBrush(color));
painter->drawEllipse(boundingRect()); painter->drawEllipse(boundingRect());
if (value) { if (value) {
painter->setFont(QFont("Times", 16, QFont::Bold)); painter->setFont(QFont("Times", 16, QFont::Bold));
painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(value)); painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(value));
} }
painter->restore();
} }
void Counter::setValue(int _value) void Counter::setValue(int _value)

View file

@ -2,7 +2,7 @@
#include "dlg_creategame.h" #include "dlg_creategame.h"
DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent) DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
: QDialog(parent), client(_client), msgid(0) : QDialog(parent), client(_client)
{ {
descriptionLabel = new QLabel(tr("&Description:")); descriptionLabel = new QLabel(tr("&Description:"));
descriptionEdit = new QLineEdit; descriptionEdit = new QLineEdit;
@ -27,50 +27,48 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
okButton = new QPushButton(tr("&OK")); okButton = new QPushButton(tr("&OK"));
okButton->setDefault(true); okButton->setDefault(true);
cancelButton = new QPushButton(tr("&Cancel")); cancelButton = new QPushButton(tr("&Cancel"));
QHBoxLayout *buttonLayout = new QHBoxLayout; QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(); buttonLayout->addStretch();
buttonLayout->addWidget(okButton); buttonLayout->addWidget(okButton);
buttonLayout->addWidget(cancelButton); buttonLayout->addWidget(cancelButton);
QVBoxLayout *mainLayout = new QVBoxLayout; QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(grid); mainLayout->addLayout(grid);
mainLayout->addLayout(buttonLayout); mainLayout->addLayout(buttonLayout);
setLayout(mainLayout); setLayout(mainLayout);
setWindowTitle(tr("Create game")); setWindowTitle(tr("Create game"));
setFixedHeight(sizeHint().height()); setFixedHeight(sizeHint().height());
connect(okButton, SIGNAL(clicked()), this, SLOT(actOK())); connect(okButton, SIGNAL(clicked()), this, SLOT(actOK()));
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject())); connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
connect(client, SIGNAL(responseReceived(ServerResponse *)), this, SLOT(checkResponse(ServerResponse *)));
} }
void DlgCreateGame::actOK() void DlgCreateGame::actOK()
{ {
bool ok; bool ok;
int maxPlayers = maxPlayersEdit->text().toInt(&ok); int maxPlayers = maxPlayersEdit->text().toInt(&ok);
if (msgid)
return;
if (!ok) { if (!ok) {
QMessageBox::critical(this, tr("Error"), tr("Invalid number of players.")); QMessageBox::critical(this, tr("Error"), tr("Invalid number of players."));
return; return;
} }
msgid = client->createGame(descriptionEdit->text(), PendingCommand *createCommand = client->createGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers);
passwordEdit->text(), connect(createCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse)));
maxPlayers); okButton->setEnabled(false);
cancelButton->setEnabled(false);
} }
void DlgCreateGame::checkResponse(ServerResponse *response) void DlgCreateGame::checkResponse(ServerResponse response)
{ {
if (response->getMsgId() != msgid) okButton->setEnabled(true);
return; cancelButton->setEnabled(true);
if (response->getOk())
if (response == RespOk)
accept(); accept();
else { else {
QMessageBox::critical(this, tr("Error"), tr("XXX")); QMessageBox::critical(this, tr("Error"), tr("XXX"));
msgid = 0;
return; return;
} }
} }

View file

@ -14,15 +14,14 @@ 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(ServerResponse response);
private: private:
Client *client; Client *client;
int msgid;
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel; QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
QLineEdit *descriptionEdit, *passwordEdit, *maxPlayersEdit; QLineEdit *descriptionEdit, *passwordEdit, *maxPlayersEdit;
QPushButton *okButton, *cancelButton; QPushButton *okButton, *cancelButton;
}; };
#endif #endif

View file

@ -1,75 +0,0 @@
#include <QtGui>
#include "dlg_games.h"
#include "dlg_creategame.h"
DlgGames::DlgGames(Client *_client, QWidget *parent)
: QDialog(parent), client(_client), msgid(0)
{
gameListView = new QTreeView;
gameListModel = new GamesModel(this);
gameListView->setModel(gameListModel);
createButton = new QPushButton(tr("&Create"));
joinButton = new QPushButton(tr("&Join"));
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch();
buttonLayout->addWidget(createButton);
buttonLayout->addWidget(joinButton);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(gameListView);
mainLayout->addLayout(buttonLayout);
setLayout(mainLayout);
setWindowTitle(tr("Games"));
setMinimumWidth(gameListView->columnWidth(0) * gameListModel->columnCount());
connect(createButton, SIGNAL(clicked()), this, SLOT(actCreate()));
connect(joinButton, SIGNAL(clicked()), this, SLOT(actJoin()));
connect(client, SIGNAL(gameListEvent(ServerGame *)), gameListModel, SLOT(updateGameList(ServerGame *)));
client->listGames();
}
void DlgGames::actCreate()
{
DlgCreateGame dlg(client, this);
if (dlg.exec())
accept();
}
void DlgGames::actRefresh()
{
client->listGames();
}
void DlgGames::checkResponse(ServerResponse *response)
{
if (response->getMsgId() != msgid)
return;
if (response->getOk())
accept();
else {
QMessageBox::critical(this, tr("Error"), tr("XXX"));
msgid = 0;
return;
}
}
void DlgGames::actJoin()
{
if (msgid)
return;
ServerGame *game = gameListModel->getGame(gameListView->currentIndex().row());
QString password;
if (game->getHasPassword()) {
bool ok;
password = QInputDialog::getText(this, tr("Join game"), tr("Password:"), QLineEdit::Password, QString(), &ok);
if (!ok)
return;
}
connect(client, SIGNAL(responseReceived(ServerResponse *)), this, SLOT(checkResponse(ServerResponse *)));
msgid = client->joinGame(game->getGameId(), password);
}

View file

@ -1,31 +0,0 @@
#ifndef DLG_GAMES_H
#define DLG_GAMES_H
#include <QDialog>
#include "gamesmodel.h"
#include "servergame.h"
#include "client.h"
class QPushButton;
class QTreeView;
class DlgGames : public QDialog {
Q_OBJECT
public:
DlgGames(Client *_client, QWidget *parent = 0);
private slots:
void actCreate();
void actRefresh();
void actJoin();
void checkResponse(ServerResponse *response);
private:
Client *client;
int msgid;
QTreeView *gameListView;
GamesModel *gameListModel;
QPushButton *refreshButton, *createButton, *joinButton;
};
#endif

View file

@ -5,7 +5,6 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent)
{ {
setBackgroundBrush(QBrush(QColor(0, 0, 0))); setBackgroundBrush(QBrush(QColor(0, 0, 0)));
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/); setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
// setOptimizationFlags(/*DontClipPainter | */DontSavePainterState);
setDragMode(RubberBandDrag); setDragMode(RubberBandDrag);
// setViewportUpdateMode(FullViewportUpdate); // setViewportUpdateMode(FullViewportUpdate);
} }

View file

@ -1,86 +0,0 @@
#include <QtGui>
#include "gravezone.h"
#include "player.h"
#include "client.h"
#include "carddragitem.h"
#include "zoneviewzone.h"
GraveZone::GraveZone(Player *_p, QGraphicsItem *parent)
: CardZone(_p, "grave", false, false, parent)
{
cards = new CardList(true);
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
setCursor(Qt::OpenHandCursor);
}
QRectF GraveZone::boundingRect() const
{
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
}
void GraveZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
qDebug("grave: paint");
if (!cards->isEmpty())
cards->at(0)->paint(painter, option, widget);
painter->save();
paintCardNumberEllipse(painter);
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
painter->restore();
}
void GraveZone::addCardImpl(CardItem *card, int x, int /*y*/)
{
cards->insert(x, card);
card->setPos(0, 0);
card->setVisible(false);
card->resetState();
card->setParentItem(this);
}
void GraveZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
{
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
}
void GraveZone::reorganizeCards()
{
qDebug(QString("grave: reorganize, x=%1, y=%2, w=%3, h=%4").arg(boundingRect().x()).arg(boundingRect().y()).arg(boundingRect().width()).arg(boundingRect().height()).toLatin1());
update(boundingRect());
}
void GraveZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
CardZone::mousePressEvent(event);
if (event->isAccepted())
return;
if (event->button() == Qt::LeftButton) {
setCursor(Qt::ClosedHandCursor);
event->accept();
} else
event->ignore();
}
void GraveZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance())
return;
if (cards->empty())
return;
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
CardItem *card = cards->at(0);
CardDragItem *drag = card->createDragItem(card->getId(), event->pos(), event->scenePos(), faceDown);
drag->grabMouse();
setCursor(Qt::OpenHandCursor);
}
void GraveZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
{
setCursor(Qt::OpenHandCursor);
}

View file

@ -1,21 +0,0 @@
#ifndef GRAVEZONE_H
#define GRAVEZONE_H
#include "cardzone.h"
class GraveZone : public CardZone {
private:
public:
GraveZone(Player *_p, QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void addCardImpl(CardItem *card, int x, int y);
};
#endif

View file

@ -21,15 +21,15 @@ QRectF LibraryZone::boundingRect() const
void LibraryZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/) void LibraryZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
{ {
painter->save();
QSizeF translatedSize = option->matrix.mapRect(boundingRect()).size(); QSizeF translatedSize = option->matrix.mapRect(boundingRect()).size();
QPixmap *translatedPixmap = player->getDb()->getCard()->getPixmap(translatedSize.toSize()); QPixmap *translatedPixmap = player->getDb()->getCard()->getPixmap(translatedSize.toSize());
painter->drawPixmap(boundingRect(), *translatedPixmap, translatedPixmap->rect());
painter->save();
painter->resetTransform();
painter->drawPixmap(translatedPixmap->rect(), *translatedPixmap, translatedPixmap->rect());
painter->restore();
paintCardNumberEllipse(painter); paintCardNumberEllipse(painter);
painter->restore();
} }
void LibraryZone::addCardImpl(CardItem *card, int x, int /*y*/) void LibraryZone::addCardImpl(CardItem *card, int x, int /*y*/)

View file

@ -26,6 +26,14 @@ void MessageLogWidget::logSocketError(const QString &errorString)
append(errorString); append(errorString);
} }
void MessageLogWidget::logServerError(ServerResponse response)
{
switch (response) {
case RespPassword: append(tr("Invalid password.")); break;
default: ;
}
}
void MessageLogWidget::logPlayerListReceived(QStringList players) void MessageLogWidget::logPlayerListReceived(QStringList players)
{ {
append("---"); append("---");

View file

@ -3,6 +3,7 @@
#include <QTextEdit> #include <QTextEdit>
#include <QAbstractSocket> #include <QAbstractSocket>
#include "client.h"
class Game; class Game;
@ -13,6 +14,7 @@ public slots:
void logConnected(const QStringList WelcomeMsg); void logConnected(const QStringList WelcomeMsg);
void logDisconnected(); void logDisconnected();
void logSocketError(const QString &errorString); void logSocketError(const QString &errorString);
void logServerError(ServerResponse response);
private slots: private slots:
void logPlayerListReceived(QStringList players); void logPlayerListReceived(QStringList players);
void logJoin(QString playerName); void logJoin(QString playerName);

View file

@ -1,18 +0,0 @@
#ifndef PENDINGCOMMAND_H
#define PENDINGCOMMAND_H
#include <QString>
class PendingCommand {
private:
QString cmd;
int msgid;
int time;
public:
int getMsgId() const { return msgid; }
QString getCmd() const { return cmd; }
bool timeout() { return ++time > 5; }
PendingCommand(const QString &_cmd, int _msgid) : cmd(_cmd), msgid(_msgid), time(0) { }
};
#endif

View file

@ -174,12 +174,12 @@ void Player::gameEvent(const ServerEventData &event)
zones.at(i)->reorganizeCards(); zones.at(i)->reorganizeCards();
if (local) { if (local) {
client->addCounter("life", QColor("white"), 20); client->addCounter("life", Qt::white, 20);
client->addCounter("w", QColor(200, 200, 200), 0); client->addCounter("w", QColor(255, 255, 150), 0);
client->addCounter("u", QColor(0, 0, 200), 0); client->addCounter("u", QColor(150, 150, 255), 0);
client->addCounter("b", QColor(100, 100, 100), 0); client->addCounter("b", QColor(150, 150, 150), 0);
client->addCounter("r", QColor(200, 0, 0), 0); client->addCounter("r", QColor(250, 150, 150), 0);
client->addCounter("g", QColor(0, 200, 0), 0); client->addCounter("g", QColor(150, 255, 150), 0);
client->addCounter("x", QColor(255, 255, 255), 0); client->addCounter("x", QColor(255, 255, 255), 0);
client->addCounter("storm", QColor(255, 255, 255), 0); client->addCounter("storm", QColor(255, 255, 255), 0);
} }

View file

@ -3,9 +3,7 @@
#include "tablezone.h" #include "tablezone.h"
#include "handzone.h" #include "handzone.h"
#include "libraryzone.h" #include "libraryzone.h"
#include "gravezone.h" #include "pilezone.h"
#include "rfgzone.h"
#include "sideboardzone.h"
#include "counter.h" #include "counter.h"
#include <QPainter> #include <QPainter>
@ -19,13 +17,13 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
qreal h = deck->boundingRect().height() + 20; qreal h = deck->boundingRect().height() + 20;
GraveZone *grave = new GraveZone(_player, this); PileZone *grave = new PileZone(_player, "grave", this);
grave->setPos(base + QPointF(0, h)); grave->setPos(base + QPointF(0, h));
RfgZone *rfg = new RfgZone(_player, this); PileZone *rfg = new PileZone(_player, "rfg", this);
rfg->setPos(base + QPointF(0, 2 * h)); rfg->setPos(base + QPointF(0, 2 * h));
SideboardZone *sb = new SideboardZone(_player, this); PileZone *sb = new PileZone(_player, "sb", this);
sb->setVisible(false); sb->setVisible(false);
base = QPointF(deck->boundingRect().width() + 60, 0); base = QPointF(deck->boundingRect().width() + 60, 0);
@ -38,7 +36,6 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
table->setPos(base); table->setPos(base);
bRect = QRectF(0, 0, base.x() + table->boundingRect().width(), base.y() + table->boundingRect().height()); bRect = QRectF(0, 0, base.x() + table->boundingRect().width(), base.y() + table->boundingRect().height());
qDebug(QString("%1").arg(bRect.width()).toLatin1());
} }
PlayerArea::~PlayerArea() PlayerArea::~PlayerArea()
@ -53,15 +50,11 @@ QRectF PlayerArea::boundingRect() const
void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{ {
painter->save();
painter->fillRect(boundingRect(), QColor(200, 200, 200)); painter->fillRect(boundingRect(), QColor(200, 200, 200));
painter->setFont(QFont("Times", 16, QFont::Bold)); painter->setFont(QFont("Times", 16, QFont::Bold));
painter->setPen(QPen(Qt::black)); painter->setPen(QPen(Qt::black));
painter->drawText(QRectF(0, 0, CARD_WIDTH + 60, 40), Qt::AlignCenter, player->getName()); painter->drawText(QRectF(0, 0, CARD_WIDTH + 60, 40), Qt::AlignCenter, player->getName());
painter->restore();
} }
Counter *PlayerArea::getCounter(const QString &name, bool remove) Counter *PlayerArea::getCounter(const QString &name, bool remove)

View file

@ -1,84 +0,0 @@
#include <QtGui>
#include "rfgzone.h"
#include "player.h"
#include "client.h"
#include "carddragitem.h"
#include "zoneviewzone.h"
RfgZone::RfgZone(Player *_p, QGraphicsItem *parent)
: CardZone(_p, "rfg", false, false, parent)
{
cards = new CardList(true);
setCacheMode(DeviceCoordinateCache); // Do not move this line to the parent constructor!
setCursor(Qt::OpenHandCursor);
}
QRectF RfgZone::boundingRect() const
{
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
}
void RfgZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
if (!cards->isEmpty())
cards->at(0)->paint(painter, option, widget);
painter->save();
paintCardNumberEllipse(painter);
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
painter->restore();
}
void RfgZone::addCardImpl(CardItem *card, int x, int /*y*/)
{
cards->insert(x, card);
card->setPos(0, 0);
card->setVisible(false);
card->resetState();
card->setParentItem(this);
}
void RfgZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
{
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
}
void RfgZone::reorganizeCards()
{
update(boundingRect());
}
void RfgZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
CardZone::mousePressEvent(event);
if (event->isAccepted())
return;
if (event->button() == Qt::LeftButton) {
setCursor(Qt::ClosedHandCursor);
event->accept();
} else
event->ignore();
}
void RfgZone::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < QApplication::startDragDistance())
return;
if (cards->empty())
return;
bool faceDown = event->modifiers().testFlag(Qt::ShiftModifier);
CardItem *card = cards->at(0);
CardDragItem *drag = card->createDragItem(card->getId(), event->pos(), event->scenePos(), faceDown);
drag->grabMouse();
setCursor(Qt::OpenHandCursor);
}
void RfgZone::mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
{
setCursor(Qt::OpenHandCursor);
}

View file

@ -1,21 +0,0 @@
#ifndef RFGZONE_H
#define RFGZONE_H
#include "cardzone.h"
class RfgZone : public CardZone {
private:
public:
RfgZone(Player *_p, QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void addCardImpl(CardItem *card, int x, int y);
};
#endif

View file

@ -1,22 +0,0 @@
#ifndef SERVERRESPONSE_H
#define SERVERRESPONSE_H
enum ServerErrorMessage {
msgNone,
msgSyntaxError
};
class ServerResponse {
private:
int msgId;
bool ok;
ServerErrorMessage message;
public:
ServerResponse(int _msgId, bool _ok, ServerErrorMessage _message)
: msgId(_msgId), ok(_ok), message(_message) { }
int getMsgId() const { return msgId; }
bool getOk() const { return ok; }
ServerErrorMessage getMessage() const { return message; }
};
#endif

View file

@ -1,45 +0,0 @@
#include <QtGui>
#include "sideboardzone.h"
#include "player.h"
#include "client.h"
#include "zoneviewzone.h"
SideboardZone::SideboardZone(Player *_p, QGraphicsItem *parent)
: CardZone(_p, "sb", false, false, parent)
{
cards = new CardList(false);
}
QRectF SideboardZone::boundingRect() const
{
return QRectF(0, 0, 50, 50);
}
void SideboardZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
painter->save();
painter->fillRect(boundingRect(), QColor("blue"));
painter->setFont(QFont("Times", 20, QFont::Bold));
painter->setPen(QPen(QColor("black")));
painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(cards->size()));
painter->restore();
}
void SideboardZone::addCardImpl(CardItem *card, int x, int /*y*/)
{
cards->insert(x, card);
card->setPos(0, 0);
card->setVisible(false);
card->resetState();
card->setParentItem(this);
}
void SideboardZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
{
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
}
void SideboardZone::reorganizeCards()
{
update(boundingRect());
}

View file

@ -1,18 +0,0 @@
#ifndef SIDEBOARDZONE_H
#define SIDEBOARDZONE_H
#include "cardzone.h"
class SideboardZone : public CardZone {
private:
public:
SideboardZone(Player *_p, QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
protected:
void addCardImpl(CardItem *card, int x, int y);
};
#endif

View file

@ -22,7 +22,7 @@
#include "window_main.h" #include "window_main.h"
#include "dlg_connect.h" #include "dlg_connect.h"
#include "dlg_games.h" #include "gameselector.h"
#include "window_deckeditor.h" #include "window_deckeditor.h"
#include "cardinfowidget.h" #include "cardinfowidget.h"
#include "messagelogwidget.h" #include "messagelogwidget.h"
@ -64,14 +64,19 @@ void MainWindow::statusChanged(ProtocolStatus _status)
game = 0; game = 0;
} }
aDisconnect->setEnabled(false); aDisconnect->setEnabled(false);
aGames->setEnabled(false);
aRestartGame->setEnabled(false); aRestartGame->setEnabled(false);
aLeaveGame->setEnabled(false); aLeaveGame->setEnabled(false);
emit logDisconnected(); emit logDisconnected();
break; break;
case StatusConnected: case StatusLoggingIn:
aDisconnect->setEnabled(true); aDisconnect->setEnabled(true);
aGames->setEnabled(true); break;
case StatusIdle: {
GameSelector *gameSelector = new GameSelector(client);
viewLayout->insertWidget(0, gameSelector);
}
case StatusPlaying:
break;
default: default:
break; break;
} }
@ -91,12 +96,6 @@ void MainWindow::actDisconnect()
client->disconnectFromServer(); client->disconnectFromServer();
} }
void MainWindow::actGames()
{
DlgGames dlg(client, this);
dlg.exec();
}
void MainWindow::actRestartGame() void MainWindow::actRestartGame()
{ {
zoneLayout->clear(); zoneLayout->clear();
@ -111,7 +110,6 @@ void MainWindow::actLeaveGame()
game = 0; game = 0;
aRestartGame->setEnabled(false); aRestartGame->setEnabled(false);
aLeaveGame->setEnabled(false); aLeaveGame->setEnabled(false);
aGames->setEnabled(true);
} }
void MainWindow::actDeckEditor() void MainWindow::actDeckEditor()
@ -164,7 +162,6 @@ void MainWindow::playerIdReceived(int id, QString name)
playerAdded(game->getLocalPlayer()); playerAdded(game->getLocalPlayer());
messageLog->connectToGame(game); messageLog->connectToGame(game);
aGames->setEnabled(false);
aRestartGame->setEnabled(true); aRestartGame->setEnabled(true);
aLeaveGame->setEnabled(true); aLeaveGame->setEnabled(true);
@ -183,9 +180,6 @@ void MainWindow::createActions()
aDisconnect = new QAction(tr("&Disconnect"), this); aDisconnect = new QAction(tr("&Disconnect"), this);
aDisconnect->setEnabled(false); aDisconnect->setEnabled(false);
connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect())); connect(aDisconnect, SIGNAL(triggered()), this, SLOT(actDisconnect()));
aGames = new QAction(tr("&Games..."), this);
aGames->setEnabled(false);
connect(aGames, SIGNAL(triggered()), this, SLOT(actGames()));
aRestartGame = new QAction(tr("&Restart game..."), this); aRestartGame = new QAction(tr("&Restart game..."), this);
aRestartGame->setShortcut(tr("F2")); aRestartGame->setShortcut(tr("F2"));
aRestartGame->setEnabled(false); aRestartGame->setEnabled(false);
@ -214,7 +208,6 @@ void MainWindow::createMenus()
gameMenu->addAction(aConnect); gameMenu->addAction(aConnect);
gameMenu->addAction(aDisconnect); gameMenu->addAction(aDisconnect);
gameMenu->addSeparator(); gameMenu->addSeparator();
gameMenu->addAction(aGames);
gameMenu->addAction(aRestartGame); gameMenu->addAction(aRestartGame);
gameMenu->addAction(aLeaveGame); gameMenu->addAction(aLeaveGame);
gameMenu->addSeparator(); gameMenu->addSeparator();
@ -232,12 +225,10 @@ void MainWindow::createMenus()
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), game(NULL) : QMainWindow(parent), game(NULL)
{ {
// setWindowState(windowState() | Qt::WindowFullScreen);
QPixmapCache::setCacheLimit(200000); QPixmapCache::setCacheLimit(200000);
db = new CardDatabase; db = new CardDatabase;
int cardCount = db->loadFromFile("../cards.dat"); db->loadFromFile("../cards.dat");
// db->importOracleDir(); // db->importOracleDir();
// db->saveToFile("../cards.dat"); // db->saveToFile("../cards.dat");
@ -266,9 +257,11 @@ MainWindow::MainWindow(QWidget *parent)
verticalLayout->addWidget(messageLog); verticalLayout->addWidget(messageLog);
verticalLayout->addLayout(hLayout); verticalLayout->addLayout(hLayout);
viewLayout = new QVBoxLayout;
viewLayout->addWidget(view);
QHBoxLayout *mainLayout = new QHBoxLayout; QHBoxLayout *mainLayout = new QHBoxLayout;
mainLayout->addWidget(view); mainLayout->addLayout(viewLayout, 10);
// mainLayout->setStretchFactor(view, 10);
mainLayout->addLayout(verticalLayout); mainLayout->addLayout(verticalLayout);
QWidget *centralWidget = new QWidget; QWidget *centralWidget = new QWidget;
@ -288,6 +281,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(client, SIGNAL(welcomeMsgReceived(const QStringList)), messageLog, SLOT(logConnected(const QStringList))); connect(client, SIGNAL(welcomeMsgReceived(const QStringList)), messageLog, SLOT(logConnected(const QStringList)));
connect(this, SIGNAL(logDisconnected()), messageLog, SLOT(logDisconnected())); connect(this, SIGNAL(logDisconnected()), messageLog, SLOT(logDisconnected()));
connect(client, SIGNAL(logSocketError(const QString &)), messageLog, SLOT(logSocketError(const QString &))); connect(client, SIGNAL(logSocketError(const QString &)), messageLog, SLOT(logSocketError(const QString &)));
connect(client, SIGNAL(serverError(ServerResponse)), messageLog, SLOT(logServerError(ServerResponse)));
createActions(); createActions();
createMenus(); createMenus();

View file

@ -29,6 +29,7 @@ class Game;
class CardDatabase; class CardDatabase;
class Player; class Player;
class QVBoxLayout;
class CardInfoWidget; class CardInfoWidget;
class MessageLogWidget; class MessageLogWidget;
class QLineEdit; class QLineEdit;
@ -52,7 +53,6 @@ private slots:
void actConnect(); void actConnect();
void actDisconnect(); void actDisconnect();
void actGames();
void actRestartGame(); void actRestartGame();
void actLeaveGame(); void actLeaveGame();
void actDeckEditor(); void actDeckEditor();
@ -67,8 +67,9 @@ private:
void createActions(); void createActions();
void createMenus(); void createMenus();
QMenu *gameMenu, *actionsMenu, *cardMenu; QMenu *gameMenu, *actionsMenu, *cardMenu;
QAction *aConnect, *aDisconnect, *aGames, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aExit; QAction *aConnect, *aDisconnect, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aExit;
QAction *aCloseMostRecentZoneView; QAction *aCloseMostRecentZoneView;
QVBoxLayout *viewLayout;
CardInfoWidget *cardInfo; CardInfoWidget *cardInfo;
MessageLogWidget *messageLog; MessageLogWidget *messageLog;

View file

@ -39,10 +39,11 @@ ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_or
zone = new ZoneViewZone(player, _origZone, numberCards, this); zone = new ZoneViewZone(player, _origZone, numberCards, this);
zone->setPos(3, y); zone->setPos(3, y);
zone->setHeight(h - y); zone->setHeight((int) (h - y));
if (!zone->initializeCards()) { if (!zone->initializeCards()) {
connect(player->client, SIGNAL(zoneDumpReceived(int, QList<ServerZoneCard *>)), this, SLOT(zoneDumpReceived(int, QList<ServerZoneCard *>))); connect(player->client, SIGNAL(zoneDumpReceived(int, QList<ServerZoneCard *>)), this, SLOT(zoneDumpReceived(int, QList<ServerZoneCard *>)));
cmdId = player->client->dumpZone(player->getId(), _origZone->getName(), numberCards); PendingCommand *dumpZoneCommand = player->client->dumpZone(player->getId(), _origZone->getName(), numberCards);
cmdId = dumpZoneCommand->getMsgId();
} }
} }

View file

@ -2,6 +2,7 @@
method=none method=none
[database] [database]
type=mysql
hostname=localhost hostname=localhost
database=servatrice database=servatrice
user=servatrice user=servatrice