fix resource packs and add support for texture packs

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

View File

@ -101,6 +101,9 @@
#include <minecraft/mod/ResourcePack.h>
#include <minecraft/mod/ResourcePackFolderModel.h>
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
#include <minecraft/mod/TexturePack.h>
#include <minecraft/mod/TexturePackFolderModel.h>
#include <minecraft/mod/tasks/LocalTexturePackParseTask.h>
#include "updater/UpdateChecker.h"
@ -920,13 +923,13 @@ bool Application::createSetupWizard()
return false;
}
bool Application::event(QEvent* event) {
bool Application::event(QEvent* event)
{
#ifdef Q_OS_MACOS
if (event->type() == QEvent::ApplicationStateChange) {
auto ev = static_cast<QApplicationStateChangeEvent*>(event);
if (m_prevAppState == Qt::ApplicationActive
&& ev->applicationState() == Qt::ApplicationActive) {
if (m_prevAppState == Qt::ApplicationActive && ev->applicationState() == Qt::ApplicationActive) {
emit clickedOnDock();
}
m_prevAppState = ev->applicationState();
@ -936,19 +939,29 @@ bool Application::event(QEvent* event) {
if (event->type() == QEvent::FileOpen) {
auto ev = static_cast<QFileOpenEvent*>(event);
ResourcePack pack{ QFileInfo(ev->file()) };
ResourcePack rp{ QFileInfo(ev->file()) };
TexturePack tp{ QFileInfo(ev->file()) };
ResourcePackUtils::process(pack);
//
ImportResourcePackDialog dlg(APPLICATION->m_mainWindow);
if (pack.valid()) {
ImportResourcePackDialog dlg(APPLICATION->m_mainWindow);
if (ResourcePackUtils::process(rp) && rp.valid()) {
dlg.exec();
if (dlg.result() == QDialog::Accepted) {
qDebug() << "Selected instance to import resource pack into: " << dlg.selectedInstanceKey;
auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey);
auto instanceButBuffed = std::dynamic_pointer_cast<MinecraftInstance>(instance);
instanceButBuffed->resourcePackList()->installResource(ev->file());
}
} else if (TexturePackUtils::process(tp) && tp.valid()) {
dlg.exec();
if (dlg.result() == QDialog::Accepted) {
qDebug() << "Selected instance to import texture pack into: " << dlg.selectedInstanceKey;
auto instance = APPLICATION->instances()->getInstanceById(dlg.selectedInstanceKey);
auto instanceButBuffed = std::dynamic_pointer_cast<MinecraftInstance>(instance);
instanceButBuffed->texturePackList()->installResource(ev->file());
}
} else {
m_mainWindow->droppedURLs({ ev->url() });
}

View File

@ -114,3 +114,8 @@ bool ResourcePack::applyFilter(QRegularExpression filter) const
return Resource::applyFilter(filter);
}
bool ResourcePack::valid() const
{
return m_pack_format != 0;
}

View File

@ -42,6 +42,8 @@ class ResourcePack : public Resource {
/** Thread-safe. */
void setImage(QImage new_image);
bool valid() const override;
[[nodiscard]] auto compare(Resource const& other, SortType type) const -> std::pair<int, bool> override;
[[nodiscard]] bool applyFilter(QRegularExpression filter) const override;

View File

@ -62,3 +62,8 @@ QPixmap TexturePack::image(QSize size)
TexturePackUtils::process(*this);
return image(size);
}
bool TexturePack::valid() const
{
return m_description != nullptr;
}

View File

@ -48,6 +48,8 @@ class TexturePack : public Resource {
/** Thread-safe. */
void setImage(QImage new_image);
bool valid() const override;
protected:
mutable QMutex m_data_lock;