summaryrefslogtreecommitdiffstats
path: root/application/dialogs
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2015-06-01 01:19:12 +0200
committerPetr Mrázek <peterix@gmail.com>2015-06-01 01:19:12 +0200
commit405cea177877234981019c6916f6f97d818dfd51 (patch)
tree2e1cc92f5bb807836fe8c4ecee98c1015305ce04 /application/dialogs
parent96c497f6542daabeaa67e96e4298df50f65663d0 (diff)
downloadMultiMC-405cea177877234981019c6916f6f97d818dfd51.tar
MultiMC-405cea177877234981019c6916f6f97d818dfd51.tar.gz
MultiMC-405cea177877234981019c6916f6f97d818dfd51.tar.lz
MultiMC-405cea177877234981019c6916f6f97d818dfd51.tar.xz
MultiMC-405cea177877234981019c6916f6f97d818dfd51.zip
GH-1031 include icon in exported instance if it is custom
Diffstat (limited to 'application/dialogs')
-rw-r--r--application/dialogs/ExportInstanceDialog.cpp49
-rw-r--r--application/dialogs/NewInstanceDialog.cpp2
-rw-r--r--application/dialogs/NewInstanceDialog.ui4
3 files changed, 50 insertions, 5 deletions
diff --git a/application/dialogs/ExportInstanceDialog.cpp b/application/dialogs/ExportInstanceDialog.cpp
index 5d24c54b..ec376b1d 100644
--- a/application/dialogs/ExportInstanceDialog.cpp
+++ b/application/dialogs/ExportInstanceDialog.cpp
@@ -28,6 +28,8 @@
#include <QSaveFile>
#include "MMCStrings.h"
#include "SeparatorPrefixTree.h"
+#include "Env.h"
+#include <icons/IconList.h>
class PackIgnoreProxy : public QSortFilterProxyModel
{
@@ -333,6 +335,51 @@ ExportInstanceDialog::~ExportInstanceDialog()
delete ui;
}
+/// Save icon to instance's folder is needed
+void SaveIcon(InstancePtr m_instance)
+{
+ auto iconKey = m_instance->iconKey();
+ auto iconList = ENV.icons();
+ auto mmcIcon = iconList->icon(iconKey);
+ if(mmcIcon)
+ {
+ bool saveIcon = false;
+ switch(mmcIcon->type())
+ {
+ case MMCIcon::FileBased:
+ case MMCIcon::Transient:
+ saveIcon = true;
+ default:
+ break;
+ }
+ if(saveIcon)
+ {
+ auto & image = mmcIcon->m_images[mmcIcon->type()];
+ auto & icon = image.icon;
+ auto sizes = icon.availableSizes();
+ if(sizes.size() == 0)
+ {
+ return;
+ }
+ auto areaOf = [](QSize size)
+ {
+ return size.width() * size.height();
+ };
+ QSize largest = sizes[0];
+ // find variant with largest area
+ for(auto size: sizes)
+ {
+ if(areaOf(largest) < areaOf(size))
+ {
+ largest = size;
+ }
+ }
+ auto pixmap = icon.pixmap(largest);
+ pixmap.save(PathCombine(m_instance->instanceRoot(), iconKey + ".png"));
+ }
+ }
+}
+
bool ExportInstanceDialog::doExport()
{
auto name = RemoveInvalidFilenameChars(m_instance->name());
@@ -356,6 +403,8 @@ bool ExportInstanceDialog::doExport()
}
}
+ SaveIcon(m_instance);
+
if (!MMCZip::compressDir(output, m_instance->instanceRoot(), name, &proxyModel->blockedPaths()))
{
QMessageBox::warning(this, tr("Error"), tr("Unable to export instance"));
diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp
index d67d3ada..6cd651e4 100644
--- a/application/dialogs/NewInstanceDialog.cpp
+++ b/application/dialogs/NewInstanceDialog.cpp
@@ -65,7 +65,7 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent)
layout()->setSizeConstraint(QLayout::SetFixedSize);
setSelectedVersion(MMC->minecraftlist()->getRecommended(), true);
- InstIconKey = "infinity";
+ InstIconKey = "default";
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));
ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit));
diff --git a/application/dialogs/NewInstanceDialog.ui b/application/dialogs/NewInstanceDialog.ui
index 6cb0c97c..58a87354 100644
--- a/application/dialogs/NewInstanceDialog.ui
+++ b/application/dialogs/NewInstanceDialog.ui
@@ -41,10 +41,6 @@
</item>
<item>
<widget class="QToolButton" name="iconButton">
- <property name="icon">
- <iconset>
- <normaloff>:/icons/instances/infinity</normaloff>:/icons/instances/infinity</iconset>
- </property>
<property name="iconSize">
<size>
<width>80</width>