summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
Diffstat (limited to 'gui')
-rw-r--r--gui/dialogs/OneSixModEditDialog.cpp120
-rw-r--r--gui/dialogs/OneSixModEditDialog.ui9
-rw-r--r--gui/groupview/InstanceDelegate.cpp85
-rw-r--r--gui/groupview/InstanceDelegate.h6
4 files changed, 130 insertions, 90 deletions
diff --git a/gui/dialogs/OneSixModEditDialog.cpp b/gui/dialogs/OneSixModEditDialog.cpp
index 78585a05..2d459001 100644
--- a/gui/dialogs/OneSixModEditDialog.cpp
+++ b/gui/dialogs/OneSixModEditDialog.cpp
@@ -42,16 +42,6 @@
#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)
{
@@ -155,34 +145,62 @@ void OneSixModEditDialog::on_removeLibraryBtn_clicked()
{
QMessageBox::critical(this, tr("Error"), tr("Couldn't remove file"));
}
- else
- {
- reloadInstanceVersion();
- }
}
}
void OneSixModEditDialog::on_resetLibraryOrderBtn_clicked()
{
- // FIXME: IMPLEMENT LOGIC IN MODEL. SEE LEGACY DIALOG FOR EXAMPLE(S).
+ try
+ {
+ m_version->resetOrder();
+ }
+ catch (MMCError &e)
+ {
+ QMessageBox::critical(this, tr("Error"), e.cause());
+ }
}
void OneSixModEditDialog::on_moveLibraryUpBtn_clicked()
{
- // FIXME: IMPLEMENT LOGIC IN MODEL. SEE LEGACY DIALOG FOR EXAMPLE(S).
+ if (ui->libraryTreeView->selectionModel()->selectedRows().isEmpty())
+ {
+ return;
+ }
+ try
+ {
+ const int row = ui->libraryTreeView->selectionModel()->selectedRows().first().row();
+ const int newRow = 0;m_version->move(row, VersionFinal::MoveUp);
+ //ui->libraryTreeView->selectionModel()->setCurrentIndex(m_version->index(newRow), QItemSelectionModel::ClearAndSelect);
+ }
+ catch (MMCError &e)
+ {
+ QMessageBox::critical(this, tr("Error"), e.cause());
+ }
}
void OneSixModEditDialog::on_moveLibraryDownBtn_clicked()
{
- // FIXME: IMPLEMENT LOGIC IN MODEL. SEE LEGACY DIALOG FOR EXAMPLE(S).
+ if (ui->libraryTreeView->selectionModel()->selectedRows().isEmpty())
+ {
+ return;
+ }
+ try
+ {
+ const int row = ui->libraryTreeView->selectionModel()->selectedRows().first().row();
+ const int newRow = 0;m_version->move(row, VersionFinal::MoveDown);
+ //ui->libraryTreeView->selectionModel()->setCurrentIndex(m_version->index(newRow), QItemSelectionModel::ClearAndSelect);
+ }
+ catch (MMCError &e)
+ {
+ QMessageBox::critical(this, tr("Error"), e.cause());
+ }
}
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 (m_version->isCustom())
{
if (QMessageBox::question(this, tr("Revert?"),
tr("This action will remove your custom.json. Continue?")) !=
@@ -190,8 +208,7 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
{
return;
}
- // FIXME: model::revertToBase();
- QDir(m_inst->instanceRoot()).remove("custom.json");
+ m_version->revertToBase();
reloadInstanceVersion();
}
VersionSelectDialog vselect(MMC->forgelist().get(), tr("Select Forge version"), this);
@@ -200,50 +217,14 @@ void OneSixModEditDialog::on_forgeBtn_clicked()
m_inst->currentVersionId());
if (vselect.exec() && vselect.selectedVersion())
{
- ForgeVersionPtr forgeVersion =
- std::dynamic_pointer_cast<ForgeVersion>(vselect.selectedVersion());
- if (!forgeVersion)
- return;
- auto entry = MMC->metacache()->resolveEntry("minecraftforge", forgeVersion->filename);
- if (entry->stale)
- {
- NetJob *fjob = new NetJob("Forge download");
- fjob->addNetAction(CacheDownload::make(forgeVersion->installer_url, entry));
- ProgressDialog dlg(this);
- dlg.exec(fjob);
- if (dlg.result() == QDialog::Accepted)
- {
- // install
- QString forgePath = entry->getFullPath();
- ForgeInstaller forge(forgePath, forgeVersion->universal_url);
- if (!forge.add(m_inst))
- {
- QLOG_ERROR() << "Failure installing forge";
- }
- }
- else
- {
- // failed to download forge :/
- }
- }
- else
- {
- // install
- QString forgePath = entry->getFullPath();
- ForgeInstaller forge(forgePath, forgeVersion->universal_url);
- if (!forge.add(m_inst))
- {
- QLOG_ERROR() << "Failure installing forge";
- }
- }
+ ProgressDialog dialog(this);
+ dialog.exec(ForgeInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this));
}
- reloadInstanceVersion();
}
void OneSixModEditDialog::on_liteloaderBtn_clicked()
{
- // FIXME: model...
- if (QDir(m_inst->instanceRoot()).exists("custom.json"))
+ if (m_version->isCustom())
{
if (QMessageBox::question(this, tr("Revert?"),
tr("This action will remove your custom.json. Continue?")) !=
@@ -251,7 +232,7 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked()
{
return;
}
- QDir(m_inst->instanceRoot()).remove("custom.json");
+ m_version->revertToBase();
reloadInstanceVersion();
}
VersionSelectDialog vselect(MMC->liteloaderlist().get(), tr("Select LiteLoader version"),
@@ -261,21 +242,8 @@ void OneSixModEditDialog::on_liteloaderBtn_clicked()
m_inst->currentVersionId());
if (vselect.exec() && vselect.selectedVersion())
{
- LiteLoaderVersionPtr liteloaderVersion =
- std::dynamic_pointer_cast<LiteLoaderVersion>(vselect.selectedVersion());
- if (!liteloaderVersion)
- return;
- LiteLoaderInstaller liteloader(liteloaderVersion);
- if (!liteloader.add(m_inst))
- {
- QMessageBox::critical(this, tr("LiteLoader"),
- tr("For reasons unknown, the LiteLoader installation failed. "
- "Check your MultiMC log files for details."));
- }
- else
- {
- reloadInstanceVersion();
- }
+ ProgressDialog dialog(this);
+ dialog.exec(LiteLoaderInstaller().createInstallTask(m_inst, vselect.selectedVersion(), this));
}
}
diff --git a/gui/dialogs/OneSixModEditDialog.ui b/gui/dialogs/OneSixModEditDialog.ui
index b606dcd2..2c9f70bb 100644
--- a/gui/dialogs/OneSixModEditDialog.ui
+++ b/gui/dialogs/OneSixModEditDialog.ui
@@ -99,9 +99,6 @@
</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>
@@ -112,9 +109,6 @@
</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>
@@ -125,9 +119,6 @@
</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>
diff --git a/gui/groupview/InstanceDelegate.cpp b/gui/groupview/InstanceDelegate.cpp
index 8a273758..7ca4d7b4 100644
--- a/gui/groupview/InstanceDelegate.cpp
+++ b/gui/groupview/InstanceDelegate.cpp
@@ -18,9 +18,13 @@
#include <QTextOption>
#include <QTextLayout>
#include <QApplication>
-#include <QtCore/qmath.h>
+#include <QtMath>
#include "GroupView.h"
+#include "logic/BaseInstance.h"
+#include "logic/lists/InstanceList.h"
+
+QCache<QString, QPixmap> ListViewDelegate::m_pixmapCache;
// Origin: Qt
static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height,
@@ -45,8 +49,6 @@ static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &he
textLayout.endLayout();
}
-#define QFIXED_MAX (INT_MAX / 256)
-
ListViewDelegate::ListViewDelegate(QObject *parent) : QStyledItemDelegate(parent)
{
}
@@ -108,6 +110,64 @@ void drawProgressOverlay(QPainter *painter, const QStyleOptionViewItemV4 &option
painter->restore();
}
+void drawBadges(QPainter *painter, const QStyleOptionViewItemV4 &option, BaseInstance *instance)
+{
+ QList<QString> pixmaps;
+ for (auto flag : instance->flags())
+ {
+ switch (flag)
+ {
+ case BaseInstance::VersionBrokenFlag:
+ pixmaps.append("broken");
+ break;
+ }
+ }
+
+ // begin easter eggs
+ if (instance->name().contains("btw", Qt::CaseInsensitive) ||
+ instance->name().contains("better then wolves", Qt::CaseInsensitive) ||
+ instance->name().contains("better than wolves", Qt::CaseInsensitive))
+ {
+ pixmaps.append("herobrine");
+ }
+ if (instance->name().contains("direwolf", Qt::CaseInsensitive))
+ {
+ pixmaps.append("enderman");
+ }
+ if (instance->name().contains("kitten", Qt::CaseInsensitive))
+ {
+ pixmaps.append("kitten");
+ }
+ if (instance->name().contains("derp", Qt::CaseInsensitive))
+ {
+ pixmaps.append("derp");
+ }
+ // end easter eggs
+
+ static const int itemSide = 24;
+ static const int spacing = 1;
+ const int itemsPerRow = qMax(1, qFloor(double(option.rect.width() + spacing) / double(itemSide + spacing)));
+ const int rows = qCeil((double)pixmaps.size() / (double)itemsPerRow);
+ QListIterator<QString> it(pixmaps);
+ painter->translate(option.rect.topLeft());
+ for (int y = 0; y < rows; ++y)
+ {
+ for (int x = 0; x < itemsPerRow; ++x)
+ {
+ if (!it.hasNext())
+ {
+ return;
+ }
+ const QPixmap pixmap = ListViewDelegate::requestPixmap(it.next()).scaled(
+ itemSide, itemSide, Qt::KeepAspectRatio, Qt::FastTransformation);
+ painter->drawPixmap(option.rect.width() - x * itemSide + qMax(x - 1, 0) * spacing - itemSide,
+ y * itemSide + qMax(y - 1, 0) * spacing, itemSide, itemSide,
+ pixmap);
+ }
+ }
+ painter->translate(-option.rect.topLeft());
+}
+
static QSize viewItemTextSize(const QStyleOptionViewItemV4 *option)
{
QStyle *style = option->widget ? option->widget->style() : QApplication::style();
@@ -257,8 +317,14 @@ void ListViewDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
line.draw(painter, position);
}
- drawProgressOverlay(painter, opt,
- index.data(GroupViewRoles::ProgressValueRole).toInt(),
+ auto instance = (BaseInstance*)index.data(InstanceList::InstancePointerRole)
+ .value<void *>();
+ if (instance)
+ {
+ drawBadges(painter, opt, instance);
+ }
+
+ drawProgressOverlay(painter, opt, index.data(GroupViewRoles::ProgressValueRole).toInt(),
index.data(GroupViewRoles::ProgressMaximumRole).toInt());
painter->restore();
@@ -284,3 +350,12 @@ QSize ListViewDelegate::sizeHint(const QStyleOptionViewItem &option,
QSize sz(100, height);
return sz;
}
+
+QPixmap ListViewDelegate::requestPixmap(const QString &key)
+{
+ if (!m_pixmapCache.contains(key))
+ {
+ m_pixmapCache.insert(key, new QPixmap(":/icons/badges/" + key + ".png"));
+ }
+ return *m_pixmapCache.object(key);
+}
diff --git a/gui/groupview/InstanceDelegate.h b/gui/groupview/InstanceDelegate.h
index de2f429b..9ab44864 100644
--- a/gui/groupview/InstanceDelegate.h
+++ b/gui/groupview/InstanceDelegate.h
@@ -16,14 +16,20 @@
#pragma once
#include <QStyledItemDelegate>
+#include <QCache>
class ListViewDelegate : public QStyledItemDelegate
{
public:
explicit ListViewDelegate(QObject *parent = 0);
+ static QPixmap requestPixmap(const QString &key);
+
protected:
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
+
+private:
+ static QCache<QString, QPixmap> m_pixmapCache;
};