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

Restored display of enabled and disabled mods in Launcher

This commit is contained in:
Ivan Savenko 2024-11-14 18:43:41 +00:00
parent ac3aecba81
commit 37e975036c
7 changed files with 36 additions and 43 deletions

View File

@ -258,10 +258,12 @@ QString CModListView::genChangelogText(const ModState & mod)
return result;
}
QStringList CModListView::getModNames(QStringList input)
QStringList CModListView::getModNames(QString queryingModID, QStringList input)
{
QStringList result;
auto queryingMod = modStateModel->getMod(queryingModID);
for(const auto & modID : input)
{
// Missing mod - use mod ID
@ -274,6 +276,9 @@ QStringList CModListView::getModNames(QStringList input)
auto mod = modStateModel->getMod(modID);
if (queryingMod.getParentID() == modID)
continue;
if (mod.isHidden())
continue;
@ -281,7 +286,7 @@ QStringList CModListView::getModNames(QStringList input)
if (displayName.isEmpty())
displayName = modID.toLower();
if (mod.isSubmod())
if (mod.isSubmod() && queryingMod.getParentID() != mod.getParentID() )
{
auto parentModID = mod.getTopParentID();
auto parentMod = modStateModel->getMod(parentModID);
@ -375,8 +380,8 @@ QString CModListView::genModInfoText(const ModState & mod)
result += replaceIfNotEmpty(supportedLanguagesTranslated, lineTemplate.arg(tr("Languages")));
}
result += replaceIfNotEmpty(getModNames(mod.getDependencies()), lineTemplate.arg(tr("Required mods")));
result += replaceIfNotEmpty(getModNames(mod.getConflicts()), lineTemplate.arg(tr("Conflicting mods")));
result += replaceIfNotEmpty(getModNames(mod.getID(), mod.getDependencies()), lineTemplate.arg(tr("Required mods")));
result += replaceIfNotEmpty(getModNames(mod.getID(), mod.getConflicts()), lineTemplate.arg(tr("Conflicting mods")));
result += replaceIfNotEmpty(mod.getDescription(), textTemplate.arg(tr("Description")));
result += "<p></p>"; // to get some empty space
@ -389,12 +394,12 @@ QString CModListView::genModInfoText(const ModState & mod)
QString notes;
notes += replaceIfNotEmpty(getModNames(findInvalidDependencies(mod.getID())), listTemplate.arg(unknownDeps));
notes += replaceIfNotEmpty(getModNames(findBlockingMods(mod.getID())), listTemplate.arg(blockingMods));
if(mod.isEnabled())
notes += replaceIfNotEmpty(getModNames(findDependentMods(mod.getID(), true)), listTemplate.arg(hasActiveDependentMods));
notes += replaceIfNotEmpty(getModNames(mod.getID(), findInvalidDependencies(mod.getID())), listTemplate.arg(unknownDeps));
notes += replaceIfNotEmpty(getModNames(mod.getID(), findBlockingMods(mod.getID())), listTemplate.arg(blockingMods));
if(modStateModel->isModEnabled(mod.getID()))
notes += replaceIfNotEmpty(getModNames(mod.getID(), findDependentMods(mod.getID(), true)), listTemplate.arg(hasActiveDependentMods));
if(mod.isInstalled())
notes += replaceIfNotEmpty(getModNames(findDependentMods(mod.getID(), false)), listTemplate.arg(hasDependentMods));
notes += replaceIfNotEmpty(getModNames(mod.getID(), findDependentMods(mod.getID(), false)), listTemplate.arg(hasDependentMods));
if(mod.isSubmod())
notes += noteTemplate.arg(thisIsSubmod);
@ -445,8 +450,8 @@ void CModListView::selectMod(const QModelIndex & index)
bool hasBlockingMods = !findBlockingMods(modName).empty();
bool hasDependentMods = !findDependentMods(modName, true).empty();
ui->disableButton->setVisible(mod.isEnabled());
ui->enableButton->setVisible(mod.isDisabled());
ui->disableButton->setVisible(modStateModel->isModEnabled(mod.getID()));
ui->enableButton->setVisible(!modStateModel->isModEnabled(mod.getID()));
ui->installButton->setVisible(mod.isAvailable() && !mod.isSubmod());
ui->uninstallButton->setVisible(mod.isInstalled() && !mod.isSubmod());
ui->updateButton->setVisible(mod.isUpdateAvailable());
@ -515,7 +520,7 @@ QStringList CModListView::findBlockingMods(QString modUnderTest)
{
auto mod = modStateModel->getMod(name);
if(mod.isEnabled())
if(modStateModel->isModEnabled(mod.getID()))
{
// one of enabled mods have requirement (or this mod) marked as conflict
for(const auto & conflict : mod.getConflicts())
@ -541,7 +546,7 @@ QStringList CModListView::findDependentMods(QString mod, bool excludeDisabled)
if(current.getDependencies().contains(mod, Qt::CaseInsensitive))
{
if(!(current.isDisabled() && excludeDisabled))
if(!(modStateModel->isModEnabled(modName) && excludeDisabled))
ret += modName;
}
}
@ -566,7 +571,7 @@ void CModListView::enableModByName(QString modName)
for(const auto & name : mod.getDependencies())
{
if(modStateModel->getMod(name).isDisabled())
if(!modStateModel->isModEnabled(name))
manager->enableMod(name);
}
}
@ -582,7 +587,7 @@ void CModListView::on_disableButton_clicked()
void CModListView::disableModByName(QString modName)
{
if(modStateModel->isModExists(modName) && modStateModel->getMod(modName).isEnabled())
if(modStateModel->isModExists(modName) && modStateModel->isModEnabled(modName))
manager->disableMod(modName);
}
@ -608,7 +613,7 @@ void CModListView::on_uninstallButton_clicked()
if(modStateModel->isModExists(modName) && modStateModel->getMod(modName).isInstalled())
{
if(modStateModel->getMod(modName).isEnabled())
if(modStateModel->isModEnabled(modName))
manager->disableMod(modName);
manager->uninstallMod(modName);
}
@ -627,14 +632,13 @@ void CModListView::on_installButton_clicked()
auto mod = modStateModel->getMod(name);
if(mod.isAvailable())
downloadFile(name + ".zip", mod.getDownloadUrl(), name, mod.getDownloadSizeMegabytes());
else if(!mod.isEnabled())
else if(modStateModel->isModEnabled(name))
enableModByName(name);
}
for(const auto & name : modStateModel->getMod(modName).getConflicts())
{
auto mod = modStateModel->getMod(name);
if(mod.isEnabled())
if(modStateModel->isModEnabled(name))
{
//TODO: consider reverse dependencies disabling
//TODO: consider if it may be possible for subdependencies to block disabling conflicting mod?
@ -915,7 +919,7 @@ void CModListView::installMods(QStringList archives)
if(entry.isInstalled())
{
// enable mod if installed and enabled
if(entry.isEnabled())
if(modStateModel->isModEnabled(mod))
modsToEnable.push_back(mod);
}
else
@ -948,12 +952,11 @@ void CModListView::installMods(QStringList archives)
{
for(const auto & dependencyName : mod.getDependencies())
{
auto dependency = modStateModel->getMod(dependencyName);
if(dependency.isDisabled())
if(!modStateModel->isModEnabled(dependencyName))
manager->enableMod(dependencyName);
}
if(mod.isDisabled() && manager->enableMod(modName))
if(!modStateModel->isModEnabled(modName) && manager->enableMod(modName))
{
for(QString child : modStateModel->getSubmods(modName))
enableMod(child);
@ -1082,8 +1085,7 @@ bool CModListView::isModAvailable(const QString & modName)
bool CModListView::isModEnabled(const QString & modName)
{
auto mod = modStateModel->getMod(modName);
return mod.isEnabled();
return modStateModel->isModEnabled(modName);
}
bool CModListView::isModInstalled(const QString & modName)
@ -1144,13 +1146,13 @@ void CModListView::on_allModsView_doubleClicked(const QModelIndex &index)
return;
}
if(!hasBlockingMods && !hasInvalidDeps && mod.isDisabled())
if(!hasBlockingMods && !hasInvalidDeps && !modStateModel->isModEnabled(modName))
{
on_enableButton_clicked();
return;
}
if(!hasDependentMods && !mod.isVisible() && mod.isEnabled())
if(!hasDependentMods && !mod.isVisible() && modStateModel->isModEnabled(modName))
{
on_disableButton_clicked();
return;

View File

@ -44,7 +44,7 @@ class CModListView : public QWidget
void checkManagerErrors();
/// replace mod ID's with proper human-readable mod names
QStringList getModNames(QStringList input);
QStringList getModNames(QString queryingMod, QStringList input);
// find mods unknown to mod list (not present in repo and not installed)
QStringList findInvalidDependencies(QString mod);

View File

@ -205,16 +205,6 @@ bool ModState::isHidden() const
return isCompatibility() || getID() == "vcmi" || getID() == "core";
}
bool ModState::isDisabled() const
{
return false; // TODO
}
bool ModState::isEnabled() const
{
return true; // TODO
}
bool ModState::isAvailable() const
{
return !isInstalled();

View File

@ -61,8 +61,6 @@ public:
bool isVisible() const;
bool isHidden() const;
bool isDisabled() const;
bool isEnabled() const;
bool isAvailable() const;
bool isInstalled() const;
bool isUpdateAvailable() const;

View File

@ -284,9 +284,9 @@ bool CModFilterModel::filterMatchesCategory(const QModelIndex & source) const
case ModFilterMask::UPDATEABLE:
return mod.isUpdateAvailable();
case ModFilterMask::ENABLED:
return mod.isInstalled() && mod.isEnabled();
return mod.isInstalled() && base->model->isModEnabled(modID);
case ModFilterMask::DISABLED:
return mod.isInstalled() && mod.isDisabled();
return mod.isInstalled() && !base->model->isModEnabled(modID);
}
assert(0);
return false;

View File

@ -70,7 +70,7 @@ bool ModStateModel::isModInstalled(QString modName) const
bool ModStateModel::isModEnabled(QString modName) const
{
return getMod(modName).isEnabled(); // TODO
return modManager->isModActive(modName.toStdString());
}
bool ModStateModel::isModUpdateAvailable(QString modName) const

View File

@ -27,6 +27,9 @@ ModDescription::ModDescription(const TModID & fullID, const JsonNode & localConf
{
if(getID() != "core")
dependencies.emplace("core");
if (!getParentID().empty())
dependencies.emplace(getParentID());
}
ModDescription::~ModDescription() = default;