Unify Java page

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2025-01-26 22:25:26 +00:00
parent 012bbca197
commit 1b4b36df33
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
11 changed files with 865 additions and 634 deletions

View file

@ -1124,6 +1124,8 @@ SET(LAUNCHER_SOURCES
ui/widgets/ThemeCustomizationWidget.cpp
ui/widgets/MinecraftSettingsWidget.h
ui/widgets/MinecraftSettingsWidget.cpp
ui/widgets/JavaSettingsWidget.h
ui/widgets/JavaSettingsWidget.cpp
# GUI - instance group view
ui/instanceview/InstanceProxyModel.cpp
@ -1197,6 +1199,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/widgets/SubTaskProgressBar.ui
ui/widgets/ThemeCustomizationWidget.ui
ui/widgets/MinecraftSettingsWidget.ui
ui/widgets/JavaSettingsWidget.ui
ui/dialogs/CopyInstanceDialog.ui
ui/dialogs/ProfileSetupDialog.ui
ui/dialogs/ProgressDialog.ui

View file

@ -62,6 +62,9 @@
JavaPage::JavaPage(QWidget* parent) : QWidget(parent), ui(new Ui::JavaPage)
{
ui->setupUi(this);
m_javaSettings = new JavaSettingsWidget(nullptr, this);
ui->generalScrollArea->setWidget(m_javaSettings);
if (BuildConfig.JAVA_DOWNLOADER_ENABLED) {
ui->managedJavaList->initialize(new JavaInstallList(this, true));
@ -69,18 +72,8 @@ JavaPage::JavaPage(QWidget* parent) : QWidget(parent), ui(new Ui::JavaPage)
ui->managedJavaList->selectCurrent();
ui->managedJavaList->setEmptyString(tr("No managed Java versions are installed"));
ui->managedJavaList->setEmptyErrorString(tr("Couldn't load the managed Java list!"));
connect(ui->autodetectJavaCheckBox, &QCheckBox::stateChanged, this, [this] {
ui->autodownloadCheckBox->setEnabled(ui->autodetectJavaCheckBox->isChecked());
if (!ui->autodetectJavaCheckBox->isChecked())
ui->autodownloadCheckBox->setChecked(false);
});
} else {
ui->autodownloadCheckBox->setHidden(true);
} else
ui->tabWidget->tabBar()->hide();
}
loadSettings();
updateThresholds();
}
JavaPage::~JavaPage()
@ -88,117 +81,18 @@ JavaPage::~JavaPage()
delete ui;
}
void JavaPage::retranslate()
{
ui->retranslateUi(this);
}
bool JavaPage::apply()
{
applySettings();
m_javaSettings->saveSettings();
JavaCommon::checkJVMArgs(APPLICATION->settings()->get("JvmArgs").toString(), this);
return true;
}
void JavaPage::applySettings()
{
auto s = APPLICATION->settings();
// Memory
int min = ui->minMemSpinBox->value();
int max = ui->maxMemSpinBox->value();
if (min < max) {
s->set("MinMemAlloc", min);
s->set("MaxMemAlloc", max);
} else {
s->set("MinMemAlloc", max);
s->set("MaxMemAlloc", min);
}
s->set("PermGen", ui->permGenSpinBox->value());
// Java Settings
s->set("JavaPath", ui->javaPathTextBox->text());
s->set("JvmArgs", ui->jvmArgsTextBox->toPlainText().replace("\n", " "));
s->set("IgnoreJavaCompatibility", ui->skipCompatibilityCheckbox->isChecked());
s->set("IgnoreJavaWizard", ui->skipJavaWizardCheckbox->isChecked());
s->set("AutomaticJavaSwitch", ui->autodetectJavaCheckBox->isChecked());
s->set("AutomaticJavaDownload", ui->autodownloadCheckBox->isChecked());
JavaCommon::checkJVMArgs(s->get("JvmArgs").toString(), this->parentWidget());
}
void JavaPage::loadSettings()
{
auto s = APPLICATION->settings();
// Memory
int min = s->get("MinMemAlloc").toInt();
int max = s->get("MaxMemAlloc").toInt();
if (min < max) {
ui->minMemSpinBox->setValue(min);
ui->maxMemSpinBox->setValue(max);
} else {
ui->minMemSpinBox->setValue(max);
ui->maxMemSpinBox->setValue(min);
}
ui->permGenSpinBox->setValue(s->get("PermGen").toInt());
// Java Settings
ui->javaPathTextBox->setText(s->get("JavaPath").toString());
ui->jvmArgsTextBox->setPlainText(s->get("JvmArgs").toString());
ui->skipCompatibilityCheckbox->setChecked(s->get("IgnoreJavaCompatibility").toBool());
ui->skipJavaWizardCheckbox->setChecked(s->get("IgnoreJavaWizard").toBool());
ui->autodetectJavaCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool());
ui->autodownloadCheckBox->setChecked(s->get("AutomaticJavaSwitch").toBool() && s->get("AutomaticJavaDownload").toBool());
}
void JavaPage::on_javaDetectBtn_clicked()
{
if (JavaUtils::getJavaCheckPath().isEmpty()) {
JavaCommon::javaCheckNotFound(this);
return;
}
JavaInstallPtr java;
VersionSelectDialog vselect(APPLICATION->javalist().get(), tr("Select a Java version"), this, true);
vselect.setResizeOn(2);
vselect.exec();
if (vselect.result() == QDialog::Accepted && vselect.selectedVersion()) {
java = std::dynamic_pointer_cast<JavaInstall>(vselect.selectedVersion());
ui->javaPathTextBox->setText(java->path);
if (!java->is_64bit && APPLICATION->settings()->get("MaxMemAlloc").toInt() > 2048) {
CustomMessageBox::selectable(this, tr("Confirm Selection"),
tr("You selected a 32-bit version of Java.\n"
"This installation does not support more than 2048MiB of RAM.\n"
"Please make sure that the maximum memory value is lower."),
QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Ok)
->exec();
}
}
}
void JavaPage::on_javaBrowseBtn_clicked()
{
QString raw_path = QFileDialog::getOpenFileName(this, tr("Find Java executable"));
// do not allow current dir - it's dirty. Do not allow dirs that don't exist
if (raw_path.isEmpty()) {
return;
}
QString cooked_path = FS::NormalizePath(raw_path);
QFileInfo javaInfo(cooked_path);
;
if (!javaInfo.exists() || !javaInfo.isExecutable()) {
return;
}
ui->javaPathTextBox->setText(cooked_path);
}
void JavaPage::on_javaTestBtn_clicked()
{
if (checker) {
return;
}
checker.reset(new JavaCommon::TestCheck(this, ui->javaPathTextBox->text(), ui->jvmArgsTextBox->toPlainText().replace("\n", " "),
ui->minMemSpinBox->value(), ui->maxMemSpinBox->value(), ui->permGenSpinBox->value()));
connect(checker.get(), SIGNAL(finished()), SLOT(checkerFinished()));
checker->run();
}
void JavaPage::on_downloadJavaButton_clicked()
{
auto jdialog = new Java::InstallDialog({}, nullptr, this);
@ -206,51 +100,6 @@ void JavaPage::on_downloadJavaButton_clicked()
ui->managedJavaList->loadList();
}
void JavaPage::on_maxMemSpinBox_valueChanged([[maybe_unused]] int i)
{
updateThresholds();
}
void JavaPage::checkerFinished()
{
checker.reset();
}
void JavaPage::retranslate()
{
ui->retranslateUi(this);
}
void JavaPage::updateThresholds()
{
auto sysMiB = Sys::getSystemRam() / Sys::mebibyte;
unsigned int maxMem = ui->maxMemSpinBox->value();
unsigned int minMem = ui->minMemSpinBox->value();
QString iconName;
if (maxMem >= sysMiB) {
iconName = "status-bad";
ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity."));
} else if (maxMem > (sysMiB * 0.9)) {
iconName = "status-yellow";
ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity."));
} else if (maxMem < minMem) {
iconName = "status-yellow";
ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation is smaller than the minimum value"));
} else {
iconName = "status-good";
ui->labelMaxMemIcon->setToolTip("");
}
{
auto height = ui->labelMaxMemIcon->fontInfo().pixelSize();
QIcon icon = APPLICATION->getThemedIcon(iconName);
QPixmap pix = icon.pixmap(height, height);
ui->labelMaxMemIcon->setPixmap(pix);
}
}
void JavaPage::on_removeJavaButton_clicked()
{
auto version = ui->managedJavaList->selectedVersion();

View file

@ -37,6 +37,7 @@
#include <Application.h>
#include <QObjectPtr.h>
#include <ui/widgets/JavaSettingsWidget.h>
#include <QDialog>
#include <QStringListModel>
#include "JavaCommon.h"
@ -59,26 +60,16 @@ class JavaPage : public QWidget, public BasePage {
QIcon icon() const override { return APPLICATION->getThemedIcon("java"); }
QString id() const override { return "java-settings"; }
QString helpPage() const override { return "Java-settings"; }
bool apply() override;
void retranslate() override;
void updateThresholds();
private:
void applySettings();
void loadSettings();
bool apply() override;
private slots:
void on_javaDetectBtn_clicked();
void on_javaTestBtn_clicked();
void on_javaBrowseBtn_clicked();
void on_downloadJavaButton_clicked();
void on_removeJavaButton_clicked();
void on_refreshJavaButton_clicked();
void on_maxMemSpinBox_valueChanged(int i);
void checkerFinished();
private:
Ui::JavaPage* ui;
unique_qobject_ptr<JavaCommon::TestCheck> checker;
JavaSettingsWidget* m_javaSettings;
};

View file

@ -40,292 +40,22 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="memoryGroupBox">
<property name="title">
<string>Memory</string>
<widget class="QScrollArea" name="generalScrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="1,0,0,0">
<item row="1" column="0">
<widget class="QLabel" name="labelMaxMem">
<property name="text">
<string>Ma&amp;ximum memory allocation:</string>
</property>
<property name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelPermGen">
<property name="text">
<string>&amp;PermGen:</string>
</property>
<property name="buddy">
<cstring>permGenSpinBox</cstring>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelMinMem">
<property name="text">
<string>&amp;Minimum memory allocation:</string>
</property>
<property name="buddy">
<cstring>minMemSpinBox</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="minMemSpinBox">
<property name="toolTip">
<string>The amount of memory Minecraft is started with.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>256</number>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSpinBox" name="maxMemSpinBox">
<property name="toolTip">
<string>The maximum amount of memory Minecraft is allowed to use.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>1024</number>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QSpinBox" name="permGenSpinBox">
<property name="toolTip">
<string>The amount of memory available to store loaded Java classes.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>4</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="singleStep">
<number>8</number>
</property>
<property name="value">
<number>64</number>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="labelMaxMemIcon">
<property name="text">
<string/>
</property>
<property name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
</layout>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>535</width>
<height>610</height>
</rect>
</property>
</widget>
</widget>
</item>
<item>
<widget class="QGroupBox" name="javaSettingsGroupBox">
<property name="title">
<string>Java Runtime</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="4" column="0">
<widget class="QCheckBox" name="skipCompatibilityCheckbox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
</property>
<property name="text">
<string>&amp;Skip Java compatibility checks</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="javaDetectBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Auto-detect...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="javaTestBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Test</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="8" column="0">
<widget class="QLabel" name="labelJVMArgs">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>JVM arguments:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QCheckBox" name="skipJavaWizardCheckbox">
<property name="toolTip">
<string>If enabled, the launcher will not prompt you to choose a Java version if one isn't found.</string>
</property>
<property name="text">
<string>Skip Java &amp;Wizard</string>
</property>
</widget>
</item>
<item row="9" column="0" colspan="3">
<widget class="QPlainTextEdit" name="jvmArgsTextBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>100</height>
</size>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QCheckBox" name="autodetectJavaCheckBox">
<property name="toolTip">
<string>Automatically selects the Java version that is compatible with the current Minecraft instance, based on the major version required.</string>
</property>
<property name="text">
<string>Autodetect Java version</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labelJavaPath">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Java path:</string>
</property>
<property name="buddy">
<cstring>javaPathTextBox</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="javaPathTextBox"/>
</item>
<item>
<widget class="QPushButton" name="javaBrowseBtn">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="autodownloadCheckBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="toolTip">
<string>Automatically downloads and selects the Java version recommended by Mojang.</string>
</property>
<property name="text">
<string>Auto-download Mojang Java</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="management">
@ -417,19 +147,6 @@
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>minMemSpinBox</tabstop>
<tabstop>maxMemSpinBox</tabstop>
<tabstop>permGenSpinBox</tabstop>
<tabstop>javaPathTextBox</tabstop>
<tabstop>javaBrowseBtn</tabstop>
<tabstop>javaDetectBtn</tabstop>
<tabstop>javaTestBtn</tabstop>
<tabstop>skipCompatibilityCheckbox</tabstop>
<tabstop>skipJavaWizardCheckbox</tabstop>
<tabstop>jvmArgsTextBox</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View file

@ -0,0 +1,309 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
* Copyright (C) 2024 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2013-2021 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "JavaSettingsWidget.h"
#include <Application.h>
#include <BuildConfig.h>
#include <JavaCommon.h>
#include <settings/Setting.h>
#include <ui/java/InstallJavaDialog.h>
#include <FileSystem.h>
#include <java/JavaInstallList.h>
#include <java/JavaUtils.h>
#include <sys.h>
#include <ui/dialogs/CustomMessageBox.h>
#include <ui/dialogs/VersionSelectDialog.h>
#include <QFileDialog>
#include <QFileInfo>
#include <memory>
#include "ui_JavaSettingsWidget.h"
JavaSettingsWidget::JavaSettingsWidget(InstancePtr instance, QWidget* parent)
: QWidget(parent), m_instance(std::move(instance)), m_ui(new Ui::JavaSettingsWidget)
{
m_ui->setupUi(this);
if (m_instance == nullptr) {
m_ui->javaDownloadBtn->hide();
if (BuildConfig.JAVA_DOWNLOADER_ENABLED) {
connect(m_ui->autodetectJavaCheckBox, &QCheckBox::stateChanged, this, [this](bool state) {
m_ui->autodownloadJavaCheckBox->setEnabled(state);
if (!state)
m_ui->autodownloadJavaCheckBox->setChecked(false);
});
} else {
m_ui->autodownloadJavaCheckBox->hide();
}
} else {
m_ui->javaDownloadBtn->setVisible(BuildConfig.JAVA_DOWNLOADER_ENABLED);
m_ui->skipWizardCheckBox->hide();
m_ui->autodetectJavaCheckBox->hide();
m_ui->autodownloadJavaCheckBox->hide();
m_ui->javaInstallationGroupBox->setCheckable(true);
m_ui->memoryGroupBox->setCheckable(true);
m_ui->javaArgumentsGroupBox->setCheckable(true);
SettingsObjectPtr settings = m_instance->settings();
connect(settings->getSetting("OverrideJavaLocation").get(), &Setting::SettingChanged, m_ui->javaInstallationGroupBox,
[this, settings] { m_ui->javaInstallationGroupBox->setChecked(settings->get("OverrideJavaLocation").toBool()); });
connect(settings->getSetting("JavaPath").get(), &Setting::SettingChanged, m_ui->javaInstallationGroupBox,
[this, settings] { m_ui->javaPathTextBox->setText(settings->get("JavaPath").toString()); });
connect(m_ui->javaDownloadBtn, &QPushButton::clicked, this, [this] {
auto javaDialog = new Java::InstallDialog({}, m_instance.get(), this);
javaDialog->exec();
});
}
connect(m_ui->javaTestBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaTest);
connect(m_ui->javaDetectBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaAutodetect);
connect(m_ui->javaBrowseBtn, &QPushButton::clicked, this, &JavaSettingsWidget::onJavaBrowse);
connect(m_ui->maxMemSpinBox, &QSpinBox::valueChanged, this, &JavaSettingsWidget::updateThresholds);
loadSettings();
updateThresholds();
}
JavaSettingsWidget::~JavaSettingsWidget()
{
delete m_ui;
}
void JavaSettingsWidget::loadSettings()
{
SettingsObjectPtr settings;
if (m_instance != nullptr)
settings = m_instance->settings();
else
settings = APPLICATION->settings();
// Java Settings
m_ui->javaInstallationGroupBox->setChecked(settings->get("OverrideJavaLocation").toBool());
m_ui->javaPathTextBox->setText(settings->get("JavaPath").toString());
m_ui->skipCompatibilityCheckBox->setChecked(settings->get("IgnoreJavaCompatibility").toBool());
m_ui->javaArgumentsGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideJavaArgs").toBool());
m_ui->jvmArgsTextBox->setPlainText(settings->get("JvmArgs").toString());
if (m_instance == nullptr) {
m_ui->skipWizardCheckBox->setChecked(settings->get("IgnoreJavaWizard").toBool());
m_ui->autodetectJavaCheckBox->setChecked(settings->get("AutomaticJavaSwitch").toBool());
m_ui->autodetectJavaCheckBox->stateChanged(m_ui->autodetectJavaCheckBox->isChecked());
m_ui->autodownloadJavaCheckBox->setChecked(settings->get("AutomaticJavaDownload").toBool());
}
// Memory
m_ui->memoryGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideMemory").toBool());
int min = settings->get("MinMemAlloc").toInt();
int max = settings->get("MaxMemAlloc").toInt();
if (min < max) {
m_ui->minMemSpinBox->setValue(min);
m_ui->maxMemSpinBox->setValue(max);
} else {
m_ui->minMemSpinBox->setValue(max);
m_ui->maxMemSpinBox->setValue(min);
}
m_ui->permGenSpinBox->setValue(settings->get("PermGen").toInt());
// Java arguments
m_ui->javaArgumentsGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideJavaArgs").toBool());
m_ui->jvmArgsTextBox->setPlainText(settings->get("JvmArgs").toString());
}
void JavaSettingsWidget::saveSettings()
{
SettingsObjectPtr settings;
if (m_instance != nullptr)
settings = m_instance->settings();
else
settings = APPLICATION->settings();
SettingsObject::Lock lock(settings);
// Java Install Settings
bool javaInstall = m_instance == nullptr || m_ui->javaInstallationGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideJavaLocation", javaInstall);
if (javaInstall) {
settings->set("JavaPath", m_ui->javaPathTextBox->text());
settings->set("IgnoreJavaCompatibility", m_ui->skipCompatibilityCheckBox->isChecked());
} else {
settings->reset("JavaPath");
settings->reset("IgnoreJavaCompatibility");
}
if (m_instance == nullptr) {
settings->set("IgnoreJavaWizard", m_ui->skipWizardCheckBox->isChecked());
settings->set("AutomaticJavaSwitch", m_ui->autodetectJavaCheckBox->isChecked());
settings->set("AutomaticJavaDownload", m_ui->autodownloadJavaCheckBox->isChecked());
}
// Memory
bool memory = m_instance == nullptr || m_ui->memoryGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideMemory", memory);
if (memory) {
int min = m_ui->minMemSpinBox->value();
int max = m_ui->maxMemSpinBox->value();
if (min < max) {
settings->set("MinMemAlloc", min);
settings->set("MaxMemAlloc", max);
} else {
settings->set("MinMemAlloc", max);
settings->set("MaxMemAlloc", min);
}
settings->set("PermGen", m_ui->permGenSpinBox->value());
} else {
settings->reset("MinMemAlloc");
settings->reset("MaxMemAlloc");
settings->reset("PermGen");
}
// Java arguments
bool javaArgs = m_instance == nullptr || m_ui->javaArgumentsGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideJavaArgs", javaArgs);
if (javaArgs) {
settings->set("JvmArgs", m_ui->jvmArgsTextBox->toPlainText().replace("\n", " "));
} else {
settings->reset("JvmArgs");
}
}
void JavaSettingsWidget::onJavaBrowse()
{
QString rawPath = QFileDialog::getOpenFileName(this, tr("Find Java executable"));
// do not allow current dir - it's dirty. Do not allow dirs that don't exist
if (rawPath.isEmpty()) {
return;
}
QString cookedPath = FS::NormalizePath(rawPath);
QFileInfo javaInfo(cookedPath);
if (!javaInfo.exists() || !javaInfo.isExecutable()) {
return;
}
m_ui->javaPathTextBox->setText(cookedPath);
}
void JavaSettingsWidget::onJavaTest()
{
if (m_checker != nullptr)
return;
QString jvmArgs;
if (m_instance == nullptr || m_ui->javaArgumentsGroupBox->isChecked())
jvmArgs = m_ui->jvmArgsTextBox->toPlainText().replace("\n", " ");
else
jvmArgs = APPLICATION->settings()->get("JvmArgs").toString();
m_checker.reset(new JavaCommon::TestCheck(this, m_ui->javaPathTextBox->text(), jvmArgs, m_ui->minMemSpinBox->value(),
m_ui->maxMemSpinBox->value(), m_ui->permGenSpinBox->value()));
connect(m_checker.get(), &JavaCommon::TestCheck::finished, this, [this] { m_checker.reset(); });
m_checker->run();
}
void JavaSettingsWidget::onJavaAutodetect()
{
if (JavaUtils::getJavaCheckPath().isEmpty()) {
JavaCommon::javaCheckNotFound(this);
return;
}
VersionSelectDialog versionDialog(APPLICATION->javalist().get(), tr("Select a Java version"), this, true);
versionDialog.setResizeOn(2);
versionDialog.exec();
if (versionDialog.result() == QDialog::Accepted && versionDialog.selectedVersion()) {
JavaInstallPtr java = std::dynamic_pointer_cast<JavaInstall>(versionDialog.selectedVersion());
m_ui->javaPathTextBox->setText(java->path);
if (!java->is_64bit && m_ui->maxMemSpinBox->value() > 2048) {
CustomMessageBox::selectable(this, tr("Confirm Selection"),
tr("You selected a 32-bit version of Java.\n"
"This installation does not support more than 2048MiB of RAM.\n"
"Please make sure that the maximum memory value is lower."),
QMessageBox::Warning, QMessageBox::Ok, QMessageBox::Ok)
->exec();
}
}
}
void JavaSettingsWidget::updateThresholds()
{
auto sysMiB = Sys::getSystemRam() / Sys::mebibyte;
unsigned int maxMem = m_ui->maxMemSpinBox->value();
unsigned int minMem = m_ui->minMemSpinBox->value();
QString iconName;
if (maxMem >= sysMiB) {
iconName = "status-bad";
m_ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity."));
} else if (maxMem > (sysMiB * 0.9)) {
iconName = "status-yellow";
m_ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity."));
} else if (maxMem < minMem) {
iconName = "status-yellow";
m_ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation is smaller than the minimum value"));
} else {
iconName = "status-good";
m_ui->labelMaxMemIcon->setToolTip("");
}
{
auto height = m_ui->labelMaxMemIcon->fontInfo().pixelSize();
QIcon icon = APPLICATION->getThemedIcon(iconName);
QPixmap pix = icon.pixmap(height, height);
m_ui->labelMaxMemIcon->setPixmap(pix);
}
}

View file

@ -0,0 +1,67 @@
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
* Copyright (C) 2024 TheKodeToad <TheKodeToad@proton.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* This file incorporates work covered by the following copyright and
* permission notice:
*
* Copyright 2013-2021 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <BaseInstance.h>
#include <JavaCommon.h>
#include <QWidget>
namespace Ui {
class JavaSettingsWidget;
}
class JavaSettingsWidget : public QWidget {
Q_OBJECT
public:
explicit JavaSettingsWidget(InstancePtr instance, QWidget* parent = nullptr);
~JavaSettingsWidget() override;
void loadSettings();
void saveSettings();
private slots:
void onJavaBrowse();
void onJavaAutodetect();
void onJavaTest();
void updateThresholds();
private:
InstancePtr m_instance;
Ui::JavaSettingsWidget* m_ui;
unique_qobject_ptr<JavaCommon::TestCheck> m_checker;
};

View file

@ -0,0 +1,254 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>JavaSettingsWidget</class>
<widget class="QWidget" name="JavaSettingsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="javaInstallationGroupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Java Insta&amp;llation</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="6" column="0">
<widget class="QCheckBox" name="autodetectJavaCheckBox">
<property name="text">
<string>Auto-&amp;detect Java version</string>
</property>
</widget>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="javaPathTextBox"/>
</item>
<item>
<widget class="QPushButton" name="javaBrowseBtn">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="javaDownloadBtn">
<property name="text">
<string>Download Java</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="javaDetectBtn">
<property name="text">
<string>Auto-detect...</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="javaTestBtn">
<property name="text">
<string>Test</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QCheckBox" name="autodownloadJavaCheckBox">
<property name="toolTip">
<string>Automatically downloads and selects the Java build recommended by Mojang.</string>
</property>
<property name="text">
<string>Auto-download &amp;Mojang Java</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="skipWizardCheckBox">
<property name="toolTip">
<string>If enabled, the launcher won't prompt you to choose a Java version if one is not found on startup.</string>
</property>
<property name="text">
<string>Skip Java setup prompt on startup</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="skipCompatibilityCheckBox">
<property name="toolTip">
<string>If enabled, the launcher will not check if an instance is compatible with the selected Java version.</string>
</property>
<property name="text">
<string>Skip Java compatibility checks</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="memoryGroupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Memor&amp;y</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_5" columnstretch="1,0,0">
<item row="2" column="0">
<widget class="QLabel" name="labelPermGen">
<property name="text">
<string>PermGen (Java 7 and earlier):</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelMinMem">
<property name="text">
<string>Minimum memory allocation:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="permGenSpinBox">
<property name="toolTip">
<string>The amount of memory available to store loaded Java classes.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>4</number>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="singleStep">
<number>8</number>
</property>
<property name="value">
<number>64</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelMaxMem">
<property name="text">
<string>Maximum memory allocation:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="labelMaxMemIcon">
<property name="text">
<string notr="true"/>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<property name="buddy">
<cstring>maxMemSpinBox</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="maxMemSpinBox">
<property name="toolTip">
<string>The maximum amount of memory Minecraft is allowed to use.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>1024</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="minMemSpinBox">
<property name="toolTip">
<string>The amount of memory Minecraft is started with.</string>
</property>
<property name="suffix">
<string notr="true"> MiB</string>
</property>
<property name="minimum">
<number>8</number>
</property>
<property name="maximum">
<number>1048576</number>
</property>
<property name="singleStep">
<number>128</number>
</property>
<property name="value">
<number>256</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="javaArgumentsGroupBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Java Argumen&amp;ts</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_6">
<item row="1" column="1">
<widget class="QPlainTextEdit" name="jvmArgsTextBox"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View file

@ -502,7 +502,7 @@ void JavaWizardWidget::retranslate()
if (BuildConfig.JAVA_DOWNLOADER_ENABLED) {
m_autodownloadCheckBox->setText(tr("Auto-download Mojang Java"));
}
m_autodetectJavaCheckBox->setText(tr("Autodetect Java version"));
m_autodetectJavaCheckBox->setText(tr("Auto-detect Java version"));
m_autoJavaGroupBox->setTitle(tr("Autodetect Java"));
}

View file

@ -47,12 +47,20 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(InstancePtr instance, QWidget*
m_ui->setupUi(this);
if (m_instance == nullptr) {
// Java
m_ui->settingsTabs->removeTab(1);
// Launch
m_ui->settingsTabs->removeTab(2);
for (int i = 0; i < m_ui->settingsTabs->count(); ++i) {
const QString name = m_ui->settingsTabs->widget(i)->objectName();
if (name == "javaTab" || name == "launchTab") {
m_ui->settingsTabs->removeTab(i);
--i;
}
}
m_ui->openGlobalSettingsButton->setVisible(false);
} else {
m_javaSettings = new JavaSettingsWidget(m_instance, this);
m_ui->javaScrollArea->setWidget(m_javaSettings);
m_ui->showGameTime->setText(tr("Show time &playing this instance"));
m_ui->recordGameTime->setText(tr("&Record time playing this instance"));
m_ui->showGlobalGameTime->hide();
@ -63,6 +71,14 @@ MinecraftSettingsWidget::MinecraftSettingsWidget(InstancePtr instance, QWidget*
"not fully supported on this Minecraft version.</span>"));
connect(m_ui->openGlobalSettingsButton, &QCommandLinkButton::clicked, this, &MinecraftSettingsWidget::openGlobalSettings);
m_ui->miscellaneousSettingsBox->setCheckable(true);
m_ui->consoleSettingsBox->setCheckable(true);
m_ui->windowSizeGroupBox->setCheckable(true);
m_ui->nativeWorkaroundsGroupBox->setCheckable(true);
m_ui->perfomanceGroupBox->setCheckable(true);
m_ui->gameTimeGroupBox->setCheckable(true);
m_ui->legacySettingsGroupBox->setCheckable(true);
}
m_ui->maximizedWarning->hide();
@ -84,29 +100,34 @@ MinecraftSettingsWidget::~MinecraftSettingsWidget()
void MinecraftSettingsWidget::loadSettings()
{
const SettingsObjectPtr settings = getSettings();
SettingsObjectPtr settings;
if (m_instance != nullptr)
settings = m_instance->settings();
else
settings = APPLICATION->settings();
// Miscellaneous
m_ui->miscellaneousSettingsBox->setCheckable(m_instance != nullptr);
m_ui->miscellaneousSettingsBox->setChecked(settings->get("OverrideMiscellaneous").toBool());
m_ui->closeAfterLaunchCheck->setChecked(settings->get("CloseAfterLaunch").toBool());
m_ui->quitAfterGameStopCheck->setChecked(settings->get("QuitAfterGameStop").toBool());
// Console
m_ui->consoleSettingsBox->setCheckable(m_instance != nullptr);
m_ui->consoleSettingsBox->setChecked(m_instance == nullptr || settings->get("OverrideConsole").toBool());
m_ui->showConsoleCheck->setChecked(settings->get("ShowConsole").toBool());
m_ui->autoCloseConsoleCheck->setChecked(settings->get("AutoCloseConsole").toBool());
m_ui->showConsoleErrorCheck->setChecked(settings->get("ShowConsoleOnError").toBool());
// Window Size
m_ui->windowSizeGroupBox->setCheckable(m_instance != nullptr);
m_ui->windowSizeGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideWindow").toBool());
m_ui->windowSizeGroupBox->setChecked(settings->get("OverrideWindow").toBool());
m_ui->maximizedCheckBox->setChecked(settings->get("LaunchMaximized").toBool());
m_ui->windowWidthSpinBox->setValue(settings->get("MinecraftWinWidth").toInt());
m_ui->windowHeightSpinBox->setValue(settings->get("MinecraftWinHeight").toInt());
if (m_javaSettings != nullptr)
m_javaSettings->loadSettings();
// Custom commands
m_ui->customCommands->initialize(m_instance != nullptr, m_instance == nullptr || settings->get("OverrideCommands").toBool(),
settings->get("PreLaunchCommand").toString(), settings->get("WrapperCommand").toString(),
@ -117,7 +138,6 @@ void MinecraftSettingsWidget::loadSettings()
settings->get("Env").toMap());
// Workarounds
m_ui->nativeWorkaroundsGroupBox->setCheckable(m_instance != nullptr);
m_ui->nativeWorkaroundsGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideNativeWorkarounds").toBool());
m_ui->useNativeGLFWCheck->setChecked(settings->get("UseNativeGLFW").toBool());
m_ui->lineEditGLFWPath->setText(settings->get("CustomGLFWPath").toString());
@ -135,7 +155,6 @@ void MinecraftSettingsWidget::loadSettings()
#endif
// Performance
m_ui->perfomanceGroupBox->setCheckable(m_instance != nullptr);
m_ui->perfomanceGroupBox->setChecked(m_instance == nullptr || settings->get("OverridePerformance").toBool());
m_ui->enableFeralGamemodeCheck->setChecked(settings->get("EnableFeralGamemode").toBool());
m_ui->enableMangoHud->setChecked(settings->get("EnableMangoHud").toBool());
@ -153,164 +172,170 @@ void MinecraftSettingsWidget::loadSettings()
}
// Miscellanous
m_ui->gameTimeGroupBox->setCheckable(m_instance != nullptr);
m_ui->gameTimeGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideGameTime").toBool());
m_ui->showGameTime->setChecked(settings->get("ShowGameTime").toBool());
m_ui->recordGameTime->setChecked(settings->get("RecordGameTime").toBool());
m_ui->showGlobalGameTime->setChecked(m_instance != nullptr && settings->get("ShowGlobalGameTime").toBool());
m_ui->showGameTimeWithoutDays->setChecked(m_instance != nullptr && settings->get("ShowGameTimeWithoutDays").toBool());
m_ui->showGlobalGameTime->setChecked(m_instance == nullptr && settings->get("ShowGlobalGameTime").toBool());
m_ui->showGameTimeWithoutDays->setChecked(m_instance == nullptr && settings->get("ShowGameTimeWithoutDays").toBool());
m_ui->legacySettingsGroupBox->setCheckable(m_instance != nullptr);
m_ui->legacySettingsGroupBox->setChecked(m_instance == nullptr || settings->get("OverrideLegacySettings").toBool());
m_ui->onlineFixes->setChecked(settings->get("OnlineFixes").toBool());
}
void MinecraftSettingsWidget::saveSettings()
{
SettingsObjectPtr settings = getSettings();
SettingsObject::Lock lock(settings);
// Miscellaneous
bool miscellaneous = m_instance == nullptr || m_ui->miscellaneousSettingsBox->isChecked();
SettingsObjectPtr settings;
if (m_instance != nullptr)
settings->set("OverrideMiscellaneous", miscellaneous);
if (miscellaneous) {
settings->set("CloseAfterLaunch", m_ui->closeAfterLaunchCheck->isChecked());
settings->set("QuitAfterGameStop", m_ui->quitAfterGameStopCheck->isChecked());
} else {
settings->reset("CloseAfterLaunch");
settings->reset("QuitAfterGameStop");
}
// Console
bool console = m_instance == nullptr || m_ui->consoleSettingsBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideConsole", console);
if (console) {
settings->set("ShowConsole", m_ui->showConsoleCheck->isChecked());
settings->set("AutoCloseConsole", m_ui->autoCloseConsoleCheck->isChecked());
settings->set("ShowConsoleOnError", m_ui->showConsoleErrorCheck->isChecked());
} else {
settings->reset("ShowConsole");
settings->reset("AutoCloseConsole");
settings->reset("ShowConsoleOnError");
}
// Window Size
bool window = m_instance == nullptr || m_ui->windowSizeGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideWindow", window);
if (window) {
settings->set("LaunchMaximized", m_ui->maximizedCheckBox->isChecked());
settings->set("MinecraftWinWidth", m_ui->windowWidthSpinBox->value());
settings->set("MinecraftWinHeight", m_ui->windowHeightSpinBox->value());
} else {
settings->reset("LaunchMaximized");
settings->reset("MinecraftWinWidth");
settings->reset("MinecraftWinHeight");
}
// Custom Commands
bool custcmd = m_instance == nullptr || m_ui->customCommands->checked();
if (m_instance != nullptr)
settings->set("OverrideCommands", custcmd);
if (custcmd) {
settings->set("PreLaunchCommand", m_ui->customCommands->prelaunchCommand());
settings->set("WrapperCommand", m_ui->customCommands->wrapperCommand());
settings->set("PostExitCommand", m_ui->customCommands->postexitCommand());
} else {
settings->reset("PreLaunchCommand");
settings->reset("WrapperCommand");
settings->reset("PostExitCommand");
}
// Environment Variables
auto env = m_instance == nullptr || m_ui->environmentVariables->override();
if (m_instance != nullptr)
settings->set("OverrideEnv", env);
if (env)
settings->set("Env", m_ui->environmentVariables->value());
settings = m_instance->settings();
else
settings->reset("Env");
settings = APPLICATION->settings();
// Workarounds
bool workarounds = m_instance == nullptr || m_ui->nativeWorkaroundsGroupBox->isChecked();
{
SettingsObject::Lock lock(settings);
if (m_instance != nullptr)
settings->set("OverrideNativeWorkarounds", workarounds);
// Miscellaneous
bool miscellaneous = m_instance == nullptr || m_ui->miscellaneousSettingsBox->isChecked();
if (workarounds) {
settings->set("UseNativeGLFW", m_ui->useNativeGLFWCheck->isChecked());
settings->set("CustomGLFWPath", m_ui->lineEditGLFWPath->text());
settings->set("UseNativeOpenAL", m_ui->useNativeOpenALCheck->isChecked());
settings->set("CustomOpenALPath", m_ui->lineEditOpenALPath->text());
} else {
settings->reset("UseNativeGLFW");
settings->reset("CustomGLFWPath");
settings->reset("UseNativeOpenAL");
settings->reset("CustomOpenALPath");
if (m_instance != nullptr)
settings->set("OverrideMiscellaneous", miscellaneous);
if (miscellaneous) {
settings->set("CloseAfterLaunch", m_ui->closeAfterLaunchCheck->isChecked());
settings->set("QuitAfterGameStop", m_ui->quitAfterGameStopCheck->isChecked());
} else {
settings->reset("CloseAfterLaunch");
settings->reset("QuitAfterGameStop");
}
// Console
bool console = m_instance == nullptr || m_ui->consoleSettingsBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideConsole", console);
if (console) {
settings->set("ShowConsole", m_ui->showConsoleCheck->isChecked());
settings->set("AutoCloseConsole", m_ui->autoCloseConsoleCheck->isChecked());
settings->set("ShowConsoleOnError", m_ui->showConsoleErrorCheck->isChecked());
} else {
settings->reset("ShowConsole");
settings->reset("AutoCloseConsole");
settings->reset("ShowConsoleOnError");
}
// Window Size
bool window = m_instance == nullptr || m_ui->windowSizeGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideWindow", window);
if (window) {
settings->set("LaunchMaximized", m_ui->maximizedCheckBox->isChecked());
settings->set("MinecraftWinWidth", m_ui->windowWidthSpinBox->value());
settings->set("MinecraftWinHeight", m_ui->windowHeightSpinBox->value());
} else {
settings->reset("LaunchMaximized");
settings->reset("MinecraftWinWidth");
settings->reset("MinecraftWinHeight");
}
// Custom Commands
bool custcmd = m_instance == nullptr || m_ui->customCommands->checked();
if (m_instance != nullptr)
settings->set("OverrideCommands", custcmd);
if (custcmd) {
settings->set("PreLaunchCommand", m_ui->customCommands->prelaunchCommand());
settings->set("WrapperCommand", m_ui->customCommands->wrapperCommand());
settings->set("PostExitCommand", m_ui->customCommands->postexitCommand());
} else {
settings->reset("PreLaunchCommand");
settings->reset("WrapperCommand");
settings->reset("PostExitCommand");
}
// Environment Variables
auto env = m_instance == nullptr || m_ui->environmentVariables->override();
if (m_instance != nullptr)
settings->set("OverrideEnv", env);
if (env)
settings->set("Env", m_ui->environmentVariables->value());
else
settings->reset("Env");
// Workarounds
bool workarounds = m_instance == nullptr || m_ui->nativeWorkaroundsGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideNativeWorkarounds", workarounds);
if (workarounds) {
settings->set("UseNativeGLFW", m_ui->useNativeGLFWCheck->isChecked());
settings->set("CustomGLFWPath", m_ui->lineEditGLFWPath->text());
settings->set("UseNativeOpenAL", m_ui->useNativeOpenALCheck->isChecked());
settings->set("CustomOpenALPath", m_ui->lineEditOpenALPath->text());
} else {
settings->reset("UseNativeGLFW");
settings->reset("CustomGLFWPath");
settings->reset("UseNativeOpenAL");
settings->reset("CustomOpenALPath");
}
// Performance
bool performance = m_instance == nullptr || m_ui->perfomanceGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverridePerformance", performance);
if (performance) {
settings->set("EnableFeralGamemode", m_ui->enableFeralGamemodeCheck->isChecked());
settings->set("EnableMangoHud", m_ui->enableMangoHud->isChecked());
settings->set("UseDiscreteGpu", m_ui->useDiscreteGpuCheck->isChecked());
settings->set("UseZink", m_ui->useZink->isChecked());
} else {
settings->reset("EnableFeralGamemode");
settings->reset("EnableMangoHud");
settings->reset("UseDiscreteGpu");
settings->reset("UseZink");
}
// Game time
bool gameTime = m_instance == nullptr || m_ui->gameTimeGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideGameTime", gameTime);
if (gameTime) {
settings->set("ShowGameTime", m_ui->showGameTime->isChecked());
settings->set("RecordGameTime", m_ui->recordGameTime->isChecked());
} else {
settings->reset("ShowGameTime");
settings->reset("RecordGameTime");
}
if (m_instance == nullptr) {
settings->set("ShowGlobalGameTime", m_ui->showGlobalGameTime->isChecked());
settings->set("ShowGameTimeWithoutDays", m_ui->showGameTimeWithoutDays->isChecked());
}
bool overrideLegacySettings = m_instance == nullptr || m_ui->legacySettingsGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideLegacySettings", overrideLegacySettings);
if (overrideLegacySettings) {
settings->set("OnlineFixes", m_ui->onlineFixes->isChecked());
} else {
settings->reset("OnlineFixes");
}
}
// Performance
bool performance = m_instance == nullptr || m_ui->perfomanceGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverridePerformance", performance);
if (performance) {
settings->set("EnableFeralGamemode", m_ui->enableFeralGamemodeCheck->isChecked());
settings->set("EnableMangoHud", m_ui->enableMangoHud->isChecked());
settings->set("UseDiscreteGpu", m_ui->useDiscreteGpuCheck->isChecked());
settings->set("UseZink", m_ui->useZink->isChecked());
} else {
settings->reset("EnableFeralGamemode");
settings->reset("EnableMangoHud");
settings->reset("UseDiscreteGpu");
settings->reset("UseZink");
}
// Game time
bool gameTime = m_instance == nullptr || m_ui->gameTimeGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideGameTime", gameTime);
if (gameTime) {
settings->set("ShowGameTime", m_ui->showGameTime->isChecked());
settings->set("RecordGameTime", m_ui->recordGameTime->isChecked());
} else {
settings->reset("ShowGameTime");
settings->reset("RecordGameTime");
}
if (m_instance == nullptr) {
settings->set("ShowGlobalGameTime", m_ui->showGlobalGameTime->isChecked());
settings->set("ShowGameTimeWithoutDays", m_ui->showGameTimeWithoutDays->isChecked());
}
bool overrideLegacySettings = m_instance == nullptr || m_ui->legacySettingsGroupBox->isChecked();
if (m_instance != nullptr)
settings->set("OverrideLegacySettings", overrideLegacySettings);
if (overrideLegacySettings) {
settings->set("OnlineFixes", m_ui->onlineFixes->isChecked());
} else {
settings->reset("OnlineFixes");
}
if (m_instance != nullptr)
m_instance->updateRuntimeContext();
if (m_javaSettings != nullptr)
m_javaSettings->saveSettings();
}
void MinecraftSettingsWidget::openGlobalSettings()
@ -322,11 +347,3 @@ void MinecraftSettingsWidget::openGlobalSettings()
else // TODO select tab
APPLICATION->ShowGlobalSettings(this, "minecraft-settings");
}
SettingsObjectPtr MinecraftSettingsWidget::getSettings() const
{
if (m_instance != nullptr)
return m_instance->settings();
return APPLICATION->settings();
}

View file

@ -38,6 +38,7 @@
#include <minecraft/MinecraftInstance.h>
#include <QWidget>
#include "JavaSettingsWidget.h"
namespace Ui {
class MinecraftSettingsWidget;
@ -54,8 +55,7 @@ class MinecraftSettingsWidget : public QWidget {
void openGlobalSettings();
private:
SettingsObjectPtr getSettings() const;
InstancePtr m_instance;
Ui::MinecraftSettingsWidget* m_ui;
JavaSettingsWidget* m_javaSettings = nullptr;
};

View file

@ -63,7 +63,7 @@
<x>0</x>
<y>0</y>
<width>610</width>
<height>607</height>
<height>550</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
@ -282,6 +282,30 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="javaTab">
<attribute name="title">
<string>Java</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QScrollArea" name="javaScrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_3">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>624</width>
<height>297</height>
</rect>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tweaksPage">
<attribute name="title">
<string>Tweaks</string>
@ -301,7 +325,7 @@
<x>0</x>
<y>0</y>
<width>610</width>
<height>439</height>
<height>398</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@ -489,7 +513,7 @@
<x>0</x>
<y>0</y>
<width>624</width>
<height>291</height>
<height>297</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">