1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-14 10:12:59 +02:00
This commit is contained in:
Ivan Savenko 2024-11-13 20:27:51 +00:00
parent 06ce71087e
commit 67fdd14dca
9 changed files with 27 additions and 51 deletions

View File

@ -206,11 +206,6 @@ void MainWindow::on_startEditorButton_clicked()
startEditor({});
}
//const CModList & MainWindow::getModList() const
//{
// return ui->modlistView->getModList();
//}
CModListView * MainWindow::getModView()
{
return ui->modlistView;

View File

@ -46,7 +46,6 @@ public:
explicit MainWindow(QWidget * parent = nullptr);
~MainWindow() override;
// const CModList & getModList() const;
CModListView * getModView();
void updateTranslation();

View File

@ -176,7 +176,7 @@ void CModListView::loadRepositories()
if (settings["launcher"]["extraRepositoryEnabled"].Bool())
repositories.push_back(QString::fromStdString(settings["launcher"]["extraRepositoryURL"].String()));
for(auto entry : repositories)
for(const auto & entry : repositories)
{
if (entry.isEmpty())
continue;
@ -218,7 +218,7 @@ static QString replaceIfNotEmpty(QStringList value, QString pattern)
return "";
}
QString CModListView::genChangelogText(ModState & mod)
QString CModListView::genChangelogText(const ModState & mod)
{
QString headerTemplate = "<p><span style=\" font-weight:600;\">%1: </span></p>";
QString entryBegin = "<p align=\"justify\"><ul>";
@ -237,11 +237,11 @@ QString CModListView::genChangelogText(ModState & mod)
});
std::reverse(versions.begin(), versions.end());
for(auto & version : versions)
for(const auto & version : versions)
{
result += headerTemplate.arg(version);
result += entryBegin;
for(auto & line : changelog.value(version))
for(const auto & line : changelog.value(version))
result += entryLine.arg(line);
result += entryEnd;
}
@ -286,7 +286,7 @@ QStringList CModListView::getModNames(QStringList input)
return result;
}
QString CModListView::genModInfoText(ModState & mod)
QString CModListView::genModInfoText(const ModState & mod)
{
QString prefix = "<p><span style=\" font-weight:600;\">%1: </span>"; // shared prefix
QString redPrefix = "<p><span style=\" font-weight:600; color:red\">%1: </span>"; // shared prefix
@ -495,7 +495,7 @@ QStringList CModListView::findBlockingMods(QString modUnderTest)
if(mod.isEnabled())
{
// one of enabled mods have requirement (or this mod) marked as conflict
for(auto conflict : mod.getConflicts())
for(const auto & conflict : mod.getConflicts())
{
if(required.contains(conflict))
ret.push_back(name);
@ -541,12 +541,11 @@ void CModListView::enableModByName(QString modName)
auto mod = modStateModel->getMod(modName);
for(auto & name : mod.getDependencies())
for(const auto & name : mod.getDependencies())
{
if(modStateModel->getMod(name).isDisabled())
manager->enableMod(name);
}
emit modsChanged();
}
void CModListView::on_disableButton_clicked()
@ -562,8 +561,6 @@ void CModListView::disableModByName(QString modName)
{
if(modStateModel->isModExists(modName) && modStateModel->getMod(modName).isEnabled())
manager->disableMod(modName);
emit modsChanged();
}
void CModListView::on_updateButton_clicked()
@ -572,7 +569,7 @@ void CModListView::on_updateButton_clicked()
assert(findInvalidDependencies(modName).empty());
for(auto & name : modStateModel->getMod(modName).getDependencies())
for(const auto & name : modStateModel->getMod(modName).getDependencies())
{
auto mod = modStateModel->getMod(name);
// update required mod, install missing (can be new dependency)
@ -593,7 +590,6 @@ void CModListView::on_uninstallButton_clicked()
manager->uninstallMod(modName);
}
emit modsChanged();
checkManagerErrors();
}
@ -603,7 +599,7 @@ void CModListView::on_installButton_clicked()
assert(findInvalidDependencies(modName).empty());
for(auto & name : modStateModel->getMod(modName).getDependencies())
for(const auto & name : modStateModel->getMod(modName).getDependencies())
{
auto mod = modStateModel->getMod(name);
if(mod.isAvailable())
@ -612,7 +608,7 @@ void CModListView::on_installButton_clicked()
enableModByName(name);
}
for(auto & name : modStateModel->getMod(modName).getConflicts())
for(const auto & name : modStateModel->getMod(modName).getConflicts())
{
auto mod = modStateModel->getMod(name);
if(mod.isEnabled())
@ -674,11 +670,10 @@ void CModListView::manualInstallFile(QString filePath)
// reload settings
Helper::loadSettings();
for(auto widget : qApp->allWidgets())
for(const auto widget : qApp->allWidgets())
if(auto settingsView = qobject_cast<CSettingsView *>(widget))
settingsView->loadSettings();
// manager->loadMods();
// manager->loadModSettings();
// TODO: rescan local mods
}
}
}
@ -771,7 +766,6 @@ void CModListView::downloadFinished(QStringList savedFiles, QStringList failedFi
installFiles(savedFiles);
hideProgressBar();
emit modsChanged();
}
void CModListView::hideProgressBar()
@ -868,9 +862,7 @@ void CModListView::installFiles(QStringList files)
{
//update
CResourceHandler::get("initial")->updateFilteredFiles([](const std::string &){ return true; });
// manager->loadMods();
// modModel->reloadRepositories();
emit modsChanged();
// TODO: rescan local mods
}
}
@ -931,7 +923,7 @@ void CModListView::installMods(QStringList archives)
auto mod = modStateModel->getMod(modName);
if(mod.isInstalled() && !mod.isKeptDisabled())
{
for (auto const & dependencyName : mod.getDependencies())
for(const auto & dependencyName : mod.getDependencies())
{
auto dependency = modStateModel->getMod(dependencyName);
if(dependency.isDisabled())
@ -1048,17 +1040,11 @@ void CModListView::on_screenshotsList_clicked(const QModelIndex & index)
}
}
//const CModList & CModListView::getModList() const
//{
// assert(modModel);
// return *modModel;
//}
void CModListView::doInstallMod(const QString & modName)
{
assert(findInvalidDependencies(modName).empty());
for(auto & name : modStateModel->getMod(modName).getDependencies())
for(const auto & name : modStateModel->getMod(modName).getDependencies())
{
auto mod = modStateModel->getMod(name);
if(!mod.isInstalled())

View File

@ -61,14 +61,12 @@ class CModListView : public QWidget
void installMaps(QStringList maps);
void installFiles(QStringList mods);
QString genChangelogText(ModState & mod);
QString genModInfoText(ModState & mod);
QString genChangelogText(const ModState & mod);
QString genModInfoText(const ModState & mod);
void changeEvent(QEvent *event) override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent *event) override;
signals:
void modsChanged();
public:
explicit CModListView(QWidget * parent = nullptr);
@ -81,8 +79,6 @@ public:
void selectMod(const QModelIndex & index);
//const CModList & getModList() const;
// First Launch View interface
/// install mod by name

View File

@ -198,7 +198,7 @@ bool ModState::isInstalled() const
bool ModState::isUpdateAvailable() const
{
return getInstalledVersion() != getRepositoryVersion() && !getRepositoryVersion().isEmpty() && !getInstalledVersion().isEmpty();;
return getInstalledVersion() != getRepositoryVersion() && !getRepositoryVersion().isEmpty() && !getInstalledVersion().isEmpty();
}
bool ModState::isCompatible() const

View File

@ -42,7 +42,7 @@ QString detectModArchive(QString path, QString modName, std::vector<std::string>
for(int folderLevel : {0, 1}) //search in subfolder if there is no mod.json in the root
{
for(auto file : filesToExtract)
for(const auto & file : filesToExtract)
{
QString filename = QString::fromUtf8(file.c_str());
modDirName = filename.section('/', 0, folderLevel);
@ -56,7 +56,7 @@ QString detectModArchive(QString path, QString modName, std::vector<std::string>
logGlobal->error("Failed to detect mod path in archive!");
logGlobal->debug("List of file in archive:");
for(auto file : filesToExtract)
for(const auto & file : filesToExtract)
logGlobal->debug("%s", file.c_str());
return "";
@ -180,7 +180,7 @@ bool ModStateController::canEnableMod(QString modname)
if(!mod.isCompatible())
return addError(modname, tr("Mod is not compatible, please update VCMI and checkout latest mod revisions"));
for(auto modEntry : mod.getDependencies())
for(const auto & modEntry : mod.getDependencies())
{
if(!modList->isModExists(modEntry)) // required mod is not available
return addError(modname, tr("Required mod %1 is missing").arg(modEntry));
@ -193,14 +193,14 @@ bool ModStateController::canEnableMod(QString modname)
for(QString modEntry : modList->getAllMods())
{
auto mod = modList->getMod(modEntry);
auto otherMod = modList->getMod(modEntry);
// "reverse conflict" - enabled mod has this one as conflict
if(modList->isModEnabled(modname) && mod.getConflicts().contains(modname))
if(modList->isModEnabled(modname) && otherMod.getConflicts().contains(modname))
return addError(modname, tr("This mod conflicts with %1").arg(modEntry));
}
for(auto modEntry : mod.getConflicts())
for(const auto & modEntry : mod.getConflicts())
{
// check if conflicting mod installed and enabled
if(modList->isModExists(modEntry) && modList->isModEnabled(modEntry))
@ -257,7 +257,7 @@ bool ModStateController::doInstallMod(QString modname, QString archivePath)
{
const auto destDirFsPath = qstringToPath(destDir);
ZipArchive archive(qstringToPath(archivePath));
for (auto const & file : filesToExtract)
for(const auto & file : filesToExtract)
{
if (!archive.extract(destDirFsPath, file))
return false;

View File

@ -109,7 +109,6 @@ QVariant ModStateItemModel::getText(const ModState & mod, int field) const
QVariant ModStateItemModel::getIcon(const ModState & mod, int field) const
{
if (field == ModFields::STATUS_ENABLED)
{
if (!model->isModInstalled(mod.getID()))

View File

@ -46,7 +46,7 @@ enum EModRoles
};
}
class ModStateItemModel : public QAbstractItemModel
class ModStateItemModel : public QAbstractItemModel
{
friend class CModFilterModel;
Q_OBJECT

View File

@ -19,6 +19,7 @@
#include "../CConfigHandler.h"
#include "../CCreatureHandler.h"
#include "../GameSettings.h"
#include "../ScriptHandler.h"
#include "../VCMI_Lib.h"
#include "../filesystem/Filesystem.h"
#include "../json/JsonUtils.h"