From a25bedd7706b14cdae91556e4a577e410745f29a Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 28 Jan 2013 15:35:09 -0600 Subject: Implemented settings dialog. --- gui/settingsdialog.cpp | 112 +++++++++++++++++++++++++++++++++++++++++++++++-- gui/settingsdialog.h | 7 ++++ gui/settingsdialog.ui | 107 +++++++++++----------------------------------- 3 files changed, 139 insertions(+), 87 deletions(-) (limited to 'gui') diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index 46569340..ab4d18ee 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -16,13 +16,19 @@ #include "settingsdialog.h" #include "ui_settingsdialog.h" +#include "data/appsettings.h" + #include +#include SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent), ui(new Ui::SettingsDialog) { ui->setupUi(this); + + loadSettings(settings); + updateCheckboxStuff(); } SettingsDialog::~SettingsDialog() @@ -32,10 +38,10 @@ SettingsDialog::~SettingsDialog() void SettingsDialog::updateCheckboxStuff() { - ui->minMemSpinBox->setEnabled(!(ui->compatModeCheckBox->isChecked() || - ui->maximizedCheckBox->isChecked())); - ui->maxMemSpinBox->setEnabled(!(ui->compatModeCheckBox->isChecked() || - ui->maximizedCheckBox->isChecked())); + ui->windowWidthSpinBox->setEnabled(!(ui->compatModeCheckBox->isChecked() || + ui->maximizedCheckBox->isChecked())); + ui->windowHeightSpinBox->setEnabled(!(ui->compatModeCheckBox->isChecked() || + ui->maximizedCheckBox->isChecked())); ui->maximizedCheckBox->setEnabled(!ui->compatModeCheckBox->isChecked()); } @@ -75,3 +81,101 @@ void SettingsDialog::on_maximizedCheckBox_clicked(bool checked) Q_UNUSED(checked); updateCheckboxStuff(); } + +void SettingsDialog::on_buttonBox_accepted() +{ + applySettings(settings); +} + +void SettingsDialog::applySettings(SettingsBase *s) +{ + // Special cases + + // Warn about dev builds. + if (!ui->devBuildsCheckBox->isChecked()) + { + s->setUseDevBuilds(false); + } + else if (!s->getUseDevBuilds()) + { + int response = QMessageBox::question(this, "Development builds", + "Development builds contain experimental features " + "and may be unstable. Are you sure you want to enable them?"); + if (response == QMessageBox::Yes) + { + s->setUseDevBuilds(true); + } + } + + + // Updates + s->setAutoUpdate(ui->autoUpdateCheckBox->isChecked()); + + // Folders + // TODO: Offer to move instances to new instance folder. + s->setInstanceDir(ui->instDirTextBox->text()); + s->setCentralModsDir(ui->modsDirTextBox->text()); + s->setLWJGLDir(ui->lwjglDirTextBox->text()); + + // Console + s->setShowConsole(ui->showConsoleCheck->isChecked()); + s->setAutoCloseConsole(ui->autoCloseConsoleCheck->isChecked()); + + // Window Size + s->setLaunchCompatMode(ui->compatModeCheckBox->isChecked()); + s->setLaunchMaximized(ui->maximizedCheckBox->isChecked()); + s->setMinecraftWinWidth(ui->windowWidthSpinBox->value()); + s->setMinecraftWinHeight(ui->windowHeightSpinBox->value()); + + // Auto Login + s->setAutoLogin(ui->autoLoginCheckBox->isChecked()); + + // Memory + s->setMinMemAlloc(ui->minMemSpinBox->value()); + s->setMaxMemAlloc(ui->maxMemSpinBox->value()); + + // Java Settings + s->setJavaPath(ui->javaPathTextBox->text()); + s->setJvmArgs(ui->jvmArgsTextBox->text()); + + // Custom Commands + s->setPreLaunchCommand(ui->preLaunchCmdTextBox->text()); + s->setPostExitCommand(ui->postExitCmdTextBox->text()); +} + +void SettingsDialog::loadSettings(SettingsBase *s) +{ + // Updates + ui->autoUpdateCheckBox->setChecked(s->getAutoUpdate()); + ui->devBuildsCheckBox->setChecked(s->getUseDevBuilds()); + + // Folders + ui->instDirTextBox->setText(s->getInstanceDir()); + ui->modsDirTextBox->setText(s->getCentralModsDir()); + ui->lwjglDirTextBox->setText(s->getLWJGLDir()); + + // Console + ui->showConsoleCheck->setChecked(s->getShowConsole()); + ui->autoCloseConsoleCheck->setChecked(s->getAutoCloseConsole()); + + // Window Size + ui->compatModeCheckBox->setChecked(s->getLaunchCompatMode()); + ui->maximizedCheckBox->setChecked(s->getLaunchMaximized()); + ui->windowWidthSpinBox->setValue(s->getMinecraftWinWidth()); + ui->windowHeightSpinBox->setValue(s->getMinecraftWinHeight()); + + // Auto Login + ui->autoLoginCheckBox->setChecked(s->getAutoLogin()); + + // Memory + ui->minMemSpinBox->setValue(s->getMinMemAlloc()); + ui->maxMemSpinBox->setValue(s->getMaxMemAlloc()); + + // Java Settings + ui->javaPathTextBox->setText(s->getJavaPath()); + ui->jvmArgsTextBox->setText(s->getJvmArgs()); + + // Custom Commands + ui->preLaunchCmdTextBox->setText(s->getPreLaunchCommand()); + ui->postExitCmdTextBox->setText(s->getPostExitCommand()); +} diff --git a/gui/settingsdialog.h b/gui/settingsdialog.h index 3e9d9e0f..e223237f 100644 --- a/gui/settingsdialog.h +++ b/gui/settingsdialog.h @@ -18,6 +18,8 @@ #include +class SettingsBase; + namespace Ui { class SettingsDialog; } @@ -32,6 +34,9 @@ public: void updateCheckboxStuff(); + void applySettings(SettingsBase* s); + void loadSettings(SettingsBase* s); + private slots: void on_instDirBrowseBtn_clicked(); @@ -43,6 +48,8 @@ private slots: void on_maximizedCheckBox_clicked(bool checked); + void on_buttonBox_accepted(); + private: Ui::SettingsDialog *ui; }; diff --git a/gui/settingsdialog.ui b/gui/settingsdialog.ui index 315686ca..d30f56bb 100644 --- a/gui/settingsdialog.ui +++ b/gui/settingsdialog.ui @@ -158,88 +158,6 @@ - - - Console - - - - - - Console Settings - - - - - - Show console while the game is running? - - - - - - - Automatically close console when the game quits? - - - - - - - - - - Instance Console Colors - - - - - - System message color: - - - - - - - - - - Output message color: - - - - - - - - - - Error message color: - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - Minecraft @@ -315,10 +233,33 @@ + + + + Console Settings + + + + + + Show console while the game is running? + + + + + + + Automatically close console when the game quits? + + + + + + - Login automatically when an instance launches? + Login automatically when an instance icon is double clicked? -- cgit v1.2.3