mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
handle enabling/disabling Extra Resolutions mod
This commit is contained in:
parent
76b36b8951
commit
d06977ecbb
@ -82,7 +82,11 @@ MainWindow::MainWindow(QWidget * parent)
|
||||
ui->tabSelectList->setMaximumWidth(width + 4);
|
||||
}
|
||||
ui->tabListWidget->setCurrentIndex(0);
|
||||
|
||||
ui->settingsView->isExtraResolutionsModEnabled = ui->stackedWidgetPage2->isExtraResolutionsModEnabled();
|
||||
ui->settingsView->setDisplayList();
|
||||
connect(ui->stackedWidgetPage2, &CModListView::extraResolutionsEnabledChanged,
|
||||
ui->settingsView, &CSettingsView::fillValidResolutions);
|
||||
|
||||
connect(ui->tabSelectList, SIGNAL(currentRowChanged(int)),
|
||||
ui->tabListWidget, SLOT(setCurrentIndex(int)));
|
||||
|
@ -28,6 +28,9 @@ void CModListView::setupModModel()
|
||||
{
|
||||
modModel = new CModListModel(this);
|
||||
manager = vstd::make_unique<CModManager>(modModel);
|
||||
|
||||
connect(manager.get(), &CModManager::extraResolutionsEnabledChanged,
|
||||
this, &CModListView::extraResolutionsEnabledChanged);
|
||||
}
|
||||
|
||||
void CModListView::setupFilterModel()
|
||||
@ -320,6 +323,11 @@ void CModListView::selectMod(const QModelIndex & index)
|
||||
}
|
||||
}
|
||||
|
||||
bool CModListView::isExtraResolutionsModEnabled() const
|
||||
{
|
||||
return manager->isExtraResolutionsModEnabled();
|
||||
}
|
||||
|
||||
void CModListView::keyPressEvent(QKeyEvent * event)
|
||||
{
|
||||
if(event->key() == Qt::Key_Escape && ui->modInfoWidget->isVisible())
|
||||
|
@ -63,6 +63,9 @@ class CModListView : public QWidget
|
||||
QString genChangelogText(CModEntry & mod);
|
||||
QString genModInfoText(CModEntry & mod);
|
||||
|
||||
signals:
|
||||
void extraResolutionsEnabledChanged(bool enabled);
|
||||
|
||||
public:
|
||||
explicit CModListView(QWidget * parent = 0);
|
||||
~CModListView();
|
||||
@ -75,6 +78,7 @@ public:
|
||||
void disableModInfo();
|
||||
|
||||
void selectMod(const QModelIndex & index);
|
||||
bool isExtraResolutionsModEnabled() const;
|
||||
|
||||
private slots:
|
||||
void dataChanged(const QModelIndex & topleft, const QModelIndex & bottomRight);
|
||||
|
@ -18,7 +18,11 @@
|
||||
#include "../jsonutils.h"
|
||||
#include "../launcherdirs.h"
|
||||
|
||||
static QString detectModArchive(QString path, QString modName)
|
||||
namespace
|
||||
{
|
||||
const QLatin1String extraResolutionsMod{"vcmi-extras.extraresolutions"};
|
||||
|
||||
QString detectModArchive(QString path, QString modName)
|
||||
{
|
||||
auto files = ZipArchive::listFiles(qstringToPath(path));
|
||||
|
||||
@ -40,6 +44,8 @@ static QString detectModArchive(QString path, QString modName)
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CModManager::CModManager(CModList * modList)
|
||||
: modList(modList)
|
||||
@ -219,6 +225,11 @@ bool CModManager::canDisableMod(QString modname)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CModManager::isExtraResolutionsModEnabled() const
|
||||
{
|
||||
return modList->hasMod(extraResolutionsMod) && modList->getMod(extraResolutionsMod).isEnabled();
|
||||
}
|
||||
|
||||
static QVariant writeValue(QString path, QVariantMap input, QVariant value)
|
||||
{
|
||||
if(path.size() > 1)
|
||||
@ -246,6 +257,9 @@ bool CModManager::doEnableMod(QString mod, bool on)
|
||||
modList->setModSettings(modSettings["activeMods"]);
|
||||
modList->modChanged(mod);
|
||||
|
||||
if(mod == extraResolutionsMod)
|
||||
sendExtraResolutionsEnabledChanged(on);
|
||||
|
||||
JsonUtils::JsonToFile(settingsPath(), modSettings);
|
||||
|
||||
return true;
|
||||
@ -261,7 +275,7 @@ bool CModManager::doInstallMod(QString modname, QString archivePath)
|
||||
if(localMods.contains(modname))
|
||||
return addError(modname, "Mod with such name is already installed");
|
||||
|
||||
QString modDirName = detectModArchive(archivePath, modname);
|
||||
QString modDirName = ::detectModArchive(archivePath, modname);
|
||||
if(!modDirName.size())
|
||||
return addError(modname, "Mod archive is invalid or corrupted");
|
||||
|
||||
@ -326,3 +340,8 @@ bool CModManager::removeModDir(QString path)
|
||||
|
||||
return dir.removeRecursively();
|
||||
}
|
||||
|
||||
void CModManager::sendExtraResolutionsEnabledChanged(bool enabled)
|
||||
{
|
||||
emit extraResolutionsEnabledChanged(enabled);
|
||||
}
|
||||
|
@ -11,8 +11,10 @@
|
||||
|
||||
#include "cmodlist.h"
|
||||
|
||||
class CModManager
|
||||
class CModManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
CModList * modList;
|
||||
|
||||
QString settingsPath();
|
||||
@ -29,6 +31,11 @@ class CModManager
|
||||
bool addError(QString modname, QString message);
|
||||
bool removeModDir(QString mod);
|
||||
|
||||
void sendExtraResolutionsEnabledChanged(bool enabled);
|
||||
|
||||
signals:
|
||||
void extraResolutionsEnabledChanged(bool enabled);
|
||||
|
||||
public:
|
||||
CModManager(CModList * modList);
|
||||
|
||||
@ -51,4 +58,6 @@ public:
|
||||
bool canUninstallMod(QString mod);
|
||||
bool canEnableMod(QString mod);
|
||||
bool canDisableMod(QString mod);
|
||||
|
||||
bool isExtraResolutionsModEnabled() const;
|
||||
};
|
||||
|
@ -106,15 +106,25 @@ void CSettingsView::loadSettings()
|
||||
ui->comboBoxAutoSave->setCurrentIndex(settings["general"]["saveFrequency"].Integer() > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
void CSettingsView::fillValidResolutions(bool isExtraResolutionsModEnabled)
|
||||
{
|
||||
this->isExtraResolutionsModEnabled = isExtraResolutionsModEnabled;
|
||||
fillValidResolutionsForScreen(ui->comboBoxDisplayIndex->isVisible() ? ui->comboBoxDisplayIndex->currentIndex() : 0);
|
||||
}
|
||||
|
||||
void CSettingsView::fillValidResolutionsForScreen(int screenIndex)
|
||||
{
|
||||
ui->comboBoxResolution->blockSignals(true); // avoid saving wrong resolution after adding first item from the list
|
||||
ui->comboBoxResolution->clear();
|
||||
|
||||
// TODO: read available resolutions from all mods
|
||||
const QLatin1String extrasResolutionsPath{"/vcmi-extras/Mods/extraResolutions/Content/config/resolutions.json"};
|
||||
const auto extrasResolutionsJson = JsonUtils::JsonFromFile(CLauncherDirs::get().modsPath() + extrasResolutionsPath);
|
||||
const auto resolutions = extrasResolutionsJson.toMap().value(QLatin1String{"GUISettings"}).toList();
|
||||
QVariantList resolutions;
|
||||
if(isExtraResolutionsModEnabled)
|
||||
{
|
||||
const QLatin1String extrasResolutionsPath{"/vcmi-extras/Mods/extraResolutions/Content/config/resolutions.json"};
|
||||
const auto extrasResolutionsJson = JsonUtils::JsonFromFile(CLauncherDirs::get().modsPath() + extrasResolutionsPath);
|
||||
resolutions = extrasResolutionsJson.toMap().value(QLatin1String{"GUISettings"}).toList();
|
||||
}
|
||||
if(resolutions.isEmpty())
|
||||
{
|
||||
ui->comboBoxResolution->blockSignals(false);
|
||||
|
@ -26,6 +26,11 @@ public:
|
||||
void loadSettings();
|
||||
void setDisplayList();
|
||||
|
||||
bool isExtraResolutionsModEnabled{};
|
||||
|
||||
public slots:
|
||||
void fillValidResolutions(bool isExtraResolutionsModEnabled);
|
||||
|
||||
private slots:
|
||||
void on_checkBoxFullScreen_stateChanged(int state);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user