More intuitive version changing for modpacks (#3841)

This commit is contained in:
Alexandru Ionut Tripon 2025-06-06 08:12:52 +03:00 committed by GitHub
commit 2d90144cd9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 30 additions and 22 deletions

View file

@ -140,3 +140,11 @@ void Flame::loadIndexedPackVersions(Flame::IndexedPack& pack, QJsonArray& arr)
pack.versions = unsortedVersions; pack.versions = unsortedVersions;
pack.versionsLoaded = true; pack.versionsLoaded = true;
} }
auto Flame::getVersionDisplayString(const IndexedVersion& version) -> QString
{
auto release_type = version.version_type.isValid() ? QString(" [%1]").arg(version.version_type.toString()) : "";
auto mcVersion =
!version.mcVersion.isEmpty() && !version.version.contains(version.mcVersion) ? QObject::tr(" for %1").arg(version.mcVersion) : "";
return QString("%1%2%3").arg(version.version, mcVersion, release_type);
}

View file

@ -47,6 +47,8 @@ struct IndexedPack {
void loadIndexedPack(IndexedPack& m, QJsonObject& obj); void loadIndexedPack(IndexedPack& m, QJsonObject& obj);
void loadIndexedInfo(IndexedPack&, QJsonObject&); void loadIndexedInfo(IndexedPack&, QJsonObject&);
void loadIndexedPackVersions(IndexedPack& m, QJsonArray& arr); void loadIndexedPackVersions(IndexedPack& m, QJsonArray& arr);
auto getVersionDisplayString(const IndexedVersion&) -> QString;
} // namespace Flame } // namespace Flame
Q_DECLARE_METATYPE(Flame::IndexedPack) Q_DECLARE_METATYPE(Flame::IndexedPack)

View file

@ -183,4 +183,14 @@ auto loadIndexedVersion(QJsonObject& obj) -> ModpackVersion
return file; return file;
} }
auto getVersionDisplayString(const ModpackVersion& version) -> QString
{
auto release_type = version.version_type.isValid() ? QString(" [%1]").arg(version.version_type.toString()) : "";
auto mcVersion = !version.gameVersion.isEmpty() && !version.name.contains(version.gameVersion)
? QObject::tr(" for %1").arg(version.gameVersion)
: "";
auto versionStr = !version.name.contains(version.version) ? version.version : "";
return QString("%1%2 — %3%4").arg(version.name, mcVersion, versionStr, release_type);
}
} // namespace Modrinth } // namespace Modrinth

View file

@ -120,6 +120,8 @@ auto loadIndexedVersion(QJsonObject&) -> ModpackVersion;
auto validateDownloadUrl(QUrl) -> bool; auto validateDownloadUrl(QUrl) -> bool;
auto getVersionDisplayString(const ModpackVersion&) -> QString;
} // namespace Modrinth } // namespace Modrinth
Q_DECLARE_METATYPE(Modrinth::Modpack) Q_DECLARE_METATYPE(Modrinth::Modpack)

View file

@ -292,11 +292,8 @@ void ModrinthManagedPackPage::parseManagedPack()
ui->versionsComboBox->clear(); ui->versionsComboBox->clear();
ui->versionsComboBox->blockSignals(false); ui->versionsComboBox->blockSignals(false);
for (auto version : m_pack.versions) { for (const auto& version : m_pack.versions) {
QString name = version.version; QString name = Modrinth::getVersionDisplayString(version);
if (!version.name.contains(version.version))
name = QString("%1 — %2").arg(version.name, version.version);
// NOTE: the id from version isn't the same id in the modpack format spec... // NOTE: the id from version isn't the same id in the modpack format spec...
// e.g. HexMC's 4.4.0 has versionId 4.0.0 in the modpack index.............. // e.g. HexMC's 4.4.0 has versionId 4.0.0 in the modpack index..............
@ -489,8 +486,8 @@ void FlameManagedPackPage::parseManagedPack()
ui->versionsComboBox->clear(); ui->versionsComboBox->clear();
ui->versionsComboBox->blockSignals(false); ui->versionsComboBox->blockSignals(false);
for (auto version : m_pack.versions) { for (const auto& version : m_pack.versions) {
QString name = version.version; QString name = Flame::getVersionDisplayString(version);
if (version.fileId == m_inst->getManagedPackVersionID().toInt()) if (version.fileId == m_inst->getManagedPackVersionID().toInt())
name = tr("%1 (Current)").arg(name); name = tr("%1 (Current)").arg(name);

View file

@ -206,13 +206,8 @@ void FlamePage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelInde
else else
++it; ++it;
#endif #endif
for (auto version : current.versions) { for (const auto& version : current.versions) {
auto release_type = version.version_type.isValid() ? QString(" [%1]").arg(version.version_type.toString()) : ""; ui->versionSelectionBox->addItem(Flame::getVersionDisplayString(version), QVariant(version.downloadUrl));
auto mcVersion = !version.mcVersion.isEmpty() && !version.version.contains(version.mcVersion)
? QString(" for %1").arg(version.mcVersion)
: "";
ui->versionSelectionBox->addItem(QString("%1%2%3").arg(version.version, mcVersion, release_type),
QVariant(version.downloadUrl));
} }
QVariant current_updated; QVariant current_updated;

View file

@ -244,14 +244,8 @@ void ModrinthPage::onSelectionChanged(QModelIndex curr, [[maybe_unused]] QModelI
else else
++it; ++it;
#endif #endif
for (auto version : current.versions) { for (const auto& version : current.versions) {
auto release_type = version.version_type.isValid() ? QString(" [%1]").arg(version.version_type.toString()) : ""; ui->versionSelectionBox->addItem(Modrinth::getVersionDisplayString(version), QVariant(version.id));
auto mcVersion = !version.gameVersion.isEmpty() && !version.name.contains(version.gameVersion)
? QString(" for %1").arg(version.gameVersion)
: "";
auto versionStr = !version.name.contains(version.version) ? version.version : "";
ui->versionSelectionBox->addItem(QString("%1%2 — %3%4").arg(version.name, mcVersion, versionStr, release_type),
QVariant(version.id));
} }
QVariant current_updated; QVariant current_updated;