2022-03-20 19:01:08 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* PolyMC - Minecraft Launcher
|
|
|
|
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
2022-05-26 22:18:54 +01:00
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
2022-03-20 19:01:08 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2014-06-09 00:29:18 +01:00
|
|
|
#include "InstanceSettingsPage.h"
|
|
|
|
#include "ui_InstanceSettingsPage.h"
|
|
|
|
|
2014-07-12 22:02:52 +01:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QMessageBox>
|
2014-06-09 00:29:18 +01:00
|
|
|
|
2021-11-22 02:55:16 +00:00
|
|
|
#include <sys.h>
|
|
|
|
|
|
|
|
#include "ui/dialogs/VersionSelectDialog.h"
|
|
|
|
#include "ui/widgets/CustomCommands.h"
|
|
|
|
|
2015-05-04 00:20:48 +01:00
|
|
|
#include "JavaCommon.h"
|
2021-11-20 15:22:22 +00:00
|
|
|
#include "Application.h"
|
2022-12-27 22:00:15 +00:00
|
|
|
#include "minecraft/auth/AccountList.h"
|
2014-06-09 00:29:18 +01:00
|
|
|
|
2021-11-22 02:55:16 +00:00
|
|
|
#include "java/JavaInstallList.h"
|
2022-06-14 21:00:24 +01:00
|
|
|
#include "java/JavaUtils.h"
|
2021-11-22 02:55:16 +00:00
|
|
|
#include "FileSystem.h"
|
|
|
|
|
2014-06-30 01:02:57 +01:00
|
|
|
InstanceSettingsPage::InstanceSettingsPage(BaseInstance *inst, QWidget *parent)
|
2018-07-15 13:51:05 +01:00
|
|
|
: QWidget(parent), ui(new Ui::InstanceSettingsPage), m_instance(inst)
|
2014-06-09 00:29:18 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
m_settings = inst->settings();
|
|
|
|
ui->setupUi(this);
|
2022-11-11 14:02:08 +00:00
|
|
|
|
2019-06-01 11:28:53 +01:00
|
|
|
connect(ui->openGlobalJavaSettingsButton, &QCommandLinkButton::clicked, this, &InstanceSettingsPage::globalSettingsButtonClicked);
|
2021-11-20 15:22:22 +00:00
|
|
|
connect(APPLICATION, &Application::globalSettingsAboutToOpen, this, &InstanceSettingsPage::applySettings);
|
|
|
|
connect(APPLICATION, &Application::globalSettingsClosed, this, &InstanceSettingsPage::loadSettings);
|
2023-05-14 18:57:51 +01:00
|
|
|
connect(ui->instanceAccountSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &InstanceSettingsPage::changeInstanceAccount);
|
2018-07-15 13:51:05 +01:00
|
|
|
loadSettings();
|
2023-05-14 18:57:51 +01:00
|
|
|
|
|
|
|
|
2022-11-11 14:02:08 +00:00
|
|
|
updateThresholds();
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
|
|
|
|
2014-07-12 16:58:23 +01:00
|
|
|
bool InstanceSettingsPage::shouldDisplay() const
|
2014-06-30 01:02:57 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
return !m_instance->isRunning();
|
2014-06-30 01:02:57 +01:00
|
|
|
}
|
|
|
|
|
2014-06-09 00:29:18 +01:00
|
|
|
InstanceSettingsPage::~InstanceSettingsPage()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
delete ui;
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
|
|
|
|
2019-06-01 11:28:53 +01:00
|
|
|
void InstanceSettingsPage::globalSettingsButtonClicked(bool)
|
|
|
|
{
|
2019-06-01 17:05:42 +01:00
|
|
|
switch(ui->settingsTabs->currentIndex()) {
|
|
|
|
case 0:
|
2021-11-20 15:22:22 +00:00
|
|
|
APPLICATION->ShowGlobalSettings(this, "java-settings");
|
2019-06-01 17:05:42 +01:00
|
|
|
return;
|
|
|
|
case 1:
|
2021-11-20 15:22:22 +00:00
|
|
|
APPLICATION->ShowGlobalSettings(this, "minecraft-settings");
|
2019-06-01 17:05:42 +01:00
|
|
|
return;
|
|
|
|
case 2:
|
2021-11-20 15:22:22 +00:00
|
|
|
APPLICATION->ShowGlobalSettings(this, "custom-commands");
|
2019-06-01 17:05:42 +01:00
|
|
|
return;
|
|
|
|
}
|
2019-06-01 11:28:53 +01:00
|
|
|
}
|
|
|
|
|
2014-06-09 00:29:18 +01:00
|
|
|
bool InstanceSettingsPage::apply()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
applySettings();
|
|
|
|
return true;
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::applySettings()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
SettingsObject::Lock lock(m_settings);
|
|
|
|
|
2022-05-12 22:11:06 +01:00
|
|
|
// Miscellaneous
|
|
|
|
bool miscellaneous = ui->miscellaneousSettingsBox->isChecked();
|
|
|
|
m_settings->set("OverrideMiscellaneous", miscellaneous);
|
|
|
|
if (miscellaneous)
|
|
|
|
{
|
|
|
|
m_settings->set("CloseAfterLaunch", ui->closeAfterLaunchCheck->isChecked());
|
|
|
|
m_settings->set("QuitAfterGameStop", ui->quitAfterGameStopCheck->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("CloseAfterLaunch");
|
|
|
|
m_settings->reset("QuitAfterGameStop");
|
|
|
|
}
|
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// Console
|
|
|
|
bool console = ui->consoleSettingsBox->isChecked();
|
|
|
|
m_settings->set("OverrideConsole", console);
|
|
|
|
if (console)
|
|
|
|
{
|
|
|
|
m_settings->set("ShowConsole", ui->showConsoleCheck->isChecked());
|
|
|
|
m_settings->set("AutoCloseConsole", ui->autoCloseConsoleCheck->isChecked());
|
|
|
|
m_settings->set("ShowConsoleOnError", ui->showConsoleErrorCheck->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("ShowConsole");
|
|
|
|
m_settings->reset("AutoCloseConsole");
|
|
|
|
m_settings->reset("ShowConsoleOnError");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Window Size
|
|
|
|
bool window = ui->windowSizeGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideWindow", window);
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
m_settings->set("LaunchMaximized", ui->maximizedCheckBox->isChecked());
|
|
|
|
m_settings->set("MinecraftWinWidth", ui->windowWidthSpinBox->value());
|
|
|
|
m_settings->set("MinecraftWinHeight", ui->windowHeightSpinBox->value());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("LaunchMaximized");
|
|
|
|
m_settings->reset("MinecraftWinWidth");
|
|
|
|
m_settings->reset("MinecraftWinHeight");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Memory
|
|
|
|
bool memory = ui->memoryGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideMemory", memory);
|
|
|
|
if (memory)
|
|
|
|
{
|
|
|
|
int min = ui->minMemSpinBox->value();
|
|
|
|
int max = ui->maxMemSpinBox->value();
|
|
|
|
if(min < max)
|
|
|
|
{
|
|
|
|
m_settings->set("MinMemAlloc", min);
|
|
|
|
m_settings->set("MaxMemAlloc", max);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->set("MinMemAlloc", max);
|
|
|
|
m_settings->set("MaxMemAlloc", min);
|
|
|
|
}
|
|
|
|
m_settings->set("PermGen", ui->permGenSpinBox->value());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("MinMemAlloc");
|
|
|
|
m_settings->reset("MaxMemAlloc");
|
|
|
|
m_settings->reset("PermGen");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Java Install Settings
|
|
|
|
bool javaInstall = ui->javaSettingsGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideJavaLocation", javaInstall);
|
|
|
|
if (javaInstall)
|
|
|
|
{
|
|
|
|
m_settings->set("JavaPath", ui->javaPathTextBox->text());
|
2022-03-24 13:47:22 +00:00
|
|
|
m_settings->set("IgnoreJavaCompatibility", ui->skipCompatibilityCheckbox->isChecked());
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("JavaPath");
|
2022-03-24 13:47:22 +00:00
|
|
|
m_settings->reset("IgnoreJavaCompatibility");
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Java arguments
|
|
|
|
bool javaArgs = ui->javaArgumentsGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideJavaArgs", javaArgs);
|
|
|
|
if(javaArgs)
|
|
|
|
{
|
|
|
|
m_settings->set("JvmArgs", ui->jvmArgsTextBox->toPlainText().replace("\n", " "));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("JvmArgs");
|
|
|
|
}
|
|
|
|
|
|
|
|
// old generic 'override both' is removed.
|
|
|
|
m_settings->reset("OverrideJava");
|
|
|
|
|
|
|
|
// Custom Commands
|
|
|
|
bool custcmd = ui->customCommands->checked();
|
|
|
|
m_settings->set("OverrideCommands", custcmd);
|
|
|
|
if (custcmd)
|
|
|
|
{
|
|
|
|
m_settings->set("PreLaunchCommand", ui->customCommands->prelaunchCommand());
|
|
|
|
m_settings->set("WrapperCommand", ui->customCommands->wrapperCommand());
|
|
|
|
m_settings->set("PostExitCommand", ui->customCommands->postexitCommand());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("PreLaunchCommand");
|
|
|
|
m_settings->reset("WrapperCommand");
|
|
|
|
m_settings->reset("PostExitCommand");
|
|
|
|
}
|
2020-09-10 22:10:17 +01:00
|
|
|
|
|
|
|
// Workarounds
|
|
|
|
bool workarounds = ui->nativeWorkaroundsGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideNativeWorkarounds", workarounds);
|
|
|
|
if(workarounds)
|
|
|
|
{
|
|
|
|
m_settings->set("UseNativeOpenAL", ui->useNativeOpenALCheck->isChecked());
|
|
|
|
m_settings->set("UseNativeGLFW", ui->useNativeGLFWCheck->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("UseNativeOpenAL");
|
|
|
|
m_settings->reset("UseNativeGLFW");
|
|
|
|
}
|
2020-12-09 22:16:01 +00:00
|
|
|
|
2022-06-29 21:37:25 +01:00
|
|
|
// Performance
|
|
|
|
bool performance = ui->perfomanceGroupBox->isChecked();
|
|
|
|
m_settings->set("OverridePerformance", performance);
|
|
|
|
if(performance)
|
|
|
|
{
|
|
|
|
m_settings->set("EnableFeralGamemode", ui->enableFeralGamemodeCheck->isChecked());
|
|
|
|
m_settings->set("EnableMangoHud", ui->enableMangoHud->isChecked());
|
|
|
|
m_settings->set("UseDiscreteGpu", ui->useDiscreteGpuCheck->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("EnableFeralGamemode");
|
|
|
|
m_settings->reset("EnableMangoHud");
|
|
|
|
m_settings->reset("UseDiscreteGpu");
|
|
|
|
}
|
|
|
|
|
2020-12-09 22:16:01 +00:00
|
|
|
// Game time
|
|
|
|
bool gameTime = ui->gameTimeGroupBox->isChecked();
|
|
|
|
m_settings->set("OverrideGameTime", gameTime);
|
|
|
|
if (gameTime)
|
|
|
|
{
|
|
|
|
m_settings->set("ShowGameTime", ui->showGameTime->isChecked());
|
|
|
|
m_settings->set("RecordGameTime", ui->recordGameTime->isChecked());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("ShowGameTime");
|
|
|
|
m_settings->reset("RecordGameTime");
|
|
|
|
}
|
2021-05-22 12:28:23 +01:00
|
|
|
|
|
|
|
// Join server on launch
|
|
|
|
bool joinServerOnLaunch = ui->serverJoinGroupBox->isChecked();
|
|
|
|
m_settings->set("JoinServerOnLaunch", joinServerOnLaunch);
|
|
|
|
if (joinServerOnLaunch)
|
|
|
|
{
|
|
|
|
m_settings->set("JoinServerOnLaunchAddress", ui->serverJoinAddress->text());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_settings->reset("JoinServerOnLaunchAddress");
|
|
|
|
}
|
2022-07-11 08:01:07 +01:00
|
|
|
|
2022-12-27 22:00:15 +00:00
|
|
|
// Use an account for this instance
|
|
|
|
bool useAccountForInstance = ui->instanceAccountGroupBox->isChecked();
|
|
|
|
m_settings->set("UseAccountForInstance", useAccountForInstance);
|
2023-01-02 18:16:09 +00:00
|
|
|
if (!useAccountForInstance) {
|
2022-12-27 22:00:15 +00:00
|
|
|
m_settings->reset("InstanceAccountId");
|
|
|
|
}
|
|
|
|
|
2022-07-11 08:01:07 +01:00
|
|
|
// FIXME: This should probably be called by a signal instead
|
|
|
|
m_instance->updateRuntimeContext();
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::loadSettings()
|
|
|
|
{
|
2022-05-12 22:11:06 +01:00
|
|
|
// Miscellaneous
|
|
|
|
ui->miscellaneousSettingsBox->setChecked(m_settings->get("OverrideMiscellaneous").toBool());
|
|
|
|
ui->closeAfterLaunchCheck->setChecked(m_settings->get("CloseAfterLaunch").toBool());
|
|
|
|
ui->quitAfterGameStopCheck->setChecked(m_settings->get("QuitAfterGameStop").toBool());
|
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
// Console
|
|
|
|
ui->consoleSettingsBox->setChecked(m_settings->get("OverrideConsole").toBool());
|
|
|
|
ui->showConsoleCheck->setChecked(m_settings->get("ShowConsole").toBool());
|
|
|
|
ui->autoCloseConsoleCheck->setChecked(m_settings->get("AutoCloseConsole").toBool());
|
|
|
|
ui->showConsoleErrorCheck->setChecked(m_settings->get("ShowConsoleOnError").toBool());
|
|
|
|
|
|
|
|
// Window Size
|
|
|
|
ui->windowSizeGroupBox->setChecked(m_settings->get("OverrideWindow").toBool());
|
|
|
|
ui->maximizedCheckBox->setChecked(m_settings->get("LaunchMaximized").toBool());
|
|
|
|
ui->windowWidthSpinBox->setValue(m_settings->get("MinecraftWinWidth").toInt());
|
|
|
|
ui->windowHeightSpinBox->setValue(m_settings->get("MinecraftWinHeight").toInt());
|
|
|
|
|
|
|
|
// Memory
|
|
|
|
ui->memoryGroupBox->setChecked(m_settings->get("OverrideMemory").toBool());
|
|
|
|
int min = m_settings->get("MinMemAlloc").toInt();
|
|
|
|
int max = m_settings->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(m_settings->get("PermGen").toInt());
|
2018-11-09 20:45:55 +00:00
|
|
|
bool permGenVisible = m_settings->get("PermGenVisible").toBool();
|
|
|
|
ui->permGenSpinBox->setVisible(permGenVisible);
|
|
|
|
ui->labelPermGen->setVisible(permGenVisible);
|
|
|
|
ui->labelPermgenNote->setVisible(permGenVisible);
|
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
|
|
|
|
// Java Settings
|
|
|
|
bool overrideJava = m_settings->get("OverrideJava").toBool();
|
|
|
|
bool overrideLocation = m_settings->get("OverrideJavaLocation").toBool() || overrideJava;
|
|
|
|
bool overrideArgs = m_settings->get("OverrideJavaArgs").toBool() || overrideJava;
|
|
|
|
|
|
|
|
ui->javaSettingsGroupBox->setChecked(overrideLocation);
|
|
|
|
ui->javaPathTextBox->setText(m_settings->get("JavaPath").toString());
|
2022-03-24 13:47:22 +00:00
|
|
|
ui->skipCompatibilityCheckbox->setChecked(m_settings->get("IgnoreJavaCompatibility").toBool());
|
2018-07-15 13:51:05 +01:00
|
|
|
|
|
|
|
ui->javaArgumentsGroupBox->setChecked(overrideArgs);
|
|
|
|
ui->jvmArgsTextBox->setPlainText(m_settings->get("JvmArgs").toString());
|
|
|
|
|
|
|
|
// Custom commands
|
|
|
|
ui->customCommands->initialize(
|
|
|
|
true,
|
|
|
|
m_settings->get("OverrideCommands").toBool(),
|
|
|
|
m_settings->get("PreLaunchCommand").toString(),
|
|
|
|
m_settings->get("WrapperCommand").toString(),
|
|
|
|
m_settings->get("PostExitCommand").toString()
|
|
|
|
);
|
2020-09-10 22:10:17 +01:00
|
|
|
|
|
|
|
// Workarounds
|
|
|
|
ui->nativeWorkaroundsGroupBox->setChecked(m_settings->get("OverrideNativeWorkarounds").toBool());
|
|
|
|
ui->useNativeGLFWCheck->setChecked(m_settings->get("UseNativeGLFW").toBool());
|
|
|
|
ui->useNativeOpenALCheck->setChecked(m_settings->get("UseNativeOpenAL").toBool());
|
2020-12-09 22:16:01 +00:00
|
|
|
|
2022-06-29 21:37:25 +01:00
|
|
|
// Performance
|
|
|
|
ui->perfomanceGroupBox->setChecked(m_settings->get("OverridePerformance").toBool());
|
|
|
|
ui->enableFeralGamemodeCheck->setChecked(m_settings->get("EnableFeralGamemode").toBool());
|
|
|
|
ui->enableMangoHud->setChecked(m_settings->get("EnableMangoHud").toBool());
|
|
|
|
ui->useDiscreteGpuCheck->setChecked(m_settings->get("UseDiscreteGpu").toBool());
|
|
|
|
|
2022-08-08 20:03:02 +01:00
|
|
|
#if !defined(Q_OS_LINUX)
|
2022-07-23 16:37:45 +01:00
|
|
|
ui->settingsTabs->setTabVisible(ui->settingsTabs->indexOf(ui->performancePage), false);
|
2022-08-08 20:03:02 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!(APPLICATION->capabilities() & Application::SupportsGameMode)) {
|
|
|
|
ui->enableFeralGamemodeCheck->setDisabled(true);
|
|
|
|
ui->enableFeralGamemodeCheck->setToolTip(tr("Feral Interactive's GameMode could not be found on your system."));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(APPLICATION->capabilities() & Application::SupportsMangoHud)) {
|
|
|
|
ui->enableMangoHud->setDisabled(true);
|
|
|
|
ui->enableMangoHud->setToolTip(tr("MangoHud could not be found on your system."));
|
|
|
|
}
|
2022-06-29 21:37:25 +01:00
|
|
|
|
2020-12-09 22:16:01 +00:00
|
|
|
// Miscellanous
|
|
|
|
ui->gameTimeGroupBox->setChecked(m_settings->get("OverrideGameTime").toBool());
|
|
|
|
ui->showGameTime->setChecked(m_settings->get("ShowGameTime").toBool());
|
|
|
|
ui->recordGameTime->setChecked(m_settings->get("RecordGameTime").toBool());
|
2021-05-22 12:28:23 +01:00
|
|
|
|
|
|
|
ui->serverJoinGroupBox->setChecked(m_settings->get("JoinServerOnLaunch").toBool());
|
|
|
|
ui->serverJoinAddress->setText(m_settings->get("JoinServerOnLaunchAddress").toString());
|
2022-12-27 22:00:15 +00:00
|
|
|
|
|
|
|
ui->instanceAccountGroupBox->setChecked(m_settings->get("UseAccountForInstance").toBool());
|
|
|
|
updateAccountsMenu();
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::on_javaDetectBtn_clicked()
|
|
|
|
{
|
2022-06-14 21:00:24 +01:00
|
|
|
if (JavaUtils::getJavaCheckPath().isEmpty()) {
|
|
|
|
JavaCommon::javaCheckNotFound(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
JavaInstallPtr java;
|
2014-06-09 00:29:18 +01:00
|
|
|
|
2021-11-20 15:22:22 +00:00
|
|
|
VersionSelectDialog vselect(APPLICATION->javalist().get(), tr("Select a Java version"), this, true);
|
2018-07-15 13:51:05 +01:00
|
|
|
vselect.setResizeOn(2);
|
|
|
|
vselect.exec();
|
2014-06-09 00:29:18 +01:00
|
|
|
|
2018-07-15 13:51:05 +01:00
|
|
|
if (vselect.result() == QDialog::Accepted && vselect.selectedVersion())
|
|
|
|
{
|
|
|
|
java = std::dynamic_pointer_cast<JavaInstall>(vselect.selectedVersion());
|
|
|
|
ui->javaPathTextBox->setText(java->path);
|
2018-11-09 20:45:55 +00:00
|
|
|
bool visible = java->id.requiresPermGen() && m_settings->get("OverrideMemory").toBool();
|
|
|
|
ui->permGenSpinBox->setVisible(visible);
|
|
|
|
ui->labelPermGen->setVisible(visible);
|
|
|
|
ui->labelPermgenNote->setVisible(visible);
|
|
|
|
m_settings->set("PermGenVisible", visible);
|
2018-07-15 13:51:05 +01:00
|
|
|
}
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::on_javaBrowseBtn_clicked()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
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);
|
|
|
|
|
2018-11-09 20:45:55 +00:00
|
|
|
QFileInfo javaInfo(cooked_path);
|
2018-07-15 13:51:05 +01:00
|
|
|
if(!javaInfo.exists() || !javaInfo.isExecutable())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ui->javaPathTextBox->setText(cooked_path);
|
2018-11-09 20:45:55 +00:00
|
|
|
|
|
|
|
// custom Java could be anything... enable perm gen option
|
|
|
|
ui->permGenSpinBox->setVisible(true);
|
|
|
|
ui->labelPermGen->setVisible(true);
|
|
|
|
ui->labelPermgenNote->setVisible(true);
|
|
|
|
m_settings->set("PermGenVisible", true);
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void InstanceSettingsPage::on_javaTestBtn_clicked()
|
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
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();
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
|
|
|
|
2022-12-27 22:00:15 +00:00
|
|
|
void InstanceSettingsPage::updateAccountsMenu()
|
|
|
|
{
|
2023-05-14 18:57:51 +01:00
|
|
|
ui->instanceAccountSelector->clear();
|
2022-12-27 22:00:15 +00:00
|
|
|
auto accounts = APPLICATION->accounts();
|
|
|
|
int accountIndex = accounts->findAccountByProfileId(m_settings->get("InstanceAccountId").toString());
|
|
|
|
|
2023-01-02 18:16:09 +00:00
|
|
|
for (int i = 0; i < accounts->count(); i++) {
|
2022-12-27 22:00:15 +00:00
|
|
|
MinecraftAccountPtr account = accounts->at(i);
|
2023-05-14 18:57:51 +01:00
|
|
|
ui->instanceAccountSelector->addItem(getFaceForAccount(account), account->profileName(), i);
|
|
|
|
if (i == accountIndex)
|
|
|
|
ui->instanceAccountSelector->setCurrentIndex(i);
|
2022-12-27 22:00:15 +00:00
|
|
|
}
|
2023-05-14 18:57:51 +01:00
|
|
|
|
2022-12-27 22:00:15 +00:00
|
|
|
}
|
|
|
|
|
2023-01-13 04:03:31 +00:00
|
|
|
QIcon InstanceSettingsPage::getFaceForAccount(MinecraftAccountPtr account)
|
|
|
|
{
|
|
|
|
if (auto face = account->getFace(); !face.isNull()) {
|
|
|
|
return face;
|
|
|
|
}
|
|
|
|
|
|
|
|
return APPLICATION->getThemedIcon("noaccount");
|
|
|
|
}
|
|
|
|
|
2023-05-14 18:57:51 +01:00
|
|
|
void InstanceSettingsPage::changeInstanceAccount(int index)
|
2022-12-27 22:00:15 +00:00
|
|
|
{
|
|
|
|
auto accounts = APPLICATION->accounts();
|
2023-05-14 18:57:51 +01:00
|
|
|
if (index != -1 && accounts->at(index) && ui->instanceAccountGroupBox->isChecked()) {
|
|
|
|
auto account = accounts->at(index);
|
|
|
|
m_settings->set("InstanceAccountId", account->profileId());
|
|
|
|
}
|
2022-12-27 22:00:15 +00:00
|
|
|
}
|
|
|
|
|
2022-11-11 14:02:08 +00:00
|
|
|
void InstanceSettingsPage::on_maxMemSpinBox_valueChanged(int i)
|
|
|
|
{
|
|
|
|
updateThresholds();
|
|
|
|
}
|
|
|
|
|
2015-05-04 00:20:48 +01:00
|
|
|
void InstanceSettingsPage::checkerFinished()
|
2014-06-09 00:29:18 +01:00
|
|
|
{
|
2018-07-15 13:51:05 +01:00
|
|
|
checker.reset();
|
2014-06-09 00:29:18 +01:00
|
|
|
}
|
2022-02-22 18:23:53 +00:00
|
|
|
|
|
|
|
void InstanceSettingsPage::retranslate()
|
|
|
|
{
|
|
|
|
ui->retranslateUi(this);
|
2022-03-20 20:50:30 +00:00
|
|
|
ui->customCommands->retranslate(); // TODO: why is this seperate from the others?
|
2022-02-22 18:23:53 +00:00
|
|
|
}
|
2022-11-11 14:02:08 +00:00
|
|
|
|
|
|
|
void InstanceSettingsPage::updateThresholds()
|
|
|
|
{
|
|
|
|
auto sysMiB = Sys::getSystemRam() / Sys::mebibyte;
|
|
|
|
unsigned int maxMem = ui->maxMemSpinBox->value();
|
|
|
|
|
2022-11-11 14:22:16 +00:00
|
|
|
QString iconName;
|
|
|
|
|
2022-11-11 14:02:08 +00:00
|
|
|
if (maxMem >= sysMiB) {
|
2022-11-11 14:22:16 +00:00
|
|
|
iconName = "status-bad";
|
2022-11-11 14:02:08 +00:00
|
|
|
ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation exceeds your system memory capacity."));
|
|
|
|
} else if (maxMem > (sysMiB * 0.9)) {
|
2022-11-11 14:22:16 +00:00
|
|
|
iconName = "status-yellow";
|
2022-11-11 14:02:08 +00:00
|
|
|
ui->labelMaxMemIcon->setToolTip(tr("Your maximum memory allocation approaches your system memory capacity."));
|
|
|
|
} else {
|
2022-11-11 14:22:16 +00:00
|
|
|
iconName = "status-good";
|
2022-11-11 14:02:08 +00:00
|
|
|
ui->labelMaxMemIcon->setToolTip("");
|
|
|
|
}
|
2022-11-11 14:22:16 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
auto height = ui->labelMaxMemIcon->fontInfo().pixelSize();
|
|
|
|
QIcon icon = APPLICATION->getThemedIcon(iconName);
|
|
|
|
QPixmap pix = icon.pixmap(height, height);
|
|
|
|
ui->labelMaxMemIcon->setPixmap(pix);
|
|
|
|
}
|
2022-11-11 14:02:08 +00:00
|
|
|
}
|