2022-12-17 00:44:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
/*
|
|
|
|
* Prism Launcher - Minecraft Launcher
|
|
|
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
|
|
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <QDialog>
|
|
|
|
#include <QDialogButtonBox>
|
2022-12-18 20:03:39 +00:00
|
|
|
#include <QHash>
|
2022-11-25 12:23:46 +00:00
|
|
|
#include <QLayout>
|
|
|
|
|
2022-12-18 18:41:46 +00:00
|
|
|
#include "QObjectPtr.h"
|
2023-04-19 22:57:09 +01:00
|
|
|
#include "minecraft/mod/tasks/GetModDependenciesTask.h"
|
2022-12-18 18:41:46 +00:00
|
|
|
#include "modplatform/ModIndex.h"
|
2022-11-25 12:23:46 +00:00
|
|
|
#include "ui/pages/BasePageProvider.h"
|
|
|
|
|
2022-12-17 00:44:21 +00:00
|
|
|
class BaseInstance;
|
|
|
|
class ModFolderModel;
|
2022-11-25 12:23:46 +00:00
|
|
|
class PageContainer;
|
|
|
|
class QVBoxLayout;
|
|
|
|
class QDialogButtonBox;
|
2022-12-17 00:44:21 +00:00
|
|
|
class ResourceDownloadTask;
|
|
|
|
class ResourceFolderModel;
|
2022-12-16 23:26:10 +00:00
|
|
|
class ResourcePackFolderModel;
|
2023-01-29 21:07:49 +00:00
|
|
|
class TexturePackFolderModel;
|
2022-12-30 17:06:07 +00:00
|
|
|
class ShaderPackFolderModel;
|
2022-11-25 12:23:46 +00:00
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
namespace ResourceDownload {
|
|
|
|
|
|
|
|
class ResourcePage;
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
class ResourceDownloadDialog : public QDialog, public BasePageProvider {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2022-12-18 18:41:46 +00:00
|
|
|
using DownloadTaskPtr = shared_qobject_ptr<ResourceDownloadTask>;
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
ResourceDownloadDialog(QWidget* parent, const std::shared_ptr<ResourceFolderModel> base_model);
|
|
|
|
|
|
|
|
void initializeContainer();
|
|
|
|
void connectButtons();
|
|
|
|
|
|
|
|
//: String that gets appended to the download dialog title ("Download " + resourcesString())
|
2023-01-08 15:28:55 +00:00
|
|
|
[[nodiscard]] virtual QString resourcesString() const { return tr("resources"); }
|
2022-11-25 12:23:46 +00:00
|
|
|
|
2023-01-08 15:28:55 +00:00
|
|
|
QString dialogTitle() override { return tr("Download %1").arg(resourcesString()); };
|
2022-11-25 12:23:46 +00:00
|
|
|
|
|
|
|
bool selectPage(QString pageId);
|
|
|
|
ResourcePage* getSelectedPage();
|
|
|
|
|
2023-05-02 22:49:54 +01:00
|
|
|
void addResource(ModPlatform::IndexedPack&, ModPlatform::IndexedVersion&);
|
|
|
|
void removeResource(const QString&);
|
2022-11-25 12:23:46 +00:00
|
|
|
|
2022-12-18 18:41:46 +00:00
|
|
|
const QList<DownloadTaskPtr> getTasks();
|
2022-11-25 12:23:46 +00:00
|
|
|
[[nodiscard]] const std::shared_ptr<ResourceFolderModel> getBaseModel() const { return m_base_model; }
|
|
|
|
|
2022-12-17 00:44:21 +00:00
|
|
|
public slots:
|
|
|
|
void accept() override;
|
|
|
|
void reject() override;
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
protected slots:
|
|
|
|
void selectedPageChanged(BasePage* previous, BasePage* selected);
|
|
|
|
|
|
|
|
virtual void confirm();
|
|
|
|
|
2022-12-17 00:44:21 +00:00
|
|
|
protected:
|
|
|
|
[[nodiscard]] virtual QString geometrySaveKey() const { return ""; }
|
2023-05-02 22:49:54 +01:00
|
|
|
void setButtonStatus();
|
2022-12-17 00:44:21 +00:00
|
|
|
|
2023-04-19 22:57:09 +01:00
|
|
|
[[nodiscard]] virtual GetModDependenciesTask::Ptr getModDependenciesTask() { return nullptr; }
|
|
|
|
|
2022-11-25 12:23:46 +00:00
|
|
|
protected:
|
|
|
|
const std::shared_ptr<ResourceFolderModel> m_base_model;
|
|
|
|
|
|
|
|
PageContainer* m_container = nullptr;
|
|
|
|
ResourcePage* m_selectedPage = nullptr;
|
|
|
|
|
|
|
|
QDialogButtonBox m_buttons;
|
|
|
|
QVBoxLayout m_vertical_layout;
|
|
|
|
};
|
2022-12-16 22:03:52 +00:00
|
|
|
|
2022-12-17 00:44:21 +00:00
|
|
|
class ModDownloadDialog final : public ResourceDownloadDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ModDownloadDialog(QWidget* parent, const std::shared_ptr<ModFolderModel>& mods, BaseInstance* instance);
|
|
|
|
~ModDownloadDialog() override = default;
|
|
|
|
|
|
|
|
//: String that gets appended to the mod download dialog title ("Download " + resourcesString())
|
2023-01-08 15:28:55 +00:00
|
|
|
[[nodiscard]] QString resourcesString() const override { return tr("mods"); }
|
2022-12-17 00:44:21 +00:00
|
|
|
[[nodiscard]] QString geometrySaveKey() const override { return "ModDownloadGeometry"; }
|
|
|
|
|
|
|
|
QList<BasePage*> getPages() override;
|
2023-04-19 22:57:09 +01:00
|
|
|
GetModDependenciesTask::Ptr getModDependenciesTask() override;
|
2022-12-17 00:44:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BaseInstance* m_instance;
|
|
|
|
};
|
|
|
|
|
2022-12-16 23:26:10 +00:00
|
|
|
class ResourcePackDownloadDialog final : public ResourceDownloadDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ResourcePackDownloadDialog(QWidget* parent,
|
|
|
|
const std::shared_ptr<ResourcePackFolderModel>& resource_packs,
|
|
|
|
BaseInstance* instance);
|
|
|
|
~ResourcePackDownloadDialog() override = default;
|
|
|
|
|
|
|
|
//: String that gets appended to the resource pack download dialog title ("Download " + resourcesString())
|
|
|
|
[[nodiscard]] QString resourcesString() const override { return tr("resource packs"); }
|
|
|
|
[[nodiscard]] QString geometrySaveKey() const override { return "RPDownloadGeometry"; }
|
|
|
|
|
|
|
|
QList<BasePage*> getPages() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
BaseInstance* m_instance;
|
|
|
|
};
|
|
|
|
|
2023-01-29 21:07:49 +00:00
|
|
|
class TexturePackDownloadDialog final : public ResourceDownloadDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TexturePackDownloadDialog(QWidget* parent,
|
2023-04-19 22:57:09 +01:00
|
|
|
const std::shared_ptr<TexturePackFolderModel>& resource_packs,
|
|
|
|
BaseInstance* instance);
|
2023-01-29 21:07:49 +00:00
|
|
|
~TexturePackDownloadDialog() override = default;
|
|
|
|
|
|
|
|
//: String that gets appended to the texture pack download dialog title ("Download " + resourcesString())
|
|
|
|
[[nodiscard]] QString resourcesString() const override { return tr("texture packs"); }
|
|
|
|
[[nodiscard]] QString geometrySaveKey() const override { return "TPDownloadGeometry"; }
|
|
|
|
|
|
|
|
QList<BasePage*> getPages() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
BaseInstance* m_instance;
|
|
|
|
};
|
|
|
|
|
2022-12-30 17:06:07 +00:00
|
|
|
class ShaderPackDownloadDialog final : public ResourceDownloadDialog {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2023-04-19 22:57:09 +01:00
|
|
|
explicit ShaderPackDownloadDialog(QWidget* parent, const std::shared_ptr<ShaderPackFolderModel>& shader_packs, BaseInstance* instance);
|
2022-12-30 17:06:07 +00:00
|
|
|
~ShaderPackDownloadDialog() override = default;
|
|
|
|
|
|
|
|
//: String that gets appended to the shader pack download dialog title ("Download " + resourcesString())
|
|
|
|
[[nodiscard]] QString resourcesString() const override { return tr("shader packs"); }
|
|
|
|
[[nodiscard]] QString geometrySaveKey() const override { return "ShaderDownloadGeometry"; }
|
|
|
|
|
|
|
|
QList<BasePage*> getPages() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
BaseInstance* m_instance;
|
|
|
|
};
|
|
|
|
|
2022-12-16 22:03:52 +00:00
|
|
|
} // namespace ResourceDownload
|