configure_system.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2016 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <array>
  5. #include <chrono>
  6. #include <optional>
  7. #include <QFileDialog>
  8. #include <QGraphicsItem>
  9. #include <QMessageBox>
  10. #include "common/assert.h"
  11. #include "common/file_util.h"
  12. #include "core/core.h"
  13. #include "core/settings.h"
  14. #include "ui_configure_system.h"
  15. #include "yuzu/configuration/configure_system.h"
  16. ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) {
  17. ui->setupUi(this);
  18. connect(ui->button_regenerate_console_id, &QPushButton::clicked, this,
  19. &ConfigureSystem::RefreshConsoleID);
  20. connect(ui->rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](bool checked) {
  21. ui->rng_seed_edit->setEnabled(checked);
  22. if (!checked) {
  23. ui->rng_seed_edit->setText(QStringLiteral("00000000"));
  24. }
  25. });
  26. connect(ui->custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](bool checked) {
  27. ui->custom_rtc_edit->setEnabled(checked);
  28. if (!checked) {
  29. ui->custom_rtc_edit->setDateTime(QDateTime::currentDateTime());
  30. }
  31. });
  32. SetConfiguration();
  33. }
  34. ConfigureSystem::~ConfigureSystem() = default;
  35. void ConfigureSystem::changeEvent(QEvent* event) {
  36. if (event->type() == QEvent::LanguageChange) {
  37. RetranslateUI();
  38. }
  39. QWidget::changeEvent(event);
  40. }
  41. void ConfigureSystem::RetranslateUI() {
  42. ui->retranslateUi(this);
  43. }
  44. void ConfigureSystem::SetConfiguration() {
  45. enabled = !Core::System::GetInstance().IsPoweredOn();
  46. ui->combo_language->setCurrentIndex(Settings::values.language_index);
  47. ui->combo_region->setCurrentIndex(Settings::values.region_index);
  48. ui->combo_time_zone->setCurrentIndex(Settings::values.time_zone_index);
  49. ui->combo_sound->setCurrentIndex(Settings::values.sound_index);
  50. ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.has_value());
  51. ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.has_value());
  52. const auto rng_seed = QStringLiteral("%1")
  53. .arg(Settings::values.rng_seed.value_or(0), 8, 16, QLatin1Char{'0'})
  54. .toUpper();
  55. ui->rng_seed_edit->setText(rng_seed);
  56. ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.has_value());
  57. ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.has_value());
  58. const auto rtc_time = Settings::values.custom_rtc.value_or(
  59. std::chrono::seconds(QDateTime::currentSecsSinceEpoch()));
  60. ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count()));
  61. }
  62. void ConfigureSystem::ReadSystemSettings() {}
  63. void ConfigureSystem::ApplyConfiguration() {
  64. if (!enabled) {
  65. return;
  66. }
  67. Settings::values.language_index = ui->combo_language->currentIndex();
  68. Settings::values.region_index = ui->combo_region->currentIndex();
  69. Settings::values.time_zone_index = ui->combo_time_zone->currentIndex();
  70. Settings::values.sound_index = ui->combo_sound->currentIndex();
  71. if (ui->rng_seed_checkbox->isChecked()) {
  72. Settings::values.rng_seed = ui->rng_seed_edit->text().toULongLong(nullptr, 16);
  73. } else {
  74. Settings::values.rng_seed = std::nullopt;
  75. }
  76. if (ui->custom_rtc_checkbox->isChecked()) {
  77. Settings::values.custom_rtc =
  78. std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch());
  79. } else {
  80. Settings::values.custom_rtc = std::nullopt;
  81. }
  82. Settings::Apply();
  83. }
  84. void ConfigureSystem::RefreshConsoleID() {
  85. QMessageBox::StandardButton reply;
  86. QString warning_text = tr("This will replace your current virtual Switch with a new one. "
  87. "Your current virtual Switch will not be recoverable. "
  88. "This might have unexpected effects in games. This might fail, "
  89. "if you use an outdated config savegame. Continue?");
  90. reply = QMessageBox::critical(this, tr("Warning"), warning_text,
  91. QMessageBox::No | QMessageBox::Yes);
  92. if (reply == QMessageBox::No) {
  93. return;
  94. }
  95. u64 console_id{};
  96. ui->label_console_id->setText(
  97. tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper()));
  98. }