diff options
author | Petr Mrázek <peterix@gmail.com> | 2014-02-01 19:37:16 +0100 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2014-02-01 19:37:16 +0100 |
commit | 1936bd181f57a554ce0dd757ffe9419100eb47f4 (patch) | |
tree | a22660979335746b930c88f353b4e29f1bbe9a2a /gui/dialogs | |
parent | b4b6091372310f4a811180cffde3ea5611881e6c (diff) | |
parent | 8637cce4333aaf56a231d5fab866b0e770436783 (diff) | |
download | MultiMC-1936bd181f57a554ce0dd757ffe9419100eb47f4.tar MultiMC-1936bd181f57a554ce0dd757ffe9419100eb47f4.tar.gz MultiMC-1936bd181f57a554ce0dd757ffe9419100eb47f4.tar.lz MultiMC-1936bd181f57a554ce0dd757ffe9419100eb47f4.tar.xz MultiMC-1936bd181f57a554ce0dd757ffe9419100eb47f4.zip |
Merge branch 'feature_derpstances' of https://github.com/02JanDal/MultiMC5 into feature_derpstances
Conflicts:
gui/dialogs/OneSixModEditDialog.cpp
logic/OneSixUpdate.cpp
Diffstat (limited to 'gui/dialogs')
-rw-r--r-- | gui/dialogs/OneSixModEditDialog.cpp | 149 | ||||
-rw-r--r-- | gui/dialogs/OneSixModEditDialog.h | 7 | ||||
-rw-r--r-- | gui/dialogs/OneSixModEditDialog.ui | 53 |
3 files changed, 87 insertions, 122 deletions
diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp index 27315c69..1742ff80 100644 --- a/gui/dialogs/OneSixModEditDialog.cpp +++ b/gui/dialogs/OneSixModEditDialog.cpp @@ -55,7 +55,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) main_model->setSourceModel(m_version.get()); ui->libraryTreeView->setModel(main_model); ui->libraryTreeView->installEventFilter(this); - ui->mainClassEdit->setText(m_version->mainClass); + connect(ui->libraryTreeView->selectionModel(), &QItemSelectionModel::currentChanged, + this, &OneSixModEditDialog::versionCurrent); updateVersionControls(); } else @@ -81,6 +82,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent) ui->resPackTreeView->installEventFilter(this); m_resourcepacks->startWatching(); } + + connect(m_inst, &OneSixInstance::versionReloaded, this, &OneSixModEditDialog::updateVersionControls); } OneSixModEditDialog::~OneSixModEditDialog() @@ -92,98 +95,76 @@ OneSixModEditDialog::~OneSixModEditDialog() void OneSixModEditDialog::updateVersionControls() { - bool customVersion = m_inst->versionIsCustom(); - ui->customizeBtn->setEnabled(!customVersion); - ui->revertBtn->setEnabled(customVersion); ui->forgeBtn->setEnabled(true); - ui->liteloaderBtn->setEnabled(LiteLoaderInstaller(m_inst->intendedVersionId()).canApply()); - ui->customEditorBtn->setEnabled(customVersion); + ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst)); + ui->mainClassEdit->setText(m_version->mainClass); } void OneSixModEditDialog::disableVersionControls() { - ui->customizeBtn->setEnabled(false); - ui->revertBtn->setEnabled(false); ui->forgeBtn->setEnabled(false); ui->liteloaderBtn->setEnabled(false); - ui->customEditorBtn->setEnabled(false); + ui->reloadLibrariesBtn->setEnabled(false); + ui->removeLibraryBtn->setEnabled(false); + ui->mainClassEdit->setText(""); } -void OneSixModEditDialog::on_customizeBtn_clicked() +void OneSixModEditDialog::on_userEditorBtn_clicked() { - if (m_inst->customizeVersion()) + QDir root(m_inst->instanceRoot()); + if (!root.exists("user.json")) { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); + QFile file(root.absoluteFilePath("user.json")); + if (!file.open(QFile::WriteOnly)) + { + QMessageBox::critical(this, tr("Error"), tr("Couldn't write a skeletion user.json file: %1").arg(file.errorString())); + return; + } + file.write("{\n}"); + file.close(); + } + if (!MMC->openJsonEditor(root.absoluteFilePath("user.json"))) + { + QMessageBox::warning(this, tr("Error"), tr("Unable to open user.json, check the settings")); } } -void OneSixModEditDialog::on_revertBtn_clicked() +void OneSixModEditDialog::on_reloadLibrariesBtn_clicked() { - auto response = CustomMessageBox::selectable( - this, tr("Revert?"), tr("Do you want to revert the " - "version of this instance to its original configuration?"), - QMessageBox::Question, QMessageBox::Yes | QMessageBox::No)->exec(); - if (response == QMessageBox::Yes) - { - if (m_inst->revertCustomVersion()) - { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } - } + m_inst->reloadVersion(this); } -void OneSixModEditDialog::on_customEditorBtn_clicked() +void OneSixModEditDialog::on_removeLibraryBtn_clicked() { - if (m_inst->versionIsCustom()) + if (ui->libraryTreeView->currentIndex().isValid()) { - if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json")) + if (!m_version->remove(ui->libraryTreeView->currentIndex().row())) + { + QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file")); + } + else { - QMessageBox::warning(this, tr("Error"), - tr("Unable to open custom.json, check the settings")); + m_inst->reloadVersion(this); } } } void OneSixModEditDialog::on_forgeBtn_clicked() { + if (QDir(m_inst->instanceRoot()).exists("custom.json")) + { + if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes) + { + return; + } + QDir(m_inst->instanceRoot()).remove("custom.json"); + } VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this); vselect.setFilter(1, m_inst->currentVersionId()); vselect.setEmptyString(tr("No Forge versions are currently available for Minecraft ") + m_inst->currentVersionId()); if (vselect.exec() && vselect.selectedVersion()) { - if (m_inst->versionIsCustom()) - { - auto reply = QMessageBox::question( - this, tr("Revert?"), - tr("This will revert any " - "changes you did to the version up to this point. Is that " - "OK?"), - QMessageBox::Yes | QMessageBox::No); - if (reply == QMessageBox::Yes) - { - m_inst->revertCustomVersion(); - m_inst->customizeVersion(); - { - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } - } - else - return; - } - else - { - m_inst->customizeVersion(); - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } ForgeVersionPtr forgeVersion = std::dynamic_pointer_cast<ForgeVersion>(vselect.selectedVersion()); if (!forgeVersion) @@ -200,9 +181,9 @@ void OneSixModEditDialog::on_forgeBtn_clicked() // install QString forgePath = entry->getFullPath(); ForgeInstaller forge(forgePath, forgeVersion->universal_url); - if (!forge.apply(m_version)) + if (!forge.add(m_inst)) { - // failure notice + QLOG_ERROR() << "Failure installing forge"; } } else @@ -215,18 +196,27 @@ void OneSixModEditDialog::on_forgeBtn_clicked() // install QString forgePath = entry->getFullPath(); ForgeInstaller forge(forgePath, forgeVersion->universal_url); - if (!forge.apply(m_version)) + if (!forge.add(m_inst)) { - // failure notice + QLOG_ERROR() << "Failure installing forge"; } } } + m_inst->reloadVersion(this); } void OneSixModEditDialog::on_liteloaderBtn_clicked() { - LiteLoaderInstaller liteloader(m_inst->intendedVersionId()); - if (!liteloader.canApply()) + if (QDir(m_inst->instanceRoot()).exists("custom.json")) + { + if (QMessageBox::question(this, tr("Revert?"), tr("This action will remove your custom.json. Continue?")) != QMessageBox::Yes) + { + return; + } + QDir(m_inst->instanceRoot()).remove("custom.json"); + } + LiteLoaderInstaller liteloader; + if (!liteloader.canApply(m_inst)) { QMessageBox::critical( this, tr("LiteLoader"), @@ -234,19 +224,16 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked() "into this version of Minecraft")); return; } - if (!m_inst->versionIsCustom()) - { - m_inst->customizeVersion(); - m_version = m_inst->getFullVersion(); - main_model->setSourceModel(m_version.get()); - updateVersionControls(); - } - if (!liteloader.apply(m_version)) + if (!liteloader.add(m_inst)) { QMessageBox::critical(this, tr("LiteLoader"), tr("For reasons unknown, the LiteLoader installation failed. " "Check your MultiMC log files for details.")); } + else + { + m_inst->reloadVersion(this); + } } bool OneSixModEditDialog::loaderListFilter(QKeyEvent *keyEvent) @@ -365,3 +352,15 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou Mod &m = m_mods->operator[](row); ui->frame->updateWithMod(m); } + +void OneSixModEditDialog::versionCurrent(const QModelIndex ¤t, const QModelIndex &previous) +{ + if (!current.isValid()) + { + ui->removeLibraryBtn->setDisabled(true); + } + else + { + ui->removeLibraryBtn->setEnabled(m_version->canRemove(current.row())); + } +} diff --git a/gui/dialogs/OneSixModEditDialog.h b/gui/dialogs/OneSixModEditDialog.h index 2510c59c..7e759f48 100644 --- a/gui/dialogs/OneSixModEditDialog.h +++ b/gui/dialogs/OneSixModEditDialog.h @@ -45,9 +45,9 @@ slots: void on_buttonBox_rejected(); void on_forgeBtn_clicked(); void on_liteloaderBtn_clicked(); - void on_customizeBtn_clicked(); - void on_revertBtn_clicked(); - void on_customEditorBtn_clicked(); + void on_userEditorBtn_clicked(); + void on_reloadLibrariesBtn_clicked(); + void on_removeLibraryBtn_clicked(); void updateVersionControls(); void disableVersionControls(); @@ -66,4 +66,5 @@ private: public slots: void loaderCurrent(QModelIndex current, QModelIndex previous); + void versionCurrent(const QModelIndex ¤t, const QModelIndex &previous); }; diff --git a/gui/dialogs/OneSixModEditDialog.ui b/gui/dialogs/OneSixModEditDialog.ui index 899e0cbf..d90c6d93 100644 --- a/gui/dialogs/OneSixModEditDialog.ui +++ b/gui/dialogs/OneSixModEditDialog.ui @@ -26,7 +26,7 @@ </size> </property> <property name="currentIndex"> - <number>1</number> + <number>0</number> </property> <widget class="QWidget" name="libTab"> <attribute name="title"> @@ -43,6 +43,9 @@ <property name="horizontalScrollBarPolicy"> <enum>Qt::ScrollBarAlwaysOff</enum> </property> + <attribute name="headerVisible"> + <bool>true</bool> + </attribute> </widget> </item> <item> @@ -85,61 +88,23 @@ </widget> </item> <item> - <widget class="QPushButton" name="customizeBtn"> - <property name="toolTip"> - <string>Create an customized copy of the base version</string> - </property> - <property name="text"> - <string>Customize</string> - </property> - </widget> - </item> - <item> - <widget class="QPushButton" name="revertBtn"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="toolTip"> - <string>Revert to original base version</string> - </property> - <property name="text"> - <string>Revert</string> - </property> - </widget> - </item> - <item> <widget class="Line" name="line"> - <property name="frameShadow"> - <enum>QFrame::Sunken</enum> - </property> <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> <item> - <widget class="QPushButton" name="addLibraryBtn"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="toolTip"> - <string>Add new libraries</string> - </property> + <widget class="QPushButton" name="reloadLibrariesBtn"> <property name="text"> - <string>&Add</string> + <string>Reload</string> </property> </widget> </item> <item> <widget class="QPushButton" name="removeLibraryBtn"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="toolTip"> - <string>Remove selected libraries</string> - </property> <property name="text"> - <string>&Remove</string> + <string>Remove</string> </property> </widget> </item> @@ -151,9 +116,9 @@ </widget> </item> <item> - <widget class="QPushButton" name="customEditorBtn"> + <widget class="QPushButton" name="userEditorBtn"> <property name="text"> - <string>Open custom.json</string> + <string>Open user.json</string> </property> </widget> </item> |