From 3ab2db7d8d4ba88867e96c04b5619caabe9e8bdd Mon Sep 17 00:00:00 2001 From: Renato Date: Fri, 10 Mar 2023 13:56:50 -0300 Subject: [PATCH 1/5] update --- modules/client_options/general.otui | 38 +++++++++++++++++++++ modules/client_options/options.lua | 23 ++++++++++++- src/client/creature.cpp | 12 +++---- src/framework/core/graphicalapplication.cpp | 18 ++++++++-- src/framework/core/graphicalapplication.h | 6 ++++ src/framework/luafunctions.cpp | 6 ++++ src/framework/platform/platformwindow.h | 2 +- 7 files changed, 94 insertions(+), 11 deletions(-) diff --git a/modules/client_options/general.otui b/modules/client_options/general.otui index 0da070a106..db5df29725 100644 --- a/modules/client_options/general.otui +++ b/modules/client_options/general.otui @@ -36,6 +36,44 @@ Panel id: enableHighlightMouseTarget !text: tr('Highlight mouse target') + Label + id: creatureInformationScaleLabel + anchors.left: parent.left + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 12 + @onSetup: | + local value = modules.client_options.getOption('creatureInformationScale') + self:setText(tr('Creature Infromation Scale: %sx', value)) + + OptionScrollbar + id: creatureInformationScale + anchors.left: parent.left + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 3 + minimum: 1 + maximum: 10 + + Label + id: textScaleLabel + anchors.left: parent.left + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 12 + @onSetup: | + local value = modules.client_options.getOption('textScale') + self:setText(tr('Text Scale: %sx', value)) + + OptionScrollbar + id: textScale + anchors.left: parent.left + anchors.right: parent.right + anchors.top: prev.bottom + margin-top: 3 + minimum: 1 + maximum: 10 + Label id: chooseCrosshairLabel !text: tr('Crosshair:') diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index 62f7195265..ed32a90f78 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -42,7 +42,9 @@ local defaultOptions = { drawEffectOnTop = false, floorViewMode = 1, floorFading = 500, - asyncTxtLoading = false + asyncTxtLoading = false, + creatureInformationScale = 0, + textScale = 0 } local optionsWindow @@ -275,6 +277,25 @@ function setOption(key, value, force) elseif key == 'floorFading' then graphicsPanel:getChildById('floorFadingLabel'):setText(tr('Floor Fading: %s ms', value)) gameMapPanel:setFloorFading(tonumber(value)) + + elseif key == 'creatureInformationScale' then + if value == 0 then + value = g_window.getDisplayDensity() + else + value = value / 2 + end + g_app.setCreatureInformationScale(value) + generalPanel:getChildById('creatureInformationScaleLabel'):setText(tr('Creature Infromation Scale: %sx', value)) + value = value * 2 + elseif key == 'textScale' then + if value == 0 then + value = g_window.getDisplayDensity() + else + value = value / 2 + end + g_app.setTextScale(value) + generalPanel:getChildById('textScaleLabel'):setText(tr('Text Scale: %sx', value)) + value = value * 2 elseif key == 'limitVisibleDimension' then gameMapPanel:setLimitVisibleDimension(value) elseif key == 'floatingEffect' then diff --git a/src/client/creature.cpp b/src/client/creature.cpp index 2aac942f1e..aced32e81a 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -232,17 +232,17 @@ void Creature::drawInformation(const MapPosInfo& mapRect, const Point& dest, boo g_drawPool.select(DrawPoolType::CREATURE_INFORMATION); { + auto backgroundRect = Rect(p.x - (13.5), p.y - cropSizeBackGround, 27, 4); + auto textRect = Rect(p.x - nameSize.width() / 2.0, p.y - cropSizeText, nameSize); + if (g_drawPool.isScaled()) { g_drawPool.scale(g_drawPool.getScaleFactor()); p.scale(g_drawPool.getScaleFactor()); + } else { + backgroundRect.bind(parentRect); + textRect.bind(parentRect); } - auto backgroundRect = Rect(p.x - (13.5), p.y - cropSizeBackGround, 27, 4); - backgroundRect.bind(parentRect); - - auto textRect = Rect(p.x - nameSize.width() / 2.0, p.y - cropSizeText, nameSize); - textRect.bind(parentRect); - // distance them uint8_t offset = 12 * g_drawPool.getScaleFactor(); if (isLocalPlayer()) { diff --git a/src/framework/core/graphicalapplication.cpp b/src/framework/core/graphicalapplication.cpp index 73b3e2f1a7..a519080e10 100644 --- a/src/framework/core/graphicalapplication.cpp +++ b/src/framework/core/graphicalapplication.cpp @@ -256,9 +256,6 @@ void GraphicalApplication::resize(const Size& size) g_ui.resize(size / scale); m_onInputEvent = false; - g_drawPool.get(DrawPoolType::TEXT)->setScaleFactor(scale); - g_drawPool.get(DrawPoolType::CREATURE_INFORMATION)->setScaleFactor(scale); - g_mainDispatcher.addEvent([size, scale] { g_drawPool.get(DrawPoolType::FOREGROUND)->setFramebuffer(size / scale); @@ -290,3 +287,18 @@ void GraphicalApplication::setLoadingAsyncTexture(bool v) { m_loadingAsyncTexture = v; g_sprites.reload(); } + +float GraphicalApplication::getCreatureInformationScale() { + return g_drawPool.get(DrawPoolType::CREATURE_INFORMATION)->getScaleFactor(); +} + +float GraphicalApplication::getTextScale() { + return g_drawPool.get(DrawPoolType::TEXT)->getScaleFactor(); +} + +void GraphicalApplication::setCreatureInformationScale(float v) { + g_drawPool.get(DrawPoolType::CREATURE_INFORMATION)->setScaleFactor(v); +} +void GraphicalApplication::setTextScale(float v) { + g_drawPool.get(DrawPoolType::TEXT)->setScaleFactor(v); +} diff --git a/src/framework/core/graphicalapplication.h b/src/framework/core/graphicalapplication.h index b616d552e1..7ec2249dd8 100644 --- a/src/framework/core/graphicalapplication.h +++ b/src/framework/core/graphicalapplication.h @@ -69,6 +69,12 @@ class GraphicalApplication : public Application void setDrawTexts(bool v) { m_drawText = v; } bool isDrawingTexts() { return m_drawText; } + float getCreatureInformationScale(); + void setCreatureInformationScale(float v); + + float getTextScale(); + void setTextScale(float v); + bool isLoadingAsyncTexture(); void setLoadingAsyncTexture(bool v); diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index b1bece1977..7c12319352 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -277,6 +277,11 @@ void Application::registerLuaFunctions() g_lua.bindSingletonFunction("g_app", "isEncrypted", &GraphicalApplication::isEncrypted, &g_app); g_lua.bindSingletonFunction("g_app", "isScaled", &GraphicalApplication::isScaled, &g_app); + g_lua.bindSingletonFunction("g_app", "getCreatureInformationScale", &GraphicalApplication::getCreatureInformationScale, &g_app); + g_lua.bindSingletonFunction("g_app", "getTextScale", &GraphicalApplication::getTextScale, &g_app); + g_lua.bindSingletonFunction("g_app", "setCreatureInformationScale", &GraphicalApplication::setCreatureInformationScale, &g_app); + g_lua.bindSingletonFunction("g_app", "setTextScale", &GraphicalApplication::setTextScale, &g_app); + // PlatformWindow g_lua.registerSingletonClass("g_window"); g_lua.bindSingletonFunction("g_window", "move", &PlatformWindow::move, &g_window); @@ -316,6 +321,7 @@ void Application::registerLuaFunctions() g_lua.bindSingletonFunction("g_window", "isFullscreen", &PlatformWindow::isFullscreen, &g_window); g_lua.bindSingletonFunction("g_window", "isMaximized", &PlatformWindow::isMaximized, &g_window); g_lua.bindSingletonFunction("g_window", "hasFocus", &PlatformWindow::hasFocus, &g_window); + g_lua.bindSingletonFunction("g_window", "getDisplayDensity", &PlatformWindow::getDisplayDensity, &g_window); // Input g_lua.registerSingletonClass("g_mouse"); diff --git a/src/framework/platform/platformwindow.h b/src/framework/platform/platformwindow.h index 0aa292ed6c..fba26906a7 100644 --- a/src/framework/platform/platformwindow.h +++ b/src/framework/platform/platformwindow.h @@ -72,7 +72,7 @@ class PlatformWindow int getDisplayWidth() { return getDisplaySize().width(); } int getDisplayHeight() { return getDisplaySize().height(); } - float getDisplayDensity() const { return m_displayDensity; } + float getDisplayDensity() { return m_displayDensity; } Size getUnmaximizedSize() { return m_unmaximizedSize; } Size getSize() { return m_size; } From 69e4e50c028ba5e4e03367a6ae45b250808a8906 Mon Sep 17 00:00:00 2001 From: Renato Date: Fri, 10 Mar 2023 13:58:45 -0300 Subject: [PATCH 2/5] Update creature.cpp --- src/client/creature.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client/creature.cpp b/src/client/creature.cpp index aced32e81a..7200a511ac 100644 --- a/src/client/creature.cpp +++ b/src/client/creature.cpp @@ -232,13 +232,15 @@ void Creature::drawInformation(const MapPosInfo& mapRect, const Point& dest, boo g_drawPool.select(DrawPoolType::CREATURE_INFORMATION); { - auto backgroundRect = Rect(p.x - (13.5), p.y - cropSizeBackGround, 27, 4); - auto textRect = Rect(p.x - nameSize.width() / 2.0, p.y - cropSizeText, nameSize); - if (g_drawPool.isScaled()) { g_drawPool.scale(g_drawPool.getScaleFactor()); p.scale(g_drawPool.getScaleFactor()); - } else { + } + + auto backgroundRect = Rect(p.x - (13.5), p.y - cropSizeBackGround, 27, 4); + auto textRect = Rect(p.x - nameSize.width() / 2.0, p.y - cropSizeText, nameSize); + + if (!g_drawPool.isScaled()) { backgroundRect.bind(parentRect); textRect.bind(parentRect); } From 8f69b3cf335fc308ffc0d232ef744237fd62b0d3 Mon Sep 17 00:00:00 2001 From: Renato Date: Fri, 10 Mar 2023 14:51:49 -0300 Subject: [PATCH 3/5] update --- modules/client_options/options.lua | 7 ++++--- src/client/animatedtext.cpp | 2 ++ src/client/mapview.cpp | 9 +++------ src/client/statictext.cpp | 11 +++++++---- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index ed32a90f78..a0d8b33225 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -285,7 +285,8 @@ function setOption(key, value, force) value = value / 2 end g_app.setCreatureInformationScale(value) - generalPanel:getChildById('creatureInformationScaleLabel'):setText(tr('Creature Infromation Scale: %sx', value)) + generalPanel:getChildById('creatureInformationScaleLabel'):setText( + tr('Creature Infromation Scale: %sx', math.max(value, 1))) value = value * 2 elseif key == 'textScale' then if value == 0 then @@ -293,8 +294,8 @@ function setOption(key, value, force) else value = value / 2 end - g_app.setTextScale(value) - generalPanel:getChildById('textScaleLabel'):setText(tr('Text Scale: %sx', value)) + g_app.setTextScale(math.max(value, 1)) + generalPanel:getChildById('textScaleLabel'):setText(tr('Text Scale: %sx', math.max(value, 1))) value = value * 2 elseif key == 'limitVisibleDimension' then gameMapPanel:setLimitVisibleDimension(value) diff --git a/src/client/animatedtext.cpp b/src/client/animatedtext.cpp index 791f5ff98c..11027013cb 100644 --- a/src/client/animatedtext.cpp +++ b/src/client/animatedtext.cpp @@ -49,6 +49,8 @@ void AnimatedText::drawText(const Point& dest, const Rect& visibleRect) p.y += 8 + (-48 * t) / tf; p += m_offset; + //p.scale(g_drawPool.getScaleFactor()); + const Rect rect{ p, textSize }; if (visibleRect.contains(rect)) { diff --git a/src/client/mapview.cpp b/src/client/mapview.cpp index dd1dc5d5bc..0b70f8358d 100644 --- a/src/client/mapview.cpp +++ b/src/client/mapview.cpp @@ -209,9 +209,7 @@ void MapView::drawFloor() void MapView::drawText() { g_drawPool.use(DrawPoolType::TEXT); - - const float scale = g_drawPool.getScaleFactor(); - g_drawPool.scale(scale); + g_drawPool.scale(g_drawPool.getScaleFactor()); for (const auto& staticText : g_map.getStaticTexts()) { if (staticText->getMessageMode() == Otc::MessageNone) @@ -225,7 +223,7 @@ void MapView::drawText() p.x *= m_posInfo.horizontalStretchFactor; p.y *= m_posInfo.verticalStretchFactor; p += m_posInfo.rect.topLeft(); - staticText->drawText(p.scale(scale), m_posInfo.rect); + staticText->drawText(p.scale(g_drawPool.getScaleFactor()), m_posInfo.rect); } for (const auto& animatedText : g_map.getAnimatedTexts()) { @@ -238,8 +236,7 @@ void MapView::drawText() p.x *= m_posInfo.horizontalStretchFactor; p.y *= m_posInfo.verticalStretchFactor; p += m_posInfo.rect.topLeft(); - - animatedText->drawText(p.scale(scale), m_posInfo.rect); + animatedText->drawText(p, m_posInfo.rect); } } diff --git a/src/client/statictext.cpp b/src/client/statictext.cpp index 243e34e7e4..0f414be6e8 100644 --- a/src/client/statictext.cpp +++ b/src/client/statictext.cpp @@ -36,13 +36,16 @@ StaticText::StaticText() void StaticText::drawText(const Point& dest, const Rect& parentRect) { const auto& textSize = m_cachedText.getTextSize(); - const auto& rect = Rect(dest - Point(textSize.width() / 2, textSize.height()) + Point(20, 5), textSize); - Rect boundRect = rect; - boundRect.bind(parentRect); + + auto dd = (dest - (Point(textSize.width() / 2, textSize.height()) + (Point(20, 5) / g_drawPool.getScaleFactor()))); + + auto rect = Rect(dd, textSize); + if (!g_drawPool.isScaled()) + rect.bind(parentRect); // draw only if the real center is not too far from the parent center, or its a yell //if(g_map.isAwareOfPosition(m_position) || isYell()) { - m_cachedText.draw(boundRect, m_color); + m_cachedText.draw(rect, m_color); //} } From 8dd3958f86093164dc9eea7fd7dc5931aefe3790 Mon Sep 17 00:00:00 2001 From: Renato Date: Fri, 10 Mar 2023 15:37:04 -0300 Subject: [PATCH 4/5] update --- modules/client_options/general.otui | 4 ++-- modules/client_options/options.lua | 8 ++++---- src/client/animatedtext.cpp | 24 ++++++++++++------------ src/client/statictext.cpp | 4 +--- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/modules/client_options/general.otui b/modules/client_options/general.otui index db5df29725..54478abfdf 100644 --- a/modules/client_options/general.otui +++ b/modules/client_options/general.otui @@ -53,7 +53,7 @@ Panel anchors.top: prev.bottom margin-top: 3 minimum: 1 - maximum: 10 + maximum: 9 Label id: textScaleLabel @@ -72,7 +72,7 @@ Panel anchors.top: prev.bottom margin-top: 3 minimum: 1 - maximum: 10 + maximum: 9 Label id: chooseCrosshairLabel diff --git a/modules/client_options/options.lua b/modules/client_options/options.lua index a0d8b33225..1281762de1 100644 --- a/modules/client_options/options.lua +++ b/modules/client_options/options.lua @@ -284,9 +284,9 @@ function setOption(key, value, force) else value = value / 2 end - g_app.setCreatureInformationScale(value) + g_app.setCreatureInformationScale(math.max(value + 0.5, 1)) generalPanel:getChildById('creatureInformationScaleLabel'):setText( - tr('Creature Infromation Scale: %sx', math.max(value, 1))) + tr('Creature Infromation Scale: %sx', math.max(value + 0.5, 1))) value = value * 2 elseif key == 'textScale' then if value == 0 then @@ -294,8 +294,8 @@ function setOption(key, value, force) else value = value / 2 end - g_app.setTextScale(math.max(value, 1)) - generalPanel:getChildById('textScaleLabel'):setText(tr('Text Scale: %sx', math.max(value, 1))) + g_app.setTextScale(math.max(value + 0.5, 1)) + generalPanel:getChildById('textScaleLabel'):setText(tr('Text Scale: %sx', math.max(value + 0.5, 1))) value = value * 2 elseif key == 'limitVisibleDimension' then gameMapPanel:setLimitVisibleDimension(value) diff --git a/src/client/animatedtext.cpp b/src/client/animatedtext.cpp index 11027013cb..9d4292e93a 100644 --- a/src/client/animatedtext.cpp +++ b/src/client/animatedtext.cpp @@ -41,28 +41,28 @@ void AnimatedText::drawText(const Point& dest, const Rect& visibleRect) const float t = m_animationTimer.ticksElapsed(); Point p = dest; - p.x += (24 - textSize.width() / 2); + p.x += (24.f / g_drawPool.getScaleFactor() - (textSize.width() / 2.f)); if (g_game.getFeature(Otc::GameDiagonalAnimatedText)) { p.x -= (4 * t / tf) + (8 * t * t / tftf); } - p.y += 8 + (-48 * t) / tf; + p.y += ((8.f / g_drawPool.getScaleFactor()) + ((-48.f * t) / tf)); p += m_offset; - //p.scale(g_drawPool.getScaleFactor()); + if (!visibleRect.contains({ p, textSize })) + return; - const Rect rect{ p, textSize }; + p.scale(g_drawPool.getScaleFactor()); - if (visibleRect.contains(rect)) { - constexpr float t0 = tf / 1.2; + const Rect& rect{ p, textSize }; + constexpr float t0 = tf / 1.2; - Color color = m_color; - if (t > t0) { - color.setAlpha(1 - (t - t0) / (tf - t0)); - } - - m_cachedText.draw(rect, color); + Color color = m_color; + if (t > t0) { + color.setAlpha(1 - (t - t0) / (tf - t0)); } + + m_cachedText.draw(rect, color); } void AnimatedText::onAppear() diff --git a/src/client/statictext.cpp b/src/client/statictext.cpp index 0f414be6e8..21ee1b59a1 100644 --- a/src/client/statictext.cpp +++ b/src/client/statictext.cpp @@ -37,9 +37,7 @@ void StaticText::drawText(const Point& dest, const Rect& parentRect) { const auto& textSize = m_cachedText.getTextSize(); - auto dd = (dest - (Point(textSize.width() / 2, textSize.height()) + (Point(20, 5) / g_drawPool.getScaleFactor()))); - - auto rect = Rect(dd, textSize); + auto rect = Rect((dest - (Point(textSize.width() / 2, textSize.height()) + (Point(20, 5) / g_drawPool.getScaleFactor()))), textSize); if (!g_drawPool.isScaled()) rect.bind(parentRect); From 8f0ef372f864b11117620e47a2e2c36644cf253e Mon Sep 17 00:00:00 2001 From: Renato Date: Fri, 10 Mar 2023 15:44:59 -0300 Subject: [PATCH 5/5] Update animatedtext.cpp --- src/client/animatedtext.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/animatedtext.cpp b/src/client/animatedtext.cpp index 9d4292e93a..d56b9168ad 100644 --- a/src/client/animatedtext.cpp +++ b/src/client/animatedtext.cpp @@ -43,10 +43,10 @@ void AnimatedText::drawText(const Point& dest, const Rect& visibleRect) Point p = dest; p.x += (24.f / g_drawPool.getScaleFactor() - (textSize.width() / 2.f)); if (g_game.getFeature(Otc::GameDiagonalAnimatedText)) { - p.x -= (4 * t / tf) + (8 * t * t / tftf); + p.x -= (4 * g_drawPool.getScaleFactor() * t / tf) + (8 * g_drawPool.getScaleFactor() * t * t / tftf); } - p.y += ((8.f / g_drawPool.getScaleFactor()) + ((-48.f * t) / tf)); + p.y += ((8.f / g_drawPool.getScaleFactor()) + ((-48.f * g_drawPool.getScaleFactor() * t) / tf)); p += m_offset; if (!visibleRect.contains({ p, textSize }))