summaryrefslogtreecommitdiffstats
path: root/gui/dialogs/OneSixModEditDialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gui/dialogs/OneSixModEditDialog.cpp')
-rw-r--r--gui/dialogs/OneSixModEditDialog.cpp174
1 files changed, 55 insertions, 119 deletions
diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp
index fe621a9a..78585a05 100644
--- a/gui/dialogs/OneSixModEditDialog.cpp
+++ b/gui/dialogs/OneSixModEditDialog.cpp
@@ -34,7 +34,7 @@
#include "gui/dialogs/ProgressDialog.h"
#include "logic/ModList.h"
-#include "logic/OneSixVersion.h"
+#include "logic/VersionFinal.h"
#include "logic/EnabledItemFilter.h"
#include "logic/lists/ForgeVersionList.h"
#include "logic/lists/LiteLoaderVersionList.h"
@@ -42,8 +42,7 @@
#include "logic/LiteLoaderInstaller.h"
#include "logic/OneSixVersionBuilder.h"
-template<typename A, typename B>
-QMap<A, B> invert(const QMap<B, A> &in)
+template <typename A, typename B> QMap<A, B> invert(const QMap<B, A> &in)
{
QMap<A, B> out;
for (auto it = in.begin(); it != in.end(); ++it)
@@ -96,7 +95,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
m_resourcepacks->startWatching();
}
- connect(m_inst, &OneSixInstance::versionReloaded, this, &OneSixModEditDialog::updateVersionControls);
+ connect(m_inst, &OneSixInstance::versionReloaded, this,
+ &OneSixModEditDialog::updateVersionControls);
}
OneSixModEditDialog::~OneSixModEditDialog()
@@ -110,7 +110,6 @@ void OneSixModEditDialog::updateVersionControls()
{
ui->forgeBtn->setEnabled(true);
ui->liteloaderBtn->setEnabled(true);
- ui->mainClassEdit->setText(m_version->mainClass);
}
void OneSixModEditDialog::disableVersionControls()
@@ -119,125 +118,86 @@ void OneSixModEditDialog::disableVersionControls()
ui->liteloaderBtn->setEnabled(false);
ui->reloadLibrariesBtn->setEnabled(false);
ui->removeLibraryBtn->setEnabled(false);
- ui->mainClassEdit->setText("");
+}
+
+bool OneSixModEditDialog::reloadInstanceVersion()
+{
+ try
+ {
+ m_inst->reloadVersion();
+ return true;
+ }
+ catch (MMCError &e)
+ {
+ QMessageBox::critical(this, tr("Error"), e.cause());
+ return false;
+ }
+ catch (...)
+ {
+ QMessageBox::critical(
+ this, tr("Error"),
+ tr("Failed to load the version description file for reasons unknown."));
+ return false;
+ }
}
void OneSixModEditDialog::on_reloadLibrariesBtn_clicked()
{
- m_inst->reloadVersion(this);
+ reloadInstanceVersion();
}
void OneSixModEditDialog::on_removeLibraryBtn_clicked()
{
if (ui->libraryTreeView->currentIndex().isValid())
{
+ // FIXME: use actual model, not reloading.
if (!m_version->remove(ui->libraryTreeView->currentIndex().row()))
{
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
}
else
{
- m_inst->reloadVersion(this);
+ reloadInstanceVersion();
}
}
}
void OneSixModEditDialog::on_resetLibraryOrderBtn_clicked()
{
- QDir(m_inst->instanceRoot()).remove("order.json");
- m_inst->reloadVersion(this);
+ // FIXME: IMPLEMENT LOGIC IN MODEL. SEE LEGACY DIALOG FOR EXAMPLE(S).
}
+
void OneSixModEditDialog::on_moveLibraryUpBtn_clicked()
{
-
- QMap<QString, int> order = getExistingOrder();
- if (order.size() < 2 || ui->libraryTreeView->selectionModel()->selectedIndexes().isEmpty())
- {
- return;
- }
- const int ourRow = ui->libraryTreeView->selectionModel()->selectedIndexes().first().row();
- const QString ourId = m_version->versionFileId(ourRow);
- const int ourOrder = order[ourId];
- if (ourId.isNull() || ourId.startsWith("org.multimc."))
- {
- return;
- }
-
- QMap<int, QString> sortedOrder = invert(order);
-
- QList<int> sortedOrders = sortedOrder.keys();
- const int ourIndex = sortedOrders.indexOf(ourOrder);
- if (ourIndex <= 0)
- {
- return;
- }
- const int ourNewOrder = sortedOrders.at(ourIndex - 1);
- order[ourId] = ourNewOrder;
- order[sortedOrder[sortedOrders[ourIndex - 1]]] = ourOrder;
-
- if (!OneSixVersionBuilder::writeOverrideOrders(order, m_inst))
- {
- QMessageBox::critical(this, tr("Error"), tr("Couldn't save the new order"));
- }
- else
- {
- m_inst->reloadVersion(this);
- ui->libraryTreeView->selectionModel()->select(m_version->index(ourRow - 1), QItemSelectionModel::SelectCurrent);
- }
+ // FIXME: IMPLEMENT LOGIC IN MODEL. SEE LEGACY DIALOG FOR EXAMPLE(S).
}
+
void OneSixModEditDialog::on_moveLibraryDownBtn_clicked()
{
- QMap<QString, int> order = getExistingOrder();
- if (order.size() < 2 || ui->libraryTreeView->selectionModel()->selectedIndexes().isEmpty())
- {
- return;
- }
- const int ourRow = ui->libraryTreeView->selectionModel()->selectedIndexes().first().row();
- const QString ourId = m_version->versionFileId(ourRow);
- const int ourOrder = order[ourId];
- if (ourId.isNull() || ourId.startsWith("org.multimc."))
- {
- return;
- }
-
- QMap<int, QString> sortedOrder = invert(order);
-
- QList<int> sortedOrders = sortedOrder.keys();
- const int ourIndex = sortedOrders.indexOf(ourOrder);
- if ((ourIndex + 1) >= sortedOrders.size())
- {
- return;
- }
- const int ourNewOrder = sortedOrders.at(ourIndex + 1);
- order[ourId] = ourNewOrder;
- order[sortedOrder[sortedOrders[ourIndex + 1]]] = ourOrder;
-
- if (!OneSixVersionBuilder::writeOverrideOrders(order, m_inst))
- {
- QMessageBox::critical(this, tr("Error"), tr("Couldn't save the new order"));
- }
- else
- {
- m_inst->reloadVersion(this);
- ui->libraryTreeView->selectionModel()->select(m_version->index(ourRow + 1), QItemSelectionModel::SelectCurrent);
- }
+ // FIXME: IMPLEMENT LOGIC IN MODEL. SEE LEGACY DIALOG FOR EXAMPLE(S).
}
void OneSixModEditDialog::on_forgeBtn_clicked()
{
+ // FIXME: use actual model, not reloading. Move logic to model.
+
+ // FIXME: model::isCustom();
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)
+ if (QMessageBox::question(this, tr("Revert?"),
+ tr("This action will remove your custom.json. Continue?")) !=
+ QMessageBox::Yes)
{
return;
}
+ // FIXME: model::revertToBase();
QDir(m_inst->instanceRoot()).remove("custom.json");
- m_inst->reloadVersion(this);
+ reloadInstanceVersion();
}
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());
+ m_inst->currentVersionId());
if (vselect.exec() && vselect.selectedVersion())
{
ForgeVersionPtr forgeVersion =
@@ -277,28 +237,32 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
}
}
}
- m_inst->reloadVersion(this);
+ reloadInstanceVersion();
}
void OneSixModEditDialog::on_liteloaderBtn_clicked()
{
+ // FIXME: model...
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)
+ 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");
- m_inst->reloadVersion(this);
+ reloadInstanceVersion();
}
- VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"), this);
+ VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"),
+ this);
vselect.setFilter(1, m_inst->currentVersionId());
vselect.setEmptyString(tr("No LiteLoader versions are currently available for Minecraft ") +
- m_inst->currentVersionId());
+ m_inst->currentVersionId());
if (vselect.exec() && vselect.selectedVersion())
{
LiteLoaderVersionPtr liteloaderVersion =
- std::dynamic_pointer_cast<LiteLoaderVersion>(vselect.selectedVersion());
+ std::dynamic_pointer_cast<LiteLoaderVersion>(vselect.selectedVersion());
if (!liteloaderVersion)
return;
LiteLoaderInstaller liteloader(liteloaderVersion);
@@ -310,7 +274,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked()
}
else
{
- m_inst->reloadVersion(this);
+ reloadInstanceVersion();
}
}
}
@@ -347,35 +311,6 @@ bool OneSixModEditDialog::resourcePackListFilter(QKeyEvent *keyEvent)
return QDialog::eventFilter(ui->resPackTreeView, keyEvent);
}
-QMap<QString, int> OneSixModEditDialog::getExistingOrder() const
-{
-
- QMap<QString, int> order;
- // default
- {
- for (OneSixVersion::VersionFile file : m_version->versionFiles)
- {
- if (file.id.startsWith("org.multimc."))
- {
- continue;
- }
- order.insert(file.id, file.order);
- }
- }
- // overriden
- {
- QMap<QString, int> overridenOrder = OneSixVersionBuilder::readOverrideOrders(m_inst);
- for (auto id : order.keys())
- {
- if (overridenOrder.contains(id))
- {
- order[id] = overridenOrder[id];
- }
- }
- }
- return order;
-}
-
bool OneSixModEditDialog::eventFilter(QObject *obj, QEvent *ev)
{
if (ev->type() != QEvent::KeyPress)
@@ -461,7 +396,8 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou
ui->frame->updateWithMod(m);
}
-void OneSixModEditDialog::versionCurrent(const QModelIndex &current, const QModelIndex &previous)
+void OneSixModEditDialog::versionCurrent(const QModelIndex &current,
+ const QModelIndex &previous)
{
if (!current.isValid())
{