decklist transfer code
This commit is contained in:
parent
63f9206eb4
commit
8dcf81654e
32 changed files with 694 additions and 260 deletions
|
@ -16,6 +16,7 @@ HEADERS += src/counter.h \
|
||||||
src/cardzone.h \
|
src/cardzone.h \
|
||||||
src/player.h \
|
src/player.h \
|
||||||
src/cardlist.h \
|
src/cardlist.h \
|
||||||
|
src/abstractcarditem.h \
|
||||||
src/carditem.h \
|
src/carditem.h \
|
||||||
src/tablezone.h \
|
src/tablezone.h \
|
||||||
src/handzone.h \
|
src/handzone.h \
|
||||||
|
@ -45,6 +46,7 @@ HEADERS += src/counter.h \
|
||||||
src/tab_game.h \
|
src/tab_game.h \
|
||||||
src/tab_deck_storage.h \
|
src/tab_deck_storage.h \
|
||||||
src/tab_supervisor.h \
|
src/tab_supervisor.h \
|
||||||
|
src/deckview.h \
|
||||||
../common/decklist.h \
|
../common/decklist.h \
|
||||||
../common/protocol.h \
|
../common/protocol.h \
|
||||||
../common/protocol_items.h \
|
../common/protocol_items.h \
|
||||||
|
@ -60,6 +62,7 @@ SOURCES += src/counter.cpp \
|
||||||
src/player.cpp \
|
src/player.cpp \
|
||||||
src/cardzone.cpp \
|
src/cardzone.cpp \
|
||||||
src/cardlist.cpp \
|
src/cardlist.cpp \
|
||||||
|
src/abstractcarditem.cpp \
|
||||||
src/carditem.cpp \
|
src/carditem.cpp \
|
||||||
src/tablezone.cpp \
|
src/tablezone.cpp \
|
||||||
src/handzone.cpp \
|
src/handzone.cpp \
|
||||||
|
@ -89,6 +92,7 @@ SOURCES += src/counter.cpp \
|
||||||
src/tab_game.cpp \
|
src/tab_game.cpp \
|
||||||
src/tab_deck_storage.cpp \
|
src/tab_deck_storage.cpp \
|
||||||
src/tab_supervisor.cpp \
|
src/tab_supervisor.cpp \
|
||||||
|
src/deckview.cpp \
|
||||||
../common/decklist.cpp \
|
../common/decklist.cpp \
|
||||||
../common/protocol.cpp \
|
../common/protocol.cpp \
|
||||||
../common/protocol_items.cpp
|
../common/protocol_items.cpp
|
||||||
|
|
148
cockatrice/src/abstractcarditem.cpp
Normal file
148
cockatrice/src/abstractcarditem.cpp
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QCursor>
|
||||||
|
#include <QStyleOptionGraphicsItem>
|
||||||
|
#include <QGraphicsSceneMouseEvent>
|
||||||
|
#include "carddatabase.h"
|
||||||
|
#include "abstractcarditem.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
AbstractCardItem::AbstractCardItem(const QString &_name, QGraphicsItem *parent)
|
||||||
|
: AbstractGraphicsItem(parent), info(db->getCard(_name)), name(_name), tapped(false)
|
||||||
|
{
|
||||||
|
setCursor(Qt::OpenHandCursor);
|
||||||
|
setFlag(ItemIsSelectable);
|
||||||
|
setAcceptsHoverEvents(true);
|
||||||
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
|
||||||
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||||
|
}
|
||||||
|
|
||||||
|
AbstractCardItem::~AbstractCardItem()
|
||||||
|
{
|
||||||
|
qDebug(QString("AbstractCardItem destructor: %1").arg(name).toLatin1());
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF AbstractCardItem::boundingRect() const
|
||||||
|
{
|
||||||
|
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractCardItem::pixmapUpdated()
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
|
||||||
|
{
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
QSizeF translatedSize = option->matrix.mapRect(boundingRect()).size();
|
||||||
|
if (tapped)
|
||||||
|
translatedSize.transpose();
|
||||||
|
QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize());
|
||||||
|
painter->save();
|
||||||
|
if (translatedPixmap) {
|
||||||
|
painter->resetTransform();
|
||||||
|
if (tapped) {
|
||||||
|
painter->translate(((qreal) translatedSize.height()) / 2, ((qreal) translatedSize.width()) / 2);
|
||||||
|
painter->rotate(90);
|
||||||
|
painter->translate(-((qreal) translatedSize.width()) / 2, -((qreal) translatedSize.height()) / 2);
|
||||||
|
}
|
||||||
|
painter->drawPixmap(translatedPixmap->rect(), *translatedPixmap, translatedPixmap->rect());
|
||||||
|
} else {
|
||||||
|
QFont f("Serif");
|
||||||
|
f.setStyleHint(QFont::Serif);
|
||||||
|
f.setPixelSize(11);
|
||||||
|
painter->setFont(f);
|
||||||
|
painter->setBrush(QColor(230, 230, 230));
|
||||||
|
qDebug() <<"COLORS:::::" << info->getColors();
|
||||||
|
QString color;
|
||||||
|
QPen pen;
|
||||||
|
if(!info->getColors().empty())
|
||||||
|
{
|
||||||
|
color = info->getColors().first();
|
||||||
|
if(color == "B")
|
||||||
|
painter->setBrush(QColor(0,0,0));
|
||||||
|
if(color == "U")
|
||||||
|
painter->setBrush(QColor(0,140,180));
|
||||||
|
if(color == "W")
|
||||||
|
painter->setBrush(QColor(255,250,140));
|
||||||
|
if(color == "R")
|
||||||
|
painter->setBrush(QColor(230,0,0));
|
||||||
|
if(color == "G")
|
||||||
|
painter->setBrush(QColor(0,160,0));
|
||||||
|
if(info->getColors().size() > 1)
|
||||||
|
{
|
||||||
|
painter->setBrush(QColor(250,190,30));
|
||||||
|
color = "M"; // Multicolor
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->setPen(Qt::black);
|
||||||
|
|
||||||
|
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||||
|
|
||||||
|
pen.setWidth(3);
|
||||||
|
painter->setPen(pen);
|
||||||
|
painter->drawRect(QRectF(3, 3, CARD_WIDTH - 6, CARD_HEIGHT - 6));
|
||||||
|
painter->setPen(Qt::white);
|
||||||
|
if(color == "W" || color == "" || color == "M")
|
||||||
|
painter->setPen(Qt::black);
|
||||||
|
painter->drawText(QRectF(5, 5, CARD_WIDTH - 15, CARD_HEIGHT - 15), Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, name);
|
||||||
|
if(info->getCardType().contains("Creature"))
|
||||||
|
{
|
||||||
|
painter->drawText(QRectF(CARD_WIDTH - 40, CARD_HEIGHT - 25, 30, 30), Qt::AlignTop | Qt::AlignRight | Qt::TextWordWrap, info->getPowTough());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
painter->restore();
|
||||||
|
|
||||||
|
if (isSelected()) {
|
||||||
|
painter->setPen(Qt::red);
|
||||||
|
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractCardItem::setName(const QString &_name)
|
||||||
|
{
|
||||||
|
disconnect(info, 0, this, 0);
|
||||||
|
name = _name;
|
||||||
|
info = db->getCard(name);
|
||||||
|
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractCardItem::setTapped(bool _tapped)
|
||||||
|
{
|
||||||
|
tapped = _tapped;
|
||||||
|
if (tapped)
|
||||||
|
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
||||||
|
else
|
||||||
|
setTransform(QTransform());
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
||||||
|
{
|
||||||
|
if (!isSelected()) {
|
||||||
|
scene()->clearSelection();
|
||||||
|
setSelected(true);
|
||||||
|
}
|
||||||
|
if (event->button() == Qt::LeftButton)
|
||||||
|
setCursor(Qt::ClosedHandCursor);
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant AbstractCardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
||||||
|
{
|
||||||
|
if (change == ItemSelectedHasChanged) {
|
||||||
|
update();
|
||||||
|
return value;
|
||||||
|
} else
|
||||||
|
return QGraphicsItem::itemChange(change, value);
|
||||||
|
}
|
||||||
|
|
43
cockatrice/src/abstractcarditem.h
Normal file
43
cockatrice/src/abstractcarditem.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef ABSTRACTCARDITEM_H
|
||||||
|
#define ABSTRACTCARDITEM_H
|
||||||
|
|
||||||
|
#include "abstractgraphicsitem.h"
|
||||||
|
|
||||||
|
class CardInfo;
|
||||||
|
|
||||||
|
const int CARD_WIDTH = 72;
|
||||||
|
const int CARD_HEIGHT = 102;
|
||||||
|
|
||||||
|
enum CardItemType {
|
||||||
|
typeCard = QGraphicsItem::UserType + 1,
|
||||||
|
typeCardDrag = QGraphicsItem::UserType + 2,
|
||||||
|
typeZone = QGraphicsItem::UserType + 3,
|
||||||
|
typeOther = QGraphicsItem::UserType + 4
|
||||||
|
};
|
||||||
|
|
||||||
|
class AbstractCardItem : public QObject, public AbstractGraphicsItem {
|
||||||
|
Q_OBJECT
|
||||||
|
protected:
|
||||||
|
CardInfo *info;
|
||||||
|
QString name;
|
||||||
|
bool tapped;
|
||||||
|
private slots:
|
||||||
|
void pixmapUpdated();
|
||||||
|
public:
|
||||||
|
enum { Type = typeCard };
|
||||||
|
int type() const { return Type; }
|
||||||
|
AbstractCardItem(const QString &_name = QString(), QGraphicsItem *parent = 0);
|
||||||
|
~AbstractCardItem();
|
||||||
|
QRectF boundingRect() const;
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
CardInfo *getInfo() const { return info; }
|
||||||
|
QString getName() const { return name; }
|
||||||
|
void setName(const QString &_name = QString());
|
||||||
|
bool getTapped() const { return tapped; }
|
||||||
|
void setTapped(bool _tapped);
|
||||||
|
protected:
|
||||||
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
||||||
|
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -11,126 +11,24 @@
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
CardItem::CardItem(const QString &_name, int _cardid, QGraphicsItem *parent)
|
CardItem::CardItem(const QString &_name, int _cardid, QGraphicsItem *parent)
|
||||||
: AbstractGraphicsItem(parent), info(db->getCard(_name)), name(_name), id(_cardid), tapped(false), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL)
|
: AbstractCardItem(_name, parent), id(_cardid), attacking(false), facedown(false), counters(0), doesntUntap(false), dragItem(NULL)
|
||||||
{
|
{
|
||||||
setCursor(Qt::OpenHandCursor);
|
|
||||||
setFlag(ItemIsSelectable);
|
|
||||||
setAcceptsHoverEvents(true);
|
|
||||||
setCacheMode(DeviceCoordinateCache);
|
|
||||||
|
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CardItem::~CardItem()
|
CardItem::~CardItem()
|
||||||
{
|
{
|
||||||
deleteDragItem();
|
deleteDragItem();
|
||||||
qDebug(QString("CardItem destructor: %1").arg(name).toLatin1());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRectF CardItem::boundingRect() const
|
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||||
{
|
|
||||||
return QRectF(0, 0, CARD_WIDTH, CARD_HEIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardItem::pixmapUpdated()
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget */*widget*/)
|
|
||||||
{
|
{
|
||||||
painter->save();
|
painter->save();
|
||||||
|
AbstractCardItem::paint(painter, option, widget);
|
||||||
QSizeF translatedSize = option->matrix.mapRect(boundingRect()).size();
|
|
||||||
if (tapped)
|
|
||||||
translatedSize.transpose();
|
|
||||||
QPixmap *translatedPixmap = info->getPixmap(translatedSize.toSize());
|
|
||||||
painter->save();
|
|
||||||
if (translatedPixmap) {
|
|
||||||
painter->resetTransform();
|
|
||||||
if (tapped) {
|
|
||||||
painter->translate(((qreal) translatedSize.height()) / 2, ((qreal) translatedSize.width()) / 2);
|
|
||||||
painter->rotate(90);
|
|
||||||
painter->translate(-((qreal) translatedSize.width()) / 2, -((qreal) translatedSize.height()) / 2);
|
|
||||||
}
|
|
||||||
painter->drawPixmap(translatedPixmap->rect(), *translatedPixmap, translatedPixmap->rect());
|
|
||||||
} else {
|
|
||||||
QFont f("Serif");
|
|
||||||
f.setStyleHint(QFont::Serif);
|
|
||||||
f.setPixelSize(11);
|
|
||||||
painter->setFont(f);
|
|
||||||
painter->setBrush(QColor(230, 230, 230));
|
|
||||||
qDebug() <<"COLORS:::::" << info->getColors();
|
|
||||||
QString color;
|
|
||||||
QPen pen;
|
|
||||||
if(!info->getColors().empty())
|
|
||||||
{
|
|
||||||
color = info->getColors().first();
|
|
||||||
if(color == "B")
|
|
||||||
painter->setBrush(QColor(0,0,0));
|
|
||||||
if(color == "U")
|
|
||||||
painter->setBrush(QColor(0,140,180));
|
|
||||||
if(color == "W")
|
|
||||||
painter->setBrush(QColor(255,250,140));
|
|
||||||
if(color == "R")
|
|
||||||
painter->setBrush(QColor(230,0,0));
|
|
||||||
if(color == "G")
|
|
||||||
painter->setBrush(QColor(0,160,0));
|
|
||||||
if(info->getColors().size() > 1)
|
|
||||||
{
|
|
||||||
painter->setBrush(QColor(250,190,30));
|
|
||||||
color = "M"; // Multicolor
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
painter->setPen(Qt::black);
|
|
||||||
|
|
||||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
|
||||||
|
|
||||||
pen.setWidth(3);
|
|
||||||
painter->setPen(pen);
|
|
||||||
painter->drawRect(QRectF(3, 3, CARD_WIDTH - 6, CARD_HEIGHT - 6));
|
|
||||||
painter->setPen(Qt::white);
|
|
||||||
if(color == "W" || color == "" || color == "M")
|
|
||||||
painter->setPen(Qt::black);
|
|
||||||
painter->drawText(QRectF(5, 5, CARD_WIDTH - 15, CARD_HEIGHT - 15), Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, name);
|
|
||||||
if(info->getCardType().contains("Creature"))
|
|
||||||
{
|
|
||||||
painter->drawText(QRectF(CARD_WIDTH - 40, CARD_HEIGHT - 25, 30, 30), Qt::AlignTop | Qt::AlignRight | Qt::TextWordWrap, info->getPowTough());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
painter->restore();
|
|
||||||
|
|
||||||
if (isSelected()) {
|
|
||||||
painter->setPen(Qt::red);
|
|
||||||
painter->drawRect(QRectF(0.5, 0.5, CARD_WIDTH - 1, CARD_HEIGHT - 1));
|
|
||||||
}
|
|
||||||
if (counters)
|
if (counters)
|
||||||
paintNumberEllipse(counters, painter);
|
paintNumberEllipse(counters, painter);
|
||||||
|
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::setName(const QString &_name)
|
|
||||||
{
|
|
||||||
disconnect(info, 0, this, 0);
|
|
||||||
name = _name;
|
|
||||||
info = db->getCard(name);
|
|
||||||
connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated()));
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardItem::setTapped(bool _tapped)
|
|
||||||
{
|
|
||||||
tapped = _tapped;
|
|
||||||
if (tapped)
|
|
||||||
setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(90).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2));
|
|
||||||
else
|
|
||||||
setTransform(QTransform());
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardItem::setAttacking(bool _attacking)
|
void CardItem::setAttacking(bool _attacking)
|
||||||
{
|
{
|
||||||
attacking = _attacking;
|
attacking = _attacking;
|
||||||
|
@ -189,17 +87,6 @@ void CardItem::deleteDragItem()
|
||||||
dragItem = NULL;
|
dragItem = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CardItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
|
||||||
{
|
|
||||||
if (!isSelected()) {
|
|
||||||
scene()->clearSelection();
|
|
||||||
setSelected(true);
|
|
||||||
}
|
|
||||||
if (event->button() == Qt::LeftButton)
|
|
||||||
setCursor(Qt::ClosedHandCursor);
|
|
||||||
event->accept();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
void CardItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->buttons().testFlag(Qt::RightButton)) {
|
if (event->buttons().testFlag(Qt::RightButton)) {
|
||||||
|
@ -278,16 +165,3 @@ void CardItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
|
||||||
((Game *) ((CardZone *) parentItem())->getPlayer()->parent())->hoverCardEvent(this);
|
((Game *) ((CardZone *) parentItem())->getPlayer()->parent())->hoverCardEvent(this);
|
||||||
QGraphicsItem::hoverEnterEvent(event);
|
QGraphicsItem::hoverEnterEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CardItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
|
|
||||||
{
|
|
||||||
if (change == ItemSelectedChange) {
|
|
||||||
// XXX
|
|
||||||
return value;
|
|
||||||
} else if (change == ItemSelectedHasChanged) {
|
|
||||||
qDebug("selection changed");
|
|
||||||
update();
|
|
||||||
return value;
|
|
||||||
} else
|
|
||||||
return QGraphicsItem::itemChange(change, value);
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,32 +1,18 @@
|
||||||
#ifndef CARDITEM_H
|
#ifndef CARDITEM_H
|
||||||
#define CARDITEM_H
|
#define CARDITEM_H
|
||||||
|
|
||||||
#include "abstractgraphicsitem.h"
|
#include "abstractcarditem.h"
|
||||||
|
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class CardDragItem;
|
class CardDragItem;
|
||||||
class CardZone;
|
class CardZone;
|
||||||
class CardInfo;
|
|
||||||
|
|
||||||
const int CARD_WIDTH = 72;
|
|
||||||
const int CARD_HEIGHT = 102;
|
|
||||||
|
|
||||||
const int MAX_COUNTERS_ON_CARD = 999;
|
const int MAX_COUNTERS_ON_CARD = 999;
|
||||||
|
|
||||||
enum CardItemType {
|
class CardItem : public AbstractCardItem {
|
||||||
typeCard = QGraphicsItem::UserType + 1,
|
|
||||||
typeCardDrag = QGraphicsItem::UserType + 2,
|
|
||||||
typeZone = QGraphicsItem::UserType + 3,
|
|
||||||
typeOther = QGraphicsItem::UserType + 4
|
|
||||||
};
|
|
||||||
|
|
||||||
class CardItem : public QObject, public AbstractGraphicsItem {
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
CardInfo *info;
|
|
||||||
QString name;
|
|
||||||
int id;
|
int id;
|
||||||
bool tapped;
|
|
||||||
bool attacking;
|
bool attacking;
|
||||||
bool facedown;
|
bool facedown;
|
||||||
int counters;
|
int counters;
|
||||||
|
@ -34,23 +20,16 @@ private:
|
||||||
bool doesntUntap;
|
bool doesntUntap;
|
||||||
QPoint gridPoint;
|
QPoint gridPoint;
|
||||||
CardDragItem *dragItem;
|
CardDragItem *dragItem;
|
||||||
private slots:
|
|
||||||
void pixmapUpdated();
|
|
||||||
public:
|
public:
|
||||||
enum { Type = typeCard };
|
enum { Type = typeCard };
|
||||||
int type() const { return Type; }
|
int type() const { return Type; }
|
||||||
CardItem(const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0);
|
CardItem(const QString &_name = QString(), int _cardid = -1, QGraphicsItem *parent = 0);
|
||||||
~CardItem();
|
~CardItem();
|
||||||
QRectF boundingRect() const;
|
|
||||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
QPoint getGridPoint() const { return gridPoint; }
|
QPoint getGridPoint() const { return gridPoint; }
|
||||||
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
void setGridPoint(const QPoint &_gridPoint) { gridPoint = _gridPoint; }
|
||||||
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; }
|
|
||||||
void setName(const QString &_name = QString());
|
|
||||||
bool getTapped() const { return tapped; }
|
|
||||||
void setTapped(bool _tapped);
|
|
||||||
bool getAttacking() const { return attacking; }
|
bool getAttacking() const { return attacking; }
|
||||||
void setAttacking(bool _attacking);
|
void setAttacking(bool _attacking);
|
||||||
bool getFaceDown() const { return facedown; }
|
bool getFaceDown() const { return facedown; }
|
||||||
|
@ -66,12 +45,10 @@ public:
|
||||||
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
CardDragItem *createDragItem(int _id, const QPointF &_pos, const QPointF &_scenePos, bool faceDown);
|
||||||
void deleteDragItem();
|
void deleteDragItem();
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
|
||||||
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
||||||
QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
168
cockatrice/src/deckview.cpp
Normal file
168
cockatrice/src/deckview.cpp
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
#include <QtGui>
|
||||||
|
#include "deckview.h"
|
||||||
|
#include "decklist.h"
|
||||||
|
#include "carddatabase.h"
|
||||||
|
#include "main.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
DeckViewCard::DeckViewCard(const QString &_name, QGraphicsItem *parent)
|
||||||
|
: AbstractCardItem(_name, parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckViewCardContainer::DeckViewCardContainer(const QString &_name)
|
||||||
|
: QGraphicsItem(), name(_name), width(0), height(0)
|
||||||
|
{
|
||||||
|
QSettings settings;
|
||||||
|
QString bgPath = settings.value("zonebg/table").toString();
|
||||||
|
if (!bgPath.isEmpty())
|
||||||
|
bgPixmap.load(bgPath);
|
||||||
|
|
||||||
|
setCacheMode(DeviceCoordinateCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF DeckViewCardContainer::boundingRect() const
|
||||||
|
{
|
||||||
|
return QRectF(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCardContainer::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
|
||||||
|
{
|
||||||
|
if (bgPixmap.isNull())
|
||||||
|
painter->fillRect(boundingRect(), QColor(0, 0, 100));
|
||||||
|
else
|
||||||
|
painter->fillRect(boundingRect(), QBrush(bgPixmap));
|
||||||
|
painter->setPen(QColor(255, 255, 255, 100));
|
||||||
|
painter->drawLine(QPointF(0, separatorY), QPointF(width, separatorY));
|
||||||
|
|
||||||
|
painter->setPen(QColor(Qt::white));
|
||||||
|
QFont f("Serif");
|
||||||
|
f.setStyleHint(QFont::Serif);
|
||||||
|
f.setPixelSize(24);
|
||||||
|
f.setWeight(QFont::Bold);
|
||||||
|
painter->setFont(f);
|
||||||
|
painter->drawText(10, 0, width - 20, separatorY, Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, InnerDecklistNode::visibleNameFromName(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCardContainer::addCard(DeckViewCard *card)
|
||||||
|
{
|
||||||
|
cards.insertMulti(card->getInfo()->getMainCardType(), card);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCardContainer::rearrangeItems()
|
||||||
|
{
|
||||||
|
separatorY = 30;
|
||||||
|
|
||||||
|
QList<QString> cardTypeList = cards.uniqueKeys();
|
||||||
|
int rows = cardTypeList.size();
|
||||||
|
int cols = 0;
|
||||||
|
for (int i = 0; i < rows; ++i) {
|
||||||
|
QList<DeckViewCard *> row = cards.values(cardTypeList[i]);
|
||||||
|
if (row.size() > cols)
|
||||||
|
cols = row.size();
|
||||||
|
for (int j = 0; j < row.size(); ++j) {
|
||||||
|
DeckViewCard *card = row[j];
|
||||||
|
card->setPos(j * CARD_WIDTH, separatorY + 10 + i * (CARD_HEIGHT + rowSpacing));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prepareGeometryChange();
|
||||||
|
width = cols * CARD_WIDTH;
|
||||||
|
height = separatorY + 10 + rows * CARD_HEIGHT + rowSpacing * (rows - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewCardContainer::setWidth(qreal _width)
|
||||||
|
{
|
||||||
|
prepareGeometryChange();
|
||||||
|
width = _width;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckViewScene::DeckViewScene(QObject *parent)
|
||||||
|
: QGraphicsScene(parent), deck(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckViewScene::~DeckViewScene()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewScene::setDeck(DeckList *_deck)
|
||||||
|
{
|
||||||
|
deck = _deck;
|
||||||
|
rebuildTree();
|
||||||
|
rearrangeItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewScene::rebuildTree()
|
||||||
|
{
|
||||||
|
InnerDecklistNode *listRoot = deck->getRoot();
|
||||||
|
for (int i = 0; i < listRoot->size(); i++) {
|
||||||
|
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||||
|
|
||||||
|
DeckViewCardContainer *container = cardContainers.value(currentZone->getName(), 0);
|
||||||
|
if (!container) {
|
||||||
|
container = new DeckViewCardContainer(currentZone->getName());
|
||||||
|
cardContainers.insert(currentZone->getName(), container);
|
||||||
|
addItem(container);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = 0; j < currentZone->size(); j++) {
|
||||||
|
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||||
|
if (!currentCard)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int k = 0; k < currentCard->getNumber(); ++k)
|
||||||
|
container->addCard(new DeckViewCard(currentCard->getName(), container));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckViewScene::rearrangeItems()
|
||||||
|
{
|
||||||
|
const int spacing = CARD_HEIGHT / 3;
|
||||||
|
QList<DeckViewCardContainer *> contList = cardContainers.values();
|
||||||
|
qreal totalHeight = -spacing;
|
||||||
|
qreal totalWidth = 0;
|
||||||
|
for (int i = 0; i < contList.size(); ++i) {
|
||||||
|
DeckViewCardContainer *c = contList[i];
|
||||||
|
c->rearrangeItems();
|
||||||
|
c->setPos(0, totalHeight + spacing);
|
||||||
|
totalHeight += c->boundingRect().height() + spacing;
|
||||||
|
if (c->boundingRect().width() > totalWidth)
|
||||||
|
totalWidth = c->boundingRect().width();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < contList.size(); ++i)
|
||||||
|
contList[i]->setWidth(totalWidth);
|
||||||
|
|
||||||
|
setSceneRect(QRectF(0, 0, totalWidth, totalHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
DeckView::DeckView(QWidget *parent)
|
||||||
|
: QGraphicsView(parent)
|
||||||
|
{
|
||||||
|
deckViewScene = new DeckViewScene(this);
|
||||||
|
|
||||||
|
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
|
||||||
|
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing/* | QPainter::SmoothPixmapTransform*/);
|
||||||
|
setScene(deckViewScene);
|
||||||
|
|
||||||
|
connect(deckViewScene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckView::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QGraphicsView::resizeEvent(event);
|
||||||
|
updateSceneRect(scene()->sceneRect());
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckView::updateSceneRect(const QRectF &rect)
|
||||||
|
{
|
||||||
|
qDebug(QString("deckView::updateSceneRect = %1,%2").arg(rect.width()).arg(rect.height()).toLatin1());
|
||||||
|
fitInView(rect, Qt::KeepAspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeckView::setDeck(DeckList *_deck)
|
||||||
|
{
|
||||||
|
deckViewScene->setDeck(_deck);
|
||||||
|
}
|
62
cockatrice/src/deckview.h
Normal file
62
cockatrice/src/deckview.h
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
#ifndef DECKVIEW_H
|
||||||
|
#define DECKVIEW_H
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include "carditem.h"
|
||||||
|
|
||||||
|
class DeckList;
|
||||||
|
class InnerDecklistNode;
|
||||||
|
class CardInfo;
|
||||||
|
|
||||||
|
class DeckViewCard : public AbstractCardItem {
|
||||||
|
public:
|
||||||
|
DeckViewCard(const QString &_name = QString(), QGraphicsItem *parent = 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeckViewCardContainer : public QGraphicsItem {
|
||||||
|
private:
|
||||||
|
QString name;
|
||||||
|
QMap<QString, DeckViewCard *> cards;
|
||||||
|
qreal width, height;
|
||||||
|
qreal separatorY;
|
||||||
|
QPixmap bgPixmap;
|
||||||
|
static const int rowSpacing = 5;
|
||||||
|
public:
|
||||||
|
DeckViewCardContainer(const QString &_name);
|
||||||
|
QRectF boundingRect() const;
|
||||||
|
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
|
||||||
|
void addCard(DeckViewCard *card);
|
||||||
|
void rearrangeItems();
|
||||||
|
void setWidth(qreal _width);
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeckViewScene : public QGraphicsScene {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
DeckList *deck;
|
||||||
|
QMap<QString, DeckViewCardContainer *> cardContainers;
|
||||||
|
void rebuildTree();
|
||||||
|
void rearrangeItems();
|
||||||
|
public:
|
||||||
|
DeckViewScene(QObject *parent = 0);
|
||||||
|
~DeckViewScene();
|
||||||
|
void setDeck(DeckList *_deck);
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeckView : public QGraphicsView {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
DeckViewScene *deckViewScene;
|
||||||
|
protected:
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
|
public slots:
|
||||||
|
void updateSceneRect(const QRectF &rect);
|
||||||
|
public:
|
||||||
|
DeckView(QWidget *parent = 0);
|
||||||
|
void setDeck(DeckList *_deck);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -212,6 +212,7 @@ Player::~Player()
|
||||||
|
|
||||||
void Player::updateBoundingRect()
|
void Player::updateBoundingRect()
|
||||||
{
|
{
|
||||||
|
// XXX! PREPARE GEOMETRY CHANGE
|
||||||
bRect = QRectF(0, 0, CARD_WIDTH + 5 + counterAreaWidth + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height());
|
bRect = QRectF(0, 0, CARD_WIDTH + 5 + counterAreaWidth + hand->boundingRect().width() + table->boundingRect().width(), table->boundingRect().height());
|
||||||
emit sizeChanged();
|
emit sizeChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@ TabChatChannel::TabChatChannel(Client *_client, const QString &_channelName)
|
||||||
setLayout(hbox);
|
setLayout(hbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabChatChannel::retranslateUi()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void TabChatChannel::sendMessage()
|
void TabChatChannel::sendMessage()
|
||||||
{
|
{
|
||||||
if (sayEdit->text().isEmpty())
|
if (sayEdit->text().isEmpty())
|
||||||
|
|
|
@ -31,6 +31,7 @@ private slots:
|
||||||
void processSayEvent(Event_ChatSay *event);
|
void processSayEvent(Event_ChatSay *event);
|
||||||
public:
|
public:
|
||||||
TabChatChannel(Client *_client, const QString &_channelName);
|
TabChatChannel(Client *_client, const QString &_channelName);
|
||||||
|
void retranslateUi();
|
||||||
void processChatEvent(ChatEvent *event);
|
void processChatEvent(ChatEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -177,9 +177,8 @@ void TabDeckStorage::actUpload()
|
||||||
curRight = curRight->parent();
|
curRight = curRight->parent();
|
||||||
if (curRight)
|
if (curRight)
|
||||||
targetPath = curRight->data(0, Qt::UserRole).toString();
|
targetPath = curRight->data(0, Qt::UserRole).toString();
|
||||||
qDebug() << "targetPath:" << targetPath;
|
|
||||||
|
|
||||||
Command_DeckUpload *command = new Command_DeckUpload(-1, deck, targetPath);
|
Command_DeckUpload *command = new Command_DeckUpload(deck, targetPath);
|
||||||
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *)));
|
connect(command, SIGNAL(finished(ProtocolResponse *)), this, SLOT(uploadFinished(ProtocolResponse *)));
|
||||||
client->sendCommand(command);
|
client->sendCommand(command);
|
||||||
}
|
}
|
||||||
|
@ -190,6 +189,7 @@ void TabDeckStorage::uploadFinished(ProtocolResponse *r)
|
||||||
if (!resp)
|
if (!resp)
|
||||||
return;
|
return;
|
||||||
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
|
Command_DeckUpload *cmd = static_cast<Command_DeckUpload *>(sender());
|
||||||
|
delete cmd->getDeck();
|
||||||
|
|
||||||
QTreeWidgetItemIterator it(serverDirView);
|
QTreeWidgetItemIterator it(serverDirView);
|
||||||
while (*it) {
|
while (*it) {
|
||||||
|
@ -264,7 +264,6 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
|
||||||
QTreeWidgetItemIterator it(serverDirView);
|
QTreeWidgetItemIterator it(serverDirView);
|
||||||
while (*it) {
|
while (*it) {
|
||||||
if ((*it)->data(0, Qt::UserRole) == cmd->getPath()) {
|
if ((*it)->data(0, Qt::UserRole) == cmd->getPath()) {
|
||||||
qDebug() << "gefunden";
|
|
||||||
QFileIconProvider fip;
|
QFileIconProvider fip;
|
||||||
QTreeWidgetItem *newItem = new QTreeWidgetItem(TWIFolderType);
|
QTreeWidgetItem *newItem = new QTreeWidgetItem(TWIFolderType);
|
||||||
newItem->setIcon(0, fip.icon(QFileIconProvider::Folder));
|
newItem->setIcon(0, fip.icon(QFileIconProvider::Folder));
|
||||||
|
@ -272,8 +271,7 @@ void TabDeckStorage::newFolderFinished(ResponseCode resp)
|
||||||
newItem->setData(0, Qt::UserRole, cmd->getPath() + "/" + cmd->getDirName());
|
newItem->setData(0, Qt::UserRole, cmd->getPath() + "/" + cmd->getDirName());
|
||||||
(*it)->addChild(newItem);
|
(*it)->addChild(newItem);
|
||||||
break;
|
break;
|
||||||
} else
|
}
|
||||||
qDebug() << "path = " << (*it)->data(0, Qt::UserRole) << " nicht gefunden";
|
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include "zoneviewzone.h"
|
#include "zoneviewzone.h"
|
||||||
#include "zoneviewwidget.h"
|
#include "zoneviewwidget.h"
|
||||||
#include "zoneviewlayout.h"
|
#include "zoneviewlayout.h"
|
||||||
|
#include "deckview.h"
|
||||||
|
#include "decklist.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
TabGame::TabGame(Client *_client, int _gameId)
|
TabGame::TabGame(Client *_client, int _gameId)
|
||||||
|
@ -17,7 +19,15 @@ TabGame::TabGame(Client *_client, int _gameId)
|
||||||
{
|
{
|
||||||
zoneLayout = new ZoneViewLayout;
|
zoneLayout = new ZoneViewLayout;
|
||||||
scene = new GameScene(zoneLayout, this);
|
scene = new GameScene(zoneLayout, this);
|
||||||
view = new GameView(scene);
|
gameView = new GameView(scene);
|
||||||
|
gameView->hide();
|
||||||
|
|
||||||
|
deckView = new DeckView;
|
||||||
|
|
||||||
|
DeckList *foo = new DeckList;
|
||||||
|
foo->loadFromFile("/home/brukie/cockatrice/decks/adfb.cod", DeckList::CockatriceFormat);
|
||||||
|
deckView->setDeck(foo);
|
||||||
|
// deckView->hide();
|
||||||
|
|
||||||
cardInfo = new CardInfoWidget(db);
|
cardInfo = new CardInfoWidget(db);
|
||||||
messageLog = new MessageLogWidget;
|
messageLog = new MessageLogWidget;
|
||||||
|
@ -30,6 +40,7 @@ TabGame::TabGame(Client *_client, int _gameId)
|
||||||
hLayout->addWidget(sayEdit);
|
hLayout->addWidget(sayEdit);
|
||||||
|
|
||||||
phasesToolbar = new PhasesToolbar;
|
phasesToolbar = new PhasesToolbar;
|
||||||
|
phasesToolbar->hide();
|
||||||
|
|
||||||
QVBoxLayout *verticalLayout = new QVBoxLayout;
|
QVBoxLayout *verticalLayout = new QVBoxLayout;
|
||||||
verticalLayout->addWidget(cardInfo);
|
verticalLayout->addWidget(cardInfo);
|
||||||
|
@ -38,11 +49,14 @@ TabGame::TabGame(Client *_client, int _gameId)
|
||||||
|
|
||||||
QHBoxLayout *mainLayout = new QHBoxLayout;
|
QHBoxLayout *mainLayout = new QHBoxLayout;
|
||||||
mainLayout->addWidget(phasesToolbar);
|
mainLayout->addWidget(phasesToolbar);
|
||||||
mainLayout->addWidget(view, 10);
|
mainLayout->addWidget(gameView, 10);
|
||||||
|
mainLayout->addWidget(deckView, 10);
|
||||||
mainLayout->addLayout(verticalLayout);
|
mainLayout->addLayout(verticalLayout);
|
||||||
|
|
||||||
setLayout(mainLayout);
|
aCloseMostRecentZoneView = new QAction(this);
|
||||||
|
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), zoneLayout, SLOT(closeMostRecentZoneView()));
|
||||||
|
addAction(aCloseMostRecentZoneView);
|
||||||
|
|
||||||
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
|
connect(sayEdit, SIGNAL(returnPressed()), this, SLOT(actSay()));
|
||||||
|
|
||||||
// connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int)));
|
// connect(client, SIGNAL(maxPingTime(int, int)), pingWidget, SLOT(setPercentage(int, int)));
|
||||||
|
@ -60,7 +74,21 @@ TabGame::TabGame(Client *_client, int _gameId)
|
||||||
messageLog->connectToGame(game);
|
messageLog->connectToGame(game);
|
||||||
|
|
||||||
game->queryGameState();
|
game->queryGameState();
|
||||||
*/}
|
*/
|
||||||
|
retranslateUi();
|
||||||
|
setLayout(mainLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabGame::retranslateUi()
|
||||||
|
{
|
||||||
|
sayLabel->setText(tr("&Say:"));
|
||||||
|
cardInfo->retranslateUi();
|
||||||
|
// if (game)
|
||||||
|
// game->retranslateUi();
|
||||||
|
zoneLayout->retranslateUi();
|
||||||
|
aCloseMostRecentZoneView->setText(tr("Close most recent zone view"));
|
||||||
|
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
|
||||||
|
}
|
||||||
|
|
||||||
void TabGame::processGameEvent(GameEvent *event)
|
void TabGame::processGameEvent(GameEvent *event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,7 @@ class Client;
|
||||||
class CardDatabase;
|
class CardDatabase;
|
||||||
class GameEvent;
|
class GameEvent;
|
||||||
class GameView;
|
class GameView;
|
||||||
|
class DeckView;
|
||||||
class GameScene;
|
class GameScene;
|
||||||
class Game;
|
class Game;
|
||||||
class CardInfoWidget;
|
class CardInfoWidget;
|
||||||
|
@ -30,12 +31,15 @@ private:
|
||||||
QLineEdit *sayEdit;
|
QLineEdit *sayEdit;
|
||||||
PhasesToolbar *phasesToolbar;
|
PhasesToolbar *phasesToolbar;
|
||||||
GameScene *scene;
|
GameScene *scene;
|
||||||
GameView *view;
|
GameView *gameView;
|
||||||
|
DeckView *deckView;
|
||||||
Game *game;
|
Game *game;
|
||||||
ZoneViewLayout *zoneLayout;
|
ZoneViewLayout *zoneLayout;
|
||||||
|
QAction *aCloseMostRecentZoneView;
|
||||||
private slots:
|
private slots:
|
||||||
public:
|
public:
|
||||||
TabGame(Client *_client, int _gameId);
|
TabGame(Client *_client, int _gameId);
|
||||||
|
void retranslateUi();
|
||||||
void processGameEvent(GameEvent *event);
|
void processGameEvent(GameEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -244,3 +244,10 @@ TabServer::TabServer(Client *_client, QWidget *parent)
|
||||||
|
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TabServer::retranslateUi()
|
||||||
|
{
|
||||||
|
gameSelector->retranslateUi();
|
||||||
|
chatChannelSelector->retranslateUi();
|
||||||
|
serverMessageLog->retranslateUi();
|
||||||
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ private:
|
||||||
ServerMessageLog *serverMessageLog;
|
ServerMessageLog *serverMessageLog;
|
||||||
public:
|
public:
|
||||||
TabServer(Client *_client, QWidget *parent = 0);
|
TabServer(Client *_client, QWidget *parent = 0);
|
||||||
|
void retranslateUi();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,10 +14,22 @@ TabSupervisor:: TabSupervisor(QWidget *parent)
|
||||||
|
|
||||||
void TabSupervisor::retranslateUi()
|
void TabSupervisor::retranslateUi()
|
||||||
{
|
{
|
||||||
if (tabServer)
|
if (tabServer) {
|
||||||
setTabText(0, tr("Server"));
|
setTabText(0, tr("Server"));
|
||||||
if (tabDeckStorage)
|
tabServer->retranslateUi();
|
||||||
|
}
|
||||||
|
if (tabDeckStorage) {
|
||||||
setTabText(1, tr("Deck storage"));
|
setTabText(1, tr("Deck storage"));
|
||||||
|
tabDeckStorage->retranslateUi();
|
||||||
|
}
|
||||||
|
|
||||||
|
QMapIterator<QString, TabChatChannel *> chatChannelIterator(chatChannelTabs);
|
||||||
|
while (chatChannelIterator.hasNext())
|
||||||
|
chatChannelIterator.next().value()->retranslateUi();
|
||||||
|
|
||||||
|
QMapIterator<int, TabGame *> gameIterator(gameTabs);
|
||||||
|
while (gameIterator.hasNext())
|
||||||
|
gameIterator.next().value()->retranslateUi();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabSupervisor::start(Client *_client)
|
void TabSupervisor::start(Client *_client)
|
||||||
|
@ -28,7 +40,6 @@ void TabSupervisor::start(Client *_client)
|
||||||
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
|
connect(client, SIGNAL(gameJoinedEventReceived(Event_GameJoined *)), this, SLOT(gameJoined(Event_GameJoined *)));
|
||||||
|
|
||||||
tabServer = new TabServer(client);
|
tabServer = new TabServer(client);
|
||||||
connect(tabServer, SIGNAL(gameJoined(int)), this, SLOT(addGameTab(int)));
|
|
||||||
connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &)));
|
connect(tabServer, SIGNAL(chatChannelJoined(const QString &)), this, SLOT(addChatChannelTab(const QString &)));
|
||||||
addTab(tabServer, QString());
|
addTab(tabServer, QString());
|
||||||
|
|
||||||
|
|
|
@ -201,20 +201,9 @@ void MainWindow::retranslateUi()
|
||||||
aFullScreen->setShortcut(tr("Ctrl+F"));
|
aFullScreen->setShortcut(tr("Ctrl+F"));
|
||||||
aSettings->setText(tr("&Settings..."));
|
aSettings->setText(tr("&Settings..."));
|
||||||
aExit->setText(tr("&Exit"));
|
aExit->setText(tr("&Exit"));
|
||||||
aCloseMostRecentZoneView->setText(tr("Close most recent zone view"));
|
|
||||||
aCloseMostRecentZoneView->setShortcut(tr("Esc"));
|
|
||||||
|
|
||||||
cockatriceMenu->setTitle(tr("&Cockatrice"));
|
cockatriceMenu->setTitle(tr("&Cockatrice"));
|
||||||
/*
|
}
|
||||||
sayLabel->setText(tr("&Say:"));
|
|
||||||
|
|
||||||
cardInfo->retranslateUi();
|
|
||||||
chatWidget->retranslateUi();
|
|
||||||
gameSelector->retranslateUi();
|
|
||||||
if (game)
|
|
||||||
game->retranslateUi();
|
|
||||||
zoneLayout->retranslateUi();
|
|
||||||
*/}
|
|
||||||
|
|
||||||
void MainWindow::createActions()
|
void MainWindow::createActions()
|
||||||
{
|
{
|
||||||
|
@ -238,10 +227,6 @@ void MainWindow::createActions()
|
||||||
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
|
connect(aSettings, SIGNAL(triggered()), this, SLOT(actSettings()));
|
||||||
aExit = new QAction(this);
|
aExit = new QAction(this);
|
||||||
connect(aExit, SIGNAL(triggered()), this, SLOT(actExit()));
|
connect(aExit, SIGNAL(triggered()), this, SLOT(actExit()));
|
||||||
|
|
||||||
aCloseMostRecentZoneView = new QAction(this);
|
|
||||||
// connect(aCloseMostRecentZoneView, SIGNAL(triggered()), zoneLayout, SLOT(closeMostRecentZoneView()));
|
|
||||||
addAction(aCloseMostRecentZoneView);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::createMenus()
|
void MainWindow::createMenus()
|
||||||
|
|
|
@ -61,7 +61,6 @@ private:
|
||||||
void createMenus();
|
void createMenus();
|
||||||
QMenu *cockatriceMenu;
|
QMenu *cockatriceMenu;
|
||||||
QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
|
QAction *aConnect, *aDisconnect, *aDeckEditor, *aFullScreen, *aSettings, *aExit;
|
||||||
QAction *aCloseMostRecentZoneView;
|
|
||||||
TabSupervisor *tabSupervisor;
|
TabSupervisor *tabSupervisor;
|
||||||
|
|
||||||
PingWidget *pingWidget;
|
PingWidget *pingWidget;
|
||||||
|
|
|
@ -26,14 +26,19 @@ InnerDecklistNode::~InnerDecklistNode()
|
||||||
clearTree();
|
clearTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString InnerDecklistNode::getVisibleName() const
|
QString InnerDecklistNode::visibleNameFromName(const QString &_name)
|
||||||
{
|
{
|
||||||
if (name == "main")
|
if (_name == "main")
|
||||||
return QObject::tr("Maindeck");
|
return QObject::tr("Maindeck");
|
||||||
else if (name == "side")
|
else if (_name == "side")
|
||||||
return QObject::tr("Sideboard");
|
return QObject::tr("Sideboard");
|
||||||
else
|
else
|
||||||
return getName();
|
return _name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString InnerDecklistNode::getVisibleName() const
|
||||||
|
{
|
||||||
|
return visibleNameFromName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InnerDecklistNode::clearTree()
|
void InnerDecklistNode::clearTree()
|
||||||
|
|
|
@ -39,6 +39,7 @@ public:
|
||||||
virtual ~InnerDecklistNode();
|
virtual ~InnerDecklistNode();
|
||||||
QString getName() const { return name; }
|
QString getName() const { return name; }
|
||||||
void setName(const QString &_name) { name = _name; }
|
void setName(const QString &_name) { name = _name; }
|
||||||
|
static QString visibleNameFromName(const QString &_name);
|
||||||
virtual QString getVisibleName() const;
|
virtual QString getVisibleName() const;
|
||||||
void clearTree();
|
void clearTree();
|
||||||
AbstractDecklistNode *findChild(const QString &name);
|
AbstractDecklistNode *findChild(const QString &name);
|
||||||
|
|
|
@ -66,6 +66,7 @@ void ProtocolItem::initializeHash()
|
||||||
initializeHashAuto();
|
initializeHashAuto();
|
||||||
|
|
||||||
itemNameHash.insert("cmddeck_upload", Command_DeckUpload::newItem);
|
itemNameHash.insert("cmddeck_upload", Command_DeckUpload::newItem);
|
||||||
|
itemNameHash.insert("cmddeck_select", Command_DeckSelect::newItem);
|
||||||
|
|
||||||
itemNameHash.insert("resp", ProtocolResponse::newItem);
|
itemNameHash.insert("resp", ProtocolResponse::newItem);
|
||||||
ProtocolResponse::initializeHash();
|
ProtocolResponse::initializeHash();
|
||||||
|
@ -102,17 +103,12 @@ void Command::processResponse(ProtocolResponse *response)
|
||||||
emit finished(response->getResponseCode());
|
emit finished(response->getResponseCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_DeckUpload::Command_DeckUpload(int _cmdId, DeckList *_deck, const QString &_path)
|
Command_DeckUpload::Command_DeckUpload(DeckList *_deck, const QString &_path)
|
||||||
: Command("deck_upload", _cmdId), deck(_deck), path(_path), readFinished(false)
|
: Command("deck_upload"), deck(_deck), path(_path), readFinished(false)
|
||||||
{
|
{
|
||||||
setParameter("path", path);
|
setParameter("path", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command_DeckUpload::~Command_DeckUpload()
|
|
||||||
{
|
|
||||||
delete deck;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Command_DeckUpload::extractParameters()
|
void Command_DeckUpload::extractParameters()
|
||||||
{
|
{
|
||||||
Command::extractParameters();
|
Command::extractParameters();
|
||||||
|
@ -144,6 +140,45 @@ void Command_DeckUpload::writeElement(QXmlStreamWriter *xml)
|
||||||
deck->writeElement(xml);
|
deck->writeElement(xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command_DeckSelect::Command_DeckSelect(int _gameId, DeckList *_deck, int _deckId)
|
||||||
|
: GameCommand("deck_upload", _gameId), deck(_deck), deckId(_deckId), readFinished(false)
|
||||||
|
{
|
||||||
|
setParameter("deck_id", _deckId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command_DeckSelect::extractParameters()
|
||||||
|
{
|
||||||
|
GameCommand::extractParameters();
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
deckId = parameters["deck_id"].toInt(&ok);
|
||||||
|
if (!ok)
|
||||||
|
deckId = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Command_DeckSelect::readElement(QXmlStreamReader *xml)
|
||||||
|
{
|
||||||
|
if (readFinished)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!deck) {
|
||||||
|
if (xml->isStartElement() && (xml->name() == "cockatrice_deck")) {
|
||||||
|
deck = new DeckList;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deck->readElement(xml))
|
||||||
|
readFinished = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Command_DeckSelect::writeElement(QXmlStreamWriter *xml)
|
||||||
|
{
|
||||||
|
if (deck)
|
||||||
|
deck->writeElement(xml);
|
||||||
|
}
|
||||||
|
|
||||||
QHash<QString, ResponseCode> ProtocolResponse::responseHash;
|
QHash<QString, ResponseCode> ProtocolResponse::responseHash;
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,14 @@ class ProtocolResponse;
|
||||||
class DeckList;
|
class DeckList;
|
||||||
|
|
||||||
enum ItemId {
|
enum ItemId {
|
||||||
ItemId_Command_DeckUpload = ItemId_Other + 1,
|
ItemId_Command_DeckUpload = ItemId_Other + 100,
|
||||||
ItemId_Event_ListChatChannels = ItemId_Other + 2,
|
ItemId_Command_DeckSelect = ItemId_Other + 101,
|
||||||
ItemId_Event_ChatListPlayers = ItemId_Other + 3,
|
ItemId_Event_ListChatChannels = ItemId_Other + 200,
|
||||||
ItemId_Event_ListGames = ItemId_Other + 4,
|
ItemId_Event_ChatListPlayers = ItemId_Other + 201,
|
||||||
ItemId_Response_DeckList = ItemId_Other + 5,
|
ItemId_Event_ListGames = ItemId_Other + 202,
|
||||||
ItemId_Response_DeckDownload = ItemId_Other + 6,
|
ItemId_Response_DeckList = ItemId_Other + 300,
|
||||||
ItemId_Response_DeckUpload = ItemId_Other + 7
|
ItemId_Response_DeckDownload = ItemId_Other + 301,
|
||||||
|
ItemId_Response_DeckUpload = ItemId_Other + 302
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProtocolItem : public QObject {
|
class ProtocolItem : public QObject {
|
||||||
|
@ -138,14 +139,31 @@ protected:
|
||||||
bool readElement(QXmlStreamReader *xml);
|
bool readElement(QXmlStreamReader *xml);
|
||||||
void writeElement(QXmlStreamWriter *xml);
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
public:
|
public:
|
||||||
Command_DeckUpload(int _cmdId = -1, DeckList *_deck = 0, const QString &_path = QString());
|
Command_DeckUpload(DeckList *_deck = 0, const QString &_path = QString());
|
||||||
~Command_DeckUpload();
|
|
||||||
static ProtocolItem *newItem() { return new Command_DeckUpload; }
|
static ProtocolItem *newItem() { return new Command_DeckUpload; }
|
||||||
int getItemId() const { return ItemId_Command_DeckUpload; }
|
int getItemId() const { return ItemId_Command_DeckUpload; }
|
||||||
DeckList *getDeck() const { return deck; }
|
DeckList *getDeck() const { return deck; }
|
||||||
QString getPath() const { return path; }
|
QString getPath() const { return path; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class Command_DeckSelect : public GameCommand {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
DeckList *deck;
|
||||||
|
int deckId;
|
||||||
|
bool readFinished;
|
||||||
|
protected:
|
||||||
|
void extractParameters();
|
||||||
|
bool readElement(QXmlStreamReader *xml);
|
||||||
|
void writeElement(QXmlStreamWriter *xml);
|
||||||
|
public:
|
||||||
|
Command_DeckSelect(int _gameId = -1, DeckList *_deck = 0, int _deckId = -1);
|
||||||
|
static ProtocolItem *newItem() { return new Command_DeckSelect; }
|
||||||
|
int getItemId() const { return ItemId_Command_DeckSelect; }
|
||||||
|
DeckList *getDeck() const { return deck; }
|
||||||
|
int getDeckId() const { return deckId; }
|
||||||
|
};
|
||||||
|
|
||||||
// -----------------
|
// -----------------
|
||||||
// --- RESPONSES ---
|
// --- RESPONSES ---
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
|
@ -33,10 +33,10 @@ ItemId_Command_SetActivePhase = 1031,
|
||||||
ItemId_Command_DumpZone = 1032,
|
ItemId_Command_DumpZone = 1032,
|
||||||
ItemId_Command_StopDumpZone = 1033,
|
ItemId_Command_StopDumpZone = 1033,
|
||||||
ItemId_Command_DumpAll = 1034,
|
ItemId_Command_DumpAll = 1034,
|
||||||
ItemId_Command_SubmitDeck = 1035,
|
ItemId_Event_Say = 1035,
|
||||||
ItemId_Event_Say = 1036,
|
ItemId_Event_Join = 1036,
|
||||||
ItemId_Event_Join = 1037,
|
ItemId_Event_Leave = 1037,
|
||||||
ItemId_Event_Leave = 1038,
|
ItemId_Event_DeckSelect = 1038,
|
||||||
ItemId_Event_GameClosed = 1039,
|
ItemId_Event_GameClosed = 1039,
|
||||||
ItemId_Event_ReadyStart = 1040,
|
ItemId_Event_ReadyStart = 1040,
|
||||||
ItemId_Event_SetupZones = 1041,
|
ItemId_Event_SetupZones = 1041,
|
||||||
|
|
|
@ -347,10 +347,6 @@ Command_DumpAll::Command_DumpAll(int _gameId)
|
||||||
: GameCommand("dump_all", _gameId)
|
: GameCommand("dump_all", _gameId)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
Command_SubmitDeck::Command_SubmitDeck(int _gameId)
|
|
||||||
: GameCommand("submit_deck", _gameId)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
Event_Say::Event_Say(int _gameId, int _playerId, const QString &_message)
|
Event_Say::Event_Say(int _gameId, int _playerId, const QString &_message)
|
||||||
: GameEvent("say", _gameId, _playerId), message(_message)
|
: GameEvent("say", _gameId, _playerId), message(_message)
|
||||||
{
|
{
|
||||||
|
@ -377,6 +373,16 @@ Event_Leave::Event_Leave(int _gameId, int _playerId)
|
||||||
: GameEvent("leave", _gameId, _playerId)
|
: GameEvent("leave", _gameId, _playerId)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
Event_DeckSelect::Event_DeckSelect(int _gameId, int _playerId, int _deckId)
|
||||||
|
: GameEvent("deck_select", _gameId, _playerId), deckId(_deckId)
|
||||||
|
{
|
||||||
|
setParameter("deck_id", deckId);
|
||||||
|
}
|
||||||
|
void Event_DeckSelect::extractParameters()
|
||||||
|
{
|
||||||
|
GameEvent::extractParameters();
|
||||||
|
deckId = parameters["deck_id"].toInt();
|
||||||
|
}
|
||||||
Event_GameClosed::Event_GameClosed(int _gameId, int _playerId)
|
Event_GameClosed::Event_GameClosed(int _gameId, int _playerId)
|
||||||
: GameEvent("game_closed", _gameId, _playerId)
|
: GameEvent("game_closed", _gameId, _playerId)
|
||||||
{
|
{
|
||||||
|
@ -687,10 +693,10 @@ void ProtocolItem::initializeHashAuto()
|
||||||
itemNameHash.insert("cmddump_zone", Command_DumpZone::newItem);
|
itemNameHash.insert("cmddump_zone", Command_DumpZone::newItem);
|
||||||
itemNameHash.insert("cmdstop_dump_zone", Command_StopDumpZone::newItem);
|
itemNameHash.insert("cmdstop_dump_zone", Command_StopDumpZone::newItem);
|
||||||
itemNameHash.insert("cmddump_all", Command_DumpAll::newItem);
|
itemNameHash.insert("cmddump_all", Command_DumpAll::newItem);
|
||||||
itemNameHash.insert("cmdsubmit_deck", Command_SubmitDeck::newItem);
|
|
||||||
itemNameHash.insert("game_eventsay", Event_Say::newItem);
|
itemNameHash.insert("game_eventsay", Event_Say::newItem);
|
||||||
itemNameHash.insert("game_eventjoin", Event_Join::newItem);
|
itemNameHash.insert("game_eventjoin", Event_Join::newItem);
|
||||||
itemNameHash.insert("game_eventleave", Event_Leave::newItem);
|
itemNameHash.insert("game_eventleave", Event_Leave::newItem);
|
||||||
|
itemNameHash.insert("game_eventdeck_select", Event_DeckSelect::newItem);
|
||||||
itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem);
|
itemNameHash.insert("game_eventgame_closed", Event_GameClosed::newItem);
|
||||||
itemNameHash.insert("game_eventready_start", Event_ReadyStart::newItem);
|
itemNameHash.insert("game_eventready_start", Event_ReadyStart::newItem);
|
||||||
itemNameHash.insert("game_eventsetup_zones", Event_SetupZones::newItem);
|
itemNameHash.insert("game_eventsetup_zones", Event_SetupZones::newItem);
|
||||||
|
|
|
@ -32,10 +32,10 @@
|
||||||
2:dump_zone:i,player_id:s,zone_name:i,number_cards
|
2:dump_zone:i,player_id:s,zone_name:i,number_cards
|
||||||
2:stop_dump_zone:i,player_id:s,zone_name
|
2:stop_dump_zone:i,player_id:s,zone_name
|
||||||
2:dump_all
|
2:dump_all
|
||||||
2:submit_deck
|
|
||||||
3:say:s,message
|
3:say:s,message
|
||||||
3:join:s,player_name:b,spectator
|
3:join:s,player_name:b,spectator
|
||||||
3:leave
|
3:leave
|
||||||
|
3:deck_select:i,deck_id
|
||||||
3:game_closed
|
3:game_closed
|
||||||
3:ready_start
|
3:ready_start
|
||||||
3:setup_zones:i,deck_size:i,sb_size
|
3:setup_zones:i,deck_size:i,sb_size
|
||||||
|
|
|
@ -437,14 +437,6 @@ public:
|
||||||
static ProtocolItem *newItem() { return new Command_DumpAll; }
|
static ProtocolItem *newItem() { return new Command_DumpAll; }
|
||||||
int getItemId() const { return ItemId_Command_DumpAll; }
|
int getItemId() const { return ItemId_Command_DumpAll; }
|
||||||
};
|
};
|
||||||
class Command_SubmitDeck : public GameCommand {
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
public:
|
|
||||||
Command_SubmitDeck(int _gameId = -1);
|
|
||||||
static ProtocolItem *newItem() { return new Command_SubmitDeck; }
|
|
||||||
int getItemId() const { return ItemId_Command_SubmitDeck; }
|
|
||||||
};
|
|
||||||
class Event_Say : public GameEvent {
|
class Event_Say : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
@ -479,6 +471,18 @@ public:
|
||||||
static ProtocolItem *newItem() { return new Event_Leave; }
|
static ProtocolItem *newItem() { return new Event_Leave; }
|
||||||
int getItemId() const { return ItemId_Event_Leave; }
|
int getItemId() const { return ItemId_Event_Leave; }
|
||||||
};
|
};
|
||||||
|
class Event_DeckSelect : public GameEvent {
|
||||||
|
Q_OBJECT
|
||||||
|
private:
|
||||||
|
int deckId;
|
||||||
|
public:
|
||||||
|
Event_DeckSelect(int _gameId = -1, int _playerId = -1, int _deckId = -1);
|
||||||
|
int getDeckId() const { return deckId; }
|
||||||
|
static ProtocolItem *newItem() { return new Event_DeckSelect; }
|
||||||
|
int getItemId() const { return ItemId_Event_DeckSelect; }
|
||||||
|
protected:
|
||||||
|
void extractParameters();
|
||||||
|
};
|
||||||
class Event_GameClosed : public GameEvent {
|
class Event_GameClosed : public GameEvent {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -7,9 +7,10 @@
|
||||||
#include "server_protocolhandler.h"
|
#include "server_protocolhandler.h"
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
|
#include "decklist.h"
|
||||||
|
|
||||||
Server_Player::Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler)
|
Server_Player::Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler)
|
||||||
: game(_game), handler(_handler), playerId(_playerId), playerName(_playerName), spectator(_spectator), nextCardId(0), PlayerStatus(StatusNormal)
|
: game(_game), handler(_handler), deck(0), playerId(_playerId), playerName(_playerName), spectator(_spectator), nextCardId(0), PlayerStatus(StatusNormal)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +52,10 @@ void Server_Player::setupZones()
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
// Create zones
|
// Create zones
|
||||||
Server_CardZone *deck = new Server_CardZone(this, "deck", false, Server_CardZone::HiddenZone);
|
Server_CardZone *deckZone = new Server_CardZone(this, "deck", false, Server_CardZone::HiddenZone);
|
||||||
addZone(deck);
|
addZone(deckZone);
|
||||||
Server_CardZone *sb = new Server_CardZone(this, "sb", false, Server_CardZone::HiddenZone);
|
Server_CardZone *sbZone = new Server_CardZone(this, "sb", false, Server_CardZone::HiddenZone);
|
||||||
addZone(sb);
|
addZone(sbZone);
|
||||||
addZone(new Server_CardZone(this, "table", true, Server_CardZone::PublicZone));
|
addZone(new Server_CardZone(this, "table", true, Server_CardZone::PublicZone));
|
||||||
addZone(new Server_CardZone(this, "hand", false, Server_CardZone::PrivateZone));
|
addZone(new Server_CardZone(this, "hand", false, Server_CardZone::PrivateZone));
|
||||||
addZone(new Server_CardZone(this, "grave", false, Server_CardZone::PublicZone));
|
addZone(new Server_CardZone(this, "grave", false, Server_CardZone::PublicZone));
|
||||||
|
@ -63,20 +64,30 @@ void Server_Player::setupZones()
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
|
||||||
// Assign card ids and create deck from decklist
|
// Assign card ids and create deck from decklist
|
||||||
QListIterator<QString> DeckIterator(DeckList);
|
InnerDecklistNode *listRoot = deck->getRoot();
|
||||||
int i = 0;
|
nextCardId = 0;
|
||||||
while (DeckIterator.hasNext())
|
for (int i = 0; i < listRoot->size(); ++i) {
|
||||||
deck->cards.append(new Server_Card(DeckIterator.next(), i++, 0, 0));
|
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
|
||||||
deck->shuffle();
|
Server_CardZone *z;
|
||||||
|
if (currentZone->getName() == "main")
|
||||||
|
z = deckZone;
|
||||||
|
else if (currentZone->getName() == "side")
|
||||||
|
z = sbZone;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int j = 0; j < currentZone->size(); ++j) {
|
||||||
|
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
|
||||||
|
if (!currentCard)
|
||||||
|
continue;
|
||||||
|
for (int k = 0; k < currentCard->getNumber(); ++k)
|
||||||
|
z->cards.append(new Server_Card(currentCard->getName(), nextCardId++, 0, 0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deckZone->shuffle();
|
||||||
|
|
||||||
QListIterator<QString> SBIterator(SideboardList);
|
|
||||||
while (SBIterator.hasNext())
|
|
||||||
sb->cards.append(new Server_Card(SBIterator.next(), i++, 0, 0));
|
|
||||||
|
|
||||||
nextCardId = i;
|
|
||||||
|
|
||||||
PlayerStatus = StatusPlaying;
|
PlayerStatus = StatusPlaying;
|
||||||
game->sendGameEvent(new Event_SetupZones(-1, playerId, deck->cards.size(), sb->cards.size()));
|
game->sendGameEvent(new Event_SetupZones(-1, playerId, deckZone->cards.size(), sbZone->cards.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server_Player::clearZones()
|
void Server_Player::clearZones()
|
||||||
|
@ -97,6 +108,12 @@ void Server_Player::clearZones()
|
||||||
arrows.clear();
|
arrows.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server_Player::setDeck(DeckList *_deck)
|
||||||
|
{
|
||||||
|
delete deck;
|
||||||
|
deck = _deck;
|
||||||
|
}
|
||||||
|
|
||||||
void Server_Player::addZone(Server_CardZone *zone)
|
void Server_Player::addZone(Server_CardZone *zone)
|
||||||
{
|
{
|
||||||
zones.insert(zone->getName(), zone);
|
zones.insert(zone->getName(), zone);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
|
class DeckList;
|
||||||
class Server_Game;
|
class Server_Game;
|
||||||
class Server_CardZone;
|
class Server_CardZone;
|
||||||
class Server_Counter;
|
class Server_Counter;
|
||||||
|
@ -20,6 +21,7 @@ class Server_Player : public QObject {
|
||||||
private:
|
private:
|
||||||
Server_Game *game;
|
Server_Game *game;
|
||||||
Server_ProtocolHandler *handler;
|
Server_ProtocolHandler *handler;
|
||||||
|
DeckList *deck;
|
||||||
QMap<QString, Server_CardZone *> zones;
|
QMap<QString, Server_CardZone *> zones;
|
||||||
QMap<int, Server_Counter *> counters;
|
QMap<int, Server_Counter *> counters;
|
||||||
QMap<int, Server_Arrow *> arrows;
|
QMap<int, Server_Arrow *> arrows;
|
||||||
|
@ -30,11 +32,6 @@ private:
|
||||||
void clearZones();
|
void clearZones();
|
||||||
PlayerStatusEnum PlayerStatus;
|
PlayerStatusEnum PlayerStatus;
|
||||||
public:
|
public:
|
||||||
// Pfusch
|
|
||||||
QList<QString> DeckList;
|
|
||||||
QList<QString> SideboardList;
|
|
||||||
// Pfusch Ende
|
|
||||||
|
|
||||||
Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler);
|
Server_Player(Server_Game *_game, int _playerId, const QString &_playerName, bool _spectator, Server_ProtocolHandler *_handler);
|
||||||
void setProtocolHandler(Server_ProtocolHandler *_handler) { handler = _handler; }
|
void setProtocolHandler(Server_ProtocolHandler *_handler) { handler = _handler; }
|
||||||
|
|
||||||
|
@ -44,6 +41,8 @@ public:
|
||||||
int getPlayerId() const { return playerId; }
|
int getPlayerId() const { return playerId; }
|
||||||
bool getSpectator() const { return spectator; }
|
bool getSpectator() const { return spectator; }
|
||||||
QString getPlayerName() const { return playerName; }
|
QString getPlayerName() const { return playerName; }
|
||||||
|
void setDeck(DeckList *_deck);
|
||||||
|
DeckList *getDeck() const { return deck; }
|
||||||
const QMap<QString, Server_CardZone *> &getZones() const { return zones; }
|
const QMap<QString, Server_CardZone *> &getZones() const { return zones; }
|
||||||
const QMap<int, Server_Counter *> &getCounters() const { return counters; }
|
const QMap<int, Server_Counter *> &getCounters() const { return counters; }
|
||||||
const QMap<int, Server_Arrow *> &getArrows() const { return arrows; }
|
const QMap<int, Server_Arrow *> &getArrows() const { return arrows; }
|
||||||
|
|
|
@ -67,6 +67,7 @@ void Server_ProtocolHandler::processCommand(Command *command)
|
||||||
Server_Player *player = gamePair.second;
|
Server_Player *player = gamePair.second;
|
||||||
|
|
||||||
switch (command->getItemId()) {
|
switch (command->getItemId()) {
|
||||||
|
case ItemId_Command_DeckSelect: response = cmdDeckSelect(qobject_cast<Command_DeckSelect *>(command), game, player); break;
|
||||||
case ItemId_Command_LeaveGame: response = cmdLeaveGame(qobject_cast<Command_LeaveGame *>(command), game, player); break;
|
case ItemId_Command_LeaveGame: response = cmdLeaveGame(qobject_cast<Command_LeaveGame *>(command), game, player); break;
|
||||||
case ItemId_Command_Say: response = cmdSay(qobject_cast<Command_Say *>(command), game, player); break;
|
case ItemId_Command_Say: response = cmdSay(qobject_cast<Command_Say *>(command), game, player); break;
|
||||||
case ItemId_Command_Shuffle: response = cmdShuffle(qobject_cast<Command_Shuffle *>(command), game, player); break;
|
case ItemId_Command_Shuffle: response = cmdShuffle(qobject_cast<Command_Shuffle *>(command), game, player); break;
|
||||||
|
@ -87,7 +88,6 @@ void Server_ProtocolHandler::processCommand(Command *command)
|
||||||
case ItemId_Command_DumpZone: response = cmdDumpZone(qobject_cast<Command_DumpZone *>(command), game, player); break;
|
case ItemId_Command_DumpZone: response = cmdDumpZone(qobject_cast<Command_DumpZone *>(command), game, player); break;
|
||||||
case ItemId_Command_StopDumpZone: response = cmdStopDumpZone(qobject_cast<Command_StopDumpZone *>(command), game, player); break;
|
case ItemId_Command_StopDumpZone: response = cmdStopDumpZone(qobject_cast<Command_StopDumpZone *>(command), game, player); break;
|
||||||
case ItemId_Command_DumpAll: response = cmdDumpAll(qobject_cast<Command_DumpAll *>(command), game, player); break;
|
case ItemId_Command_DumpAll: response = cmdDumpAll(qobject_cast<Command_DumpAll *>(command), game, player); break;
|
||||||
case ItemId_Command_SubmitDeck: response = cmdSubmitDeck(qobject_cast<Command_SubmitDeck *>(command), game, player); break;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "received generic Command";
|
qDebug() << "received generic Command";
|
||||||
|
@ -245,6 +245,27 @@ ResponseCode Server_ProtocolHandler::cmdLeaveGame(Command_LeaveGame * /*cmd*/, S
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResponseCode Server_ProtocolHandler::cmdDeckSelect(Command_DeckSelect *cmd, Server_Game *game, Server_Player *player)
|
||||||
|
{
|
||||||
|
DeckList *deck;
|
||||||
|
if (cmd->getDeckId() == -1) {
|
||||||
|
if (!cmd->getDeck())
|
||||||
|
return RespInvalidData;
|
||||||
|
deck = cmd->getDeck();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
deck = getDeckFromDatabase(cmd->getDeckId());
|
||||||
|
} catch(ResponseCode r) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
player->setDeck(deck);
|
||||||
|
|
||||||
|
game->sendGameEvent(new Event_DeckSelect(-1, player->getPlayerId(), cmd->getDeckId()));
|
||||||
|
|
||||||
|
return RespOk;
|
||||||
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
game->sendGameEvent(new Event_Say(-1, player->getPlayerId(), cmd->getMessage()));
|
game->sendGameEvent(new Event_Say(-1, player->getPlayerId(), cmd->getMessage()));
|
||||||
|
@ -468,6 +489,9 @@ ResponseCode Server_ProtocolHandler::cmdSetCardAttr(Command_SetCardAttr *cmd, Se
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
|
ResponseCode Server_ProtocolHandler::cmdReadyStart(Command_ReadyStart * /*cmd*/, Server_Game *game, Server_Player *player)
|
||||||
{
|
{
|
||||||
|
if (!player->getDeck())
|
||||||
|
return RespContextError;
|
||||||
|
|
||||||
player->setStatus(StatusReadyStart);
|
player->setStatus(StatusReadyStart);
|
||||||
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
|
game->sendGameEvent(new Event_ReadyStart(-1, player->getPlayerId()));
|
||||||
game->startGameIfReady();
|
game->startGameIfReady();
|
||||||
|
@ -570,8 +594,3 @@ ResponseCode Server_ProtocolHandler::cmdDumpAll(Command_DumpAll *cmd, Server_Gam
|
||||||
{
|
{
|
||||||
return RespOk;
|
return RespOk;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode Server_ProtocolHandler::cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player)
|
|
||||||
{
|
|
||||||
return RespOk;
|
|
||||||
}
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
QList<ProtocolItem *> itemQueue;
|
QList<ProtocolItem *> itemQueue;
|
||||||
|
|
||||||
|
virtual DeckList *getDeckFromDatabase(int deckId) = 0;
|
||||||
|
|
||||||
ResponseCode cmdPing(Command_Ping *cmd);
|
ResponseCode cmdPing(Command_Ping *cmd);
|
||||||
ResponseCode cmdLogin(Command_Login *cmd);
|
ResponseCode cmdLogin(Command_Login *cmd);
|
||||||
virtual ResponseCode cmdDeckList(Command_DeckList *cmd) = 0;
|
virtual ResponseCode cmdDeckList(Command_DeckList *cmd) = 0;
|
||||||
|
@ -43,6 +45,7 @@ private:
|
||||||
ResponseCode cmdCreateGame(Command_CreateGame *cmd);
|
ResponseCode cmdCreateGame(Command_CreateGame *cmd);
|
||||||
ResponseCode cmdJoinGame(Command_JoinGame *cmd);
|
ResponseCode cmdJoinGame(Command_JoinGame *cmd);
|
||||||
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
|
ResponseCode cmdLeaveGame(Command_LeaveGame *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
ResponseCode cmdDeckSelect(Command_DeckSelect *cmd, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
|
ResponseCode cmdSay(Command_Say *cmd, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
|
ResponseCode cmdShuffle(Command_Shuffle *cmd, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player);
|
ResponseCode cmdRollDie(Command_RollDie *cmd, Server_Game *game, Server_Player *player);
|
||||||
|
@ -62,7 +65,6 @@ private:
|
||||||
ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player);
|
ResponseCode cmdDumpZone(Command_DumpZone *cmd, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
|
ResponseCode cmdStopDumpZone(Command_StopDumpZone *cmd, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
|
ResponseCode cmdDumpAll(Command_DumpAll *cmd, Server_Game *game, Server_Player *player);
|
||||||
ResponseCode cmdSubmitDeck(Command_SubmitDeck *cmd, Server_Game *game, Server_Player *player);
|
|
||||||
public:
|
public:
|
||||||
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
|
Server_ProtocolHandler(Server *_server, QObject *parent = 0);
|
||||||
~Server_ProtocolHandler();
|
~Server_ProtocolHandler();
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "protocol.h"
|
#include "protocol.h"
|
||||||
#include "protocol_items.h"
|
#include "protocol_items.h"
|
||||||
#include "decklist.h"
|
#include "decklist.h"
|
||||||
|
#include "server_player.h"
|
||||||
|
|
||||||
ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent)
|
ServerSocketInterface::ServerSocketInterface(Servatrice *_server, QTcpSocket *_socket, QObject *parent)
|
||||||
: Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), currentItem(0)
|
: Server_ProtocolHandler(_server, parent), servatrice(_server), socket(_socket), currentItem(0)
|
||||||
|
@ -279,31 +280,41 @@ ResponseCode ServerSocketInterface::cmdDeckUpload(Command_DeckUpload *cmd)
|
||||||
query.bindValue(":content", deckContents);
|
query.bindValue(":content", deckContents);
|
||||||
servatrice->execSqlQuery(query);
|
servatrice->execSqlQuery(query);
|
||||||
|
|
||||||
|
delete cmd->getDeck();
|
||||||
|
|
||||||
sendProtocolItem(new Response_DeckUpload(cmd->getCmdId(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime())));
|
sendProtocolItem(new Response_DeckUpload(cmd->getCmdId(), RespOk, new DeckList_File(deckName, query.lastInsertId().toInt(), QDateTime::currentDateTime())));
|
||||||
return RespNothing;
|
return RespNothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd)
|
DeckList *ServerSocketInterface::getDeckFromDatabase(int deckId)
|
||||||
{
|
{
|
||||||
servatrice->checkSql();
|
servatrice->checkSql();
|
||||||
|
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
|
|
||||||
query.prepare("select content from decklist_files where id = :id and user = :user");
|
query.prepare("select content from decklist_files where id = :id and user = :user");
|
||||||
query.bindValue(":id", cmd->getDeckId());
|
query.bindValue(":id", deckId);
|
||||||
query.bindValue(":user", playerName);
|
query.bindValue(":user", playerName);
|
||||||
servatrice->execSqlQuery(query);
|
servatrice->execSqlQuery(query);
|
||||||
if (!query.next())
|
if (!query.next())
|
||||||
return RespNameNotFound;
|
throw RespNameNotFound;
|
||||||
|
|
||||||
QXmlStreamReader deckReader(query.value(0).toString());
|
QXmlStreamReader deckReader(query.value(0).toString());
|
||||||
DeckList *deck = new DeckList;
|
DeckList *deck = new DeckList;
|
||||||
if (!deck->loadFromXml(&deckReader)) {
|
if (!deck->loadFromXml(&deckReader))
|
||||||
delete deck;
|
throw RespInvalidData;
|
||||||
deck = 0;
|
|
||||||
return RespInvalidData;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
return deck;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResponseCode ServerSocketInterface::cmdDeckDownload(Command_DeckDownload *cmd)
|
||||||
|
{
|
||||||
|
DeckList *deck;
|
||||||
|
try {
|
||||||
|
deck = getDeckFromDatabase(cmd->getDeckId());
|
||||||
|
} catch(ResponseCode r) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck));
|
sendProtocolItem(new Response_DeckDownload(cmd->getCmdId(), RespOk, deck));
|
||||||
return RespNothing;
|
return RespNothing;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ class QTcpSocket;
|
||||||
class Servatrice;
|
class Servatrice;
|
||||||
class QXmlStreamReader;
|
class QXmlStreamReader;
|
||||||
class QXmlStreamWriter;
|
class QXmlStreamWriter;
|
||||||
|
class DeckList;
|
||||||
|
|
||||||
class ServerSocketInterface : public Server_ProtocolHandler
|
class ServerSocketInterface : public Server_ProtocolHandler
|
||||||
{
|
{
|
||||||
|
@ -50,6 +51,7 @@ private:
|
||||||
ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd);
|
ResponseCode cmdDeckDelDir(Command_DeckDelDir *cmd);
|
||||||
ResponseCode cmdDeckDel(Command_DeckDel *cmd);
|
ResponseCode cmdDeckDel(Command_DeckDel *cmd);
|
||||||
ResponseCode cmdDeckUpload(Command_DeckUpload *cmd);
|
ResponseCode cmdDeckUpload(Command_DeckUpload *cmd);
|
||||||
|
DeckList *getDeckFromDatabase(int deckId);
|
||||||
ResponseCode cmdDeckDownload(Command_DeckDownload *cmd);
|
ResponseCode cmdDeckDownload(Command_DeckDownload *cmd);
|
||||||
|
|
||||||
void itemFinishedReading();
|
void itemFinishedReading();
|
||||||
|
|
Loading…
Reference in a new issue