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.
This commit is contained in:
parent
c356a6fc48
commit
66adeb6d75
4 changed files with 59 additions and 35 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
const int CardDatabase::versionNeeded = 3;
|
const int CardDatabase::versionNeeded = 3;
|
||||||
const char* CardDatabase::TOKENS_SETNAME = "TK";
|
const char* CardDatabase::TOKENS_SETNAME = "TK";
|
||||||
|
@ -1028,6 +1029,8 @@ LoadStatus CardDatabase::loadCardDatabase(const QString &path, bool tokens)
|
||||||
allSets.append(setsIterator.next().value());
|
allSets.append(setsIterator.next().value());
|
||||||
allSets.sortByKey();
|
allSets.sortByKey();
|
||||||
|
|
||||||
|
if(!tokens)
|
||||||
|
checkUnknownSets();
|
||||||
emit cardListChanged();
|
emit cardListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1098,3 +1101,51 @@ void CardDatabase::picsPathChanged()
|
||||||
pictureLoader->setPicsPath(settingsCache->getPicsPath());
|
pictureLoader->setPicsPath(settingsCache->getPicsPath());
|
||||||
clearPixmapCache();
|
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;
|
||||||
|
}
|
|
@ -232,12 +232,14 @@ protected:
|
||||||
QThread *pictureLoaderThread;
|
QThread *pictureLoaderThread;
|
||||||
PictureLoader *pictureLoader;
|
PictureLoader *pictureLoader;
|
||||||
LoadStatus loadStatus;
|
LoadStatus loadStatus;
|
||||||
|
bool detectedFirstRun;
|
||||||
private:
|
private:
|
||||||
static const int versionNeeded;
|
static const int versionNeeded;
|
||||||
void loadCardsFromXml(QXmlStreamReader &xml, bool tokens);
|
void loadCardsFromXml(QXmlStreamReader &xml, bool tokens);
|
||||||
void loadSetsFromXml(QXmlStreamReader &xml);
|
void loadSetsFromXml(QXmlStreamReader &xml);
|
||||||
|
|
||||||
CardInfo *getCardFromMap(CardNameMap &cardMap, const QString &cardName, bool createIfNotFound);
|
CardInfo *getCardFromMap(CardNameMap &cardMap, const QString &cardName, bool createIfNotFound);
|
||||||
|
void checkUnknownSets();
|
||||||
public:
|
public:
|
||||||
static const char* TOKENS_SETNAME;
|
static const char* TOKENS_SETNAME;
|
||||||
|
|
||||||
|
@ -265,6 +267,7 @@ public:
|
||||||
bool getLoadSuccess() const { return loadStatus == Ok; }
|
bool getLoadSuccess() const { return loadStatus == Ok; }
|
||||||
void cacheCardPixmaps(const QStringList &cardNames);
|
void cacheCardPixmaps(const QStringList &cardNames);
|
||||||
void loadImage(CardInfo *card);
|
void loadImage(CardInfo *card);
|
||||||
|
bool hasDetectedFirstRun();
|
||||||
public slots:
|
public slots:
|
||||||
void clearPixmapCache();
|
void clearPixmapCache();
|
||||||
LoadStatus loadCardDatabase(const QString &path, bool tokens = false);
|
LoadStatus loadCardDatabase(const QString &path, bool tokens = false);
|
||||||
|
|
|
@ -293,8 +293,7 @@ TabDeckEditor::TabDeckEditor(TabSupervisor *_tabSupervisor, QWidget *parent)
|
||||||
|
|
||||||
resize(950, 700);
|
resize(950, 700);
|
||||||
|
|
||||||
connect(this, SIGNAL(setListChanged()), db, SIGNAL(cardListChanged()));
|
QTimer::singleShot(0, this, SLOT(checkFirstRunDetected()));
|
||||||
QTimer::singleShot(0, this, SLOT(checkUnknownSets()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TabDeckEditor::~TabDeckEditor()
|
TabDeckEditor::~TabDeckEditor()
|
||||||
|
@ -786,39 +785,11 @@ void TabDeckEditor::filterRemove(QAction *action) {
|
||||||
filterModel->removeRow(idx.row(), idx.parent());
|
filterModel->removeRow(idx.row(), idx.parent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDeckEditor::checkUnknownSets()
|
void TabDeckEditor::checkFirstRunDetected()
|
||||||
{
|
{
|
||||||
SetList sets = db->getSetList();
|
if(db->hasDetectedFirstRun())
|
||||||
|
|
||||||
// no set is enabled. Probably this is the first time running trice
|
|
||||||
if(!sets.getEnabledSetsNum())
|
|
||||||
{
|
{
|
||||||
sets.guessSortKeys();
|
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."));
|
||||||
sets.sortByKey();
|
|
||||||
sets.enableAll();
|
|
||||||
db->emitCardListChanged();
|
|
||||||
|
|
||||||
actEditSets();
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -113,10 +113,9 @@ public:
|
||||||
bool confirmClose();
|
bool confirmClose();
|
||||||
public slots:
|
public slots:
|
||||||
void closeRequest();
|
void closeRequest();
|
||||||
void checkUnknownSets();
|
void checkFirstRunDetected();
|
||||||
signals:
|
signals:
|
||||||
void deckEditorClosing(TabDeckEditor *tab);
|
void deckEditorClosing(TabDeckEditor *tab);
|
||||||
void setListChanged();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue