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