minor cleanups
This commit is contained in:
parent
0ef00dd437
commit
7e13352a95
29 changed files with 102 additions and 134 deletions
|
@ -46,7 +46,7 @@ private:
|
||||||
public:
|
public:
|
||||||
enum { Type = typeCard };
|
enum { Type = typeCard };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
CardItem(CardDatabase *_db, const QString &_name, int _cardid, QGraphicsItem *parent = 0);
|
CardItem(CardDatabase *_db, const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0);
|
||||||
~CardItem();
|
~CardItem();
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
|
|
||||||
CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, QGraphicsItem *parent, bool isView)
|
CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _isShufflable, QGraphicsItem *parent, bool isView)
|
||||||
: QGraphicsItem(parent), player(_p), name(_name), cards(NULL), menu(NULL), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
|
: QGraphicsItem(parent), player(_p), name(_name), cards(NULL), view(NULL), menu(NULL), hasCardAttr(_hasCardAttr), isShufflable(_isShufflable)
|
||||||
{
|
{
|
||||||
if (!isView)
|
if (!isView)
|
||||||
player->addZone(this);
|
player->addZone(this);
|
||||||
|
@ -15,9 +15,7 @@ CardZone::CardZone(Player *_p, const QString &_name, bool _hasCardAttr, bool _is
|
||||||
CardZone::~CardZone()
|
CardZone::~CardZone()
|
||||||
{
|
{
|
||||||
qDebug(QString("CardZone destructor: %1").arg(name).toLatin1());
|
qDebug(QString("CardZone destructor: %1").arg(name).toLatin1());
|
||||||
while (!views.empty())
|
delete view;
|
||||||
delete views.at(0);
|
|
||||||
|
|
||||||
clearContents();
|
clearContents();
|
||||||
delete cards;
|
delete cards;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +39,17 @@ void CardZone::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
event->ignore();
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CardZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
||||||
|
{
|
||||||
|
if (view)
|
||||||
|
view->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y);
|
||||||
|
|
||||||
|
addCardImpl(card, x, y);
|
||||||
|
|
||||||
|
if (reorganize)
|
||||||
|
reorganizeCards();
|
||||||
|
}
|
||||||
|
|
||||||
CardItem *CardZone::getCard(int cardId, const QString &cardName)
|
CardItem *CardZone::getCard(int cardId, const QString &cardName)
|
||||||
{
|
{
|
||||||
CardItem *c = cards->findCard(cardId, false);
|
CardItem *c = cards->findCard(cardId, false);
|
||||||
|
@ -60,13 +69,13 @@ CardItem *CardZone::takeCard(int position, int cardId, const QString &cardName)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
CardItem *c = cards->takeAt(position);
|
CardItem *c = cards->takeAt(position);
|
||||||
for (int i = 0; i < views.size(); i++)
|
|
||||||
views[i]->removeCard(position);
|
if (view)
|
||||||
|
view->removeCard(position);
|
||||||
|
|
||||||
|
c->setId(cardId);
|
||||||
|
c->setName(cardName);
|
||||||
|
|
||||||
// if (c->getId() == -1) {
|
|
||||||
c->setId(cardId);
|
|
||||||
c->setName(cardName);
|
|
||||||
// }
|
|
||||||
reorganizeCards();
|
reorganizeCards();
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -82,14 +91,9 @@ void CardZone::hoverCardEvent(CardItem *card)
|
||||||
player->hoverCardEvent(card);
|
player->hoverCardEvent(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardZone::addView(ZoneViewZone *view)
|
void CardZone::setView(ZoneViewZone *_view)
|
||||||
{
|
{
|
||||||
views.append(view);
|
view = _view;
|
||||||
}
|
|
||||||
|
|
||||||
void CardZone::removeView(ZoneViewZone *view)
|
|
||||||
{
|
|
||||||
views.removeAt(views.indexOf(view));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardZone::moveAllToZone(const QString &targetZone, int targetX)
|
void CardZone::moveAllToZone(const QString &targetZone, int targetX)
|
||||||
|
|
|
@ -14,11 +14,12 @@ protected:
|
||||||
Player *player;
|
Player *player;
|
||||||
QString name;
|
QString name;
|
||||||
CardList *cards;
|
CardList *cards;
|
||||||
QList<ZoneViewZone *> views;
|
ZoneViewZone *view;
|
||||||
QMenu *menu;
|
QMenu *menu;
|
||||||
bool hasCardAttr;
|
bool hasCardAttr;
|
||||||
bool isShufflable;
|
bool isShufflable;
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
virtual void addCardImpl(CardItem *card, int x, int y) = 0;
|
||||||
public:
|
public:
|
||||||
enum { Type = typeZone };
|
enum { Type = typeZone };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
|
@ -33,16 +34,15 @@ public:
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
Player *getPlayer() const { return player; }
|
Player *getPlayer() const { return player; }
|
||||||
bool contentsKnown() const { return cards->getContentsKnown(); }
|
bool contentsKnown() const { return cards->getContentsKnown(); }
|
||||||
CardList *const getCards() const { return cards; }
|
CardList *getCards() const { return cards; }
|
||||||
virtual void addCard(CardItem *card, bool reorganize = true, int x = -1, int y = -1) = 0;
|
void addCard(CardItem *card, bool reorganize, int x, int y = -1);
|
||||||
// getCard() finds a card by id.
|
// getCard() finds a card by id.
|
||||||
CardItem *getCard(int cardId, const QString &cardName);
|
CardItem *getCard(int cardId, const QString &cardName);
|
||||||
// takeCard() finds a card by position and removes it from the zone and from all of its views.
|
// takeCard() finds a card by position and removes it from the zone and from all of its views.
|
||||||
CardItem *takeCard(int position, int cardId, const QString &cardName);
|
CardItem *takeCard(int position, int cardId, const QString &cardName);
|
||||||
void setCardAttr(int cardId, const QString &aname, const QString &avalue);
|
void setCardAttr(int cardId, const QString &aname, const QString &avalue);
|
||||||
void hoverCardEvent(CardItem *card);
|
void hoverCardEvent(CardItem *card);
|
||||||
void addView(ZoneViewZone *view);
|
void setView(ZoneViewZone *_view);
|
||||||
void removeView(ZoneViewZone *view);
|
|
||||||
virtual void reorganizeCards() = 0;
|
virtual void reorganizeCards() = 0;
|
||||||
void moveAllToZone(const QString &targetZone, int targetX);
|
void moveAllToZone(const QString &targetZone, int targetX);
|
||||||
};
|
};
|
||||||
|
|
|
@ -95,7 +95,7 @@ Game::Game(CardDatabase *_db, Client *_client, QGraphicsScene *_scene, QMenu *_a
|
||||||
|
|
||||||
dlgStartGame = new DlgStartGame(db);
|
dlgStartGame = new DlgStartGame(db);
|
||||||
connect(dlgStartGame, SIGNAL(newDeckLoaded(const QStringList &)), client, SLOT(submitDeck(const QStringList &)));
|
connect(dlgStartGame, SIGNAL(newDeckLoaded(const QStringList &)), client, SLOT(submitDeck(const QStringList &)));
|
||||||
connect(dlgStartGame, SIGNAL(finished(int)), this, SLOT(readyStart(int)));
|
connect(dlgStartGame, SIGNAL(finished(int)), this, SLOT(readyStart()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
|
@ -144,10 +144,8 @@ void Game::playerListReceived(QList<ServerPlayer *> playerList)
|
||||||
restartGameDialog();
|
restartGameDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::readyStart(int foo)
|
void Game::readyStart()
|
||||||
{
|
{
|
||||||
Q_UNUSED(foo);
|
|
||||||
|
|
||||||
client->readyStart();
|
client->readyStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ private slots:
|
||||||
|
|
||||||
void gameEvent(ServerEventData *msg);
|
void gameEvent(ServerEventData *msg);
|
||||||
void playerListReceived(QList<ServerPlayer *> playerList);
|
void playerListReceived(QList<ServerPlayer *> playerList);
|
||||||
void readyStart(int foo);
|
void readyStart();
|
||||||
signals:
|
signals:
|
||||||
void submitDecklist();
|
void submitDecklist();
|
||||||
void hoverCard(QString name);
|
void hoverCard(QString name);
|
||||||
|
|
|
@ -6,12 +6,12 @@ GamesModel::~GamesModel()
|
||||||
cleanList();
|
cleanList();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GamesModel::rowCount(const QModelIndex &parent) const
|
int GamesModel::rowCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return gameList.size();
|
return gameList.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GamesModel::columnCount(const QModelIndex &parent) const
|
int GamesModel::columnCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,8 @@ QRectF GraveZone::boundingRect() const
|
||||||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraveZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void GraveZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
|
||||||
Q_UNUSED(widget);
|
|
||||||
painter->save();
|
painter->save();
|
||||||
|
|
||||||
painter->fillRect(boundingRect(), QColor("yellow"));
|
painter->fillRect(boundingRect(), QColor("yellow"));
|
||||||
|
@ -33,22 +31,16 @@ void GraveZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraveZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
void GraveZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < views.size(); i++)
|
|
||||||
views[i]->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y);
|
|
||||||
|
|
||||||
cards->insert(x, card);
|
cards->insert(x, card);
|
||||||
card->setPos(0, 0);
|
card->setPos(0, 0);
|
||||||
card->setVisible(false);
|
card->setVisible(false);
|
||||||
card->resetState();
|
card->resetState();
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
|
|
||||||
if (reorganize)
|
|
||||||
reorganizeCards();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraveZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
|
void GraveZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ public:
|
||||||
GraveZone(Player *_p, QGraphicsItem *parent = 0);
|
GraveZone(Player *_p, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(CardItem *card, bool reorganize = true, int x = 0, int y = -1);
|
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -45,10 +45,8 @@ void HandZone::reorganizeCards()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
void HandZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
Q_UNUSED(y);
|
|
||||||
|
|
||||||
if (x == -1)
|
if (x == -1)
|
||||||
x = cards->size();
|
x = cards->size();
|
||||||
cards->insert(x, card);
|
cards->insert(x, card);
|
||||||
|
@ -61,13 +59,9 @@ void HandZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
||||||
card->resetState();
|
card->resetState();
|
||||||
card->setVisible(true);
|
card->setVisible(true);
|
||||||
card->update(card->boundingRect());
|
card->update(card->boundingRect());
|
||||||
|
|
||||||
if (reorganize)
|
|
||||||
reorganizeCards();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
|
void HandZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
Q_UNUSED(dropPoint);
|
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), cards->size(), 0);
|
player->client->moveCard(cardId, startZone->getName(), getName(), cards->size(), 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,10 @@ public:
|
||||||
HandZone(Player *_p, QGraphicsItem *parent = 0);
|
HandZone(Player *_p, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(CardItem *card, bool reorganize = true, int x = -1, int y = -1);
|
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
||||||
|
protected:
|
||||||
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,11 +40,8 @@ void LibraryZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *optio
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
void LibraryZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < views.size(); i++)
|
|
||||||
views[i]->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y);
|
|
||||||
|
|
||||||
cards->insert(x, card);
|
cards->insert(x, card);
|
||||||
card->setId(-1);
|
card->setId(-1);
|
||||||
card->setName(QString());
|
card->setName(QString());
|
||||||
|
@ -52,12 +49,9 @@ void LibraryZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
||||||
card->setVisible(false);
|
card->setVisible(false);
|
||||||
card->resetState();
|
card->resetState();
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
|
|
||||||
if (reorganize)
|
|
||||||
reorganizeCards();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibraryZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
|
void LibraryZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ public:
|
||||||
LibraryZone(Player *_p, QGraphicsItem *parent = 0);
|
LibraryZone(Player *_p, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(CardItem *card, bool reorganize = true, int x = 0, int y = -1);
|
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -161,12 +161,12 @@ void Player::gameEvent(ServerEventData *event)
|
||||||
|
|
||||||
CardZone *deck = zones.findZone("deck");
|
CardZone *deck = zones.findZone("deck");
|
||||||
for (; deck_cards; deck_cards--)
|
for (; deck_cards; deck_cards--)
|
||||||
deck->addCard(new CardItem(db, QString(), -1));
|
deck->addCard(new CardItem(db), false, -1);
|
||||||
deck->reorganizeCards();
|
deck->reorganizeCards();
|
||||||
|
|
||||||
CardZone *sb = zones.findZone("sb");
|
CardZone *sb = zones.findZone("sb");
|
||||||
for (; sb_cards; sb_cards--)
|
for (; sb_cards; sb_cards--)
|
||||||
sb->addCard(new CardItem(db, QString(), -1));
|
sb->addCard(new CardItem(db), false, -1);
|
||||||
sb->reorganizeCards();
|
sb->reorganizeCards();
|
||||||
|
|
||||||
if (local) {
|
if (local) {
|
||||||
|
@ -186,11 +186,12 @@ void Player::gameEvent(ServerEventData *event)
|
||||||
CardZone *deck = zones.findZone("deck");
|
CardZone *deck = zones.findZone("deck");
|
||||||
CardZone *hand = zones.findZone("hand");
|
CardZone *hand = zones.findZone("hand");
|
||||||
if (!event->getPublic()) {
|
if (!event->getPublic()) {
|
||||||
hand->addCard(deck->takeCard(0, data[0].toInt(), data[1]));
|
hand->addCard(deck->takeCard(0, data[0].toInt(), data[1]), true, -1);
|
||||||
} else {
|
} else {
|
||||||
int number = data[0].toInt();
|
int number = data[0].toInt();
|
||||||
for (; number; number--)
|
for (; number; number--)
|
||||||
hand->addCard(deck->takeCard(0, -1, QString()));
|
hand->addCard(deck->takeCard(0, -1, QString()), false, -1);
|
||||||
|
hand->reorganizeCards();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ public:
|
||||||
int getId() const { return id; }
|
int getId() const { return id; }
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
bool getLocal() const { return local; }
|
bool getLocal() const { return local; }
|
||||||
const ZoneList *const getZones() const { return &zones; }
|
const ZoneList *getZones() const { return &zones; }
|
||||||
void gameEvent(ServerEventData *event);
|
void gameEvent(ServerEventData *event);
|
||||||
void hoverCardEvent(CardItem *card);
|
void hoverCardEvent(CardItem *card);
|
||||||
CardDatabase *getDb() const { return db; }
|
CardDatabase *getDb() const { return db; }
|
||||||
|
|
|
@ -33,22 +33,16 @@ void RfgZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RfgZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
void RfgZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < views.size(); i++)
|
|
||||||
views[i]->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y);
|
|
||||||
|
|
||||||
cards->insert(x, card);
|
cards->insert(x, card);
|
||||||
card->setPos(0, 0);
|
card->setPos(0, 0);
|
||||||
card->setVisible(false);
|
card->setVisible(false);
|
||||||
card->resetState();
|
card->resetState();
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
|
|
||||||
if (reorganize)
|
|
||||||
reorganizeCards();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RfgZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
|
void RfgZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@ public:
|
||||||
RfgZone(Player *_p, QGraphicsItem *parent = 0);
|
RfgZone(Player *_p, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(CardItem *card, bool reorganize = true, int x = 0, int y = -1);
|
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -15,10 +15,8 @@ QRectF SideboardZone::boundingRect() const
|
||||||
return QRectF(0, 0, 50, 50);
|
return QRectF(0, 0, 50, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideboardZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
void SideboardZone::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
|
||||||
{
|
{
|
||||||
Q_UNUSED(option);
|
|
||||||
Q_UNUSED(widget);
|
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->fillRect(boundingRect(), QColor("blue"));
|
painter->fillRect(boundingRect(), QColor("blue"));
|
||||||
painter->setFont(QFont("Times", 20, QFont::Bold));
|
painter->setFont(QFont("Times", 20, QFont::Bold));
|
||||||
|
@ -27,22 +25,16 @@ void SideboardZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *opt
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideboardZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
void SideboardZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < views.size(); i++)
|
|
||||||
views[i]->addCard(new CardItem(player->getDb(), card->getName(), card->getId()), reorganize, x, y);
|
|
||||||
|
|
||||||
cards->insert(x, card);
|
cards->insert(x, card);
|
||||||
card->setPos(0, 0);
|
card->setPos(0, 0);
|
||||||
card->setVisible(false);
|
card->setVisible(false);
|
||||||
card->resetState();
|
card->resetState();
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
|
|
||||||
if (reorganize)
|
|
||||||
reorganizeCards();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SideboardZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
|
void SideboardZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
||||||
}
|
}
|
||||||
|
@ -51,4 +43,3 @@ void SideboardZone::reorganizeCards()
|
||||||
{
|
{
|
||||||
update(boundingRect());
|
update(boundingRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,10 @@ public:
|
||||||
SideboardZone(Player *_p, QGraphicsItem *parent = 0);
|
SideboardZone(Player *_p, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(CardItem *card, bool reorganize = true, int x = 0, int y = -1);
|
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
||||||
|
protected:
|
||||||
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,9 +21,8 @@ void TableZone::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TableZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
void TableZone::addCardImpl(CardItem *card, int x, int y)
|
||||||
{
|
{
|
||||||
Q_UNUSED(reorganize);
|
|
||||||
cards->append(card);
|
cards->append(card);
|
||||||
if ((x != -1) && (y != -1)) {
|
if ((x != -1) && (y != -1)) {
|
||||||
if (!player->getLocal())
|
if (!player->getLocal())
|
||||||
|
|
|
@ -13,10 +13,11 @@ public:
|
||||||
TableZone(Player *_p, QGraphicsItem *parent = 0);
|
TableZone(Player *_p, QGraphicsItem *parent = 0);
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(CardItem *card, bool reorganize = true, int x = -1, int y = -1);
|
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
void toggleTapped();
|
void toggleTapped();
|
||||||
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
void handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown);
|
||||||
|
protected:
|
||||||
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -277,11 +277,8 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
createMenus();
|
createMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::closeEvent(QCloseEvent *event)
|
void MainWindow::closeEvent(QCloseEvent */*event*/)
|
||||||
{
|
{
|
||||||
delete game;
|
delete game;
|
||||||
|
|
||||||
// db->importOracle();
|
|
||||||
// db->saveToFile("../cards.dat");
|
|
||||||
delete db;
|
delete db;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,13 @@ ZoneViewZone::ZoneViewZone(Player *_p, CardZone *_origZone, int _numberCards, QG
|
||||||
: CardZone(_p, _origZone->getName(), false, false, parent, true), height(0), numberCards(_numberCards), origZone(_origZone)
|
: CardZone(_p, _origZone->getName(), false, false, parent, true), height(0), numberCards(_numberCards), origZone(_origZone)
|
||||||
{
|
{
|
||||||
cards = new CardList(true);
|
cards = new CardList(true);
|
||||||
origZone->addView(this);
|
origZone->setView(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZoneViewZone::~ZoneViewZone()
|
ZoneViewZone::~ZoneViewZone()
|
||||||
{
|
{
|
||||||
qDebug("ZoneViewZone destructor");
|
qDebug("ZoneViewZone destructor");
|
||||||
origZone->removeView(this);
|
origZone->setView(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF ZoneViewZone::boundingRect() const
|
QRectF ZoneViewZone::boundingRect() const
|
||||||
|
@ -74,20 +74,15 @@ void ZoneViewZone::reorganizeCards()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneViewZone::addCard(CardItem *card, bool reorganize, int x, int y)
|
void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
|
||||||
{
|
{
|
||||||
Q_UNUSED(y);
|
|
||||||
qDebug(QString("ZoneViewZone: inserting '%1' at x=%2").arg(card->getName()).arg(x).toLatin1());
|
|
||||||
cards->insert(x, card);
|
cards->insert(x, card);
|
||||||
card->setParentItem(this);
|
card->setParentItem(this);
|
||||||
card->update(card->boundingRect());
|
card->update(card->boundingRect());
|
||||||
if (reorganize)
|
|
||||||
reorganizeCards();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &dropPoint, bool faceDown)
|
void ZoneViewZone::handleDropEvent(int cardId, CardZone *startZone, const QPoint &/*dropPoint*/, bool /*faceDown*/)
|
||||||
{
|
{
|
||||||
Q_UNUSED(dropPoint);
|
|
||||||
qDebug(QString("handleDropEvent id=%1").arg(cardId).toLatin1());
|
qDebug(QString("handleDropEvent id=%1").arg(cardId).toLatin1());
|
||||||
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
player->client->moveCard(cardId, startZone->getName(), getName(), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,12 @@ public:
|
||||||
~ZoneViewZone();
|
~ZoneViewZone();
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(CardItem *card, bool reorganize = true, int x = 0, int y = -1);
|
|
||||||
void reorganizeCards();
|
void reorganizeCards();
|
||||||
bool initializeCards();
|
bool initializeCards();
|
||||||
void removeCard(int position);
|
void removeCard(int position);
|
||||||
void setHeight(int _height) { height = _height; }
|
void setHeight(int _height) { height = _height; }
|
||||||
|
protected:
|
||||||
|
void addCardImpl(CardItem *card, int x, int y);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
[authentication]
|
||||||
|
method=none
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
hostname=localhost
|
hostname=localhost
|
||||||
database=servatrice
|
database=servatrice
|
||||||
|
|
|
@ -6,6 +6,8 @@ TEMPLATE = app
|
||||||
TARGET =
|
TARGET =
|
||||||
DEPENDPATH += . src
|
DEPENDPATH += . src
|
||||||
INCLUDEPATH += . src
|
INCLUDEPATH += . src
|
||||||
|
MOC_DIR = build
|
||||||
|
OBJECTS_DIR = build
|
||||||
|
|
||||||
CONFIG += qt thread
|
CONFIG += qt thread
|
||||||
QT += network sql
|
QT += network sql
|
||||||
|
|
|
@ -32,10 +32,6 @@ int main(int argc, char *argv[])
|
||||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
Server server;
|
Server server;
|
||||||
if (!server.openDatabase()) {
|
|
||||||
qCritical("Database error");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
server.listen(QHostAddress::Any, 4747);
|
server.listen(QHostAddress::Any, 4747);
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include <QThread>
|
#include <QDateTime>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
void Random::init()
|
Random::Random(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
if (initialized)
|
|
||||||
return;
|
|
||||||
int seed = QDateTime::currentDateTime().toTime_t();
|
int seed = QDateTime::currentDateTime().toTime_t();
|
||||||
qDebug(QString("%1: qsrand(%2)").arg(thread()->metaObject()->className()).arg(seed).toLatin1());
|
qDebug(QString("qsrand(%1)").arg(seed).toLatin1());
|
||||||
qsrand(seed);
|
qsrand(seed);
|
||||||
initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Random::getNumber(unsigned int min, unsigned int max)
|
unsigned int Random::getNumber(unsigned int min, unsigned int max)
|
||||||
|
|
|
@ -2,16 +2,11 @@
|
||||||
#define RANDOM_H
|
#define RANDOM_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDateTime>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
class Random : public QObject {
|
class Random : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
|
||||||
bool initialized;
|
|
||||||
public:
|
public:
|
||||||
Random(QObject *parent) : QObject(parent), initialized(false) { }
|
Random(QObject *parent = 0);
|
||||||
void init();
|
|
||||||
unsigned int getNumber(unsigned int min, unsigned int max);
|
unsigned int getNumber(unsigned int min, unsigned int max);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,10 @@ Server::Server(QObject *parent)
|
||||||
: QTcpServer(parent), nextGameId(0)
|
: QTcpServer(parent), nextGameId(0)
|
||||||
{
|
{
|
||||||
settings = new QSettings("servatrice.ini", QSettings::IniFormat, this);
|
settings = new QSettings("servatrice.ini", QSettings::IniFormat, this);
|
||||||
|
|
||||||
|
QString dbType = settings->value("database/type").toString();
|
||||||
|
if (dbType == "mysql")
|
||||||
|
openDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::~Server()
|
Server::~Server()
|
||||||
|
@ -81,21 +85,27 @@ void Server::incomingConnection(int socketId)
|
||||||
|
|
||||||
AuthenticationResult Server::checkUserPassword(const QString &user, const QString &password)
|
AuthenticationResult Server::checkUserPassword(const QString &user, const QString &password)
|
||||||
{
|
{
|
||||||
if (!QSqlDatabase::database().exec("select 1").isActive())
|
const QString method = settings->value("authentication/method").toString();
|
||||||
openDatabase();
|
if (method == "none")
|
||||||
|
return UnknownUser;
|
||||||
QSqlQuery query;
|
else if (method == "sql") {
|
||||||
query.prepare("select password from players where name = :name");
|
if (!QSqlDatabase::database().exec("select 1").isActive())
|
||||||
query.bindValue(":name", user);
|
openDatabase();
|
||||||
if (!query.exec()) {
|
|
||||||
qCritical(QString("Database error: %1").arg(query.lastError().text()).toLatin1());
|
QSqlQuery query;
|
||||||
return PasswordWrong;
|
query.prepare("select password from players where name = :name");
|
||||||
}
|
query.bindValue(":name", user);
|
||||||
if (query.next()) {
|
if (!query.exec()) {
|
||||||
if (query.value(0).toString() == password)
|
qCritical(QString("Database error: %1").arg(query.lastError().text()).toLatin1());
|
||||||
return PasswordRight;
|
|
||||||
else
|
|
||||||
return PasswordWrong;
|
return PasswordWrong;
|
||||||
|
}
|
||||||
|
if (query.next()) {
|
||||||
|
if (query.value(0).toString() == password)
|
||||||
|
return PasswordRight;
|
||||||
|
else
|
||||||
|
return PasswordWrong;
|
||||||
|
} else
|
||||||
|
return UnknownUser;
|
||||||
} else
|
} else
|
||||||
return UnknownUser;
|
return UnknownUser;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue