diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 8e97fe55..a4a5b217 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -93,15 +93,15 @@ GeneralSettingsPage::GeneralSettingsPage() personalGrid->addWidget(&pixmapCacheLabel, 2, 0); personalGrid->addWidget(&pixmapCacheEdit, 2, 1); personalGrid->addWidget(&updateNotificationCheckBox, 3, 0); - personalGrid->addWidget(&picDownloadCheckBox, 4, 0, 1, 3); - personalGrid->addWidget(&defaultUrlLabel, 5, 0, 1, 1); - personalGrid->addWidget(defaultUrlEdit, 5, 1, 1, 1); - personalGrid->addWidget(&defaultUrlRestoreButton, 5, 2, 1, 1); - personalGrid->addWidget(&fallbackUrlLabel, 6, 0, 1, 1); - personalGrid->addWidget(fallbackUrlEdit, 6, 1, 1, 1); - personalGrid->addWidget(&fallbackUrlRestoreButton, 6, 2, 1, 1); - personalGrid->addWidget(&showTipsOnStartup, 7, 0); - personalGrid->addWidget(&urlLinkLabel, 7, 1, 1, 1); + personalGrid->addWidget(&showTipsOnStartup, 4, 0); + personalGrid->addWidget(&picDownloadCheckBox, 5, 0); + personalGrid->addWidget(&urlLinkLabel, 5, 1); + personalGrid->addWidget(&defaultUrlLabel, 6, 0, 1, 1); + personalGrid->addWidget(defaultUrlEdit, 6, 1, 1, 1); + personalGrid->addWidget(&defaultUrlRestoreButton, 6, 2, 1, 1); + personalGrid->addWidget(&fallbackUrlLabel, 7, 0, 1, 1); + personalGrid->addWidget(fallbackUrlEdit, 7, 1, 1, 1); + personalGrid->addWidget(&fallbackUrlRestoreButton, 7, 2, 1, 1); personalGrid->addWidget(&clearDownloadedPicsButton, 8, 0, 1, 3); urlLinkLabel.setTextInteractionFlags(Qt::LinksAccessibleByMouse); diff --git a/cockatrice/src/dlg_tip_of_the_day.cpp b/cockatrice/src/dlg_tip_of_the_day.cpp index 0bb78f07..67ecc400 100644 --- a/cockatrice/src/dlg_tip_of_the_day.cpp +++ b/cockatrice/src/dlg_tip_of_the_day.cpp @@ -41,7 +41,19 @@ DlgTipOfTheDay::DlgTipOfTheDay(QWidget *parent) : QDialog(parent) tipNumber = new QLabel(); tipNumber->setAlignment(Qt::AlignCenter); - currentTip = settingsCache->getLastShownTip() + 1; + if (settingsCache->getSeenTips().size() != tipDatabase->rowCount()) { + newTipsAvailable = true; + QList rangeToMaxTips; + for (int i = 0; i < tipDatabase->rowCount(); i++) { + rangeToMaxTips.append(i); + } + QSet unseenTips = rangeToMaxTips.toSet() - settingsCache->getSeenTips().toSet(); + currentTip = *std::min_element(unseenTips.begin(), unseenTips.end()); + } else { + newTipsAvailable = false; + currentTip = 0; + } + connect(this, SIGNAL(newTipRequested(int)), this, SLOT(updateTip(int))); newTipRequested(currentTip); @@ -63,7 +75,7 @@ DlgTipOfTheDay::DlgTipOfTheDay(QWidget *parent) : QDialog(parent) connect(previousButton, SIGNAL(clicked()), this, SLOT(previousClicked())); showTipsOnStartupCheck = new QCheckBox("Show tips on startup"); - showTipsOnStartupCheck->setChecked(true); + showTipsOnStartupCheck->setChecked(settingsCache->getShowTipsOnStartup()); connect(showTipsOnStartupCheck, SIGNAL(clicked(bool)), settingsCache, SLOT(setShowTipsOnStartup(bool))); buttonBar = new QHBoxLayout(); buttonBar->addWidget(showTipsOnStartupCheck); @@ -118,6 +130,13 @@ void DlgTipOfTheDay::updateTip(int tipId) tipId = tipId % tipDatabase->rowCount(); } + // Store tip id as seen + QList seenTips = settingsCache->getSeenTips(); + if (!seenTips.contains(tipId)) { + seenTips.append(tipId); + settingsCache->setSeenTips(seenTips); + } + TipOfTheDay tip = tipDatabase->getTip(tipId); titleText = tip.getTitle(); contentText = tip.getContent(); @@ -140,7 +159,6 @@ void DlgTipOfTheDay::updateTip(int tipId) tipNumber->setText("Tip " + QString::number(tipId + 1) + " / " + QString::number(tipDatabase->rowCount())); currentTip = static_cast(tipId); - settingsCache->setLastShownTip(currentTip); } void DlgTipOfTheDay::resizeEvent(QResizeEvent *event) diff --git a/cockatrice/src/dlg_tip_of_the_day.h b/cockatrice/src/dlg_tip_of_the_day.h index b40aab3b..79d01f5c 100644 --- a/cockatrice/src/dlg_tip_of_the_day.h +++ b/cockatrice/src/dlg_tip_of_the_day.h @@ -21,6 +21,7 @@ public: explicit DlgTipOfTheDay(QWidget *parent = nullptr); ~DlgTipOfTheDay() override; bool successfulInit; + bool newTipsAvailable; signals: void newTipRequested(int tipId); diff --git a/cockatrice/src/main.cpp b/cockatrice/src/main.cpp index 83ed6cb2..8612780e 100644 --- a/cockatrice/src/main.cpp +++ b/cockatrice/src/main.cpp @@ -139,7 +139,7 @@ int main(int argc, char *argv[]) qDebug("main(): ui.show() finished"); DlgTipOfTheDay tip; - if (settingsCache->getShowTipsOnStartup() && tip.successfulInit) { + if (tip.successfulInit && settingsCache->getShowTipsOnStartup() && tip.newTipsAvailable) { tip.show(); } diff --git a/cockatrice/src/settingscache.cpp b/cockatrice/src/settingscache.cpp index c65bc888..e039fb08 100644 --- a/cockatrice/src/settingscache.cpp +++ b/cockatrice/src/settingscache.cpp @@ -143,6 +143,7 @@ QString SettingsCache::getSafeConfigFilePath(QString configEntry, QString defaul tmp = defaultPath; return tmp; } + SettingsCache::SettingsCache() { // first, figure out if we are running in portable mode @@ -181,7 +182,9 @@ SettingsCache::SettingsCache() // tip of the day settings showTipsOnStartup = settings->value("tipOfDay/showTips", true).toBool(); - lastShownTip = settings->value("tipOfDay/lastShown", -1).toInt(); + for (auto tipNumber : settings->value("tipOfDay/seenTips").toList()) { + seenTips.append(tipNumber.toInt()); + } deckPath = getSafeConfigPath("paths/decks", dataPath + "/decks/"); replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/"); @@ -345,10 +348,14 @@ void SettingsCache::setShowTipsOnStartup(bool _showTipsOnStartup) settings->setValue("tipOfDay/showTips", showTipsOnStartup); } -void SettingsCache::setLastShownTip(int _lastShownTip) +void SettingsCache::setSeenTips(const QList &_seenTips) { - lastShownTip = _lastShownTip; - settings->setValue("tipOfDay/lastShown", lastShownTip); + seenTips = _seenTips; + QList storedTipList; + for (auto tipNumber : seenTips) { + storedTipList.append(tipNumber); + } + settings->setValue("tipOfDay/seenTips", storedTipList); } void SettingsCache::setDeckPath(const QString &_deckPath) diff --git a/cockatrice/src/settingscache.h b/cockatrice/src/settingscache.h index 482e5ef3..1f21a8c2 100644 --- a/cockatrice/src/settingscache.h +++ b/cockatrice/src/settingscache.h @@ -68,7 +68,7 @@ private: spoilerDatabasePath, tokenDatabasePath, themeName; bool notifyAboutUpdates; bool showTipsOnStartup; - unsigned int lastShownTip; + QList seenTips; bool mbDownloadSpoilers; int updateReleaseChannel; int maxFontSize; @@ -205,9 +205,9 @@ public: { return showTipsOnStartup; } - unsigned int getLastShownTip() const + QList getSeenTips() const { - return lastShownTip; + return seenTips; } ReleaseChannel *getUpdateReleaseChannel() const { @@ -444,7 +444,7 @@ public slots: void setTokenDialogGeometry(const QByteArray &_tokenDialog); void setLang(const QString &_lang); void setShowTipsOnStartup(bool _showTipsOnStartup); - void setLastShownTip(int _lastShowTip); + void setSeenTips(const QList &_seenTips); void setDeckPath(const QString &_deckPath); void setReplaysPath(const QString &_replaysPath); void setPicsPath(const QString &_picsPath); diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index 4ae54ce3..854b5d6f 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -41,6 +41,7 @@ #include "dlg_forgotpasswordreset.h" #include "dlg_register.h" #include "dlg_settings.h" +#include "dlg_tip_of_the_day.h" #include "dlg_update.h" #include "dlg_viewlog.h" #include "localclient.h" @@ -312,6 +313,14 @@ void MainWindow::actAbout() mb.exec(); } +void MainWindow::actTips() +{ + DlgTipOfTheDay tip; + if (tip.successfulInit) { + tip.exec(); + } +} + void MainWindow::actUpdate() { DlgUpdate dlg(this); @@ -627,6 +636,7 @@ void MainWindow::retranslateUi() aEditTokens->setText(tr("Edit &tokens...")); aAbout->setText(tr("&About Cockatrice")); + aTips->setText(tr("&Tip of the Day")); aUpdate->setText(tr("Check for Client Updates")); aViewLog->setText(tr("View &debug log")); helpMenu->setTitle(tr("&Help")); @@ -659,6 +669,8 @@ void MainWindow::createActions() aAbout = new QAction(this); connect(aAbout, SIGNAL(triggered()), this, SLOT(actAbout())); + aTips = new QAction(this); + connect(aTips, SIGNAL(triggered()), this, SLOT(actTips())); aUpdate = new QAction(this); connect(aUpdate, SIGNAL(triggered()), this, SLOT(actUpdate())); aViewLog = new QAction(this); @@ -729,6 +741,7 @@ void MainWindow::createMenus() helpMenu = menuBar()->addMenu(QString()); helpMenu->addAction(aAbout); + helpMenu->addAction(aTips); helpMenu->addAction(aUpdate); helpMenu->addAction(aViewLog); } diff --git a/cockatrice/src/window_main.h b/cockatrice/src/window_main.h index 44ffb716..6122ba4b 100644 --- a/cockatrice/src/window_main.h +++ b/cockatrice/src/window_main.h @@ -72,6 +72,7 @@ private slots: void actExit(); void actForgotPasswordRequest(); void actAbout(); + void actTips(); void actUpdate(); void actViewLog(); void forgotPasswordSuccess(); @@ -115,7 +116,7 @@ private: QList tabMenus; QMenu *cockatriceMenu, *dbMenu, *helpMenu; QAction *aConnect, *aDisconnect, *aSinglePlayer, *aWatchReplay, *aDeckEditor, *aFullScreen, *aSettings, *aExit, - *aAbout, *aCheckCardUpdates, *aRegister, *aUpdate, *aViewLog; + *aAbout, *aTips, *aCheckCardUpdates, *aRegister, *aUpdate, *aViewLog; QAction *aManageSets, *aEditTokens, *aOpenCustomFolder, *aOpenCustomsetsFolder, *aAddCustomSet; TabSupervisor *tabSupervisor;