From ca3c6227c4aacf5aa8c10256b2513caf7f4b1374 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Tue, 24 Sep 2024 12:17:25 +0000 Subject: [PATCH] Add selector for font type in Launcher, add autoselection --- client/renderSDL/FontChain.cpp | 27 +- client/renderSDL/FontChain.h | 1 + client/renderSDL/RenderHandler.cpp | 3 +- config/schemas/settings.json | 9 +- launcher/settingsView/csettingsview_moc.cpp | 42 +- launcher/settingsView/csettingsview_moc.h | 8 +- launcher/settingsView/csettingsview_moc.ui | 1620 ++++++++++--------- 7 files changed, 930 insertions(+), 780 deletions(-) diff --git a/client/renderSDL/FontChain.cpp b/client/renderSDL/FontChain.cpp index df139e766..44f71097f 100644 --- a/client/renderSDL/FontChain.cpp +++ b/client/renderSDL/FontChain.cpp @@ -39,17 +39,36 @@ size_t FontChain::getFontAscentScaled() const return maxHeight; } +bool FontChain::bitmapFontsPrioritized() const +{ + const std::string & fontType = settings["video"]["fontsType"].String(); + if (fontType == "original") + return true; + if (fontType == "scalable") + return false; + + // else - autoselection. + + if (getScalingFactor() != 1) + return false; // If xbrz in use ttf/scalable fonts are preferred + + if (!vstd::isAlmostEqual(1.0, settings["video"]["fontScalingFactor"].Float())) + return false; // If player requested non-100% scaling - use scalable fonts + + return true; // else - use original bitmap fonts +} + void FontChain::addTrueTypeFont(const JsonNode & trueTypeConfig) { - chain.push_back(std::make_unique(trueTypeConfig)); + chain.insert(chain.begin(), std::make_unique(trueTypeConfig)); } void FontChain::addBitmapFont(const std::string & bitmapFilename) { - if (settings["video"]["scalableFonts"].Bool()) - chain.push_back(std::make_unique(bitmapFilename)); - else + if (bitmapFontsPrioritized()) chain.insert(chain.begin(), std::make_unique(bitmapFilename)); + else + chain.push_back(std::make_unique(bitmapFilename)); } bool FontChain::canRepresentCharacter(const char * data) const diff --git a/client/renderSDL/FontChain.h b/client/renderSDL/FontChain.h index 9f7ba7b03..b07902cd4 100644 --- a/client/renderSDL/FontChain.h +++ b/client/renderSDL/FontChain.h @@ -29,6 +29,7 @@ class FontChain final : public IFont void renderText(SDL_Surface * surface, const std::string & data, const ColorRGBA & color, const Point & pos) const override; size_t getFontAscentScaled() const override; + bool bitmapFontsPrioritized() const; public: FontChain() = default; diff --git a/client/renderSDL/RenderHandler.cpp b/client/renderSDL/RenderHandler.cpp index afc45773d..be0d5db3b 100644 --- a/client/renderSDL/RenderHandler.cpp +++ b/client/renderSDL/RenderHandler.cpp @@ -356,7 +356,8 @@ std::shared_ptr RenderHandler::loadFont(EFonts font) const JsonNode & ttfConf = config["trueType"]; bitmapPath = bmpConf[index].String(); - loadedFont->addTrueTypeFont(ttfConf[bitmapPath]); + if (!ttfConf[bitmapPath].isNull()) + loadedFont->addTrueTypeFont(ttfConf[bitmapPath]); } loadedFont->addBitmapFont(bitmapPath); diff --git a/config/schemas/settings.json b/config/schemas/settings.json index f7cde9e7e..3cc99dc28 100644 --- a/config/schemas/settings.json +++ b/config/schemas/settings.json @@ -166,7 +166,7 @@ "showfps", "targetfps", "vsync", - "scalableFonts", + "fontsType", "fontScalingFactor", "upscalingFilter", "fontUpscalingFilter", @@ -234,9 +234,10 @@ "type" : "boolean", "default" : true }, - "scalableFonts" : { - "type" : "boolean", - "default" : false + "fontsType" : { + "type" : "string", + "enum" : [ "auto", "original", "scalable" ], + "default" : "auto" }, "fontScalingFactor" : { "type" : "number", diff --git a/launcher/settingsView/csettingsview_moc.cpp b/launcher/settingsView/csettingsview_moc.cpp index 571774663..8cb8c32a0 100644 --- a/launcher/settingsView/csettingsview_moc.cpp +++ b/launcher/settingsView/csettingsview_moc.cpp @@ -174,7 +174,14 @@ 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()); - + + if (settings["video"]["fontsType"].String() == "auto") + ui->buttonFontAuto->setChecked(true); + else if (settings["video"]["fontsType"].String() == "original") + ui->buttonFontOriginal->setChecked(true); + else + ui->buttonFontScalable->setChecked(true); + loadToggleButtonSettings(); } @@ -195,11 +202,13 @@ void CSettingsView::loadToggleButtonSettings() setCheckbuttonState(ui->buttonRelativeCursorMode, settings["general"]["userRelativePointer"].Bool()); setCheckbuttonState(ui->buttonHapticFeedback, settings["general"]["hapticFeedback"].Bool()); - setCheckbuttonState(ui->buttonTtfFont, settings["video"]["scalableFonts"].Bool()); - std::string cursorType = settings["video"]["cursor"].String(); int cursorTypeIndex = vstd::find_pos(cursorTypesList, cursorType); setCheckbuttonState(ui->buttonCursorType, cursorTypeIndex); + + int fontScalingPercentage = settings["video"]["fontScalingFactor"].Float() * 100; + ui->sliderScalingFont->setValue(fontScalingPercentage / 5); + } void CSettingsView::fillValidResolutions() @@ -757,9 +766,28 @@ void CSettingsView::on_sliderControllerSticksSensitivity_valueChanged(int value) node->Integer() = value; } -void CSettingsView::on_buttonTtfFont_toggled(bool value) +void CSettingsView::on_sliderScalingFont_valueChanged(int value) { - Settings node = settings.write["video"]["scalableFonts"]; - node->Bool() = value; - updateCheckbuttonText(ui->buttonTtfFont); + int actualValuePercentage = value * 5; + ui->labelScalingFontValue->setText(QString("%1%").arg(actualValuePercentage)); + Settings node = settings.write["video"]["fontScalingFactor"]; + node->Float() = actualValuePercentage / 100.0; +} + +void CSettingsView::on_buttonFontAuto_clicked(bool checked) +{ + Settings node = settings.write["video"]["fontsType"]; + node->String() = "auto"; +} + +void CSettingsView::on_buttonFontScalable_clicked(bool checked) +{ + Settings node = settings.write["video"]["fontsType"]; + node->String() = "scalable"; +} + +void CSettingsView::on_buttonFontOriginal_clicked(bool checked) +{ + Settings node = settings.write["video"]["fontsType"]; + node->String() = "original"; } diff --git a/launcher/settingsView/csettingsview_moc.h b/launcher/settingsView/csettingsview_moc.h index 4bcf51ad9..1e76f6f2e 100644 --- a/launcher/settingsView/csettingsview_moc.h +++ b/launcher/settingsView/csettingsview_moc.h @@ -88,7 +88,13 @@ private slots: void on_sliderControllerSticksSensitivity_valueChanged(int value); - void on_buttonTtfFont_toggled(bool value); + //void on_buttonTtfFont_toggled(bool value); + + void on_sliderScalingFont_valueChanged(int value); + + void on_buttonFontAuto_clicked(bool checked); + void on_buttonFontScalable_clicked(bool checked); + void on_buttonFontOriginal_clicked(bool checked); private: Ui::CSettingsView * ui; diff --git a/launcher/settingsView/csettingsview_moc.ui b/launcher/settingsView/csettingsview_moc.ui index 87e8f8e70..578fd55b4 100644 --- a/launcher/settingsView/csettingsview_moc.ui +++ b/launcher/settingsView/csettingsview_moc.ui @@ -49,27 +49,12 @@ 0 0 729 - 1396 + 1449 - - - - - - true - - - - General - - - 5 - - - + - + false @@ -88,76 +73,8 @@ - - - - Sticks Acceleration - - - - - - - Refresh now - - - - - - - - - - - - - - % - - - 50 - - - 400 - - - 10 - - - - - - - Reserved screen area - - - - - - - Online Lobby address - - - - - - - VCAI - - - - VCAI - - - - - Nullkiller - - - - - - + + 0 @@ -172,42 +89,10 @@ - - - - 100 - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 10 - - - - - - - - 0 - 0 - - + + - - - - true - - - - - - - VCMI Language + Use Relative Pointer Mode @@ -227,39 +112,105 @@ - - - - - 0 - 0 - - + + - - - - true + Additional repository - - + + - Default repository + Music Volume - - + + + + + - 1024 + 0 - 65535 + 50 + + + 1 + + + 10 - 3030 + 0 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 10 + + + + + + + Long Touch Duration + + + + + + + false + + + BattleAI + + + + BattleAI + + + + + StupidAI + + + + + + + + + true + + + + Video + + + 5 + + + + + + + + true + + + + General + + + 5 @@ -270,119 +221,34 @@ - - - - 100 - - - 300 - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 25 - - - - - - - Renderer - - - - - - - - true - - - - Artificial Intelligence - - - 5 - - - - + - Use Relative Pointer Mode + Show Tutorial again - - + + - Fullscreen + Online Lobby port - - + + - Autocombat AI in battles + Relative Pointer Speed - - - - Display index - - - - - - - Long Touch Duration - - - - - - - Sticks Sensitivity - - - - + Touch Tap Tolerance - - - - - - - - - - - 100 - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 10 - - - @@ -414,168 +280,20 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - - - - true - - - - 0 - 0 - - - - - - - true - - - false - - - - - - - - - - true - - - - - - - Show intro - - - - - - - - - - 0 - - - 50 - - - 1 - - - 10 - - - 0 - - - Qt::Horizontal - - - QSlider::TicksAbove - - - 10 - - - - - - - Online Lobby port - - - - - - - - 0 - 0 - - - - - - - true - - - - - - - - - - - true - - - - Video - - - 5 - - - - - - - - true - - - - Audio - - - 5 - - - - - - - - 0 - 0 - - - - - - - true - - - false - - - - - + + 500 - 2500 + 2000 - 25 + 250 250 - - 500 - Qt::Horizontal @@ -587,67 +305,75 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - - + + - VSync + Neutral AI in battles - - + + + + + true + + - + Input - Mouse + + + 5 - - - - - Nearest - - - - - Linear - - - - - Automatic (Linear) - - + + + + + 0 + 0 + + + + Automatic + + + true + + + true + + + buttonGroup + - - - - false + + + + Adventure Map Enemies + + + + - BattleAI + VCAI - BattleAI + VCAI - StupidAI + Nullkiller - - - - Check on startup - - - - + 0 @@ -675,35 +401,38 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - - - - - 0 - 0 - - + + - - - - true + Autosave - - - - 500 + + + + Renderer + + + + + + Autosave limit (0 = off) + + + + + + + Default repository + + + + + - 2000 - - - 250 - - - 250 + 100 Qt::Horizontal @@ -712,15 +441,44 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use QSlider::TicksAbove - 250 + 10 - - + + + + Sticks Sensitivity + + - - + + + + + true + + + + Audio + + + 5 + + + + + + + + + + Downscaling Filter + + + + + 1024 @@ -732,222 +490,56 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - - - - Enemy AI in battles + + + + 0 + + + 50 + + + 1 + + + 10 + + + 0 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 10 - - - - - true - - - - Input - Touchscreen - - - 5 - - - - - - - Autosave prefix - - - - + Ignore SSL errors - - - - - + + - Autosave limit (0 = off) + Upscaling Filter - - + + - + Refresh now - - - - Autosave - - - - - - - Haptic Feedback - - - - - - - - 0 - 0 - - - - - - - true - - - - - - - Additional repository - - - - - - - Mouse Click Tolerance - - - - - - - Software Cursor - - - - - - - Relative Pointer Speed - - - - - - - - true - - - - Network - - - 5 - - - - - - - Network port - - - - - - - true - - - - 0 - 0 - - - - - - - true - - - false - - - - - - - Downscaling Filter - - - - - - - Adventure Map Enemies - - - - - - - BattleAI - - - - BattleAI - - - - - StupidAI - - - - - - - - Neutral AI in battles - - - - - - - Adventure Map Allies - - - - - - - - true - - - - Input - Mouse - - - 5 - - - - + true @@ -969,23 +561,52 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - - - - - - - 20 - - - 1000 - - - 10 + + + + VSync - + + + + Resolution + + + + + + + VCMI Language + + + + + + + Interface Scaling + + + + + + + + + + + + + + + + + Online Lobby address + + + + VCAI @@ -1002,43 +623,30 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - - - - empty = map name prefix - - - - - - - - true - + + + + + 0 + 0 + - Input - Controller + - - 5 + + true - - + + - Framerate Limit + - - - - Controller Click Tolerance - - - - + 100 @@ -1066,43 +674,64 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - - + + - Interface Scaling + Autosave prefix - - + + - Resolution + Reserved screen area - + Sound Volume - - - - 0 + + + + Font Scaling (experimental) + + + + + + Framerate Limit + + + + + + + + Nearest + + + + + Linear + + + + + Automatic (Linear) + + + + + + - 50 - - - 1 - - - 10 - - - 0 + 100 Qt::Horizontal @@ -1115,50 +744,6 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use - - - - - 0 - 0 - - - - - - - true - - - - - - - Music Volume - - - - - - - Show Tutorial again - - - - - - - Reset - - - - - - - Upscaling Filter - - - @@ -1188,15 +773,115 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use + + + + Autocombat AI in battles + + + - + Use scalable fonts - - + + + + + + + true + + + + + + + + true + + + + Artificial Intelligence + + + 5 + + + + + + + Fullscreen + + + + + + + 500 + + + 2500 + + + 25 + + + 250 + + + 500 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 250 + + + + + + + Enemy AI in battles + + + + + + + Sticks Acceleration + + + + + + + 100 + + + 300 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 25 + + + + + 0 @@ -1211,6 +896,412 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use + + + + empty = map name prefix + + + + + + + true + + + + 0 + 0 + + + + + + + true + + + false + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + Adventure Map Allies + + + + + + + Haptic Feedback + + + + + + + % + + + 50 + + + 400 + + + 10 + + + + + + + + 0 + 0 + + + + + + + true + + + false + + + + + + + Mouse Click Tolerance + + + + + + + BattleAI + + + + BattleAI + + + + + StupidAI + + + + + + + + true + + + + 0 + 0 + + + + + + + true + + + false + + + + + + + Reset + + + + + + + + + + Network port + + + + + + + + + + + true + + + + Input - Controller + + + 5 + + + + + + + Display index + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + + true + + + + Network + + + 5 + + + + + + + + 0 + 0 + + + + Original + + + true + + + true + + + buttonGroup + + + + + + + + + + + + + + Show intro + + + + + + + + 0 + 0 + + + + + + + true + + + + + + + 1024 + + + 65535 + + + 3030 + + + + + + + + true + + + + Input - Touchscreen + + + 5 + + + + + + + 20 + + + 1000 + + + 10 + + + + + + + Controller Click Tolerance + + + + + + + Check on startup + + + + + + + 10 + + + 30 + + + 1 + + + 2 + + + 20 + + + 20 + + + Qt::Horizontal + + + QSlider::TicksAbove + + + 2 + + + + + + + Software Cursor + + + + + + + + 0 + 0 + + + + Scalable + + + true + + + true + + + buttonGroup + + + + + + @@ -1219,4 +1310,7 @@ Fullscreen Exclusive Mode - game will cover entirety of your screen and will use + + +