Merge branch 'develop' into feature_badges
Conflicts: logic/OneSixInstance.cpp
This commit is contained in:
@ -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 ¤t, const QModelIndex &previous)
|
||||
void OneSixModEditDialog::versionCurrent(const QModelIndex ¤t,
|
||||
const QModelIndex &previous)
|
||||
{
|
||||
if (!current.isValid())
|
||||
{
|
||||
|
@ -57,17 +57,17 @@ protected:
|
||||
bool eventFilter(QObject *obj, QEvent *ev);
|
||||
bool loaderListFilter(QKeyEvent *ev);
|
||||
bool resourcePackListFilter(QKeyEvent *ev);
|
||||
/// FIXME: this shouldn't be necessary!
|
||||
bool reloadInstanceVersion();
|
||||
|
||||
private:
|
||||
Ui::OneSixModEditDialog *ui;
|
||||
std::shared_ptr<OneSixVersion> m_version;
|
||||
std::shared_ptr<VersionFinal> m_version;
|
||||
std::shared_ptr<ModList> m_mods;
|
||||
std::shared_ptr<ModList> m_resourcepacks;
|
||||
EnabledItemFilter *main_model;
|
||||
OneSixInstance *m_inst;
|
||||
|
||||
QMap<QString, int> getExistingOrder() const;
|
||||
|
||||
public
|
||||
slots:
|
||||
void loaderCurrent(QModelIndex current, QModelIndex previous);
|
||||
|
@ -48,24 +48,6 @@
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Main Class:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="mainClassEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
@ -108,13 +90,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="resetLibraryOrderBtn">
|
||||
<property name="text">
|
||||
<string>Reset order</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
@ -124,6 +99,12 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="moveLibraryUpBtn">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>This isn't implemented yet.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move up</string>
|
||||
</property>
|
||||
@ -131,11 +112,30 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="moveLibraryDownBtn">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>This isn't implemented yet.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Move down</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="resetLibraryOrderBtn">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>This isn't implemented yet.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Reset order</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_7">
|
||||
<property name="orientation">
|
||||
|
Reference in New Issue
Block a user