From db2c2d1b15ec37d8ba7b1d91cb927b9b6863f0d7 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Thu, 7 Oct 2010 17:18:15 +0200 Subject: [PATCH 1/6] card tap/untap animation; misc fixes --- cockatrice/src/abstractcarditem.cpp | 62 +++++++++++++++++++++-------- cockatrice/src/abstractcarditem.h | 7 +++- cockatrice/src/carddatabase.cpp | 1 + cockatrice/src/dlg_settings.cpp | 23 ++++++++--- cockatrice/src/dlg_settings.h | 5 ++- cockatrice/src/player.cpp | 2 +- cockatrice/src/settingscache.cpp | 17 +++++--- cockatrice/src/settingscache.h | 11 +++-- cockatrice/src/tablezone.cpp | 8 ++-- 9 files changed, 98 insertions(+), 38 deletions(-) diff --git a/cockatrice/src/abstractcarditem.cpp b/cockatrice/src/abstractcarditem.cpp index 62be01132..4489ee21e 100644 --- a/cockatrice/src/abstractcarditem.cpp +++ b/cockatrice/src/abstractcarditem.cpp @@ -3,13 +3,16 @@ #include #include #include +#include #include "carddatabase.h" #include "abstractcarditem.h" +#include "settingscache.h" #include "main.h" #include +#include AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphicsItem *parent) - : ArrowTarget(_owner, parent), info(db->getCard(_name)), name(_name), tapped(false) + : ArrowTarget(_owner, parent), info(db->getCard(_name)), name(_name), tapped(false), tapAngle(0) { setCursor(Qt::OpenHandCursor); setFlag(ItemIsSelectable); @@ -17,6 +20,10 @@ AbstractCardItem::AbstractCardItem(const QString &_name, Player *_owner, QGraphi setCacheMode(DeviceCoordinateCache); connect(info, SIGNAL(pixmapUpdated()), this, SLOT(pixmapUpdated())); + + animationTimer = new QTimer(this); + animationTimer->setSingleShot(false); + connect(animationTimer, SIGNAL(timeout()), this, SLOT(animationEvent())); } AbstractCardItem::~AbstractCardItem() @@ -37,19 +44,22 @@ void AbstractCardItem::pixmapUpdated() void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/) { painter->save(); - QSizeF translatedSize = painter->combinedTransform().mapRect(boundingRect()).size(); - if (tapped) - translatedSize.transpose(); + qreal w = painter->combinedTransform().map(QLineF(0, 0, boundingRect().width(), 0)).length(); + qreal h = painter->combinedTransform().map(QLineF(0, 0, 0, boundingRect().height())).length(); + QSizeF translatedSize(w, h); + QRectF totalBoundingRect = painter->combinedTransform().mapRect(boundingRect()); 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()); + QTransform pixmapTransform; + pixmapTransform.translate(totalBoundingRect.width() / 2, totalBoundingRect.height() / 2); + pixmapTransform.rotate(tapAngle); + QPointF transPoint = QPointF(-w / 2, -h / 2); + pixmapTransform.translate(transPoint.x(), transPoint.y()); + painter->setTransform(pixmapTransform); + + painter->drawPixmap(QPointF(0, 0), *translatedPixmap); } else { QFont f("Times"); f.setStyleHint(QFont::Serif); @@ -105,6 +115,21 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * painter->restore(); } +void AbstractCardItem::animationEvent() +{ + int delta = 10; + if (!tapped) + delta *= -1; + + tapAngle += delta; + + setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2)); + update(); + + if ((tapped && (tapAngle >= 90)) || (!tapped && (tapAngle <= 0))) + animationTimer->stop(); +} + void AbstractCardItem::setName(const QString &_name) { disconnect(info, 0, this, 0); @@ -120,14 +145,19 @@ void AbstractCardItem::setColor(const QString &_color) update(); } -void AbstractCardItem::setTapped(bool _tapped) +void AbstractCardItem::setTapped(bool _tapped, bool canAnimate) { + if (tapped == _tapped) + return; + 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(); + if (settingsCache->getTapAnimation() && canAnimate) + animationTimer->start(25); + else { + tapAngle = tapped ? 90 : 0; + setTransform(QTransform().translate((float) CARD_WIDTH / 2, (float) CARD_HEIGHT / 2).rotate(tapAngle).translate((float) -CARD_WIDTH / 2, (float) -CARD_HEIGHT / 2)); + update(); + } } void AbstractCardItem::mousePressEvent(QGraphicsSceneMouseEvent *event) diff --git a/cockatrice/src/abstractcarditem.h b/cockatrice/src/abstractcarditem.h index 6d77f6f33..d87ba1a99 100644 --- a/cockatrice/src/abstractcarditem.h +++ b/cockatrice/src/abstractcarditem.h @@ -5,6 +5,7 @@ class CardInfo; class Player; +class QTimer; const int CARD_WIDTH = 72; const int CARD_HEIGHT = 102; @@ -15,8 +16,12 @@ protected: CardInfo *info; QString name; bool tapped; + int tapAngle; QString color; +private: + QTimer *animationTimer; private slots: + void animationEvent(); void pixmapUpdated(); signals: void hovered(AbstractCardItem *card); @@ -33,7 +38,7 @@ public: QString getColor() const { return color; } void setColor(const QString &_color); bool getTapped() const { return tapped; } - void setTapped(bool _tapped); + void setTapped(bool _tapped, bool canAnimate = false); void processHoverEvent(); protected: void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 2d1bc248c..4bb24da59 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -252,6 +252,7 @@ CardDatabase::CardDatabase(QObject *parent) CardDatabase::~CardDatabase() { clear(); + delete noCard; } void CardDatabase::clear() diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index d7365adbc..a27d4b37b 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -202,12 +202,12 @@ AppearanceSettingsPage::AppearanceSettingsPage() handGroupBox = new QGroupBox; handGroupBox->setLayout(handGrid); - economicGridCheckBox = new QCheckBox; - economicGridCheckBox->setChecked(settingsCache->getEconomicGrid()); - connect(economicGridCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setEconomicGrid(int))); + economicalGridCheckBox = new QCheckBox; + economicalGridCheckBox->setChecked(settingsCache->getEconomicalGrid()); + connect(economicalGridCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setEconomicalGrid(int))); QGridLayout *tableGrid = new QGridLayout; - tableGrid->addWidget(economicGridCheckBox, 0, 0, 1, 2); + tableGrid->addWidget(economicalGridCheckBox, 0, 0, 1, 2); tableGroupBox = new QGroupBox; tableGroupBox->setLayout(tableGrid); @@ -248,7 +248,7 @@ void AppearanceSettingsPage::retranslateUi() horizontalHandCheckBox->setText(tr("Display hand horizontally (wastes space)")); tableGroupBox->setTitle(tr("Table grid layout")); - economicGridCheckBox->setText(tr("Economic layout")); + economicalGridCheckBox->setText(tr("Economical layout")); zoneViewGroupBox->setTitle(tr("Zone view layout")); zoneViewSortByNameCheckBox->setText(tr("Sort by name")); @@ -307,8 +307,19 @@ UserInterfaceSettingsPage::UserInterfaceSettingsPage() generalGroupBox = new QGroupBox; generalGroupBox->setLayout(generalGrid); + tapAnimationCheckBox = new QCheckBox; + tapAnimationCheckBox->setChecked(settingsCache->getTapAnimation()); + connect(tapAnimationCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setTapAnimation(int))); + + QGridLayout *animationGrid = new QGridLayout; + animationGrid->addWidget(tapAnimationCheckBox, 0, 0); + + animationGroupBox = new QGroupBox; + animationGroupBox->setLayout(animationGrid); + QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->addWidget(generalGroupBox); + mainLayout->addWidget(animationGroupBox); setLayout(mainLayout); } @@ -317,6 +328,8 @@ void UserInterfaceSettingsPage::retranslateUi() { generalGroupBox->setTitle(tr("General interface settings")); doubleClickToPlayCheckBox->setText(tr("&Double-click cards to play them (instead of single-click)")); + animationGroupBox->setTitle(tr("Animation settings")); + tapAnimationCheckBox->setText(tr("&Tap/untap animation")); } MessagesSettingsPage::MessagesSettingsPage() diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index b8575fb9e..f9cb71a1f 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -60,7 +60,7 @@ signals: private: QLabel *handBgLabel, *tableBgLabel, *playerAreaBgLabel, *cardBackPicturePathLabel; QLineEdit *handBgEdit, *tableBgEdit, *playerAreaBgEdit, *cardBackPicturePathEdit; - QCheckBox *horizontalHandCheckBox, *economicGridCheckBox, *zoneViewSortByNameCheckBox, *zoneViewSortByTypeCheckBox; + QCheckBox *horizontalHandCheckBox, *economicalGridCheckBox, *zoneViewSortByNameCheckBox, *zoneViewSortByTypeCheckBox; QGroupBox *zoneBgGroupBox, *handGroupBox, *tableGroupBox, *zoneViewGroupBox; public: AppearanceSettingsPage(); @@ -71,7 +71,8 @@ class UserInterfaceSettingsPage : public AbstractSettingsPage { Q_OBJECT private: QCheckBox *doubleClickToPlayCheckBox; - QGroupBox *generalGroupBox; + QCheckBox *tapAnimationCheckBox; + QGroupBox *generalGroupBox, *animationGroupBox; public: UserInterfaceSettingsPage(); void retranslateUi(); diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index 8eee68806..dd7e56aa8 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -526,7 +526,7 @@ void Player::setCardAttrHelper(CardItem *card, const QString &aname, const QStri if (!(!tapped && card->getDoesntUntap() && allCards)) { if (!allCards) emit logSetTapped(this, card->getName(), tapped); - card->setTapped(tapped); + card->setTapped(tapped, true); } } else if (aname == "attacking") card->setAttacking(avalue == "1"); diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index 3d291f7e1..177d119a4 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -19,7 +19,8 @@ SettingsCache::SettingsCache() picDownload = settings->value("personal/picturedownload", false).toBool(); doubleClickToPlay = settings->value("interface/doubleclicktoplay", true).toBool(); horizontalHand = settings->value("hand/horizontal", false).toBool(); - economicGrid = settings->value("table/economic", false).toBool(); + economicalGrid = settings->value("table/economic", false).toBool(); + tapAnimation = settings->value("cards/tapanimation", true).toBool(); zoneViewSortByName = settings->value("zoneview/sortbyname", false).toBool(); zoneViewSortByType = settings->value("zoneview/sortbytype", false).toBool(); @@ -100,11 +101,17 @@ void SettingsCache::setHorizontalHand(int _horizontalHand) emit horizontalHandChanged(); } -void SettingsCache::setEconomicGrid(int _economicGrid) +void SettingsCache::setEconomicalGrid(int _economicalGrid) { - economicGrid = _economicGrid; - settings->setValue("table/economic", economicGrid); - emit economicGridChanged(); + economicalGrid = _economicalGrid; + settings->setValue("table/economic", economicalGrid); + emit economicalGridChanged(); +} + +void SettingsCache::setTapAnimation(int _tapAnimation) +{ + tapAnimation = _tapAnimation; + settings->setValue("cards/tapanimation", tapAnimation); } void SettingsCache::setZoneViewSortByName(int _zoneViewSortByName) diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index d501d44b7..2232ef99c 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -17,7 +17,7 @@ signals: void cardBackPicturePathChanged(); void picDownloadChanged(); void horizontalHandChanged(); - void economicGridChanged(); + void economicalGridChanged(); private: QSettings *settings; @@ -27,7 +27,8 @@ private: bool picDownload; bool doubleClickToPlay; bool horizontalHand; - bool economicGrid; + bool economicalGrid; + bool tapAnimation; bool zoneViewSortByName, zoneViewSortByType; public: SettingsCache(); @@ -42,7 +43,8 @@ public: bool getPicDownload() const { return picDownload; } bool getDoubleClickToPlay() const { return doubleClickToPlay; } bool getHorizontalHand() const { return horizontalHand; } - bool getEconomicGrid() const { return economicGrid; } + bool getEconomicalGrid() const { return economicalGrid; } + bool getTapAnimation() const { return tapAnimation; } bool getZoneViewSortByName() const { return zoneViewSortByName; } bool getZoneViewSortByType() const { return zoneViewSortByType; } public slots: @@ -57,7 +59,8 @@ public slots: void setPicDownload(int _picDownload); void setDoubleClickToPlay(int _doubleClickToPlay); void setHorizontalHand(int _horizontalHand); - void setEconomicGrid(int _economicGrid); + void setEconomicalGrid(int _economicalGrid); + void setTapAnimation(int _tapAnimation); void setZoneViewSortByName(int _zoneViewSortByName); void setZoneViewSortByType(int _zoneViewSortByType); }; diff --git a/cockatrice/src/tablezone.cpp b/cockatrice/src/tablezone.cpp index 139bed6ed..9593105f4 100644 --- a/cockatrice/src/tablezone.cpp +++ b/cockatrice/src/tablezone.cpp @@ -12,10 +12,10 @@ TableZone::TableZone(Player *_p, QGraphicsItem *parent) : CardZone(_p, "table", true, false, true, parent), active(false) { connect(settingsCache, SIGNAL(tableBgPathChanged()), this, SLOT(updateBgPixmap())); - connect(settingsCache, SIGNAL(economicGridChanged()), this, SLOT(reorganizeCards())); + connect(settingsCache, SIGNAL(economicalGridChanged()), this, SLOT(reorganizeCards())); updateBgPixmap(); - if (settingsCache->getEconomicGrid()) + if (settingsCache->getEconomicalGrid()) height = 2 * boxLineWidth + (int) (14.0 / 3 * CARD_HEIGHT + 3 * paddingY); else height = 2 * boxLineWidth + 4 * CARD_HEIGHT + 3 * paddingY; @@ -210,7 +210,7 @@ CardItem *TableZone::getCardFromCoords(const QPointF &point) const QPointF TableZone::mapFromGrid(const QPoint &gridPoint) const { qreal x, y; - if ((gridPoint.y() == 3) && (settingsCache->getEconomicGrid())) { + if ((gridPoint.y() == 3) && (settingsCache->getEconomicalGrid())) { x = marginX + (CARD_WIDTH * gridPoint.x() + CARD_WIDTH * (gridPoint.x() / 3)) / 2; y = boxLineWidth + (CARD_HEIGHT + paddingY) * gridPoint.y() + (gridPoint.x() % 3 * CARD_HEIGHT) / 3; } else { @@ -245,7 +245,7 @@ QPoint TableZone::mapToGrid(const QPointF &mapPoint) const int resultY = (int) (y / (CARD_HEIGHT + paddingY)); - if ((resultY == 3) && (settingsCache->getEconomicGrid())) + if ((resultY == 3) && (settingsCache->getEconomicalGrid())) return QPoint( (int) (x * 2 / CARD_WIDTH - floor(x / (2 * CARD_WIDTH))), 3 From 9285a3952cd49a43123dc9f6cf8950ce88857fb3 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Fri, 8 Oct 2010 15:01:57 +0200 Subject: [PATCH 2/6] translation update --- cockatrice/translations/cockatrice_de.ts | 52 +++++++++++++++--------- cockatrice/translations/cockatrice_en.ts | 48 +++++++++++++--------- cockatrice/translations/cockatrice_es.ts | 52 +++++++++++++++--------- 3 files changed, 95 insertions(+), 57 deletions(-) diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index 96debf004..505cd983d 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -68,9 +68,13 @@ - Economic layout + Economical layout Platzsparende Anordnung + + Economic layout + Platzsparende Anordnung + Zone view layout @@ -854,54 +858,54 @@ DlgSettings - - - + + + Error Fehler - + Your card database is invalid. Please check if the path is set correctly. Ihre Kartendatenbank ist ungültig. Bitte überprüfen Sie, ob der Pfad korrekt gesetzt ist. - + The path to your deck directory is invalid. Der Pfad zum Deckverzeichnis ist ungültig. - + The path to your card pictures directory is invalid. Der Pfad zum Kartenbilderverzeichnis ist ungültig. - + Settings Einstellungen - + General Allgemeines - + Appearance Erscheinungsbild - + User interface Bedienung - + Messages Nachrichten - + &Close S&chließen @@ -2186,12 +2190,12 @@ MessagesSettingsPage - + &Add &Hinzufügen - + &Remove &Entfernen @@ -2204,12 +2208,12 @@ Entfernen - + Add message Nachricht hinzufügen - + Message: Nachricht: @@ -3073,15 +3077,25 @@ Bitte geben Sie einen Namen ein: UserInterfaceSettingsPage - + General interface settings Allgemeine Bedienung - + &Double-click cards to play them (instead of single-click) Karten durch &Doppelklick ausspielen (statt Einzelklick) + + + Animation settings + Animationseinstellungen + + + + &Tap/untap animation + Animiertes &Tappen/Enttappen + UserList diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index bd56a08cd..2f9d1ee67 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -45,7 +45,7 @@ - Economic layout + Economical layout @@ -735,54 +735,54 @@ DlgSettings - - - + + + Error - + Your card database is invalid. Please check if the path is set correctly. - + The path to your deck directory is invalid. - + The path to your card pictures directory is invalid. - + Settings - + General - + Appearance - + User interface - + Messages - + &Close @@ -1489,22 +1489,22 @@ MessagesSettingsPage - + &Add - + &Remove - + Add message - + Message: @@ -2152,15 +2152,25 @@ Please enter a name: UserInterfaceSettingsPage - + General interface settings - + &Double-click cards to play them (instead of single-click) + + + Animation settings + + + + + &Tap/untap animation + + UserList diff --git a/cockatrice/translations/cockatrice_es.ts b/cockatrice/translations/cockatrice_es.ts index f72b0f772..fe4b1c2c3 100644 --- a/cockatrice/translations/cockatrice_es.ts +++ b/cockatrice/translations/cockatrice_es.ts @@ -45,8 +45,12 @@ + Economical layout + + + Economic layout - Disposición económica + Disposición económica @@ -735,54 +739,54 @@ DlgSettings - - - + + + Error Error - + Your card database is invalid. Please check if the path is set correctly. Tu base de datos de cartas es invalida. Por favor, comprueba si la ruta está asignada correctamente. - + The path to your deck directory is invalid. La ruta a tu directorio de mazos es invalida. - + The path to your card pictures directory is invalid. La ruta a tu directorio de imagenes de las cartas es invalida. - + Settings Preferencias - + General General - + Appearance Apariencia - + User interface Interfaz de usuario - + Messages Mensajes - + &Close &Cerrar @@ -1489,22 +1493,22 @@ MessagesSettingsPage - + &Add &Añadir - + &Remove &Quitar - + Add message Añadir mensaje - + Message: Mensaje: @@ -2165,15 +2169,25 @@ Por favor, introduzca un nombre: UserInterfaceSettingsPage - + General interface settings Preferencias generales de la interfaz - + &Double-click cards to play them (instead of single-click) &Doble click en las cartas para jugarlas (en lugar de un solo click) + + + Animation settings + + + + + &Tap/untap animation + + UserList From 548684360502ecdb48c0795e0edd4d2c331a3e9d Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sat, 9 Oct 2010 00:44:11 +0200 Subject: [PATCH 3/6] adjusted angle increment for tap animation --- cockatrice/src/abstractcarditem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cockatrice/src/abstractcarditem.cpp b/cockatrice/src/abstractcarditem.cpp index 4489ee21e..3b62c390d 100644 --- a/cockatrice/src/abstractcarditem.cpp +++ b/cockatrice/src/abstractcarditem.cpp @@ -117,7 +117,7 @@ void AbstractCardItem::paint(QPainter *painter, const QStyleOptionGraphicsItem * void AbstractCardItem::animationEvent() { - int delta = 10; + int delta = 18; if (!tapped) delta *= -1; From ee0a010add9d6b3d777f08e3b87f7cf432638086 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sat, 9 Oct 2010 14:09:36 +0200 Subject: [PATCH 4/6] fixed bug #35 --- cockatrice/cockatrice.qrc | 1 + cockatrice/resources/icon_delete.svg | 357 +++++++++++++++++++++++++++ cockatrice/src/carddatabase.cpp | 2 +- cockatrice/src/dlg_settings.cpp | 73 ++++-- cockatrice/src/dlg_settings.h | 4 + 5 files changed, 421 insertions(+), 16 deletions(-) create mode 100644 cockatrice/resources/icon_delete.svg diff --git a/cockatrice/cockatrice.qrc b/cockatrice/cockatrice.qrc index 14581493d..ee53d1af6 100644 --- a/cockatrice/cockatrice.qrc +++ b/cockatrice/cockatrice.qrc @@ -1,6 +1,7 @@ resources/back.svg + resources/icon_delete.svg resources/icon_tab_changed.svg resources/icon_config_general.svg resources/icon_config_appearance.svg diff --git a/cockatrice/resources/icon_delete.svg b/cockatrice/resources/icon_delete.svg new file mode 100644 index 000000000..008d8d429 --- /dev/null +++ b/cockatrice/resources/icon_delete.svg @@ -0,0 +1,357 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/cockatrice/src/carddatabase.cpp b/cockatrice/src/carddatabase.cpp index 4bb24da59..02a6f4d41 100644 --- a/cockatrice/src/carddatabase.cpp +++ b/cockatrice/src/carddatabase.cpp @@ -454,7 +454,7 @@ bool CardDatabase::loadFromFile(const QString &fileName) } } qDebug(QString("%1 cards in %2 sets loaded").arg(cardHash.size()).arg(setHash.size()).toLatin1()); - return true; + return !cardHash.isEmpty(); } bool CardDatabase::saveToFile(const QString &fileName) diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index a27d4b37b..1c4334949 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -151,43 +151,57 @@ void GeneralSettingsPage::retranslateUi() AppearanceSettingsPage::AppearanceSettingsPage() { + QIcon deleteIcon(":/resources/icon_delete.svg"); + handBgLabel = new QLabel; handBgEdit = new QLineEdit(settingsCache->getHandBgPath()); handBgEdit->setReadOnly(true); + QPushButton *handBgClearButton = new QPushButton(deleteIcon, QString()); + connect(handBgClearButton, SIGNAL(clicked()), this, SLOT(handBgClearButtonClicked())); QPushButton *handBgButton = new QPushButton("..."); connect(handBgButton, SIGNAL(clicked()), this, SLOT(handBgButtonClicked())); tableBgLabel = new QLabel; tableBgEdit = new QLineEdit(settingsCache->getTableBgPath()); tableBgEdit->setReadOnly(true); + QPushButton *tableBgClearButton = new QPushButton(deleteIcon, QString()); + connect(tableBgClearButton, SIGNAL(clicked()), this, SLOT(tableBgClearButtonClicked())); QPushButton *tableBgButton = new QPushButton("..."); connect(tableBgButton, SIGNAL(clicked()), this, SLOT(tableBgButtonClicked())); playerAreaBgLabel = new QLabel; playerAreaBgEdit = new QLineEdit(settingsCache->getPlayerBgPath()); playerAreaBgEdit->setReadOnly(true); + QPushButton *playerAreaBgClearButton = new QPushButton(deleteIcon, QString()); + connect(playerAreaBgClearButton, SIGNAL(clicked()), this, SLOT(playerAreaBgClearButtonClicked())); QPushButton *playerAreaBgButton = new QPushButton("..."); connect(playerAreaBgButton, SIGNAL(clicked()), this, SLOT(playerAreaBgButtonClicked())); cardBackPicturePathLabel = new QLabel; cardBackPicturePathEdit = new QLineEdit(settingsCache->getCardBackPicturePath()); cardBackPicturePathEdit->setReadOnly(true); + QPushButton *cardBackPicturePathClearButton = new QPushButton(deleteIcon, QString()); + connect(cardBackPicturePathClearButton, SIGNAL(clicked()), this, SLOT(cardBackPicturePathClearButtonClicked())); QPushButton *cardBackPicturePathButton = new QPushButton("..."); connect(cardBackPicturePathButton, SIGNAL(clicked()), this, SLOT(cardBackPicturePathButtonClicked())); QGridLayout *zoneBgGrid = new QGridLayout; zoneBgGrid->addWidget(handBgLabel, 0, 0); zoneBgGrid->addWidget(handBgEdit, 0, 1); - zoneBgGrid->addWidget(handBgButton, 0, 2); + zoneBgGrid->addWidget(handBgClearButton, 0, 2); + zoneBgGrid->addWidget(handBgButton, 0, 3); zoneBgGrid->addWidget(tableBgLabel, 1, 0); zoneBgGrid->addWidget(tableBgEdit, 1, 1); - zoneBgGrid->addWidget(tableBgButton, 1, 2); + zoneBgGrid->addWidget(tableBgClearButton, 1, 2); + zoneBgGrid->addWidget(tableBgButton, 1, 3); zoneBgGrid->addWidget(playerAreaBgLabel, 2, 0); zoneBgGrid->addWidget(playerAreaBgEdit, 2, 1); - zoneBgGrid->addWidget(playerAreaBgButton, 2, 2); + zoneBgGrid->addWidget(playerAreaBgClearButton, 2, 2); + zoneBgGrid->addWidget(playerAreaBgButton, 2, 3); zoneBgGrid->addWidget(cardBackPicturePathLabel, 3, 0); zoneBgGrid->addWidget(cardBackPicturePathEdit, 3, 1); - zoneBgGrid->addWidget(cardBackPicturePathButton, 3, 2); + zoneBgGrid->addWidget(cardBackPicturePathClearButton, 3, 2); + zoneBgGrid->addWidget(cardBackPicturePathButton, 3, 3); zoneBgGroupBox = new QGroupBox; zoneBgGroupBox->setLayout(zoneBgGrid); @@ -255,6 +269,12 @@ void AppearanceSettingsPage::retranslateUi() zoneViewSortByTypeCheckBox->setText(tr("Sort by type")); } +void AppearanceSettingsPage::handBgClearButtonClicked() +{ + handBgEdit->setText(QString()); + settingsCache->setHandBgPath(QString()); +} + void AppearanceSettingsPage::handBgButtonClicked() { QString path = QFileDialog::getOpenFileName(this, tr("Choose path")); @@ -265,6 +285,12 @@ void AppearanceSettingsPage::handBgButtonClicked() settingsCache->setHandBgPath(path); } +void AppearanceSettingsPage::tableBgClearButtonClicked() +{ + tableBgEdit->setText(QString()); + settingsCache->setTableBgPath(QString()); +} + void AppearanceSettingsPage::tableBgButtonClicked() { QString path = QFileDialog::getOpenFileName(this, tr("Choose path")); @@ -275,6 +301,12 @@ void AppearanceSettingsPage::tableBgButtonClicked() settingsCache->setTableBgPath(path); } +void AppearanceSettingsPage::playerAreaBgClearButtonClicked() +{ + playerAreaBgEdit->setText(QString()); + settingsCache->setPlayerBgPath(QString()); +} + void AppearanceSettingsPage::playerAreaBgButtonClicked() { QString path = QFileDialog::getOpenFileName(this, tr("Choose path")); @@ -285,6 +317,12 @@ void AppearanceSettingsPage::playerAreaBgButtonClicked() settingsCache->setPlayerBgPath(path); } +void AppearanceSettingsPage::cardBackPicturePathClearButtonClicked() +{ + cardBackPicturePathEdit->setText(QString()); + settingsCache->setCardBackPicturePath(QString()); +} + void AppearanceSettingsPage::cardBackPicturePathButtonClicked() { QString path = QFileDialog::getOpenFileName(this, tr("Choose path")); @@ -485,17 +523,22 @@ void DlgSettings::changeEvent(QEvent *event) void DlgSettings::closeEvent(QCloseEvent *event) { - if (!db->getLoadSuccess()) { - QMessageBox::critical(this, tr("Error"), tr("Your card database is invalid. Please check if the path is set correctly.")); - event->ignore(); - } else if (!QDir(settingsCache->getDeckPath()).exists()) { - QMessageBox::critical(this, tr("Error"), tr("The path to your deck directory is invalid.")); - event->ignore(); - } else if (!QDir(settingsCache->getPicsPath()).exists()) { - QMessageBox::critical(this, tr("Error"), tr("The path to your card pictures directory is invalid.")); - event->ignore(); - } else - event->accept(); + if (!db->getLoadSuccess()) + if (QMessageBox::critical(this, tr("Error"), tr("Your card database is invalid. Would you like to go back and set the correct path?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + event->ignore(); + return; + } + if (!QDir(settingsCache->getDeckPath()).exists()) + if (QMessageBox::critical(this, tr("Error"), tr("The path to your deck directory is invalid. Would you like to go back and set the correct path?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + event->ignore(); + return; + } + if (!QDir(settingsCache->getPicsPath()).exists()) + if (QMessageBox::critical(this, tr("Error"), tr("The path to your card pictures directory is invalid. Would you like to go back and set the correct path?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + event->ignore(); + return; + } + event->accept(); } void DlgSettings::retranslateUi() diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index f9cb71a1f..9e82cc7a7 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -48,9 +48,13 @@ private: class AppearanceSettingsPage : public AbstractSettingsPage { Q_OBJECT private slots: + void handBgClearButtonClicked(); void handBgButtonClicked(); + void tableBgClearButtonClicked(); void tableBgButtonClicked(); + void playerAreaBgClearButtonClicked(); void playerAreaBgButtonClicked(); + void cardBackPicturePathClearButtonClicked(); void cardBackPicturePathButtonClicked(); signals: void handBgChanged(const QString &path); From b1d8c7bda0e538939a438474327297422facc63e Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sat, 9 Oct 2010 18:50:06 +0200 Subject: [PATCH 5/6] Made QColor wrapper class so that Servatrice will compile without QtGui --- cockatrice/cockatrice.pro | 1 + cockatrice/src/player.cpp | 6 +- cockatrice/translations/cockatrice_de.ts | 98 +++++++++++++----------- cockatrice/translations/cockatrice_en.ts | 86 ++++++++++----------- cockatrice/translations/cockatrice_es.ts | 98 +++++++++++++----------- common/color.h | 27 +++++++ common/decklist.cpp | 1 - common/decklist.h | 1 + common/protocol_datastructures.cpp | 4 +- common/protocol_datastructures.h | 10 +-- common/protocol_items.cpp | 4 +- common/protocol_items.h | 8 +- common/protocol_mc.pl | 6 +- common/serializable_item.cpp | 14 +--- common/serializable_item.h | 12 ++- common/server_arrow.h | 8 +- common/server_counter.h | 8 +- common/server_player.cpp | 16 ++-- servatrice/servatrice.pro | 2 + 19 files changed, 226 insertions(+), 184 deletions(-) create mode 100644 common/color.h diff --git a/cockatrice/cockatrice.pro b/cockatrice/cockatrice.pro index e96500e07..c905b6c6d 100644 --- a/cockatrice/cockatrice.pro +++ b/cockatrice/cockatrice.pro @@ -64,6 +64,7 @@ HEADERS += src/counter.h \ src/localserver.h \ src/localserverinterface.h \ src/localclient.h \ + ../common/color.h \ ../common/serializable_item.h \ ../common/decklist.h \ ../common/protocol.h \ diff --git a/cockatrice/src/player.cpp b/cockatrice/src/player.cpp index dd7e56aa8..a91227a57 100644 --- a/cockatrice/src/player.cpp +++ b/cockatrice/src/player.cpp @@ -956,7 +956,7 @@ void Player::addZone(CardZone *z) Counter *Player::addCounter(ServerInfo_Counter *counter) { - return addCounter(counter->getId(), counter->getName(), counter->getColor(), counter->getRadius(), counter->getCount()); + return addCounter(counter->getId(), counter->getName(), counter->getColor().getQColor(), counter->getRadius(), counter->getCount()); } Counter *Player::addCounter(int counterId, const QString &name, QColor color, int radius, int value) @@ -1010,9 +1010,9 @@ ArrowItem *Player::addArrow(ServerInfo_Arrow *arrow) return 0; if (targetCard) - return addArrow(arrow->getId(), startCard, targetCard, arrow->getColor()); + return addArrow(arrow->getId(), startCard, targetCard, arrow->getColor().getQColor()); else - return addArrow(arrow->getId(), startCard, targetPlayer->getPlayerTarget(), arrow->getColor()); + return addArrow(arrow->getId(), startCard, targetPlayer->getPlayerTarget(), arrow->getColor().getQColor()); } ArrowItem *Player::addArrow(int arrowId, CardItem *startCard, ArrowTarget *targetItem, const QColor &color) diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index 505cd983d..95836ea9f 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -27,47 +27,47 @@ AppearanceSettingsPage - + Zone background pictures Hintergrundbilder für Kartenzonen - + Path to hand background: Hintergrundbild für die Hand: - + Path to table background: Hintergrundbild für das Spielfeld: - + Path to player info background: Hintergrundbild für den Spielerbereich: - + Path to picture of card back: Pfad zum Bild der Kartenrückseite: - + Hand layout Kartenhand - + Display hand horizontally (wastes space) Hand horizonal anzeigen (verschwendet Platz) - + Table grid layout Spielfeldraster - + Economical layout Platzsparende Anordnung @@ -76,17 +76,17 @@ Platzsparende Anordnung - + Zone view layout Aussehen des Zonenbetrachters - + Sort by name nach Namen sortieren - + Sort by type nach Kartentypen sortieren @@ -95,10 +95,10 @@ standardmäßig alphabetisch sortieren - - - + + + Choose path Pfad auswählen @@ -858,54 +858,66 @@ DlgSettings - - - + + + Error Fehler - Your card database is invalid. Please check if the path is set correctly. - Ihre Kartendatenbank ist ungültig. Bitte überprüfen Sie, ob der Pfad korrekt gesetzt ist. + Ihre Kartendatenbank ist ungültig. Bitte überprüfen Sie, ob der Pfad korrekt gesetzt ist. - The path to your deck directory is invalid. - Der Pfad zum Deckverzeichnis ist ungültig. + Der Pfad zum Deckverzeichnis ist ungültig. - The path to your card pictures directory is invalid. - Der Pfad zum Kartenbilderverzeichnis ist ungültig. + Der Pfad zum Kartenbilderverzeichnis ist ungültig. - + + Your card database is invalid. Would you like to go back and set the correct path? + Ihre Kartendatenbank ist ungültig. Möchten Sie zurückgehen und den korrekten Pfad einstellen? + + + + The path to your deck directory is invalid. Would you like to go back and set the correct path? + Der Pfad zu Ihrem Deckordner ist ungültig. Möchten Sie zurückgehen und den korrekten Pfad einstellen? + + + + The path to your card pictures directory is invalid. Would you like to go back and set the correct path? + Der Pfad zu Ihrem Kartenbilderordner ist ungültig. Möchten Sie zurückgehen und den korrekten Pfad einstellen? + + + Settings Einstellungen - + General Allgemeines - + Appearance Erscheinungsbild - + User interface Bedienung - + Messages Nachrichten - + &Close S&chließen @@ -2190,12 +2202,12 @@ MessagesSettingsPage - + &Add &Hinzufügen - + &Remove &Entfernen @@ -2208,12 +2220,12 @@ Entfernen - + Add message Nachricht hinzufügen - + Message: Nachricht: @@ -2757,27 +2769,27 @@ QObject - + Maindeck Hauptdeck - + Sideboard Sideboard - + Cockatrice decks (*.cod) Cockatrice Decks (*.cod) - + Plain text decks (*.dec *.mwDeck) Text Decks (*.dec *.mwDeck) - + All files (*.*) Alle Dateien (*.*) @@ -3077,22 +3089,22 @@ Bitte geben Sie einen Namen ein: UserInterfaceSettingsPage - + General interface settings Allgemeine Bedienung - + &Double-click cards to play them (instead of single-click) Karten durch &Doppelklick ausspielen (statt Einzelklick) - + Animation settings Animationseinstellungen - + &Tap/untap animation Animiertes &Tappen/Enttappen diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index 2f9d1ee67..23c3d2445 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -4,70 +4,70 @@ AppearanceSettingsPage - + Zone background pictures - + Path to hand background: - + Path to table background: - + Path to player info background: - + Path to picture of card back: - + Hand layout - + Display hand horizontally (wastes space) - + Table grid layout - + Economical layout - + Zone view layout - + Sort by name - + Sort by type - - - + + + Choose path @@ -735,54 +735,54 @@ DlgSettings - - - + + + Error - - Your card database is invalid. Please check if the path is set correctly. + + Your card database is invalid. Would you like to go back and set the correct path? - - The path to your deck directory is invalid. + + The path to your deck directory is invalid. Would you like to go back and set the correct path? - - The path to your card pictures directory is invalid. + + The path to your card pictures directory is invalid. Would you like to go back and set the correct path? - + Settings - + General - + Appearance - + User interface - + Messages - + &Close @@ -1489,22 +1489,22 @@ MessagesSettingsPage - + &Add - + &Remove - + Add message - + Message: @@ -1876,27 +1876,27 @@ QObject - + Maindeck - + Sideboard - + Cockatrice decks (*.cod) - + Plain text decks (*.dec *.mwDeck) - + All files (*.*) @@ -2152,22 +2152,22 @@ Please enter a name: UserInterfaceSettingsPage - + General interface settings - + &Double-click cards to play them (instead of single-click) - + Animation settings - + &Tap/untap animation diff --git a/cockatrice/translations/cockatrice_es.ts b/cockatrice/translations/cockatrice_es.ts index fe4b1c2c3..f6e1e6bdc 100644 --- a/cockatrice/translations/cockatrice_es.ts +++ b/cockatrice/translations/cockatrice_es.ts @@ -4,47 +4,47 @@ AppearanceSettingsPage - + Zone background pictures Imagenes de la zona de fondo - + Path to hand background: Ruta a la imagen de fondo de la mano: - + Path to table background: Ruta a la imagen de fondo de la mesa: - + Path to player info background: Ruta a la imagen de fondo de la información del jugador: - + Path to picture of card back: Ruta al reverso de las cartas: - + Hand layout Disposición de la mano - + Display hand horizontally (wastes space) Mostrar la mano horizontalmente (desperdicia espacio) - + Table grid layout Disposición de la rejilla de la mesa - + Economical layout @@ -53,25 +53,25 @@ Disposición económica - + Zone view layout Distribución de la zona de visionado - + Sort by name Ordenar por nombre - + Sort by type Ordenar por tipo - - - + + + Choose path Elija ruta @@ -739,54 +739,66 @@ DlgSettings - - - + + + Error Error - Your card database is invalid. Please check if the path is set correctly. - Tu base de datos de cartas es invalida. Por favor, comprueba si la ruta está asignada correctamente. + Tu base de datos de cartas es invalida. Por favor, comprueba si la ruta está asignada correctamente. - The path to your deck directory is invalid. - La ruta a tu directorio de mazos es invalida. + La ruta a tu directorio de mazos es invalida. - The path to your card pictures directory is invalid. - La ruta a tu directorio de imagenes de las cartas es invalida. + La ruta a tu directorio de imagenes de las cartas es invalida. - + + Your card database is invalid. Would you like to go back and set the correct path? + + + + + The path to your deck directory is invalid. Would you like to go back and set the correct path? + + + + + The path to your card pictures directory is invalid. Would you like to go back and set the correct path? + + + + Settings Preferencias - + General General - + Appearance Apariencia - + User interface Interfaz de usuario - + Messages Mensajes - + &Close &Cerrar @@ -1493,22 +1505,22 @@ MessagesSettingsPage - + &Add &Añadir - + &Remove &Quitar - + Add message Añadir mensaje - + Message: Mensaje: @@ -1892,27 +1904,27 @@ QObject - + Maindeck Mazo principal - + Sideboard Reserva - + Cockatrice decks (*.cod) Mazos de Cockatrice (*.cod) - + Plain text decks (*.dec *.mwDeck) Archivos de texto plano (*.dec *.mwDeck) - + All files (*.*) Todos los archivos (*.*) @@ -2169,22 +2181,22 @@ Por favor, introduzca un nombre: UserInterfaceSettingsPage - + General interface settings Preferencias generales de la interfaz - + &Double-click cards to play them (instead of single-click) &Doble click en las cartas para jugarlas (en lugar de un solo click) - + Animation settings - + &Tap/untap animation diff --git a/common/color.h b/common/color.h new file mode 100644 index 000000000..af498fdb4 --- /dev/null +++ b/common/color.h @@ -0,0 +1,27 @@ +#ifndef COLOR_H +#define COLOR_H + +#ifdef QT_GUI_LIB +#include +#endif + +class Color { +private: + int value; +public: + Color(int _value = 0) : value(_value) { } + Color(int r, int g, int b) : value(r * 65536 + g * 256 + b) { } + int getValue() const { return value; } +#ifdef QT_GUI_LIB + Color(const QColor &_color) + { + value = _color.red() * 65536 + _color.green() * 256 + _color.blue(); + } + QColor getQColor() const + { + return QColor(value / 65536, (value % 65536) / 256, value % 256); + } +#endif +}; + +#endif \ No newline at end of file diff --git a/common/decklist.cpp b/common/decklist.cpp index c52ef8ddc..ec5efbf5a 100644 --- a/common/decklist.cpp +++ b/common/decklist.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include diff --git a/common/decklist.h b/common/decklist.h index 55545a289..eca8dda08 100644 --- a/common/decklist.h +++ b/common/decklist.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "serializable_item.h" class CardDatabase; diff --git a/common/protocol_datastructures.cpp b/common/protocol_datastructures.cpp index a8f7a71f0..dbe927e28 100644 --- a/common/protocol_datastructures.cpp +++ b/common/protocol_datastructures.cpp @@ -113,7 +113,7 @@ QList ServerInfo_Zone::getCardList() const return result; } -ServerInfo_Counter::ServerInfo_Counter(int _id, const QString &_name, const QColor &_color, int _radius, int _count) +ServerInfo_Counter::ServerInfo_Counter(int _id, const QString &_name, const Color &_color, int _radius, int _count) : SerializableItem_Map("counter") { insertItem(new SerializableItem_Int("id", _id)); @@ -123,7 +123,7 @@ ServerInfo_Counter::ServerInfo_Counter(int _id, const QString &_name, const QCol insertItem(new SerializableItem_Int("count", _count)); } -ServerInfo_Arrow::ServerInfo_Arrow(int _id, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color) +ServerInfo_Arrow::ServerInfo_Arrow(int _id, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const Color &_color) : SerializableItem_Map("arrow") { insertItem(new SerializableItem_Int("id", _id)); diff --git a/common/protocol_datastructures.h b/common/protocol_datastructures.h index f6ead5558..6e498dbe8 100644 --- a/common/protocol_datastructures.h +++ b/common/protocol_datastructures.h @@ -2,9 +2,9 @@ #define PROTOCOL_DATASTRUCTURES_H #include -#include #include #include "serializable_item.h" +#include "color.h" class DeckList; @@ -107,18 +107,18 @@ public: class ServerInfo_Counter : public SerializableItem_Map { public: - ServerInfo_Counter(int _id = -1, const QString &_name = QString(), const QColor &_color = QColor(), int _radius = -1, int _count = -1); + ServerInfo_Counter(int _id = -1, const QString &_name = QString(), const Color &_color = Color(), int _radius = -1, int _count = -1); static SerializableItem *newItem() { return new ServerInfo_Counter; } int getId() const { return static_cast(itemMap.value("id"))->getData(); } QString getName() const { return static_cast(itemMap.value("name"))->getData(); } - QColor getColor() const { return static_cast(itemMap.value("color"))->getData(); } + Color getColor() const { return static_cast(itemMap.value("color"))->getData(); } int getRadius() const { return static_cast(itemMap.value("radius"))->getData(); } int getCount() const { return static_cast(itemMap.value("count"))->getData(); } }; class ServerInfo_Arrow : public SerializableItem_Map { public: - ServerInfo_Arrow(int _id = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor()); + ServerInfo_Arrow(int _id = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const Color &_color = Color()); static SerializableItem *newItem() { return new ServerInfo_Arrow; } int getId() const { return static_cast(itemMap.value("id"))->getData(); } int getStartPlayerId() const { return static_cast(itemMap.value("start_player_id"))->getData(); } @@ -127,7 +127,7 @@ public: int getTargetPlayerId() const { return static_cast(itemMap.value("target_player_id"))->getData(); } QString getTargetZone() const { return static_cast(itemMap.value("target_zone"))->getData(); } int getTargetCardId() const { return static_cast(itemMap.value("target_card_id"))->getData(); } - QColor getColor() const { return static_cast(itemMap.value("color"))->getData(); } + Color getColor() const { return static_cast(itemMap.value("color"))->getData(); } }; class ServerInfo_PlayerProperties : public SerializableItem_Map { diff --git a/common/protocol_items.cpp b/common/protocol_items.cpp index 9c5c8d597..369bd5181 100644 --- a/common/protocol_items.cpp +++ b/common/protocol_items.cpp @@ -152,7 +152,7 @@ Command_CreateToken::Command_CreateToken(int _gameId, const QString &_zone, cons insertItem(new SerializableItem_Int("x", _x)); insertItem(new SerializableItem_Int("y", _y)); } -Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const QColor &_color) +Command_CreateArrow::Command_CreateArrow(int _gameId, int _startPlayerId, const QString &_startZone, int _startCardId, int _targetPlayerId, const QString &_targetZone, int _targetCardId, const Color &_color) : GameCommand("create_arrow", _gameId) { insertItem(new SerializableItem_Int("start_player_id", _startPlayerId)); @@ -207,7 +207,7 @@ Command_IncCounter::Command_IncCounter(int _gameId, int _counterId, int _delta) insertItem(new SerializableItem_Int("counter_id", _counterId)); insertItem(new SerializableItem_Int("delta", _delta)); } -Command_CreateCounter::Command_CreateCounter(int _gameId, const QString &_counterName, const QColor &_color, int _radius, int _value) +Command_CreateCounter::Command_CreateCounter(int _gameId, const QString &_counterName, const Color &_color, int _radius, int _value) : GameCommand("create_counter", _gameId) { insertItem(new SerializableItem_String("counter_name", _counterName)); diff --git a/common/protocol_items.h b/common/protocol_items.h index 3edfc650c..277211e5a 100644 --- a/common/protocol_items.h +++ b/common/protocol_items.h @@ -235,14 +235,14 @@ public: class Command_CreateArrow : public GameCommand { Q_OBJECT public: - Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const QColor &_color = QColor()); + Command_CreateArrow(int _gameId = -1, int _startPlayerId = -1, const QString &_startZone = QString(), int _startCardId = -1, int _targetPlayerId = -1, const QString &_targetZone = QString(), int _targetCardId = -1, const Color &_color = Color()); int getStartPlayerId() const { return static_cast(itemMap.value("start_player_id"))->getData(); }; QString getStartZone() const { return static_cast(itemMap.value("start_zone"))->getData(); }; int getStartCardId() const { return static_cast(itemMap.value("start_card_id"))->getData(); }; int getTargetPlayerId() const { return static_cast(itemMap.value("target_player_id"))->getData(); }; QString getTargetZone() const { return static_cast(itemMap.value("target_zone"))->getData(); }; int getTargetCardId() const { return static_cast(itemMap.value("target_card_id"))->getData(); }; - QColor getColor() const { return static_cast(itemMap.value("color"))->getData(); }; + Color getColor() const { return static_cast(itemMap.value("color"))->getData(); }; static SerializableItem *newItem() { return new Command_CreateArrow; } int getItemId() const { return ItemId_Command_CreateArrow; } }; @@ -314,9 +314,9 @@ public: class Command_CreateCounter : public GameCommand { Q_OBJECT public: - Command_CreateCounter(int _gameId = -1, const QString &_counterName = QString(), const QColor &_color = QColor(), int _radius = -1, int _value = -1); + Command_CreateCounter(int _gameId = -1, const QString &_counterName = QString(), const Color &_color = Color(), int _radius = -1, int _value = -1); QString getCounterName() const { return static_cast(itemMap.value("counter_name"))->getData(); }; - QColor getColor() const { return static_cast(itemMap.value("color"))->getData(); }; + Color getColor() const { return static_cast(itemMap.value("color"))->getData(); }; int getRadius() const { return static_cast(itemMap.value("radius"))->getData(); }; int getValue() const { return static_cast(itemMap.value("value"))->getData(); }; static SerializableItem *newItem() { return new Command_CreateCounter; } diff --git a/common/protocol_mc.pl b/common/protocol_mc.pl index 765b23e60..696915d92 100755 --- a/common/protocol_mc.pl +++ b/common/protocol_mc.pl @@ -109,9 +109,9 @@ while () { $constructorCode .= "\tinsertItem(new SerializableItem_Int(\"$value\", _$prettyVarName));\n"; $getFunctionCode .= "\t$dataType get$prettyVarName2() const { return static_cast(itemMap.value(\"$value\"))->getData(); };\n"; } elsif ($key eq 'c') { - $dataType = 'QColor'; - $constructorParamsH .= "const QColor &_$prettyVarName = QColor()"; - $constructorParamsCpp .= "const QColor &_$prettyVarName"; + $dataType = 'Color'; + $constructorParamsH .= "const Color &_$prettyVarName = Color()"; + $constructorParamsCpp .= "const Color &_$prettyVarName"; $constructorCode .= "\tinsertItem(new SerializableItem_Color(\"$value\", _$prettyVarName));\n"; $getFunctionCode .= "\t$dataType get$prettyVarName2() const { return static_cast(itemMap.value(\"$value\"))->getData(); };\n"; } diff --git a/common/serializable_item.cpp b/common/serializable_item.cpp index 7815259b2..9a091e452 100644 --- a/common/serializable_item.cpp +++ b/common/serializable_item.cpp @@ -116,29 +116,19 @@ void SerializableItem_Bool::writeElement(QXmlStreamWriter *xml) xml->writeCharacters(data ? "1" : "0"); } -int SerializableItem_Color::colorToInt(const QColor &color) const -{ - return color.red() * 65536 + color.green() * 256 + color.blue(); -} - -QColor SerializableItem_Color::colorFromInt(int colorValue) const -{ - return QColor(colorValue / 65536, (colorValue % 65536) / 256, colorValue % 256); -} - bool SerializableItem_Color::readElement(QXmlStreamReader *xml) { if (xml->isCharacters() && !xml->isWhitespace()) { bool ok; int colorValue = xml->text().toString().toInt(&ok); - data = ok ? colorFromInt(colorValue) : Qt::black; + data = ok ? Color(colorValue) : Color(); } return SerializableItem::readElement(xml); } void SerializableItem_Color::writeElement(QXmlStreamWriter *xml) { - xml->writeCharacters(QString::number(colorToInt(data))); + xml->writeCharacters(QString::number(data.getValue())); } bool SerializableItem_DateTime::readElement(QXmlStreamReader *xml) diff --git a/common/serializable_item.h b/common/serializable_item.h index 54dd44a13..4867d8a10 100644 --- a/common/serializable_item.h +++ b/common/serializable_item.h @@ -6,8 +6,8 @@ #include #include #include -#include #include +#include "color.h" class QXmlStreamReader; class QXmlStreamWriter; @@ -111,17 +111,15 @@ public: class SerializableItem_Color : public SerializableItem { private: - QColor data; - int colorToInt(const QColor &color) const; - QColor colorFromInt(int colorValue) const; + Color data; protected: bool readElement(QXmlStreamReader *xml); void writeElement(QXmlStreamWriter *xml); public: - SerializableItem_Color(const QString &_itemType, const QColor &_data) + SerializableItem_Color(const QString &_itemType, const Color &_data) : SerializableItem(_itemType), data(_data) { } - const QColor &getData() { return data; } - void setData(const QColor &_data) { data = _data; } + const Color &getData() { return data; } + void setData(const Color &_data) { data = _data; } }; class SerializableItem_DateTime : public SerializableItem { diff --git a/common/server_arrow.h b/common/server_arrow.h index d82ac6cd6..e608a20b4 100644 --- a/common/server_arrow.h +++ b/common/server_arrow.h @@ -1,7 +1,7 @@ #ifndef SERVER_ARROW_H #define SERVER_ARROW_H -#include +#include "color.h" class Server_Card; class Server_ArrowTarget; @@ -11,14 +11,14 @@ private: int id; Server_Card *startCard; Server_ArrowTarget *targetItem; - QColor color; + Color color; public: - Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const QColor &_color) + Server_Arrow(int _id, Server_Card *_startCard, Server_ArrowTarget *_targetItem, const Color &_color) : id(_id), startCard(_startCard), targetItem(_targetItem), color(_color) { } int getId() const { return id; } Server_Card *getStartCard() const { return startCard; } Server_ArrowTarget *getTargetItem() const { return targetItem; } - QColor getColor() const { return color; } + const Color &getColor() const { return color; } }; #endif diff --git a/common/server_counter.h b/common/server_counter.h index aa3fe0711..20a438a67 100644 --- a/common/server_counter.h +++ b/common/server_counter.h @@ -21,21 +21,21 @@ #define SERVER_COUNTER_H #include -#include +#include "color.h" class Server_Counter { protected: int id; QString name; - QColor color; + Color color; int radius; int count; public: - Server_Counter(int _id, const QString &_name, const QColor &_color, int _radius, int _count = 0) : id(_id), name(_name), color(_color), radius(_radius), count(_count) { } + Server_Counter(int _id, const QString &_name, const Color &_color, int _radius, int _count = 0) : id(_id), name(_name), color(_color), radius(_radius), count(_count) { } ~Server_Counter() { } int getId() const { return id; } QString getName() const { return name; } - QColor getColor() const { return color; } + Color getColor() const { return color; } int getRadius() const { return radius; } int getCount() const { return count; } void setCount(int _count) { count = _count; } diff --git a/common/server_player.cpp b/common/server_player.cpp index daed7b1a5..4a6fd692b 100644 --- a/common/server_player.cpp +++ b/common/server_player.cpp @@ -67,14 +67,14 @@ void Server_Player::setupZones() addZone(new Server_CardZone(this, "grave", false, PublicZone)); addZone(new Server_CardZone(this, "rfg", false, PublicZone)); - addCounter(new Server_Counter(0, "life", Qt::white, 25, 20)); - addCounter(new Server_Counter(1, "w", QColor(255, 255, 150), 20, 0)); - addCounter(new Server_Counter(2, "u", QColor(150, 150, 255), 20, 0)); - addCounter(new Server_Counter(3, "b", QColor(150, 150, 150), 20, 0)); - addCounter(new Server_Counter(4, "r", QColor(250, 150, 150), 20, 0)); - addCounter(new Server_Counter(5, "g", QColor(150, 255, 150), 20, 0)); - addCounter(new Server_Counter(6, "x", QColor(255, 255, 255), 20, 0)); - addCounter(new Server_Counter(7, "storm", QColor(255, 255, 255), 20, 0)); + addCounter(new Server_Counter(0, "life", Color(255, 255, 255), 25, 20)); + addCounter(new Server_Counter(1, "w", Color(255, 255, 150), 20, 0)); + addCounter(new Server_Counter(2, "u", Color(150, 150, 255), 20, 0)); + addCounter(new Server_Counter(3, "b", Color(150, 150, 150), 20, 0)); + addCounter(new Server_Counter(4, "r", Color(250, 150, 150), 20, 0)); + addCounter(new Server_Counter(5, "g", Color(150, 255, 150), 20, 0)); + addCounter(new Server_Counter(6, "x", Color(255, 255, 255), 20, 0)); + addCounter(new Server_Counter(7, "storm", Color(255, 255, 255), 20, 0)); initialCards = 7; diff --git a/servatrice/servatrice.pro b/servatrice/servatrice.pro index 60f04b7c6..d89ecf08f 100755 --- a/servatrice/servatrice.pro +++ b/servatrice/servatrice.pro @@ -11,9 +11,11 @@ OBJECTS_DIR = build CONFIG += qt debug QT += network sql +QT -= gui HEADERS += src/servatrice.h \ src/serversocketinterface.h \ + ../common/color.h \ ../common/serializable_item.h \ ../common/decklist.h \ ../common/protocol.h \ From 8d6a4f4f90805770f2816c6a4e4b5c9afca2aca3 Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Sun, 10 Oct 2010 00:06:05 +0200 Subject: [PATCH 6/6] preliminary avatar support --- cockatrice/src/tab_server.cpp | 61 +++++++++- cockatrice/src/tab_server.h | 13 +++ cockatrice/translations/cockatrice_de.ts | 53 +++++---- cockatrice/translations/cockatrice_en.ts | 53 +++++---- cockatrice/translations/cockatrice_es.ts | 53 +++++---- common/protocol.cpp | 9 ++ common/protocol.h | 18 ++- common/protocol_datastructures.cpp | 4 +- common/protocol_datastructures.h | 3 +- common/protocol_item_ids.h | 135 ++++++++++++----------- common/protocol_items.cpp | 6 + common/protocol_items.dat | 1 + common/protocol_items.h | 8 ++ common/serializable_item.cpp | 13 +++ common/serializable_item.h | 15 ++- common/server.cpp | 2 - common/server_protocolhandler.cpp | 20 ++++ common/server_protocolhandler.h | 1 + servatrice/src/servatrice.cpp | 19 +++- 19 files changed, 344 insertions(+), 143 deletions(-) diff --git a/cockatrice/src/tab_server.cpp b/cockatrice/src/tab_server.cpp index 9014d783d..04eb7e1b9 100644 --- a/cockatrice/src/tab_server.cpp +++ b/cockatrice/src/tab_server.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -338,12 +339,65 @@ void UserList::userClicked(QTreeWidgetItem *item, int /*column*/) emit openMessageDialog(item->data(2, Qt::UserRole).toString(), true); } +UserInfoBox::UserInfoBox(AbstractClient *_client, QWidget *parent) + : QWidget(parent) +{ + avatarLabel = new QLabel; + nameLabel = new QLabel; + QFont nameFont = nameLabel->font(); + nameFont.setBold(true); + nameFont.setPointSize(nameFont.pointSize() * 1.5); + nameLabel->setFont(nameFont); + countryLabel1 = new QLabel; + countryLabel2 = new QLabel; + userLevelLabel1 = new QLabel; + userLevelLabel2 = new QLabel; + + QGridLayout *mainLayout = new QGridLayout; + mainLayout->addWidget(avatarLabel, 0, 0, 3, 1); + mainLayout->addWidget(nameLabel, 0, 1, 1, 2); + mainLayout->addWidget(countryLabel1, 1, 1, 1, 1); + mainLayout->addWidget(countryLabel2, 1, 2, 1, 1); + mainLayout->addWidget(userLevelLabel1, 2, 1, 1, 1); + mainLayout->addWidget(userLevelLabel2, 2, 2, 1, 1); + + setLayout(mainLayout); + + Command_GetUserInfo *cmd = new Command_GetUserInfo; + connect(cmd, SIGNAL(finished(ProtocolResponse *)), this, SLOT(processResponse(ProtocolResponse *))); + _client->sendCommand(cmd); +} + +void UserInfoBox::retranslateUi() +{ + countryLabel1->setText(tr("Location:")); + userLevelLabel1->setText(tr("User level:")); +} + +void UserInfoBox::processResponse(ProtocolResponse *response) +{ + Response_GetUserInfo *resp = qobject_cast(response); + if (!resp) + return; + ServerInfo_User *user = resp->getUserInfo(); + + QPixmap avatarPixmap; + if (!avatarPixmap.loadFromData(user->getAvatarBmp())) + avatarPixmap = UserLevelPixmapGenerator::generatePixmap(64, user->getUserLevel()); + avatarLabel->setPixmap(avatarPixmap); + + nameLabel->setText(user->getName()); + countryLabel2->setPixmap(CountryPixmapGenerator::generatePixmap(15, user->getCountry())); + userLevelLabel2->setPixmap(UserLevelPixmapGenerator::generatePixmap(15, user->getUserLevel())); +} + TabServer::TabServer(AbstractClient *_client, QWidget *parent) : Tab(parent), client(_client) { gameSelector = new GameSelector(client); chatChannelSelector = new ChatChannelSelector(client); serverMessageLog = new ServerMessageLog(client); + userInfoBox = new UserInfoBox(client); userList = new UserList(client); connect(gameSelector, SIGNAL(gameJoined(int)), this, SIGNAL(gameJoined(int))); @@ -359,9 +413,13 @@ TabServer::TabServer(AbstractClient *_client, QWidget *parent) vbox->addWidget(gameSelector); vbox->addLayout(hbox); + QVBoxLayout *vbox2 = new QVBoxLayout; + vbox2->addWidget(userInfoBox); + vbox2->addWidget(userList); + QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addLayout(vbox, 3); - mainLayout->addWidget(userList, 1); + mainLayout->addLayout(vbox2, 1); setLayout(mainLayout); } @@ -371,5 +429,6 @@ void TabServer::retranslateUi() gameSelector->retranslateUi(); chatChannelSelector->retranslateUi(); serverMessageLog->retranslateUi(); + userInfoBox->retranslateUi(); userList->retranslateUi(); } diff --git a/cockatrice/src/tab_server.h b/cockatrice/src/tab_server.h index d9549e20d..3ddd89cd5 100644 --- a/cockatrice/src/tab_server.h +++ b/cockatrice/src/tab_server.h @@ -13,6 +13,7 @@ class QTreeWidgetItem; class QPushButton; class QCheckBox; class QTextEdit; +class QLabel; class GamesModel; class GamesProxyModel; @@ -101,6 +102,17 @@ public: void retranslateUi(); }; +class UserInfoBox : public QWidget { + Q_OBJECT +private: + QLabel *avatarLabel, *nameLabel, *countryLabel1, *countryLabel2, *userLevelLabel1, *userLevelLabel2; +private slots: + void processResponse(ProtocolResponse *response); +public: + UserInfoBox(AbstractClient *_client, QWidget *parent = 0); + void retranslateUi(); +}; + class TabServer : public Tab { Q_OBJECT signals: @@ -114,6 +126,7 @@ private: ChatChannelSelector *chatChannelSelector; ServerMessageLog *serverMessageLog; UserList *userList; + UserInfoBox *userInfoBox; public: TabServer(AbstractClient *_client, QWidget *parent = 0); void retranslateUi(); diff --git a/cockatrice/translations/cockatrice_de.ts b/cockatrice/translations/cockatrice_de.ts index 95836ea9f..08a93af4d 100644 --- a/cockatrice/translations/cockatrice_de.ts +++ b/cockatrice/translations/cockatrice_de.ts @@ -402,27 +402,27 @@ ChatChannelSelector - + Chat channels Chaträume - + Joi&n Teil&nehmen - + Channel Raum - + Description Beschreibung - + Players Spieler @@ -1183,20 +1183,20 @@ GameSelector - + C&reate Spiel e&rstellen - + &Join &Teilnehmen - + Error Fehler @@ -1205,47 +1205,47 @@ XXX - + Wrong password. Falsches Passwort. - + Spectators are not allowed in this game. In diesem Spiel sind keine Zuschauer zugelassen. - + The game is already full. Das Spiel ist bereits voll. - + The game does not exist any more. Dieses Spiel gibt es nicht mehr. - + Join game Spiel beitreten - + Password: Passwort: - + Games Spiele - + &Show full games &Volle Spiele anzeigen - + J&oin as spectator &Zuschauen @@ -2815,7 +2815,7 @@ ServerMessageLog - + Server messages Servernachrichten @@ -3066,7 +3066,7 @@ Bitte geben Sie einen Namen ein: TabServer - + Server Server @@ -3086,6 +3086,19 @@ Bitte geben Sie einen Namen ein: Spiel %1 + + UserInfoBox + + + Location: + Ort: + + + + User level: + Nutzerstatus: + + UserInterfaceSettingsPage @@ -3112,7 +3125,7 @@ Bitte geben Sie einen Namen ein: UserList - + Users online: %1 Benutzer online: %1 diff --git a/cockatrice/translations/cockatrice_en.ts b/cockatrice/translations/cockatrice_en.ts index 23c3d2445..c04f4ab0f 100644 --- a/cockatrice/translations/cockatrice_en.ts +++ b/cockatrice/translations/cockatrice_en.ts @@ -352,27 +352,27 @@ ChatChannelSelector - + Chat channels - + Joi&n - + Channel - + Description - + Players @@ -790,65 +790,65 @@ GameSelector - + C&reate - + &Join - + Error - + Wrong password. - + Spectators are not allowed in this game. - + The game is already full. - + The game does not exist any more. - + Join game - + Password: - + Games - + &Show full games - + J&oin as spectator @@ -1922,7 +1922,7 @@ ServerMessageLog - + Server messages @@ -2144,11 +2144,24 @@ Please enter a name: TabServer - + Server + + UserInfoBox + + + Location: + + + + + User level: + + + UserInterfaceSettingsPage @@ -2175,7 +2188,7 @@ Please enter a name: UserList - + Users online: %1 diff --git a/cockatrice/translations/cockatrice_es.ts b/cockatrice/translations/cockatrice_es.ts index f6e1e6bdc..34cb314e6 100644 --- a/cockatrice/translations/cockatrice_es.ts +++ b/cockatrice/translations/cockatrice_es.ts @@ -356,27 +356,27 @@ ChatChannelSelector - + Chat channels Canales de Chat - + Joi&n E&ntrar - + Channel Canal - + Description Descripción - + Players Jugadores @@ -806,65 +806,65 @@ GameSelector - + C&reate C&rear - + &Join E&ntrar - + Error Error - + Wrong password. Contraseña incorrecta. - + Spectators are not allowed in this game. No se permiten espectadores en esta partida. - + The game is already full. La partida no tiene plazas libres. - + The game does not exist any more. La partida ya no existe. - + Join game Entrar en la partida - + Password: Contraseña: - + Games Partidas - + &Show full games &Ver partidas sin plazas libres - + J&oin as spectator Entrar como e&spectador @@ -1950,7 +1950,7 @@ ServerMessageLog - + Server messages Mensajes del servidor @@ -2173,11 +2173,24 @@ Por favor, introduzca un nombre: TabServer - + Server Servidor + + UserInfoBox + + + Location: + + + + + User level: + + + UserInterfaceSettingsPage @@ -2204,7 +2217,7 @@ Por favor, introduzca un nombre: UserList - + Users online: %1 Usuarios online: %1 diff --git a/common/protocol.cpp b/common/protocol.cpp index 4facb234d..dac2c55c1 100644 --- a/common/protocol.cpp +++ b/common/protocol.cpp @@ -38,6 +38,7 @@ void ProtocolItem::initializeHash() registerSerializableItem("resp", ProtocolResponse::newItem); ProtocolResponse::initializeHash(); registerSerializableItem("resplist_users", Response_ListUsers::newItem); + registerSerializableItem("respget_user_info", Response_GetUserInfo::newItem); registerSerializableItem("respdeck_list", Response_DeckList::newItem); registerSerializableItem("respdeck_download", Response_DeckDownload::newItem); registerSerializableItem("respdeck_upload", Response_DeckUpload::newItem); @@ -232,6 +233,14 @@ Response_DeckList::Response_DeckList(int _cmdId, ResponseCode _responseCode, Dec insertItem(_root); } +Response_GetUserInfo::Response_GetUserInfo(int _cmdId, ResponseCode _responseCode, ServerInfo_User *_user) + : ProtocolResponse(_cmdId, _responseCode, "get_user_info") +{ + if (!_user) + _user = new ServerInfo_User; + insertItem(_user); +} + Response_DeckDownload::Response_DeckDownload(int _cmdId, ResponseCode _responseCode, DeckList *_deck) : ProtocolResponse(_cmdId, _responseCode, "deck_download") { diff --git a/common/protocol.h b/common/protocol.h index b7de90f37..53532e6e6 100644 --- a/common/protocol.h +++ b/common/protocol.h @@ -38,10 +38,11 @@ enum ItemId { ItemId_Event_Join = ItemId_Other + 210, ItemId_Event_Ping = ItemId_Other + 211, ItemId_Response_ListUsers = ItemId_Other + 300, - ItemId_Response_DeckList = ItemId_Other + 301, - ItemId_Response_DeckDownload = ItemId_Other + 302, - ItemId_Response_DeckUpload = ItemId_Other + 303, - ItemId_Response_DumpZone = ItemId_Other + 304, + ItemId_Response_GetUserInfo = ItemId_Other + 301, + ItemId_Response_DeckList = ItemId_Other + 302, + ItemId_Response_DeckDownload = ItemId_Other + 303, + ItemId_Response_DeckUpload = ItemId_Other + 304, + ItemId_Response_DumpZone = ItemId_Other + 305, ItemId_Invalid = ItemId_Other + 1000 }; @@ -210,6 +211,15 @@ public: QList getUserList() const { return typecastItemList(); } }; +class Response_GetUserInfo : public ProtocolResponse { + Q_OBJECT +public: + Response_GetUserInfo(int _cmdId = -1, ResponseCode _responseCode = RespOk, ServerInfo_User *_userInfo = 0); + int getItemId() const { return ItemId_Response_GetUserInfo; } + static SerializableItem *newItem() { return new Response_GetUserInfo; } + ServerInfo_User *getUserInfo() const { return static_cast(itemMap.value("user")); } +}; + class Response_DeckList : public ProtocolResponse { Q_OBJECT public: diff --git a/common/protocol_datastructures.cpp b/common/protocol_datastructures.cpp index dbe927e28..afbf726af 100644 --- a/common/protocol_datastructures.cpp +++ b/common/protocol_datastructures.cpp @@ -12,12 +12,13 @@ ServerInfo_ChatChannel::ServerInfo_ChatChannel(const QString &_name, const QStri insertItem(new SerializableItem_Bool("auto_join", _autoJoin)); } -ServerInfo_User::ServerInfo_User(const QString &_name, int _userLevel, const QString &_country) +ServerInfo_User::ServerInfo_User(const QString &_name, int _userLevel, const QString &_country, const QByteArray &_avatarBmp) : SerializableItem_Map("user") { insertItem(new SerializableItem_String("name", _name)); insertItem(new SerializableItem_Int("userlevel", _userLevel)); insertItem(new SerializableItem_String("country", _country)); + insertItem(new SerializableItem_ByteArray("avatar_bmp", _avatarBmp)); } ServerInfo_User::ServerInfo_User(const ServerInfo_User *other) @@ -26,6 +27,7 @@ ServerInfo_User::ServerInfo_User(const ServerInfo_User *other) insertItem(new SerializableItem_String("name", other->getName())); insertItem(new SerializableItem_Int("userlevel", other->getUserLevel())); insertItem(new SerializableItem_String("country", other->getCountry())); + insertItem(new SerializableItem_ByteArray("avatar_bmp", other->getAvatarBmp())); } ServerInfo_Game::ServerInfo_Game(int _gameId, const QString &_description, bool _hasPassword, int _playerCount, int _maxPlayers, ServerInfo_User *_creatorInfo, bool _spectatorsAllowed, bool _spectatorsNeedPassword, int _spectatorCount) diff --git a/common/protocol_datastructures.h b/common/protocol_datastructures.h index 6e498dbe8..ff16b667f 100644 --- a/common/protocol_datastructures.h +++ b/common/protocol_datastructures.h @@ -39,13 +39,14 @@ public: IsJudge = 0x04, IsAdmin = 0x08 }; - ServerInfo_User(const QString &_name = QString(), int _userLevel = IsNothing, const QString &_country = QString()); + ServerInfo_User(const QString &_name = QString(), int _userLevel = IsNothing, const QString &_country = QString(), const QByteArray &_avatarBmp = QByteArray()); ServerInfo_User(const ServerInfo_User *other); static SerializableItem *newItem() { return new ServerInfo_User; } QString getName() const { return static_cast(itemMap.value("name"))->getData(); } int getUserLevel() const { return static_cast(itemMap.value("userlevel"))->getData(); } void setUserLevel(int _userLevel) { static_cast(itemMap.value("userlevel"))->setData(_userLevel); } QString getCountry() const { return static_cast(itemMap.value("country"))->getData(); } + QByteArray getAvatarBmp() const { return static_cast(itemMap.value("avatar_bmp"))->getData(); } }; class ServerInfo_Game : public SerializableItem_Map { diff --git a/common/protocol_item_ids.h b/common/protocol_item_ids.h index 211e03acc..6921eb813 100644 --- a/common/protocol_item_ids.h +++ b/common/protocol_item_ids.h @@ -2,71 +2,72 @@ enum AutoItemId { ItemId_Command_Ping = 1001, ItemId_Command_Login = 1002, ItemId_Command_Message = 1003, -ItemId_Command_DeckList = 1004, -ItemId_Command_DeckNewDir = 1005, -ItemId_Command_DeckDelDir = 1006, -ItemId_Command_DeckDel = 1007, -ItemId_Command_DeckDownload = 1008, -ItemId_Command_ListChatChannels = 1009, -ItemId_Command_ChatJoinChannel = 1010, -ItemId_Command_ChatLeaveChannel = 1011, -ItemId_Command_ChatSay = 1012, -ItemId_Command_ListGames = 1013, -ItemId_Command_ListUsers = 1014, -ItemId_Command_CreateGame = 1015, -ItemId_Command_JoinGame = 1016, -ItemId_Command_LeaveGame = 1017, -ItemId_Command_Say = 1018, -ItemId_Command_Shuffle = 1019, -ItemId_Command_Mulligan = 1020, -ItemId_Command_RollDie = 1021, -ItemId_Command_DrawCards = 1022, -ItemId_Command_MoveCard = 1023, -ItemId_Command_FlipCard = 1024, -ItemId_Command_AttachCard = 1025, -ItemId_Command_CreateToken = 1026, -ItemId_Command_CreateArrow = 1027, -ItemId_Command_DeleteArrow = 1028, -ItemId_Command_SetCardAttr = 1029, -ItemId_Command_SetCardCounter = 1030, -ItemId_Command_IncCardCounter = 1031, -ItemId_Command_ReadyStart = 1032, -ItemId_Command_Concede = 1033, -ItemId_Command_IncCounter = 1034, -ItemId_Command_CreateCounter = 1035, -ItemId_Command_SetCounter = 1036, -ItemId_Command_DelCounter = 1037, -ItemId_Command_NextTurn = 1038, -ItemId_Command_SetActivePhase = 1039, -ItemId_Command_DumpZone = 1040, -ItemId_Command_StopDumpZone = 1041, -ItemId_Event_Say = 1042, -ItemId_Event_Leave = 1043, -ItemId_Event_GameClosed = 1044, -ItemId_Event_Shuffle = 1045, -ItemId_Event_RollDie = 1046, -ItemId_Event_MoveCard = 1047, -ItemId_Event_FlipCard = 1048, -ItemId_Event_DestroyCard = 1049, -ItemId_Event_AttachCard = 1050, -ItemId_Event_CreateToken = 1051, -ItemId_Event_DeleteArrow = 1052, -ItemId_Event_SetCardAttr = 1053, -ItemId_Event_SetCardCounter = 1054, -ItemId_Event_SetCounter = 1055, -ItemId_Event_DelCounter = 1056, -ItemId_Event_SetActivePlayer = 1057, -ItemId_Event_SetActivePhase = 1058, -ItemId_Event_DumpZone = 1059, -ItemId_Event_StopDumpZone = 1060, -ItemId_Event_ServerMessage = 1061, -ItemId_Event_Message = 1062, -ItemId_Event_GameJoined = 1063, -ItemId_Event_UserLeft = 1064, -ItemId_Event_ChatLeaveChannel = 1065, -ItemId_Event_ChatSay = 1066, -ItemId_Context_ReadyStart = 1067, -ItemId_Context_Concede = 1068, -ItemId_Context_DeckSelect = 1069, -ItemId_Other = 1070 +ItemId_Command_GetUserInfo = 1004, +ItemId_Command_DeckList = 1005, +ItemId_Command_DeckNewDir = 1006, +ItemId_Command_DeckDelDir = 1007, +ItemId_Command_DeckDel = 1008, +ItemId_Command_DeckDownload = 1009, +ItemId_Command_ListChatChannels = 1010, +ItemId_Command_ChatJoinChannel = 1011, +ItemId_Command_ChatLeaveChannel = 1012, +ItemId_Command_ChatSay = 1013, +ItemId_Command_ListGames = 1014, +ItemId_Command_ListUsers = 1015, +ItemId_Command_CreateGame = 1016, +ItemId_Command_JoinGame = 1017, +ItemId_Command_LeaveGame = 1018, +ItemId_Command_Say = 1019, +ItemId_Command_Shuffle = 1020, +ItemId_Command_Mulligan = 1021, +ItemId_Command_RollDie = 1022, +ItemId_Command_DrawCards = 1023, +ItemId_Command_MoveCard = 1024, +ItemId_Command_FlipCard = 1025, +ItemId_Command_AttachCard = 1026, +ItemId_Command_CreateToken = 1027, +ItemId_Command_CreateArrow = 1028, +ItemId_Command_DeleteArrow = 1029, +ItemId_Command_SetCardAttr = 1030, +ItemId_Command_SetCardCounter = 1031, +ItemId_Command_IncCardCounter = 1032, +ItemId_Command_ReadyStart = 1033, +ItemId_Command_Concede = 1034, +ItemId_Command_IncCounter = 1035, +ItemId_Command_CreateCounter = 1036, +ItemId_Command_SetCounter = 1037, +ItemId_Command_DelCounter = 1038, +ItemId_Command_NextTurn = 1039, +ItemId_Command_SetActivePhase = 1040, +ItemId_Command_DumpZone = 1041, +ItemId_Command_StopDumpZone = 1042, +ItemId_Event_Say = 1043, +ItemId_Event_Leave = 1044, +ItemId_Event_GameClosed = 1045, +ItemId_Event_Shuffle = 1046, +ItemId_Event_RollDie = 1047, +ItemId_Event_MoveCard = 1048, +ItemId_Event_FlipCard = 1049, +ItemId_Event_DestroyCard = 1050, +ItemId_Event_AttachCard = 1051, +ItemId_Event_CreateToken = 1052, +ItemId_Event_DeleteArrow = 1053, +ItemId_Event_SetCardAttr = 1054, +ItemId_Event_SetCardCounter = 1055, +ItemId_Event_SetCounter = 1056, +ItemId_Event_DelCounter = 1057, +ItemId_Event_SetActivePlayer = 1058, +ItemId_Event_SetActivePhase = 1059, +ItemId_Event_DumpZone = 1060, +ItemId_Event_StopDumpZone = 1061, +ItemId_Event_ServerMessage = 1062, +ItemId_Event_Message = 1063, +ItemId_Event_GameJoined = 1064, +ItemId_Event_UserLeft = 1065, +ItemId_Event_ChatLeaveChannel = 1066, +ItemId_Event_ChatSay = 1067, +ItemId_Context_ReadyStart = 1068, +ItemId_Context_Concede = 1069, +ItemId_Context_DeckSelect = 1070, +ItemId_Other = 1071 }; diff --git a/common/protocol_items.cpp b/common/protocol_items.cpp index 369bd5181..74f51c026 100644 --- a/common/protocol_items.cpp +++ b/common/protocol_items.cpp @@ -17,6 +17,11 @@ Command_Message::Command_Message(const QString &_userName, const QString &_text) insertItem(new SerializableItem_String("user_name", _userName)); insertItem(new SerializableItem_String("text", _text)); } +Command_GetUserInfo::Command_GetUserInfo(const QString &_userName) + : Command("get_user_info") +{ + insertItem(new SerializableItem_String("user_name", _userName)); +} Command_DeckList::Command_DeckList() : Command("deck_list") { @@ -432,6 +437,7 @@ void ProtocolItem::initializeHashAuto() itemNameHash.insert("cmdping", Command_Ping::newItem); itemNameHash.insert("cmdlogin", Command_Login::newItem); itemNameHash.insert("cmdmessage", Command_Message::newItem); + itemNameHash.insert("cmdget_user_info", Command_GetUserInfo::newItem); itemNameHash.insert("cmddeck_list", Command_DeckList::newItem); itemNameHash.insert("cmddeck_new_dir", Command_DeckNewDir::newItem); itemNameHash.insert("cmddeck_del_dir", Command_DeckDelDir::newItem); diff --git a/common/protocol_items.dat b/common/protocol_items.dat index 5d7b3b118..ec077b415 100644 --- a/common/protocol_items.dat +++ b/common/protocol_items.dat @@ -1,6 +1,7 @@ 0:ping 0:login:s,username:s,password 0:message:s,user_name:s,text +0:get_user_info:s,user_name 0:deck_list 0:deck_new_dir:s,path:s,dir_name 0:deck_del_dir:s,path diff --git a/common/protocol_items.h b/common/protocol_items.h index 277211e5a..00c16260e 100644 --- a/common/protocol_items.h +++ b/common/protocol_items.h @@ -28,6 +28,14 @@ public: static SerializableItem *newItem() { return new Command_Message; } int getItemId() const { return ItemId_Command_Message; } }; +class Command_GetUserInfo : public Command { + Q_OBJECT +public: + Command_GetUserInfo(const QString &_userName = QString()); + QString getUserName() const { return static_cast(itemMap.value("user_name"))->getData(); }; + static SerializableItem *newItem() { return new Command_GetUserInfo; } + int getItemId() const { return ItemId_Command_GetUserInfo; } +}; class Command_DeckList : public Command { Q_OBJECT public: diff --git a/common/serializable_item.cpp b/common/serializable_item.cpp index 9a091e452..4fcdf0e1c 100644 --- a/common/serializable_item.cpp +++ b/common/serializable_item.cpp @@ -145,3 +145,16 @@ void SerializableItem_DateTime::writeElement(QXmlStreamWriter *xml) { xml->writeCharacters(QString::number(data.toTime_t())); } + +bool SerializableItem_ByteArray::readElement(QXmlStreamReader *xml) +{ + if (xml->isCharacters() && !xml->isWhitespace()) + data = qUncompress(QByteArray::fromBase64(xml->text().toString().toAscii())); + + return SerializableItem::readElement(xml); +} + +void SerializableItem_ByteArray::writeElement(QXmlStreamWriter *xml) +{ + xml->writeCharacters(QString(qCompress(data).toBase64())); +} diff --git a/common/serializable_item.h b/common/serializable_item.h index 4867d8a10..ef1e91ad2 100644 --- a/common/serializable_item.h +++ b/common/serializable_item.h @@ -121,7 +121,7 @@ public: const Color &getData() { return data; } void setData(const Color &_data) { data = _data; } }; - + class SerializableItem_DateTime : public SerializableItem { private: QDateTime data; @@ -135,4 +135,17 @@ public: void setData(const QDateTime &_data) { data = _data; } }; +class SerializableItem_ByteArray : public SerializableItem { +private: + QByteArray data; +protected: + bool readElement(QXmlStreamReader *xml); + void writeElement(QXmlStreamWriter *xml); +public: + SerializableItem_ByteArray(const QString &_itemType, const QByteArray &_data) + : SerializableItem(_itemType), data(_data) { } + const QByteArray &getData() { return data; } + void setData(const QByteArray &_data) { data = _data; } +}; + #endif diff --git a/common/server.cpp b/common/server.cpp index 499dfa4de..dc4125b24 100644 --- a/common/server.cpp +++ b/common/server.cpp @@ -56,8 +56,6 @@ AuthenticationResult Server::loginUser(Server_ProtocolHandler *session, QString } ServerInfo_User *data = getUserData(name); - if (authState == PasswordRight) - data->setUserLevel(data->getUserLevel() | ServerInfo_User::IsRegistered); session->setUserInfo(data); users.insert(name, session); diff --git a/common/server_protocolhandler.cpp b/common/server_protocolhandler.cpp index 87054352d..8a51dd3a0 100644 --- a/common/server_protocolhandler.cpp +++ b/common/server_protocolhandler.cpp @@ -123,6 +123,7 @@ ResponseCode Server_ProtocolHandler::processCommandHelper(Command *command, Comm case ItemId_Command_DeckDel: return cmdDeckDel(qobject_cast(command), cont); case ItemId_Command_DeckUpload: return cmdDeckUpload(qobject_cast(command), cont); case ItemId_Command_DeckDownload: return cmdDeckDownload(qobject_cast(command), cont); + case ItemId_Command_GetUserInfo: return cmdGetUserInfo(qobject_cast(command), cont); case ItemId_Command_ListChatChannels: return cmdListChatChannels(qobject_cast(command), cont); case ItemId_Command_ChatJoinChannel: return cmdChatJoinChannel(qobject_cast(command), cont); case ItemId_Command_ListUsers: return cmdListUsers(qobject_cast(command), cont); @@ -246,6 +247,25 @@ ResponseCode Server_ProtocolHandler::cmdMessage(Command_Message *cmd, CommandCon return RespOk; } +ResponseCode Server_ProtocolHandler::cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont) +{ + if (authState == PasswordWrong) + return RespLoginNeeded; + + ServerInfo_User *result; + if (cmd->getUserName().isEmpty()) + result = new ServerInfo_User(userInfo); + else { + Server_ProtocolHandler *handler = server->getUsers().value(cmd->getUserName()); + if (!handler) + return RespNameNotFound; + result = handler->getUserInfo(); + } + + cont->setResponse(new Response_GetUserInfo(cont->getCmdId(), RespOk, result)); + return RespNothing; +} + ResponseCode Server_ProtocolHandler::cmdListChatChannels(Command_ListChatChannels * /*cmd*/, CommandContainer *cont) { if (authState == PasswordWrong) diff --git a/common/server_protocolhandler.h b/common/server_protocolhandler.h index 5a54ccde3..0f6ccc8ce 100644 --- a/common/server_protocolhandler.h +++ b/common/server_protocolhandler.h @@ -44,6 +44,7 @@ private: virtual ResponseCode cmdDeckDel(Command_DeckDel *cmd, CommandContainer *cont) = 0; virtual ResponseCode cmdDeckUpload(Command_DeckUpload *cmd, CommandContainer *cont) = 0; virtual ResponseCode cmdDeckDownload(Command_DeckDownload *cmd, CommandContainer *cont) = 0; + ResponseCode cmdGetUserInfo(Command_GetUserInfo *cmd, CommandContainer *cont); ResponseCode cmdListChatChannels(Command_ListChatChannels *cmd, CommandContainer *cont); ResponseCode cmdChatJoinChannel(Command_ChatJoinChannel *cmd, CommandContainer *cont); ResponseCode cmdChatLeaveChannel(Command_ChatLeaveChannel *cmd, CommandContainer *cont, Server_ChatChannel *channel); diff --git a/servatrice/src/servatrice.cpp b/servatrice/src/servatrice.cpp index f7d493367..e138f70b3 100644 --- a/servatrice/src/servatrice.cpp +++ b/servatrice/src/servatrice.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "servatrice.h" #include "server_chatchannel.h" #include "serversocketinterface.h" @@ -79,8 +80,12 @@ bool Servatrice::openDatabase() sqldb.setPassword(settings->value("password").toString()); settings->endGroup(); - if (!sqldb.open()) + std::cerr << "Opening database..."; + if (!sqldb.open()) { + std::cerr << "error" << std::endl; return false; + } + std::cerr << "OK" << std::endl; if (!nextGameId) { QSqlQuery query; @@ -124,7 +129,7 @@ AuthenticationResult Servatrice::checkUserPassword(const QString &user, const QS checkSql(); QSqlQuery query; - query.prepare("select password from users where name = :name"); + query.prepare("select password from users where name = :name and active = 1"); query.bindValue(":name", user); if (!execSqlQuery(query)) return PasswordWrong; @@ -147,7 +152,7 @@ ServerInfo_User *Servatrice::getUserData(const QString &name) checkSql(); QSqlQuery query; - query.prepare("select admin, country from users where name = :name"); + query.prepare("select admin, country, avatar_bmp from users where name = :name and active = 1"); query.bindValue(":name", name); if (!execSqlQuery(query)) return new ServerInfo_User(name); @@ -155,15 +160,17 @@ ServerInfo_User *Servatrice::getUserData(const QString &name) if (query.next()) { bool is_admin = query.value(0).toInt(); QString country = query.value(1).toString(); + QByteArray avatarBmp = query.value(2).toByteArray(); - int userLevel = ServerInfo_User::IsUser; + int userLevel = ServerInfo_User::IsUser | ServerInfo_User::IsRegistered; if (is_admin) userLevel |= ServerInfo_User::IsAdmin; return new ServerInfo_User( name, userLevel, - country + country, + avatarBmp ); } else return new ServerInfo_User(name); @@ -171,4 +178,4 @@ ServerInfo_User *Servatrice::getUserData(const QString &name) return new ServerInfo_User(name); } -const QString Servatrice::versionString = "Servatrice 0.20100918"; +const QString Servatrice::versionString = "Servatrice 0.20101009";