NOISSUE handle recommended versions better

Moved constants to the version data file
Use recommended Minecraft instead of latest stable for new instances by default
This commit is contained in:
Petr Mrázek 2015-05-02 12:44:37 +02:00
parent bb01c91469
commit 4fc4a17256
8 changed files with 40 additions and 8 deletions

View File

@ -64,7 +64,7 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent)
resize(minimumSizeHint());
layout()->setSizeConstraint(QLayout::SetFixedSize);
setSelectedVersion(MMC->minecraftlist()->getLatestStable(), true);
setSelectedVersion(MMC->minecraftlist()->getRecommended(), true);
InstIconKey = "infinity";
ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey));

View File

@ -38,6 +38,11 @@ BaseVersionPtr BaseVersionList::getLatestStable() const
return at(0);
}
BaseVersionPtr BaseVersionList::getRecommended() const
{
return getLatestStable();
}
QVariant BaseVersionList::data(const QModelIndex &index, int role) const
{
if (!index.isValid())

View File

@ -90,12 +90,16 @@ public:
virtual BaseVersionPtr findVersion(const QString &descriptor);
/*!
* \brief Gets the latest stable version of this instance type.
* This is the version that will be selected by default.
* By default, this is simply the first version in the list.
* \brief Gets the latest stable version from this list
*/
virtual BaseVersionPtr getLatestStable() const;
/*!
* \brief Gets the recommended version from this list
* If the list doesn't support recommended versions, this works exactly as getLatestStable
*/
virtual BaseVersionPtr getRecommended() const;
/*!
* Sorts the version list.
*/

View File

@ -23,6 +23,7 @@
#include "java/JavaCheckerJob.h"
#include "java/JavaUtils.h"
#include "MMCStrings.h"
#include "minecraft/VersionFilterData.h"
JavaVersionList::JavaVersionList(QObject *parent) : BaseVersionList(parent)
{
@ -121,8 +122,8 @@ bool sortJavas(BaseVersionPtr left, BaseVersionPtr right)
if(archCompare != 0)
return archCompare > 0;
// dirty hack - 1.9 and above is too new
auto labove19 = Strings::naturalCompare(rleft->name(), "1.9.0", Qt::CaseInsensitive) >= 0;
auto rabove19 = Strings::naturalCompare(rright->name(), "1.9.0", Qt::CaseInsensitive) >= 0;
auto labove19 = Strings::naturalCompare(rleft->name(), g_VersionFilterData.discouragedJavaVersion, Qt::CaseInsensitive) >= 0;
auto rabove19 = Strings::naturalCompare(rright->name(), g_VersionFilterData.discouragedJavaVersion, Qt::CaseInsensitive) >= 0;
if(labove19 == rabove19)
{
// prefer higher versions in general

View File

@ -364,7 +364,7 @@ QVariant MinecraftVersionList::data(const QModelIndex& index, int role) const
return version->descriptor();
case RecommendedRole:
return version->descriptor() == "1.7.10";
return version->descriptor() == g_VersionFilterData.recommendedMinecraftVersion;
case TypeRole:
return version->typeString();
@ -386,6 +386,19 @@ BaseVersionPtr MinecraftVersionList::getLatestStable() const
return BaseVersionPtr();
}
BaseVersionPtr MinecraftVersionList::getRecommended() const
{
for(auto item: m_vlist)
{
auto version = std::dynamic_pointer_cast<MinecraftVersion>(item);
if(version->descriptor() == g_VersionFilterData.recommendedMinecraftVersion)
{
return item;
}
}
return getLatestStable();
}
void MinecraftVersionList::updateListData(QList<BaseVersionPtr> versions)
{
beginResetModel();

View File

@ -53,7 +53,8 @@ public:
virtual QVariant data(const QModelIndex & index, int role) const;
virtual RoleList providesRoles();
virtual BaseVersionPtr getLatestStable() const;
virtual BaseVersionPtr getLatestStable() const override;
virtual BaseVersionPtr getRecommended() const override;
protected:
QList<BaseVersionPtr> m_vlist;

View File

@ -69,4 +69,8 @@ VersionFilterData::VersionFilterData()
QSet<QString>{"net.java.jinput:jinput", "net.java.jinput:jinput-platform",
"net.java.jutils:jutils", "org.lwjgl.lwjgl:lwjgl",
"org.lwjgl.lwjgl:lwjgl_util", "org.lwjgl.lwjgl:lwjgl-platform"};
// Version list magic
recommendedMinecraftVersion = "1.7.10";
discouragedJavaVersion = "1.9.0";
}

View File

@ -24,5 +24,9 @@ struct VersionFilterData
QDateTime legacyCutoffDate;
// Libraries that belong to LWJGL
QSet<QString> lwjglWhitelist;
// Currently recommended minecraft version
QString recommendedMinecraftVersion;
// Currently discouraged java version (anything equal and above will be discouraged)
QString discouragedJavaVersion;
};
extern VersionFilterData g_VersionFilterData;