Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: text scale options #466

Merged
merged 5 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions modules/client_options/general.otui
Original file line number Diff line number Diff line change
Expand Up @@ -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: 9

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: 9

Label
id: chooseCrosshairLabel
!text: tr('Crosshair:')
Expand Down
24 changes: 23 additions & 1 deletion modules/client_options/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ local defaultOptions = {
drawEffectOnTop = false,
floorViewMode = 1,
floorFading = 500,
asyncTxtLoading = false
asyncTxtLoading = false,
creatureInformationScale = 0,
textScale = 0
}

local optionsWindow
Expand Down Expand Up @@ -275,6 +277,26 @@ 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(math.max(value + 0.5, 1))
generalPanel:getChildById('creatureInformationScaleLabel'):setText(
tr('Creature Infromation Scale: %sx', math.max(value + 0.5, 1)))
value = value * 2
elseif key == 'textScale' then
if value == 0 then
value = g_window.getDisplayDensity()
else
value = value / 2
end
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)
elseif key == 'floatingEffect' then
Expand Down
24 changes: 13 additions & 11 deletions src/client/animatedtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +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.x -= (4 * g_drawPool.getScaleFactor() * t / tf) + (8 * g_drawPool.getScaleFactor() * t * t / tftf);
}

p.y += 8 + (-48 * t) / tf;
p.y += ((8.f / g_drawPool.getScaleFactor()) + ((-48.f * g_drawPool.getScaleFactor() * t) / tf));
p += m_offset;

const Rect rect{ p, textSize };
if (!visibleRect.contains({ p, textSize }))
return;

if (visibleRect.contains(rect)) {
constexpr float t0 = tf / 1.2;
p.scale(g_drawPool.getScaleFactor());

Color color = m_color;
if (t > t0) {
color.setAlpha(1 - (t - t0) / (tf - t0));
}
const Rect& rect{ p, textSize };
constexpr float t0 = tf / 1.2;

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()
Expand Down
8 changes: 5 additions & 3 deletions src/client/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,12 @@ void Creature::drawInformation(const MapPosInfo& mapRect, const Point& dest, boo
}

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);

if (!g_drawPool.isScaled()) {
backgroundRect.bind(parentRect);
textRect.bind(parentRect);
}

// distance them
uint8_t offset = 12 * g_drawPool.getScaleFactor();
Expand Down
9 changes: 3 additions & 6 deletions src/client/mapview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()) {
Expand All @@ -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);
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/client/statictext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ 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 rect = Rect((dest - (Point(textSize.width() / 2, textSize.height()) + (Point(20, 5) / g_drawPool.getScaleFactor()))), 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);
//}
}

Expand Down
18 changes: 15 additions & 3 deletions src/framework/core/graphicalapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions src/framework/core/graphicalapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 6 additions & 0 deletions src/framework/luafunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/framework/platform/platformwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down