This commit is contained in:
Petr Mrázek 2020-09-03 02:42:03 +02:00
parent 4ab7091318
commit 8d1ea8ebc8
4 changed files with 76 additions and 92 deletions

View File

@ -5,6 +5,7 @@
#include "pages/BasePage.h"
#include "pages/BasePageProvider.h"
#include "pages/instance/LogPage.h"
#include "pages/instance/ModpackPage.h"
#include "pages/instance/VersionPage.h"
#include "pages/instance/ModFolderPage.h"
#include "pages/instance/ResourcePackPage.h"
@ -50,6 +51,7 @@ public:
// values.append(new GameOptionsPage(onesix.get()));
values.append(new ScreenshotsPage(FS::PathCombine(onesix->gameRoot(), "screenshots")));
values.append(new InstanceSettingsPage(onesix.get()));
values.append(new ModpackPage(onesix.get()));
}
std::shared_ptr<LegacyInstance> legacy = std::dynamic_pointer_cast<LegacyInstance>(inst);
if(legacy)

View File

@ -18,7 +18,42 @@ ModpackPage::ModpackPage(BaseInstance *inst, QWidget *parent)
{
ui->setupUi(this);
connect(ui->activateUIButton, &QCommandLinkButton::clicked, this, &ModpackPage::activateUIClicked);
connect(ui->modpackCheck, &QCheckBox::stateChanged, this, &ModpackPage::updateState);
connect(ui->javaArgumentsGroupBox, &QGroupBox::toggled, this, &ModpackPage::updateState);
connect(ui->repositoryCheck, &QCheckBox::stateChanged, this, &ModpackPage::updateState);
connect(ui->coordinateCheck, &QCheckBox::stateChanged, this, &ModpackPage::updateState);
connect(ui->maxMemCheck, &QCheckBox::stateChanged, this, &ModpackPage::updateState);
connect(ui->minMemCheck, &QCheckBox::stateChanged, this, &ModpackPage::updateState);
connect(ui->optMemCheck, &QCheckBox::stateChanged, this, &ModpackPage::updateState);
loadSettings();
updateState();
}
void ModpackPage::updateState()
{
bool enabled = uiActivated && ui->modpackCheck->isChecked();
ui->modpackCheck->setEnabled(uiActivated);
ui->platformComboBox->setEnabled(enabled);
ui->javaArgumentsGroupBox->setEnabled(enabled);
ui->jvmArgsTextBox->setEnabled(enabled && ui->javaArgumentsGroupBox->isChecked());
ui->repositoryCheck->setEnabled(enabled);
ui->repositoryEdit->setEnabled(enabled && ui->repositoryCheck->isChecked());
ui->coordinateCheck->setEnabled(enabled);
ui->coordinateEdit->setEnabled(enabled && ui->coordinateCheck->isChecked());
ui->maxMemCheck->setEnabled(enabled);
ui->maxMemSpinBox->setEnabled(enabled && ui->maxMemCheck->isChecked());
ui->minMemCheck->setEnabled(enabled);
ui->minMemSpinBox->setEnabled(enabled && ui->minMemCheck->isChecked());
ui->optMemCheck->setEnabled(enabled);
ui->optMemSpinBox->setEnabled(enabled && ui->optMemCheck->isChecked());
}
bool ModpackPage::shouldDisplay() const
@ -33,7 +68,9 @@ ModpackPage::~ModpackPage()
void ModpackPage::activateUIClicked(bool)
{
uiActivated = true;
ui->activateUIButton->setHidden(true);
updateState();
}
bool ModpackPage::apply()
@ -46,103 +83,50 @@ void ModpackPage::applySettings()
{
PackProfileModpackInfo out;
out.hasValue = ui->modpackCheck->isChecked();
// FIXME: add a layer of indirection here
if(out.hasValue) {
out.platform = ui->platformComboBox->currentText();
if(ui->javaArgumentsGroupBox->isChecked()) {
out.recommendedArgs = ui->jvmArgsTextBox->toPlainText();
}
if(ui->repositoryCheck->isChecked()) {
out.repository = ui->repositoryEdit->text();
}
if(ui->coordinateCheck->isChecked()) {
out.coordinate = ui->coordinateEdit->text();
}
if(ui->maxMemCheck->isChecked()) {
out.maxHeap = ui->maxMemSpinBox->value();
}
if(ui->mimMemCheck->isChecked()) {
out.minHeap = ui->minMemSpinBox->value();
}
if(ui->optMemCheck->isChecked()) {
out.optimalHeap = ui->optMemSpinBox->value();
}
out.platform = ui->platformComboBox->currentText();
if(ui->javaArgumentsGroupBox->isChecked()) {
out.recommendedArgs = ui->jvmArgsTextBox->toPlainText();
}
/*
struct PackProfileModpackInfo
{
operator bool() const {
return hasValue;
if(ui->repositoryCheck->isChecked()) {
out.repository = ui->repositoryEdit->text();
}
if(ui->coordinateCheck->isChecked()) {
out.coordinate = ui->coordinateEdit->text();
}
if(ui->maxMemCheck->isChecked()) {
out.maxHeap = ui->maxMemSpinBox->value();
}
if(ui->minMemCheck->isChecked()) {
out.minHeap = ui->minMemSpinBox->value();
}
if(ui->optMemCheck->isChecked()) {
out.optimalHeap = ui->optMemSpinBox->value();
}
bool hasValue = false;
QString platform;
QString repository;
QString coordinate;
MaybeInt minHeap;
MaybeInt optimalHeap;
MaybeInt maxHeap;
QString recommendedArgs;
};
*/
}
void ModpackPage::loadSettings()
{
PackProfileModpackInfo in;
// 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());
ui->modpackCheck->setChecked(in.hasValue);
// FIXME: validate?
ui->platformComboBox->setCurrentText(in.platform);
// 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());
ui->javaArgumentsGroupBox->setChecked(!in.recommendedArgs.isNull());
ui->jvmArgsTextBox->setPlainText(in.recommendedArgs);
// 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());
bool permGenVisible = m_settings->get("PermGenVisible").toBool();
ui->permGenSpinBox->setVisible(permGenVisible);
ui->labelPermGen->setVisible(permGenVisible);
ui->labelPermgenNote->setVisible(permGenVisible);
ui->repositoryCheck->setChecked(!in.repository.isNull());
ui->repositoryEdit->setText(in.repository);
ui->coordinateCheck->setChecked(!in.coordinate.isNull());
ui->coordinateEdit->setText(in.coordinate);
// 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->maxMemCheck->setChecked(in.maxHeap);
ui->maxMemSpinBox->setValue(in.maxHeap.get());
ui->javaSettingsGroupBox->setChecked(overrideLocation);
ui->javaPathTextBox->setText(m_settings->get("JavaPath").toString());
ui->minMemCheck->setChecked(in.minHeap);
ui->minMemSpinBox->setValue(in.minHeap.get());
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()
);
ui->optMemCheck->setChecked(in.optimalHeap);
ui->optMemSpinBox->setValue(in.optimalHeap.get());
}

View File

@ -55,16 +55,14 @@ public:
virtual bool shouldDisplay() const override;
private slots:
void on_javaDetectBtn_clicked();
void on_javaTestBtn_clicked();
void on_javaBrowseBtn_clicked();
void applySettings();
void loadSettings();
void activateUIClicked(bool checked);
void updateState();
private:
Ui::ModpackPage *ui;
BaseInstance *m_instance;
bool uiActivated = false;
};

View File

@ -104,7 +104,7 @@
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QCheckBox" name="mimMemCheck">
<widget class="QCheckBox" name="minMemCheck">
<property name="text">
<string>Minimum memory allocation:</string>
</property>
@ -239,7 +239,7 @@
<tabstop>repositoryEdit</tabstop>
<tabstop>coordinateCheck</tabstop>
<tabstop>coordinateEdit</tabstop>
<tabstop>mimMemCheck</tabstop>
<tabstop>minMemCheck</tabstop>
<tabstop>minMemSpinBox</tabstop>
<tabstop>maxMemCheck</tabstop>
<tabstop>maxMemSpinBox</tabstop>