diff --git a/launcher/firstLaunch/firstlaunch_moc.cpp b/launcher/firstLaunch/firstlaunch_moc.cpp index c3c1e7c35..192d8891e 100644 --- a/launcher/firstLaunch/firstlaunch_moc.cpp +++ b/launcher/firstLaunch/firstlaunch_moc.cpp @@ -30,8 +30,8 @@ FirstLaunchView::FirstLaunchView(QWidget * parent) enterSetup(); activateTabLanguage(); - ui->lineEditDataSystem->setText(boost::filesystem::absolute(VCMIDirs::get().dataPaths().front()).c_str()); - ui->lineEditDataUser->setText(boost::filesystem::absolute(VCMIDirs::get().userDataPath()).c_str()); + ui->lineEditDataSystem->setText(pathToQString(boost::filesystem::absolute(VCMIDirs::get().dataPaths().front()))); + ui->lineEditDataUser->setText(pathToQString(boost::filesystem::absolute(VCMIDirs::get().userDataPath()))); } void FirstLaunchView::on_buttonTabLanguage_clicked() @@ -156,7 +156,8 @@ void FirstLaunchView::activateTabModPreset() void FirstLaunchView::exitSetup() { - //TODO: unlock UI, switch to another tab (mods?) + if(auto * mainWindow = dynamic_cast(qApp->activeWindow())) + mainWindow->exitSetup(); } // Tab Language @@ -279,38 +280,37 @@ void FirstLaunchView::forceHeroesLanguage(const QString & language) void FirstLaunchView::copyHeroesData() { - assert(0); // TODO: test + QDir sourceRoot = QFileDialog::getExistingDirectory(this, "", "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - QDir dir = QFileDialog::getExistingDirectory(this, "", "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); - - if(!dir.exists()) + if(!sourceRoot.exists()) return; - QStringList dirData = dir.entryList({"data"}, QDir::Filter::Dirs); - QStringList dirMaps = dir.entryList({"maps"}, QDir::Filter::Dirs); - QStringList dirMp3 = dir.entryList({"mp3"}, QDir::Filter::Dirs); + QStringList dirData = sourceRoot.entryList({"data"}, QDir::Filter::Dirs); + QStringList dirMaps = sourceRoot.entryList({"maps"}, QDir::Filter::Dirs); + QStringList dirMp3 = sourceRoot.entryList({"mp3"}, QDir::Filter::Dirs); if(dirData.empty() || dirMaps.empty() || dirMp3.empty()) return; - QStringList lodArchives = QDir(dirData.front()).entryList({"*.lod"}, QDir::Filter::Files); + QDir sourceData = sourceRoot.filePath(dirData.front()); + QStringList lodArchives = sourceData.entryList({"*.lod"}, QDir::Filter::Files); if(lodArchives.empty()) return; QStringList copyDirectories = {dirData.front(), dirMaps.front(), dirMp3.front()}; - QDir targetRoot = QString(VCMIDirs::get().userDataPath().c_str()); + QDir targetRoot = pathToQString(VCMIDirs::get().userDataPath()); - for(QDir sourceDir : copyDirectories) + for(const QString & dirName : copyDirectories) { - QString dirName = sourceDir.dirName(); + QDir sourceDir = sourceRoot.filePath(dirName); QDir targetDir = targetRoot.filePath(dirName); if(!targetRoot.exists(dirName)) targetRoot.mkdir(dirName); - for(QString filename : sourceDir.entryList(QDir::Filter::Files)) + for(const QString & filename : sourceDir.entryList(QDir::Filter::Files)) { QFile sourceFile(sourceDir.filePath(filename)); sourceFile.copy(targetDir.filePath(filename)); @@ -326,12 +326,12 @@ void FirstLaunchView::modPresetUpdate() bool translationExists = !findTranslationModName().isEmpty(); ui->labelPresetLanguage->setVisible(translationExists); - ui->toolButtonPresetLanguage->setVisible(translationExists); + ui->checkBoxPresetLanguage->setVisible(translationExists); - ui->toolButtonPresetLanguage->setEnabled(checkCanInstallTranslation()); - ui->toolButtonPresetExtras->setEnabled(checkCanInstallExtras()); - ui->toolButtonPresetHota->setEnabled(checkCanInstallHota()); - ui->toolButtonPresetWog->setEnabled(checkCanInstallWog()); + ui->checkBoxPresetLanguage->setEnabled(checkCanInstallTranslation()); + ui->checkBoxPresetExtras->setEnabled(checkCanInstallExtras()); + ui->checkBoxPresetHota->setEnabled(checkCanInstallHota()); + ui->checkBoxPresetWog->setEnabled(checkCanInstallWog()); } QString FirstLaunchView::findTranslationModName() @@ -389,41 +389,30 @@ bool FirstLaunchView::checkCanInstallMod(const QString & modID) return getModView() && !getModView()->isModInstalled(modID); } -void FirstLaunchView::installTranslation() -{ - installMod(findTranslationModName()); -} - -void FirstLaunchView::installWog() -{ - installMod("wake-of-gods"); -} - -void FirstLaunchView::installHota() -{ - installMod("hota"); -} - -void FirstLaunchView::instalExtras() -{ - installMod("vcmi-extras"); -} - -void FirstLaunchView::installMod(const QString & modID) -{ - assert(0); // TODO: test - - return getModView()->doInstallMod(modID); -} - void FirstLaunchView::on_pushButtonPresetBack_clicked() { activateTabHeroesData(); } - void FirstLaunchView::on_pushButtonPresetNext_clicked() { + QStringList modsToInstall; + + if (ui->checkBoxPresetLanguage && checkCanInstallTranslation()) + modsToInstall.push_back(findTranslationModName()); + + if (ui->checkBoxPresetExtras && checkCanInstallExtras()) + modsToInstall.push_back("vcmi-extras"); + + if (ui->checkBoxPresetWog && checkCanInstallWog()) + modsToInstall.push_back("wake-of-gods"); + + if (ui->checkBoxPresetHota && checkCanInstallHota()) + modsToInstall.push_back("hota"); + exitSetup(); + + for (auto const & modName : modsToInstall) + getModView()->doInstallMod(modName); } diff --git a/launcher/firstLaunch/firstlaunch_moc.h b/launcher/firstLaunch/firstlaunch_moc.h index 2640e9a95..051bd6600 100644 --- a/launcher/firstLaunch/firstlaunch_moc.h +++ b/launcher/firstLaunch/firstlaunch_moc.h @@ -65,10 +65,6 @@ class FirstLaunchView : public QWidget bool checkCanInstallExtras(); bool checkCanInstallMod(const QString & modID); - void installTranslation(); - void installWog(); - void installHota(); - void instalExtras(); void installMod(const QString & modID); public: diff --git a/launcher/firstLaunch/firstlaunch_moc.ui b/launcher/firstLaunch/firstlaunch_moc.ui index 8809515de..23f461ce2 100644 --- a/launcher/firstLaunch/firstlaunch_moc.ui +++ b/launcher/firstLaunch/firstlaunch_moc.ui @@ -539,135 +539,7 @@ - - - - - - 100 - 0 - - - - VCMI provides support for Horn of the Abyss: fan-made Heroes III expansion, ported by VCMI team - - - true - - - - - - - - 100 - 0 - - - - VCMI provides support for playing Heroes III in resolutions other than 800x600. If you wish, you can install this support - - - true - - - - - - - - 0 - 0 - - - - Install HD support - - - Qt::ToolButtonTextOnly - - - - - - - - 0 - 0 - - - - Install In the Wake of Gods - - - Qt::ToolButtonTextOnly - - - - - - - - 0 - 0 - - - - Install localization - - - Qt::ToolButtonTextOnly - - - - - - - - 100 - 0 - - - - VCMI provides compatible version of the "In The Wake of Gods" fan-made addon - - - true - - - - - - - - 100 - 0 - - - - VCMI provides translations of Heroes III into a different languages. If you wish, you can install translation to English - - - true - - - - - - - - 0 - 0 - - - - Install Horn of the Abyss - - - Qt::ToolButtonTextOnly - - - + @@ -677,7 +549,129 @@ - Optionally, you can install additional mods either now or at any point later + Optionally, you can install additional mods either now or at any point later: + + + true + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + + 100 + 0 + + + + Install English translation of Heroes III + + + true + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + + 100 + 0 + + + + Install support for playing Heroes III in resolutions other than 800x600. + + + true + + + + + + + + 0 + 0 + + + + + + + + + + + + 100 + 0 + + + + Install compatible version of addon Horn of the Abyss: fan-made Heroes III expansion, ported by VCMI team + + + true + + + + + + + + 0 + 0 + + + + + + + + + + + + 100 + 0 + + + + Install compatible version of addon "In The Wake of Gods": fan-made Heroes III expansion true diff --git a/launcher/mainwindow_moc.cpp b/launcher/mainwindow_moc.cpp index af487b845..98c2d112e 100644 --- a/launcher/mainwindow_moc.cpp +++ b/launcher/mainwindow_moc.cpp @@ -106,18 +106,9 @@ MainWindow::MainWindow(QWidget * parent) bool setupCompleted = settings["launcher"]["setupCompleted"].Bool(); if (h3DataFound && setupCompleted) - { ui->tabListWidget->setCurrentIndex(TabRows::MODS); - } else - { - ui->startGameButton->setEnabled(false); - ui->startEditorButton->setEnabled(false); - ui->lobbyButton->setEnabled(false); - ui->settingsButton->setEnabled(false); - ui->modslistButton->setEnabled(false); - ui->tabListWidget->setCurrentIndex(TabRows::SETUP); - } + enterSetup(); ui->settingsView->isExtraResolutionsModEnabled = ui->modlistView->isExtraResolutionsModEnabled(); ui->settingsView->setDisplayList(); @@ -128,6 +119,29 @@ MainWindow::MainWindow(QWidget * parent) UpdateDialog::showUpdateDialog(false); } +void MainWindow::enterSetup() +{ + ui->startGameButton->setEnabled(false); + ui->startEditorButton->setEnabled(false); + ui->lobbyButton->setEnabled(false); + ui->settingsButton->setEnabled(false); + ui->modslistButton->setEnabled(false); + ui->tabListWidget->setCurrentIndex(TabRows::SETUP); +} + +void MainWindow::exitSetup() +{ + Settings writer = settings.write["launcher"]["setupCompleted"]; + writer->Bool() = true; + + ui->startGameButton->setEnabled(true); + ui->startEditorButton->setEnabled(true); + ui->lobbyButton->setEnabled(true); + ui->settingsButton->setEnabled(true); + ui->modslistButton->setEnabled(true); + ui->tabListWidget->setCurrentIndex(TabRows::MODS); +} + void MainWindow::changeEvent(QEvent *event) { if(event->type() == QEvent::LanguageChange) diff --git a/launcher/mainwindow_moc.h b/launcher/mainwindow_moc.h index 4c9b96d51..0c4b36402 100644 --- a/launcher/mainwindow_moc.h +++ b/launcher/mainwindow_moc.h @@ -53,6 +53,9 @@ public: void updateTranslation(); void computeSidePanelSizes(); + void enterSetup(); + void exitSetup(); + public slots: void on_startGameButton_clicked(); diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp index 89258a7dc..d123e1f56 100644 --- a/launcher/modManager/cmodlistview_moc.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -90,12 +90,14 @@ void CModListView::setupModsView() } CModListView::CModListView(QWidget * parent) - : QWidget(parent), settingsListener(settings.listen["launcher"]["repositoryURL"]), ui(new Ui::CModListView) + : QWidget(parent) + , settingsListener(settings.listen["launcher"]["repositoryURL"]) + , ui(new Ui::CModListView) + , repositoriesChanged(false) { settingsListener([&](const JsonNode &){ repositoriesChanged = true; }); ui->setupUi(this); - setupModModel(); setupFilterModel(); setupModsView(); @@ -835,7 +837,7 @@ bool CModListView::isModInstalled(const QString & modName) QString CModListView::getTranslationModName(const QString & language) { - for (auto const & modName : modModel->getModList()) + for(const auto & modName : modModel->getModList()) { auto mod = modModel->getMod(modName); diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index 325f8bde9..7d9bab60f 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -83,12 +83,13 @@ void CSettingsView::loadSettings() ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Integer()); ui->comboBoxAutoCheck->setCurrentIndex(settings["launcher"]["autoCheckRepositories"].Bool()); - // all calls to plainText will trigger textChanged() signal overwriting config. Create backup before editing widget - JsonNode urls = settings["launcher"]["repositoryURL"]; + JsonNode urls = settings["launcher"]["repositoryURL"]; + ui->plainTextEditRepos->blockSignals(true); // Do not report loading as change of data ui->plainTextEditRepos->clear(); for(auto entry : urls.Vector()) ui->plainTextEditRepos->appendPlainText(QString::fromUtf8(entry.String().c_str())); + ui->plainTextEditRepos->blockSignals(false); ui->lineEditUserDataDir->setText(pathToQString(VCMIDirs::get().userDataPath())); ui->lineEditGameDir->setText(pathToQString(VCMIDirs::get().binaryPath()));