1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
// SPDX-License-Identifier: GPL-3.0-only
/*
* Prism Launcher - Minecraft Launcher
* Copyright (C) 2023 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/>.
*/
#include "InstallLoaderDialog.h"
#include <QDialogButtonBox>
#include <QPushButton>
#include <QVBoxLayout>
#include "Application.h"
#include "BuildConfig.h"
#include "DesktopServices.h"
#include "meta/Index.h"
#include "minecraft/MinecraftInstance.h"
#include "minecraft/PackProfile.h"
#include "ui/widgets/PageContainer.h"
#include "ui/widgets/VersionSelectWidget.h"
class InstallLoaderPage : public VersionSelectWidget, public BasePage {
public:
InstallLoaderPage(const QString& id,
const QString& icon,
const QString& name,
// "lightweight" loaders are independent to any game version
const bool lightweight,
const std::shared_ptr<PackProfile> profile)
: VersionSelectWidget(nullptr), m_id(id), m_icon(icon), m_name(name)
{
const QString minecraftVersion = profile->getComponentVersion("net.minecraft");
setEmptyString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion));
if (!lightweight)
setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion);
if (const QString currentVersion = profile->getComponentVersion(id); !currentVersion.isNull())
setCurrentVersion(currentVersion);
}
QString id() const override { return m_id; }
QString displayName() const override { return m_name; }
QIcon icon() const override { return APPLICATION->getThemedIcon(m_icon); }
void openedImpl() override
{
if (m_loaded)
return;
const auto versions = APPLICATION->metadataIndex()->get(m_id);
if (!versions)
return;
initialize(versions.get());
m_loaded = true;
}
void setParentContainer(BasePageContainer* container) override
{
auto dialog = dynamic_cast<QDialog*>(dynamic_cast<PageContainer*>(container)->parent());
connect(view(), &QAbstractItemView::doubleClicked, dialog, &QDialog::accept);
}
private:
const QString m_id;
const QString m_icon;
const QString m_name;
bool m_loaded = false;
};
InstallLoaderPage* pageCast(BasePage* page)
{
auto result = dynamic_cast<InstallLoaderPage*>(page);
Q_ASSERT(result != nullptr);
return result;
}
InstallLoaderDialog::InstallLoaderDialog(std::shared_ptr<PackProfile> profile, const QString& uid, QWidget* parent)
: QDialog(parent), m_profile(profile), m_container(new PageContainer(this, QString(), this)), m_buttons(new QDialogButtonBox(this))
{
auto layout = new QVBoxLayout(this);
m_container->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
layout->addWidget(m_container);
auto buttonLayout = new QHBoxLayout(this);
auto refreshButton = new QPushButton(tr("&Refresh"), this);
connect(refreshButton, &QPushButton::pressed, this, [this] { pageCast(m_container->selectedPage())->loadList(); });
buttonLayout->addWidget(refreshButton);
m_buttons->setOrientation(Qt::Horizontal);
m_buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
connect(m_buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
buttonLayout->addWidget(m_buttons);
layout->addLayout(buttonLayout);
setWindowTitle(dialogTitle());
resize(650, 400);
pageCast(m_container->selectedPage())->selectSearch();
for (BasePage* page : m_container->getPages())
if (page->id() == uid)
m_container->selectPage(page->id());
}
QList<BasePage*> InstallLoaderDialog::getPages()
{
return { // Forge
new InstallLoaderPage("net.minecraftforge", "forge", tr("Forge"), false, m_profile),
// Fabric
new InstallLoaderPage("net.fabricmc.fabric-loader", "fabricmc-small", tr("Fabric"), true, m_profile),
// Quilt
new InstallLoaderPage("org.quiltmc.quilt-loader", "quiltmc", tr("Quilt"), true, m_profile),
// LiteLoader
new InstallLoaderPage("com.mumfrey.liteloader", "liteloader", tr("LiteLoader"), false, m_profile)
};
}
QString InstallLoaderDialog::dialogTitle()
{
return tr("Install Loader");
}
void InstallLoaderDialog::done(int result)
{
if (result == Accepted) {
auto* page = pageCast(m_container->selectedPage());
if (page->selectedVersion()) {
m_profile->setComponentVersion(page->id(), page->selectedVersion()->descriptor());
m_profile->resolve(Net::Mode::Online);
}
}
QDialog::done(result);
}
|