csettingsview_moc.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "StdInc.h"
  2. #include "csettingsview_moc.h"
  3. #include "ui_csettingsview_moc.h"
  4. #include "../../lib/CConfigHandler.h"
  5. #include "../../lib/VCMIDirs.h"
  6. /// List of encoding which can be selected from Launcher.
  7. /// Note that it is possible to specify enconding manually in settings.json
  8. static const std::string knownEncodingsList[] = //TODO: remove hardcode
  9. {
  10. // European Windows-125X encodings
  11. "CP1250", // West European, covers mostly Slavic languages that use latin script
  12. "CP1251", // Covers languages that use cyrillic scrypt
  13. "CP1252", // Latin/East European, covers most of latin languages
  14. // Chinese encodings
  15. "GBK", // extension of GB2312, also known as CP936
  16. "GB2312" // basic set for Simplified Chinese. Separate from GBK to allow proper detection of H3 fonts
  17. };
  18. void CSettingsView::loadSettings()
  19. {
  20. int resX = settings["video"]["screenRes"]["width"].Float();
  21. int resY = settings["video"]["screenRes"]["height"].Float();
  22. int resIndex = ui->comboBoxResolution->findText(QString("%1x%2").arg(resX).arg(resY));
  23. ui->comboBoxResolution->setCurrentIndex(resIndex);
  24. ui->comboBoxFullScreen->setCurrentIndex(settings["video"]["fullscreen"].Bool());
  25. int neutralAIIndex = ui->comboBoxNeutralAI->findText(QString::fromUtf8(settings["server"]["neutralAI"].String().c_str()));
  26. int playerAIIndex = ui->comboBoxPlayerAI->findText(QString::fromUtf8(settings["server"]["playerAI"].String().c_str()));
  27. ui->comboBoxNeutralAI->setCurrentIndex(neutralAIIndex);
  28. ui->comboBoxPlayerAI->setCurrentIndex(playerAIIndex);
  29. ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Float());
  30. ui->comboBoxEnableMods->setCurrentIndex(settings["launcher"]["enableInstalledMods"].Bool());
  31. // all calls to plainText will trigger textChanged() signal overwriting config. Create backup before editing widget
  32. JsonNode urls = settings["launcher"]["repositoryURL"];
  33. ui->plainTextEditRepos->clear();
  34. for (auto entry : urls.Vector())
  35. ui->plainTextEditRepos->appendPlainText(QString::fromUtf8(entry.String().c_str()));
  36. ui->lineEditUserDataDir->setText(QString::fromUtf8(VCMIDirs::get().userDataPath().c_str()));
  37. QStringList dataDirs;
  38. for (auto string : VCMIDirs::get().dataPaths())
  39. dataDirs += QString::fromUtf8(string.c_str());
  40. ui->lineEditGameDir->setText(dataDirs.join(':'));
  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_comboBoxPlayerAI_currentIndexChanged(const QString &arg1)
  70. {
  71. Settings node = settings.write["server"]["playerAI"];
  72. node->String() = arg1.toUtf8().data();
  73. }
  74. void CSettingsView::on_comboBoxNeutralAI_currentIndexChanged(const QString &arg1)
  75. {
  76. Settings node = settings.write["server"]["neutralAI"];
  77. node->String() = arg1.toUtf8().data();
  78. }
  79. void CSettingsView::on_comboBoxEnableMods_currentIndexChanged(int index)
  80. {
  81. Settings node = settings.write["launcher"]["enableInstalledMods"];
  82. node->Bool() = index;
  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. }