Commit 66adeb6d authored by Fabio Bas's avatar Fabio Bas
Browse files

Improve sets handling

Move the “check unknown sets” method inside the cards database, so that
it can be executed when the card database gets reloaded after a card
database update.
Additionally, show the user a welcome message the first time they run a
new cockatrice version, so that they know why they get shown the “edit
sets” window and how to hide/disable sets.
parent c356a6fc
......@@ -14,6 +14,7 @@
#include <QNetworkRequest>
#include <QDebug>
#include <QImageReader>
#include <QMessageBox>
const int CardDatabase::versionNeeded = 3;
const char* CardDatabase::TOKENS_SETNAME = "TK";
......@@ -1028,6 +1029,8 @@ LoadStatus CardDatabase::loadCardDatabase(const QString &path, bool tokens)
allSets.append(setsIterator.next().value());
allSets.sortByKey();
if(!tokens)
checkUnknownSets();
emit cardListChanged();
}
......@@ -1098,3 +1101,51 @@ void CardDatabase::picsPathChanged()
pictureLoader->setPicsPath(settingsCache->getPicsPath());
clearPixmapCache();
}
void CardDatabase::checkUnknownSets()
{
SetList sets = getSetList();
// no set is enabled. Probably this is the first time running trice
if(!sets.getEnabledSetsNum())
{
sets.guessSortKeys();
sets.sortByKey();
sets.enableAll();
detectedFirstRun = true;
return;
}
int numUnknownSets = sets.getUnknownSetsNum();
// no unkown sets.
if(!numUnknownSets)
return;
QMessageBox msgbox(QMessageBox::Question, tr("New sets found"), tr("%1 new set(s) have been found in the card database. Do you want to enable them?").arg(numUnknownSets), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel);
switch(msgbox.exec())
{
case QMessageBox::No:
sets.markAllAsKnown();
break;
case QMessageBox::Yes:
sets.enableAllUnknown();
break;
default:
break;
}
return;
}
bool CardDatabase::hasDetectedFirstRun()
{
if(detectedFirstRun)
{
detectedFirstRun=false;
return true;
}
return false;
}
\ No newline at end of file
......@@ -232,12 +232,14 @@ protected:
QThread *pictureLoaderThread;
PictureLoader *pictureLoader;
LoadStatus loadStatus;
bool detectedFirstRun;
private:
static const int versionNeeded;
void loadCardsFromXml(QXmlStreamReader &xml, bool tokens);
void loadSetsFromXml(QXmlStreamReader &xml);
CardInfo *getCardFromMap(CardNameMap &cardMap, const QString &cardName, bool createIfNotFound);
void checkUnknownSets();
public:
static const char* TOKENS_SETNAME;
......@@ -265,6 +267,7 @@ public:
bool getLoadSuccess() const { return loadStatus == Ok; }
void cacheCardPixmaps(const QStringList &cardNames);
void loadImage(CardInfo *card);
bool hasDetectedFirstRun();
public slots:
void clearPixmapCache();
LoadStatus loadCardDatabase(const QString &path, bool tokens = false);
......
......@@ -293,8 +293,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
resize(950, 700);
connect(this, SIGNAL(setListChanged()), db, SIGNAL(cardListChanged()));
QTimer::singleShot(0, this, SLOT(checkUnknownSets()));
QTimer::singleShot(0, this, SLOT(checkFirstRunDetected()));
}
TabDeckEditor::~TabDeckEditor()
......@@ -786,39 +785,11 @@ void TabDeckEditor::filterRemove(QAction *action) {
filterModel->removeRow(idx.row(), idx.parent());
}
void TabDeckEditor::checkUnknownSets()
void TabDeckEditor::checkFirstRunDetected()
{
SetList sets = db->getSetList();
// no set is enabled. Probably this is the first time running trice
if(!sets.getEnabledSetsNum())
if(db->hasDetectedFirstRun())
{
sets.guessSortKeys();
sets.sortByKey();
sets.enableAll();
db->emitCardListChanged();
QMessageBox::information(this, tr("Welcome"), tr("Hi! Its seems like it's the first time you run this version of Cockatrice.<br/>All the sets in the card database have been enabled; if you want to hide a set from the deck editor, disable it in the \"Edit Sets\" window."));
actEditSets();
return;
}
int numUnknownSets = sets.getUnknownSetsNum();
// no unkown sets.
if(!numUnknownSets)
return;
int ret = QMessageBox::question(this, tr("New sets found"), tr("%1 new set(s) have been found in the card database. Do you want to enable them?").arg(numUnknownSets), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel, QMessageBox::Yes);
switch(ret)
{
case QMessageBox::No:
sets.markAllAsKnown();
break;
case QMessageBox::Yes:
sets.enableAllUnknown();
db->emitCardListChanged();
break;
default:
break;
}
}
\ No newline at end of file
......@@ -113,10 +113,9 @@ public:
bool confirmClose();
public slots:
void closeRequest();
void checkUnknownSets();
void checkFirstRunDetected();
signals:
void deckEditorClosing(TabDeckEditor *tab);
void setListChanged();
};
#endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment