Better parent version filtering; handle old fabric :P

Signed-off-by: TheKodeToad <TheKodeToad@proton.me>
This commit is contained in:
TheKodeToad 2023-07-03 20:48:37 +01:00
parent 0e5c377680
commit 64c591b234
8 changed files with 40 additions and 20 deletions

View File

@ -16,6 +16,12 @@ bool ExactFilter::accepts(const QString& value)
return value == pattern; return value == pattern;
} }
ExactIfPresentFilter::ExactIfPresentFilter(const QString& pattern) : pattern(pattern) {}
bool ExactIfPresentFilter::accepts(const QString& value)
{
return value.isEmpty() || value == pattern;
}
RegexpFilter::RegexpFilter(const QString& regexp, bool invert) RegexpFilter::RegexpFilter(const QString& regexp, bool invert)
:invert(invert) :invert(invert)
{ {

View File

@ -30,6 +30,16 @@ private:
QString pattern; QString pattern;
}; };
class ExactIfPresentFilter: public Filter
{
public:
ExactIfPresentFilter(const QString& pattern);
~ExactIfPresentFilter() override = default;
bool accepts(const QString& value) override;
private:
QString pattern;
};
class RegexpFilter: public Filter class RegexpFilter: public Filter
{ {
public: public:

View File

@ -35,15 +35,16 @@ class InstallLoaderPage : public VersionSelectWidget, public BasePage {
InstallLoaderPage(const QString& id, InstallLoaderPage(const QString& id,
const QString& icon, const QString& icon,
const QString& name, const QString& name,
// "lightweight" loaders are independent to any game version const Version& oldestVersion,
const bool lightweight,
const std::shared_ptr<PackProfile> profile) const std::shared_ptr<PackProfile> profile)
: VersionSelectWidget(nullptr), uid(id), iconName(icon), name(name) : VersionSelectWidget(nullptr), uid(id), iconName(icon), name(name)
{ {
const QString minecraftVersion = profile->getComponentVersion("net.minecraft"); const QString minecraftVersion = profile->getComponentVersion("net.minecraft");
setEmptyString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion)); setEmptyString(tr("No versions are currently available for Minecraft %1").arg(minecraftVersion));
if (!lightweight) setExactIfPresentFilter(BaseVersionList::ParentVersionRole, minecraftVersion);
setExactFilter(BaseVersionList::ParentVersionRole, minecraftVersion);
if (oldestVersion != Version() && Version(minecraftVersion) < oldestVersion)
setExactFilter(BaseVersionList::ParentVersionRole, "AAA");
if (const QString currentVersion = profile->getComponentVersion(id); !currentVersion.isNull()) if (const QString currentVersion = profile->getComponentVersion(id); !currentVersion.isNull())
setCurrentVersion(currentVersion); setCurrentVersion(currentVersion);
@ -129,13 +130,13 @@ InstallLoaderDialog::InstallLoaderDialog(std::shared_ptr<PackProfile> profile, c
QList<BasePage*> InstallLoaderDialog::getPages() QList<BasePage*> InstallLoaderDialog::getPages()
{ {
return { // Forge return { // Forge
new InstallLoaderPage("net.minecraftforge", "forge", tr("Forge"), false, profile), new InstallLoaderPage("net.minecraftforge", "forge", tr("Forge"), {}, profile),
// Fabric // Fabric
new InstallLoaderPage("net.fabricmc.fabric-loader", "fabricmc-small", tr("Fabric"), true, profile), new InstallLoaderPage("net.fabricmc.fabric-loader", "fabricmc-small", tr("Fabric"), Version("1.14"), profile),
// Quilt // Quilt
new InstallLoaderPage("org.quiltmc.quilt-loader", "quiltmc", tr("Quilt"), true, profile), new InstallLoaderPage("org.quiltmc.quilt-loader", "quiltmc", tr("Quilt"), Version("1.14"), profile),
// LiteLoader // LiteLoader
new InstallLoaderPage("com.mumfrey.liteloader", "liteloader", tr("LiteLoader"), false, profile) new InstallLoaderPage("com.mumfrey.liteloader", "liteloader", tr("LiteLoader"), {}, profile)
}; };
} }

View File

@ -152,6 +152,10 @@ void VersionSelectDialog::setExactFilter(BaseVersionList::ModelRoles role, QStri
m_versionWidget->setExactFilter(role, filter); m_versionWidget->setExactFilter(role, filter);
} }
void VersionSelectDialog::setExactIfPresentFilter(BaseVersionList::ModelRoles role, QString filter) {
m_versionWidget->setExactIfPresentFilter(role, filter);
}
void VersionSelectDialog::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter) void VersionSelectDialog::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter)
{ {
m_versionWidget->setFuzzyFilter(role, filter); m_versionWidget->setFuzzyFilter(role, filter);

View File

@ -49,6 +49,7 @@ public:
void setCurrentVersion(const QString & version); void setCurrentVersion(const QString & version);
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter); void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactFilter(BaseVersionList::ModelRoles role, QString filter); void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactIfPresentFilter(BaseVersionList::ModelRoles role, QString filter);
void setEmptyString(QString emptyString); void setEmptyString(QString emptyString);
void setEmptyErrorString(QString emptyErrorString); void setEmptyErrorString(QString emptyErrorString);
void setResizeOn(int column); void setResizeOn(int column);

View File

@ -434,22 +434,14 @@ void VersionPage::on_actionChange_version_triggered()
} }
auto uid = list->uid(); auto uid = list->uid();
// FIXME: this is still a horrible HACK.
if (uid == "net.minecraftforge" || uid == "com.mumfrey.liteloader" || uid == "net.fabricmc.fabric-loader" ||
uid == "org.quiltmc.quilt-loader") {
InstallLoaderDialog dialog(m_inst->getPackProfile(), uid, this);
dialog.exec();
m_container->refreshContainer();
return;
}
VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this); VersionSelectDialog vselect(list.get(), tr("Change %1 version").arg(name), this);
if (uid == "net.fabricmc.intermediary" || uid == "org.quiltmc.hashed") if (uid == "net.fabricmc.intermediary" || uid == "org.quiltmc.hashed")
{ {
vselect.setEmptyString(tr("No intermediary mappings versions are currently available.")); vselect.setEmptyString(tr("No intermediary mappings versions are currently available."));
vselect.setEmptyErrorString(tr("Couldn't load or download the intermediary mappings version lists!")); vselect.setEmptyErrorString(tr("Couldn't load or download the intermediary mappings version lists!"));
vselect.setExactFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
} }
vselect.setExactIfPresentFilter(BaseVersionList::ParentVersionRole, m_profile->getComponentVersion("net.minecraft"));
auto currentVersion = patch->getVersion(); auto currentVersion = patch->getVersion();
if(!currentVersion.isEmpty()) if(!currentVersion.isEmpty())
{ {

View File

@ -238,14 +238,19 @@ BaseVersion::Ptr VersionSelectWidget::selectedVersion() const
return variant.value<BaseVersion::Ptr>(); return variant.value<BaseVersion::Ptr>();
} }
void VersionSelectWidget::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter)
{
m_proxyModel->setFilter(role, new ContainsFilter(filter));
}
void VersionSelectWidget::setExactFilter(BaseVersionList::ModelRoles role, QString filter) void VersionSelectWidget::setExactFilter(BaseVersionList::ModelRoles role, QString filter)
{ {
m_proxyModel->setFilter(role, new ExactFilter(filter)); m_proxyModel->setFilter(role, new ExactFilter(filter));
} }
void VersionSelectWidget::setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter) void VersionSelectWidget::setExactIfPresentFilter(BaseVersionList::ModelRoles role, QString filter)
{ {
m_proxyModel->setFilter(role, new ContainsFilter(filter)); m_proxyModel->setFilter(role, new ExactIfPresentFilter(filter));
} }
void VersionSelectWidget::setFilter(BaseVersionList::ModelRoles role, Filter *filter) void VersionSelectWidget::setFilter(BaseVersionList::ModelRoles role, Filter *filter)

View File

@ -70,6 +70,7 @@ public:
void setCurrentVersion(const QString & version); void setCurrentVersion(const QString & version);
void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter); void setFuzzyFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactFilter(BaseVersionList::ModelRoles role, QString filter); void setExactFilter(BaseVersionList::ModelRoles role, QString filter);
void setExactIfPresentFilter(BaseVersionList::ModelRoles role, QString filter);
void setFilter(BaseVersionList::ModelRoles role, Filter *filter); void setFilter(BaseVersionList::ModelRoles role, Filter *filter);
void setEmptyString(QString emptyString); void setEmptyString(QString emptyString);
void setEmptyErrorString(QString emptyErrorString); void setEmptyErrorString(QString emptyErrorString);