csettingsview_moc.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. void CSettingsView::loadSettings()
  7. {
  8. int resX = settings["video"]["screenRes"]["width"].Float();
  9. int resY = settings["video"]["screenRes"]["height"].Float();
  10. int resIndex = ui->comboBoxResolution->findText(QString("%1x%2").arg(resX).arg(resY));
  11. ui->comboBoxResolution->setCurrentIndex(resIndex);
  12. ui->comboBoxFullScreen->setCurrentIndex(settings["video"]["fullscreen"].Bool());
  13. int neutralAIIndex = ui->comboBoxNeutralAI->findText(QString::fromUtf8(settings["server"]["neutralAI"].String().c_str()));
  14. int playerAIIndex = ui->comboBoxPlayerAI->findText(QString::fromUtf8(settings["server"]["playerAI"].String().c_str()));
  15. ui->comboBoxNeutralAI->setCurrentIndex(neutralAIIndex);
  16. ui->comboBoxPlayerAI->setCurrentIndex(playerAIIndex);
  17. ui->spinBoxNetworkPort->setValue(settings["server"]["port"].Float());
  18. ui->comboBoxEnableMods->setCurrentIndex(settings["launcher"]["enableInstalledMods"].Bool());
  19. // all calls to plainText will trigger textChanged() signal overwriting config. Create backup before editing widget
  20. JsonNode urls = settings["launcher"]["repositoryURL"];
  21. ui->plainTextEditRepos->clear();
  22. for (auto entry : urls.Vector())
  23. ui->plainTextEditRepos->appendPlainText(QString::fromUtf8(entry.String().c_str()));
  24. ui->lineEditUserDataDir->setText(QString::fromUtf8(VCMIDirs::get().userDataPath().c_str()));
  25. QStringList dataDirs;
  26. for (auto string : VCMIDirs::get().dataPaths())
  27. dataDirs += QString::fromUtf8(string.c_str());
  28. ui->lineEditGameDir->setText(dataDirs.join(':'));
  29. }
  30. CSettingsView::CSettingsView(QWidget *parent) :
  31. QWidget(parent),
  32. ui(new Ui::CSettingsView)
  33. {
  34. ui->setupUi(this);
  35. loadSettings();
  36. }
  37. CSettingsView::~CSettingsView()
  38. {
  39. delete ui;
  40. }
  41. void CSettingsView::on_comboBoxResolution_currentIndexChanged(const QString &arg1)
  42. {
  43. QStringList list = arg1.split("x");
  44. Settings node = settings.write["video"]["screenRes"];
  45. node["width"].Float() = list[0].toInt();
  46. node["height"].Float() = list[1].toInt();
  47. }
  48. void CSettingsView::on_comboBoxFullScreen_currentIndexChanged(int index)
  49. {
  50. Settings node = settings.write["video"]["fullscreen"];
  51. node->Bool() = index;
  52. }
  53. void CSettingsView::on_comboBoxPlayerAI_currentIndexChanged(const QString &arg1)
  54. {
  55. Settings node = settings.write["server"]["playerAI"];
  56. node->String() = arg1.toUtf8().data();
  57. }
  58. void CSettingsView::on_comboBoxNeutralAI_currentIndexChanged(const QString &arg1)
  59. {
  60. Settings node = settings.write["server"]["neutralAI"];
  61. node->String() = arg1.toUtf8().data();
  62. }
  63. void CSettingsView::on_comboBoxEnableMods_currentIndexChanged(int index)
  64. {
  65. Settings node = settings.write["launcher"]["enableInstalledMods"];
  66. node->Bool() = index;
  67. }
  68. void CSettingsView::on_spinBoxNetworkPort_valueChanged(int arg1)
  69. {
  70. Settings node = settings.write["server"]["port"];
  71. node->Float() = arg1;
  72. }
  73. void CSettingsView::on_plainTextEditRepos_textChanged()
  74. {
  75. Settings node = settings.write["launcher"]["repositoryURL"];
  76. QStringList list = ui->plainTextEditRepos->toPlainText().split('\n');
  77. node->Vector().clear();
  78. for (QString line : list)
  79. {
  80. if (line.trimmed().size() > 0)
  81. {
  82. JsonNode entry;
  83. entry.String() = line.trimmed().toUtf8().data();
  84. node->Vector().push_back(entry);
  85. }
  86. }
  87. }