Things... and stuff... with 1.6 modding. Maybe.

This commit is contained in:
Petr Mrázek 2013-09-20 01:21:48 +02:00
parent 930b07afd4
commit c2c7293083
7 changed files with 124 additions and 8 deletions

View File

@ -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()

View File

@ -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())

View File

@ -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;
};

View File

@ -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>

View File

@ -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);

View File

@ -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();

View File

@ -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);
}