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

More progress with Start Game tab, Chronicles status shown

This commit is contained in:
Ivan Savenko 2024-12-04 20:56:34 +00:00
parent 009fe1836a
commit 3a8b0ead35
9 changed files with 183 additions and 53 deletions

View File

@ -549,15 +549,13 @@ void FirstLaunchView::modPresetUpdate()
QString FirstLaunchView::findTranslationModName()
{
if (!getModView())
auto * mainWindow = dynamic_cast<MainWindow *>(QApplication::activeWindow());
auto status = mainWindow->getTranslationStatus();
if (status == ETranslationStatus::ACTIVE || status == ETranslationStatus::NOT_AVAILABLE)
return QString();
QString preferredlanguage = QString::fromStdString(settings["general"]["language"].String());
QString installedlanguage = QString::fromStdString(settings["session"]["language"].String());
if (preferredlanguage == installedlanguage)
return QString();
return getModView()->getTranslationModName(preferredlanguage);
}

View File

@ -286,6 +286,28 @@ void MainWindow::manualInstallFile(QString filePath)
getModView()->downloadFile(fileName, QUrl::fromLocalFile(filePath), fileName);
}
ETranslationStatus MainWindow::getTranslationStatus()
{
QString preferredlanguage = QString::fromStdString(settings["general"]["language"].String());
QString installedlanguage = QString::fromStdString(settings["session"]["language"].String());
if (preferredlanguage == installedlanguage)
return ETranslationStatus::ACTIVE;
QString modName = getModView()->getTranslationModName(preferredlanguage);
if (modName.isEmpty())
return ETranslationStatus::NOT_AVAILABLE;
if (!getModView()->isModInstalled(modName))
return ETranslationStatus::NOT_INSTALLLED;
if (!getModView()->isModEnabled(modName))
return ETranslationStatus::DISABLED;
return ETranslationStatus::ACTIVE;
}
void MainWindow::updateTranslation()
{
#ifdef ENABLE_QT_TRANSLATIONS

View File

@ -23,6 +23,14 @@ class QTableWidgetItem;
class CModList;
class CModListView;
enum class ETranslationStatus : int8_t
{
NOT_AVAILABLE, // translation for this language was not found in mod list. Could also happen if player is offline or disabled repository checkout
NOT_INSTALLLED, // translation mod found, but it is not installed
DISABLED, // translation mod found, and installed, but toggled off
ACTIVE // translation mod active OR game is already in specified language (e.g. English H3 for players with English language)
};
class MainWindow : public QMainWindow
{
Q_OBJECT
@ -60,7 +68,9 @@ public:
void dragEnterEvent(QDragEnterEvent* event) override;
void dropEvent(QDropEvent *event) override;
void manualInstallFile(QString filePath);
ETranslationStatus getTranslationStatus();
protected:
void changeEvent(QEvent * event) override;

View File

@ -975,6 +975,25 @@ bool CModListView::isModInstalled(const QString & modName)
return mod.isInstalled();
}
QStringList CModListView::getInstalledChronicles()
{
QStringList result;
for(const auto & modName : modStateModel->getAllMods())
{
auto mod = modStateModel->getMod(modName);
if (!mod.isInstalled())
continue;
if (mod.getTopParentID() != "chronicles")
continue;
result += modName;
}
return result;
}
QString CModListView::getTranslationModName(const QString & language)
{
for(const auto & modName : modStateModel->getAllMods())

View File

@ -52,7 +52,6 @@ class CModListView : public QWidget
// find mods unknown to mod list (not present in repo and not installed)
QStringList findUnavailableMods(QStringList candidates);
void installMods(QStringList archives);
void installMaps(QStringList maps);
void installFiles(QStringList mods);
@ -86,6 +85,9 @@ public:
/// finds translation mod for specified languages. Returns empty string on error
QString getTranslationModName(const QString & language);
/// finds all already imported Heroes Chronicles mods (if any)
QStringList getInstalledChronicles();
/// returns true if mod is currently enabled
bool isModEnabled(const QString & modName);

View File

@ -517,36 +517,26 @@ void CSettingsView::loadTranslation()
if (!mainWindow)
return;
QString languageName = QString::fromStdString(settings["general"]["language"].String());
QString modName = mainWindow->getModView()->getTranslationModName(languageName);
bool translationExists = !modName.isEmpty();
bool translationNeeded = languageName != baseLanguage;
bool showTranslation = translationNeeded && translationExists;
auto translationStatus = mainWindow->getTranslationStatus();
bool showTranslation = translationStatus == ETranslationStatus::DISABLED || translationStatus == ETranslationStatus::NOT_INSTALLLED;
ui->labelTranslation->setVisible(showTranslation);
ui->labelTranslationStatus->setVisible(showTranslation);
ui->pushButtonTranslation->setVisible(showTranslation);
ui->pushButtonTranslation->setVisible(translationStatus != ETranslationStatus::ACTIVE);
if (!translationExists || !translationNeeded)
return;
bool translationAvailable = mainWindow->getModView()->isModAvailable(modName);
bool translationEnabled = mainWindow->getModView()->isModEnabled(modName);
ui->pushButtonTranslation->setVisible(!translationEnabled);
if (translationEnabled)
if (translationStatus == ETranslationStatus::ACTIVE)
{
ui->labelTranslationStatus->setText(tr("Active"));
}
if (!translationEnabled && !translationAvailable)
if (translationStatus == ETranslationStatus::DISABLED)
{
ui->labelTranslationStatus->setText(tr("Disabled"));
ui->pushButtonTranslation->setText(tr("Enable"));
}
if (translationAvailable)
if (translationStatus == ETranslationStatus::NOT_INSTALLLED)
{
ui->labelTranslationStatus->setText(tr("Not Installed"));
ui->pushButtonTranslation->setText(tr("Install"));

View File

@ -41,7 +41,7 @@ void StartGameTab::refreshState()
{
refreshGameData();
refreshUpdateStatus(EGameUpdateStatus::NOT_CHECKED);//TODO
refreshTranslation(ETranslationStatus::ACTIVE);
refreshTranslation(getMainWindow()->getTranslationStatus());
refreshMods();
}
@ -92,8 +92,6 @@ void StartGameTab::refreshGameData()
ui->buttonMissingFilesHelp->setVisible(missingGameFiles);
ui->buttonMissingVideoHelp->setVisible(missingVideoFiles);
ui->buttonMissingSoundtrackHelp->setVisible(missingSoundtrack);
// TODO: Chronicles
}
void StartGameTab::refreshTranslation(ETranslationStatus status)
@ -107,10 +105,16 @@ void StartGameTab::refreshTranslation(ETranslationStatus status)
void StartGameTab::refreshMods()
{
QStringList updateableMods;
constexpr int chroniclesCount = 8;
QStringList updateableMods; // TODO
QStringList chroniclesMods = getMainWindow()->getModView()->getInstalledChronicles();
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->setVisible(chroniclesMods.size() != chroniclesCount);
ui->buttonChroniclesHelp->setVisible(chroniclesMods.size() != chroniclesCount);
}
void StartGameTab::refreshUpdateStatus(EGameUpdateStatus status)
@ -134,26 +138,22 @@ void StartGameTab::on_buttonOpenChangelog_clicked()
QDesktopServices::openUrl(QUrl("https://vcmi.eu/ChangeLog/"));
}
void StartGameTab::on_buttonOpenDownloads_clicked()
{
QDesktopServices::openUrl(QUrl("https://vcmi.eu/download/"));
}
void StartGameTab::on_buttonUpdateCheck_clicked()
{
// TODO: implement
}
void StartGameTab::on_buttonGameEditor_clicked()
{
getMainWindow()->hide();
startEditor({});
}
void StartGameTab::on_buttonImportFiles_clicked()
{
const auto & importFunctor = [this]
@ -181,5 +181,62 @@ void StartGameTab::on_buttonImportFiles_clicked()
QTimer::singleShot(0, this, importFunctor);
}
void StartGameTab::on_buttonInstallTranslation_clicked()
{
// TODO
}
void StartGameTab::on_buttonActivateTranslation_clicked()
{
// TODO
}
void StartGameTab::on_buttonUpdateMods_clicked()
{
// TODO
}
void StartGameTab::on_buttonHelpImportFiles_clicked()
{
QMessageBox::information(this, ui->buttonImportFiles->text(), tr("TODO")); // TODO
}
void StartGameTab::on_buttonInstallTranslationHelp_clicked()
{
QMessageBox::information(this, ui->buttonInstallTranslation->text(), tr("TODO")); // TODO
}
void StartGameTab::on_buttonActivateTranslationHelp_clicked()
{
QMessageBox::information(this, ui->buttonActivateTranslation->text(), tr("TODO")); // TODO
}
void StartGameTab::on_buttonUpdateModsHelp_clicked()
{
QMessageBox::information(this, ui->buttonUpdateMods->text(), tr("TODO")); // TODO
}
void StartGameTab::on_buttonChroniclesHelp_clicked()
{
QMessageBox::information(this, ui->labelChronicles->text(), tr("TODO")); // TODO
}
void StartGameTab::on_buttonMissingSoundtrackHelp_clicked()
{
QMessageBox::information(this, ui->labelMissingSoundtrack->text(), tr("TODO")); // TODO
}
void StartGameTab::on_buttonMissingVideoHelp_clicked()
{
QMessageBox::information(this, ui->labelMissingVideo->text(), tr("TODO")); // TODO
}
void StartGameTab::on_buttonMissingFilesHelp_clicked()
{
QMessageBox::information(this, ui->labelMissingCampaigns->text(), tr("TODO")); // TODO
}
void StartGameTab::on_buttonMissingCampaignsHelp_clicked()
{
QMessageBox::information(this, ui->labelMissingCampaigns->text(), tr("TODO")); // TODO
}

View File

@ -15,13 +15,7 @@ enum class EGameUpdateStatus : int8_t
UPDATE_AVAILABLE
};
enum ETranslationStatus
{
NOT_AVAILABLE, // translation for this language was not found in mod list. Could also happen if player is offline or disabled repository checkout
NOT_INSTALLLED, // translation mod found, but it is not installed
DISABLED, // translation mod found, and installed, but toggled off
ACTIVE // translation mod active OR game is already in specified language (e.g. English H3 for players with English language)
};
enum class ETranslationStatus : int8_t;
class MainWindow;
@ -44,16 +38,23 @@ public:
private slots:
void on_buttonGameStart_clicked();
void on_buttonOpenChangelog_clicked();
void on_buttonOpenDownloads_clicked();
void on_buttonUpdateCheck_clicked();
void on_buttonGameEditor_clicked();
void on_buttonImportFiles_clicked();
void on_buttonInstallTranslation_clicked();
void on_buttonActivateTranslation_clicked();
void on_buttonUpdateMods_clicked();
void on_buttonHelpImportFiles_clicked();
void on_buttonInstallTranslationHelp_clicked();
void on_buttonActivateTranslationHelp_clicked();
void on_buttonUpdateModsHelp_clicked();
void on_buttonChroniclesHelp_clicked();
void on_buttonMissingSoundtrackHelp_clicked();
void on_buttonMissingVideoHelp_clicked();
void on_buttonMissingFilesHelp_clicked();
void on_buttonMissingCampaignsHelp_clicked();
private:
Ui::StartGameTab * ui;

View File

@ -270,8 +270,7 @@
</size>
</property>
<property name="text">
<string>Heroes Chronicles:
0/8 installed</string>
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
@ -758,8 +757,8 @@
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>80</height>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
@ -767,8 +766,8 @@
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="toolButtonStyle">
@ -776,6 +775,22 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonGameStart">
<property name="sizePolicy">
@ -809,6 +824,22 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="buttonGameEditor">
<property name="sizePolicy">
@ -819,8 +850,8 @@
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>80</height>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
@ -828,8 +859,8 @@
</property>
<property name="iconSize">
<size>
<width>64</width>
<height>64</height>
<width>48</width>
<height>48</height>
</size>
</property>
<property name="toolButtonStyle">