aboutsummaryrefslogtreecommitdiff
path: root/launcher
diff options
context:
space:
mode:
authorRyan Cao <70191398+ryanccn@users.noreply.github.com>2022-11-19 23:04:26 +0800
committerRyan Cao <70191398+ryanccn@users.noreply.github.com>2022-11-19 23:14:57 +0800
commit8dacbafc8ba45ae6c2b770da77cc0d3d632849ba (patch)
treec0b850d2a4bea1c2a4d60e7280ef28b60726ee0e /launcher
parent3482076a207444bbdd9a7667df40b80bce1c545c (diff)
downloadPrismLauncher-8dacbafc8ba45ae6c2b770da77cc0d3d632849ba.tar.gz
PrismLauncher-8dacbafc8ba45ae6c2b770da77cc0d3d632849ba.tar.bz2
PrismLauncher-8dacbafc8ba45ae6c2b770da77cc0d3d632849ba.zip
feat: initial support for smart resource pack parsing on file handler
Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com>
Diffstat (limited to 'launcher')
-rw-r--r--launcher/Application.cpp23
-rw-r--r--launcher/CMakeLists.txt3
-rw-r--r--launcher/ui/dialogs/ImportResourcePackDialog.cpp61
-rw-r--r--launcher/ui/dialogs/ImportResourcePackDialog.h24
-rw-r--r--launcher/ui/dialogs/ImportResourcePackDialog.ui67
5 files changed, 177 insertions, 1 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp
index 883f8968..71cd009a 100644
--- a/launcher/Application.cpp
+++ b/launcher/Application.cpp
@@ -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);
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 8db93429..58d5d964 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -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
diff --git a/launcher/ui/dialogs/ImportResourcePackDialog.cpp b/launcher/ui/dialogs/ImportResourcePackDialog.cpp
new file mode 100644
index 00000000..ef76445c
--- /dev/null
+++ b/launcher/ui/dialogs/ImportResourcePackDialog.cpp
@@ -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;
+}
diff --git a/launcher/ui/dialogs/ImportResourcePackDialog.h b/launcher/ui/dialogs/ImportResourcePackDialog.h
new file mode 100644
index 00000000..b077a811
--- /dev/null
+++ b/launcher/ui/dialogs/ImportResourcePackDialog.h
@@ -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);
+};
diff --git a/launcher/ui/dialogs/ImportResourcePackDialog.ui b/launcher/ui/dialogs/ImportResourcePackDialog.ui
new file mode 100644
index 00000000..2a1de0f9
--- /dev/null
+++ b/launcher/ui/dialogs/ImportResourcePackDialog.ui
@@ -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>