summaryrefslogtreecommitdiffstats
path: root/gui/dialogs/OneSixModEditDialog.cpp
diff options
context:
space:
mode:
authorJan Dalheimer <jan@dalheimer.de>2014-02-08 17:22:26 +0100
committerJan Dalheimer <jan@dalheimer.de>2014-02-08 17:22:26 +0100
commit53069205faf4063e838bab4beea5089d6ec2a0af (patch)
treecf71bc71efc845f652807232b1e6d7442e587abb /gui/dialogs/OneSixModEditDialog.cpp
parent6d9819cccf3809edef2f6a1aeb0c6d01d6067501 (diff)
downloadMultiMC-53069205faf4063e838bab4beea5089d6ec2a0af.tar
MultiMC-53069205faf4063e838bab4beea5089d6ec2a0af.tar.gz
MultiMC-53069205faf4063e838bab4beea5089d6ec2a0af.tar.lz
MultiMC-53069205faf4063e838bab4beea5089d6ec2a0af.tar.xz
MultiMC-53069205faf4063e838bab4beea5089d6ec2a0af.zip
Allow overriding the order in which patches are applied
Diffstat (limited to 'gui/dialogs/OneSixModEditDialog.cpp')
-rw-r--r--gui/dialogs/OneSixModEditDialog.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp
index 1b61771d..9e585de5 100644
--- a/gui/dialogs/OneSixModEditDialog.cpp
+++ b/gui/dialogs/OneSixModEditDialog.cpp
@@ -39,6 +39,18 @@
#include "logic/lists/ForgeVersionList.h"
#include "logic/ForgeInstaller.h"
#include "logic/LiteLoaderInstaller.h"
+#include "logic/OneSixVersionBuilder.h"
+
+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)
+ {
+ out.insert(it.value(), it.key());
+ }
+ return out;
+}
OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
: QDialog(parent), ui(new Ui::OneSixModEditDialog), m_inst(inst)
@@ -129,6 +141,87 @@ void OneSixModEditDialog::on_removeLibraryBtn_clicked()
}
}
+void OneSixModEditDialog::on_resetLibraryOrderBtn_clicked()
+{
+ QDir(m_inst->instanceRoot()).remove("order.json");
+ m_inst->reloadVersion(this);
+}
+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);
+ }
+}
+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);
+ }
+}
+
void OneSixModEditDialog::on_forgeBtn_clicked()
{
if (QDir(m_inst->instanceRoot()).exists("custom.json"))
@@ -250,6 +343,35 @@ 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)