Feature/3139 new features for tips (#3152)

* "Tip of the Day" option added to Help menu

* Tip of the Day setting moved

* If no new tips are availabe, don't show tip of the day again

* list storing try #1

* first unseen tip shown first

* lastShownTip removed

* fixed next/previous buttons

* spaces > tab

* "Show this window on startup" is not checked by default
This commit is contained in:
David Szabo 2018-04-01 10:52:26 +02:00 committed by Zach H
parent 6374d157fc
commit e1394bd851
8 changed files with 62 additions and 22 deletions

View file

@ -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);

View file

@ -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<int> rangeToMaxTips;
for (int i = 0; i < tipDatabase->rowCount(); i++) {
rangeToMaxTips.append(i);
}
QSet<int> 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<int> 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<unsigned int>(tipId);
settingsCache->setLastShownTip(currentTip);
}
void DlgTipOfTheDay::resizeEvent(QResizeEvent *event)

View file

@ -21,6 +21,7 @@ public:
explicit DlgTipOfTheDay(QWidget *parent = nullptr);
~DlgTipOfTheDay() override;
bool successfulInit;
bool newTipsAvailable;
signals:
void newTipRequested(int tipId);

View file

@ -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();
}

View file

@ -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<int> &_seenTips)
{
lastShownTip = _lastShownTip;
settings->setValue("tipOfDay/lastShown", lastShownTip);
seenTips = _seenTips;
QList<QVariant> storedTipList;
for (auto tipNumber : seenTips) {
storedTipList.append(tipNumber);
}
settings->setValue("tipOfDay/seenTips", storedTipList);
}
void SettingsCache::setDeckPath(const QString &_deckPath)

View file

@ -68,7 +68,7 @@ private:
spoilerDatabasePath, tokenDatabasePath, themeName;
bool notifyAboutUpdates;
bool showTipsOnStartup;
unsigned int lastShownTip;
QList<int> seenTips;
bool mbDownloadSpoilers;
int updateReleaseChannel;
int maxFontSize;
@ -205,9 +205,9 @@ public:
{
return showTipsOnStartup;
}
unsigned int getLastShownTip() const
QList<int> 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<int> &_seenTips);
void setDeckPath(const QString &_deckPath);
void setReplaysPath(const QString &_replaysPath);
void setPicsPath(const QString &_picsPath);

View file

@ -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);
}

View file

@ -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<QMenu *> 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;