1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-08 00:39:47 +02:00

Implement mod update function

This commit is contained in:
Ivan Savenko 2024-12-04 22:53:07 +00:00
parent 3a8b0ead35
commit 9b1ca39818
4 changed files with 44 additions and 5 deletions

View File

@ -581,6 +581,11 @@ QStringList CModListView::getModsToInstall(QString mod)
void CModListView::on_updateButton_clicked()
{
QString modName = ui->allModsView->currentIndex().data(ModRoles::ModNameRole).toString();
doUpdateMod(modName);
}
void CModListView::doUpdateMod(const QString & modName)
{
auto targetMod = modStateModel->getMod(modName);
if(targetMod.isUpdateAvailable())
@ -994,6 +999,20 @@ QStringList CModListView::getInstalledChronicles()
return result;
}
QStringList CModListView::getUpdateableMods()
{
QStringList result;
for(const auto & modName : modStateModel->getAllMods())
{
auto mod = modStateModel->getMod(modName);
if (mod.isUpdateAvailable())
result.push_back(modName);
}
return result;
}
QString CModListView::getTranslationModName(const QString & language)
{
for(const auto & modName : modStateModel->getAllMods())

View File

@ -79,6 +79,9 @@ public:
/// install mod by name
void doInstallMod(const QString & modName);
/// update mod by name
void doUpdateMod(const QString & modName);
/// returns true if mod is available in repository and can be installed
bool isModAvailable(const QString & modName);
@ -88,6 +91,9 @@ public:
/// finds all already imported Heroes Chronicles mods (if any)
QStringList getInstalledChronicles();
/// finds all mods that can be updated
QStringList getUpdateableMods();
/// returns true if mod is currently enabled
bool isModEnabled(const QString & modName);

View File

@ -106,13 +106,14 @@ void StartGameTab::refreshTranslation(ETranslationStatus status)
void StartGameTab::refreshMods()
{
constexpr int chroniclesCount = 8;
QStringList updateableMods; // TODO
QStringList updateableMods = getMainWindow()->getModView()->getUpdateableMods();
QStringList chroniclesMods = getMainWindow()->getModView()->getInstalledChronicles();
ui->buttonUpdateMods->setText(tr("Update %n mods", "", updateableMods.size()));
ui->buttonUpdateMods->setVisible(!updateableMods.empty());
ui->buttonUpdateModsHelp->setVisible(!updateableMods.empty());
ui->labelChronicles->setText(tr("Heroes Chronicles:\n%1/%2 installed").arg(chroniclesMods.size()).arg(chroniclesCount));
ui->labelChronicles->setText(tr("Heroes Chronicles:\n%n/%1 installed", "", chroniclesMods.size()).arg(chroniclesCount));
ui->labelChronicles->setVisible(chroniclesMods.size() != chroniclesCount);
ui->buttonChroniclesHelp->setVisible(chroniclesMods.size() != chroniclesCount);
}
@ -183,7 +184,17 @@ void StartGameTab::on_buttonImportFiles_clicked()
void StartGameTab::on_buttonInstallTranslation_clicked()
{
// TODO
if (getMainWindow()->getTranslationStatus() == ETranslationStatus::NOT_INSTALLLED)
{
getMainWindow()->getModView()->getTranslationModName();
mainWindow->getModView()->doInstallMod(modName);
}
}
else
{
mainWindow->getModView()->enableModByName(modName);
}
}
}
void StartGameTab::on_buttonActivateTranslation_clicked()
@ -193,7 +204,10 @@ void StartGameTab::on_buttonActivateTranslation_clicked()
void StartGameTab::on_buttonUpdateMods_clicked()
{
// TODO
QStringList updateableMods = getMainWindow()->getModView()->getUpdateableMods();
for (const auto & modName : updateableMods)
getMainWindow()->getModView()->doInstallMod(modName);
}
void StartGameTab::on_buttonHelpImportFiles_clicked()

View File

@ -567,7 +567,7 @@
</size>
</property>
<property name="text">
<string>Update %1 mods</string>
<string/>
</property>
</widget>
</item>