Merge pull request #2670 from ctrlaltca/load_tokens

Improved token loading, removed card price code
This commit is contained in:
Zach H 2017-05-05 00:24:48 -04:00 committed by GitHub
commit fd3d62284d
20 changed files with 84 additions and 493 deletions

View file

@ -97,8 +97,7 @@ SET(cockatrice_SOURCES
src/thememanager.cpp
src/localserver.cpp
src/localserverinterface.cpp
src/localclient.cpp
src/priceupdater.cpp
src/localclient.cpp
src/qt-json/json.cpp
src/soundengine.cpp
src/pending_command.cpp

View file

@ -190,9 +190,19 @@ void DeckLoader::saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklis
{
DecklistCardNode* card = cards[i];
if (zoneNode->getName() == "side")
if (zoneNode->getName() == DECK_ZONE_SIDE)
out << "SB: ";
out << card->getNumber() << " " << card->getName() << "\n";
}
}
QString DeckLoader::getCardZoneFromName(QString cardName, QString currentZoneName)
{
CardInfo *card = db->getCard(cardName);
if(card && card->getIsToken())
return DECK_ZONE_TOKENS;
return currentZoneName;
}

View file

@ -36,6 +36,7 @@ protected:
void saveToStream_DeckHeader(QTextStream &out);
void saveToStream_DeckZone(QTextStream &out, const InnerDecklistNode *zoneNode);
void saveToStream_DeckZoneCards(QTextStream &out, const InnerDecklistNode *zoneNode, QList <DecklistCardNode*> cards);
virtual QString getCardZoneFromName(QString cardName, QString currentZoneName);
};
#endif

View file

@ -68,9 +68,6 @@ int DeckListModel::rowCount(const QModelIndex &parent) const
int DeckListModel::columnCount(const QModelIndex &/*parent*/) const
{
if (settingsCache->getPriceTagFeature())
return 3;
else
return 2;
}
@ -97,7 +94,6 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
switch (index.column()) {
case 0: return node->recursiveCount(true);
case 1: return node->getVisibleName();
case 2: return QString().sprintf("$%.2f", node->recursivePrice(true));
default: return QVariant();
}
case Qt::BackgroundRole: {
@ -116,7 +112,6 @@ QVariant DeckListModel::data(const QModelIndex &index, int role) const
switch (index.column()) {
case 0: return card->getNumber();
case 1: return card->getName();
case 2: return QString().sprintf("$%.2f", card->getTotalPrice());
default: return QVariant();
}
}
@ -141,7 +136,6 @@ QVariant DeckListModel::headerData(int section, Qt::Orientation orientation, int
switch (section) {
case 0: return tr("Number");
case 1: return tr("Card");
case 2: return tr("Price");
default: return QVariant();
}
}
@ -195,7 +189,6 @@ bool DeckListModel::setData(const QModelIndex &index, const QVariant &value, int
switch (index.column()) {
case 0: node->setNumber(value.toInt()); break;
case 1: node->setName(value.toString()); break;
case 2: node->setPrice(value.toFloat()); break;
default: return false;
}
emitRecursiveUpdates(index);
@ -347,9 +340,6 @@ void DeckListModel::sort(int column, Qt::SortOrder order)
case 1:
sortMethod = ByName;
break;
case 2:
sortMethod = ByPrice;
break;
default:
sortMethod = ByName;
}
@ -374,7 +364,7 @@ void DeckListModel::setDeckList(DeckLoader *_deck)
void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *node)
{
const int totalColumns = settingsCache->getPriceTagFeature() ? 3 : 2;
const int totalColumns = 2;
if (node->height() == 1) {
QTextBlockFormat blockFormat;
@ -382,10 +372,6 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
charFormat.setFontPointSize(11);
charFormat.setFontWeight(QFont::Bold);
cursor->insertBlock(blockFormat, charFormat);
QString priceStr;
if (settingsCache->getPriceTagFeature())
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
QTextTableFormat tableFormat;
tableFormat.setCellPadding(0);
@ -408,12 +394,6 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(card->getName());
if (settingsCache->getPriceTagFeature()) {
cell = table->cellAt(i, 2);
cell.setFormat(cellCharFormat);
cellCursor = cell.firstCursorPosition();
cellCursor.insertText(QString().sprintf("$%.2f ", card->getTotalPrice()));
}
}
} else if (node->height() == 2) {
QTextBlockFormat blockFormat;
@ -422,10 +402,6 @@ void DeckListModel::printDeckListNode(QTextCursor *cursor, InnerDecklistNode *no
charFormat.setFontWeight(QFont::Bold);
cursor->insertBlock(blockFormat, charFormat);
QString priceStr;
if (settingsCache->getPriceTagFeature())
priceStr = QString().sprintf(": $%.2f", node->recursivePrice(true));
cursor->insertText(QString("%1: %2").arg(node->getVisibleName()).arg(node->recursiveCount(true)).append(priceStr));
QTextTableFormat tableFormat;
tableFormat.setCellPadding(10);
@ -477,9 +453,4 @@ void DeckListModel::printDeckList(QPrinter *printer)
}
doc.print(printer);
}
void DeckListModel::pricesUpdated()
{
emit layoutChanged();
}
}

View file

@ -18,8 +18,6 @@ public:
DecklistModelCardNode(DecklistCardNode *_dataNode, InnerDecklistNode *_parent) : AbstractDecklistCardNode(_parent), dataNode(_dataNode) { }
int getNumber() const { return dataNode->getNumber(); }
void setNumber(int _number) { dataNode->setNumber(_number); }
float getPrice() const { return dataNode->getPrice(); }
void setPrice(const float _price) { dataNode->setPrice(_price); }
QString getName() const { return dataNode->getName(); }
void setName(const QString &_name) { dataNode->setName(_name); }
DecklistCardNode *getDataNode() const { return dataNode; }
@ -51,7 +49,6 @@ public:
void cleanList();
DeckLoader *getDeckList() const { return deckList; }
void setDeckList(DeckLoader *_deck);
void pricesUpdated();
private:
DeckLoader *deckList;
InnerDecklistNode *root;

View file

@ -82,7 +82,7 @@ void DeckViewCard::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
QPen pen;
pen.setWidth(3);
pen.setJoinStyle(Qt::MiterJoin);
pen.setColor(originZone == "main" ? Qt::green : Qt::red);
pen.setColor(originZone == DECK_ZONE_MAIN ? Qt::green : Qt::red);
painter->setPen(pen);
painter->drawRect(QRectF(1, 1, CARD_WIDTH - 2, CARD_HEIGHT - 2.5));
painter->restore();
@ -134,10 +134,10 @@ void DeckView::mouseDoubleClickEvent(QMouseEvent *event)
m.set_card_name(c->getName().toStdString());
m.set_start_zone(zone->getName().toStdString());
if (zone->getName() == "main")
m.set_target_zone("side");
else if (zone->getName() == "side")
m.set_target_zone("main");
if (zone->getName() == DECK_ZONE_MAIN)
m.set_target_zone(DECK_ZONE_SIDE);
else if (zone->getName() == DECK_ZONE_SIDE)
m.set_target_zone(DECK_ZONE_MAIN);
else // Trying to move from another zone
m.set_target_zone(zone->getName().toStdString());

View file

@ -27,7 +27,6 @@
#include "main.h"
#include "settingscache.h"
#include "thememanager.h"
#include "priceupdater.h"
#include "releasechannel.h"
#include "soundengine.h"
#include "sequenceEdit/shortcutstab.h"
@ -468,13 +467,7 @@ void UserInterfaceSettingsPage::retranslateUi()
DeckEditorSettingsPage::DeckEditorSettingsPage()
{
//priceTagsCheckBox.setChecked(settingsCache->getPriceTagFeature());
//connect(&priceTagsCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setPriceTagFeature(int)));
//connect(this, SIGNAL(priceTagSourceChanged(int)), settingsCache, SLOT(setPriceTagSource(int)));
QGridLayout *generalGrid = new QGridLayout;
//generalGrid->addWidget(&priceTagsCheckBox, 0, 0);
generalGrid->addWidget(new QLabel(tr("Nothing is here... yet")), 0, 0);
@ -489,21 +482,9 @@ DeckEditorSettingsPage::DeckEditorSettingsPage()
void DeckEditorSettingsPage::retranslateUi()
{
//priceTagsCheckBox.setText(tr("Enable &price tag feature from deckbrew.com"));
generalGroupBox->setTitle(tr("General"));
}
/*
void DeckEditorSettingsPage::radioPriceTagSourceClicked(bool checked)
{
if(!checked)
return;
int source=AbstractPriceUpdater::DBPriceSource;
emit priceTagSourceChanged(source);
}
*/
MessagesSettingsPage::MessagesSettingsPage()
{
chatMentionCheckBox.setChecked(settingsCache->getChatMention());

View file

@ -130,11 +130,8 @@ public:
DeckEditorSettingsPage();
void retranslateUi();
private slots:
//void radioPriceTagSourceClicked(bool checked);
signals:
//void priceTagSourceChanged(int _priceTagSource);
private:
//QCheckBox priceTagsCheckBox;
QGroupBox *generalGroupBox;
};

View file

@ -857,7 +857,7 @@ void Player::setDeck(const DeckLoader &_deck)
createPredefinedTokenMenu->clear();
predefinedTokens.clear();
InnerDecklistNode *tokenZone = dynamic_cast<InnerDecklistNode *>(deck->getRoot()->findChild("tokens"));
InnerDecklistNode *tokenZone = dynamic_cast<InnerDecklistNode *>(deck->getRoot()->findChild(DECK_ZONE_TOKENS));
if (tokenZone)
for (int i = 0; i < tokenZone->size(); ++i) {

View file

@ -1,216 +0,0 @@
/**
* @author Marcio Ribeiro <mmr@b1n.org>, Max-Wilhelm Bruker <brukie@gmx.net>
* @version 1.1
*/
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QMessageBox>
#include "qt-json/json.h"
#include "priceupdater.h"
#include "main.h"
#include "carddatabase.h"
/**
* Constructor.
*
* @param _deck deck.
*/
AbstractPriceUpdater::AbstractPriceUpdater(const DeckList *_deck)
{
nam = new QNetworkAccessManager(this);
deck = _deck;
}
// deckbrew.com
/**
* Constructor.
*
* @param _deck deck.
*/
/*
DBPriceUpdater::DBPriceUpdater(const DeckList *_deck)
: AbstractPriceUpdater(_deck)
{
}
*/
/**
* Update the prices of the cards in deckList.
*/
/*
void DBPriceUpdater::updatePrices()
{
QString base = "https://api.deckbrew.com/mtg/cards", q = "";
QStringList cards = deck->getCardList();
muidMap.clear();
urls.clear();
CardInfo * card;
int muid;
SetList sets;
bool bNotFirst=false;
for (int i = 0; i < cards.size(); ++i) {
card = db->getCard(cards[i]);
if(!card)
continue;
sets = card->getSets();
for(int j = 0; j < sets.size(); ++j)
{
muid=card->getMuId(sets[j]->getShortName());
if (!muid) {
continue;
}
//qDebug() << "muid " << muid << " card: " << cards[i] << endl;
if(bNotFirst)
{
q += QString("&m=%1").arg(muid);
} else {
q += QString("?m=%1").arg(muid);
bNotFirst = true;
}
muidMap.insert(muid, cards[i]);
if(q.length() > 240)
{
urls.append(base + q);
bNotFirst=false;
q = "";
}
}
}
if(q.length() > 0)
urls.append(base + q);
requestNext();
}
*/
/*
void DBPriceUpdater::requestNext()
{
if(urls.empty())
return;
QUrl url(urls.takeFirst(), QUrl::TolerantMode);
//qDebug() << "request prices from: " << url.toString() << endl;
QNetworkReply *reply = nam->get(QNetworkRequest(url));
connect(reply, SIGNAL(finished()), this, SLOT(downloadFinished()));
}
*/
/**
* Called when the download of the json file with the prices is finished.
*/
/*
void DBPriceUpdater::downloadFinished()
{
QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
bool ok;
QString tmp = QString(reply->readAll());
// Errors are incapsulated in an object, check for them first
QVariantMap resultMap = QtJson::Json::parse(tmp, ok).toMap();
if (!ok) {
QMessageBox::critical(this, tr("Error"), tr("A problem has occured while fetching card prices."));
reply->deleteLater();
if(urls.isEmpty())
{
deleteLater();
emit finishedUpdate();
} else {
requestNext();
}
}
if(resultMap.contains("errors"))
{
QMessageBox::critical(this, tr("Error"), tr("A problem has occured while fetching card prices:") +
"<br/>" + resultMap["errors"].toList().first().toString().toHtmlEscaped()
);
reply->deleteLater();
if(urls.isEmpty())
{
deleteLater();
emit finishedUpdate();
} else {
requestNext();
}
}
// Good results are a list
QVariantList resultList = QtJson::Json::parse(tmp, ok).toList();
if (!ok) {
QMessageBox::critical(this, tr("Error"), tr("A problem has occured while fetching card prices."));
reply->deleteLater();
if(urls.isEmpty())
{
deleteLater();
emit finishedUpdate();
} else {
requestNext();
}
}
QMap<QString, float> cardsPrice;
QListIterator<QVariant> it(resultList);
while (it.hasNext()) {
QVariantMap cardMap = it.next().toMap();
// get sets list
QList<QVariant> editions = cardMap.value("editions").toList();
foreach (QVariant ed, editions)
{
// retrieve card name "as we know it" from the muid
QVariantMap edition = ed.toMap();
QString set = edition.value("set_id").toString();
int muid = edition.value("multiverse_id").toString().toInt();
if(!muidMap.contains(muid))
continue;
QString name=muidMap.value(muid);
// Prices are in USD cents
float price = edition.value("price").toMap().value("median").toString().toFloat() / 100;
//qDebug() << "card " << name << " set " << set << " price " << price << endl;
* Make sure Masters Edition (MED) isn't the set, as it doesn't
* physically exist. Also check the price to see that the cheapest set
* ends up as the final price.
if (set != "MED" && price > 0 && (!cardsPrice.contains(name) || cardsPrice.value(name) > price))
cardsPrice.insert(name, price);
}
}
InnerDecklistNode *listRoot = deck->getRoot();
for (int i = 0; i < listRoot->size(); i++) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
for (int j = 0; j < currentZone->size(); j++) {
DecklistCardNode *currentCard = dynamic_cast<DecklistCardNode *>(currentZone->at(j));
if (!currentCard)
continue;
float price = cardsPrice[currentCard->getName()];
if(price > 0)
currentCard->setPrice(price);
}
}
reply->deleteLater();
if(urls.isEmpty())
{
deleteLater();
emit finishedUpdate();
} else {
requestNext();
}
}
*/

View file

@ -1,49 +0,0 @@
#ifndef PRICEUPDATER_H
#define PRICEUPDATER_H
#include <QNetworkAccessManager>
#include "decklist.h"
class QNetworkAccessManager;
// If we don't typedef this, won't compile on OS X < 10.9
typedef QMap<int, QString> MuidStringMap;
/**
* Price Updater.
*
* @author Marcio Ribeiro <mmr@b1n.org>
*/
class AbstractPriceUpdater : public QWidget
{
Q_OBJECT
public:
enum PriceSource { DBPriceSource };
protected:
const DeckList *deck;
QNetworkAccessManager *nam;
signals:
void finishedUpdate();
protected slots:
virtual void downloadFinished() = 0;
public:
AbstractPriceUpdater(const DeckList *deck);
virtual void updatePrices() = 0;
};
/*
class DBPriceUpdater : public AbstractPriceUpdater
{
Q_OBJECT
protected:
MuidStringMap muidMap;
QList<QString> urls;
protected:
virtual void downloadFinished();
void requestNext();
public:
DBPriceUpdater(const DeckList *deck);
virtual void updatePrices();
};
*/
#endif

View file

@ -236,9 +236,6 @@ SettingsCache::SettingsCache()
maxFontSize = settings->value("game/maxfontsize", DEFAULT_FONT_SIZE).toInt();
priceTagFeature = settings->value("deckeditor/pricetags", false).toBool();
priceTagSource = settings->value("deckeditor/pricetagsource", 0).toInt();
ignoreUnregisteredUsers = settings->value("chat/ignore_unregistered", false).toBool();
ignoreUnregisteredUserMessages = settings->value("chat/ignore_unregistered_messages", false).toBool();
@ -514,19 +511,6 @@ void SettingsCache::setSoundThemeName(const QString &_soundThemeName)
emit soundThemeChanged();
}
void SettingsCache::setPriceTagFeature(int _priceTagFeature)
{
priceTagFeature = _priceTagFeature;
settings->setValue("deckeditor/pricetags", priceTagFeature);
emit priceTagFeatureChanged(priceTagFeature);
}
void SettingsCache::setPriceTagSource(int _priceTagSource)
{
priceTagSource = _priceTagSource;
settings->setValue("deckeditor/pricetagsource", priceTagSource);
}
void SettingsCache::setIgnoreUnregisteredUsers(int _ignoreUnregisteredUsers)
{
ignoreUnregisteredUsers = _ignoreUnregisteredUsers;

View file

@ -43,7 +43,6 @@ signals:
void minPlayersForMultiColumnLayoutChanged();
void soundEnabledChanged();
void soundThemeChanged();
void priceTagFeatureChanged(int enabled);
void ignoreUnregisteredUsersChanged();
void ignoreUnregisteredUserMessagesChanged();
void pixmapCacheSizeChanged(int newSizeInMBs);
@ -86,8 +85,6 @@ private:
bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView;
bool soundEnabled;
QString soundThemeName;
bool priceTagFeature;
int priceTagSource;
bool ignoreUnregisteredUsers;
bool ignoreUnregisteredUserMessages;
QString picUrl;
@ -165,8 +162,6 @@ public:
bool getZoneViewPileView() const { return zoneViewPileView; }
bool getSoundEnabled() const { return soundEnabled; }
QString getSoundThemeName() const { return soundThemeName; }
bool getPriceTagFeature() const { return false; /* #859; priceTagFeature;*/ }
int getPriceTagSource() const { return priceTagSource; }
bool getIgnoreUnregisteredUsers() const { return ignoreUnregisteredUsers; }
bool getIgnoreUnregisteredUserMessages() const { return ignoreUnregisteredUserMessages; }
QString getPicUrl() const { return picUrl; }
@ -236,8 +231,6 @@ public slots:
void setZoneViewPileView(int _zoneViewPileView);
void setSoundEnabled(int _soundEnabled);
void setSoundThemeName(const QString &_soundThemeName);
void setPriceTagFeature(int _priceTagFeature);
void setPriceTagSource(int _priceTagSource);
void setIgnoreUnregisteredUsers(int _ignoreUnregisteredUsers);
void setIgnoreUnregisteredUserMessages(int _ignoreUnregisteredUserMessages);
void setPicUrl(const QString &_picUrl);

View file

@ -31,7 +31,6 @@
#include "dlg_load_deck_from_clipboard.h"
#include "main.h"
#include "settingscache.h"
#include "priceupdater.h"
#include "tab_supervisor.h"
#include "deckstats_interface.h"
#include "tappedout_interface.h"
@ -536,9 +535,6 @@ void TabDeckEditor::retranslateUi()
nameLabel->setText(tr("Deck &name:"));
commentsLabel->setText(tr("&Comments:"));
hashLabel1->setText(tr("Hash:"));
//aUpdatePrices->setText(tr("&Update prices"));
//aUpdatePrices->setShortcut(QKeySequence("Ctrl+U"));
aNewDeck->setText(tr("&New deck"));
aLoadDeck->setText(tr("&Load deck..."));
@ -821,7 +817,7 @@ void TabDeckEditor::addCardHelper(QString zoneName)
if(!info)
return;
if (info->getIsToken())
zoneName = "tokens";
zoneName = DECK_ZONE_TOKENS;
QModelIndex newCardIndex = deckModel->addCard(info->getName(), zoneName);
recursiveExpand(newCardIndex);
@ -843,7 +839,7 @@ void TabDeckEditor::actSwapCard()
const QString zoneName = gparent.sibling(gparent.row(), 1).data().toString();
actDecrement();
const QString otherZoneName = zoneName == "Maindeck" ? "side" : "main";
const QString otherZoneName = zoneName == "Maindeck" ? DECK_ZONE_SIDE : DECK_ZONE_MAIN;
QModelIndex newCardIndex = deckModel->addCard(cardName, otherZoneName);
recursiveExpand(newCardIndex);
@ -856,12 +852,12 @@ void TabDeckEditor::actAddCard()
if(QApplication::keyboardModifiers() & Qt::ControlModifier)
actAddCardToSideboard();
else
addCardHelper("main");
addCardHelper(DECK_ZONE_MAIN);
}
void TabDeckEditor::actAddCardToSideboard()
{
addCardHelper("side");
addCardHelper(DECK_ZONE_SIDE);
}
void TabDeckEditor::actRemoveCard()
@ -898,7 +894,7 @@ void TabDeckEditor::decrementCardHelper(QString zoneName)
if(!info)
return;
if (info->getIsToken())
zoneName = "tokens";
zoneName = DECK_ZONE_TOKENS;
idx = deckModel->findCard(info->getName(), zoneName);
offsetCountAtIndex(idx, -1);
@ -906,12 +902,12 @@ void TabDeckEditor::decrementCardHelper(QString zoneName)
void TabDeckEditor::actDecrementCard()
{
decrementCardHelper("main");
decrementCardHelper(DECK_ZONE_MAIN);
}
void TabDeckEditor::actDecrementCardFromSideboard()
{
decrementCardHelper("side");
decrementCardHelper(DECK_ZONE_SIDE);
}
void TabDeckEditor::actIncrement()
@ -926,38 +922,6 @@ void TabDeckEditor::actDecrement()
offsetCountAtIndex(currentIndex, -1);
}
void TabDeckEditor::setPriceTagFeatureEnabled(int /* enabled */)
{
//aUpdatePrices->setVisible(enabled);
deckModel->pricesUpdated();
}
/*
void TabDeckEditor::actUpdatePrices()
{
aUpdatePrices->setDisabled(true);
AbstractPriceUpdater *up;
switch(settingsCache->getPriceTagSource())
{
case AbstractPriceUpdater::DBPriceSource:
default:
up = new DBPriceUpdater(deckModel->getDeckList());
break;
}
connect(up, SIGNAL(finishedUpdate()), this, SLOT(finishedUpdatingPrices()));
up->updatePrices();
}
*/
void TabDeckEditor::finishedUpdatingPrices()
{
//deckModel->pricesUpdated();
//setModified(true);
//aUpdatePrices->setDisabled(false);
}
void TabDeckEditor::setDeck(DeckLoader *_deck)
{

View file

@ -67,13 +67,9 @@ class TabDeckEditor : public Tab {
void actDecrementCard();
void actDecrementCardFromSideboard();
//void actUpdatePrices();
void finishedUpdatingPrices();
void saveDeckRemoteFinished(const Response &r);
void filterViewCustomContextMenu(const QPoint &point);
void filterRemove(QAction *action);
void setPriceTagFeatureEnabled(int enabled);
void loadLayout();
void restartLayout();
@ -116,7 +112,7 @@ private:
QMenu *deckMenu, *viewMenu, *cardInfoDockMenu, *deckDockMenu, *filterDockMenu, *analyzeDeckMenu;
QAction *aNewDeck, *aLoadDeck, *aSaveDeck, *aSaveDeckAs, *aLoadDeckFromClipboard, *aSaveDeckToClipboard, *aPrintDeck, *aAnalyzeDeckDeckstats, *aAnalyzeDeckTappedout, *aClose;
QAction *aClearFilterAll, *aClearFilterOne;
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;// *aUpdatePrices;
QAction *aAddCard, *aAddCardToSideboard, *aRemoveCard, *aIncrement, *aDecrement;
QAction *aResetLayout;
QAction *aCardInfoDockVisible, *aCardInfoDockFloating, *aDeckDockVisible, *aDeckDockFloating, *aFilterDockVisible, *aFilterDockFloating;

View file

@ -109,7 +109,7 @@ struct CopyMainOrSide {
return;
DecklistCardNode *addedCard;
if(node->getName() == "side")
if(node->getName() == DECK_ZONE_SIDE)
addedCard = sideboard.addCard(card->getName(), node->getName());
else
addedCard = mainboard.addCard(card->getName(), node->getName());

View file

@ -95,11 +95,11 @@ InnerDecklistNode::~InnerDecklistNode()
QString InnerDecklistNode::visibleNameFromName(const QString &_name)
{
if (_name == "main")
if (_name == DECK_ZONE_MAIN)
return QObject::tr("Maindeck");
else if (_name == "side")
else if (_name == DECK_ZONE_SIDE)
return QObject::tr("Sideboard");
else if (_name == "tokens")
else if (_name == DECK_ZONE_TOKENS)
return QObject::tr("Tokens");
else
return _name;
@ -125,7 +125,7 @@ void InnerDecklistNode::clearTree()
}
DecklistCardNode::DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent)
: AbstractDecklistCardNode(_parent), name(other->getName()), number(other->getNumber()), price(other->getPrice())
: AbstractDecklistCardNode(_parent), name(other->getName()), number(other->getNumber())
{
}
@ -157,19 +157,6 @@ int InnerDecklistNode::recursiveCount(bool countTotalCards) const
return result;
}
float InnerDecklistNode::recursivePrice(bool countTotalCards) const
{
float result = 0;
for (int i = 0; i < size(); i++) {
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(at(i));
if (node)
result += node->recursivePrice(countTotalCards);
else if (countTotalCards)
result += dynamic_cast<AbstractDecklistCardNode *>(at(i))->getTotalPrice();
}
return result;
}
bool InnerDecklistNode::compare(AbstractDecklistNode *other) const
{
switch (sortMethod) {
@ -177,8 +164,6 @@ bool InnerDecklistNode::compare(AbstractDecklistNode *other) const
return compareNumber(other);
case ByName:
return compareName(other);
case ByPrice:
return comparePrice(other);
}
return 0;
}
@ -205,18 +190,6 @@ bool InnerDecklistNode::compareName(AbstractDecklistNode *other) const
}
}
bool InnerDecklistNode::comparePrice(AbstractDecklistNode *other) const
{
InnerDecklistNode *other2 = dynamic_cast<InnerDecklistNode *>(other);
if (other2) {
int p1 = 100*recursivePrice(true);
int p2 = 100*other2->recursivePrice(true);
return (p1 != p2) ? (p1 > p2) : compareName(other);
} else {
return false;
}
}
bool AbstractDecklistCardNode::compare(AbstractDecklistNode *other) const
{
switch (sortMethod) {
@ -224,8 +197,6 @@ bool AbstractDecklistCardNode::compare(AbstractDecklistNode *other) const
return compareNumber(other);
case ByName:
return compareName(other);
case ByPrice:
return compareTotalPrice(other);
}
return 0;
}
@ -252,18 +223,6 @@ bool AbstractDecklistCardNode::compareName(AbstractDecklistNode *other) const
}
}
bool AbstractDecklistCardNode::compareTotalPrice(AbstractDecklistNode *other) const
{
AbstractDecklistCardNode *other2 = dynamic_cast<AbstractDecklistCardNode *>(other);
if (other2) {
int p1 = 100*getTotalPrice();
int p2 = 100*other2->getTotalPrice();
return (p1 != p2) ? (p1 > p2) : compareName(other);
} else {
return true;
}
}
class InnerDecklistNode::compareFunctor {
private:
Qt::SortOrder order;
@ -285,8 +244,7 @@ bool InnerDecklistNode::readElement(QXmlStreamReader *xml)
InnerDecklistNode *newZone = new InnerDecklistNode(xml->attributes().value("name").toString(), this);
newZone->readElement(xml);
} else if (childName == "card") {
float price = (xml->attributes().value("price") != NULL) ? xml->attributes().value("price").toString().toFloat() : 0;
DecklistCardNode *newCard = new DecklistCardNode(xml->attributes().value("name").toString(), xml->attributes().value("number").toString().toInt(), price, this);
DecklistCardNode *newCard = new DecklistCardNode(xml->attributes().value("name").toString(), xml->attributes().value("number").toString().toInt(), this);
newCard->readElement(xml);
}
} else if (xml->isEndElement() && (childName == "zone"))
@ -318,7 +276,6 @@ void AbstractDecklistCardNode::writeElement(QXmlStreamWriter *xml)
{
xml->writeEmptyElement("card");
xml->writeAttribute("number", QString::number(getNumber()));
xml->writeAttribute("price", QString::number(getPrice()));
xml->writeAttribute("name", getName());
}
@ -414,7 +371,7 @@ bool DeckList::readElement(QXmlStreamReader *xml)
else if (childName == "comments")
comments = xml->readElementText();
else if (childName == "zone") {
InnerDecklistNode *newZone = new InnerDecklistNode(xml->attributes().value("name").toString(), root);
InnerDecklistNode *newZone = getZoneObjFromName(xml->attributes().value("name").toString());
newZone->readElement(xml);
} else if (childName == "sideboard_plan") {
SideboardPlan *newSideboardPlan = new SideboardPlan;
@ -510,13 +467,14 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
{
cleanList();
InnerDecklistNode *main = 0, *side = 0;
bool inSideboard = false;
bool inSideboard = false, isSideboard = false;
int okRows = 0;
bool titleFound = false;
while (!in.atEnd()) {
QString line = in.readLine().simplified();
// skip comments
if (line.startsWith("//"))
{
if(!titleFound)
@ -529,23 +487,17 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
continue;
}
InnerDecklistNode *zone;
// check for sideboard prefix
if (line.startsWith("Sideboard", Qt::CaseInsensitive)) {
inSideboard = true;
continue;
} else if (line.startsWith("SB:", Qt::CaseInsensitive)) {
}
isSideboard = inSideboard;
if (line.startsWith("SB:", Qt::CaseInsensitive)) {
line = line.mid(3).trimmed();
if (!side)
side = new InnerDecklistNode("side", root);
zone = side;
} else if (inSideboard) {
if (!side)
side = new InnerDecklistNode("side", root);
zone = side;
} else {
if (!main)
main = new InnerDecklistNode("main", root);
zone = main;
isSideboard = true;
}
// Filter out MWS edition symbols and basic land extras
@ -593,13 +545,27 @@ bool DeckList::loadFromStream_Plain(QTextStream &in)
cardName.replace(rx, QString("%1 // ").arg(rx.cap(1)));
}
// Look for the correct card zone
QString zoneName = getCardZoneFromName(cardName, isSideboard ? DECK_ZONE_SIDE: DECK_ZONE_MAIN);
++okRows;
new DecklistCardNode(cardName, number, 0, zone);
new DecklistCardNode(cardName, number, getZoneObjFromName(zoneName));
}
updateDeckHash();
return (okRows > 0);
}
InnerDecklistNode * DeckList::getZoneObjFromName(const QString zoneName)
{
for (int i = 0; i < root->size(); i++) {
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
if(node->getName() == zoneName)
return node;
}
return new InnerDecklistNode(zoneName, root);
}
bool DeckList::loadFromFile_Plain(QIODevice *device)
{
QTextStream in(device);
@ -616,7 +582,7 @@ struct WriteToStream {
const InnerDecklistNode *node,
const DecklistCardNode *card
) {
if (prefixSideboardCards && node->getName() == "side") {
if (prefixSideboardCards && node->getName() == DECK_ZONE_SIDE) {
stream << "SB: ";
}
stream << QString("%1 %2\n").arg(
@ -680,7 +646,7 @@ int DeckList::getSideboardSize() const
int size = 0;
for (int i = 0; i < root->size(); ++i) {
InnerDecklistNode *node = dynamic_cast<InnerDecklistNode *>(root->at(i));
if (node->getName() != "side")
if (node->getName() != DECK_ZONE_SIDE)
continue;
for (int j = 0; j < node->size(); j++) {
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
@ -696,7 +662,7 @@ DecklistCardNode *DeckList::addCard(const QString &cardName, const QString &zone
if (!zoneNode)
zoneNode = new InnerDecklistNode(zoneName, root);
DecklistCardNode *node = new DecklistCardNode(cardName, 1, 0, zoneNode);
DecklistCardNode *node = new DecklistCardNode(cardName, 1, zoneNode);
updateDeckHash();
return node;
}
@ -738,8 +704,8 @@ void DeckList::updateDeckHash()
bool isValidDeckList = true;
QSet<QString> hashZones, optionalZones;
hashZones << "main" << "side"; // Zones in deck to be included in hashing process
optionalZones << "tokens"; // Optional zones in deck not included in hashing process
hashZones << DECK_ZONE_MAIN << DECK_ZONE_SIDE; // Zones in deck to be included in hashing process
optionalZones << DECK_ZONE_TOKENS; // Optional zones in deck not included in hashing process
for (int i = 0; i < root->size(); i++)
{
@ -750,7 +716,7 @@ void DeckList::updateDeckHash()
{
DecklistCardNode *card = dynamic_cast<DecklistCardNode *>(node->at(j));
for (int k = 0; k < card->getNumber(); ++k)
cardList.append((node->getName() == "side" ? "SB:" : "") + card->getName().toLower());
cardList.append((node->getName() == DECK_ZONE_SIDE ? "SB:" : "") + card->getName().toLower());
}
else if (!optionalZones.contains(node->getName())) // Not a valid zone -> cheater?
{

View file

@ -21,6 +21,10 @@ class QTextStream;
class InnerDecklistNode;
#define DECK_ZONE_MAIN "main"
#define DECK_ZONE_SIDE "side"
#define DECK_ZONE_TOKENS "tokens"
class SideboardPlan {
private:
QString name;
@ -35,7 +39,7 @@ public:
void setMoveList(const QList<MoveCard_ToZone> &_moveList);
};
enum DeckSortMethod { ByNumber, ByName, ByPrice };
enum DeckSortMethod { ByNumber, ByName };
class AbstractDecklistNode {
protected:
@ -72,11 +76,9 @@ public:
AbstractDecklistNode *findChild(const QString &name);
int height() const;
int recursiveCount(bool countTotalCards = false) const;
float recursivePrice(bool countTotalCards = false) const;
bool compare(AbstractDecklistNode *other) const;
bool compareNumber(AbstractDecklistNode *other) const;
bool compareName(AbstractDecklistNode *other) const;
bool comparePrice(AbstractDecklistNode *other) const;
QVector<QPair<int, int> > sort(Qt::SortOrder order = Qt::AscendingOrder);
bool readElement(QXmlStreamReader *xml);
@ -90,14 +92,10 @@ public:
virtual void setNumber(int _number) = 0;
virtual QString getName() const = 0;
virtual void setName(const QString &_name) = 0;
virtual float getPrice() const = 0;
virtual void setPrice(const float _price) = 0;
float getTotalPrice() const { return getNumber() * getPrice(); }
int height() const { return 0; }
bool compare(AbstractDecklistNode *other) const;
bool compareNumber(AbstractDecklistNode *other) const;
bool compareName(AbstractDecklistNode *other) const;
bool compareTotalPrice(AbstractDecklistNode *other) const;
bool readElement(QXmlStreamReader *xml);
void writeElement(QXmlStreamWriter *xml);
@ -107,17 +105,13 @@ class DecklistCardNode : public AbstractDecklistCardNode {
private:
QString name;
int number;
float price;
public:
DecklistCardNode(const QString &_name = QString(), int _number = 1, float _price = 0, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number), price(_price) { }
DecklistCardNode(const QString &_name = QString(), int _number = 1, InnerDecklistNode *_parent = 0) : AbstractDecklistCardNode(_parent), name(_name), number(_number) { }
DecklistCardNode(DecklistCardNode *other, InnerDecklistNode *_parent);
int getNumber() const { return number; }
void setNumber(int _number) { number = _number; }
QString getName() const { return name; }
void setName(const QString &_name) { name = _name; }
float getPrice() const { return price; }
void setPrice(const float _price) { price = _price; }
};
class DeckList : public QObject {
@ -128,6 +122,9 @@ private:
QMap<QString, SideboardPlan *> sideboardPlans;
InnerDecklistNode *root;
void getCardListHelper(InnerDecklistNode *node, QSet<QString> &result) const;
InnerDecklistNode *getZoneObjFromName(const QString zoneName);
protected:
virtual QString getCardZoneFromName(QString /* cardName */, QString currentZoneName) { return currentZoneName; };
signals:
void deckHashChanged();
public slots:

View file

@ -170,9 +170,9 @@ void Server_Player::setupZones()
for (int i = 0; i < listRoot->size(); ++i) {
InnerDecklistNode *currentZone = dynamic_cast<InnerDecklistNode *>(listRoot->at(i));
Server_CardZone *z;
if (currentZone->getName() == "main")
if (currentZone->getName() == DECK_ZONE_MAIN)
z = deckZone;
else if (currentZone->getName() == "side")
else if (currentZone->getName() == DECK_ZONE_SIDE)
z = sbZone;
else
continue;
@ -193,15 +193,15 @@ void Server_Player::setupZones()
const QString targetZone = QString::fromStdString(m.target_zone());
Server_CardZone *start, *target;
if (startZone == "main")
if (startZone == DECK_ZONE_MAIN)
start = deckZone;
else if (startZone == "side")
else if (startZone == DECK_ZONE_SIDE)
start = sbZone;
else
continue;
if (targetZone == "main")
if (targetZone == DECK_ZONE_MAIN)
target = deckZone;
else if (targetZone == "side")
else if (targetZone == DECK_ZONE_SIDE)
target = sbZone;
else
continue;

View file

@ -20,9 +20,9 @@ struct DecklistBuilder {
explicit DecklistBuilder() : actualMainboard({}), actualSideboard({}) {}
void operator()(const InnerDecklistNode *innerDecklistNode, const DecklistCardNode *card) {
if (innerDecklistNode->getName() == "main") {
if (innerDecklistNode->getName() == DECK_ZONE_MAIN) {
actualMainboard[card->getName()] += card->getNumber();
} else if (innerDecklistNode->getName() == "side") {
} else if (innerDecklistNode->getName() == DECK_ZONE_SIDE) {
actualSideboard[card->getName()] += card->getNumber();
} else {
FAIL();