diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 88a613040..ecd606f43 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -665,7 +665,6 @@ Application::Application(int& argc, char** argv) : QApplication(argc, argv) m_settings->registerSetting("AutomaticJavaSwitch", defaultEnableAutoJava); m_settings->registerSetting("AutomaticJavaDownload", defaultEnableAutoJava); m_settings->registerSetting("UserAskedAboutAutomaticJavaDownload", false); - m_settings->registerSetting("AdvancedJavaMemoryControl", false); // Legacy settings m_settings->registerSetting("OnlineFixes", false); diff --git a/launcher/ui/pages/global/JavaPage.cpp b/launcher/ui/pages/global/JavaPage.cpp index b99d0c63e..6a44c9290 100644 --- a/launcher/ui/pages/global/JavaPage.cpp +++ b/launcher/ui/pages/global/JavaPage.cpp @@ -62,7 +62,7 @@ JavaPage::JavaPage(QWidget* parent) : QWidget(parent), ui(new Ui::JavaPage) { ui->setupUi(this); - + if (BuildConfig.JAVA_DOWNLOADER_ENABLED) { ui->managedJavaList->initialize(new JavaInstallList(this, true)); ui->managedJavaList->setResizeOn(2); diff --git a/launcher/ui/widgets/JavaSettingsWidget.cpp b/launcher/ui/widgets/JavaSettingsWidget.cpp index 200d81db8..bd48f3faa 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.cpp +++ b/launcher/ui/widgets/JavaSettingsWidget.cpp @@ -53,11 +53,6 @@ #include "ui_JavaSettingsWidget.h" -static QString formatGiBLabel(int value) -{ - return QObject::tr("%1 GiB").arg(value / 1024.0, 0, 'f', 1); -} - JavaSettingsWidget::JavaSettingsWidget(InstancePtr instance, QWidget* parent) : QWidget(parent), m_instance(std::move(instance)), m_ui(new Ui::JavaSettingsWidget) { @@ -106,50 +101,11 @@ JavaSettingsWidget::JavaSettingsWidget(InstancePtr instance, QWidget* parent) connect(m_ui->javaDetectBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaAutodetect); connect(m_ui->javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaBrowse); - connect(m_ui->minMemSpinBox, QOverload::of(&QSpinBox::valueChanged), m_ui->minMemSlider, [this](int value) { - m_ui->minMemSlider->blockSignals(true); - m_ui->minMemSlider->setValue(value); - m_ui->minMemSlider->blockSignals(false); - }); - connect(m_ui->maxMemSpinBox, QOverload::of(&QSpinBox::valueChanged), m_ui->maxMemSlider, [this](int value) { - m_ui->maxMemSlider->blockSignals(true); - m_ui->maxMemSlider->setValue(value); - m_ui->maxMemSlider->blockSignals(false); - }); - - connect(m_ui->minMemSlider, &QAbstractSlider::valueChanged, m_ui->minMemSpinBox, QOverload::of(&QSpinBox::setValue)); - connect(m_ui->maxMemSlider, &QAbstractSlider::valueChanged, m_ui->maxMemSpinBox, QOverload::of(&QSpinBox::setValue)); - - connect(m_ui->minMemSpinBox, &QAbstractSpinBox::editingFinished, this, &JavaSettingsWidget::finishAdjustingMinMemory); - connect(m_ui->maxMemSpinBox, &QAbstractSpinBox::editingFinished, this, &JavaSettingsWidget::finishAdjustingMaxMemory); - connect(m_ui->minMemSlider, &QAbstractSlider::valueChanged, this, &JavaSettingsWidget::finishAdjustingMinMemory); - connect(m_ui->maxMemSlider, &QAbstractSlider::valueChanged, this, &JavaSettingsWidget::finishAdjustingMaxMemory); - - connect(m_ui->maxMemSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::onMemoryChange); - connect(m_ui->minMemSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::onMemoryChange); - - int maxSystemMemory = (Sys::getSystemRam() / Sys::mebibyte) - 1; - m_ui->minMemSlider->setMaximum(maxSystemMemory - 1); - m_ui->maxMemSlider->setMaximum(maxSystemMemory - 1); - m_ui->minMemMaxValueHint->setText(formatGiBLabel(maxSystemMemory - 1)); - m_ui->maxMemMaxValueHint->setText(formatGiBLabel(maxSystemMemory - 1)); - - SettingsObjectPtr settings = APPLICATION->settings(); - - enableAdvancedMemoryControl(settings->get("AdvancedJavaMemoryControl").toBool()); - - connect(m_ui->memorySimpleButton, &QPushButton::clicked, this, [this, settings] () { - enableAdvancedMemoryControl(false); - settings->set("AdvancedJavaMemoryControl", false); - }); - - connect(m_ui->memoryAdvancedButton, &QPushButton::clicked, this, [this, settings] () { - enableAdvancedMemoryControl(true); - settings->set("AdvancedJavaMemoryControl", true); - }); + connect(m_ui->maxMemSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::updateThresholds); + connect(m_ui->minMemSpinBox, QOverload::of(&QSpinBox::valueChanged), this, &JavaSettingsWidget::updateThresholds); loadSettings(); - onMemoryChange(); + updateThresholds(); } JavaSettingsWidget::~JavaSettingsWidget() @@ -327,43 +283,23 @@ void JavaSettingsWidget::onJavaAutodetect() } } } - -void JavaSettingsWidget::onMemoryChange() +void JavaSettingsWidget::updateThresholds() { auto sysMiB = Sys::getSystemRam() / Sys::mebibyte; unsigned int maxMem = m_ui->maxMemSpinBox->value(); + unsigned int minMem = m_ui->minMemSpinBox->value(); + + const QString warningColour(QStringLiteral("%1")); if (maxMem >= sysMiB) { m_ui->labelMaxMemNotice->setText(QString("%1").arg(tr("Your maximum memory allocation exceeds your system memory capacity."))); m_ui->labelMaxMemNotice->show(); } else if (maxMem > (sysMiB * 0.9)) { - // TODO: where is this colour from - m_ui->labelMaxMemNotice->setText(QString("%1") - .arg(tr("Your maximum memory allocation is close to your system memory capacity."))); + m_ui->labelMaxMemNotice->setText(warningColour.arg(tr("Your maximum memory allocation is close to your system memory capacity."))); m_ui->labelMaxMemNotice->show(); + } else if (maxMem < minMem) { + m_ui->labelMaxMemNotice->setText(warningColour.arg(tr("Your maximum memory allocation is below the minimum memory allocation."))) } else { m_ui->labelMaxMemNotice->hide(); } - - m_ui->minMemGBLabel->setText(formatGiBLabel(m_ui->minMemSlider->value())); - m_ui->maxMemGBLabel->setText(formatGiBLabel(m_ui->maxMemSlider->value())); -} - -void JavaSettingsWidget::finishAdjustingMinMemory() -{ - if (m_ui->minMemSpinBox->value() > m_ui->maxMemSpinBox->value()) - m_ui->maxMemSpinBox->setValue(m_ui->minMemSpinBox->value()); -} - -void JavaSettingsWidget::finishAdjustingMaxMemory() -{ - if (m_ui->maxMemSpinBox->value() < m_ui->minMemSpinBox->value()) - m_ui->minMemSpinBox->setValue(m_ui->maxMemSpinBox->value()); -} - -void JavaSettingsWidget::enableAdvancedMemoryControl(bool enabled) { - m_ui->memorySimpleButton->setChecked(!enabled); - m_ui->memoryAdvancedButton->setChecked(enabled); - m_ui->memorySimple->setVisible(!enabled); - m_ui->memoryAdvanced->setVisible(enabled); } diff --git a/launcher/ui/widgets/JavaSettingsWidget.h b/launcher/ui/widgets/JavaSettingsWidget.h index ed38d63f8..85266bc2b 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.h +++ b/launcher/ui/widgets/JavaSettingsWidget.h @@ -59,13 +59,10 @@ class JavaSettingsWidget : public QWidget { void onJavaBrowse(); void onJavaAutodetect(); void onJavaTest(); - void onMemoryChange(); - void finishAdjustingMinMemory(); - void finishAdjustingMaxMemory(); - void enableAdvancedMemoryControl(bool enabled); + void updateThresholds(); private: InstancePtr m_instance; Ui::JavaSettingsWidget* m_ui; unique_qobject_ptr m_checker; -}; +}; \ No newline at end of file diff --git a/launcher/ui/widgets/JavaSettingsWidget.ui b/launcher/ui/widgets/JavaSettingsWidget.ui index 0e44980bf..5cc894b8e 100644 --- a/launcher/ui/widgets/JavaSettingsWidget.ui +++ b/launcher/ui/widgets/JavaSettingsWidget.ui @@ -165,420 +165,123 @@ - - - - - Simple - - - true - - - false - - - - - - - Advanced - - - true - - - false - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - - - M&inimum Memory Usage - - - minMemSpinBox - - - - - - - 0 GiB - - - - - - - 8 - - - 8192 - - - 512 - - - 512 - - - true - - - Qt::Horizontal - - - QSlider::TicksBelow - - - 1024 - - - - - - - - - false - - - 0 GiB - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - 8 GiB - - - - - - - - - M&aximum Memory Usage - - - maxMemSpinBox - - - - - - - 0 GiB - - - - - - - 8 - - - 8192 - - - 512 - - - 512 - - - Qt::Horizontal - - - QSlider::TicksBelow - - - 1024 - - - - - - - - - false - - - 0 GiB - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - 8 GiB - - - - - - + + + M&inimum Memory Usage (-Xms) + + + minMemSpinBox + - - - - - - Minimum Memory Allocation - - - - - - - 0 - - - - - -Xm&s= - - - minMemSpinBox - - - - - - - - 0 - 0 - - - - The amount of memory Minecraft is started with. - - - M - - - 8 - - - 1048576 - - - 128 - - - 256 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Maximum Memory Allocation - - - - - - - 0 - - - - - -Xm&x= - - - maxMemSpinBox - - - - - - - - 0 - 0 - - - - The maximum amount of memory Minecraft is allowed to use. - - - M - - - 8 - - - 1048576 - - - 128 - - - 1024 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - PermGen Size - - - - - - - 0 - - - - - -XX:&PermSize= - - - permGenSpinBox - - - - - - - - 0 - 0 - - - - The amount of memory available to store loaded Java classes. - - - M - - - 4 - - - 999999999 - - - 8 - - - 64 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - + + + + 0 + 0 + + + + The amount of memory Minecraft is started with. + + + MiB + + + 8 + + + 1048576 + + + 128 + + + 256 + + + + + + + Ma&ximum Memory Usage (-Xmx) + + + maxMemSpinBox + + + + + + + + 0 + 0 + + + + The maximum amount of memory Minecraft is allowed to use. + + + MiB + + + 8 + + + 1048576 + + + 128 + + + 1024 + + + + + + + &PermGen Size (-XX:PermSize) + + + permGenSpinBox + + + + + + + + 0 + 0 + + + + The amount of memory available to store loaded Java classes. + + + MiB + + + 4 + + + 999999999 + + + 8 + + + 64 + - Maximum Memory Notice + TextLabel @@ -609,11 +312,18 @@ + javaTestBtn + javaDownloadBtn javaPathTextBox + javaDetectBtn + javaBrowseBtn skipCompatibilityCheckBox skipWizardCheckBox autodetectJavaCheckBox autodownloadJavaCheckBox + minMemSpinBox + maxMemSpinBox + permGenSpinBox jvmArgsTextBox