From 98b77111009b90ad418daadf4b3cf0ebad2add80 Mon Sep 17 00:00:00 2001 From: Gregor Klevze Date: Sun, 30 Nov 2025 09:43:50 +0100 Subject: [PATCH] Added option for turn on/off smooth scroll --- settings.ini | 5 ++++- src/core/Settings.cpp | 7 +++++++ src/core/Settings.h | 4 ++++ src/graphics/renderers/GameRenderer.cpp | 3 ++- src/states/OptionsState.cpp | 23 +++++++++++++++++++++-- src/states/OptionsState.h | 5 ++++- 6 files changed, 42 insertions(+), 5 deletions(-) diff --git a/settings.ini b/settings.ini index 9724bbf..200523e 100644 --- a/settings.ini +++ b/settings.ini @@ -5,9 +5,12 @@ Fullscreen=1 [Audio] -Music=0 +Music=1 Sound=1 +[Gameplay] +SmoothScroll=1 + [Player] Name=GREGOR diff --git a/src/core/Settings.cpp b/src/core/Settings.cpp index 2ff17b3..2a24320 100644 --- a/src/core/Settings.cpp +++ b/src/core/Settings.cpp @@ -66,6 +66,10 @@ bool Settings::load() { } else if (key == "Sound") { m_soundEnabled = (value == "1" || value == "true" || value == "True"); } + } else if (currentSection == "Gameplay") { + if (key == "SmoothScroll") { + m_smoothScrollEnabled = (value == "1" || value == "true" || value == "True"); + } } else if (currentSection == "Player") { if (key == "Name") { m_playerName = value; @@ -100,6 +104,9 @@ bool Settings::save() { file << "Music=" << (m_musicEnabled ? "1" : "0") << "\n"; file << "Sound=" << (m_soundEnabled ? "1" : "0") << "\n\n"; + file << "[Gameplay]\n"; + file << "SmoothScroll=" << (m_smoothScrollEnabled ? "1" : "0") << "\n\n"; + file << "[Player]\n"; file << "Name=" << m_playerName << "\n\n"; diff --git a/src/core/Settings.h b/src/core/Settings.h index ce78740..048bd81 100644 --- a/src/core/Settings.h +++ b/src/core/Settings.h @@ -28,6 +28,9 @@ public: bool isDebugEnabled() const { return m_debugEnabled; } void setDebugEnabled(bool value) { m_debugEnabled = value; } + + bool isSmoothScrollEnabled() const { return m_smoothScrollEnabled; } + void setSmoothScrollEnabled(bool value) { m_smoothScrollEnabled = value; } const std::string& getPlayerName() const { return m_playerName; } void setPlayerName(const std::string& name) { m_playerName = name; } @@ -45,5 +48,6 @@ private: bool m_musicEnabled = true; bool m_soundEnabled = true; bool m_debugEnabled = false; + bool m_smoothScrollEnabled = true; std::string m_playerName = "Player"; }; diff --git a/src/graphics/renderers/GameRenderer.cpp b/src/graphics/renderers/GameRenderer.cpp index 50e67c8..074d586 100644 --- a/src/graphics/renderers/GameRenderer.cpp +++ b/src/graphics/renderers/GameRenderer.cpp @@ -238,6 +238,7 @@ void GameRenderer::renderPlayingState( } bool allowActivePieceRender = true; + const bool smoothScrollEnabled = Settings::instance().isSmoothScrollEnabled(); auto computeFallOffset = [&]() -> float { if (game->isPaused()) { @@ -257,7 +258,7 @@ void GameRenderer::renderPlayingState( return progress * finalBlockSize; }; - float activePieceOffset = (!game->isPaused()) ? computeFallOffset() : 0.0f; + float activePieceOffset = (!game->isPaused() && smoothScrollEnabled) ? computeFallOffset() : 0.0f; if (activePieceOffset > 0.0f) { const auto& boardRef = game->boardRef(); const Game::Piece& piece = game->current(); diff --git a/src/states/OptionsState.cpp b/src/states/OptionsState.cpp index a074894..9fc3e2a 100644 --- a/src/states/OptionsState.cpp +++ b/src/states/OptionsState.cpp @@ -61,6 +61,10 @@ void OptionsState::handleEvent(const SDL_Event& e) { toggleSoundFx(); return; } + if (m_selectedField == Field::SmoothScroll) { + toggleSmoothScroll(); + return; + } break; default: break; @@ -151,7 +155,7 @@ void OptionsState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect l SDL_SetRenderDrawColor(renderer, 40, 80, 140, 240); SDL_RenderRect(renderer, &inner); - constexpr int rowCount = 4; + constexpr int rowCount = 5; const float rowHeight = 60.0f; const float spacing = std::max(0.0f, (inner.h - rowHeight * rowCount) / (rowCount + 1)); @@ -180,7 +184,7 @@ void OptionsState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect l int valueW = 0, valueH = 0; float valueScale = (field == Field::Back) ? 1.3f : 1.5f; retroFont->measure(value, valueScale, valueW, valueH); - bool rightAlign = (field == Field::Fullscreen || field == Field::Music || field == Field::SoundFx); + bool rightAlign = (field == Field::Fullscreen || field == Field::Music || field == Field::SoundFx || field == Field::SmoothScroll); float valX = rightAlign ? (row.x + row.w - static_cast(valueW) - 16.0f) : (row.x + (row.w - static_cast(valueW)) * 0.5f); @@ -197,6 +201,8 @@ void OptionsState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect l rowY += rowHeight + spacing; drawField(Field::SoundFx, rowY, "SOUND FX", isSoundFxEnabled() ? "ON" : "OFF"); rowY += rowHeight + spacing; + drawField(Field::SmoothScroll, rowY, "SMOOTH SCROLL", isSmoothScrollEnabled() ? "ON" : "OFF"); + rowY += rowHeight + spacing; drawField(Field::Back, rowY, "", "RETURN TO MENU"); (void)retroFont; // footer removed for cleaner layout @@ -220,6 +226,9 @@ void OptionsState::activateSelection() { case Field::SoundFx: toggleSoundFx(); break; + case Field::SmoothScroll: + toggleSmoothScroll(); + break; case Field::Back: exitToMenu(); break; @@ -266,6 +275,12 @@ void OptionsState::toggleSoundFx() { Settings::instance().save(); } +void OptionsState::toggleSmoothScroll() { + bool next = !Settings::instance().isSmoothScrollEnabled(); + Settings::instance().setSmoothScrollEnabled(next); + Settings::instance().save(); +} + void OptionsState::exitToMenu() { if (ctx.requestFadeTransition) { ctx.requestFadeTransition(AppState::Menu); @@ -291,3 +306,7 @@ bool OptionsState::isMusicEnabled() const { bool OptionsState::isSoundFxEnabled() const { return SoundEffectManager::instance().isEnabled(); } + +bool OptionsState::isSmoothScrollEnabled() const { + return Settings::instance().isSmoothScrollEnabled(); +} diff --git a/src/states/OptionsState.h b/src/states/OptionsState.h index 58885e3..2ae8638 100644 --- a/src/states/OptionsState.h +++ b/src/states/OptionsState.h @@ -16,7 +16,8 @@ private: Fullscreen = 0, Music = 1, SoundFx = 2, - Back = 3 + SmoothScroll = 3, + Back = 4 }; static constexpr int MAX_NAME_LENGTH = 12; @@ -29,8 +30,10 @@ private: void toggleFullscreen(); void toggleMusic(); void toggleSoundFx(); + void toggleSmoothScroll(); void exitToMenu(); bool isFullscreen() const; bool isMusicEnabled() const; bool isSoundFxEnabled() const; + bool isSmoothScrollEnabled() const; };