csettingsview_moc.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #include "StdInc.h"
  2. #include "csettingsview_moc.h"
  3. #include "ui_csettingsview_moc.h"
  4. #include <QFileInfo>
  5. #include "../../lib/CConfigHandler.h"
  6. #include "../../lib/VCMIDirs.h"
  7. /// List of encoding which can be selected from Launcher.
  8. /// Note that it is possible to specify enconding manually in settings.json
  9. static const std::string knownEncodingsList[] = //TODO: remove hardcode
  10. {
  11. // European Windows-125X encodings
  12. "CP1250", // West European, covers mostly Slavic languages that use latin script
  13. "CP1251", // Covers languages that use cyrillic scrypt
  14. "CP1252", // Latin/East European, covers most of latin languages
  15. // Chinese encodings
  16. "GBK", // extension of GB2312, also known as CP936
  17. "GB2312" // basic set for Simplified Chinese. Separate from GBK to allow proper detection of H3 fonts
  18. };
  19. void CSettingsView::loadSettings()
  20. {
  21. int resX = settings["video"]["screenRes"]["width"].Float();
  22. int resY = settings["video"]["screenRes"]["height"].Float();
  23. int resIndex = ui->comboBoxResolution->findText(QString("%1x%2").arg(resX).arg(resY));
  24. ui->comboBoxResolution->setCurrentIndex(resIndex);
  25. ui->comboBoxFullScreen->setCurrentIndex(settings["video"]["fullscreen"].Bool());
  26. ui->comboBoxShowIntro->setCurrentIndex(settings["video"]["showIntro"].Bool());
  27. int neutralAIIndex = ui->comboBoxNeutralAI->findText(QString::fromUtf8(settings["server"]["neutralAI"].String().c_str()));
  28. int playerAIIndex = ui->comboBoxPlayerAI->findText(QString::fromUtf8(settings["server"]["playerAI"].String().c_str()));
  29. ui->comboBoxNeutralAI->setCurrentIndex(neutralAIIndex);
  30. ui->comboBoxPlayerAI->setCurrentIndex(playerAIIndex);
  31. ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Float());
  32. ui->comboBoxAutoCheck->setCurrentIndex(settings["launcher"]["autoCheckRepositories"].Bool());
  33. // all calls to plainText will trigger textChanged() signal overwriting config. Create backup before editing widget
  34. JsonNode urls = settings["launcher"]["repositoryURL"];
  35. ui->plainTextEditRepos->clear();
  36. for (auto entry : urls.Vector())
  37. ui->plainTextEditRepos->appendPlainText(QString::fromUtf8(entry.String().c_str()));
  38. ui->lineEditUserDataDir->setText(pathToQString(VCMIDirs::get().userDataPath()));
  39. ui->lineEditGameDir->setText(pathToQString(VCMIDirs::get().binaryPath()));
  40. ui->lineEditTempDir->setText(pathToQString(VCMIDirs::get().userCachePath()));
  41. std::string encoding = settings["general"]["encoding"].String();
  42. size_t encodingIndex = boost::range::find(knownEncodingsList, encoding) - knownEncodingsList;
  43. if (encodingIndex < ui->comboBoxEncoding->count())
  44. ui->comboBoxEncoding->setCurrentIndex(encodingIndex);
  45. }
  46. CSettingsView::CSettingsView(QWidget *parent) :
  47. QWidget(parent),
  48. ui(new Ui::CSettingsView)
  49. {
  50. ui->setupUi(this);
  51. loadSettings();
  52. }
  53. CSettingsView::~CSettingsView()
  54. {
  55. delete ui;
  56. }
  57. void CSettingsView::on_comboBoxResolution_currentIndexChanged(const QString &arg1)
  58. {
  59. QStringList list = arg1.split("x");
  60. Settings node = settings.write["video"]["screenRes"];
  61. node["width"].Float() = list[0].toInt();
  62. node["height"].Float() = list[1].toInt();
  63. }
  64. void CSettingsView::on_comboBoxFullScreen_currentIndexChanged(int index)
  65. {
  66. Settings node = settings.write["video"]["fullscreen"];
  67. node->Bool() = index;
  68. }
  69. void CSettingsView::on_comboBoxAutoCheck_currentIndexChanged(int index)
  70. {
  71. Settings node = settings.write["launcher"]["autoCheckRepositories"];
  72. node->Bool() = index;
  73. }
  74. void CSettingsView::on_comboBoxPlayerAI_currentIndexChanged(const QString &arg1)
  75. {
  76. Settings node = settings.write["server"]["playerAI"];
  77. node->String() = arg1.toUtf8().data();
  78. }
  79. void CSettingsView::on_comboBoxNeutralAI_currentIndexChanged(const QString &arg1)
  80. {
  81. Settings node = settings.write["server"]["neutralAI"];
  82. node->String() = arg1.toUtf8().data();
  83. }
  84. void CSettingsView::on_spinBoxNetworkPort_valueChanged(int arg1)
  85. {
  86. Settings node = settings.write["server"]["port"];
  87. node->Float() = arg1;
  88. }
  89. void CSettingsView::on_plainTextEditRepos_textChanged()
  90. {
  91. Settings node = settings.write["launcher"]["repositoryURL"];
  92. QStringList list = ui->plainTextEditRepos->toPlainText().split('\n');
  93. node->Vector().clear();
  94. for (QString line : list)
  95. {
  96. if (line.trimmed().size() > 0)
  97. {
  98. JsonNode entry;
  99. entry.String() = line.trimmed().toUtf8().data();
  100. node->Vector().push_back(entry);
  101. }
  102. }
  103. }
  104. void CSettingsView::on_comboBoxEncoding_currentIndexChanged(int index)
  105. {
  106. Settings node = settings.write["general"]["encoding"];
  107. node->String() = knownEncodingsList[index];
  108. }
  109. void CSettingsView::on_openTempDir_clicked()
  110. {
  111. QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditTempDir->text()).absoluteFilePath()));
  112. }
  113. void CSettingsView::on_openUserDataDir_clicked()
  114. {
  115. QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditUserDataDir->text()).absoluteFilePath()));
  116. }
  117. void CSettingsView::on_openGameDataDir_clicked()
  118. {
  119. QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(ui->lineEditGameDir->text()).absoluteFilePath()));
  120. }
  121. void CSettingsView::on_comboBoxShowIntro_currentIndexChanged(int index)
  122. {
  123. Settings node = settings.write["video"]["showIntro"];
  124. node->Bool() = index;
  125. }
  126. void CSettingsView::on_changeGameDataDir_clicked()
  127. {
  128. }