Added option for turn on/off smooth scroll

This commit is contained in:
2025-11-30 09:43:50 +01:00
parent 8b350bfb9e
commit 98b7711100
6 changed files with 42 additions and 5 deletions

View File

@ -5,9 +5,12 @@
Fullscreen=1
[Audio]
Music=0
Music=1
Sound=1
[Gameplay]
SmoothScroll=1
[Player]
Name=GREGOR

View File

@ -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";

View File

@ -29,6 +29,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";
};

View File

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

View File

@ -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<float>(valueW) - 16.0f)
: (row.x + (row.w - static_cast<float>(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();
}

View File

@ -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;
};