diff options
-rw-r--r-- | gui/LegacyModEditDialog.cpp | 1 | ||||
-rw-r--r-- | gui/OneSixModEditDialog.cpp | 85 | ||||
-rw-r--r-- | gui/OneSixModEditDialog.h | 5 | ||||
-rw-r--r-- | gui/OneSixModEditDialog.ui | 9 | ||||
-rw-r--r-- | logic/OneSixInstance.cpp | 24 | ||||
-rw-r--r-- | logic/OneSixInstance.h | 4 | ||||
-rw-r--r-- | logic/lists/ForgeVersionList.cpp | 4 |
7 files changed, 124 insertions, 8 deletions
diff --git a/gui/LegacyModEditDialog.cpp b/gui/LegacyModEditDialog.cpp index ac7f7f25..1a1198b1 100644 --- a/gui/LegacyModEditDialog.cpp +++ b/gui/LegacyModEditDialog.cpp @@ -230,7 +230,6 @@ void LegacyModEditDialog::on_addForgeBtn_clicked() m_jarmods->installMod(QFileInfo(entry->getFullPath())); m_jarmods->startWatching(); } - //m_selectedInstance->setIntendedVersionId(->descriptor()); } } void LegacyModEditDialog::on_addJarBtn_clicked() diff --git a/gui/OneSixModEditDialog.cpp b/gui/OneSixModEditDialog.cpp index fad9d2e2..7cbb9cbd 100644 --- a/gui/OneSixModEditDialog.cpp +++ b/gui/OneSixModEditDialog.cpp @@ -21,9 +21,11 @@ #include "logic/EnabledItemFilter.h" #include "logic/lists/ForgeVersionList.h" #include "gui/versionselectdialog.h" +#include "ProgressDialog.h" #include <pathutils.h> #include <QFileDialog> +#include <QMessageBox> #include <QDebug> #include <QEvent> #include <QKeyEvent> @@ -38,11 +40,13 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance * inst, QWidget *parent) { m_version = m_inst->getFullVersion(); - auto filter = new EnabledItemFilter(this); - filter->setActive(true); - filter->setSourceModel(m_version.data()); - ui->libraryTreeView->setModel(filter); + main_model = new EnabledItemFilter(this); + main_model->setActive(true); + main_model->setSourceModel(m_version.data()); + ui->libraryTreeView->setModel(main_model); ui->libraryTreeView->installEventFilter( this ); + ui->mainClassEdit->setText(m_version->mainClass); + updateButtons(); } // Loader mods { @@ -69,17 +73,86 @@ OneSixModEditDialog::~OneSixModEditDialog() delete ui; } +void OneSixModEditDialog::updateButtons() +{ + bool customVersion = m_inst->versionIsCustom(); + ui->customizeBtn->setEnabled(!customVersion); + ui->revertBtn->setEnabled(customVersion); +} + + +void OneSixModEditDialog::on_customizeBtn_clicked() +{ + if(m_inst->customizeVersion()) + { + m_version = m_inst->getFullVersion(); + main_model->setSourceModel(m_version.data()); + updateButtons(); + } +} + +void OneSixModEditDialog::on_revertBtn_clicked() +{ + auto reply = QMessageBox::question(this, tr("Revert?"), tr("Do you want to revert the version of this instance to its original configuration?"),QMessageBox::Yes|QMessageBox::No); + if (reply == QMessageBox::Yes) + { + if(m_inst->revertCustomVersion()) + { + m_version = m_inst->getFullVersion(); + main_model->setSourceModel(m_version.data()); + updateButtons(); + } + } +} + + void OneSixModEditDialog::on_forgeBtn_clicked() { VersionSelectDialog vselect(MMC->forgelist(), this); vselect.setFilter(1, m_inst->currentVersionId()); if (vselect.exec() && vselect.selectedVersion()) { - //m_selectedInstance->setIntendedVersionId(vselect.selectedVersion()->descriptor()); + 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.data()); + updateButtons(); + } + } + else return; + } + ForgeVersionPtr forge = vselect.selectedVersion().dynamicCast<ForgeVersion>(); + if(!forge) + return; + auto entry = MMC->metacache()->resolveEntry("minecraftforge", forge->filename); + if(entry->stale) + { + DownloadJob * fjob = new DownloadJob("Forge download"); + fjob->add(forge->universal_url, entry); + ProgressDialog dlg(this); + dlg.exec(fjob); + if(dlg.result() == QDialog::Accepted) + { + // install + } + else + { + // failed to download forge :/ + } + } + else + { + // install + } } } - bool OneSixModEditDialog::loaderListFilter ( QKeyEvent* keyEvent ) { switch(keyEvent->key()) diff --git a/gui/OneSixModEditDialog.h b/gui/OneSixModEditDialog.h index d14c842c..714c911a 100644 --- a/gui/OneSixModEditDialog.h +++ b/gui/OneSixModEditDialog.h @@ -18,6 +18,7 @@ #include <logic/OneSixInstance.h> +class EnabledItemFilter; namespace Ui { class OneSixModEditDialog; } @@ -41,6 +42,9 @@ private slots: // Questionable: SettingsDialog doesn't need this for some reason? void on_buttonBox_rejected(); void on_forgeBtn_clicked(); + void on_customizeBtn_clicked(); + void on_revertBtn_clicked(); + void updateButtons(); protected: bool eventFilter(QObject *obj, QEvent *ev); bool loaderListFilter( QKeyEvent* ev ); @@ -50,5 +54,6 @@ private: QSharedPointer<OneSixVersion> m_version; QSharedPointer<ModList> m_mods; QSharedPointer<ModList> m_resourcepacks; + EnabledItemFilter * main_model; OneSixInstance * m_inst; }; diff --git a/gui/OneSixModEditDialog.ui b/gui/OneSixModEditDialog.ui index aadaf3ae..527899ca 100644 --- a/gui/OneSixModEditDialog.ui +++ b/gui/OneSixModEditDialog.ui @@ -55,7 +55,11 @@ </widget> </item> <item> - <widget class="QLineEdit" name="mainClassEdit"/> + <widget class="QLineEdit" name="mainClassEdit"> + <property name="enabled"> + <bool>false</bool> + </property> + </widget> </item> </layout> </item> @@ -85,6 +89,9 @@ </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> diff --git a/logic/OneSixInstance.cpp b/logic/OneSixInstance.cpp index 7b038c46..8124b4a0 100644 --- a/logic/OneSixInstance.cpp +++ b/logic/OneSixInstance.cpp @@ -226,6 +226,30 @@ QString OneSixInstance::currentVersionId() const return intendedVersionId(); } +bool OneSixInstance::customizeVersion() +{ + if(!versionIsCustom()) + { + auto pathCustom = PathCombine(instanceRoot(), "custom.json"); + auto pathOrig = PathCombine(instanceRoot(), "version.json"); + QFile::copy(pathOrig, pathCustom); + return reloadFullVersion(); + } + else return true; +} + +bool OneSixInstance::revertCustomVersion() +{ + if(versionIsCustom()) + { + auto path = PathCombine(instanceRoot(), "custom.json"); + QFile::remove(path); + return reloadFullVersion(); + } + else return true; +} + + bool OneSixInstance::reloadFullVersion() { I_D(OneSixInstance); diff --git a/logic/OneSixInstance.h b/logic/OneSixInstance.h index 72bde630..0139b645 100644 --- a/logic/OneSixInstance.h +++ b/logic/OneSixInstance.h @@ -41,6 +41,10 @@ public: bool reloadFullVersion(); /// get the current full version info QSharedPointer<OneSixVersion> getFullVersion(); + /// revert the current custom version back to base + bool revertCustomVersion(); + /// customize the current base version + bool customizeVersion(); /// is the current version original, or custom? bool versionIsCustom(); diff --git a/logic/lists/ForgeVersionList.cpp b/logic/lists/ForgeVersionList.cpp index 412c04fe..492849ee 100644 --- a/logic/lists/ForgeVersionList.cpp +++ b/logic/lists/ForgeVersionList.cpp @@ -220,6 +220,7 @@ void ForgeListLoadTask::list_downloaded() QJsonArray files = obj.value("files").toArray(); QString url, jobbuildver, mcver, buildtype, filename; QString changelog_url, installer_url; + QString installer_filename; bool valid = false; for(int j = 0; j < files.count(); j++) { @@ -246,6 +247,8 @@ void ForgeListLoadTask::list_downloaded() else if(buildtype == "installer") { installer_url = file.value("url").toString(); + int lastSlash = installer_url.lastIndexOf('/'); + installer_filename = installer_url.mid(lastSlash+1); } } if(valid) @@ -258,6 +261,7 @@ void ForgeListLoadTask::list_downloaded() fVersion->jobbuildver = jobbuildver; fVersion->mcver = mcver; fVersion->filename = filename; + fVersion->filename = installer_filename; fVersion->m_buildnr = build_nr; tempList.append(fVersion); } |