Change the OneSix library view. It now shows a list of patches.

This commit is contained in:
Jan Dalheimer 2014-02-01 14:52:21 +01:00
parent 556d8f0ec1
commit 4a9e213238
10 changed files with 183 additions and 49 deletions

View File

@ -55,6 +55,8 @@ OneSixModEditDialog::OneSixModEditDialog(OneSixInstance *inst, QWidget *parent)
main_model->setSourceModel(m_version.get());
ui->libraryTreeView->setModel(main_model);
ui->libraryTreeView->installEventFilter(this);
connect(ui->libraryTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
this, &OneSixModEditDialog::versionCurrent);
updateVersionControls();
}
else
@ -93,10 +95,8 @@ OneSixModEditDialog::~OneSixModEditDialog()
void OneSixModEditDialog::updateVersionControls()
{
bool customVersion = m_inst->versionIsCustom();
ui->forgeBtn->setEnabled(true);
ui->liteloaderBtn->setEnabled(LiteLoaderInstaller().canApply(m_inst));
ui->customEditorBtn->setEnabled(customVersion);
ui->mainClassEdit->setText(m_version->mainClass);
}
@ -104,23 +104,52 @@ void OneSixModEditDialog::disableVersionControls()
{
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_customEditorBtn_clicked()
void OneSixModEditDialog::on_userEditorBtn_clicked()
{
if (QDir(m_inst->instanceRoot()).exists("custom.json"))
if (QDir(m_inst->instanceRoot()).exists("user.json"))
{
if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/custom.json"))
if (!MMC->openJsonEditor(m_inst->instanceRoot() + "/user.json"))
{
QMessageBox::warning(this, tr("Error"), tr("Unable to open custom.json, check the settings"));
QMessageBox::warning(this, tr("Error"), tr("Unable to open user.json, check the settings"));
}
}
}
void OneSixModEditDialog::on_reloadLibrariesBtn_clicked()
{
m_inst->reloadVersion(this);
}
void OneSixModEditDialog::on_removeLibraryBtn_clicked()
{
if (ui->libraryTreeView->currentIndex().isValid())
{
if (!m_version->remove(ui->libraryTreeView->currentIndex().row()))
{
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
}
else
{
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());
if (vselect.exec() && vselect.selectedVersion())
@ -167,6 +196,14 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
void OneSixModEditDialog::on_liteloaderBtn_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");
}
LiteLoaderInstaller liteloader;
if (!liteloader.canApply(m_inst))
{
@ -304,3 +341,15 @@ void OneSixModEditDialog::loaderCurrent(QModelIndex current, QModelIndex previou
Mod &m = m_mods->operator[](row);
ui->frame->updateWithMod(m);
}
void OneSixModEditDialog::versionCurrent(const QModelIndex &current, const QModelIndex &previous)
{
if (!current.isValid())
{
ui->removeLibraryBtn->setDisabled(true);
}
else
{
ui->removeLibraryBtn->setEnabled(m_version->canRemove(current.row()));
}
}

View File

@ -45,7 +45,9 @@ slots:
void on_buttonBox_rejected();
void on_forgeBtn_clicked();
void on_liteloaderBtn_clicked();
void on_customEditorBtn_clicked();
void on_userEditorBtn_clicked();
void on_reloadLibrariesBtn_clicked();
void on_removeLibraryBtn_clicked();
void updateVersionControls();
void disableVersionControls();
@ -64,4 +66,5 @@ private:
public
slots:
void loaderCurrent(QModelIndex current, QModelIndex previous);
void versionCurrent(const QModelIndex &current, const QModelIndex &previous);
};

View File

@ -26,7 +26,7 @@
</size>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="libTab">
<attribute name="title">
@ -35,13 +35,6 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Tweakers:</string>
</property>
</widget>
</item>
<item>
<widget class="ModListView" name="libraryTreeView">
<property name="verticalScrollBarPolicy">
@ -51,7 +44,7 @@
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<attribute name="headerVisible">
<bool>false</bool>
<bool>true</bool>
</attribute>
</widget>
</item>
@ -96,37 +89,22 @@
</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>&amp;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>&amp;Remove</string>
<string>Remove</string>
</property>
</widget>
</item>
@ -138,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>

View File

@ -74,6 +74,7 @@ ForgeInstaller::ForgeInstaller(QString filename, QString universal_url)
QJsonObject installObj = installVal.toObject();
QString libraryName = installObj.value("path").toString();
internalPath = installObj.value("filePath").toString();
m_forgeVersionString = installObj.value("version").toString().remove("Forge").trimmed();
// where do we put the library? decode the mojang path
OneSixLibrary lib(libraryName);
@ -204,6 +205,11 @@ bool ForgeInstaller::add(OneSixInstance *to)
}
}
obj.insert("name", QString("Forge"));
obj.insert("id", id());
obj.insert("version", m_forgeVersionString);
obj.insert("mcVersion", to->intendedVersionId());
QFile file(filename(to->instanceRoot()));
if (!file.open(QFile::WriteOnly))
{

View File

@ -37,5 +37,6 @@ private:
QString internalPath;
QString finalPath;
QString realVersionId;
QString m_forgeVersionString;
QString m_universal_url;
};

View File

@ -78,6 +78,10 @@ bool LiteLoaderInstaller::add(OneSixInstance *to)
}
obj.insert("+libraries", libraries);
obj.insert("name", QString("LiteLoader"));
obj.insert("id", id());
obj.insert("version", to->intendedVersionId());
obj.insert("mcVersion", to->intendedVersionId());
QFile file(filename(to->instanceRoot()));
if (!file.open(QFile::WriteOnly))

View File

@ -319,8 +319,9 @@ bool OneSixInstance::shouldUpdate() const
bool OneSixInstance::versionIsCustom()
{
QDir patches(PathCombine(instanceRoot(), "patches/"));
return QFile::exists(PathCombine(instanceRoot(), "custom.json"))
|| (patches.exists() && patches.count() >= 0);
return (patches.exists() && patches.count() >= 0)
|| QFile::exists(PathCombine(instanceRoot(), "custom.json"))
|| QFile::exists(PathCombine(instanceRoot(), "user.json"));
}
QString OneSixInstance::currentVersionId() const

View File

@ -16,6 +16,7 @@
#include "OneSixVersion.h"
#include <QDebug>
#include <QFile>
#include "OneSixVersionBuilder.h"
@ -47,6 +48,7 @@ void OneSixVersion::clear()
mainClass.clear();
libraries.clear();
tweakers.clear();
versionFiles.clear();
endResetModel();
}
@ -70,6 +72,24 @@ void OneSixVersion::dump() const
qDebug().nospace() << "\n)";
}
bool OneSixVersion::canRemove(const int index) const
{
if (index < versionFiles.size())
{
return versionFiles.at(index).id != "org.multimc.version.json";
}
return false;
}
bool OneSixVersion::remove(const int index)
{
if (canRemove(index))
{
return QFile::remove(versionFiles.at(index).filename);
}
return false;
}
QList<std::shared_ptr<OneSixLibrary> > OneSixVersion::getActiveNormalLibs()
{
QList<std::shared_ptr<OneSixLibrary> > output;
@ -114,14 +134,39 @@ QVariant OneSixVersion::data(const QModelIndex &index, int role) const
int row = index.row();
int column = index.column();
if (row < 0 || row >= tweakers.size())
if (row < 0 || row >= versionFiles.size())
return QVariant();
if (role == Qt::DisplayRole)
{
if (column == 0)
switch (column)
{
return tweakers.at(row);
case 0:
return versionFiles.at(row).name;
case 1:
return versionFiles.at(row).version;
default:
return QVariant();
}
}
return QVariant();
}
QVariant OneSixVersion::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal)
{
if (role == Qt::DisplayRole)
{
switch (section)
{
case 0:
return tr("Name");
case 1:
return tr("Version");
default:
return QVariant();
}
}
}
return QVariant();
@ -136,12 +181,12 @@ Qt::ItemFlags OneSixVersion::flags(const QModelIndex &index) const
int OneSixVersion::rowCount(const QModelIndex &parent) const
{
return tweakers.size();
return versionFiles.size();
}
int OneSixVersion::columnCount(const QModelIndex &parent) const
{
return 1;
return 2;
}
QDebug operator<<(QDebug &dbg, const OneSixVersion *version)

View File

@ -32,6 +32,7 @@ public:
explicit OneSixVersion(OneSixInstance *instance, QObject *parent = 0);
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex &parent) const;
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
@ -41,6 +42,12 @@ public:
void dump() const;
bool canRemove(const int index) const;
public
slots:
bool remove(const int index);
public:
QList<std::shared_ptr<OneSixLibrary>> getActiveNormalLibs();
QList<std::shared_ptr<OneSixLibrary>> getActiveNativeLibs();
@ -109,6 +116,16 @@ public:
*/
// QList<Rule> rules;
struct VersionFile
{
QString name;
QString id;
QString version;
QString mcVersion;
QString filename;
};
QList<VersionFile> versionFiles;
private:
OneSixInstance *m_instance;
};

View File

@ -34,6 +34,14 @@
struct VersionFile
{
int order;
QString name;
QString fileId;
QString version;
// TODO use the mcVersion to determine if a version file should be removed on update
QString mcVersion;
QString filename;
// TODO requirements
// QMap<QString, QString> requirements;
QString id;
QString mainClass;
QString overwriteMinecraftArguments;
@ -216,6 +224,12 @@ struct VersionFile
}
}
out.name = root.value("name").toString();
out.fileId = root.value("id").toString();
out.version = root.value("version").toString();
out.mcVersion = root.value("mcVersion").toString();
out.filename = filename;
auto readString = [root, filename](const QString &key, QString &variable)
{
if (root.contains(key))
@ -661,6 +675,14 @@ struct VersionFile
}
}
OneSixVersion::VersionFile versionFile;
versionFile.name = name;
versionFile.id = fileId;
versionFile.version = this->version;
versionFile.mcVersion = mcVersion;
versionFile.filename = filename;
version->versionFiles.append(versionFile);
isError = false;
}
};
@ -727,6 +749,10 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
{
return false;
}
file.name = "version.json";
file.fileId = "org.multimc.version.json";
file.version = m_instance->intendedVersionId();
file.mcVersion = m_instance->intendedVersionId();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
@ -773,17 +799,21 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
}
}
// instance.json
// user.json
if (!excludeCustom)
{
if (QFile::exists(root.absoluteFilePath("instance.json")))
if (QFile::exists(root.absoluteFilePath("user.json")))
{
QLOG_INFO() << "Reading instance.json";
QLOG_INFO() << "Reading user.json";
VersionFile file;
if (!read(QFileInfo(root.absoluteFilePath("instance.json")), false, &file))
if (!read(QFileInfo(root.absoluteFilePath("user.json")), false, &file))
{
return false;
}
file.name = "user.json";
file.fileId = "org.multimc.user.json";
file.version = QString();
file.mcVersion = QString();
bool isError = false;
file.applyTo(m_version, isError);
if (isError)
@ -792,7 +822,7 @@ bool OneSixVersionBuilder::build(const bool excludeCustom)
m_widgetParent, QObject::tr("Error"),
QObject::tr(
"Error while applying %1. Please check MultiMC-0.log for more info.")
.arg(root.absoluteFilePath("instance.json")));
.arg(root.absoluteFilePath("user.json")));
return false;
}
}