GH-1031 include icon in exported instance if it is custom
This commit is contained in:
parent
96c497f654
commit
405cea1778
@ -1137,7 +1137,27 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin
|
||||
}
|
||||
|
||||
newInstance->setName(instName);
|
||||
newInstance->setIconKey(instIcon);
|
||||
if(instIcon != "default")
|
||||
{
|
||||
newInstance->setIconKey(instIcon);
|
||||
}
|
||||
else
|
||||
{
|
||||
instIcon = newInstance->iconKey();
|
||||
auto importIconPath = PathCombine(newInstance->instanceRoot(), instIcon + ".png");
|
||||
if (QFile::exists(importIconPath))
|
||||
{
|
||||
// import icon
|
||||
auto iconList = ENV.icons();
|
||||
// FIXME: check if the file is OK before removing the existing one...
|
||||
if(iconList->iconFileExists(instIcon))
|
||||
{
|
||||
//FIXME: ask if icon should be overwritten. Show difference in the question dialog.
|
||||
iconList->deleteIcon(instIcon);
|
||||
}
|
||||
iconList->installIcons({importIconPath});
|
||||
}
|
||||
}
|
||||
newInstance->setGroupInitial(instGroup);
|
||||
MMC->instances()->add(InstancePtr(newInstance));
|
||||
MMC->instances()->saveGroupList();
|
||||
@ -1225,7 +1245,6 @@ void MainWindow::on_actionAddInstance_triggered()
|
||||
|
||||
const QUrl modpackUrl = newInstDlg.modpackUrl();
|
||||
|
||||
|
||||
if (modpackUrl.isValid())
|
||||
{
|
||||
instanceFromZipPack(newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey(), modpackUrl);
|
||||
|
@ -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"));
|
||||
|
@ -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));
|
||||
|
@ -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>
|
||||
|
@ -261,6 +261,24 @@ void IconList::installIcons(QStringList iconFiles)
|
||||
}
|
||||
}
|
||||
|
||||
bool IconList::iconFileExists(QString key)
|
||||
{
|
||||
auto iconEntry = icon(key);
|
||||
if(!iconEntry)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return iconEntry->has(MMCIcon::FileBased);
|
||||
}
|
||||
|
||||
const MMCIcon *IconList::icon(QString key)
|
||||
{
|
||||
int iconIdx = getIconIndex(key);
|
||||
if (iconIdx == -1)
|
||||
return nullptr;
|
||||
return &icons[iconIdx];
|
||||
}
|
||||
|
||||
bool IconList::deleteIcon(QString key)
|
||||
{
|
||||
int iconIdx = getIconIndex(key);
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
|
||||
bool addIcon(QString key, QString name, QString path, MMCIcon::Type type);
|
||||
bool deleteIcon(QString key);
|
||||
bool iconFileExists(QString key);
|
||||
|
||||
virtual QStringList mimeTypes() const;
|
||||
virtual Qt::DropActions supportedDropActions() const;
|
||||
@ -52,6 +53,8 @@ public:
|
||||
|
||||
void installIcons(QStringList iconFiles);
|
||||
|
||||
const MMCIcon * icon(QString key);
|
||||
|
||||
void startWatching();
|
||||
void stopWatching();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user