some changes
This commit is contained in:
parent
9b1adf2dc1
commit
c8a2ed9415
26 changed files with 243 additions and 613 deletions
|
@ -14,5 +14,5 @@ QT += network
|
|||
#QTPLUGIN += qjpeg
|
||||
|
||||
# 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
|
||||
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
|
||||
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/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
|
||||
|
|
|
@ -1,12 +1,31 @@
|
|||
#include <QTimer>
|
||||
#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)
|
||||
: QObject(parent), status(StatusDisconnected), MsgId(0)
|
||||
{
|
||||
timer = new QTimer(this);
|
||||
timer->setInterval(1000);
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(checkTimeout()));
|
||||
connect(timer, SIGNAL(timeout()), this, SLOT(ping()));
|
||||
|
||||
socket = new QTcpSocket(this);
|
||||
socket->setTextModeEnabled(true);
|
||||
|
@ -20,22 +39,10 @@ Client::~Client()
|
|||
disconnectFromServer();
|
||||
}
|
||||
|
||||
void Client::checkTimeout()
|
||||
void Client::timeout()
|
||||
{
|
||||
bool timeout = false;
|
||||
QListIterator<PendingCommand *> i(PendingCommands);
|
||||
while (i.hasNext()) {
|
||||
PendingCommand *c = i.next();
|
||||
if (c->timeout()) {
|
||||
timeout = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (timeout) {
|
||||
disconnectFromServer();
|
||||
emit serverTimeout();
|
||||
} else
|
||||
ping();
|
||||
emit serverTimeout();
|
||||
disconnectFromServer();
|
||||
}
|
||||
|
||||
void Client::slotSocketError(QAbstractSocket::SocketError /*error*/)
|
||||
|
@ -50,6 +57,33 @@ void Client::slotConnected()
|
|||
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()
|
||||
{
|
||||
while (socket->canReadLine()) {
|
||||
|
@ -57,7 +91,7 @@ void Client::readLine()
|
|||
|
||||
if (line.isNull())
|
||||
break;
|
||||
qDebug(QString("readLine: %1").arg(line).toLatin1());
|
||||
qDebug(QString("<< %1").arg(line).toLatin1());
|
||||
QStringList values = line.split("|");
|
||||
QString prefix = values.takeFirst();
|
||||
// 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
|
||||
}
|
||||
|
||||
ok = !values.takeFirst().compare("ok");
|
||||
|
||||
// XXX
|
||||
ServerErrorMessage message = msgNone;
|
||||
|
||||
// Update list of pending commands
|
||||
QListIterator<PendingCommand *> i(PendingCommands);
|
||||
bool found = false;
|
||||
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));
|
||||
ServerResponse resp;
|
||||
if (values[0] == "ok")
|
||||
resp = RespOk;
|
||||
else if (values[1] == "password")
|
||||
resp = RespPassword;
|
||||
else
|
||||
resp = RespErr;
|
||||
emit responseReceived(msgid, resp);
|
||||
} 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()));
|
||||
} 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();
|
||||
|
||||
// XXX Parametergültigkeit überprüfen
|
||||
if (!prefix.compare("list_players"))
|
||||
if (prefix == "list_players")
|
||||
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());
|
||||
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]);
|
||||
else if (!prefix.compare("welcome"))
|
||||
else if (prefix == "welcome")
|
||||
welcomemsg << val[0];
|
||||
}
|
||||
if (!prefix.compare("list_players"))
|
||||
if (prefix == "list_players")
|
||||
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);
|
||||
else if (!prefix.compare("dump_zone"))
|
||||
else if (prefix == "dump_zone")
|
||||
emit zoneDumpReceived(cmdid, zonedump);
|
||||
else if (!prefix.compare("welcome")) {
|
||||
else if (prefix == "welcome") {
|
||||
emit welcomeMsgReceived(welcomemsg);
|
||||
setStatus(StatusConnected);
|
||||
login(PlayerName, password);
|
||||
setStatus(StatusLoggingIn);
|
||||
login(playerName, password);
|
||||
}
|
||||
msgbuf.clear();
|
||||
} else
|
||||
|
@ -165,23 +184,27 @@ void Client::setStatus(const ProtocolStatus _status)
|
|||
|
||||
void Client::msg(const QString &s)
|
||||
{
|
||||
qDebug(QString("msg gibt aus: %1").arg(s).toLatin1());
|
||||
qDebug(QString(">> %1").arg(s).toLatin1());
|
||||
QTextStream stream(socket);
|
||||
stream.setCodec("UTF-8");
|
||||
stream << s << endl;
|
||||
stream.flush();
|
||||
}
|
||||
|
||||
int Client::cmd(const QString &s)
|
||||
PendingCommand *Client::cmd(const QString &s)
|
||||
{
|
||||
msg(QString("%1|%2").arg(++MsgId).arg(s));
|
||||
PendingCommands << new PendingCommand(s, MsgId);
|
||||
return MsgId;
|
||||
PendingCommand *pc = new PendingCommand(s, MsgId, this);
|
||||
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;
|
||||
socket->connectToHost(hostname, port);
|
||||
setStatus(StatusConnecting);
|
||||
|
@ -199,74 +222,82 @@ void Client::disconnectFromServer()
|
|||
socket->close();
|
||||
}
|
||||
|
||||
int Client::ping()
|
||||
void Client::ping()
|
||||
{
|
||||
return cmd("ping");
|
||||
cmd("ping");
|
||||
}
|
||||
|
||||
int Client::listGames()
|
||||
PendingCommand *Client::listGames()
|
||||
{
|
||||
return cmd("list_games");
|
||||
}
|
||||
|
||||
int Client::listPlayers()
|
||||
PendingCommand *Client::listPlayers()
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
int Client::shuffle()
|
||||
PendingCommand *Client::shuffle()
|
||||
{
|
||||
return cmd("shuffle");
|
||||
}
|
||||
|
||||
int Client::rollDice(unsigned int sides)
|
||||
PendingCommand *Client::rollDice(unsigned int 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));
|
||||
}
|
||||
|
||||
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
|
||||
// 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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
@ -280,42 +311,42 @@ void Client::submitDeck(const QStringList &deck)
|
|||
msg(".");
|
||||
}
|
||||
|
||||
int Client::readyStart()
|
||||
PendingCommand *Client::readyStart()
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
int Client::delCounter(const QString &counter)
|
||||
PendingCommand *Client::delCounter(const QString &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));
|
||||
}
|
||||
|
||||
int Client::setActivePhase(int phase)
|
||||
PendingCommand *Client::setActivePhase(int 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));
|
||||
}
|
||||
|
|
|
@ -2,12 +2,10 @@
|
|||
#define CLIENT_H
|
||||
|
||||
#include "servereventdata.h"
|
||||
#include "serverresponse.h"
|
||||
#include "servergame.h"
|
||||
#include "serverplayer.h"
|
||||
#include "serverzone.h"
|
||||
#include "serverzonecard.h"
|
||||
#include "pendingcommand.h"
|
||||
#include <QTcpSocket>
|
||||
#include <QColor>
|
||||
|
||||
|
@ -19,7 +17,33 @@ class QTimer;
|
|||
enum ProtocolStatus { StatusDisconnected,
|
||||
StatusConnecting,
|
||||
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 {
|
||||
Q_OBJECT
|
||||
|
@ -30,60 +54,62 @@ signals:
|
|||
void playerListReceived(QList<ServerPlayer *> players);
|
||||
void zoneListReceived(int commandId, QList<ServerZone *> zones);
|
||||
void zoneDumpReceived(int commandId, QList<ServerZoneCard *> cards);
|
||||
void responseReceived(ServerResponse *response);
|
||||
void responseReceived(int msgid, ServerResponse resp);
|
||||
void playerIdReceived(int id, QString name);
|
||||
void gameEvent(const ServerEventData &msg);
|
||||
void serverTimeout();
|
||||
void logSocketError(const QString &errorString);
|
||||
|
||||
void serverError(ServerResponse resp);
|
||||
private slots:
|
||||
void slotConnected();
|
||||
void readLine();
|
||||
void checkTimeout();
|
||||
void timeout();
|
||||
void slotSocketError(QAbstractSocket::SocketError error);
|
||||
|
||||
void ping();
|
||||
void removePendingCommand();
|
||||
void loginResponse(ServerResponse response);
|
||||
void enterGameResponse(ServerResponse response);
|
||||
void leaveGameResponse(ServerResponse response);
|
||||
private:
|
||||
QTimer *timer;
|
||||
QList<PendingCommand *> PendingCommands;
|
||||
QTcpSocket *socket;
|
||||
ProtocolStatus status;
|
||||
QList<QStringList> msgbuf;
|
||||
QString PlayerName;
|
||||
QString password;
|
||||
QString playerName, password;
|
||||
unsigned int MsgId;
|
||||
void msg(const QString &s);
|
||||
int cmd(const QString &s);
|
||||
PendingCommand *cmd(const QString &s);
|
||||
void setStatus(const ProtocolStatus _status);
|
||||
public:
|
||||
Client(QObject *parent = 0);
|
||||
~Client();
|
||||
ProtocolStatus getStatus() const { return status; }
|
||||
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();
|
||||
int ping();
|
||||
int listGames();
|
||||
int listPlayers();
|
||||
int createGame(const QString &description, const QString &password, unsigned int maxPlayers);
|
||||
int joinGame(int gameId, const QString &password);
|
||||
int leaveGame();
|
||||
int login(const QString &name, const QString &pass);
|
||||
int say(const QString &s);
|
||||
int shuffle();
|
||||
int rollDice(unsigned int sides);
|
||||
int drawCards(unsigned int number);
|
||||
int moveCard(int cardid, const QString &startzone, const QString &targetzone, int x, int y = 0, bool faceDown = false);
|
||||
int createToken(const QString &zone, const QString &name, const QString &powtough, int x, int y);
|
||||
int setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue);
|
||||
int readyStart();
|
||||
int incCounter(const QString &counter, int delta);
|
||||
int addCounter(const QString &counter, QColor color, int value);
|
||||
int setCounter(const QString &counter, int value);
|
||||
int delCounter(const QString &counter);
|
||||
int setActivePlayer(int player);
|
||||
int setActivePhase(int phase);
|
||||
int dumpZone(int player, const QString &zone, int numberCards);
|
||||
PendingCommand *listGames();
|
||||
PendingCommand *listPlayers();
|
||||
PendingCommand *createGame(const QString &description, const QString &password, unsigned int maxPlayers);
|
||||
PendingCommand *joinGame(int gameId, const QString &password);
|
||||
PendingCommand *leaveGame();
|
||||
PendingCommand *login(const QString &name, const QString &pass);
|
||||
PendingCommand *say(const QString &s);
|
||||
PendingCommand *shuffle();
|
||||
PendingCommand *rollDice(unsigned int sides);
|
||||
PendingCommand *drawCards(unsigned int number);
|
||||
PendingCommand *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);
|
||||
PendingCommand *setCardAttr(const QString &zone, int cardid, const QString &aname, const QString &avalue);
|
||||
PendingCommand *readyStart();
|
||||
PendingCommand *incCounter(const QString &counter, int delta);
|
||||
PendingCommand *addCounter(const QString &counter, QColor color, int value);
|
||||
PendingCommand *setCounter(const QString &counter, int value);
|
||||
PendingCommand *delCounter(const QString &counter);
|
||||
PendingCommand *setActivePlayer(int player);
|
||||
PendingCommand *setActivePhase(int phase);
|
||||
PendingCommand *dumpZone(int player, const QString &zone, int numberCards);
|
||||
public slots:
|
||||
void submitDeck(const QStringList &deck);
|
||||
};
|
||||
|
|
|
@ -15,14 +15,12 @@ QRectF Counter::boundingRect() const
|
|||
|
||||
void Counter::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||
{
|
||||
painter->save();
|
||||
painter->setBrush(QBrush(color));
|
||||
painter->drawEllipse(boundingRect());
|
||||
if (value) {
|
||||
painter->setFont(QFont("Times", 16, QFont::Bold));
|
||||
painter->drawText(boundingRect(), Qt::AlignCenter, QString::number(value));
|
||||
}
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void Counter::setValue(int _value)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#include "dlg_creategame.h"
|
||||
|
||||
DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
|
||||
: QDialog(parent), client(_client), msgid(0)
|
||||
: QDialog(parent), client(_client)
|
||||
{
|
||||
descriptionLabel = new QLabel(tr("&Description:"));
|
||||
descriptionEdit = new QLineEdit;
|
||||
|
@ -27,50 +27,48 @@ DlgCreateGame::DlgCreateGame(Client *_client, QWidget *parent)
|
|||
okButton = new QPushButton(tr("&OK"));
|
||||
okButton->setDefault(true);
|
||||
cancelButton = new QPushButton(tr("&Cancel"));
|
||||
|
||||
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch();
|
||||
buttonLayout->addWidget(okButton);
|
||||
buttonLayout->addWidget(cancelButton);
|
||||
|
||||
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout;
|
||||
mainLayout->addLayout(grid);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
|
||||
|
||||
setLayout(mainLayout);
|
||||
|
||||
|
||||
setWindowTitle(tr("Create game"));
|
||||
setFixedHeight(sizeHint().height());
|
||||
|
||||
|
||||
connect(okButton, SIGNAL(clicked()), this, SLOT(actOK()));
|
||||
connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
|
||||
connect(client, SIGNAL(responseReceived(ServerResponse *)), this, SLOT(checkResponse(ServerResponse *)));
|
||||
}
|
||||
|
||||
void DlgCreateGame::actOK()
|
||||
{
|
||||
bool ok;
|
||||
int maxPlayers = maxPlayersEdit->text().toInt(&ok);
|
||||
if (msgid)
|
||||
return;
|
||||
if (!ok) {
|
||||
QMessageBox::critical(this, tr("Error"), tr("Invalid number of players."));
|
||||
return;
|
||||
}
|
||||
msgid = client->createGame(descriptionEdit->text(),
|
||||
passwordEdit->text(),
|
||||
maxPlayers);
|
||||
PendingCommand *createCommand = client->createGame(descriptionEdit->text(), passwordEdit->text(), maxPlayers);
|
||||
connect(createCommand, SIGNAL(finished(ServerResponse)), this, SLOT(checkResponse(ServerResponse)));
|
||||
okButton->setEnabled(false);
|
||||
cancelButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void DlgCreateGame::checkResponse(ServerResponse *response)
|
||||
void DlgCreateGame::checkResponse(ServerResponse response)
|
||||
{
|
||||
if (response->getMsgId() != msgid)
|
||||
return;
|
||||
if (response->getOk())
|
||||
okButton->setEnabled(true);
|
||||
cancelButton->setEnabled(true);
|
||||
|
||||
if (response == RespOk)
|
||||
accept();
|
||||
else {
|
||||
QMessageBox::critical(this, tr("Error"), tr("XXX"));
|
||||
msgid = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,15 +14,14 @@ public:
|
|||
DlgCreateGame(Client *_client, QWidget *parent = 0);
|
||||
private slots:
|
||||
void actOK();
|
||||
void checkResponse(ServerResponse *response);
|
||||
void checkResponse(ServerResponse response);
|
||||
private:
|
||||
Client *client;
|
||||
int msgid;
|
||||
|
||||
|
||||
QLabel *descriptionLabel, *passwordLabel, *maxPlayersLabel;
|
||||
QLineEdit *descriptionEdit, *passwordEdit, *maxPlayersEdit;
|
||||
QPushButton *okButton, *cancelButton;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
||||
|
|
@ -5,7 +5,6 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent)
|
|||
{
|
||||
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
||||
// setOptimizationFlags(/*DontClipPainter | */DontSavePainterState);
|
||||
setDragMode(RubberBandDrag);
|
||||
// setViewportUpdateMode(FullViewportUpdate);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -21,15 +21,15 @@ QRectF LibraryZone::boundingRect() const
|
|||
|
||||
void LibraryZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
QSizeF translatedSize = option->matrix.mapRect(boundingRect()).size();
|
||||
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);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void LibraryZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||
|
|
|
@ -26,6 +26,14 @@ void MessageLogWidget::logSocketError(const QString &errorString)
|
|||
append(errorString);
|
||||
}
|
||||
|
||||
void MessageLogWidget::logServerError(ServerResponse response)
|
||||
{
|
||||
switch (response) {
|
||||
case RespPassword: append(tr("Invalid password.")); break;
|
||||
default: ;
|
||||
}
|
||||
}
|
||||
|
||||
void MessageLogWidget::logPlayerListReceived(QStringList players)
|
||||
{
|
||||
append("---");
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QTextEdit>
|
||||
#include <QAbstractSocket>
|
||||
#include "client.h"
|
||||
|
||||
class Game;
|
||||
|
||||
|
@ -13,6 +14,7 @@ public slots:
|
|||
void logConnected(const QStringList WelcomeMsg);
|
||||
void logDisconnected();
|
||||
void logSocketError(const QString &errorString);
|
||||
void logServerError(ServerResponse response);
|
||||
private slots:
|
||||
void logPlayerListReceived(QStringList players);
|
||||
void logJoin(QString playerName);
|
||||
|
|
|
@ -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
|
|
@ -174,12 +174,12 @@ void Player::gameEvent(const ServerEventData &event)
|
|||
zones.at(i)->reorganizeCards();
|
||||
|
||||
if (local) {
|
||||
client->addCounter("life", QColor("white"), 20);
|
||||
client->addCounter("w", QColor(200, 200, 200), 0);
|
||||
client->addCounter("u", QColor(0, 0, 200), 0);
|
||||
client->addCounter("b", QColor(100, 100, 100), 0);
|
||||
client->addCounter("r", QColor(200, 0, 0), 0);
|
||||
client->addCounter("g", QColor(0, 200, 0), 0);
|
||||
client->addCounter("life", Qt::white, 20);
|
||||
client->addCounter("w", QColor(255, 255, 150), 0);
|
||||
client->addCounter("u", QColor(150, 150, 255), 0);
|
||||
client->addCounter("b", QColor(150, 150, 150), 0);
|
||||
client->addCounter("r", QColor(250, 150, 150), 0);
|
||||
client->addCounter("g", QColor(150, 255, 150), 0);
|
||||
client->addCounter("x", QColor(255, 255, 255), 0);
|
||||
client->addCounter("storm", QColor(255, 255, 255), 0);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,7 @@
|
|||
#include "tablezone.h"
|
||||
#include "handzone.h"
|
||||
#include "libraryzone.h"
|
||||
#include "gravezone.h"
|
||||
#include "rfgzone.h"
|
||||
#include "sideboardzone.h"
|
||||
#include "pilezone.h"
|
||||
#include "counter.h"
|
||||
#include <QPainter>
|
||||
|
||||
|
@ -19,13 +17,13 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
|
|||
|
||||
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));
|
||||
|
||||
RfgZone *rfg = new RfgZone(_player, this);
|
||||
PileZone *rfg = new PileZone(_player, "rfg", this);
|
||||
rfg->setPos(base + QPointF(0, 2 * h));
|
||||
|
||||
SideboardZone *sb = new SideboardZone(_player, this);
|
||||
PileZone *sb = new PileZone(_player, "sb", this);
|
||||
sb->setVisible(false);
|
||||
|
||||
base = QPointF(deck->boundingRect().width() + 60, 0);
|
||||
|
@ -38,7 +36,6 @@ PlayerArea::PlayerArea(Player *_player, QGraphicsItem *parent)
|
|||
table->setPos(base);
|
||||
|
||||
bRect = QRectF(0, 0, base.x() + table->boundingRect().width(), base.y() + table->boundingRect().height());
|
||||
qDebug(QString("%1").arg(bRect.width()).toLatin1());
|
||||
}
|
||||
|
||||
PlayerArea::~PlayerArea()
|
||||
|
@ -53,15 +50,11 @@ QRectF PlayerArea::boundingRect() const
|
|||
|
||||
void PlayerArea::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||
{
|
||||
painter->save();
|
||||
|
||||
painter->fillRect(boundingRect(), QColor(200, 200, 200));
|
||||
|
||||
painter->setFont(QFont("Times", 16, QFont::Bold));
|
||||
painter->setPen(QPen(Qt::black));
|
||||
painter->drawText(QRectF(0, 0, CARD_WIDTH + 60, 40), Qt::AlignCenter, player->getName());
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
Counter *PlayerArea::getCounter(const QString &name, bool remove)
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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
|
|
@ -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());
|
||||
}
|
|
@ -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
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "window_main.h"
|
||||
#include "dlg_connect.h"
|
||||
#include "dlg_games.h"
|
||||
#include "gameselector.h"
|
||||
#include "window_deckeditor.h"
|
||||
#include "cardinfowidget.h"
|
||||
#include "messagelogwidget.h"
|
||||
|
@ -64,14 +64,19 @@ void MainWindow::statusChanged(ProtocolStatus _status)
|
|||
game = 0;
|
||||
}
|
||||
aDisconnect->setEnabled(false);
|
||||
aGames->setEnabled(false);
|
||||
aRestartGame->setEnabled(false);
|
||||
aLeaveGame->setEnabled(false);
|
||||
emit logDisconnected();
|
||||
break;
|
||||
case StatusConnected:
|
||||
case StatusLoggingIn:
|
||||
aDisconnect->setEnabled(true);
|
||||
aGames->setEnabled(true);
|
||||
break;
|
||||
case StatusIdle: {
|
||||
GameSelector *gameSelector = new GameSelector(client);
|
||||
viewLayout->insertWidget(0, gameSelector);
|
||||
}
|
||||
case StatusPlaying:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -91,12 +96,6 @@ void MainWindow::actDisconnect()
|
|||
client->disconnectFromServer();
|
||||
}
|
||||
|
||||
void MainWindow::actGames()
|
||||
{
|
||||
DlgGames dlg(client, this);
|
||||
dlg.exec();
|
||||
}
|
||||
|
||||
void MainWindow::actRestartGame()
|
||||
{
|
||||
zoneLayout->clear();
|
||||
|
@ -111,7 +110,6 @@ void MainWindow::actLeaveGame()
|
|||
game = 0;
|
||||
aRestartGame->setEnabled(false);
|
||||
aLeaveGame->setEnabled(false);
|
||||
aGames->setEnabled(true);
|
||||
}
|
||||
|
||||
void MainWindow::actDeckEditor()
|
||||
|
@ -164,7 +162,6 @@ void MainWindow::playerIdReceived(int id, QString name)
|
|||
playerAdded(game->getLocalPlayer());
|
||||
|
||||
messageLog->connectToGame(game);
|
||||
aGames->setEnabled(false);
|
||||
aRestartGame->setEnabled(true);
|
||||
aLeaveGame->setEnabled(true);
|
||||
|
||||
|
@ -183,9 +180,6 @@ void MainWindow::createActions()
|
|||
aDisconnect = new QAction(tr("&Disconnect"), this);
|
||||
aDisconnect->setEnabled(false);
|
||||
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->setShortcut(tr("F2"));
|
||||
aRestartGame->setEnabled(false);
|
||||
|
@ -214,7 +208,6 @@ void MainWindow::createMenus()
|
|||
gameMenu->addAction(aConnect);
|
||||
gameMenu->addAction(aDisconnect);
|
||||
gameMenu->addSeparator();
|
||||
gameMenu->addAction(aGames);
|
||||
gameMenu->addAction(aRestartGame);
|
||||
gameMenu->addAction(aLeaveGame);
|
||||
gameMenu->addSeparator();
|
||||
|
@ -232,12 +225,10 @@ void MainWindow::createMenus()
|
|||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QMainWindow(parent), game(NULL)
|
||||
{
|
||||
// setWindowState(windowState() | Qt::WindowFullScreen);
|
||||
|
||||
QPixmapCache::setCacheLimit(200000);
|
||||
|
||||
db = new CardDatabase;
|
||||
int cardCount = db->loadFromFile("../cards.dat");
|
||||
db->loadFromFile("../cards.dat");
|
||||
// db->importOracleDir();
|
||||
// db->saveToFile("../cards.dat");
|
||||
|
||||
|
@ -266,9 +257,11 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
verticalLayout->addWidget(messageLog);
|
||||
verticalLayout->addLayout(hLayout);
|
||||
|
||||
viewLayout = new QVBoxLayout;
|
||||
viewLayout->addWidget(view);
|
||||
|
||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||
mainLayout->addWidget(view);
|
||||
// mainLayout->setStretchFactor(view, 10);
|
||||
mainLayout->addLayout(viewLayout, 10);
|
||||
mainLayout->addLayout(verticalLayout);
|
||||
|
||||
QWidget *centralWidget = new QWidget;
|
||||
|
@ -288,6 +281,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
connect(client, SIGNAL(welcomeMsgReceived(const QStringList)), messageLog, SLOT(logConnected(const QStringList)));
|
||||
connect(this, SIGNAL(logDisconnected()), messageLog, SLOT(logDisconnected()));
|
||||
connect(client, SIGNAL(logSocketError(const QString &)), messageLog, SLOT(logSocketError(const QString &)));
|
||||
connect(client, SIGNAL(serverError(ServerResponse)), messageLog, SLOT(logServerError(ServerResponse)));
|
||||
|
||||
createActions();
|
||||
createMenus();
|
||||
|
|
|
@ -29,6 +29,7 @@ class Game;
|
|||
class CardDatabase;
|
||||
class Player;
|
||||
|
||||
class QVBoxLayout;
|
||||
class CardInfoWidget;
|
||||
class MessageLogWidget;
|
||||
class QLineEdit;
|
||||
|
@ -52,7 +53,6 @@ private slots:
|
|||
|
||||
void actConnect();
|
||||
void actDisconnect();
|
||||
void actGames();
|
||||
void actRestartGame();
|
||||
void actLeaveGame();
|
||||
void actDeckEditor();
|
||||
|
@ -67,8 +67,9 @@ private:
|
|||
void createActions();
|
||||
void createMenus();
|
||||
QMenu *gameMenu, *actionsMenu, *cardMenu;
|
||||
QAction *aConnect, *aDisconnect, *aGames, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aExit;
|
||||
QAction *aConnect, *aDisconnect, *aRestartGame, *aLeaveGame, *aDeckEditor, *aFullScreen, *aExit;
|
||||
QAction *aCloseMostRecentZoneView;
|
||||
QVBoxLayout *viewLayout;
|
||||
|
||||
CardInfoWidget *cardInfo;
|
||||
MessageLogWidget *messageLog;
|
||||
|
|
|
@ -39,10 +39,11 @@ ZoneViewWidget::ZoneViewWidget(CardDatabase *_db, Player *_player, CardZone *_or
|
|||
|
||||
zone = new ZoneViewZone(player, _origZone, numberCards, this);
|
||||
zone->setPos(3, y);
|
||||
zone->setHeight(h - y);
|
||||
zone->setHeight((int) (h - y));
|
||||
if (!zone->initializeCards()) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
method=none
|
||||
|
||||
[database]
|
||||
type=mysql
|
||||
hostname=localhost
|
||||
database=servatrice
|
||||
user=servatrice
|
||||
|
|
Loading…
Reference in a new issue