# HG changeset patch # User nemo # Date 1387897856 18000 # Node ID 1957c7f92460b63ff581eb5c5bc60f51f9377bdb # Parent b1038b4373ccc1030eec5e39eca10562841ca419 Pick random tip from the tip file each time front page is viewed. diff -r b1038b4373cc -r 1957c7f92460 QTfrontend/ui/page/AbstractPage.cpp --- a/QTfrontend/ui/page/AbstractPage.cpp Tue Dec 24 09:53:08 2013 -0500 +++ b/QTfrontend/ui/page/AbstractPage.cpp Tue Dec 24 10:10:56 2013 -0500 @@ -67,7 +67,7 @@ descLabel->setAlignment(Qt::AlignCenter); descLabel->setWordWrap(true); descLabel->setOpenExternalLinks(true); - descLabel->setFixedHeight(50); + descLabel->setFixedHeight(60); descLabel->setStyleSheet("font-size: 16px"); bottomLeftLayout->addWidget(descLabel); pageLayout->addWidget(descLabel, 1, 1); diff -r b1038b4373cc -r 1957c7f92460 QTfrontend/ui/page/pagemain.cpp --- a/QTfrontend/ui/page/pagemain.cpp Tue Dec 24 09:53:08 2013 -0500 +++ b/QTfrontend/ui/page/pagemain.cpp Tue Dec 24 10:10:56 2013 -0500 @@ -121,6 +121,9 @@ void PageMain::connectSignals() { +#ifndef QT_DEBUG + connect(this, SIGNAL(pageEnter()), this, SLOT(updateTip())); +#endif connect(BtnNet, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice())); //connect(BtnNetLocal, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice())); //connect(BtnNetOfficial, SIGNAL(clicked()), this, SLOT(toggleNetworkChoice())); @@ -134,16 +137,19 @@ if(frontendEffects) setAttribute(Qt::WA_NoSystemBackground, true); mainNote->setOpenExternalLinks(true); - #ifdef QT_DEBUG setDefaultDescription(QLabel::tr("This development build is 'work in progress' and may not be compatible with other versions of the game, while some features might be broken or incomplete!")); #else setDefaultDescription(QLabel::tr("Tip: %1").arg(randomTip())); #endif - } -QString PageMain::randomTip() const +void PageMain::updateTip() +{ + setDefaultDescription(QLabel::tr("Tip: %1").arg(randomTip())); +} + +QString PageMain::randomTip() { #ifdef _WIN32 int platform = 1; @@ -152,54 +158,56 @@ #else int platform = 3; #endif - DataManager & dataMgr = DataManager::instance(); + if(Tips.length() == 0) + { + DataManager & dataMgr = DataManager::instance(); - // get locale - QSettings settings(dataMgr.settingsFileName(), - QSettings::IniFormat); - - QString loc = settings.value("misc/locale", "").toString(); - if (loc.isEmpty()) - loc = QLocale::system().name(); + // get locale + QSettings settings(dataMgr.settingsFileName(), + QSettings::IniFormat); - QString tipFile = QString("physfs://Locale/tips_" + loc + ".xml"); + QString loc = settings.value("misc/locale", "").toString(); + if (loc.isEmpty()) + loc = QLocale::system().name(); + + QString tipFile = QString("physfs://Locale/tips_" + loc + ".xml"); - // if file is non-existant try with language only - if (!QFile::exists(tipFile)) - tipFile = QString("physfs://Locale/tips_" + loc.remove(QRegExp("_.*$")) + ".xml"); + // if file is non-existant try with language only + if (!QFile::exists(tipFile)) + tipFile = QString("physfs://Locale/tips_" + loc.remove(QRegExp("_.*$")) + ".xml"); - // fallback if file for current locale is non-existant - if (!QFile::exists(tipFile)) - tipFile = QString("physfs://Locale/tips_en.xml"); + // fallback if file for current locale is non-existant + if (!QFile::exists(tipFile)) + tipFile = QString("physfs://Locale/tips_en.xml"); - QStringList Tips; - QFile file(tipFile); - file.open(QIODevice::ReadOnly); - QTextStream in(&file); - QString line = in.readLine(); - int tip_platform = 0; - while (!line.isNull()) { - if(line.contains("", Qt::CaseSensitive)) - tip_platform = 1; - if(line.contains("", Qt::CaseSensitive)) - tip_platform = 2; - if(line.contains("", Qt::CaseSensitive)) - tip_platform = 3; - if(line.contains("", Qt::CaseSensitive) || - line.contains("", Qt::CaseSensitive) || - line.contains("", Qt::CaseSensitive)) { - tip_platform = 0; + QFile file(tipFile); + file.open(QIODevice::ReadOnly); + QTextStream in(&file); + QString line = in.readLine(); + int tip_platform = 0; + while (!line.isNull()) { + if(line.contains("", Qt::CaseSensitive)) + tip_platform = 1; + if(line.contains("", Qt::CaseSensitive)) + tip_platform = 2; + if(line.contains("", Qt::CaseSensitive)) + tip_platform = 3; + if(line.contains("", Qt::CaseSensitive) || + line.contains("", Qt::CaseSensitive) || + line.contains("", Qt::CaseSensitive)) { + tip_platform = 0; + } + QStringList split_string = line.split(QRegExp("")); + if((tip_platform == platform || tip_platform == 0) && split_string.size() != 1) + Tips << tr(split_string[1].toLatin1().data(), "Tips"); + line = in.readLine(); } - QStringList split_string = line.split(QRegExp("")); - if((tip_platform == platform || tip_platform == 0) && split_string.size() != 1) - Tips << tr(split_string[1].toLatin1().data(), "Tips"); - line = in.readLine(); + // The following tip will require links to app store entries first. + //Tips << tr("Want to play Hedgewars any time? Grab the Mobile version for %1 and %2.", "Tips").arg("").arg(""); + // the ios version is located here: http://itunes.apple.com/us/app/hedgewars/id391234866 + + file.close(); } - // The following tip will require links to app store entries first. - //Tips << tr("Want to play Hedgewars any time? Grab the Mobile version for %1 and %2.", "Tips").arg("").arg(""); - // the ios version is located here: http://itunes.apple.com/us/app/hedgewars/id391234866 - - file.close(); return Tips[QTime(0, 0, 0).secsTo(QTime::currentTime()) % Tips.length()]; } diff -r b1038b4373cc -r 1957c7f92460 QTfrontend/ui/page/pagemain.h --- a/QTfrontend/ui/page/pagemain.h Tue Dec 24 09:53:08 2013 -0500 +++ b/QTfrontend/ui/page/pagemain.h Tue Dec 24 10:10:56 2013 -0500 @@ -48,10 +48,12 @@ void connectSignals(); QIcon originalNetworkIcon, disabledNetworkIcon; - QString randomTip() const; + QString randomTip(); + QStringList Tips; private slots: void toggleNetworkChoice(); + void updateTip(); }; #endif