feat: initial support for smart resource pack parsing on file handler

Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com>
This commit is contained in:
Ryan Cao 2022-11-19 23:04:26 +08:00
parent 3482076a20
commit 8dacbafc8b
No known key found for this signature in database
5 changed files with 177 additions and 1 deletions

View File

@ -66,6 +66,7 @@
#include "ui/setupwizard/PasteWizardPage.h"
#include "ui/dialogs/CustomMessageBox.h"
#include "ui/dialogs/ImportResourcePackDialog.h"
#include "ui/pagedialog/PageDialog.h"
@ -96,6 +97,10 @@
#include "net/HttpMetaCache.h"
#include "java/JavaUtils.h"
#include <minecraft/MinecraftInstance.h>
#include <minecraft/mod/ResourcePack.h>
#include <minecraft/mod/ResourcePackFolderModel.h>
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
#include "updater/UpdateChecker.h"
@ -930,7 +935,23 @@ bool Application::event(QEvent* event) {
if (event->type() == QEvent::FileOpen) {
auto ev = static_cast<QFileOpenEvent*>(event);
m_mainWindow->droppedURLs({ ev->url() });
ResourcePack pack{ QFileInfo(ev->file()) };
ResourcePackUtils::process(pack);
//
if (pack.valid()) {
ImportResourcePackDialog dlg(APPLICATION->m_mainWindow);
dlg.exec();
if (dlg.result() == QDialog::Accepted) {
auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey);
auto instanceButBuffed = std::dynamic_pointer_cast<MinecraftInstance>(instance);
instanceButBuffed->resourcePackList()->installResource(ev->file());
}
} else {
m_mainWindow->droppedURLs({ ev->url() });
}
}
return QApplication::event(event);

View File

@ -791,6 +791,8 @@ SET(LAUNCHER_SOURCES
ui/dialogs/ExportInstanceDialog.h
ui/dialogs/IconPickerDialog.cpp
ui/dialogs/IconPickerDialog.h
ui/dialogs/ImportResourcePackDialog.cpp
ui/dialogs/ImportResourcePackDialog.h
ui/dialogs/LoginDialog.cpp
ui/dialogs/LoginDialog.h
ui/dialogs/MSALoginDialog.cpp
@ -939,6 +941,7 @@ qt_wrap_ui(LAUNCHER_UI
ui/dialogs/SkinUploadDialog.ui
ui/dialogs/ExportInstanceDialog.ui
ui/dialogs/IconPickerDialog.ui
ui/dialogs/ImportResourcePackDialog.ui
ui/dialogs/MSALoginDialog.ui
ui/dialogs/OfflineLoginDialog.ui
ui/dialogs/AboutDialog.ui

View File

@ -0,0 +1,61 @@
#include "ImportResourcePackDialog.h"
#include "ui_ImportResourcePackDialog.h"
#include <QFileDialog>
#include <QPushButton>
#include "Application.h"
#include "InstanceList.h"
#include "ui/instanceview/InstanceDelegate.h"
ImportResourcePackDialog::ImportResourcePackDialog(QWidget* parent) : QDialog(parent), ui(new Ui::ImportResourcePackDialog)
{
ui->setupUi(this);
setWindowModality(Qt::WindowModal);
auto contentsWidget = ui->instanceView;
contentsWidget->setViewMode(QListView::ListMode);
contentsWidget->setFlow(QListView::LeftToRight);
contentsWidget->setIconSize(QSize(48, 48));
contentsWidget->setMovement(QListView::Static);
contentsWidget->setResizeMode(QListView::Adjust);
contentsWidget->setSelectionMode(QAbstractItemView::SingleSelection);
contentsWidget->setSpacing(5);
contentsWidget->setWordWrap(false);
contentsWidget->setWrapping(true);
contentsWidget->setUniformItemSizes(true);
contentsWidget->setTextElideMode(Qt::ElideRight);
contentsWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
contentsWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
contentsWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
contentsWidget->setItemDelegate(new ListViewDelegate());
contentsWidget->setModel(APPLICATION->instances().get());
connect(contentsWidget, SIGNAL(doubleClicked(QModelIndex)), SLOT(activated(QModelIndex)));
connect(contentsWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)),
SLOT(selectionChanged(QItemSelection, QItemSelection)));
}
void ImportResourcePackDialog::activated(QModelIndex index)
{
selectedInstanceKey = index.data(Qt::UserRole).toString();
accept();
}
void ImportResourcePackDialog::selectionChanged(QItemSelection selected, QItemSelection deselected)
{
if (selected.empty())
return;
QString key = selected.first().indexes().first().data(Qt::UserRole).toString();
if (!key.isEmpty()) {
selectedInstanceKey = key;
}
}
ImportResourcePackDialog::~ImportResourcePackDialog()
{
delete ui;
}

View File

@ -0,0 +1,24 @@
#pragma once
#include <QDialog>
#include <QItemSelection>
namespace Ui {
class ImportResourcePackDialog;
}
class ImportResourcePackDialog : public QDialog {
Q_OBJECT
public:
explicit ImportResourcePackDialog(QWidget* parent = 0);
~ImportResourcePackDialog();
QString selectedInstanceKey;
private:
Ui::ImportResourcePackDialog* ui;
private slots:
void selectionChanged(QItemSelection, QItemSelection);
void activated(QModelIndex);
};

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ImportResourcePackDialog</class>
<widget class="QDialog" name="ImportResourcePackDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<height>555</height>
</rect>
</property>
<property name="windowTitle">
<string>Pick icon</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListView" name="instanceView"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ImportResourcePackDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ImportResourcePackDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>