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
|
|
|
|
2014-08-04 14:03:57 +03:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
2013-09-02 20:26:52 +03:00
|
|
|
#include "../../lib/CConfigHandler.h"
|
|
|
|
#include "../../lib/VCMIDirs.h"
|
2013-08-22 17:22:49 +03:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
"GB2312" // basic set for Simplified Chinese. Separate from GBK to allow proper detection of H3 fonts
|
|
|
|
};
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CSettingsView::loadSettings()
|
|
|
|
{
|
|
|
|
int resX = settings["video"]["screenRes"]["width"].Float();
|
|
|
|
int resY = settings["video"]["screenRes"]["height"].Float();
|
|
|
|
|
|
|
|
int resIndex = ui->comboBoxResolution->findText(QString("%1x%2").arg(resX).arg(resY));
|
|
|
|
|
|
|
|
ui->comboBoxResolution->setCurrentIndex(resIndex);
|
|
|
|
ui->comboBoxFullScreen->setCurrentIndex(settings["video"]["fullscreen"].Bool());
|
2014-08-04 14:03:57 +03:00
|
|
|
ui->comboBoxShowIntro->setCurrentIndex(settings["video"]["showIntro"].Bool());
|
2013-08-22 17:22:49 +03:00
|
|
|
|
|
|
|
int neutralAIIndex = ui->comboBoxNeutralAI->findText(QString::fromUtf8(settings["server"]["neutralAI"].String().c_str()));
|
|
|
|
int playerAIIndex = ui->comboBoxPlayerAI->findText(QString::fromUtf8(settings["server"]["playerAI"].String().c_str()));
|
|
|
|
|
|
|
|
ui->comboBoxNeutralAI->setCurrentIndex(neutralAIIndex);
|
|
|
|
ui->comboBoxPlayerAI->setCurrentIndex(playerAIIndex);
|
|
|
|
|
|
|
|
ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Float());
|
|
|
|
|
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();
|
|
|
|
for (auto entry : urls.Vector())
|
|
|
|
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()));
|
|
|
|
ui->lineEditTempDir->setText(pathToQString(VCMIDirs::get().userCachePath()));
|
2013-10-26 00:45:14 +03:00
|
|
|
|
|
|
|
std::string encoding = settings["general"]["encoding"].String();
|
|
|
|
size_t encodingIndex = boost::range::find(knownEncodingsList, encoding) - knownEncodingsList;
|
|
|
|
if (encodingIndex < ui->comboBoxEncoding->count())
|
|
|
|
ui->comboBoxEncoding->setCurrentIndex(encodingIndex);
|
2013-08-22 17:22:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CSettingsView::CSettingsView(QWidget *parent) :
|
|
|
|
QWidget(parent),
|
|
|
|
ui(new Ui::CSettingsView)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
loadSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
CSettingsView::~CSettingsView()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_comboBoxResolution_currentIndexChanged(const QString &arg1)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-11-03 17:47:37 +02:00
|
|
|
void CSettingsView::on_comboBoxAutoCheck_currentIndexChanged(int index)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["launcher"]["autoCheckRepositories"];
|
|
|
|
node->Bool() = index;
|
|
|
|
}
|
|
|
|
|
2013-08-22 17:22:49 +03:00
|
|
|
void CSettingsView::on_comboBoxPlayerAI_currentIndexChanged(const QString &arg1)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["server"]["playerAI"];
|
|
|
|
node->String() = arg1.toUtf8().data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSettingsView::on_comboBoxNeutralAI_currentIndexChanged(const QString &arg1)
|
|
|
|
{
|
|
|
|
Settings node = settings.write["server"]["neutralAI"];
|
|
|
|
node->String() = arg1.toUtf8().data();
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
for (QString line : list)
|
|
|
|
{
|
|
|
|
if (line.trimmed().size() > 0)
|
|
|
|
{
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|