Initial commit for sideboarding. It's supposed to be fully functional.
This commit is contained in:
parent
2ee4bb834d
commit
b2f83541e7
18 changed files with 474 additions and 87 deletions
|
@ -37,6 +37,7 @@ HEADERS += src/counter.h \
|
||||||
src/setsmodel.h \
|
src/setsmodel.h \
|
||||||
src/window_sets.h \
|
src/window_sets.h \
|
||||||
src/abstractgraphicsitem.h \
|
src/abstractgraphicsitem.h \
|
||||||
|
src/abstractcarddragitem.h \
|
||||||
src/dlg_settings.h \
|
src/dlg_settings.h \
|
||||||
src/dlg_cardsearch.h \
|
src/dlg_cardsearch.h \
|
||||||
src/phasestoolbar.h \
|
src/phasestoolbar.h \
|
||||||
|
@ -89,6 +90,7 @@ SOURCES += src/counter.cpp \
|
||||||
src/setsmodel.cpp \
|
src/setsmodel.cpp \
|
||||||
src/window_sets.cpp \
|
src/window_sets.cpp \
|
||||||
src/abstractgraphicsitem.cpp \
|
src/abstractgraphicsitem.cpp \
|
||||||
|
src/abstractcarddragitem.cpp \
|
||||||
src/dlg_settings.cpp \
|
src/dlg_settings.cpp \
|
||||||
src/dlg_cardsearch.cpp \
|
src/dlg_cardsearch.cpp \
|
||||||
src/phasestoolbar.cpp \
|
src/phasestoolbar.cpp \
|
||||||
|
|
50
cockatrice/src/abstractcarddragitem.cpp
Normal file
50
cockatrice/src/abstractcarddragitem.cpp
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#include "abstractcarddragitem.h"
|
||||||
|
#include "carddatabase.h"
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
|
||||||
|
AbstractCardDragItem::AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
|
||||||
|
: QGraphicsItem(), item(_item), hotSpot(_hotSpot)
|
||||||
|
{
|
||||||
|
if (parentDrag) {
|
||||||
|
parentDrag->addChildDrag(this);
|
||||||
|
setZValue(1000000000 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
|
||||||
|
} else {
|
||||||
|
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
|
||||||
|
qDebug(QString("CardDragItem: coordinate overflow: x = %1, y = %2").arg(hotSpot.x()).arg(hotSpot.y()).toLatin1());
|
||||||
|
hotSpot = QPointF();
|
||||||
|
} else if ((hotSpot.x() > CARD_WIDTH) || (hotSpot.y() > CARD_HEIGHT)) {
|
||||||
|
qDebug(QString("CardDragItem: coordinate overflow: x = %1, y = %2").arg(hotSpot.x()).arg(hotSpot.y()).toLatin1());
|
||||||
|
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
|
||||||
|
}
|
||||||
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
setZValue(1000000000);
|
||||||
|
}
|
||||||
|
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));
|
||||||
|
|
||||||
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractCardDragItem::~AbstractCardDragItem()
|
||||||
|
{
|
||||||
|
qDebug("CardDragItem destructor");
|
||||||
|
for (int i = 0; i < childDrags.size(); i++)
|
||||||
|
delete childDrags[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractCardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
|
{
|
||||||
|
item->paint(painter, option, widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractCardDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
event->accept();
|
||||||
|
updatePosition(event->scenePos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractCardDragItem::addChildDrag(AbstractCardDragItem *child)
|
||||||
|
{
|
||||||
|
childDrags << child;
|
||||||
|
}
|
29
cockatrice/src/abstractcarddragitem.h
Normal file
29
cockatrice/src/abstractcarddragitem.h
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
#ifndef ABSTRACTCARDDRAGITEM_H
|
||||||
|
#define ABSTRACTCARDDRAGITEM_H
|
||||||
|
|
||||||
|
#include "abstractcarditem.h"
|
||||||
|
|
||||||
|
class QGraphicsScene;
|
||||||
|
class CardZone;
|
||||||
|
class CardInfo;
|
||||||
|
|
||||||
|
class AbstractCardDragItem : public QGraphicsItem {
|
||||||
|
protected:
|
||||||
|
AbstractCardItem *item;
|
||||||
|
QPointF hotSpot;
|
||||||
|
QList<AbstractCardDragItem *> childDrags;
|
||||||
|
public:
|
||||||
|
enum { Type = typeCardDrag };
|
||||||
|
int type() const { return Type; }
|
||||||
|
AbstractCardDragItem(AbstractCardItem *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
|
||||||
|
~AbstractCardDragItem();
|
||||||
|
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
QPointF getHotSpot() const { return hotSpot; }
|
||||||
|
void addChildDrag(AbstractCardDragItem *child);
|
||||||
|
virtual void updatePosition(const QPointF &cursorScenePos) = 0;
|
||||||
|
protected:
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,42 +1,13 @@
|
||||||
#include "carddragitem.h"
|
#include "carddragitem.h"
|
||||||
#include "cardzone.h"
|
#include "cardzone.h"
|
||||||
#include "carddatabase.h"
|
|
||||||
#include "tablezone.h"
|
#include "tablezone.h"
|
||||||
#include <QtGui>
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include <QCursor>
|
||||||
|
|
||||||
CardDragItem::CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, CardDragItem *parentDrag)
|
CardDragItem::CardDragItem(AbstractCardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag)
|
||||||
: QGraphicsItem(), id(_id), item(_item), hotSpot(_hotSpot), faceDown(_faceDown), currentZone(0)
|
: AbstractCardDragItem(_item, _hotSpot, parentDrag), id(_id), faceDown(_faceDown), currentZone(0)
|
||||||
{
|
{
|
||||||
if (parentDrag) {
|
|
||||||
parentDrag->addChildDrag(this);
|
|
||||||
setZValue(1000000000 + hotSpot.x() * 1000000 + hotSpot.y() * 1000 + 1000);
|
|
||||||
} else {
|
|
||||||
if ((hotSpot.x() < 0) || (hotSpot.y() < 0)) {
|
|
||||||
qDebug(QString("CardDragItem: coordinate overflow: x = %1, y = %2").arg(hotSpot.x()).arg(hotSpot.y()).toLatin1());
|
|
||||||
hotSpot = QPointF();
|
|
||||||
} else if ((hotSpot.x() > CARD_WIDTH) || (hotSpot.y() > CARD_HEIGHT)) {
|
|
||||||
qDebug(QString("CardDragItem: coordinate overflow: x = %1, y = %2").arg(hotSpot.x()).arg(hotSpot.y()).toLatin1());
|
|
||||||
hotSpot = QPointF(CARD_WIDTH, CARD_HEIGHT);
|
|
||||||
}
|
|
||||||
setCursor(Qt::ClosedHandCursor);
|
|
||||||
setZValue(1000000000);
|
|
||||||
}
|
|
||||||
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));
|
|
||||||
|
|
||||||
setCacheMode(DeviceCoordinateCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
CardDragItem::~CardDragItem()
|
|
||||||
{
|
|
||||||
qDebug("CardDragItem destructor");
|
|
||||||
for (int i = 0; i < childDrags.size(); i++)
|
|
||||||
delete childDrags[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardDragItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
|
||||||
{
|
|
||||||
item->paint(painter, option, widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
||||||
|
@ -56,8 +27,6 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
||||||
QPointF cardTopLeft = cursorPosInZone - hotSpot;
|
QPointF cardTopLeft = cursorPosInZone - hotSpot;
|
||||||
QPointF newPos = zonePos + cursorZone->closestGridPoint(cardTopLeft);
|
QPointF newPos = zonePos + cursorZone->closestGridPoint(cardTopLeft);
|
||||||
|
|
||||||
// qDebug(QString("cardTopLeft = %1, %2 cardCenter = %3, %4").arg((cardTopLeft).x()).arg((cardTopLeft).y()).arg(cardCenter.x()).arg(cardCenter.y()).toLatin1());
|
|
||||||
|
|
||||||
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());
|
||||||
|
@ -65,25 +34,18 @@ void CardDragItem::updatePosition(const QPointF &cursorScenePos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDragItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
|
||||||
{
|
|
||||||
event->accept();
|
|
||||||
updatePosition(event->scenePos());
|
|
||||||
}
|
|
||||||
|
|
||||||
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();
|
||||||
qDebug(QString("sp: x=%1, y=%2").arg(sp.x()).arg(sp.y()).toLatin1());
|
|
||||||
sc->removeItem(this);
|
sc->removeItem(this);
|
||||||
|
|
||||||
if (currentZone) {
|
if (currentZone) {
|
||||||
CardZone *startZone = qgraphicsitem_cast<CardZone *>(item->parentItem());
|
CardZone *startZone = qgraphicsitem_cast<CardZone *>(item->parentItem());
|
||||||
currentZone->handleDropEvent(id, startZone, (sp - currentZone->scenePos()).toPoint(), faceDown);
|
currentZone->handleDropEvent(id, startZone, (sp - currentZone->scenePos()).toPoint(), faceDown);
|
||||||
for (int i = 0; i < childDrags.size(); i++) {
|
for (int i = 0; i < childDrags.size(); i++) {
|
||||||
CardDragItem *c = childDrags[i];
|
CardDragItem *c = static_cast<CardDragItem *>(childDrags[i]);
|
||||||
currentZone->handleDropEvent(c->id, startZone, (sp - currentZone->scenePos() + c->getHotSpot()).toPoint(), faceDown);
|
currentZone->handleDropEvent(c->id, startZone, (sp - currentZone->scenePos() + c->getHotSpot()).toPoint(), faceDown);
|
||||||
sc->removeItem(c);
|
sc->removeItem(c);
|
||||||
}
|
}
|
||||||
|
@ -91,8 +53,3 @@ void CardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardDragItem::addChildDrag(CardDragItem *child)
|
|
||||||
{
|
|
||||||
childDrags << child;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,33 +1,18 @@
|
||||||
#ifndef CARDDRAGITEM_H
|
#ifndef CARDDRAGITEM_H
|
||||||
#define CARDDRAGITEM_H
|
#define CARDDRAGITEM_H
|
||||||
|
|
||||||
#include "carditem.h"
|
#include "abstractcarddragitem.h"
|
||||||
|
|
||||||
class QGraphicsScene;
|
class CardDragItem : public AbstractCardDragItem {
|
||||||
class CardZone;
|
|
||||||
class CardInfo;
|
|
||||||
|
|
||||||
class CardDragItem : public QGraphicsItem {
|
|
||||||
private:
|
private:
|
||||||
int id;
|
int id;
|
||||||
CardItem *item;
|
|
||||||
QPointF hotSpot;
|
|
||||||
bool faceDown;
|
bool faceDown;
|
||||||
QList<CardDragItem *> childDrags;
|
|
||||||
CardZone *currentZone;
|
CardZone *currentZone;
|
||||||
public:
|
public:
|
||||||
enum { Type = typeCardDrag };
|
CardDragItem(AbstractCardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, AbstractCardDragItem *parentDrag = 0);
|
||||||
int type() const { return Type; }
|
|
||||||
CardDragItem(CardItem *_item, int _id, const QPointF &_hotSpot, bool _faceDown, CardDragItem *parentDrag = 0);
|
|
||||||
~CardDragItem();
|
|
||||||
QRectF boundingRect() const { return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT); }
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
|
||||||
QPointF getHotSpot() const { return hotSpot; }
|
|
||||||
void addChildDrag(CardDragItem *child);
|
|
||||||
void updatePosition(const QPointF &cursorScenePos);
|
void updatePosition(const QPointF &cursorScenePos);
|
||||||
protected:
|
protected:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -5,13 +5,110 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
DeckViewCard::DeckViewCard(const QString &_name, QGraphicsItem *parent)
|
DeckViewCardDragItem::DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag)
|
||||||
: AbstractCardItem(_name, parent)
|
: AbstractCardDragItem(_item, _hotSpot, parentDrag)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckViewCardDragItem::updatePosition(const QPointF &cursorScenePos)
|
||||||
|
{
|
||||||
|
QList<QGraphicsItem *> colliding = scene()->items(cursorScenePos);
|
||||||
|
|
||||||
|
DeckViewCardContainer *cursorZone = 0;
|
||||||
|
for (int i = colliding.size() - 1; i >= 0; i--)
|
||||||
|
if ((cursorZone = qgraphicsitem_cast<DeckViewCardContainer *>(colliding.at(i))))
|
||||||
|
break;
|
||||||
|
if (!cursorZone)
|
||||||
|
return;
|
||||||
|
currentZone = cursorZone;
|
||||||
|
|
||||||
|
QPointF newPos = cursorScenePos;
|
||||||
|
if (newPos != pos()) {
|
||||||
|
for (int i = 0; i < childDrags.size(); i++)
|
||||||
|
childDrags[i]->setPos(newPos + childDrags[i]->getHotSpot());
|
||||||
|
setPos(newPos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCardDragItem::handleDrop(DeckViewCardContainer *target)
|
||||||
|
{
|
||||||
|
DeckViewCard *card = static_cast<DeckViewCard *>(item);
|
||||||
|
DeckViewCardContainer *start = static_cast<DeckViewCardContainer *>(item->parentItem());
|
||||||
|
start->removeCard(card);
|
||||||
|
target->addCard(card);
|
||||||
|
card->setParentItem(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCardDragItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
DeckViewScene *sc = static_cast<DeckViewScene *>(scene());
|
||||||
|
QPointF sp = pos();
|
||||||
|
sc->removeItem(this);
|
||||||
|
|
||||||
|
if (currentZone) {
|
||||||
|
handleDrop(currentZone);
|
||||||
|
for (int i = 0; i < childDrags.size(); i++) {
|
||||||
|
DeckViewCardDragItem *c = static_cast<DeckViewCardDragItem *>(childDrags[i]);
|
||||||
|
c->handleDrop(currentZone);
|
||||||
|
sc->removeItem(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
sc->updateContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckViewCard::DeckViewCard(const QString &_name, const QString &_originZone, QGraphicsItem *parent)
|
||||||
|
: AbstractCardItem(_name, parent), originZone(_originZone), dragItem(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
|
{
|
||||||
|
AbstractCardItem::paint(painter, option, widget);
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
QPen pen(Qt::DotLine);
|
||||||
|
pen.setWidth(2);
|
||||||
|
if (originZone == "main")
|
||||||
|
pen.setColor(QColor(0, 255, 0));
|
||||||
|
else
|
||||||
|
pen.setColor(QColor(255, 255, 0));
|
||||||
|
painter->setPen(pen);
|
||||||
|
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2));
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCard::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if ((event->screenPos() - event->buttonDownScreenPos(Qt::LeftButton)).manhattanLength() < 2 * QApplication::startDragDistance())
|
||||||
|
return;
|
||||||
|
|
||||||
|
delete dragItem;
|
||||||
|
dragItem = new DeckViewCardDragItem(this, event->pos());
|
||||||
|
scene()->addItem(dragItem);
|
||||||
|
dragItem->updatePosition(event->scenePos());
|
||||||
|
dragItem->grabMouse();
|
||||||
|
|
||||||
|
QList<QGraphicsItem *> sel = scene()->selectedItems();
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < sel.size(); i++) {
|
||||||
|
DeckViewCard *c = static_cast<DeckViewCard *>(sel.at(i));
|
||||||
|
if (c == this)
|
||||||
|
continue;
|
||||||
|
++j;
|
||||||
|
QPointF childPos = QPointF(j * CARD_WIDTH / 2, 0);
|
||||||
|
DeckViewCardDragItem *drag = new DeckViewCardDragItem(c, childPos, dragItem);
|
||||||
|
drag->setPos(dragItem->pos() + childPos);
|
||||||
|
scene()->addItem(drag);
|
||||||
|
}
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
}
|
||||||
|
|
||||||
DeckViewCardContainer::DeckViewCardContainer(const QString &_name)
|
DeckViewCardContainer::DeckViewCardContainer(const QString &_name)
|
||||||
: QGraphicsItem(), name(_name), width(0), height(0)
|
: QGraphicsItem(), name(_name), width(0), height(0), maxWidth(0)
|
||||||
{
|
{
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString bgPath = settings.value("zonebg/table").toString();
|
QString bgPath = settings.value("zonebg/table").toString();
|
||||||
|
@ -41,23 +138,32 @@ void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsI
|
||||||
f.setPixelSize(24);
|
f.setPixelSize(24);
|
||||||
f.setWeight(QFont::Bold);
|
f.setWeight(QFont::Bold);
|
||||||
painter->setFont(f);
|
painter->setFont(f);
|
||||||
painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, InnerDecklistNode::visibleNameFromName(name));
|
painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, InnerDecklistNode::visibleNameFromName(name) + QString(": %1").arg(cards.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardContainer::addCard(DeckViewCard *card)
|
void DeckViewCardContainer::addCard(DeckViewCard *card)
|
||||||
{
|
{
|
||||||
cards.insertMulti(card->getInfo()->getMainCardType(), card);
|
cards.append(card);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCardContainer::removeCard(DeckViewCard *card)
|
||||||
|
{
|
||||||
|
cards.removeAt(cards.indexOf(card));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckViewCardContainer::rearrangeItems()
|
void DeckViewCardContainer::rearrangeItems()
|
||||||
{
|
{
|
||||||
separatorY = 30;
|
separatorY = 30;
|
||||||
|
|
||||||
QList<QString> cardTypeList = cards.uniqueKeys();
|
QMap<QString, DeckViewCard *> cardsByType;
|
||||||
|
for (int i = 0; i < cards.size(); ++i)
|
||||||
|
cardsByType.insertMulti(cards[i]->getInfo()->getMainCardType(), cards[i]);
|
||||||
|
|
||||||
|
QList<QString> cardTypeList = cardsByType.uniqueKeys();
|
||||||
int rows = cardTypeList.size();
|
int rows = cardTypeList.size();
|
||||||
int cols = 0;
|
int cols = 0;
|
||||||
for (int i = 0; i < rows; ++i) {
|
for (int i = 0; i < rows; ++i) {
|
||||||
QList<DeckViewCard *> row = cards.values(cardTypeList[i]);
|
QList<DeckViewCard *> row = cardsByType.values(cardTypeList[i]);
|
||||||
if (row.size() > cols)
|
if (row.size() > cols)
|
||||||
cols = row.size();
|
cols = row.size();
|
||||||
for (int j = 0; j < row.size(); ++j) {
|
for (int j = 0; j < row.size(); ++j) {
|
||||||
|
@ -67,7 +173,8 @@ void DeckViewCardContainer::rearrangeItems()
|
||||||
}
|
}
|
||||||
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
width = cols * CARD_WIDTH;
|
if (cols * CARD_WIDTH > maxWidth)
|
||||||
|
width = maxWidth = cols * CARD_WIDTH;
|
||||||
height = separatorY + 10 + rows * CARD_HEIGHT + rowSpacing * (rows - 1);
|
height = separatorY + 10 + rows * CARD_HEIGHT + rowSpacing * (rows - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +205,7 @@ void DeckViewScene::setDeck(DeckList *_deck)
|
||||||
|
|
||||||
deck = _deck;
|
deck = _deck;
|
||||||
rebuildTree();
|
rebuildTree();
|
||||||
|
applySideboardPlan(deck->getCurrentSideboardPlan());
|
||||||
rearrangeItems();
|
rearrangeItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +228,7 @@ void DeckViewScene::rebuildTree()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
for (int k = 0; k < currentCard->getNumber(); ++k) {
|
||||||
DeckViewCard *newCard = new DeckViewCard(currentCard->getName(), container);
|
DeckViewCard *newCard = new DeckViewCard(currentCard->getName(), currentZone->getName(), container);
|
||||||
container->addCard(newCard);
|
container->addCard(newCard);
|
||||||
emit newCardAdded(newCard);
|
emit newCardAdded(newCard);
|
||||||
}
|
}
|
||||||
|
@ -128,6 +236,32 @@ void DeckViewScene::rebuildTree()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckViewScene::applySideboardPlan(const QList<MoveCardToZone *> &plan)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < plan.size(); ++i) {
|
||||||
|
MoveCardToZone *m = plan[i];
|
||||||
|
|
||||||
|
DeckViewCardContainer *start = cardContainers.value(m->getStartZone());
|
||||||
|
DeckViewCardContainer *target = cardContainers.value(m->getTargetZone());
|
||||||
|
if (!start || !target)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
DeckViewCard *card = 0;
|
||||||
|
const QList<DeckViewCard *> &cardList = start->getCards();
|
||||||
|
for (int j = 0; j < cardList.size(); ++j)
|
||||||
|
if (cardList[j]->getName() == m->getCardName()) {
|
||||||
|
card = cardList[j];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!card)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
start->removeCard(card);
|
||||||
|
target->addCard(card);
|
||||||
|
card->setParentItem(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DeckViewScene::rearrangeItems()
|
void DeckViewScene::rearrangeItems()
|
||||||
{
|
{
|
||||||
const int spacing = CARD_HEIGHT / 3;
|
const int spacing = CARD_HEIGHT / 3;
|
||||||
|
@ -148,17 +282,39 @@ void DeckViewScene::rearrangeItems()
|
||||||
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
|
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeckViewScene::updateContents()
|
||||||
|
{
|
||||||
|
rearrangeItems();
|
||||||
|
emit sideboardPlanChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<MoveCardToZone *> DeckViewScene::getSideboardPlan() const
|
||||||
|
{
|
||||||
|
QList<MoveCardToZone *> result;
|
||||||
|
QMapIterator<QString, DeckViewCardContainer *> containerIterator(cardContainers);
|
||||||
|
while (containerIterator.hasNext()) {
|
||||||
|
DeckViewCardContainer *cont = containerIterator.next().value();
|
||||||
|
const QList<DeckViewCard *> cardList = cont->getCards();
|
||||||
|
for (int i = 0; i < cardList.size(); ++i)
|
||||||
|
if (cardList[i]->getOriginZone() != cont->getName())
|
||||||
|
result.append(new MoveCardToZone(cardList[i]->getName(), cardList[i]->getOriginZone(), cont->getName()));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
DeckView::DeckView(QWidget *parent)
|
DeckView::DeckView(QWidget *parent)
|
||||||
: QGraphicsView(parent)
|
: QGraphicsView(parent)
|
||||||
{
|
{
|
||||||
deckViewScene = new DeckViewScene(this);
|
deckViewScene = new DeckViewScene(this);
|
||||||
|
|
||||||
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||||
|
setDragMode(RubberBandDrag);
|
||||||
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
||||||
setScene(deckViewScene);
|
setScene(deckViewScene);
|
||||||
|
|
||||||
connect(deckViewScene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
connect(deckViewScene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
||||||
connect(deckViewScene, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
|
connect(deckViewScene, SIGNAL(newCardAdded(AbstractCardItem *)), this, SIGNAL(newCardAdded(AbstractCardItem *)));
|
||||||
|
connect(deckViewScene, SIGNAL(sideboardPlanChanged()), this, SIGNAL(sideboardPlanChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckView::resizeEvent(QResizeEvent *event)
|
void DeckView::resizeEvent(QResizeEvent *event)
|
||||||
|
@ -169,7 +325,6 @@ void DeckView::resizeEvent(QResizeEvent *event)
|
||||||
|
|
||||||
void DeckView::updateSceneRect(const QRectF &rect)
|
void DeckView::updateSceneRect(const QRectF &rect)
|
||||||
{
|
{
|
||||||
qDebug(QString("deckView::updateSceneRect = %1,%2").arg(rect.width()).arg(rect.height()).toLatin1());
|
|
||||||
fitInView(rect, Qt::KeepAspectRatio);
|
fitInView(rect, Qt::KeepAspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,22 +5,45 @@
|
||||||
#include <QGraphicsView>
|
#include <QGraphicsView>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include "carditem.h"
|
#include "abstractcarditem.h"
|
||||||
|
#include "abstractcarddragitem.h"
|
||||||
|
|
||||||
class DeckList;
|
class DeckList;
|
||||||
class InnerDecklistNode;
|
class InnerDecklistNode;
|
||||||
class CardInfo;
|
class CardInfo;
|
||||||
|
class DeckViewCardContainer;
|
||||||
|
class DeckViewCardDragItem;
|
||||||
|
class MoveCardToZone;
|
||||||
|
|
||||||
class DeckViewCard : public AbstractCardItem {
|
class DeckViewCard : public AbstractCardItem {
|
||||||
|
private:
|
||||||
|
QString originZone;
|
||||||
|
DeckViewCardDragItem *dragItem;
|
||||||
public:
|
public:
|
||||||
DeckViewCard(const QString &_name = QString(), QGraphicsItem *parent = 0);
|
DeckViewCard(const QString &_name = QString(), const QString &_originZone = QString(), QGraphicsItem *parent = 0);
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
const QString &getOriginZone() const { return originZone; }
|
||||||
|
protected:
|
||||||
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeckViewCardDragItem : public AbstractCardDragItem {
|
||||||
|
private:
|
||||||
|
DeckViewCardContainer *currentZone;
|
||||||
|
void handleDrop(DeckViewCardContainer *target);
|
||||||
|
public:
|
||||||
|
DeckViewCardDragItem(DeckViewCard *_item, const QPointF &_hotSpot, AbstractCardDragItem *parentDrag = 0);
|
||||||
|
void updatePosition(const QPointF &cursorScenePos);
|
||||||
|
protected:
|
||||||
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckViewCardContainer : public QGraphicsItem {
|
class DeckViewCardContainer : public QGraphicsItem {
|
||||||
private:
|
private:
|
||||||
QString name;
|
QString name;
|
||||||
QMap<QString, DeckViewCard *> cards;
|
QList<DeckViewCard *> cards;
|
||||||
qreal width, height;
|
qreal width, height;
|
||||||
|
qreal maxWidth;
|
||||||
qreal separatorY;
|
qreal separatorY;
|
||||||
QPixmap bgPixmap;
|
QPixmap bgPixmap;
|
||||||
static const int rowSpacing = 5;
|
static const int rowSpacing = 5;
|
||||||
|
@ -29,6 +52,9 @@ public:
|
||||||
QRectF boundingRect() const;
|
QRectF boundingRect() const;
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
void addCard(DeckViewCard *card);
|
void addCard(DeckViewCard *card);
|
||||||
|
void removeCard(DeckViewCard *card);
|
||||||
|
const QList<DeckViewCard *> &getCards() const { return cards; }
|
||||||
|
const QString &getName() const { return name; }
|
||||||
void rearrangeItems();
|
void rearrangeItems();
|
||||||
void setWidth(qreal _width);
|
void setWidth(qreal _width);
|
||||||
};
|
};
|
||||||
|
@ -37,15 +63,19 @@ class DeckViewScene : public QGraphicsScene {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
signals:
|
signals:
|
||||||
void newCardAdded(AbstractCardItem *card);
|
void newCardAdded(AbstractCardItem *card);
|
||||||
|
void sideboardPlanChanged();
|
||||||
private:
|
private:
|
||||||
DeckList *deck;
|
DeckList *deck;
|
||||||
QMap<QString, DeckViewCardContainer *> cardContainers;
|
QMap<QString, DeckViewCardContainer *> cardContainers;
|
||||||
void rebuildTree();
|
void rebuildTree();
|
||||||
|
void applySideboardPlan(const QList<MoveCardToZone *> &plan);
|
||||||
void rearrangeItems();
|
void rearrangeItems();
|
||||||
public:
|
public:
|
||||||
DeckViewScene(QObject *parent = 0);
|
DeckViewScene(QObject *parent = 0);
|
||||||
~DeckViewScene();
|
~DeckViewScene();
|
||||||
void setDeck(DeckList *_deck);
|
void setDeck(DeckList *_deck);
|
||||||
|
void updateContents();
|
||||||
|
QList<MoveCardToZone *> getSideboardPlan() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DeckView : public QGraphicsView {
|
class DeckView : public QGraphicsView {
|
||||||
|
@ -58,9 +88,11 @@ public slots:
|
||||||
void updateSceneRect(const QRectF &rect);
|
void updateSceneRect(const QRectF &rect);
|
||||||
signals:
|
signals:
|
||||||
void newCardAdded(AbstractCardItem *card);
|
void newCardAdded(AbstractCardItem *card);
|
||||||
|
void sideboardPlanChanged();
|
||||||
public:
|
public:
|
||||||
DeckView(QWidget *parent = 0);
|
DeckView(QWidget *parent = 0);
|
||||||
void setDeck(DeckList *_deck);
|
void setDeck(DeckList *_deck);
|
||||||
|
QList<MoveCardToZone *> getSideboardPlan() const { return deckViewScene->getSideboardPlan(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -286,9 +286,6 @@ void MessageLogWidget::logSetActivePhase(int phase)
|
||||||
void MessageLogWidget::connectToPlayer(Player *player)
|
void MessageLogWidget::connectToPlayer(Player *player)
|
||||||
{
|
{
|
||||||
connect(player, SIGNAL(logSay(Player *, QString)), this, SLOT(logSay(Player *, QString)));
|
connect(player, SIGNAL(logSay(Player *, QString)), this, SLOT(logSay(Player *, QString)));
|
||||||
connect(player, SIGNAL(logDeckSelect(Player *, int)), this, SLOT(logDeckSelect(Player *, int)));
|
|
||||||
connect(player, SIGNAL(logReadyStart(Player *)), this, SLOT(logReadyStart(Player *)));
|
|
||||||
connect(player, SIGNAL(logConcede(Player *)), this, SLOT(logConcede(Player *)));
|
|
||||||
connect(player, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *)));
|
connect(player, SIGNAL(logShuffle(Player *)), this, SLOT(logShuffle(Player *)));
|
||||||
connect(player, SIGNAL(logRollDie(Player *, int, int)), this, SLOT(logRollDie(Player *, int, int)));
|
connect(player, SIGNAL(logRollDie(Player *, int, int)), this, SLOT(logRollDie(Player *, int, int)));
|
||||||
connect(player, SIGNAL(logCreateArrow(Player *, Player *, QString, Player *, QString)), this, SLOT(logCreateArrow(Player *, Player *, QString, Player *, QString)));
|
connect(player, SIGNAL(logCreateArrow(Player *, Player *, QString, Player *, QString)), this, SLOT(logCreateArrow(Player *, Player *, QString, Player *, QString)));
|
||||||
|
|
|
@ -38,7 +38,7 @@ Player::Player(const QString &_name, int _id, bool _local, Client *_client, TabG
|
||||||
PileZone *rfg = new PileZone(this, "rfg", false, true, this);
|
PileZone *rfg = new PileZone(this, "rfg", false, true, this);
|
||||||
rfg->setPos(base + QPointF(0, 2 * h));
|
rfg->setPos(base + QPointF(0, 2 * h));
|
||||||
|
|
||||||
PileZone *sb = new PileZone(this, "sb", false, true, this);
|
PileZone *sb = new PileZone(this, "sb", false, false, this);
|
||||||
sb->setVisible(false);
|
sb->setVisible(false);
|
||||||
|
|
||||||
table = new TableZone(this, this);
|
table = new TableZone(this, this);
|
||||||
|
|
|
@ -40,6 +40,7 @@ TabGame::TabGame(Client *_client, int _gameId, const QString &_gameDescription,
|
||||||
buttonHBox->addStretch();
|
buttonHBox->addStretch();
|
||||||
deckView = new DeckView;
|
deckView = new DeckView;
|
||||||
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *)));
|
connect(deckView, SIGNAL(newCardAdded(AbstractCardItem *)), this, SLOT(newCardAdded(AbstractCardItem *)));
|
||||||
|
connect(deckView, SIGNAL(sideboardPlanChanged()), this, SLOT(sideboardPlanChanged()));
|
||||||
QVBoxLayout *deckViewLayout = new QVBoxLayout;
|
QVBoxLayout *deckViewLayout = new QVBoxLayout;
|
||||||
deckViewLayout->addLayout(buttonHBox);
|
deckViewLayout->addLayout(buttonHBox);
|
||||||
deckViewLayout->addWidget(deckView);
|
deckViewLayout->addWidget(deckView);
|
||||||
|
@ -490,3 +491,9 @@ void TabGame::newCardAdded(AbstractCardItem *card)
|
||||||
{
|
{
|
||||||
connect(card, SIGNAL(hovered(AbstractCardItem *)), cardInfo, SLOT(setCard(AbstractCardItem *)));
|
connect(card, SIGNAL(hovered(AbstractCardItem *)), cardInfo, SLOT(setCard(AbstractCardItem *)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabGame::sideboardPlanChanged()
|
||||||
|
{
|
||||||
|
QList<MoveCardToZone *> newPlan = deckView->getSideboardPlan();
|
||||||
|
client->sendCommand(new Command_SetSideboardPlan(gameId, newPlan));
|
||||||
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ private slots:
|
||||||
void readyStart();
|
void readyStart();
|
||||||
void deckSelectFinished(ProtocolResponse *r);
|
void deckSelectFinished(ProtocolResponse *r);
|
||||||
void newCardAdded(AbstractCardItem *card);
|
void newCardAdded(AbstractCardItem *card);
|
||||||
|
void sideboardPlanChanged();
|
||||||
|
|
||||||
void actConcede();
|
void actConcede();
|
||||||
void actLeaveGame();
|
void actLeaveGame();
|
||||||
|
|
|
@ -7,6 +7,41 @@
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
MoveCardToZone::MoveCardToZone(const QString &_cardName, const QString &_startZone, const QString &_targetZone)
|
||||||
|
: SerializableItem_Map("move_card_to_zone")
|
||||||
|
{
|
||||||
|
insertItem(new SerializableItem_String("card_name", _cardName));
|
||||||
|
insertItem(new SerializableItem_String("start_zone", _startZone));
|
||||||
|
insertItem(new SerializableItem_String("target_zone", _targetZone));
|
||||||
|
}
|
||||||
|
|
||||||
|
MoveCardToZone::MoveCardToZone(MoveCardToZone *other)
|
||||||
|
: SerializableItem_Map("move_card_to_zone")
|
||||||
|
{
|
||||||
|
insertItem(new SerializableItem_String("card_name", other->getCardName()));
|
||||||
|
insertItem(new SerializableItem_String("start_zone", other->getStartZone()));
|
||||||
|
insertItem(new SerializableItem_String("target_zone", other->getTargetZone()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SideboardPlan::SideboardPlan(const QString &_name, const QList<MoveCardToZone *> &_moveList)
|
||||||
|
: SerializableItem_Map("sideboard_plan")
|
||||||
|
{
|
||||||
|
insertItem(new SerializableItem_String("name", _name));
|
||||||
|
|
||||||
|
for (int i = 0; i < _moveList.size(); ++i)
|
||||||
|
itemList.append(_moveList[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SideboardPlan::setMoveList(const QList<MoveCardToZone *> &_moveList)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < itemList.size(); ++i)
|
||||||
|
delete itemList[i];
|
||||||
|
itemList.clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < _moveList.size(); ++i)
|
||||||
|
itemList.append(_moveList[i]);
|
||||||
|
}
|
||||||
|
|
||||||
AbstractDecklistNode::AbstractDecklistNode(InnerDecklistNode *_parent)
|
AbstractDecklistNode::AbstractDecklistNode(InnerDecklistNode *_parent)
|
||||||
: parent(_parent), currentItem(0)
|
: parent(_parent), currentItem(0)
|
||||||
{
|
{
|
||||||
|
@ -197,20 +232,57 @@ const QStringList DeckList::fileNameFilters = QStringList()
|
||||||
<< QObject::tr("All files (*.*)");
|
<< QObject::tr("All files (*.*)");
|
||||||
|
|
||||||
DeckList::DeckList()
|
DeckList::DeckList()
|
||||||
: SerializableItem("cockatrice_deck"), currentZone(0)
|
: SerializableItem("cockatrice_deck"), currentZone(0), currentSideboardPlan(0)
|
||||||
{
|
{
|
||||||
root = new InnerDecklistNode;
|
root = new InnerDecklistNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckList::DeckList(DeckList *other)
|
DeckList::DeckList(DeckList *other)
|
||||||
: SerializableItem("cockatrice_deck"), currentZone(0)
|
: SerializableItem("cockatrice_deck"), currentZone(0), currentSideboardPlan(0)
|
||||||
{
|
{
|
||||||
root = new InnerDecklistNode(other->getRoot());
|
root = new InnerDecklistNode(other->getRoot());
|
||||||
|
|
||||||
|
QMapIterator<QString, SideboardPlan *> spIterator(other->getSideboardPlans());
|
||||||
|
while (spIterator.hasNext()) {
|
||||||
|
spIterator.next();
|
||||||
|
QList<MoveCardToZone *> newMoveList;
|
||||||
|
QList<MoveCardToZone *> oldMoveList = spIterator.value()->getMoveList();
|
||||||
|
for (int i = 0; i < oldMoveList.size(); ++i)
|
||||||
|
newMoveList.append(new MoveCardToZone(oldMoveList[i]));
|
||||||
|
sideboardPlans.insert(spIterator.key(), new SideboardPlan(spIterator.key(), newMoveList));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DeckList::~DeckList()
|
DeckList::~DeckList()
|
||||||
{
|
{
|
||||||
delete root;
|
delete root;
|
||||||
|
|
||||||
|
QMapIterator<QString, SideboardPlan *> i(sideboardPlans);
|
||||||
|
while (i.hasNext())
|
||||||
|
delete i.next().value();
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<MoveCardToZone *> DeckList::getCurrentSideboardPlan()
|
||||||
|
{
|
||||||
|
SideboardPlan *current = sideboardPlans.value(QString(), 0);
|
||||||
|
if (!current)
|
||||||
|
return QList<MoveCardToZone *>();
|
||||||
|
else
|
||||||
|
return current->getMoveList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckList::setCurrentSideboardPlan(const QList<MoveCardToZone *> &plan)
|
||||||
|
{
|
||||||
|
SideboardPlan *current = sideboardPlans.value(QString(), 0);
|
||||||
|
if (!current) {
|
||||||
|
current = new SideboardPlan;
|
||||||
|
sideboardPlans.insert(QString(), current);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<MoveCardToZone *> newList;
|
||||||
|
for (int i = 0; i < plan.size(); ++i)
|
||||||
|
newList.append(new MoveCardToZone(plan[i]));
|
||||||
|
current->setMoveList(newList);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeckList::readElement(QXmlStreamReader *xml)
|
bool DeckList::readElement(QXmlStreamReader *xml)
|
||||||
|
@ -218,6 +290,11 @@ bool DeckList::readElement(QXmlStreamReader *xml)
|
||||||
if (currentZone) {
|
if (currentZone) {
|
||||||
if (currentZone->readElement(xml))
|
if (currentZone->readElement(xml))
|
||||||
currentZone = 0;
|
currentZone = 0;
|
||||||
|
} else if (currentSideboardPlan) {
|
||||||
|
if (currentSideboardPlan->readElement(xml)) {
|
||||||
|
sideboardPlans.insert(currentSideboardPlan->getName(), currentSideboardPlan);
|
||||||
|
currentSideboardPlan = 0;
|
||||||
|
}
|
||||||
} else if (xml->isEndElement()) {
|
} else if (xml->isEndElement()) {
|
||||||
if (xml->name() == "deckname")
|
if (xml->name() == "deckname")
|
||||||
name = currentElementText;
|
name = currentElementText;
|
||||||
|
@ -227,6 +304,8 @@ bool DeckList::readElement(QXmlStreamReader *xml)
|
||||||
currentElementText.clear();
|
currentElementText.clear();
|
||||||
} else if (xml->isStartElement() && (xml->name() == "zone"))
|
} else if (xml->isStartElement() && (xml->name() == "zone"))
|
||||||
currentZone = new InnerDecklistNode(xml->attributes().value("name").toString(), root);
|
currentZone = new InnerDecklistNode(xml->attributes().value("name").toString(), root);
|
||||||
|
else if (xml->isStartElement() && (xml->name() == "sideboard_plan"))
|
||||||
|
currentSideboardPlan = new SideboardPlan;
|
||||||
else if (xml->isCharacters() && !xml->isWhitespace())
|
else if (xml->isCharacters() && !xml->isWhitespace())
|
||||||
currentElementText = xml->text().toString();
|
currentElementText = xml->text().toString();
|
||||||
return SerializableItem::readElement(xml);
|
return SerializableItem::readElement(xml);
|
||||||
|
@ -240,6 +319,10 @@ void DeckList::writeElement(QXmlStreamWriter *xml)
|
||||||
|
|
||||||
for (int i = 0; i < root->size(); i++)
|
for (int i = 0; i < root->size(); i++)
|
||||||
root->at(i)->writeElement(xml);
|
root->at(i)->writeElement(xml);
|
||||||
|
|
||||||
|
QMapIterator<QString, SideboardPlan *> i(sideboardPlans);
|
||||||
|
while (i.hasNext())
|
||||||
|
i.next().value()->write(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeckList::loadFromXml(QXmlStreamReader *xml)
|
void DeckList::loadFromXml(QXmlStreamReader *xml)
|
||||||
|
|
|
@ -14,6 +14,25 @@ class QXmlStreamWriter;
|
||||||
|
|
||||||
class InnerDecklistNode;
|
class InnerDecklistNode;
|
||||||
|
|
||||||
|
class MoveCardToZone : public SerializableItem_Map {
|
||||||
|
public:
|
||||||
|
MoveCardToZone(const QString &_cardName = QString(), const QString &_startZone = QString(), const QString &_targetZone = QString());
|
||||||
|
MoveCardToZone(MoveCardToZone *other);
|
||||||
|
static SerializableItem *newItem() { return new MoveCardToZone; }
|
||||||
|
QString getCardName() const { return static_cast<SerializableItem_String *>(itemMap.value("card_name"))->getData(); }
|
||||||
|
QString getStartZone() const { return static_cast<SerializableItem_String *>(itemMap.value("start_zone"))->getData(); }
|
||||||
|
QString getTargetZone() const { return static_cast<SerializableItem_String *>(itemMap.value("target_zone"))->getData(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
class SideboardPlan : public SerializableItem_Map {
|
||||||
|
public:
|
||||||
|
SideboardPlan(const QString &_name = QString(), const QList<MoveCardToZone *> &_moveList = QList<MoveCardToZone *>());
|
||||||
|
static SerializableItem *newItem() { return new SideboardPlan; }
|
||||||
|
QString getName() const { return static_cast<SerializableItem_String *>(itemMap.value("name"))->getData(); }
|
||||||
|
QList<MoveCardToZone *> getMoveList() const { return typecastItemList<MoveCardToZone *>(); }
|
||||||
|
void setMoveList(const QList<MoveCardToZone *> &_moveList);
|
||||||
|
};
|
||||||
|
|
||||||
class AbstractDecklistNode {
|
class AbstractDecklistNode {
|
||||||
protected:
|
protected:
|
||||||
InnerDecklistNode *parent;
|
InnerDecklistNode *parent;
|
||||||
|
@ -89,8 +108,10 @@ private:
|
||||||
QString name, comments;
|
QString name, comments;
|
||||||
QString lastFileName;
|
QString lastFileName;
|
||||||
FileFormat lastFileFormat;
|
FileFormat lastFileFormat;
|
||||||
|
QMap<QString, SideboardPlan *> sideboardPlans;
|
||||||
InnerDecklistNode *root;
|
InnerDecklistNode *root;
|
||||||
InnerDecklistNode *currentZone;
|
InnerDecklistNode *currentZone;
|
||||||
|
SideboardPlan *currentSideboardPlan;
|
||||||
QString currentElementText;
|
QString currentElementText;
|
||||||
signals:
|
signals:
|
||||||
void deckLoaded();
|
void deckLoaded();
|
||||||
|
@ -106,6 +127,9 @@ public:
|
||||||
QString getComments() const { return comments; }
|
QString getComments() const { return comments; }
|
||||||
QString getLastFileName() const { return lastFileName; }
|
QString getLastFileName() const { return lastFileName; }
|
||||||
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
FileFormat getLastFileFormat() const { return lastFileFormat; }
|
||||||
|
QList<MoveCardToZone *> getCurrentSideboardPlan();
|
||||||
|
void setCurrentSideboardPlan(const QList<MoveCardToZone *> &plan);
|
||||||
|
const QMap<QString, SideboardPlan *> &getSideboardPlans() const { return sideboardPlans; }
|
||||||
|
|
||||||
bool readElement(QXmlStreamReader *xml);
|
bool readElement(QXmlStreamReader *xml);
|
||||||
void writeElement(QXmlStreamWriter *xml);
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
|
|
|
@ -14,6 +14,7 @@ void ProtocolItem::initializeHash()
|
||||||
{
|
{
|
||||||
initializeHashAuto();
|
initializeHashAuto();
|
||||||
|
|
||||||
|
registerSerializableItem("move_card_to_zone", MoveCardToZone::newItem);
|
||||||
registerSerializableItem("chat_channel", ServerInfo_ChatChannel::newItem);
|
registerSerializableItem("chat_channel", ServerInfo_ChatChannel::newItem);
|
||||||
registerSerializableItem("chat_user", ServerInfo_ChatUser::newItem);
|
registerSerializableItem("chat_user", ServerInfo_ChatUser::newItem);
|
||||||
registerSerializableItem("game", ServerInfo_Game::newItem);
|
registerSerializableItem("game", ServerInfo_Game::newItem);
|
||||||
|
@ -32,6 +33,7 @@ void ProtocolItem::initializeHash()
|
||||||
|
|
||||||
registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem);
|
registerSerializableItem("cmddeck_upload", Command_DeckUpload::newItem);
|
||||||
registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem);
|
registerSerializableItem("cmddeck_select", Command_DeckSelect::newItem);
|
||||||
|
registerSerializableItem("cmdset_sideboard_plan", Command_SetSideboardPlan::newItem);
|
||||||
|
|
||||||
registerSerializableItem("resp", ProtocolResponse::newItem);
|
registerSerializableItem("resp", ProtocolResponse::newItem);
|
||||||
ProtocolResponse::initializeHash();
|
ProtocolResponse::initializeHash();
|
||||||
|
@ -170,6 +172,18 @@ DeckList *Command_DeckSelect::getDeck() const
|
||||||
return static_cast<DeckList *>(itemMap.value("cockatrice_deck"));
|
return static_cast<DeckList *>(itemMap.value("cockatrice_deck"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command_SetSideboardPlan::Command_SetSideboardPlan(int _gameId, const QList<MoveCardToZone *> &_moveList)
|
||||||
|
: GameCommand("set_sideboard_plan", _gameId)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _moveList.size(); ++i)
|
||||||
|
itemList.append(_moveList[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<MoveCardToZone *> Command_SetSideboardPlan::getMoveList() const
|
||||||
|
{
|
||||||
|
return typecastItemList<MoveCardToZone *>();
|
||||||
|
}
|
||||||
|
|
||||||
QHash<QString, ResponseCode> ProtocolResponse::responseHash;
|
QHash<QString, ResponseCode> ProtocolResponse::responseHash;
|
||||||
|
|
||||||
ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode, const QString &_itemName)
|
ProtocolResponse::ProtocolResponse(int _cmdId, ResponseCode _responseCode, const QString &_itemName)
|
||||||
|
|
|
@ -17,12 +17,14 @@ class ProtocolResponse;
|
||||||
class DeckList;
|
class DeckList;
|
||||||
class GameEvent;
|
class GameEvent;
|
||||||
class GameEventContainer;
|
class GameEventContainer;
|
||||||
|
class MoveCardToZone;
|
||||||
|
|
||||||
enum ItemId {
|
enum ItemId {
|
||||||
ItemId_CommandContainer = ItemId_Other + 50,
|
ItemId_CommandContainer = ItemId_Other + 50,
|
||||||
ItemId_GameEventContainer = ItemId_Other + 51,
|
ItemId_GameEventContainer = ItemId_Other + 51,
|
||||||
ItemId_Command_DeckUpload = ItemId_Other + 100,
|
ItemId_Command_DeckUpload = ItemId_Other + 100,
|
||||||
ItemId_Command_DeckSelect = ItemId_Other + 101,
|
ItemId_Command_DeckSelect = ItemId_Other + 101,
|
||||||
|
ItemId_Command_SetSideboardPlan = ItemId_Other + 102,
|
||||||
ItemId_Event_ListChatChannels = ItemId_Other + 200,
|
ItemId_Event_ListChatChannels = ItemId_Other + 200,
|
||||||
ItemId_Event_ChatListPlayers = ItemId_Other + 201,
|
ItemId_Event_ChatListPlayers = ItemId_Other + 201,
|
||||||
ItemId_Event_ListGames = ItemId_Other + 202,
|
ItemId_Event_ListGames = ItemId_Other + 202,
|
||||||
|
@ -164,6 +166,15 @@ public:
|
||||||
int getDeckId() const { return static_cast<SerializableItem_Int *>(itemMap.value("deck_id"))->getData(); }
|
int getDeckId() const { return static_cast<SerializableItem_Int *>(itemMap.value("deck_id"))->getData(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Command_SetSideboardPlan : public GameCommand {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
Command_SetSideboardPlan(int _gameId = -1, const QList<MoveCardToZone *> &_moveList = QList<MoveCardToZone *>());
|
||||||
|
static SerializableItem *newItem() { return new Command_SetSideboardPlan; }
|
||||||
|
int getItemId() const { return ItemId_Command_SetSideboardPlan; }
|
||||||
|
QList<MoveCardToZone *> getMoveList() const;
|
||||||
|
};
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// --- RESPONSES ---
|
// --- RESPONSES ---
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
|
@ -103,6 +103,34 @@ void Server_Player::setupZones()
|
||||||
z->cards.append(new Server_Card(currentCard->getName(), nextCardId++, 0, 0));
|
z->cards.append(new Server_Card(currentCard->getName(), nextCardId++, 0, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QList<MoveCardToZone *> &sideboardPlan = deck->getCurrentSideboardPlan();
|
||||||
|
for (int i = 0; i < sideboardPlan.size(); ++i) {
|
||||||
|
MoveCardToZone *m = sideboardPlan[i];
|
||||||
|
|
||||||
|
Server_CardZone *start, *target;
|
||||||
|
if (m->getStartZone() == "main")
|
||||||
|
start = deckZone;
|
||||||
|
else if (m->getStartZone() == "side")
|
||||||
|
start = sbZone;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
if (m->getTargetZone() == "main")
|
||||||
|
target = deckZone;
|
||||||
|
else if (m->getTargetZone() == "side")
|
||||||
|
target = sbZone;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int j = 0; j < start->cards.size(); ++j)
|
||||||
|
if (start->cards[j]->getName() == m->getCardName()) {
|
||||||
|
Server_Card *card = start->cards[j];
|
||||||
|
start->cards.removeAt(j);
|
||||||
|
target->cards.append(card);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deckZone->shuffle();
|
deckZone->shuffle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,6 +85,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm
|
||||||
|
|
||||||
switch (command->getItemId()) {
|
switch (command->getItemId()) {
|
||||||
case ItemId_Command_DeckSelect: return cmdDeckSelect(qobject_cast<Command_DeckSelect *>(command), cont, game, player);
|
case ItemId_Command_DeckSelect: return cmdDeckSelect(qobject_cast<Command_DeckSelect *>(command), cont, game, player);
|
||||||
|
case ItemId_Command_SetSideboardPlan: return cmdSetSideboardPlan(qobject_cast<Command_SetSideboardPlan *>(command), cont, game, player);
|
||||||
case ItemId_Command_LeaveGame: return cmdLeaveGame(qobject_cast<Command_LeaveGame *>(command), cont, game, player);
|
case ItemId_Command_LeaveGame: return cmdLeaveGame(qobject_cast<Command_LeaveGame *>(command), cont, game, player);
|
||||||
case ItemId_Command_ReadyStart: return cmdReadyStart(qobject_cast<Command_ReadyStart *>(command), cont, game, player);
|
case ItemId_Command_ReadyStart: return cmdReadyStart(qobject_cast<Command_ReadyStart *>(command), cont, game, player);
|
||||||
case ItemId_Command_Concede: return cmdConcede(qobject_cast<Command_Concede *>(command), cont, game, player);
|
case ItemId_Command_Concede: return cmdConcede(qobject_cast<Command_Concede *>(command), cont, game, player);
|
||||||
|
@ -351,6 +352,16 @@ ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Comm
|
||||||
return RespNothing;
|
return RespNothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResponseCode Server_ProtocolHandler::cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
DeckList *deck = player->getDeck();
|
||||||
|
if (!deck)
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
|
deck->setCurrentSideboardPlan(cmd->getMoveList());
|
||||||
|
return RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdConcede(Command_Concede * /*cmd*/, CommandContainer *cont, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
player->setConceded(true);
|
player->setConceded(true);
|
||||||
|
|
|
@ -51,6 +51,7 @@ private:
|
||||||
ResponseCode cmdConcede(Command_Concede *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
ResponseCode cmdConcede(Command_Concede *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
ResponseCode cmdReadyStart(Command_ReadyStart *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||||
|
ResponseCode cmdSetSideboardPlan(Command_SetSideboardPlan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
ResponseCode cmdSay(Command_Say *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdShuffle(Command_Shuffle *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
ResponseCode cmdShuffle(Command_Shuffle *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdMulligan(Command_Mulligan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
ResponseCode cmdMulligan(Command_Mulligan *cmd, CommandContainer *cont, Server_Game *game, Server_Player *player);
|
||||||
|
|
Loading…
Reference in a new issue