1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-23 22:37:55 +02:00

code review

This commit is contained in:
Laserlicht
2025-07-17 20:42:27 +02:00
parent 3504d1ce38
commit 187d79bc7c
7 changed files with 43 additions and 35 deletions

View File

@@ -97,6 +97,9 @@
"vcmi.randomMap.description.monster.normal" : "normal",
"vcmi.randomMap.description.monster.strong" : "strong",
"vcmi.overlay.battery" : "Battery",
"vcmi.overlay.charging" : "Charging",
"vcmi.spellBook.search" : "search...",
"vcmi.spellBook.tab.hover" : "%s Spells",
"vcmi.spellBook.tab.help" : "Turn to view %s spells",
@@ -313,8 +316,8 @@
"vcmi.systemOptions.longTouchMenu.hover" : "Select Long Touch Interval",
"vcmi.systemOptions.longTouchMenu.help" : "Change duration of long touch interval.",
"vcmi.systemOptions.longTouchMenu.entry" : "%d milliseconds",
"vcmi.systemOptions.infoboxButton.hover" : "Show Infobox (with FPS)",
"vcmi.systemOptions.infoboxButton.help" : "{Show Infobox}\n\nToggle the visibility of the infobox with additional information like frames per second, time and battery charge level (if available) in the corner of the game window.",
"vcmi.systemOptions.performanceOverlayButton.hover" : "Show Performance Overlay",
"vcmi.systemOptions.performanceOverlayButton.help" : "{Show Performance Overlay}\n\nToggle the visibility of the overlay with additional information like frames per second, time and battery charge level (if available) in the corner of the game window.",
"vcmi.systemOptions.hapticFeedbackButton.hover" : "Haptic feedback",
"vcmi.systemOptions.hapticFeedbackButton.help" : "{Haptic feedback}\n\nToggle the haptic feedback on touch inputs.",
"vcmi.systemOptions.enableUiEnhancementsButton.hover" : "Interface Enhancements",

View File

@@ -97,6 +97,9 @@
"vcmi.randomMap.description.monster.normal" : "Normal",
"vcmi.randomMap.description.monster.strong" : "Stark",
"vcmi.overlay.battery" : "Batterie",
"vcmi.overlay.charging" : "Lädt",
"vcmi.spellBook.search" : "suchen...",
"vcmi.spellBook.tab.hover" : "%szauber",
"vcmi.spellBook.tab.help" : "Zu %szaubersprüchen blättern",
@@ -313,8 +316,8 @@
"vcmi.systemOptions.longTouchMenu.hover" : "Wähle Dauer für Touch",
"vcmi.systemOptions.longTouchMenu.help" : "Ändere die Dauer für den langen Touch",
"vcmi.systemOptions.longTouchMenu.entry" : "%d Millisekunden",
"vcmi.systemOptions.infoboxButton.hover" : "Infobox anzeigen (mit FPS)",
"vcmi.systemOptions.infoboxButton.help" : "{Infobox anzeigen}\n\n Schaltet die Sichtbarkeit einer Infobox für zusätzliche Informationen, wie eines Zählers für die Bilder pro Sekunde, der Uhrzeit oder des Batterieladezustands (wenn verfügbar) in der Ecke des Spielfensters um.",
"vcmi.systemOptions.performanceOverlayButton.hover" : "Leistungs-Overlay anzeigen",
"vcmi.systemOptions.performanceOverlayButton.help" : "{Leistungs-Overlay anzeigen}\n\n Schaltet die Sichtbarkeit eines Overlays für zusätzliche Informationen, wie eines Zählers für die Bilder pro Sekunde, der Uhrzeit oder des Batterieladezustands (wenn verfügbar) in der Ecke des Spielfensters um.",
"vcmi.systemOptions.hapticFeedbackButton.hover" : "Haptisches Feedback",
"vcmi.systemOptions.hapticFeedbackButton.help" : "{Haptisches Feedback}\n\nHaptisches Feedback bei Touch-Eingaben.",
"vcmi.systemOptions.enableUiEnhancementsButton.hover" : "Interface Verbesserungen",

View File

@@ -9,6 +9,7 @@
*/
#include "StdInc.h"
#include "GameEngine.h"
#include "GameLibrary.h"
#include "gui/CIntObject.h"
#include "gui/CursorHandler.h"
@@ -36,6 +37,7 @@
#include "../lib/AsyncRunner.h"
#include "../lib/CConfigHandler.h"
#include "../lib/texts/TextOperations.h"
#include "../lib/texts/CGeneralTextHandler.h"
#include <SDL_render.h>
@@ -126,8 +128,8 @@ void GameEngine::updateFrame()
handleEvents();
windows().simpleRedraw();
if (settings["video"]["infobox"]["show"].Bool())
drawInfoBox();
if (settings["video"]["performanceOverlay"]["show"].Bool())
drawPerformanceOverlay();
screenHandlerInstance->updateScreenTexture();
@@ -185,7 +187,7 @@ Point GameEngine::screenDimensions() const
return screenHandlerInstance->getLogicalResolution();
}
void GameEngine::drawInfoBox()
void GameEngine::drawPerformanceOverlay()
{
auto font = EFonts::FONT_SMALL;
const auto & fontPtr = ENGINE->renderHandler().loadFont(font);
@@ -194,10 +196,10 @@ void GameEngine::drawInfoBox()
auto powerState = ENGINE->input().getPowerState();
std::string powerSymbol = ""; // add symbol if emoji are supported (e.g. VCMI extras)
if(fontPtr->canRepresentCharacter("🔋") && powerState.powerState == PowerStateMode::ON_BATTERY)
powerSymbol = "🔋 ";
else if(fontPtr->canRepresentCharacter("🔌") && powerState.powerState == PowerStateMode::CHARGING)
powerSymbol = "🔌 ";
if(powerState.powerState == PowerStateMode::ON_BATTERY)
powerSymbol = fontPtr->canRepresentCharacter("🔋") ? "🔋 " : (LIBRARY->generaltexth->translate("vcmi.overlay.battery") + " ");
else if(powerState.powerState == PowerStateMode::CHARGING)
powerSymbol = fontPtr->canRepresentCharacter("🔌") ? "🔌 " : (LIBRARY->generaltexth->translate("vcmi.overlay.charging") + " ");
std::string fps = std::to_string(framerate().getFramerate())+" FPS";
std::string time = TextOperations::getFormattedTimeLocal(std::time(nullptr));
@@ -205,23 +207,23 @@ void GameEngine::drawInfoBox()
std::string textToDisplay = time + (power.empty() ? "" : " | " + power) + " | " + fps;
maxInfoBoxTextWidth = std::max(maxInfoBoxTextWidth, static_cast<int>(fontPtr->getStringWidth(textToDisplay))); // do not get smaller (can cause graphical glitches)
maxPerformanceOverlayTextWidth = std::max(maxPerformanceOverlayTextWidth, static_cast<int>(fontPtr->getStringWidth(textToDisplay))); // do not get smaller (can cause graphical glitches)
Rect targetArea;
std::string edge = settings["video"]["infobox"]["edge"].String();
int pos1 = settings["video"]["infobox"]["pos1"].Integer();
int pos2 = settings["video"]["infobox"]["pos2"].Integer();
std::string edge = settings["video"]["performanceOverlay"]["edge"].String();
int marginTopBottom = settings["video"]["performanceOverlay"]["marginTopBottom"].Integer();
int marginLeftRight = settings["video"]["performanceOverlay"]["marginLeftRight"].Integer();
Point boxSize(maxInfoBoxTextWidth + 4, fontPtr->getLineHeight() + 2);
Point boxSize(maxPerformanceOverlayTextWidth + 6, fontPtr->getLineHeight() + 2);
if (edge == "topleft")
targetArea = Rect(pos2, pos1, boxSize.x, boxSize.y);
targetArea = Rect(marginLeftRight, marginTopBottom, boxSize.x, boxSize.y);
else if (edge == "topright")
targetArea = Rect(screenDimensions().x - pos2 - boxSize.x, pos1, boxSize.x, boxSize.y);
targetArea = Rect(screenDimensions().x - marginLeftRight - boxSize.x, marginTopBottom, boxSize.x, boxSize.y);
else if (edge == "bottomleft")
targetArea = Rect(pos2, screenDimensions().y - pos1 - boxSize.y, boxSize.x, boxSize.y);
targetArea = Rect(marginLeftRight, screenDimensions().y - marginTopBottom - boxSize.y, boxSize.x, boxSize.y);
else if (edge == "bottomright")
targetArea = Rect(screenDimensions().x - pos2 - boxSize.x, screenDimensions().y - pos1 - boxSize.y, boxSize.x, boxSize.y);
targetArea = Rect(screenDimensions().x - marginLeftRight - boxSize.x, screenDimensions().y - marginTopBottom - boxSize.y, boxSize.x, boxSize.y);
target.drawColor(targetArea.resize(1), Colors::BRIGHT_YELLOW);
target.drawColor(targetArea, ColorRGBA(0, 0, 0));

View File

@@ -57,11 +57,11 @@ private:
IGameEngineUser *engineUser = nullptr;
int maxInfoBoxTextWidth = 0;
int maxPerformanceOverlayTextWidth = 0;
void updateFrame();
void handleEvents(); //takes events from queue and calls interested objects
void drawInfoBox(); // draws box with additional infos (e.g. fps)
void drawPerformanceOverlay(); // draws box with additional infos (e.g. fps)
public:
std::mutex interfaceMutex;

View File

@@ -152,9 +152,9 @@ GeneralOptionsTab::GeneralOptionsTab()
{
selectLongTouchDuration();
});
addCallback("infoboxChanged", [](bool value)
addCallback("performanceOverlayChanged", [](bool value)
{
Settings gameRes = settings.write["video"]["infobox"];
Settings gameRes = settings.write["video"]["performanceOverlay"];
gameRes["show"].Bool() = value;
});
addCallback("hapticFeedbackChanged", [](bool value)
@@ -226,8 +226,8 @@ GeneralOptionsTab::GeneralOptionsTab()
if (fullscreenExclusiveCheckbox)
fullscreenExclusiveCheckbox->setSelected(settings["video"]["fullscreen"].Bool() && settings["video"]["realFullscreen"].Bool());
std::shared_ptr<CToggleButton> infoboxCheckbox = widget<CToggleButton>("infoboxCheckbox");
infoboxCheckbox->setSelected(settings["video"]["infobox"]["show"].Bool());
std::shared_ptr<CToggleButton> infoboxCheckbox = widget<CToggleButton>("performanceOverlayCheckbox");
infoboxCheckbox->setSelected(settings["video"]["performanceOverlay"]["show"].Bool());
std::shared_ptr<CToggleButton> hapticFeedbackCheckbox = widget<CToggleButton>("hapticFeedbackCheckbox");
if (hapticFeedbackCheckbox)

View File

@@ -210,7 +210,7 @@
"spellbookAnimation",
"driver",
"displayIndex",
"infobox",
"performanceOverlay",
"targetfps",
"vsync",
"fontsType",
@@ -270,15 +270,15 @@
"type" : "number",
"default" : 0
},
"infobox" : {
"performanceOverlay" : {
"type" : "object",
"additionalProperties" : false,
"required" : [ "show", "edge", "pos1", "pos2" ],
"required" : [ "show", "edge", "marginTopBottom", "marginLeftRight" ],
"properties" : {
"show" : { "type" : "boolean", "default" : false },
"edge" : { "type" : "string", "enum" : [ "topleft", "topright", "bottomleft", "bottomright" ], "default" : "bottomleft" },
"pos1" : { "type" : "number", "default" : 5 },
"pos2" : { "type" : "number", "default" : 7 }
"marginTopBottom" : { "type" : "number", "default" : 5 },
"marginLeftRight" : { "type" : "number", "default" : 7 }
}
},
"targetfps" : {

View File

@@ -50,7 +50,7 @@
"created" : "desktop"
},
{
"text": "vcmi.systemOptions.infoboxButton.hover"
"text": "vcmi.systemOptions.performanceOverlayButton.hover"
},
{
"text": "vcmi.systemOptions.enableLargeSpellbookButton.hover"
@@ -136,9 +136,9 @@
"created" : "desktop"
},
{
"name": "infoboxCheckbox",
"help": "vcmi.systemOptions.infoboxButton",
"callback": "infoboxChanged"
"name": "performanceOverlayCheckbox",
"help": "vcmi.systemOptions.performanceOverlayButton",
"callback": "performanceOverlayChanged"
},
{
"name": "enableLargeSpellbookCheckbox",