2017-07-13 10:26:03 +02:00
|
|
|
/*
|
|
|
|
* csettingsview_moc.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
2013-08-22 17:22:49 +03:00
|
|
|
#include "StdInc.h"
|
2013-08-24 23:11:51 +03:00
|
|
|
#include "csettingsview_moc.h"
|
|
|
|
#include "ui_csettingsview_moc.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2022-09-26 15:58:27 +02:00
|
|
|
#include "../jsonutils.h"
|
|
|
|
#include "../launcherdirs.h"
|
2022-09-04 18:32:48 +02:00
|
|
|
#include "../updatedialog_moc.h"
|
|
|
|
|
2014-08-04 14:03:57 +03:00
|
|
|
#include <QFileInfo>
|
2022-05-28 15:32:20 +02:00
|
|
|
#include <QGuiApplication>
|
2014-08-04 14:03:57 +03:00
|
|
|
|
2013-09-02 20:26:52 +03:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/VCMIDirs.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2022-09-26 15:37:31 +02:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
QString resolutionToString(const QSize & resolution)
|
|
|
|
{
|
|
|
|
return QString{"%1x%2"}.arg(resolution.width()).arg(resolution.height());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 00:45:14 +03:00
|
|
|
/// List of encoding which can be selected from Launcher.
|
|
|
|
/// Note that it is possible to specify enconding manually in settings.json
|
|
|
|
static const std::string knownEncodingsList[] = //TODO: remove hardcode
|
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
// European Windows-125X encodings
|
|
|
|
"CP1250", // West European, covers mostly Slavic languages that use latin script
|
|
|
|
"CP1251", // Covers languages that use cyrillic scrypt
|
|
|
|
"CP1252", // Latin/East European, covers most of latin languages
|
|
|
|
// Chinese encodings
|
|
|
|
"GBK", // extension of GB2312, also known as CP936
|
2020-03-19 09:11:55 +02:00
|
|
|
"GB2312", // basic set for Simplified Chinese. Separate from GBK to allow proper detection of H3 fonts
|
|
|
|
// Korean encodings
|
|
|
|
"CP949" // extension of EUC-KR.
|
2013-10-26 00:45:14 +03:00
|
|
|
};
|
|
|
|
|
2017-08-24 03:52:02 +02:00
|
|
|
void CSettingsView::setDisplayList()
|
2016-08-30 20:54:37 +02:00
|
|
|
{
|
2017-08-24 03:52:02 +02:00
|
|
|
QStringList list;
|
2022-05-28 15:32:20 +02:00
|
|
|
|
|
|
|
for (const auto screen : QGuiApplication::screens())
|
2022-09-26 15:37:31 +02:00
|
|
|
list << QString{"%1 - %2"}.arg(screen->name(), resolutionToString(screen->size()));
|
2017-08-24 03:52:02 +02:00
|
|
|
|
|
|
|
if(list.count() < 2)
|
|
|
|
{
|
|
|
|
ui->comboBoxDisplayIndex->hide();
|
|
|
|
ui->labelDisplayIndex->hide();
|
2022-09-26 15:58:27 +02:00
|
|
|
fillValidResolutionsForScreen(0);
|
2017-08-24 03:52:02 +02:00
|
|
|
}
|
2016-08-30 20:54:37 +02:00
|
|
|
else
|
2017-08-24 03:52:02 +02:00
|
|
|
{
|
|
|
|
int displayIndex = settings["video"]["displayIndex"].Integer();
|
|
|
|
ui->comboBoxDisplayIndex->addItems(list);
|
2022-09-26 15:58:27 +02:00
|
|
|
// calls fillValidResolutions() in slot
|
2017-08-24 03:52:02 +02:00
|
|
|
ui->comboBoxDisplayIndex->setCurrentIndex(displayIndex);
|
|
|
|
}
|
2016-08-30 20:54:37 +02:00
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CSettingsView::loadSettings()
|
|
|
|
{
|
2014-08-04 14:03:57 +03:00
|
|
|
ui->comboBoxShowIntro->setCurrentIndex(settings["video"]["showIntro"].Bool());
|
2021-04-21 08:55:13 +02:00
|
|
|
|
|
|
|
#ifdef Q_OS_IOS
|
|
|
|
ui->comboBoxFullScreen->setCurrentIndex(true);
|
|
|
|
ui->checkBoxFullScreen->setChecked(false);
|
|
|
|
for (auto widget : std::initializer_list<QWidget *>{ui->comboBoxFullScreen, ui->checkBoxFullScreen})
|
|
|
|
widget->setDisabled(true);
|
|
|
|
#else
|
|
|
|
ui->comboBoxFullScreen->setCurrentIndex(settings["video"]["fullscreen"].Bool());
|
2017-07-08 18:01:58 +02:00
|
|
|
ui->checkBoxFullScreen->setChecked(settings["video"]["realFullscreen"].Bool());
|
2021-04-21 08:55:13 +02:00
|
|
|
#endif
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2022-09-26 15:37:31 +02:00
|
|
|
ui->comboBoxFriendlyAI->setCurrentText(QString::fromStdString(settings["server"]["friendlyAI"].String()));
|
|
|
|
ui->comboBoxNeutralAI->setCurrentText(QString::fromStdString(settings["server"]["neutralAI"].String()));
|
|
|
|
ui->comboBoxEnemyAI->setCurrentText(QString::fromStdString(settings["server"]["enemyAI"].String()));
|
|
|
|
ui->comboBoxPlayerAI->setCurrentText(QString::fromStdString(settings["server"]["playerAI"].String()));
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2017-06-04 07:49:23 +02:00
|
|
|
ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Integer());
|
2013-08-22 17:22:49 +03:00
|
|
|
|
2014-11-03 17:47:37 +02:00
|
|
|
ui->comboBoxAutoCheck->setCurrentIndex(settings["launcher"]["autoCheckRepositories"].Bool());
|
2013-08-22 17:22:49 +03:00
|
|
|
// all calls to plainText will trigger textChanged() signal overwriting config. Create backup before editing widget
|
|
|
|
JsonNode urls = settings["launcher"]["repositoryURL"];
|
|
|
|
|
|
|
|
ui->plainTextEditRepos->clear();
|
2018-04-13 07:34:58 +02:00
|
|
|
for(auto entry : urls.Vector())
|
2013-08-22 17:22:49 +03:00
|
|
|
ui->plainTextEditRepos->appendPlainText(QString::fromUtf8(entry.String().c_str()));
|
|
|
|
|
2014-08-21 23:26:28 +03:00
|
|
|
ui->lineEditUserDataDir->setText(pathToQString(VCMIDirs::get().userDataPath()));
|
|
|
|
ui->lineEditGameDir->setText(pathToQString(VCMIDirs::get().binaryPath()));
|
2022-10-09 16:37:59 +02:00
|
|
|
ui->lineEditTempDir->setText(pathToQString(VCMIDirs::get().userLogsPath()));
|
2013-10-26 00:45:14 +03:00
|
|
|
|
|
|
|
std::string encoding = settings["general"]["encoding"].String();
|
|
|
|
size_t encodingIndex = boost::range::find(knownEncodingsList, encoding) - knownEncodingsList;
|
2018-04-13 07:34:58 +02:00
|
|
|
if(encodingIndex < ui->comboBoxEncoding->count())
|
2020-10-01 10:38:06 +02:00
|
|
|
ui->comboBoxEncoding->setCurrentIndex((int)encodingIndex);
|
2018-04-03 03:37:09 +02:00
|
|
|
ui->comboBoxAutoSave->setCurrentIndex(settings["general"]["saveFrequency"].Integer() > 0 ? 1 : 0);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
2022-09-27 10:51:49 +02:00
|
|
|
void CSettingsView::fillValidResolutions(bool isExtraResolutionsModEnabled)
|
|
|
|
{
|
|
|
|
this->isExtraResolutionsModEnabled = isExtraResolutionsModEnabled;
|
|
|
|
fillValidResolutionsForScreen(ui->comboBoxDisplayIndex->isVisible() ? ui->comboBoxDisplayIndex->currentIndex() : 0);
|
|
|
|
}
|
|
|
|
|
2022-09-26 15:58:27 +02:00
|
|
|
void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
|
|
|
|
{
|
|
|
|
ui->comboBoxResolution->blockSignals(true); // avoid saving wrong resolution after adding first item from the list
|
|
|
|
ui->comboBoxResolution->clear();
|
|
|
|
|
|
|
|
// TODO: read available resolutions from all mods
|
2022-09-27 10:51:49 +02:00
|
|
|
QVariantList resolutions;
|
|
|
|
if(isExtraResolutionsModEnabled)
|
|
|
|
{
|
2022-09-27 10:55:03 +02:00
|
|
|
const auto extrasResolutionsPath = settings["launcher"]["extraResolutionsModPath"].String().c_str();
|
2022-09-27 10:51:49 +02:00
|
|
|
const auto extrasResolutionsJson = JsonUtils::JsonFromFile(CLauncherDirs::get().modsPath() + extrasResolutionsPath);
|
|
|
|
resolutions = extrasResolutionsJson.toMap().value(QLatin1String{"GUISettings"}).toList();
|
|
|
|
}
|
2022-09-26 15:58:27 +02:00
|
|
|
if(resolutions.isEmpty())
|
|
|
|
{
|
|
|
|
ui->comboBoxResolution->blockSignals(false);
|
|
|
|
ui->comboBoxResolution->addItem(resolutionToString({800, 600}));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto screens = qGuiApp->screens();
|
|
|
|
const auto currentScreen = screenIndex < screens.size() ? screens[screenIndex] : qGuiApp->primaryScreen();
|
|
|
|
const auto screenSize = currentScreen->size();
|
|
|
|
for(const auto & entry : resolutions)
|
|
|
|
{
|
|
|
|
const auto resolutionMap = entry.toMap().value(QLatin1String{"resolution"}).toMap();
|
|
|
|
if(resolutionMap.isEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const auto widthValue = resolutionMap[QLatin1String{"x"}];
|
|
|
|
const auto heightValue = resolutionMap[QLatin1String{"y"}];
|
|
|
|
if(!widthValue.isValid() || !heightValue.isValid())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const QSize resolution{widthValue.toInt(), heightValue.toInt()};
|
2022-09-26 15:59:59 +02:00
|
|
|
#ifndef VCMI_IOS
|
2022-09-26 15:58:27 +02:00
|
|
|
if(screenSize.width() < resolution.width() || screenSize.height() < resolution.height())
|
|
|
|
continue;
|
2022-09-26 15:59:59 +02:00
|
|
|
#endif
|
2022-09-26 15:58:27 +02:00
|
|
|
ui->comboBoxResolution->addItem(resolutionToString(resolution));
|
|
|
|
}
|
|
|
|
|
|
|
|
int resX = settings["video"]["screenRes"]["width"].Integer();
|
|
|
|
int resY = settings["video"]["screenRes"]["height"].Integer();
|
|
|
|
int resIndex = ui->comboBoxResolution->findText(resolutionToString({resX, resY}));
|
|
|
|
ui->comboBoxResolution->setCurrentIndex(resIndex);
|
|
|
|
|
|
|
|
ui->comboBoxResolution->blockSignals(false);
|
|
|
|
|
|
|
|
// if selected resolution no longer exists, force update value to the first resolution
|
|
|
|
if(resIndex == -1)
|
|
|
|
ui->comboBoxResolution->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
CSettingsView::CSettingsView(QWidget * parent)
|
|
|
|
: QWidget(parent), ui(new Ui::CSettingsView)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2022-09-30 10:27:03 +02:00
|
|
|
ui->labelBuildVersion->setText(QString::fromStdString(GameConstants::VCMI_VERSION));
|
2013-08-22 17:22:49 +03:00
|
|
|
loadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSettingsView::~CSettingsView()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:01:58 +02:00
|
|
|
|
2022-09-26 15:39:10 +02:00
|
|
|
void CSettingsView::on_comboBoxResolution_currentTextChanged(const QString & arg1)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
QStringList list = arg1.split("x");
|
|
|
|
|
|
|
|
Settings node = settings.write["video"]["screenRes"];
|
|
|
|
node["width"].Float() = list[0].toInt();
|
|
|
|
node["height"].Float() = list[1].toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_comboBoxFullScreen_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["video"]["fullscreen"];
|
|
|
|
node->Bool() = index;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:01:58 +02:00
|
|
|
void CSettingsView::on_checkBoxFullScreen_stateChanged(int state)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["video"]["realFullscreen"];
|
|
|
|
node->Bool() = state;
|
|
|
|
}
|
|
|
|
|
2014-11-03 17:47:37 +02:00
|
|
|
void CSettingsView::on_comboBoxAutoCheck_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["launcher"]["autoCheckRepositories"];
|
|
|
|
node->Bool() = index;
|
|
|
|
}
|
|
|
|
|
2016-08-30 20:54:37 +02:00
|
|
|
void CSettingsView::on_comboBoxDisplayIndex_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["video"];
|
|
|
|
node["displayIndex"].Float() = index;
|
2022-09-26 15:58:27 +02:00
|
|
|
|
|
|
|
fillValidResolutionsForScreen(index);
|
2016-08-30 20:54:37 +02:00
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CSettingsView::on_comboBoxPlayerAI_currentIndexChanged(const QString & arg1)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
Settings node = settings.write["server"]["playerAI"];
|
|
|
|
node->String() = arg1.toUtf8().data();
|
|
|
|
}
|
|
|
|
|
2017-01-17 13:17:37 +02:00
|
|
|
void CSettingsView::on_comboBoxFriendlyAI_currentIndexChanged(const QString & arg1)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["server"]["friendlyAI"];
|
|
|
|
node->String() = arg1.toUtf8().data();
|
|
|
|
}
|
|
|
|
|
2018-04-13 07:34:58 +02:00
|
|
|
void CSettingsView::on_comboBoxNeutralAI_currentIndexChanged(const QString & arg1)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
Settings node = settings.write["server"]["neutralAI"];
|
|
|
|
node->String() = arg1.toUtf8().data();
|
|
|
|
}
|
|
|
|
|
2017-01-17 13:17:37 +02:00
|
|
|
void CSettingsView::on_comboBoxEnemyAI_currentIndexChanged(const QString & arg1)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["server"]["enemyAI"];
|
|
|
|
node->String() = arg1.toUtf8().data();
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CSettingsView::on_spinBoxNetworkPort_valueChanged(int arg1)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["server"]["port"];
|
|
|
|
node->Float() = arg1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_plainTextEditRepos_textChanged()
|
|
|
|
{
|
|
|
|
Settings node = settings.write["launcher"]["repositoryURL"];
|
|
|
|
|
|
|
|
QStringList list = ui->plainTextEditRepos->toPlainText().split('\n');
|
|
|
|
|
|
|
|
node->Vector().clear();
|
2018-04-13 07:34:58 +02:00
|
|
|
for(QString line : list)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
2018-04-13 07:34:58 +02:00
|
|
|
if(line.trimmed().size() > 0)
|
2013-08-22 17:22:49 +03:00
|
|
|
{
|
|
|
|
JsonNode entry;
|
|
|
|
entry.String() = line.trimmed().toUtf8().data();
|
|
|
|
node->Vector().push_back(entry);
|
|
|
|
}
|
|
|
|
}
|
2013-09-21 21:29:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_comboBoxEncoding_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["general"]["encoding"];
|
2013-10-26 00:45:14 +03:00
|
|
|
node->String() = knownEncodingsList[index];
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
2014-08-04 14:03:57 +03:00
|
|
|
|
|
|
|
void CSettingsView::on_openTempDir_clicked()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditTempDir->text()).absoluteFilePath()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_openUserDataDir_clicked()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditUserDataDir->text()).absoluteFilePath()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_openGameDataDir_clicked()
|
|
|
|
{
|
|
|
|
QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditGameDir->text()).absoluteFilePath()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_comboBoxShowIntro_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["video"]["showIntro"];
|
|
|
|
node->Bool() = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_changeGameDataDir_clicked()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2018-04-03 03:37:09 +02:00
|
|
|
|
|
|
|
void CSettingsView::on_comboBoxAutoSave_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["general"]["saveFrequency"];
|
|
|
|
node->Integer() = index;
|
|
|
|
}
|
2022-09-04 18:32:48 +02:00
|
|
|
|
|
|
|
void CSettingsView::on_updatesButton_clicked()
|
|
|
|
{
|
|
|
|
UpdateDialog::showUpdateDialog(true);
|
|
|
|
}
|
|
|
|
|