Commit 07706262 authored by sylvanbasilisk's avatar sylvanbasilisk
Browse files

Merge branch 'master' into editor-redesign

Conflicts:
	cockatrice/src/carddatabasemodel.cpp
	cockatrice/src/carddatabasemodel.h
	cockatrice/src/decklistmodel.cpp
	cockatrice/src/decklistmodel.h
	cockatrice/src/tab_deck_editor.cpp
	cockatrice/src/tab_deck_editor.h
parents 748aac7e ed5f02bf
...@@ -28,7 +28,6 @@ Note that "improve" and "write" always also means: "document and comment" ...@@ -28,7 +28,6 @@ Note that "improve" and "write" always also means: "document and comment"
* Rename the picture filenames to something more meaningful. * Rename the picture filenames to something more meaningful.
* Create an index, lists of tables/figures/... * Create an index, lists of tables/figures/...
## Storage ## Storage
* Find a better place for sets.xml than doc. * Find a better place for sets.xml than doc.
...@@ -41,24 +40,6 @@ Note that "improve" and "write" always also means: "document and comment" ...@@ -41,24 +40,6 @@ Note that "improve" and "write" always also means: "document and comment"
* Document everything!1!! * Document everything!1!!
* Coding guidelines * Coding guidelines
##Fix compile warnings
* (CMAKE_VERBOSE_MAKEFILE, compile with clang++), this could indicate missing program functionality:
```
cockatrice/src/abstractclient.cpp:72:12: warning: enumeration value 'SessionEvent_SessionEventType_SERVER_COMPLETE_LIST' not handled in switch [-Wswitch]
switch ((SessionEvent::SessionEventType) getPbExtension(event)) {
```
```
cockatrice/Cockatrice.VanNostrand/cockatrice/src/player.cpp:1725:12: warning: 4 enumeration values not handled in switch: 'cmMoveToTopLibrary', 'cmMoveToBottomLibrary', 'cmMoveToGraveyard'... [-Wswitch]
switch (static_cast<CardMenuActionType>(a->data().toInt())) {
```
```
cockatrice/src/cardzone.cpp:127:11: warning: enumeration values 'CaseTopCardsOfZone', 'CaseRevealZone', and 'CaseShuffleZone' not handled in switch [-Wswitch]
switch (gc) {
```
##Else ##Else
* Update SFMT library (http://www.math.sci.hiroshima-u.ac.jp/~m-mat@math.sci.hiroshima-u.ac.jp/MT/SFMT/) in common/sfmt and adapt common/rng_sfmt.cpp * Update SFMT library (http://www.math.sci.hiroshima-u.ac.jp/~m-mat@math.sci.hiroshima-u.ac.jp/MT/SFMT/) in common/sfmt and adapt common/rng_sfmt.cpp
......
...@@ -5,47 +5,47 @@ ...@@ -5,47 +5,47 @@
#include <QDebug> #include <QDebug>
AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag) AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
: QGraphicsItem(), item(_item), hotSpot(_hotSpot) : QGraphicsItem(), item(_item), hotSpot(_hotSpot)
{ {
if (parentDrag) { if (parentDrag) {
parentDrag->addChildDrag(this); parentDrag->addChildDrag(this);
setZValue(2000000007 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000); setZValue(2000000007 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
} else { } else {
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) { if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y(); qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
hotSpot = QPointF(); hotSpot = QPointF();
} else if ((hotSpot.x() > CARD_WIDTH) || (hotSpot.y() > CARD_HEIGHT)) { } else if ((hotSpot.x() > CARD_WIDTH) || (hotSpot.y() > CARD_HEIGHT)) {
qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y(); qDebug() << "CardDragItem: coordinate overflow: x =" << hotSpot.x() << ", y =" << hotSpot.y();
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT); hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
} }
setCursor(Qt::ClosedHandCursor); setCursor(Qt::ClosedHandCursor);
setZValue(2000000007); setZValue(2000000007);
} }
if (item->getTapped()) if (item->getTapped())
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2)); setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
} }
AbstractCardDragItem::~AbstractCardDragItem() AbstractCardDragItem::~AbstractCardDragItem()
{ {
qDebug("CardDragItem destructor"); qDebug("CardDragItem destructor");
for (int i = 0; i < childDrags.size(); i++) for (int i = 0; i < childDrags.size(); i++)
delete childDrags[i]; delete childDrags[i];
} }
void AbstractCardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void AbstractCardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
item->paint(painter, option, widget); item->paint(painter, option, widget);
} }
void AbstractCardDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void AbstractCardDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
event->accept(); event->accept();
updatePosition(event->scenePos()); updatePosition(event->scenePos());
} }
void AbstractCardDragItem::addChildDrag(AbstractCardDragItem *child) void AbstractCardDragItem::addChildDrag(AbstractCardDragItem *child)
{ {
childDrags << child; childDrags << child;
} }
...@@ -8,24 +8,24 @@ class CardZone; ...@@ -8,24 +8,24 @@ class CardZone;
class CardInfo; class CardInfo;
class AbstractCardDragItem : public QObject, public QGraphicsItem { class AbstractCardDragItem : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
protected: protected:
AbstractCardItem *item; AbstractCardItem *item;
QPointF hotSpot; QPointF hotSpot;
QList<AbstractCardDragItem *> childDrags; QList<AbstractCardDragItem *> childDrags;
public: public:
enum { Type = typeCardDrag }; enum { Type = typeCardDrag };
int type() const { return Type; } int type() const { return Type; }
AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0); AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
~AbstractCardDragItem(); ~AbstractCardDragItem();
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); } QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
AbstractCardItem *getItem() const { return item; } AbstractCardItem *getItem() const { return item; }
QPointF getHotSpot() const { return hotSpot; } QPointF getHotSpot() const { return hotSpot; }
void addChildDrag(AbstractCardDragItem *child); void addChildDrag(AbstractCardDragItem *child);
virtual void updatePosition(const QPointF &cursorScenePos) = 0; virtual void updatePosition(const QPointF &cursorScenePos) = 0;
protected: protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
}; };
#endif #endif
...@@ -12,245 +12,245 @@ ...@@ -12,245 +12,245 @@
#include <QDebug> #include <QDebug>
AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent) AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, int _id, QGraphicsItem *parent)
: ArrowTarget(_owner, parent), infoWidget(0), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0), isHovered(false), realZValue(0) : ArrowTarget(_owner, parent), infoWidget(0), id(_id), name(_name), tapped(false), facedown(false), tapAngle(0), isHovered(false), realZValue(0)
{ {
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
setFlag(ItemIsSelectable); setFlag(ItemIsSelectable);
setCacheMode(DeviceCoordinateCache); setCacheMode(DeviceCoordinateCache);
connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated())); connect(db, SIGNAL(cardListChanged()), this, SLOT(cardInfoUpdated()));
connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate())); connect(settingsCache, SIGNAL(displayCardNamesChanged()), this, SLOT(callUpdate()));
cardInfoUpdated(); cardInfoUpdated();
} }
AbstractCardItem::~AbstractCardItem() AbstractCardItem::~AbstractCardItem()
{ {
emit deleteCardInfoPopup(name); emit deleteCardInfoPopup(name);
} }
QRectF AbstractCardItem::boundingRect() const QRectF AbstractCardItem::boundingRect() const
{ {
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
} }
void AbstractCardItem::pixmapUpdated() void AbstractCardItem::pixmapUpdated()
{ {
update(); update();
emit sigPixmapUpdated(); emit sigPixmapUpdated();
} }
void AbstractCardItem::cardInfoUpdated() void AbstractCardItem::cardInfoUpdated()
{ {
info = db->getCard(name); info = db->getCard(name);
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated())); connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
} }
void AbstractCardItem::setRealZValue(qreal _zValue) void AbstractCardItem::setRealZValue(qreal _zValue)
{ {
realZValue = _zValue; realZValue = _zValue;
setZValue(_zValue); setZValue(_zValue);
} }
QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const QSizeF AbstractCardItem::getTranslatedSize(QPainter *painter) const
{ {
return QSizeF( return QSizeF(
painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(), painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(),
painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length() painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length()
); );
} }
void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle) void AbstractCardItem::transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle)
{ {
QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect()); QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect());
painter->resetTransform(); painter->resetTransform();
QTransform pixmapTransform; QTransform pixmapTransform;
pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2); pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2);
pixmapTransform.rotate(angle); pixmapTransform.rotate(angle);
pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2); pixmapTransform.translate(-translatedSize.width() / 2, -translatedSize.height() / 2);
painter->setTransform(pixmapTransform); painter->setTransform(pixmapTransform);
QFont f; QFont f;
int fontSize = round(translatedSize.height() / 8); int fontSize = round(translatedSize.height() / 8);
if (fontSize < 9) if (fontSize < 9)
fontSize = 9; fontSize = 9;
if (fontSize > 10) if (fontSize > 10)
fontSize = 10; fontSize = 10;
f.setPixelSize(fontSize); f.setPixelSize(fontSize);
painter->setFont(f); painter->setFont(f);
} }
void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle) void AbstractCardItem::paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle)
{ {
qreal scaleFactor = translatedSize.width() / boundingRect().width(); qreal scaleFactor = translatedSize.width() / boundingRect().width();
CardInfo *imageSource = facedown ? db->getCard() : info; CardInfo *imageSource = facedown ? db->getCard() : info;
QPixmap *translatedPixmap = imageSource->getPixmap(translatedSize.toSize()); QPixmap *translatedPixmap = imageSource->getPixmap(translatedSize.toSize());
painter->save(); painter->save();
QColor bgColor = Qt::transparent; QColor bgColor = Qt::transparent;
if (translatedPixmap) { if (translatedPixmap) {
painter->save(); painter->save();
transformPainter(painter, translatedSize, angle); transformPainter(painter, translatedSize, angle);
painter->drawPixmap(QPointF(0, 0), *translatedPixmap); painter->drawPixmap(QPointF(0, 0), *translatedPixmap);
painter->restore(); painter->restore();
} else { } else {
QString colorStr; QString colorStr;
if (!color.isEmpty()) if (!color.isEmpty())
colorStr = color; colorStr = color;
else if (info->getColors().size() > 1) else if (info->getColors().size() > 1)
colorStr = "m"; colorStr = "m";
else if (!info->getColors().isEmpty()) else if (!info->getColors().isEmpty())
colorStr = info->getColors().first().toLower(); colorStr = info->getColors().first().toLower();
if (colorStr == "b") if (colorStr == "b")
bgColor = QColor(0, 0, 0); bgColor = QColor(0, 0, 0);
else if (colorStr == "u") else if (colorStr == "u")
bgColor = QColor(0, 140, 180); bgColor = QColor(0, 140, 180);
else if (colorStr == "w") else if (colorStr == "w")
bgColor = QColor(255, 250, 140); bgColor = QColor(255, 250, 140);
else if (colorStr == "r") else if (colorStr == "r")
bgColor = QColor(230, 0, 0); bgColor = QColor(230, 0, 0);
else if (colorStr == "g") else if (colorStr == "g")
bgColor = QColor(0, 160, 0); bgColor = QColor(0, 160, 0);
else if (colorStr == "m") else if (colorStr == "m")
bgColor = QColor(250, 190, 30); bgColor = QColor(250, 190, 30);
else else
bgColor = QColor(230, 230, 230); bgColor = QColor(230, 230, 230);
} }
painter->setBrush(bgColor); painter->setBrush(bgColor);
QPen pen(Qt::black); QPen pen(Qt::black);
pen.setWidth(2); pen.setWidth(2);
painter->setPen(pen); painter->setPen(pen);
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2)); painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
if (!translatedPixmap || settingsCache->getDisplayCardNames() || facedown) { if (!translatedPixmap || settingsCache->getDisplayCardNames() || facedown) {
painter->save(); painter->save();
transformPainter(painter, translatedSize, angle); transformPainter(painter, translatedSize, angle);
painter->setPen(Qt::white); painter->setPen(Qt::white);
painter->setBackground(Qt::black); painter->setBackground(Qt::black);
painter->setBackgroundMode(Qt::OpaqueMode); painter->setBackgroundMode(Qt::OpaqueMode);
QString nameStr; QString nameStr;
if (facedown) if (facedown)
nameStr = "# " + QString::number(id); nameStr = "# " + QString::number(id);
else else
nameStr = name; nameStr = name;
painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor, translatedSize.height() - 6 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, nameStr); painter->drawText(QRectF(3 * scaleFactor, 3 * scaleFactor, translatedSize.width() - 6 * scaleFactor, translatedSize.height() - 6 * scaleFactor), Qt::AlignTop | Qt::AlignLeft | Qt::TextWrapAnywhere, nameStr);
painter->restore(); painter->restore();
} }
painter->restore(); painter->restore();
} }
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{ {
painter->save(); painter->save();
QSizeF translatedSize = getTranslatedSize(painter); QSizeF translatedSize = getTranslatedSize(painter);
paintPicture(painter, translatedSize, tapAngle); paintPicture(painter, translatedSize, tapAngle);
painter->save(); painter->save();
painter->setRenderHint(QPainter::Antialiasing, false); painter->setRenderHint(QPainter::Antialiasing, false);
transformPainter(painter, translatedSize, tapAngle); transformPainter(painter, translatedSize, tapAngle);
if (isSelected()) { if (isSelected()) {
painter->setPen(Qt::red); painter->setPen(Qt::red);
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1)); painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
} else if (isHovered) { } else if (isHovered) {
painter->setPen(Qt::yellow); painter->setPen(Qt::yellow);
painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1)); painter->drawRect(QRectF(0.5, 0.5, translatedSize.width() - 1, translatedSize.height() - 1));
} }
painter->restore(); painter->restore();
painter->restore(); painter->restore();
} }
void AbstractCardItem::setName(const QString &_name) void AbstractCardItem::setName(const QString &_name)
{ {
if (name == _name) if (name == _name)
return; return;
emit deleteCardInfoPopup(name); emit deleteCardInfoPopup(name);
disconnect(info, 0, this, 0); disconnect(info, 0, this, 0);
name = _name; name = _name;
info = db->getCard(name); info = db->getCard(name);
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated())); connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
update(); update();
} }
void AbstractCardItem::setHovered(bool _hovered) void AbstractCardItem::setHovered(bool _hovered)
{ {
if (isHovered == _hovered) if (isHovered == _hovered)
return; return;
if (_hovered) if (_hovered)
processHoverEvent(); processHoverEvent();
isHovered = _hovered; isHovered = _hovered;
setZValue(_hovered ? 2000000004 : realZValue); setZValue(_hovered ? 2000000004 : realZValue);
update(); update();
} }
void AbstractCardItem::setColor(const QString &_color) void AbstractCardItem::setColor(const QString &_color)
{ {
color = _color; color = _color;
update(); update();
} }
void AbstractCardItem::setTapped(bool _tapped, bool canAnimate) void AbstractCardItem::setTapped(bool _tapped, bool canAnimate)
{ {
if (tapped == _tapped) if (tapped == _tapped)
return; return;
tapped = _tapped; tapped = _tapped;
if (settingsCache->getTapAnimation() && canAnimate) if (settingsCache->getTapAnimation() && canAnimate)
static_cast<GameScene *>(scene())->registerAnimationItem(this); static_cast<GameScene *>(scene())->registerAnimationItem(this);
else { else {
tapAngle = tapped ? 90 : 0; tapAngle = tapped ? 90 : 0;
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2)); setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
update(); update();
} }
} }
void AbstractCardItem::setFaceDown(bool _facedown) void AbstractCardItem::setFaceDown(bool _facedown)
{ {
facedown = _facedown; facedown = _facedown;
update(); update();
emit updateCardMenu(this); emit updateCardMenu(this);
} }
void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (!isSelected()) { if (!isSelected()) {
scene()->clearSelection(); scene()->clearSelection();
setSelected(true); setSelected(true);
} }
if (event->button() == Qt::LeftButton) if (event->button() == Qt::LeftButton)
setCursor(Qt::ClosedHandCursor); setCursor(Qt::ClosedHandCursor);
else if (event->button() == Qt::MidButton) else if (event->button() == Qt::MidButton)
emit showCardInfoPopup(event->screenPos(), name); emit showCardInfoPopup(event->screenPos(), name);
event->accept(); event->accept();
} }
void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void AbstractCardItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::MidButton) if (event->button() == Qt::MidButton)
emit deleteCardInfoPopup(name); emit deleteCardInfoPopup(name);
// This function ensures the parent function doesn't mess around with our selection. // This function ensures the parent function doesn't mess around with our selection.
event->accept(); event->accept();
} }
void AbstractCardItem::processHoverEvent() void AbstractCardItem::processHoverEvent()
{ {
emit hovered(this); emit hovered(this);
} }
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value) QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{ {
if (change == ItemSelectedHasChanged) { if (change == ItemSelectedHasChanged) {
update(); update();
return value; return value;
} else } else
return QGraphicsItem::itemChange(change, value); return QGraphicsItem::itemChange(change, value);
} }
...@@ -12,59 +12,59 @@ const int CARD_WIDTH = 72; ...@@ -12,59 +12,59 @@ const int CARD_WIDTH = 72;
const int CARD_HEIGHT = 102; const int CARD_HEIGHT = 102;
class AbstractCardItem : public ArrowTarget { class AbstractCardItem : public ArrowTarget {
Q_OBJECT Q_OBJECT
protected: protected:
CardInfo *info; CardInfo *info;
CardInfoWidget *infoWidget; CardInfoWidget *infoWidget;
int id; int id;
QString name; QString name;
bool tapped; bool tapped;
bool facedown; bool facedown;
int tapAngle; int tapAngle;
QString color; QString color;
private: private:
bool isHovered; bool isHovered;
qreal realZValue; qreal realZValue;
private slots: private slots:
void pixmapUpdated(); void pixmapUpdated();
void cardInfoUpdated(); void cardInfoUpdated();
void callUpdate() { update(); } void callUpdate() { update(); }
signals: signals:
void hovered(AbstractCardItem *card); void hovered(AbstractCardItem *card);
void showCardInfoPopup(QPoint pos, QString cardName); void showCardInfoPopup(QPoint pos, QString cardName);
void deleteCardInfoPopup(QString cardName); void deleteCardInfoPopup(QString cardName);
void updateCardMenu(AbstractCardItem *card); void updateCardMenu(AbstractCardItem *card);
void sigPixmapUpdated(); void sigPixmapUpdated();
public: public:
enum { Type = typeCard }; enum { Type = typeCard };
int type() const { return Type; } int type() const { return Type; }
AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, int _id = -1, QGraphicsItem *parent = 0); AbstractCardItem(const QString &_name = QString(), Player *_owner = 0, int _id = -1, QGraphicsItem *parent = 0);
~AbstractCardItem(); ~AbstractCardItem();
QRectF boundingRect() const; QRectF boundingRect() const;
QSizeF getTranslatedSize(QPainter *painter) const; QSizeF getTranslatedSize(QPainter *painter) const;
void paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle); void paintPicture(QPainter *painter, const QSizeF &translatedSize, int angle);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
CardInfo *getInfo() const { return info; } CardInfo *getInfo() const { return info; }
int getId() const { return id; } int getId() const { return id; }
void setId(int _id) { id = _id; } void setId(int _id) { id = _id; }
QString getName() const { return name; } QString getName() const { return name; }
void setName(const QString &_name = QString()); void setName(const QString &_name = QString());
qreal getRealZValue() const { return realZValue; } qreal getRealZValue() const { return realZValue; }
void setRealZValue(qreal _zValue); void setRealZValue(qreal _zValue);
void setHovered(bool _hovered); void setHovered(bool _hovered);
QString getColor() const { return color; } QString getColor() const { return color; }
void setColor(const QString &_color); void setColor(const QString &_color);
bool getTapped() const { return tapped; } bool getTapped() const { return tapped; }
void setTapped(bool _tapped, bool canAnimate = false); void setTapped(bool _tapped, bool canAnimate = false);
bool getFaceDown() const { return facedown; } bool getFaceDown() const { return facedown; }
void setFaceDown(bool _facedown); void setFaceDown(bool _facedown);
void processHoverEvent(); void processHoverEvent();
void deleteCardInfoPopup() { emit deleteCardInfoPopup(name); } void deleteCardInfoPopup() { emit deleteCardInfoPopup(name); }
protected: protected:
void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle); void transformPainter(QPainter *painter, const QSizeF &translatedSize, int angle);
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
}; };
#endif #endif
...@@ -20,31 +20,31 @@ ...@@ -20,31 +20,31 @@
#include "client_metatypes.h" #include "client_metatypes.h"
AbstractClient::AbstractClient(QObject *parent) AbstractClient::AbstractClient(QObject *parent)
: QObject(parent), nextCmdId(0), status(StatusDisconnected) : QObject(parent), nextCmdId(0), status(StatusDisconnected)
{ {
qRegisterMetaType<QVariant>("QVariant"); qRegisterMetaType<QVariant>("QVariant");
qRegisterMetaType<CommandContainer>("CommandContainer"); qRegisterMetaType<CommandContainer>("CommandContainer");
qRegisterMetaType<Response>("Response"); qRegisterMetaType<Response>("Response");
qRegisterMetaType<Response::ResponseCode>("Response::ResponseCode"); qRegisterMetaType<Response::ResponseCode>("Response::ResponseCode");
qRegisterMetaType<ClientStatus>("ClientStatus"); qRegisterMetaType<ClientStatus>("ClientStatus");
qRegisterMetaType<RoomEvent>("RoomEvent"); qRegisterMetaType<RoomEvent>("RoomEvent");
qRegisterMetaType<GameEventContainer>("GameEventContainer"); qRegisterMetaType<GameEventContainer>("GameEventContainer");
qRegisterMetaType<Event_ServerIdentification>("Event_ServerIdentification"); qRegisterMetaType<Event_ServerIdentification>("Event_ServerIdentification");
qRegisterMetaType<Event_ConnectionClosed>("Event_ConnectionClosed"); qRegisterMetaType<Event_ConnectionClosed>("Event_ConnectionClosed");
qRegisterMetaType<Event_ServerShutdown>("Event_ServerShutdown"); qRegisterMetaType<Event_ServerShutdown>("Event_ServerShutdown");
qRegisterMetaType<Event_AddToList>("Event_AddToList"); qRegisterMetaType<Event_AddToList>("Event_AddToList");
qRegisterMetaType<Event_RemoveFromList>("Event_RemoveFromList"); qRegisterMetaType<Event_RemoveFromList>("Event_RemoveFromList");
qRegisterMetaType<Event_UserJoined>("Event_UserJoined"); qRegisterMetaType<Event_UserJoined>("Event_UserJoined");
qRegisterMetaType<Event_UserLeft>("Event_UserLeft"); qRegisterMetaType<Event_UserLeft>("Event_UserLeft");
qRegisterMetaType<Event_ServerMessage>("Event_ServerMessage"); qRegisterMetaType<Event_ServerMessage>("Event_ServerMessage");
qRegisterMetaType<Event_ListRooms>("Event_ListRooms"); qRegisterMetaType<Event_ListRooms>("Event_ListRooms");
qRegisterMetaType<Event_GameJoined>("Event_GameJoined"); qRegisterMetaType<Event_GameJoined>("Event_GameJoined");
qRegisterMetaType<Event_UserMessage>("Event_UserMessage"); qRegisterMetaType<Event_UserMessage>("Event_UserMessage");
qRegisterMetaType<ServerInfo_User>("ServerInfo_User"); qRegisterMetaType<ServerInfo_User>("ServerInfo_User");
qRegisterMetaType<QList<ServerInfo_User> >("QList<ServerInfo_User>"); qRegisterMetaType<QList<ServerInfo_User> >("QList<ServerInfo_User>");
qRegisterMetaType<Event_ReplayAdded>("Event_ReplayAdded"); qRegisterMetaType<Event_ReplayAdded>("Event_ReplayAdded");
connect(this, SIGNAL(sigQueuePendingCommand(PendingCommand *)), this, SLOT(queuePendingCommand(PendingCommand *))); connect(this, SIGNAL(sigQueuePendingCommand(PendingCommand *)), this, SLOT(queuePendingCommand(PendingCommand *)));
} }
AbstractClient::~AbstractClient() AbstractClient::~AbstractClient()
...@@ -53,109 +53,110 @@ AbstractClient::~AbstractClient() ...@@ -53,109 +53,110 @@ AbstractClient::~AbstractClient()
void AbstractClient::processProtocolItem(const ServerMessage &item) void AbstractClient::processProtocolItem(const ServerMessage &item)
{ {
switch (item.message_type()) { switch (item.message_type()) {
case ServerMessage::RESPONSE: { case ServerMessage::RESPONSE: {
const Response &response = item.response(); const Response &response = item.response();
const int cmdId = response.cmd_id(); const int cmdId = response.cmd_id();
PendingCommand *pend = pendingCommands.value(cmdId, 0); PendingCommand *pend = pendingCommands.value(cmdId, 0);
if (!pend) if (!pend)
return; return;
pendingCommands.remove(cmdId); pendingCommands.remove(cmdId);
pend->processResponse(response); pend->processResponse(response);
pend->deleteLater(); pend->deleteLater();
break; break;
} }
case ServerMessage::SESSION_EVENT: { case ServerMessage::SESSION_EVENT: {
const SessionEvent &event = item.session_event(); const SessionEvent &event = item.session_event();
switch ((SessionEvent::SessionEventType) getPbExtension(event)) { switch ((SessionEvent::SessionEventType) getPbExtension(event)) {
case SessionEvent::SERVER_IDENTIFICATION: emit serverIdentificationEventReceived(event.GetExtension(Event_ServerIdentification::ext)); break; case SessionEvent::SERVER_IDENTIFICATION: emit serverIdentificationEventReceived(event.GetExtension(Event_ServerIdentification::ext)); break;
case SessionEvent::SERVER_MESSAGE: emit serverMessageEventReceived(event.GetExtension(Event_ServerMessage::ext)); break; case SessionEvent::SERVER_MESSAGE: emit serverMessageEventReceived(event.GetExtension(Event_ServerMessage::ext)); break;
case SessionEvent::SERVER_SHUTDOWN: emit serverShutdownEventReceived(event.GetExtension(Event_ServerShutdown::ext)); break; case SessionEvent::SERVER_SHUTDOWN: emit serverShutdownEventReceived(event.GetExtension(Event_ServerShutdown::ext)); break;
case SessionEvent::CONNECTION_CLOSED: emit connectionClosedEventReceived(event.GetExtension(Event_ConnectionClosed::ext)); break; case SessionEvent::CONNECTION_CLOSED: emit connectionClosedEventReceived(event.GetExtension(Event_ConnectionClosed::ext)); break;
case SessionEvent::USER_MESSAGE: emit userMessageEventReceived(event.GetExtension(Event_UserMessage::ext)); break; case SessionEvent::USER_MESSAGE: emit userMessageEventReceived(event.GetExtension(Event_UserMessage::ext)); break;
case SessionEvent::LIST_ROOMS: emit listRoomsEventReceived(event.GetExtension(Event_ListRooms::ext)); break; case SessionEvent::LIST_ROOMS: emit listRoomsEventReceived(event.GetExtension(Event_ListRooms::ext)); break;
case SessionEvent::ADD_TO_LIST: emit addToListEventReceived(event.GetExtension(Event_AddToList::ext)); break; case SessionEvent::ADD_TO_LIST: emit addToListEventReceived(event.GetExtension(Event_AddToList::ext)); break;
case SessionEvent::REMOVE_FROM_LIST: emit removeFromListEventReceived(event.GetExtension(Event_RemoveFromList::ext)); break; case SessionEvent::REMOVE_FROM_LIST: emit removeFromListEventReceived(event.GetExtension(Event_RemoveFromList::ext)); break;
case SessionEvent::USER_JOINED: emit userJoinedEventReceived(event.GetExtension(Event_UserJoined::ext)); break; case SessionEvent::USER_JOINED: emit userJoinedEventReceived(event.GetExtension(Event_UserJoined::ext)); break;
case SessionEvent::USER_LEFT: emit userLeftEventReceived(event.GetExtension(Event_UserLeft::ext)); break; case SessionEvent::USER_LEFT: emit userLeftEventReceived(event.GetExtension(Event_UserLeft::ext)); break;
case SessionEvent::GAME_JOINED: emit gameJoinedEventReceived(event.GetExtension(Event_GameJoined::ext)); break; case SessionEvent::GAME_JOINED: emit gameJoinedEventReceived(event.GetExtension(Event_GameJoined::ext)); break;
case SessionEvent::REPLAY_ADDED: emit replayAddedEventReceived(event.GetExtension(Event_ReplayAdded::ext)); break; case SessionEvent::REPLAY_ADDED: emit replayAddedEventReceived(event.GetExtension(Event_ReplayAdded::ext)); break;
} default: break;
break; }
} break;
case ServerMessage::GAME_EVENT_CONTAINER: { }
emit gameEventContainerReceived(item.game_event_container()); case ServerMessage::GAME_EVENT_CONTAINER: {
break; emit gameEventContainerReceived(item.game_event_container());
} break;
case ServerMessage::ROOM_EVENT: { }
emit roomEventReceived(item.room_event()); case ServerMessage::ROOM_EVENT: {
break; emit roomEventReceived(item.room_event());
} break;
} }
}
} }
void AbstractClient::setStatus(const ClientStatus _status) void AbstractClient::setStatus(const ClientStatus _status)
{ {
QMutexLocker locker(&clientMutex); QMutexLocker locker(&clientMutex);
if (_status != status) { if (_status != status) {
status = _status; status = _status;
emit statusChanged(_status); emit statusChanged(_status);
} }
} }
void AbstractClient::sendCommand(const CommandContainer &cont) void AbstractClient::sendCommand(const CommandContainer &cont)
{ {
sendCommand(new PendingCommand(cont)); sendCommand(new PendingCommand(cont));
} }
void AbstractClient::sendCommand(PendingCommand *pend) void AbstractClient::sendCommand(PendingCommand *pend)
{ {
pend->moveToThread(thread()); pend->moveToThread(thread());
emit sigQueuePendingCommand(pend); emit sigQueuePendingCommand(pend);
} }
void AbstractClient::queuePendingCommand(PendingCommand *pend) void AbstractClient::queuePendingCommand(PendingCommand *pend)
{ {
// This function is always called from the client thread via signal/slot. // This function is always called from the client thread via signal/slot.
const int cmdId = getNewCmdId(); const int cmdId = getNewCmdId();
pend->getCommandContainer().set_cmd_id(cmdId); pend->getCommandContainer().set_cmd_id(cmdId);
pendingCommands.insert(cmdId, pend); pendingCommands.insert(cmdId, pend);
sendCommandContainer(pend->getCommandContainer()); sendCommandContainer(pend->getCommandContainer());
} }
PendingCommand *AbstractClient::prepareSessionCommand(const ::google::protobuf::Message &cmd) PendingCommand *AbstractClient::prepareSessionCommand(const ::google::protobuf::Message &cmd)
{ {
CommandContainer cont; CommandContainer cont;
SessionCommand *c = cont.add_session_command(); SessionCommand *c = cont.add_session_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
} }
PendingCommand *AbstractClient::prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId) PendingCommand *AbstractClient::prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId)
{ {
CommandContainer cont; CommandContainer cont;
RoomCommand *c = cont.add_room_command(); RoomCommand *c = cont.add_room_command();
cont.set_room_id(roomId); cont.set_room_id(roomId);
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
} }
PendingCommand *AbstractClient::prepareModeratorCommand(const ::google::protobuf::Message &cmd) PendingCommand *AbstractClient::prepareModeratorCommand(const ::google::protobuf::Message &cmd)
{ {
CommandContainer cont; CommandContainer cont;
ModeratorCommand *c = cont.add_moderator_command(); ModeratorCommand *c = cont.add_moderator_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
} }
PendingCommand *AbstractClient::prepareAdminCommand(const ::google::protobuf::Message &cmd) PendingCommand *AbstractClient::prepareAdminCommand(const ::google::protobuf::Message &cmd)
{ {
CommandContainer cont; CommandContainer cont;
AdminCommand *c = cont.add_admin_command(); AdminCommand *c = cont.add_admin_command();
c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd); c->GetReflection()->MutableMessage(c, cmd.GetDescriptor()->FindExtensionByName("ext"))->CopyFrom(cmd);
return new PendingCommand(cont); return new PendingCommand(cont);
} }
...@@ -26,67 +26,67 @@ class Event_ServerShutdown; ...@@ -26,67 +26,67 @@ class Event_ServerShutdown;
class Event_ReplayAdded; class Event_ReplayAdded;
enum ClientStatus { enum ClientStatus {
StatusDisconnected, StatusDisconnected,
StatusDisconnecting, StatusDisconnecting,
StatusConnecting, StatusConnecting,
StatusAwaitingWelcome, StatusAwaitingWelcome,
StatusLoggingIn, StatusLoggingIn,
StatusLoggedIn, StatusLoggedIn,
}; };
class AbstractClient : public QObject { class AbstractClient : public QObject {
Q_OBJECT Q_OBJECT
signals: signals:
void statusChanged(ClientStatus _status); void statusChanged(ClientStatus _status);
// Room events // Room events
void roomEventReceived(const RoomEvent &event); void roomEventReceived(const RoomEvent &event);
// Game events // Game events
void gameEventContainerReceived(const GameEventContainer &event); void gameEventContainerReceived(const GameEventContainer &event);
// Session events // Session events
void serverIdentificationEventReceived(const Event_ServerIdentification &event); void serverIdentificationEventReceived(const Event_ServerIdentification &event);
void connectionClosedEventReceived(const Event_ConnectionClosed &event); void connectionClosedEventReceived(const Event_ConnectionClosed &event);
void serverShutdownEventReceived(const Event_ServerShutdown &event); void serverShutdownEventReceived(const Event_ServerShutdown &event);
void addToListEventReceived(const Event_AddToList &event); void addToListEventReceived(const Event_AddToList &event);
void removeFromListEventReceived(const Event_RemoveFromList &event); void removeFromListEventReceived(const Event_RemoveFromList &event);
void userJoinedEventReceived(const Event_UserJoined &event); void userJoinedEventReceived(const Event_UserJoined &event);
void userLeftEventReceived(const Event_UserLeft &event); void userLeftEventReceived(const Event_UserLeft &event);
void serverMessageEventReceived(const Event_ServerMessage &event); void serverMessageEventReceived(const Event_ServerMessage &event);
void listRoomsEventReceived(const Event_ListRooms &event); void listRoomsEventReceived(const Event_ListRooms &event);
void gameJoinedEventReceived(const Event_GameJoined &event); void gameJoinedEventReceived(const Event_GameJoined &event);
void userMessageEventReceived(const Event_UserMessage &event); void userMessageEventReceived(const Event_UserMessage &event);
void userInfoChanged(const ServerInfo_User &userInfo); void userInfoChanged(const ServerInfo_User &userInfo);
void buddyListReceived(const QList<ServerInfo_User> &buddyList); void buddyListReceived(const QList<ServerInfo_User> &buddyList);
void ignoreListReceived(const QList<ServerInfo_User> &ignoreList); void ignoreListReceived(const QList<ServerInfo_User> &ignoreList);
void replayAddedEventReceived(const Event_ReplayAdded &event); void replayAddedEventReceived(const Event_ReplayAdded &event);
void sigQueuePendingCommand(PendingCommand *pend); void sigQueuePendingCommand(PendingCommand *pend);
private: private:
int nextCmdId; int nextCmdId;
mutable QMutex clientMutex; mutable QMutex clientMutex;
ClientStatus status; ClientStatus status;
private slots: private slots:
void queuePendingCommand(PendingCommand *pend); void queuePendingCommand(PendingCommand *pend);
protected slots: protected slots:
void processProtocolItem(const ServerMessage &item); void processProtocolItem(const ServerMessage &item);
protected: protected:
QMap<int, PendingCommand *> pendingCommands; QMap<int, PendingCommand *> pendingCommands;
QString userName, password; QString userName, password;
void setStatus(ClientStatus _status); void setStatus(ClientStatus _status);
int getNewCmdId() { return nextCmdId++; } int getNewCmdId() { return nextCmdId++; }
virtual void sendCommandContainer(const CommandContainer &cont) = 0; virtual void sendCommandContainer(const CommandContainer &cont) = 0;
public: public:
AbstractClient(QObject *parent = 0); AbstractClient(QObject *parent = 0);
~AbstractClient(); ~AbstractClient();
ClientStatus getStatus() const { QMutexLocker locker(&clientMutex); return status; } ClientStatus getStatus() const { QMutexLocker locker(&clientMutex); return status; }
void sendCommand(const CommandContainer &cont); void sendCommand(const CommandContainer &cont);
void sendCommand(PendingCommand *pend); void sendCommand(PendingCommand *pend);
static PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd); static PendingCommand *prepareSessionCommand(const ::google::protobuf::Message &cmd);
static PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId); static PendingCommand *prepareRoomCommand(const ::google::protobuf::Message &cmd, int roomId);
static PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd); static PendingCommand *prepareModeratorCommand(const ::google::protobuf::Message &cmd);
static PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd); static PendingCommand *prepareAdminCommand(const ::google::protobuf::Message &cmd);
}; };
#endif #endif
...@@ -9,137 +9,137 @@ ...@@ -9,137 +9,137 @@
#include "pb/command_set_counter.pb.h" #include "pb/command_set_counter.pb.h"
AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent) AbstractCounter::AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent)
: QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea) : QGraphicsItem(parent), player(_player), id(_id), name(_name), value(_value), hovered(false), aDec(0), aInc(0), dialogSemaphore(false), deleteAfterDialog(false), shownInCounterArea(_shownInCounterArea)
{ {
setAcceptsHoverEvents(true); setAcceptsHoverEvents(true);
if (player->getLocal()) { if (player->getLocal()) {
menu = new QMenu(name); menu = new QMenu(name);
aSet = new QAction(this); aSet = new QAction(this);
connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter())); connect(aSet, SIGNAL(triggered()), this, SLOT(setCounter()));
menu->addAction(aSet); menu->addAction(aSet);
menu->addSeparator(); menu->addSeparator();
for (int i = -10; i <= 10; ++i) for (int i = -10; i <= 10; ++i)
if (i == 0) if (i == 0)
menu->addSeparator(); menu->addSeparator();
else { else {
QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this); QAction *aIncrement = new QAction(QString(i < 0 ? "%1" : "+%1").arg(i), this);
if (i == -1) if (i == -1)
aDec = aIncrement; aDec = aIncrement;
else if (i == 1) else if (i == 1)
aInc = aIncrement; aInc = aIncrement;
aIncrement->setData(i); aIncrement->setData(i);
connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter())); connect(aIncrement, SIGNAL(triggered()), this, SLOT(incrementCounter()));
menu->addAction(aIncrement); menu->addAction(aIncrement);
} }
} else } else
menu = 0; menu = 0;
retranslateUi(); retranslateUi();
} }
AbstractCounter::~AbstractCounter() AbstractCounter::~AbstractCounter()
{ {
delete menu; delete menu;
} }
void AbstractCounter::delCounter() void AbstractCounter::delCounter()
{ {
if (dialogSemaphore) if (dialogSemaphore)
deleteAfterDialog = true; deleteAfterDialog = true;
else else
deleteLater(); deleteLater();
} }
void AbstractCounter::retranslateUi() void AbstractCounter::retranslateUi()
{ {
if (menu) { if (menu) {
aSet->setText(tr("&Set counter...")); aSet->setText(tr("&Set counter..."));
} }
} }
void AbstractCounter::setShortcutsActive() void AbstractCounter::setShortcutsActive()
{ {
if (name == "life") { if (name == "life") {
aSet->setShortcut(tr("Ctrl+L")); aSet->setShortcut(tr("Ctrl+L"));
aDec->setShortcut(tr("F11")); aDec->setShortcut(tr("F11"));
aInc->setShortcut(tr("F12")); aInc->setShortcut(tr("F12"));
} }
} }
void AbstractCounter::setShortcutsInactive() void AbstractCounter::setShortcutsInactive()
{ {
if (name == "life") { if (name == "life") {
aSet->setShortcut(QKeySequence()); aSet->setShortcut(QKeySequence());
aDec->setShortcut(QKeySequence()); aDec->setShortcut(QKeySequence());
aInc->setShortcut(QKeySequence()); aInc->setShortcut(QKeySequence());
} }
} }
void AbstractCounter::setValue(int _value) void AbstractCounter::setValue(int _value)
{ {
value = _value; value = _value;
update(); update();
} }
void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event) void AbstractCounter::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (event->button() == Qt::LeftButton) { if (event->button() == Qt::LeftButton) {
Command_IncCounter cmd; Command_IncCounter cmd;
cmd.set_counter_id(id); cmd.set_counter_id(id);
cmd.set_delta(1); cmd.set_delta(1);
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
event->accept(); event->accept();
} else if (event->button() == Qt::RightButton) { } else if (event->button() == Qt::RightButton) {
Command_IncCounter cmd; Command_IncCounter cmd;
cmd.set_counter_id(id); cmd.set_counter_id(id);
cmd.set_delta(-1); cmd.set_delta(-1);
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
event->accept(); event->accept();
} else if (event->button() == Qt::MidButton) { } else if (event->button() == Qt::MidButton) {
if (menu) if (menu)
menu->exec(event->screenPos()); menu->exec(event->screenPos());
event->accept(); event->accept();
} else } else
event->ignore(); event->ignore();
} }
void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/) void AbstractCounter::hoverEnterEvent(QGraphicsSceneHoverEvent * /*event*/)
{ {
hovered = true; hovered = true;
update(); update();
} }
void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/) void AbstractCounter::hoverLeaveEvent(QGraphicsSceneHoverEvent * /*event*/)
{ {
hovered = false; hovered = false;
update(); update();
} }
void AbstractCounter::incrementCounter() void AbstractCounter::incrementCounter()
{ {
const int delta = static_cast<QAction *>(sender())->data().toInt(); const int delta = static_cast<QAction *>(sender())->data().toInt();
Command_IncCounter cmd; Command_IncCounter cmd;
cmd.set_counter_id(id); cmd.set_counter_id(id);
cmd.set_delta(delta); cmd.set_delta(delta);
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
} }
void AbstractCounter::setCounter() void AbstractCounter::setCounter()
{ {
bool ok; bool ok;
dialogSemaphore = true; dialogSemaphore = true;
int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok); int newValue = QInputDialog::getInteger(0, tr("Set counter"), tr("New value for counter '%1':").arg(name), value, -2000000000, 2000000000, 1, &ok);
if (deleteAfterDialog) { if (deleteAfterDialog) {
deleteLater(); deleteLater();
return; return;
} }
dialogSemaphore = false; dialogSemaphore = false;
if (!ok) if (!ok)
return; return;
Command_SetCounter cmd; Command_SetCounter cmd;
cmd.set_counter_id(id); cmd.set_counter_id(id);
cmd.set_value(newValue); cmd.set_value(newValue);
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
} }
...@@ -8,41 +8,41 @@ class QMenu; ...@@ -8,41 +8,41 @@ class QMenu;
class QAction; class QAction;
class AbstractCounter : public QObject, public QGraphicsItem { class AbstractCounter : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
protected: protected:
Player *player; Player *player;
int id; int id;
QString name; QString name;
int value; int value;
bool hovered; bool hovered;
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
private: private:
QAction *aSet, *aDec, *aInc; QAction *aSet, *aDec, *aInc;
QMenu *menu; QMenu *menu;
bool dialogSemaphore, deleteAfterDialog; bool dialogSemaphore, deleteAfterDialog;
bool shownInCounterArea; bool shownInCounterArea;
private slots: private slots:
void incrementCounter(); void incrementCounter();
void setCounter(); void setCounter();
public: public:
AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent = 0); AbstractCounter(Player *_player, int _id, const QString &_name, bool _shownInCounterArea, int _value, QGraphicsItem *parent = 0);
~AbstractCounter(); ~AbstractCounter();
QMenu *getMenu() const { return menu; } QMenu *getMenu() const { return menu; }
void retranslateUi(); void retranslateUi();
int getId() const { return id; } int getId() const { return id; }
QString getName() const { return name; } QString getName() const { return name; }
bool getShownInCounterArea() const { return shownInCounterArea; } bool getShownInCounterArea() const { return shownInCounterArea; }
int getValue() const { return value; } int getValue() const { return value; }
void setValue(int _value); void setValue(int _value);
void delCounter(); void delCounter();
void setShortcutsActive(); void setShortcutsActive();
void setShortcutsInactive(); void setShortcutsInactive();
}; };
#endif #endif
...@@ -3,48 +3,48 @@ ...@@ -3,48 +3,48 @@
void AbstractGraphicsItem::paintNumberEllipse(int number, int fontSize, const QColor &color, int position, int count, QPainter *painter) void AbstractGraphicsItem::paintNumberEllipse(int number, int fontSize, const QColor &color, int position, int count, QPainter *painter)
{ {
painter->save(); painter->save();
QString numStr = QString::number(number); QString numStr = QString::number(number);
QFont font("Serif"); QFont font("Serif");
font.setPixelSize(fontSize); font.setPixelSize(fontSize);
font.setWeight(QFont::Bold); font.setWeight(QFont::Bold);
QFontMetrics fm(font); QFontMetrics fm(font);
double w = fm.width(numStr) * 1.3; double w = fm.width(numStr) * 1.3;
double h = fm.height() * 1.3; double h = fm.height() * 1.3;
if (w < h) if (w < h)
w = h; w = h;
painter->setPen(QColor(255, 255, 255, 0)); painter->setPen(QColor(255, 255, 255, 0));
QRadialGradient grad(QPointF(0.5, 0.5), 0.5); QRadialGradient grad(QPointF(0.5, 0.5), 0.5);
grad.setCoordinateMode(QGradient::ObjectBoundingMode); grad.setCoordinateMode(QGradient::ObjectBoundingMode);
QColor color1(color), color2(color); QColor color1(color), color2(color);
color1.setAlpha(255); color1.setAlpha(255);
color2.setAlpha(0); color2.setAlpha(0);
grad.setColorAt(0, color1); grad.setColorAt(0, color1);
grad.setColorAt(0.8, color1); grad.setColorAt(0.8, color1);
grad.setColorAt(1, color2); grad.setColorAt(1, color2);
painter->setBrush(QBrush(grad)); painter->setBrush(QBrush(grad));
QRectF textRect; QRectF textRect;
if (position == -1) if (position == -1)
textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h); textRect = QRectF((boundingRect().width() - w) / 2.0, (boundingRect().height() - h) / 2.0, w, h);
else { else {
qreal xOffset = 10; qreal xOffset = 10;
qreal yOffset = 20; qreal yOffset = 20;
qreal spacing = 2; qreal spacing = 2;
if (position < 2) if (position < 2)
textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset, w, h); textRect = QRectF(count == 1 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset, w, h);
else else
textRect = QRectF(count == 3 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset + (spacing + h) * (position / 2), w, h); textRect = QRectF(count == 3 ? ((boundingRect().width() - w) / 2.0) : (position % 2 == 0 ? xOffset : (boundingRect().width() - xOffset - w)), yOffset + (spacing + h) * (position / 2), w, h);
} }
painter->drawEllipse(textRect); painter->drawEllipse(textRect);
painter->setPen(Qt::black); painter->setPen(Qt::black);
painter->setFont(font); painter->setFont(font);
painter->drawText(textRect, Qt::AlignCenter, numStr); painter->drawText(textRect, Qt::AlignCenter, numStr);
painter->restore(); painter->restore();
} }
...@@ -4,20 +4,20 @@ ...@@ -4,20 +4,20 @@
#include <QGraphicsItem> #include <QGraphicsItem>
enum GraphicsItemType { enum GraphicsItemType {
typeCard = QGraphicsItem::UserType + 1, typeCard = QGraphicsItem::UserType + 1,
typeCardDrag = QGraphicsItem::UserType + 2, typeCardDrag = QGraphicsItem::UserType + 2,
typeZone = QGraphicsItem::UserType + 3, typeZone = QGraphicsItem::UserType + 3,
typePlayerTarget = QGraphicsItem::UserType + 4, typePlayerTarget = QGraphicsItem::UserType + 4,
typeDeckViewCardContainer = QGraphicsItem::UserType + 5, typeDeckViewCardContainer = QGraphicsItem::UserType + 5,
typeOther = QGraphicsItem::UserType + 6 typeOther = QGraphicsItem::UserType + 6
}; };
class AbstractGraphicsItem : public QObject, public QGraphicsItem { class AbstractGraphicsItem : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
protected: protected:
void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter); void paintNumberEllipse(int number, int radius, const QColor &color, int position, int count, QPainter *painter);
public: public:
AbstractGraphicsItem(QGraphicsItem *parent = 0) : QObject(), QGraphicsItem(parent) { } AbstractGraphicsItem(QGraphicsItem *parent = 0) : QObject(), QGraphicsItem(parent) { }
}; };
#endif #endif
...@@ -17,127 +17,127 @@ ...@@ -17,127 +17,127 @@
ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color) ArrowItem::ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &_color)
: QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true) : QGraphicsItem(), player(_player), id(_id), startItem(_startItem), targetItem(_targetItem), color(_color), fullColor(true)
{ {
qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem); qDebug() << "ArrowItem constructor: startItem=" << static_cast<QGraphicsItem *>(startItem);
setZValue(2000000005); setZValue(2000000005);
if (startItem) if (startItem)
startItem->addArrowFrom(this); startItem->addArrowFrom(this);
if (targetItem) if (targetItem)
targetItem->addArrowTo(this); targetItem->addArrowTo(this);
if (startItem && targetItem) if (startItem && targetItem)
updatePath(); updatePath();
} }
ArrowItem::~ArrowItem() ArrowItem::~ArrowItem()
{ {
qDebug() << "ArrowItem destructor"; qDebug() << "ArrowItem destructor";
} }
void ArrowItem::delArrow() void ArrowItem::delArrow()
{ {
if (startItem) { if (startItem) {
startItem->removeArrowFrom(this); startItem->removeArrowFrom(this);
startItem = 0; startItem = 0;
} }
if (targetItem) { if (targetItem) {
targetItem->setBeingPointedAt(false); targetItem->setBeingPointedAt(false);
targetItem->removeArrowTo(this); targetItem->removeArrowTo(this);
targetItem = 0; targetItem = 0;
} }
player->removeArrow(this); player->removeArrow(this);
deleteLater(); deleteLater();
} }
void ArrowItem::updatePath() void ArrowItem::updatePath()
{ {
if (!targetItem) if (!targetItem)
return; return;
QPointF endPoint = targetItem->mapToScene(QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2)); QPointF endPoint = targetItem->mapToScene(QPointF(targetItem->boundingRect().width() / 2, targetItem->boundingRect().height() / 2));
updatePath(endPoint); updatePath(endPoint);
} }
void ArrowItem::updatePath(const QPointF &endPoint) void ArrowItem::updatePath(const QPointF &endPoint)
{ {
const double arrowWidth = 15.0; const double arrowWidth = 15.0;
const double headWidth = 40.0; const double headWidth = 40.0;
const double headLength = headWidth / sqrt(2); const double headLength = headWidth / sqrt(2);
const double phi = 15; const double phi = 15;
if (!startItem) if (!startItem)
return; return;
QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2)); QPointF startPoint = startItem->mapToScene(QPointF(startItem->boundingRect().width() / 2, startItem->boundingRect().height() / 2));
QLineF line(startPoint, endPoint); QLineF line(startPoint, endPoint);
qreal lineLength = line.length(); qreal lineLength = line.length();
prepareGeometryChange(); prepareGeometryChange();
if (lineLength < 30) if (lineLength < 30)
path = QPainterPath(); path = QPainterPath();
else { else {
QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength); QPointF c(lineLength / 2, tan(phi * M_PI / 180) * lineLength);
QPainterPath centerLine; QPainterPath centerLine;
centerLine.moveTo(0, 0); centerLine.moveTo(0, 0);
centerLine.quadTo(c, QPointF(lineLength, 0)); centerLine.quadTo(c, QPointF(lineLength, 0));
double percentage = 1 - headLength / lineLength; double percentage = 1 - headLength / lineLength;
QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage); QPointF arrowBodyEndPoint = centerLine.pointAtPercent(percentage);
QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001)); QLineF testLine(arrowBodyEndPoint, centerLine.pointAtPercent(percentage + 0.001));
qreal alpha = testLine.angle() - 90; qreal alpha = testLine.angle() - 90;
QPointF endPoint1 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180)); QPointF endPoint1 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
QPointF endPoint2 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180)); QPointF endPoint2 = arrowBodyEndPoint + arrowWidth / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
QPointF point1 = endPoint1 + (headWidth - arrowWidth) / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180)); QPointF point1 = endPoint1 + (headWidth - arrowWidth) / 2 * QPointF(cos(alpha * M_PI / 180), -sin(alpha * M_PI / 180));
QPointF point2 = endPoint2 + (headWidth - arrowWidth) / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180)); QPointF point2 = endPoint2 + (headWidth - arrowWidth) / 2 * QPointF(-cos(alpha * M_PI / 180), sin(alpha * M_PI / 180));
path = QPainterPath(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180))); path = QPainterPath(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
path.quadTo(c, endPoint1); path.quadTo(c, endPoint1);
path.lineTo(point1); path.lineTo(point1);
path.lineTo(QPointF(lineLength, 0)); path.lineTo(QPointF(lineLength, 0));
path.lineTo(point2); path.lineTo(point2);
path.lineTo(endPoint2); path.lineTo(endPoint2);
path.quadTo(c, arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180))); path.quadTo(c, arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
path.lineTo(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180))); path.lineTo(-arrowWidth / 2 * QPointF(cos((phi - 90) * M_PI / 180), sin((phi - 90) * M_PI / 180)));
} }
setPos(startPoint); setPos(startPoint);
setTransform(QTransform().rotate(-line.angle())); setTransform(QTransform().rotate(-line.angle()));
} }
void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) void ArrowItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
{ {
QColor paintColor(color); QColor paintColor(color);
if (fullColor) if (fullColor)
paintColor.setAlpha(200); paintColor.setAlpha(200);
else else
paintColor.setAlpha(150); paintColor.setAlpha(150);
painter->setBrush(paintColor); painter->setBrush(paintColor);
painter->drawPath(path); painter->drawPath(path);
} }
void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void ArrowItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{ {
if (!player->getLocal()) { if (!player->getLocal()) {
event->ignore(); event->ignore();
return; return;
} }
QList<QGraphicsItem *> colliding = scene()->items(event->scenePos()); QList<QGraphicsItem *> colliding = scene()->items(event->scenePos());
for (int i = 0; i < colliding.size(); ++i) for (int i = 0; i < colliding.size(); ++i)
if (qgraphicsitem_cast<CardItem *>(colliding[i])) { if (qgraphicsitem_cast<CardItem *>(colliding[i])) {
event->ignore(); event->ignore();
return; return;
} }
event->accept(); event->accept();
if (event->button() == Qt::RightButton) { if (event->button() == Qt::RightButton) {
Command_DeleteArrow cmd; Command_DeleteArrow cmd;
cmd.set_arrow_id(id); cmd.set_arrow_id(id);
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
} }
} }
ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color) ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color)
...@@ -147,85 +147,85 @@ ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QCol ...@@ -147,85 +147,85 @@ ArrowDragItem::ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QCol
void ArrowDragItem::addChildArrow(ArrowDragItem *childArrow) void ArrowDragItem::addChildArrow(ArrowDragItem *childArrow)
{ {
childArrows.append(childArrow); childArrows.append(childArrow);
} }
void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void ArrowDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
// This ensures that if a mouse move event happens after a call to delArrow(), // This ensures that if a mouse move event happens after a call to delArrow(),
// the event will be discarded as it would create some stray pointers. // the event will be discarded as it would create some stray pointers.
if (!startItem) if (!startItem)
return; return;
QPointF endPos = event->scenePos(); QPointF endPos = event->scenePos();
QList<QGraphicsItem *> colliding = scene()->items(endPos); QList<QGraphicsItem *> colliding = scene()->items(endPos);
ArrowTarget *cursorItem = 0; ArrowTarget *cursorItem = 0;
qreal cursorItemZ = -1; qreal cursorItemZ = -1;
for (int i = colliding.size() - 1; i >= 0; i--) for (int i = colliding.size() - 1; i >= 0; i--)
if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i))) if (qgraphicsitem_cast<PlayerTarget *>(colliding.at(i)) || qgraphicsitem_cast<CardItem *>(colliding.at(i)))
if (colliding.at(i)->zValue() > cursorItemZ) { if (colliding.at(i)->zValue() > cursorItemZ) {
cursorItem = static_cast<ArrowTarget *>(colliding.at(i)); cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
cursorItemZ = cursorItem->zValue(); cursorItemZ = cursorItem->zValue();
} }
if ((cursorItem != targetItem) && targetItem) { if ((cursorItem != targetItem) && targetItem) {
targetItem->setBeingPointedAt(false); targetItem->setBeingPointedAt(false);
targetItem->removeArrowTo(this); targetItem->removeArrowTo(this);
} }
if (!cursorItem) { if (!cursorItem) {
fullColor = false; fullColor = false;
targetItem = 0; targetItem = 0;
updatePath(endPos); updatePath(endPos);
} else { } else {
if (cursorItem != targetItem) { if (cursorItem != targetItem) {
fullColor = true; fullColor = true;
if (cursorItem != startItem) { if (cursorItem != startItem) {
cursorItem->setBeingPointedAt(true); cursorItem->setBeingPointedAt(true);
cursorItem->addArrowTo(this); cursorItem->addArrowTo(this);
} }
targetItem = cursorItem; targetItem = cursorItem;
} }
updatePath(); updatePath();
} }
update(); update();
for (int i = 0; i < childArrows.size(); ++i) for (int i = 0; i < childArrows.size(); ++i)
childArrows[i]->mouseMoveEvent(event); childArrows[i]->mouseMoveEvent(event);
} }
void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void ArrowDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
if (!startItem) if (!startItem)
return; return;
if (targetItem && (targetItem != startItem)) { if (targetItem && (targetItem != startItem)) {
CardZone *startZone = static_cast<CardItem *>(startItem)->getZone(); CardZone *startZone = static_cast<CardItem *>(startItem)->getZone();
// For now, we can safely assume that the start item is always a card. // For now, we can safely assume that the start item is always a card.
// The target item can be a player as well. // The target item can be a player as well.
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem); CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem); CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
Command_CreateArrow cmd; Command_CreateArrow cmd;
cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(color)); cmd.mutable_arrow_color()->CopyFrom(convertQColorToColor(color));
cmd.set_start_player_id(startZone->getPlayer()->getId()); cmd.set_start_player_id(startZone->getPlayer()->getId());
cmd.set_start_zone(startZone->getName().toStdString()); cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_start_card_id(startCard->getId()); cmd.set_start_card_id(startCard->getId());
if (targetCard) { if (targetCard) {
CardZone *targetZone = targetCard->getZone(); CardZone *targetZone = targetCard->getZone();
cmd.set_target_player_id(targetZone->getPlayer()->getId()); cmd.set_target_player_id(targetZone->getPlayer()->getId());
cmd.set_target_zone(targetZone->getName().toStdString()); cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId()); cmd.set_target_card_id(targetCard->getId());
} else { } else {
PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem); PlayerTarget *targetPlayer = qgraphicsitem_cast<PlayerTarget *>(targetItem);
cmd.set_target_player_id(targetPlayer->getOwner()->getId()); cmd.set_target_player_id(targetPlayer->getOwner()->getId());
} }
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
} }
delArrow(); delArrow();
for (int i = 0; i < childArrows.size(); ++i) for (int i = 0; i < childArrows.size(); ++i)
childArrows[i]->mouseReleaseEvent(event); childArrows[i]->mouseReleaseEvent(event);
} }
ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem) ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem)
...@@ -235,57 +235,57 @@ ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem) ...@@ -235,57 +235,57 @@ ArrowAttachItem::ArrowAttachItem(ArrowTarget *_startItem)
void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void ArrowAttachItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{ {
if (!startItem) if (!startItem)
return; return;
QPointF endPos = event->scenePos(); QPointF endPos = event->scenePos();
QList<QGraphicsItem *> colliding = scene()->items(endPos); QList<QGraphicsItem *> colliding = scene()->items(endPos);
ArrowTarget *cursorItem = 0; ArrowTarget *cursorItem = 0;
qreal cursorItemZ = -1; qreal cursorItemZ = -1;
for (int i = colliding.size() - 1; i >= 0; i--) for (int i = colliding.size() - 1; i >= 0; i--)
if (qgraphicsitem_cast<CardItem *>(colliding.at(i))) if (qgraphicsitem_cast<CardItem *>(colliding.at(i)))
if (colliding.at(i)->zValue() > cursorItemZ) { if (colliding.at(i)->zValue() > cursorItemZ) {
cursorItem = static_cast<ArrowTarget *>(colliding.at(i)); cursorItem = static_cast<ArrowTarget *>(colliding.at(i));
cursorItemZ = cursorItem->zValue(); cursorItemZ = cursorItem->zValue();
} }
if ((cursorItem != targetItem) && targetItem) if ((cursorItem != targetItem) && targetItem)
targetItem->setBeingPointedAt(false); targetItem->setBeingPointedAt(false);
if (!cursorItem) { if (!cursorItem) {
fullColor = false; fullColor = false;
targetItem = 0; targetItem = 0;
updatePath(endPos); updatePath(endPos);
} else { } else {
fullColor = true; fullColor = true;
if (cursorItem != startItem) if (cursorItem != startItem)
cursorItem->setBeingPointedAt(true); cursorItem->setBeingPointedAt(true);
targetItem = cursorItem; targetItem = cursorItem;
updatePath(); updatePath();
} }
update(); update();
} }
void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/) void ArrowAttachItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * /*event*/)
{ {
if (!startItem) if (!startItem)
return; return;
if (targetItem && (targetItem != startItem)) { if (targetItem && (targetItem != startItem)) {
CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem); CardItem *startCard = qgraphicsitem_cast<CardItem *>(startItem);
CardZone *startZone = startCard->getZone(); CardZone *startZone = startCard->getZone();
CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem); CardItem *targetCard = qgraphicsitem_cast<CardItem *>(targetItem);
CardZone *targetZone = targetCard->getZone(); CardZone *targetZone = targetCard->getZone();
Command_AttachCard cmd; Command_AttachCard cmd;
cmd.set_start_zone(startZone->getName().toStdString()); cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_card_id(startCard->getId()); cmd.set_card_id(startCard->getId());
cmd.set_target_player_id(targetZone->getPlayer()->getId()); cmd.set_target_player_id(targetZone->getPlayer()->getId());
cmd.set_target_zone(targetZone->getName().toStdString()); cmd.set_target_zone(targetZone->getName().toStdString());
cmd.set_target_card_id(targetCard->getId()); cmd.set_target_card_id(targetCard->getId());
player->sendGameCommand(cmd); player->sendGameCommand(cmd);
} }
delArrow(); delArrow();
} }
...@@ -10,54 +10,54 @@ class Player; ...@@ -10,54 +10,54 @@ class Player;
class ArrowTarget; class ArrowTarget;
class ArrowItem : public QObject, public QGraphicsItem { class ArrowItem : public QObject, public QGraphicsItem {
Q_OBJECT Q_OBJECT
private: private:
QPainterPath path; QPainterPath path;
QMenu *menu; QMenu *menu;
protected: protected:
Player *player; Player *player;
int id; int id;
ArrowTarget *startItem, *targetItem; ArrowTarget *startItem, *targetItem;
QColor color; QColor color;
bool fullColor; bool fullColor;
void mousePressEvent(QGraphicsSceneMouseEvent *event); void mousePressEvent(QGraphicsSceneMouseEvent *event);
public: public:
ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &color); ArrowItem(Player *_player, int _id, ArrowTarget *_startItem, ArrowTarget *_targetItem, const QColor &color);
~ArrowItem(); ~ArrowItem();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
QRectF boundingRect() const { return path.boundingRect(); } QRectF boundingRect() const { return path.boundingRect(); }
QPainterPath shape() const { return path; } QPainterPath shape() const { return path; }
void updatePath(); void updatePath();
void updatePath(const QPointF &endPoint); void updatePath(const QPointF &endPoint);
int getId() const { return id; } int getId() const { return id; }
Player *getPlayer() const { return player; } Player *getPlayer() const { return player; }
void setStartItem(ArrowTarget *_item) { startItem = _item; } void setStartItem(ArrowTarget *_item) { startItem = _item; }
void setTargetItem(ArrowTarget *_item) { targetItem = _item; } void setTargetItem(ArrowTarget *_item) { targetItem = _item; }
ArrowTarget *getStartItem() const { return startItem; } ArrowTarget *getStartItem() const { return startItem; }
ArrowTarget *getTargetItem() const { return targetItem; } ArrowTarget *getTargetItem() const { return targetItem; }
void delArrow(); void delArrow();
}; };
class ArrowDragItem : public ArrowItem { class ArrowDragItem : public ArrowItem {
Q_OBJECT Q_OBJECT
private: private:
QList<ArrowDragItem *> childArrows; QList<ArrowDragItem *> childArrows;
public: public:
ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color); ArrowDragItem(Player *_owner, ArrowTarget *_startItem, const QColor &_color);
void addChildArrow(ArrowDragItem *childArrow); void addChildArrow(ArrowDragItem *childArrow);
protected: protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
}; };
class ArrowAttachItem : public ArrowItem { class ArrowAttachItem : public ArrowItem {
Q_OBJECT Q_OBJECT
public: public:
ArrowAttachItem(ArrowTarget *_startItem); ArrowAttachItem(ArrowTarget *_startItem);
protected: protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event); void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
}; };
#endif // ARROWITEM_H #endif // ARROWITEM_H
...@@ -3,24 +3,24 @@ ...@@ -3,24 +3,24 @@
#include "player.h" #include "player.h"
ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent) ArrowTarget::ArrowTarget(Player *_owner, QGraphicsItem *parent)
: AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false) : AbstractGraphicsItem(parent), owner(_owner), beingPointedAt(false)
{ {
} }
ArrowTarget::~ArrowTarget() ArrowTarget::~ArrowTarget()
{ {
for (int i = 0; i < arrowsFrom.size(); ++i) { for (int i = 0; i < arrowsFrom.size(); ++i) {
arrowsFrom[i]->setStartItem(0); arrowsFrom[i]->setStartItem(0);
arrowsFrom[i]->delArrow(); arrowsFrom[i]->delArrow();
} }
for (int i = 0; i < arrowsTo.size(); ++i) { for (int i = 0; i < arrowsTo.size(); ++i) {
arrowsTo[i]->setTargetItem(0); arrowsTo[i]->setTargetItem(0);
arrowsTo[i]->delArrow(); arrowsTo[i]->delArrow();
} }
} }
void ArrowTarget::setBeingPointedAt(bool _beingPointedAt) void ArrowTarget::setBeingPointedAt(bool _beingPointedAt)
{ {
beingPointedAt = _beingPointedAt; beingPointedAt = _beingPointedAt;
update(); update();
} }
...@@ -8,28 +8,28 @@ class Player; ...@@ -8,28 +8,28 @@ class Player;
class ArrowItem; class ArrowItem;
class ArrowTarget : public AbstractGraphicsItem { class ArrowTarget : public AbstractGraphicsItem {
Q_OBJECT Q_OBJECT
protected: protected:
Player *owner; Player *owner;
private: private:
bool beingPointedAt; bool beingPointedAt;
QList<ArrowItem *> arrowsFrom, arrowsTo; QList<ArrowItem *> arrowsFrom, arrowsTo;
public: public:
ArrowTarget(Player *_owner, QGraphicsItem *parent = 0); ArrowTarget(Player *_owner, QGraphicsItem *parent = 0);
~ArrowTarget(); ~ArrowTarget();
Player *getOwner() const { return owner; } Player *getOwner() const { return owner; }
void setBeingPointedAt(bool _beingPointedAt); void setBeingPointedAt(bool _beingPointedAt);
bool getBeingPointedAt() const { return beingPointedAt; } bool getBeingPointedAt() const { return beingPointedAt; }
const QList<ArrowItem *> &getArrowsFrom() const { return arrowsFrom; } const QList<ArrowItem *> &getArrowsFrom() const { return arrowsFrom; }
void addArrowFrom(ArrowItem *arrow) { arrowsFrom.append(arrow); } void addArrowFrom(ArrowItem *arrow) { arrowsFrom.append(arrow); }
void removeArrowFrom(ArrowItem *arrow) { arrowsFrom.removeAt(arrowsFrom.indexOf(arrow)); } void removeArrowFrom(ArrowItem *arrow) { arrowsFrom.removeAt(arrowsFrom.indexOf(arrow)); }
const QList<ArrowItem *> &getArrowsTo() const { return arrowsTo; } const QList<ArrowItem *> &getArrowsTo() const { return arrowsTo; }
void addArrowTo(ArrowItem *arrow) { arrowsTo.append(arrow); } void addArrowTo(ArrowItem *arrow) { arrowsTo.append(arrow); }
void removeArrowTo(ArrowItem *arrow) { arrowsTo.removeAt(arrowsTo.indexOf(arrow)); } void removeArrowTo(ArrowItem *arrow) { arrowsTo.removeAt(arrowsTo.indexOf(arrow)); }
}; };
#endif #endif
This diff is collapsed.
...@@ -22,191 +22,191 @@ typedef QMap<QString, QString> QStringMap; ...@@ -22,191 +22,191 @@ typedef QMap<QString, QString> QStringMap;
class CardSet : public QList<CardInfo *> { class CardSet : public QList<CardInfo *> {
private: private:
QString shortName, longName; QString shortName, longName;
unsigned int sortKey; unsigned int sortKey;
public: public:
CardSet(const QString &_shortName = QString(), const QString &_longName = QString()); CardSet(const QString &_shortName = QString(), const QString &_longName = QString());
QString getShortName() const { return shortName; } QString getShortName() const { return shortName; }
QString getLongName() const { return longName; } QString getLongName() const { return longName; }
int getSortKey() const { return sortKey; } int getSortKey() const { return sortKey; }
void setSortKey(unsigned int _sortKey); void setSortKey(unsigned int _sortKey);
void updateSortKey(); void updateSortKey();
}; };
class SetList : public QList<CardSet *> { class SetList : public QList<CardSet *> {
private: private:
class CompareFunctor; class CompareFunctor;
public: public:
void sortByKey(); void sortByKey();
}; };
class PictureToLoad { class PictureToLoad {
private: private:
CardInfo *card; CardInfo *card;
bool stripped; bool stripped;
SetList sortedSets; SetList sortedSets;
int setIndex; int setIndex;
bool hq; bool hq;
public: public:
PictureToLoad(CardInfo *_card = 0, bool _stripped = false, bool _hq = true); PictureToLoad(CardInfo *_card = 0, bool _stripped = false, bool _hq = true);
CardInfo *getCard() const { return card; } CardInfo *getCard() const { return card; }
bool getStripped() const { return stripped; } bool getStripped() const { return stripped; }
QString getSetName() const { return sortedSets[setIndex]->getShortName(); } QString getSetName() const { return sortedSets[setIndex]->getShortName(); }
bool nextSet(); bool nextSet();
bool getHq() const { return hq; } bool getHq() const { return hq; }
void setHq(bool _hq) { hq = _hq; } void setHq(bool _hq) { hq = _hq; }
}; };
class PictureLoader : public QObject { class PictureLoader : public QObject {
Q_OBJECT Q_OBJECT
private: private:
QString _picsPath; QString _picsPath;
QList<PictureToLoad> loadQueue; QList<PictureToLoad> loadQueue;
QMutex mutex; QMutex mutex;
QNetworkAccessManager *networkManager; QNetworkAccessManager *networkManager;
QList<PictureToLoad> cardsToDownload; QList<PictureToLoad> cardsToDownload;
PictureToLoad cardBeingDownloaded; PictureToLoad cardBeingDownloaded;
bool picDownload, downloadRunning, loadQueueRunning; bool picDownload, downloadRunning, loadQueueRunning;
void startNextPicDownload(); void startNextPicDownload();
public: public:
PictureLoader(const QString &__picsPath, bool _picDownload, QObject *parent = 0); PictureLoader(const QString &__picsPath, bool _picDownload, QObject *parent = 0);
~PictureLoader(); ~PictureLoader();
void setPicsPath(const QString &path); void setPicsPath(const QString &path);
void setPicDownload(bool _picDownload); void setPicDownload(bool _picDownload);
void loadImage(CardInfo *card, bool stripped); void loadImage(CardInfo *card, bool stripped);
private slots: private slots:
void picDownloadFinished(QNetworkReply *reply); void picDownloadFinished(QNetworkReply *reply);
public slots: public slots:
void processLoadQueue(); void processLoadQueue();
signals: signals:
void startLoadQueue(); void startLoadQueue();
void imageLoaded(CardInfo *card, const QImage &image); void imageLoaded(CardInfo *card, const QImage &image);
}; };
class CardInfo : public QObject { class CardInfo : public QObject {
Q_OBJECT Q_OBJECT
private: private:
CardDatabase *db; CardDatabase *db;
QString name; QString name;
bool isToken; bool isToken;
SetList sets; SetList sets;
QString manacost; QString manacost;
QString cardtype; QString cardtype;
QString powtough; QString powtough;
QString text; QString text;
QStringList colors; QStringList colors;
int loyalty; int loyalty;
QMap<QString, QString> picURLs, picURLsHq, picURLsSt; QMap<QString, QString> picURLs, picURLsHq, picURLsSt;
bool cipt; bool cipt;
int tableRow; int tableRow;
QPixmap *pixmap; QPixmap *pixmap;
QMap<int, QPixmap *> scaledPixmapCache; QMap<int, QPixmap *> scaledPixmapCache;
public: public:
CardInfo(CardDatabase *_db, CardInfo(CardDatabase *_db,
const QString &_name = QString(), const QString &_name = QString(),
bool _isToken = false, bool _isToken = false,
const QString &_manacost = QString(), const QString &_manacost = QString(),
const QString &_cardtype = QString(), const QString &_cardtype = QString(),
const QString &_powtough = QString(), const QString &_powtough = QString(),
const QString &_text = QString(), const QString &_text = QString(),
const QStringList &_colors = QStringList(), const QStringList &_colors = QStringList(),
int _loyalty = 0, int _loyalty = 0,
bool _cipt = false, bool _cipt = false,
int _tableRow = 0, int _tableRow = 0,
const SetList &_sets = SetList(), const SetList &_sets = SetList(),
const QStringMap &_picURLs = QStringMap(), const QStringMap &_picURLs = QStringMap(),
const QStringMap &_picURLsHq = QStringMap(), const QStringMap &_picURLsHq = QStringMap(),
const QStringMap &_picURLsSt = QStringMap()); const QStringMap &_picURLsSt = QStringMap());
~CardInfo(); ~CardInfo();
const QString &getName() const { return name; } const QString &getName() const { return name; }
bool getIsToken() const { return isToken; } bool getIsToken() const { return isToken; }
const SetList &getSets() const { return sets; } const SetList &getSets() const { return sets; }
const QString &getManaCost() const { return manacost; } const QString &getManaCost() const { return manacost; }
const QString &getCardType() const { return cardtype; } const QString &getCardType() const { return cardtype; }
const QString &getPowTough() const { return powtough; } const QString &getPowTough() const { return powtough; }
const QString &getText() const { return text; } const QString &getText() const { return text; }
const int &getLoyalty() const { return loyalty; } const int &getLoyalty() const { return loyalty; }
bool getCipt() const { return cipt; } bool getCipt() const { return cipt; }
void setManaCost(const QString &_manaCost) { manacost = _manaCost; emit cardInfoChanged(this); } void setManaCost(const QString &_manaCost) { manacost = _manaCost; emit cardInfoChanged(this); }
void setCardType(const QString &_cardType) { cardtype = _cardType; emit cardInfoChanged(this); } void setCardType(const QString &_cardType) { cardtype = _cardType; emit cardInfoChanged(this); }
void setPowTough(const QString &_powTough) { powtough = _powTough; emit cardInfoChanged(this); } void setPowTough(const QString &_powTough) { powtough = _powTough; emit cardInfoChanged(this); }
void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); } void setText(const QString &_text) { text = _text; emit cardInfoChanged(this); }
void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); } void setColors(const QStringList &_colors) { colors = _colors; emit cardInfoChanged(this); }
const QStringList &getColors() const { return colors; } const QStringList &getColors() const { return colors; }
QString getPicURL(const QString &set) const { return picURLs.value(set); } QString getPicURL(const QString &set) const { return picURLs.value(set); }
QString getPicURLHq(const QString &set) const { return picURLsHq.value(set); } QString getPicURLHq(const QString &set) const { return picURLsHq.value(set); }
QString getPicURLSt(const QString &set) const { return picURLsSt.value(set); } QString getPicURLSt(const QString &set) const { return picURLsSt.value(set); }
QString getPicURL() const; QString getPicURL() const;
const QMap<QString, QString> &getPicURLs() const { return picURLs; } const QMap<QString, QString> &getPicURLs() const { return picURLs; }
QString getMainCardType() const; QString getMainCardType() const;
QString getCorrectedName() const; QString getCorrectedName() const;
int getTableRow() const { return tableRow; } int getTableRow() const { return tableRow; }
void setTableRow(int _tableRow) { tableRow = _tableRow; } void setTableRow(int _tableRow) { tableRow = _tableRow; }
void setLoyalty(int _loyalty) { loyalty = _loyalty; emit cardInfoChanged(this); } void setLoyalty(int _loyalty) { loyalty = _loyalty; emit cardInfoChanged(this); }
void setPicURL(const QString &_set, const QString &_picURL) { picURLs.insert(_set, _picURL); } void setPicURL(const QString &_set, const QString &_picURL) { picURLs.insert(_set, _picURL); }
void setPicURLHq(const QString &_set, const QString &_picURL) { picURLsHq.insert(_set, _picURL); } void setPicURLHq(const QString &_set, const QString &_picURL) { picURLsHq.insert(_set, _picURL); }
void setPicURLSt(const QString &_set, const QString &_picURL) { picURLsSt.insert(_set, _picURL); } void setPicURLSt(const QString &_set, const QString &_picURL) { picURLsSt.insert(_set, _picURL); }
void addToSet(CardSet *set); void addToSet(CardSet *set);
QPixmap *loadPixmap(); QPixmap *loadPixmap();
QPixmap *getPixmap(QSize size); QPixmap *getPixmap(QSize size);
void clearPixmapCache(); void clearPixmapCache();
void clearPixmapCacheMiss(); void clearPixmapCacheMiss();
void imageLoaded(const QImage &image); void imageLoaded(const QImage &image);
public slots: public slots:
void updatePixmapCache(); void updatePixmapCache();
signals: signals:
void pixmapUpdated(); void pixmapUpdated();
void cardInfoChanged(CardInfo *card); void cardInfoChanged(CardInfo *card);
}; };
class CardDatabase : public QObject { class CardDatabase : public QObject {
Q_OBJECT Q_OBJECT
protected: protected:
QHash<QString, CardInfo *> cardHash; QHash<QString, CardInfo *> cardHash;
QHash<QString, CardSet *> setHash; QHash<QString, CardSet *> setHash;
bool loadSuccess; bool loadSuccess;
CardInfo *noCard; CardInfo *noCard;
QThread *pictureLoaderThread; QThread *pictureLoaderThread;
PictureLoader *pictureLoader; PictureLoader *pictureLoader;
private: private:
static const int versionNeeded; static const int versionNeeded;
void loadCardsFromXml(QXmlStreamReader &xml); void loadCardsFromXml(QXmlStreamReader &xml);
void loadSetsFromXml(QXmlStreamReader &xml); void loadSetsFromXml(QXmlStreamReader &xml);
public: public:
CardDatabase(QObject *parent = 0); CardDatabase(QObject *parent = 0);
~CardDatabase(); ~CardDatabase();
void clear(); void clear();
void addCard(CardInfo *card); void addCard(CardInfo *card);
void removeCard(CardInfo *card); void removeCard(CardInfo *card);
CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = true); CardInfo *getCard(const QString &cardName = QString(), bool createIfNotFound = true);
CardSet *getSet(const QString &setName); CardSet *getSet(const QString &setName);
QList<CardInfo *> getCardList() const { return cardHash.values(); } QList<CardInfo *> getCardList() const { return cardHash.values(); }
SetList getSetList() const; SetList getSetList() const;
bool loadFromFile(const QString &fileName, bool tokens = false); bool loadFromFile(const QString &fileName, bool tokens = false);
bool saveToFile(const QString &fileName, bool tokens = false); bool saveToFile(const QString &fileName, bool tokens = false);
QStringList getAllColors() const; QStringList getAllColors() const;
QStringList getAllMainCardTypes() const; QStringList getAllMainCardTypes() const;
bool getLoadSuccess() const { return loadSuccess; } bool getLoadSuccess() const { return loadSuccess; }
void cacheCardPixmaps(const QStringList &cardNames); void cacheCardPixmaps(const QStringList &cardNames);
void loadImage(CardInfo *card); void loadImage(CardInfo *card);
public slots: public slots:
void clearPixmapCache(); void clearPixmapCache();
bool loadCardDatabase(const QString &path, bool tokens = false); bool loadCardDatabase(const QString &path, bool tokens = false);
private slots: private slots:
void imageLoaded(CardInfo *card, QImage image); void imageLoaded(CardInfo *card, QImage image);
void picDownloadChanged(); void picDownloadChanged();
void picsPathChanged(); void picsPathChanged();
void loadCardDatabase(); void loadCardDatabase();
void loadTokenDatabase(); void loadTokenDatabase();
signals: signals:
void cardListChanged(); void cardListChanged();
void cardAdded(CardInfo *card); void cardAdded(CardInfo *card);
void cardRemoved(CardInfo *card); void cardRemoved(CardInfo *card);
}; };
#endif #endif
...@@ -118,7 +118,6 @@ CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent) ...@@ -118,7 +118,6 @@ CardDatabaseDisplayModel::CardDatabaseDisplayModel(QObject *parent)
bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const bool CardDatabaseDisplayModel::filterAcceptsRow(int sourceRow, const QModelIndex & /*sourceParent*/) const
{ {
CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow); CardInfo const *info = static_cast<CardDatabaseModel *>(sourceModel())->getCard(sourceRow);
if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken())) if (((isToken == ShowTrue) && !info->getIsToken()) || ((isToken == ShowFalse) && info->getIsToken()))
return false; return false;
......
...@@ -9,82 +9,82 @@ ...@@ -9,82 +9,82 @@
#include <QPainter> #include <QPainter>
CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag) CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag)
: AbstractCardDragItem(_item, _hotSpot, parentDrag), id(_id), faceDown(_faceDown), occupied(false), currentZone(0) : AbstractCardDragItem(_item, _hotSpot, parentDrag), id(_id), faceDown(_faceDown), occupied(false), currentZone(0)
{ {
} }
void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
AbstractCardDragItem::paint(painter, option, widget); AbstractCardDragItem::paint(painter, option, widget);
if (occupied) if (occupied)
painter->fillRect(boundingRect(), QColor(200, 0, 0, 100)); painter->fillRect(boundingRect(), QColor(200, 0, 0, 100));
} }
void CardDragItem::updatePosition(const QPointF &cursorScenePos) void CardDragItem::updatePosition(const QPointF &cursorScenePos)
{ {
QList<QGraphicsItem *> colliding = scene()->items(cursorScenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, static_cast<GameScene *>(scene())->getViewTransform()); QList<QGraphicsItem *> colliding = scene()->items(cursorScenePos, Qt::IntersectsItemBoundingRect, Qt::DescendingOrder, static_cast<GameScene *>(scene())->getViewTransform());
CardZone *cardZone = 0; CardZone *cardZone = 0;
ZoneViewZone *zoneViewZone = 0; ZoneViewZone *zoneViewZone = 0;
for (int i = colliding.size() - 1; i >= 0; i--) { for (int i = colliding.size() - 1; i >= 0; i--) {
CardZone *temp = qgraphicsitem_cast<CardZone *>(colliding.at(i)); CardZone *temp = qgraphicsitem_cast<CardZone *>(colliding.at(i));
if (!cardZone) if (!cardZone)
cardZone = temp; cardZone = temp;
if (!zoneViewZone) if (!zoneViewZone)
zoneViewZone = qobject_cast<ZoneViewZone *>(temp); zoneViewZone = qobject_cast<ZoneViewZone *>(temp);
} }
CardZone *cursorZone = 0; CardZone *cursorZone = 0;
if (zoneViewZone) if (zoneViewZone)
cursorZone = zoneViewZone; cursorZone = zoneViewZone;
else if (cardZone) else if (cardZone)
cursorZone = cardZone; cursorZone = cardZone;
if (!cursorZone) if (!cursorZone)
return; return;
currentZone = cursorZone; currentZone = cursorZone;
QPointF zonePos = currentZone->scenePos(); QPointF zonePos = currentZone->scenePos();
QPointF cursorPosInZone = cursorScenePos - zonePos; QPointF cursorPosInZone = cursorScenePos - zonePos;
QPointF cardTopLeft = cursorPosInZone - hotSpot; QPointF cardTopLeft = cursorPosInZone - hotSpot;
QPointF closestGridPoint = cursorZone->closestGridPoint(cardTopLeft); QPointF closestGridPoint = cursorZone->closestGridPoint(cardTopLeft);
QPointF newPos = zonePos + closestGridPoint; QPointF newPos = zonePos + closestGridPoint;
if (newPos != pos()) { if (newPos != pos()) {
for (int i = 0; i < childDrags.size(); i++) for (int i = 0; i < childDrags.size(); i++)
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot()); childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
setPos(newPos); setPos(newPos);
bool newOccupied = false; bool newOccupied = false;
TableZone *table = qobject_cast<TableZone *>(cursorZone); TableZone *table = qobject_cast<TableZone *>(cursorZone);
if (table) if (table)
if (table->getCardFromCoords(closestGridPoint)) if (table->getCardFromCoords(closestGridPoint))
newOccupied = true; newOccupied = true;
if (newOccupied != occupied) { if (newOccupied != occupied) {
occupied = newOccupied; occupied = newOccupied;
update(); update();
} }
} }
} }
void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{ {
setCursor(Qt::OpenHandCursor); setCursor(Qt::OpenHandCursor);
QGraphicsScene *sc = scene(); QGraphicsScene *sc = scene();
QPointF sp = pos(); QPointF sp = pos();
sc->removeItem(this); sc->removeItem(this);
QList<CardDragItem *> dragItemList; QList<CardDragItem *> dragItemList;
CardZone *startZone = static_cast<CardItem *>(item)->getZone(); CardZone *startZone = static_cast<CardItem *>(item)->getZone();
if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone))) { if (currentZone && !(static_cast<CardItem *>(item)->getAttachedTo() && (startZone == currentZone))) {
dragItemList.append(this); dragItemList.append(this);
for (int i = 0; i < childDrags.size(); i++) { for (int i = 0; i < childDrags.size(); i++) {
CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]); CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]);
if (!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone)) && !c->occupied) if (!(static_cast<CardItem *>(c->item)->getAttachedTo() && (startZone == currentZone)) && !c->occupied)
dragItemList.append(c); dragItemList.append(c);
sc->removeItem(c); sc->removeItem(c);
} }
} }
currentZone->handleDropEvent(dragItemList, startZone, (sp - currentZone->scenePos()).toPoint()); currentZone->handleDropEvent(dragItemList, startZone, (sp - currentZone->scenePos()).toPoint());
event->accept(); event->accept();
} }
...@@ -6,20 +6,20 @@ ...@@ -6,20 +6,20 @@
class CardItem; class CardItem;
class CardDragItem : public AbstractCardDragItem { class CardDragItem : public AbstractCardDragItem {
Q_OBJECT Q_OBJECT
private: private:
int id; int id;
bool faceDown; bool faceDown;
bool occupied; bool occupied;
CardZone *currentZone; CardZone *currentZone;
public: public:
CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0); CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0);
int getId() const { return id; } int getId() const { return id; }
bool getFaceDown() const { return faceDown; } bool getFaceDown() const { return faceDown; }
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void updatePosition(const QPointF &cursorScenePos); void updatePosition(const QPointF &cursorScenePos);
protected: protected:
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
}; };
#endif #endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment