From 743cee7470c4dc9e7070aa289a9ffaa809b19ffc Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Sat, 14 Sep 2024 21:34:39 +0200 Subject: [PATCH 1/2] simplify usage of ttf font --- launcher/modManager/cmodlistview_moc.cpp | 6 + launcher/modManager/cmodlistview_moc.h | 3 + launcher/settingsView/csettingsview_moc.cpp | 42 ++++++- launcher/settingsView/csettingsview_moc.h | 6 + launcher/settingsView/csettingsview_moc.ui | 133 ++++++++++++-------- 5 files changed, 130 insertions(+), 60 deletions(-) diff --git a/launcher/modManager/cmodlistview_moc.cpp b/launcher/modManager/cmodlistview_moc.cpp index 63b17b3c3..d8797979a 100644 --- a/launcher/modManager/cmodlistview_moc.cpp +++ b/launcher/modManager/cmodlistview_moc.cpp @@ -1080,6 +1080,12 @@ bool CModListView::isModEnabled(const QString & modName) return mod.isEnabled(); } +bool CModListView::isModInstalled(const QString & modName) +{ + auto mod = modModel->getMod(modName); + return mod.isInstalled(); +} + QString CModListView::getTranslationModName(const QString & language) { for(const auto & modName : modModel->getModList()) diff --git a/launcher/modManager/cmodlistview_moc.h b/launcher/modManager/cmodlistview_moc.h index 7cfe44012..595680bf5 100644 --- a/launcher/modManager/cmodlistview_moc.h +++ b/launcher/modManager/cmodlistview_moc.h @@ -95,6 +95,9 @@ public: /// returns true if mod is currently enabled bool isModEnabled(const QString & modName); + /// returns true if mod is currently installed + bool isModInstalled(const QString & modName); + public slots: void enableModByName(QString modName); void disableModByName(QString modName); diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index 038fb986b..bc9a7776f 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -54,6 +54,14 @@ static constexpr std::array downscalingFilterTypes = "best" }; +MainWindow * CSettingsView::getMainWindow() +{ + foreach(QWidget *w, qApp->allWidgets()) + if(QMainWindow* mainWin = qobject_cast(w)) + return dynamic_cast(mainWin); + return nullptr; +} + void CSettingsView::setDisplayList() { QStringList list; @@ -166,6 +174,17 @@ void CSettingsView::loadSettings() ui->sliderControllerSticksAcceleration->setValue(settings["input"]["controllerAxisScale"].Float() * 100); ui->lineEditGameLobbyHost->setText(QString::fromStdString(settings["lobby"]["hostname"].String())); ui->spinBoxNetworkPortLobby->setValue(settings["lobby"]["port"].Integer()); + + auto mainWindow = getMainWindow(); + if(mainWindow) + { + bool fontModAvailable = mainWindow->getModView()->isModInstalled("vcmi-extras.truetypefonts"); + if(!fontModAvailable) + { + ui->labelTtfFont->hide(); + ui->buttonTtfFont->hide(); + } + } loadToggleButtonSettings(); } @@ -190,6 +209,10 @@ void CSettingsView::loadToggleButtonSettings() std::string cursorType = settings["video"]["cursor"].String(); int cursorTypeIndex = vstd::find_pos(cursorTypesList, cursorType); setCheckbuttonState(ui->buttonCursorType, cursorTypeIndex); + + auto mainWindow = getMainWindow(); + if(mainWindow) + setCheckbuttonState(ui->buttonTtfFont, mainWindow->getModView()->isModEnabled("vcmi-extras.truetypefonts")); } void CSettingsView::fillValidResolutions() @@ -442,8 +465,7 @@ void CSettingsView::on_comboBoxLanguage_currentIndexChanged(int index) QString selectedLanguage = ui->comboBoxLanguage->itemData(index).toString(); node->String() = selectedLanguage.toStdString(); - if(auto * mainWindow = dynamic_cast(qApp->activeWindow())) - mainWindow->updateTranslation(); + getMainWindow()->updateTranslation(); } void CSettingsView::changeEvent(QEvent *event) @@ -475,7 +497,7 @@ void CSettingsView::loadTranslation() { QString baseLanguage = Languages::getHeroesDataLanguage(); - auto * mainWindow = dynamic_cast(qApp->activeWindow()); + auto * mainWindow = getMainWindow(); if (!mainWindow) return; @@ -518,7 +540,7 @@ void CSettingsView::loadTranslation() void CSettingsView::on_pushButtonTranslation_clicked() { - auto * mainWindow = dynamic_cast(qApp->activeWindow()); + auto * mainWindow = getMainWindow(); assert(mainWindow); if (!mainWindow) @@ -582,7 +604,7 @@ void CSettingsView::on_spinBoxInterfaceScaling_valueChanged(int arg1) void CSettingsView::on_refreshRepositoriesButton_clicked() { - auto * mainWindow = dynamic_cast(qApp->activeWindow()); + auto * mainWindow = getMainWindow(); assert(mainWindow); if (!mainWindow) @@ -747,3 +769,13 @@ void CSettingsView::on_sliderControllerSticksSensitivity_valueChanged(int value) Settings node = settings.write["input"]["controllerAxisSpeed"]; node->Integer() = value; } + +void CSettingsView::on_buttonTtfFont_toggled(bool value) +{ + auto mainWindow = getMainWindow(); + if(value) + mainWindow->getModView()->enableModByName("vcmi-extras.truetypefonts"); + else + mainWindow->getModView()->disableModByName("vcmi-extras.truetypefonts"); + updateCheckbuttonText(ui->buttonTtfFont); +} diff --git a/launcher/settingsView/csettingsview_moc.h b/launcher/settingsView/csettingsview_moc.h index f18f0d811..4bcf51ad9 100644 --- a/launcher/settingsView/csettingsview_moc.h +++ b/launcher/settingsView/csettingsview_moc.h @@ -14,10 +14,14 @@ namespace Ui class CSettingsView; } +class MainWindow; + class CSettingsView : public QWidget { Q_OBJECT + MainWindow * getMainWindow(); + public: explicit CSettingsView(QWidget * parent = nullptr); ~CSettingsView(); @@ -84,6 +88,8 @@ private slots: void on_sliderControllerSticksSensitivity_valueChanged(int value); + void on_buttonTtfFont_toggled(bool value); + private: Ui::CSettingsView * ui; diff --git a/launcher/settingsView/csettingsview_moc.ui b/launcher/settingsView/csettingsview_moc.ui index 2c6d46df9..cfb4dc832 100644 --- a/launcher/settingsView/csettingsview_moc.ui +++ b/launcher/settingsView/csettingsview_moc.ui @@ -68,7 +68,7 @@ - + false @@ -88,14 +88,14 @@ - + Sticks Acceleration - + Refresh now @@ -132,14 +132,14 @@ - + Online Lobby address - + VCAI @@ -172,7 +172,7 @@ - + 100 @@ -243,7 +243,7 @@ - + Default repository @@ -270,7 +270,7 @@ - + 100 @@ -296,7 +296,7 @@ - + @@ -311,7 +311,7 @@ - + Use Relative Pointer Mode @@ -325,7 +325,7 @@ - + Autocombat AI in battles @@ -339,35 +339,35 @@ - + Long Touch Duration - + Sticks Sensitivity - + Touch Tap Tolerance - + - + 100 @@ -414,7 +414,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + true @@ -436,7 +436,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + @@ -456,7 +456,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + 0 @@ -484,7 +484,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Online Lobby port @@ -525,7 +525,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + @@ -540,7 +540,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + @@ -559,7 +559,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + 500 @@ -620,7 +620,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + false @@ -640,14 +640,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Check on startup - + 0 @@ -691,7 +691,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + 500 @@ -719,7 +719,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + 1024 @@ -732,14 +732,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Enemy AI in battles - + @@ -761,7 +761,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Ignore SSL errors @@ -778,7 +778,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + @@ -792,14 +792,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Haptic Feedback - + @@ -815,14 +815,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Additional repository - + Mouse Click Tolerance @@ -836,14 +836,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Relative Pointer Speed - + @@ -865,7 +865,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + true @@ -894,14 +894,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Adventure Map Enemies - + BattleAI @@ -918,21 +918,21 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Neutral AI in battles - + Adventure Map Allies - + @@ -947,7 +947,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + true @@ -985,7 +985,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + VCAI @@ -1009,7 +1009,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + @@ -1031,14 +1031,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Controller Click Tolerance - + 100 @@ -1080,14 +1080,14 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Sound Volume - + 0 @@ -1115,7 +1115,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + @@ -1131,21 +1131,21 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - + Music Volume - + Show Tutorial again - + Reset @@ -1188,6 +1188,29 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use + + + + TrueType Font + + + + + + + + 0 + 0 + + + + + + + true + + + From 0c1ef33d5a6635cc6b7c5062b1a310a7810e272b Mon Sep 17 00:00:00 2001 From: Laserlicht <13953785+Laserlicht@users.noreply.github.com> Date: Thu, 19 Sep 2024 20:03:33 +0200 Subject: [PATCH 2/2] text change --- launcher/settingsView/csettingsview_moc.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/settingsView/csettingsview_moc.ui b/launcher/settingsView/csettingsview_moc.ui index cfb4dc832..87e8f8e70 100644 --- a/launcher/settingsView/csettingsview_moc.ui +++ b/launcher/settingsView/csettingsview_moc.ui @@ -1191,7 +1191,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - TrueType Font + Use scalable fonts