1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00

Implemented missing mod description fields

This commit is contained in:
Ivan Savenko 2024-11-14 18:01:49 +00:00
parent 75a1a0938f
commit f72fb53117
5 changed files with 72 additions and 8 deletions

View File

@ -314,8 +314,13 @@ QString CModListView::genModInfoText(const ModState & mod)
QString result;
result += replaceIfNotEmpty(mod.getName(), lineTemplate.arg(tr("Mod name")));
result += replaceIfNotEmpty(mod.getInstalledVersion(), lineTemplate.arg(tr("Installed version")));
result += replaceIfNotEmpty(mod.getRepositoryVersion(), lineTemplate.arg(tr("Latest version")));
if (mod.isUpdateAvailable())
{
result += replaceIfNotEmpty(mod.getInstalledVersion(), lineTemplate.arg(tr("Installed version")));
result += replaceIfNotEmpty(mod.getRepositoryVersion(), lineTemplate.arg(tr("Latest version")));
}
else
result += replaceIfNotEmpty(mod.getVersion(), lineTemplate.arg(tr("Version")));
if(!mod.getLocalSizeFormatted().isEmpty())
result += replaceIfNotEmpty(mod.getLocalSizeFormatted(), lineTemplate.arg(tr("Size")));
@ -416,6 +421,8 @@ void CModListView::dataChanged(const QModelIndex & topleft, const QModelIndex &
void CModListView::selectMod(const QModelIndex & index)
{
ui->tabWidget->setCurrentIndex(0);
if(!index.isValid())
{
disableModInfo();
@ -425,6 +432,9 @@ void CModListView::selectMod(const QModelIndex & index)
const auto modName = index.data(ModRoles::ModNameRole).toString();
auto mod = modStateModel->getMod(modName);
ui->tabWidget->setTabEnabled(1, !mod.getChangelog().isEmpty());
ui->tabWidget->setTabEnabled(2, !mod.getScreenshots().isEmpty());
ui->modInfoBrowser->setHtml(genModInfoText(mod));
ui->changelogBrowser->setHtml(genChangelogText(mod));

View File

@ -13,6 +13,7 @@
#include "../../lib/modding/ModDescription.h"
#include "../../lib/json/JsonNode.h"
#include "../../lib/texts/CGeneralTextHandler.h"
#include "../../lib/texts/Languages.h"
ModState::ModState(const ModDescription & impl)
: impl(impl)
@ -70,7 +71,7 @@ QStringList ModState::getConflicts() const
QStringList ModState::getScreenshots() const
{
return {}; // TODO
return stringListStdToQt(impl.getValue("screenshots").convertTo<std::vector<std::string>>());
}
QString ModState::getBaseLanguage() const
@ -80,12 +81,33 @@ QString ModState::getBaseLanguage() const
QStringList ModState::getSupportedLanguages() const
{
return {}; //TODO
QStringList result;
result.push_back(getBaseLanguage());
for (const auto & language : Languages::getLanguageList())
{
QString languageID = QString::fromStdString(language.identifier);
if (languageID != getBaseLanguage() && !impl.getValue(language.identifier).isNull())
result.push_back(languageID);
}
return result;
}
QMap<QString, QStringList> ModState::getChangelog() const
{
return {}; //TODO
QMap<QString, QStringList> result;
const JsonNode & changelog = impl.getValue("changelog");
for (const auto & entry : changelog.Struct())
{
QString version = QString::fromStdString(entry.first);
QStringList changes = stringListStdToQt(entry.second.convertTo<std::vector<std::string>>());
result[version] = changes;
}
return result;
}
QString ModState::getInstalledVersion() const
@ -98,6 +120,11 @@ QString ModState::getRepositoryVersion() const
return QString::fromStdString(impl.getRepositoryValue("version").String());
}
QString ModState::getVersion() const
{
return QString::fromStdString(impl.getValue("version").String());
}
double ModState::getDownloadSizeMegabytes() const
{
return impl.getRepositoryValue("downloadSize").Float();
@ -110,7 +137,7 @@ size_t ModState::getDownloadSizeBytes() const
QString ModState::getDownloadSizeFormatted() const
{
return {}; // TODO
return QCoreApplication::translate("File size", "%1 MiB").arg(QString::number(getDownloadSizeMegabytes(), 'f', 1));
}
QString ModState::getLocalSizeFormatted() const
@ -145,7 +172,14 @@ QString ModState::getDownloadUrl() const
QPair<QString, QString> ModState::getCompatibleVersionRange() const
{
return {}; // TODO
const JsonNode & compatibility = impl.getValue("compatibility");
if (compatibility.isNull())
return {};
auto min = QString::fromStdString(compatibility["min"].String());
auto max = QString::fromStdString(compatibility["max"].String());
return { min, max};
}
bool ModState::isSubmod() const
@ -203,7 +237,7 @@ bool ModState::isUpdateAvailable() const
bool ModState::isCompatible() const
{
return true; //TODO
return impl.isCompatible();
}
bool ModState::isKeptDisabled() const

View File

@ -41,6 +41,7 @@ public:
QString getInstalledVersion() const;
QString getRepositoryVersion() const;
QString getVersion() const;
double getDownloadSizeMegabytes() const;
size_t getDownloadSizeBytes() const;

View File

@ -126,6 +126,23 @@ ModVerificationInfo ModDescription::getVerificationInfo() const
return result;
}
bool ModDescription::isCompatible() const
{
const JsonNode & compatibility = getValue("compatibility");
if (compatibility.isNull())
return true;
auto vcmiCompatibleMin = CModVersion::fromString(compatibility["min"].String());
auto vcmiCompatibleMax = CModVersion::fromString(compatibility["max"].String());
bool compatible = true;
compatible &= (vcmiCompatibleMin.isNull() || CModVersion::GameVersion().compatible(vcmiCompatibleMin, true, true));
compatible &= (vcmiCompatibleMax.isNull() || vcmiCompatibleMax.compatible(CModVersion::GameVersion(), true, true));
return compatible;
}
bool ModDescription::isCompatibility() const
{
return getValue("modType").String() == "Compatibility";

View File

@ -55,6 +55,8 @@ public:
CModVersion getVersion() const;
ModVerificationInfo getVerificationInfo() const;
bool isCompatible() const;
bool affectsGameplay() const;
bool isCompatibility() const;
bool isTranslation() const;