Added option for turn on/off smooth scroll
This commit is contained in:
@ -5,9 +5,12 @@
|
|||||||
Fullscreen=1
|
Fullscreen=1
|
||||||
|
|
||||||
[Audio]
|
[Audio]
|
||||||
Music=0
|
Music=1
|
||||||
Sound=1
|
Sound=1
|
||||||
|
|
||||||
|
[Gameplay]
|
||||||
|
SmoothScroll=1
|
||||||
|
|
||||||
[Player]
|
[Player]
|
||||||
Name=GREGOR
|
Name=GREGOR
|
||||||
|
|
||||||
|
|||||||
@ -66,6 +66,10 @@ bool Settings::load() {
|
|||||||
} else if (key == "Sound") {
|
} else if (key == "Sound") {
|
||||||
m_soundEnabled = (value == "1" || value == "true" || value == "True");
|
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") {
|
} else if (currentSection == "Player") {
|
||||||
if (key == "Name") {
|
if (key == "Name") {
|
||||||
m_playerName = value;
|
m_playerName = value;
|
||||||
@ -100,6 +104,9 @@ bool Settings::save() {
|
|||||||
file << "Music=" << (m_musicEnabled ? "1" : "0") << "\n";
|
file << "Music=" << (m_musicEnabled ? "1" : "0") << "\n";
|
||||||
file << "Sound=" << (m_soundEnabled ? "1" : "0") << "\n\n";
|
file << "Sound=" << (m_soundEnabled ? "1" : "0") << "\n\n";
|
||||||
|
|
||||||
|
file << "[Gameplay]\n";
|
||||||
|
file << "SmoothScroll=" << (m_smoothScrollEnabled ? "1" : "0") << "\n\n";
|
||||||
|
|
||||||
file << "[Player]\n";
|
file << "[Player]\n";
|
||||||
file << "Name=" << m_playerName << "\n\n";
|
file << "Name=" << m_playerName << "\n\n";
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,9 @@ public:
|
|||||||
bool isDebugEnabled() const { return m_debugEnabled; }
|
bool isDebugEnabled() const { return m_debugEnabled; }
|
||||||
void setDebugEnabled(bool value) { m_debugEnabled = value; }
|
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; }
|
const std::string& getPlayerName() const { return m_playerName; }
|
||||||
void setPlayerName(const std::string& name) { m_playerName = name; }
|
void setPlayerName(const std::string& name) { m_playerName = name; }
|
||||||
|
|
||||||
@ -45,5 +48,6 @@ private:
|
|||||||
bool m_musicEnabled = true;
|
bool m_musicEnabled = true;
|
||||||
bool m_soundEnabled = true;
|
bool m_soundEnabled = true;
|
||||||
bool m_debugEnabled = false;
|
bool m_debugEnabled = false;
|
||||||
|
bool m_smoothScrollEnabled = true;
|
||||||
std::string m_playerName = "Player";
|
std::string m_playerName = "Player";
|
||||||
};
|
};
|
||||||
|
|||||||
@ -238,6 +238,7 @@ void GameRenderer::renderPlayingState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool allowActivePieceRender = true;
|
bool allowActivePieceRender = true;
|
||||||
|
const bool smoothScrollEnabled = Settings::instance().isSmoothScrollEnabled();
|
||||||
|
|
||||||
auto computeFallOffset = [&]() -> float {
|
auto computeFallOffset = [&]() -> float {
|
||||||
if (game->isPaused()) {
|
if (game->isPaused()) {
|
||||||
@ -257,7 +258,7 @@ void GameRenderer::renderPlayingState(
|
|||||||
return progress * finalBlockSize;
|
return progress * finalBlockSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
float activePieceOffset = (!game->isPaused()) ? computeFallOffset() : 0.0f;
|
float activePieceOffset = (!game->isPaused() && smoothScrollEnabled) ? computeFallOffset() : 0.0f;
|
||||||
if (activePieceOffset > 0.0f) {
|
if (activePieceOffset > 0.0f) {
|
||||||
const auto& boardRef = game->boardRef();
|
const auto& boardRef = game->boardRef();
|
||||||
const Game::Piece& piece = game->current();
|
const Game::Piece& piece = game->current();
|
||||||
|
|||||||
@ -61,6 +61,10 @@ void OptionsState::handleEvent(const SDL_Event& e) {
|
|||||||
toggleSoundFx();
|
toggleSoundFx();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (m_selectedField == Field::SmoothScroll) {
|
||||||
|
toggleSmoothScroll();
|
||||||
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -151,7 +155,7 @@ void OptionsState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect l
|
|||||||
SDL_SetRenderDrawColor(renderer, 40, 80, 140, 240);
|
SDL_SetRenderDrawColor(renderer, 40, 80, 140, 240);
|
||||||
SDL_RenderRect(renderer, &inner);
|
SDL_RenderRect(renderer, &inner);
|
||||||
|
|
||||||
constexpr int rowCount = 4;
|
constexpr int rowCount = 5;
|
||||||
const float rowHeight = 60.0f;
|
const float rowHeight = 60.0f;
|
||||||
const float spacing = std::max(0.0f, (inner.h - rowHeight * rowCount) / (rowCount + 1));
|
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;
|
int valueW = 0, valueH = 0;
|
||||||
float valueScale = (field == Field::Back) ? 1.3f : 1.5f;
|
float valueScale = (field == Field::Back) ? 1.3f : 1.5f;
|
||||||
retroFont->measure(value, valueScale, valueW, valueH);
|
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
|
float valX = rightAlign
|
||||||
? (row.x + row.w - static_cast<float>(valueW) - 16.0f)
|
? (row.x + row.w - static_cast<float>(valueW) - 16.0f)
|
||||||
: (row.x + (row.w - static_cast<float>(valueW)) * 0.5f);
|
: (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;
|
rowY += rowHeight + spacing;
|
||||||
drawField(Field::SoundFx, rowY, "SOUND FX", isSoundFxEnabled() ? "ON" : "OFF");
|
drawField(Field::SoundFx, rowY, "SOUND FX", isSoundFxEnabled() ? "ON" : "OFF");
|
||||||
rowY += rowHeight + spacing;
|
rowY += rowHeight + spacing;
|
||||||
|
drawField(Field::SmoothScroll, rowY, "SMOOTH SCROLL", isSmoothScrollEnabled() ? "ON" : "OFF");
|
||||||
|
rowY += rowHeight + spacing;
|
||||||
drawField(Field::Back, rowY, "", "RETURN TO MENU");
|
drawField(Field::Back, rowY, "", "RETURN TO MENU");
|
||||||
|
|
||||||
(void)retroFont; // footer removed for cleaner layout
|
(void)retroFont; // footer removed for cleaner layout
|
||||||
@ -220,6 +226,9 @@ void OptionsState::activateSelection() {
|
|||||||
case Field::SoundFx:
|
case Field::SoundFx:
|
||||||
toggleSoundFx();
|
toggleSoundFx();
|
||||||
break;
|
break;
|
||||||
|
case Field::SmoothScroll:
|
||||||
|
toggleSmoothScroll();
|
||||||
|
break;
|
||||||
case Field::Back:
|
case Field::Back:
|
||||||
exitToMenu();
|
exitToMenu();
|
||||||
break;
|
break;
|
||||||
@ -266,6 +275,12 @@ void OptionsState::toggleSoundFx() {
|
|||||||
Settings::instance().save();
|
Settings::instance().save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionsState::toggleSmoothScroll() {
|
||||||
|
bool next = !Settings::instance().isSmoothScrollEnabled();
|
||||||
|
Settings::instance().setSmoothScrollEnabled(next);
|
||||||
|
Settings::instance().save();
|
||||||
|
}
|
||||||
|
|
||||||
void OptionsState::exitToMenu() {
|
void OptionsState::exitToMenu() {
|
||||||
if (ctx.requestFadeTransition) {
|
if (ctx.requestFadeTransition) {
|
||||||
ctx.requestFadeTransition(AppState::Menu);
|
ctx.requestFadeTransition(AppState::Menu);
|
||||||
@ -291,3 +306,7 @@ bool OptionsState::isMusicEnabled() const {
|
|||||||
bool OptionsState::isSoundFxEnabled() const {
|
bool OptionsState::isSoundFxEnabled() const {
|
||||||
return SoundEffectManager::instance().isEnabled();
|
return SoundEffectManager::instance().isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OptionsState::isSmoothScrollEnabled() const {
|
||||||
|
return Settings::instance().isSmoothScrollEnabled();
|
||||||
|
}
|
||||||
|
|||||||
@ -16,7 +16,8 @@ private:
|
|||||||
Fullscreen = 0,
|
Fullscreen = 0,
|
||||||
Music = 1,
|
Music = 1,
|
||||||
SoundFx = 2,
|
SoundFx = 2,
|
||||||
Back = 3
|
SmoothScroll = 3,
|
||||||
|
Back = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr int MAX_NAME_LENGTH = 12;
|
static constexpr int MAX_NAME_LENGTH = 12;
|
||||||
@ -29,8 +30,10 @@ private:
|
|||||||
void toggleFullscreen();
|
void toggleFullscreen();
|
||||||
void toggleMusic();
|
void toggleMusic();
|
||||||
void toggleSoundFx();
|
void toggleSoundFx();
|
||||||
|
void toggleSmoothScroll();
|
||||||
void exitToMenu();
|
void exitToMenu();
|
||||||
bool isFullscreen() const;
|
bool isFullscreen() const;
|
||||||
bool isMusicEnabled() const;
|
bool isMusicEnabled() const;
|
||||||
bool isSoundFxEnabled() const;
|
bool isSoundFxEnabled() const;
|
||||||
|
bool isSmoothScrollEnabled() const;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user