From fe0cd289e20045dfba843b820cd0161daea8c04a Mon Sep 17 00:00:00 2001 From: Gregor Klevze Date: Fri, 19 Dec 2025 16:48:26 +0100 Subject: [PATCH] fix --- src/core/application/ApplicationManager.cpp | 23 +++++++++++++++++++- src/main.cpp | 24 +++++++-------------- src/states/MenuState.cpp | 7 +++--- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/core/application/ApplicationManager.cpp b/src/core/application/ApplicationManager.cpp index cd81a1e..528bfd5 100644 --- a/src/core/application/ApplicationManager.cpp +++ b/src/core/application/ApplicationManager.cpp @@ -328,6 +328,26 @@ bool ApplicationManager::initializeManagers() { // Global hotkeys (handled across all states) if (pressed) { + // While the help overlay is visible, swallow input so gameplay/menu doesn't react. + // Allow only help-toggle/close keys to pass through this global handler. + if (m_showHelpOverlay) { + if (sc == SDL_SCANCODE_ESCAPE) { + m_showHelpOverlay = false; + if (m_helpOverlayPausedGame && m_game) { + m_game->setPaused(false); + } + m_helpOverlayPausedGame = false; + } else if (sc == SDL_SCANCODE_F1) { + // Toggle off + m_showHelpOverlay = false; + if (m_helpOverlayPausedGame && m_game) { + m_game->setPaused(false); + } + m_helpOverlayPausedGame = false; + } + consume = true; + } + // Toggle fullscreen on F, F11 or Alt+Enter (or Alt+KP_Enter) if (sc == SDL_SCANCODE_F || sc == SDL_SCANCODE_F11 || ((sc == SDL_SCANCODE_RETURN || sc == SDL_SCANCODE_RETURN2 || sc == SDL_SCANCODE_KP_ENTER) && @@ -362,8 +382,9 @@ bool ApplicationManager::initializeManagers() { consume = true; } - if (!consume && sc == SDL_SCANCODE_F1) { + if (!consume && (sc == SDL_SCANCODE_F1)) { AppState currentState = m_stateManager ? m_stateManager->getState() : AppState::Loading; + // F1 is global (except Loading). if (currentState != AppState::Loading) { m_showHelpOverlay = !m_showHelpOverlay; if (currentState == AppState::Playing && m_game) { diff --git a/src/main.cpp b/src/main.cpp index 3f0c0bc..b273636 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -849,7 +849,9 @@ int main(int, char **) Settings::instance().setSoundEnabled(SoundEffectManager::instance().isEnabled()); } // Help overlay toggle: F1 (keep it disabled on Loading/Menu) - if (e.key.scancode == SDL_SCANCODE_F1 && state != AppState::Loading && state != AppState::Menu) + const bool helpToggleKey = + (e.key.scancode == SDL_SCANCODE_F1 && state != AppState::Loading && state != AppState::Menu); + if (helpToggleKey) { showHelpOverlay = !showHelpOverlay; if (state == AppState::Playing) { @@ -868,24 +870,14 @@ int main(int, char **) helpOverlayPausedGame = false; } } - // If help overlay is visible and the user presses ESC, close help and return to Menu + // If help overlay is visible and the user presses ESC, close help. if (e.key.scancode == SDL_SCANCODE_ESCAPE && showHelpOverlay) { showHelpOverlay = false; + // Unpause only if the overlay paused the game. + if (state == AppState::Playing && helpOverlayPausedGame) { + game.setPaused(false); + } helpOverlayPausedGame = false; - // Unpause game if we paused it for the overlay - if (state == AppState::Playing) { - if (game.isPaused() && !helpOverlayPausedGame) { - // If paused for other reasons, avoid overriding; otherwise ensure unpaused - // (The flag helps detect pause because of help overlay.) - } - } - if (state != AppState::Menu && ctx.requestFadeTransition) { - // Request a transition back to the Menu state - ctx.requestFadeTransition(AppState::Menu); - } else if (state != AppState::Menu && ctx.stateManager) { - state = AppState::Menu; - ctx.stateManager->setState(state); - } } if (e.key.key == SDLK_F11 || (e.key.key == SDLK_RETURN && (e.key.mod & SDL_KMOD_ALT))) { diff --git a/src/states/MenuState.cpp b/src/states/MenuState.cpp index 9b20f9d..895f434 100644 --- a/src/states/MenuState.cpp +++ b/src/states/MenuState.cpp @@ -1314,14 +1314,15 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi } }; - float leftCursor = panelY + 48.0f - static_cast(helpScroll); - float rightCursor = panelY + 48.0f - static_cast(helpScroll); + const float contentTopY = panelY + 30.0f; + float leftCursor = contentTopY - static_cast(helpScroll); + float rightCursor = contentTopY - static_cast(helpScroll); drawSection(leftX, leftCursor, "GENERAL", generalShortcuts, (int)(sizeof(generalShortcuts)/sizeof(generalShortcuts[0]))); drawSection(leftX, leftCursor, "MENUS", menuShortcuts, (int)(sizeof(menuShortcuts)/sizeof(menuShortcuts[0]))); drawSection(rightX, rightCursor, "GAMEPLAY", gameplayShortcuts, (int)(sizeof(gameplayShortcuts)/sizeof(gameplayShortcuts[0]))); // Ensure helpScroll bounds (simple clamp) - float contentHeight = std::max(leftCursor, rightCursor) - (panelY + 48.0f); + float contentHeight = std::max(leftCursor, rightCursor) - contentTopY; float maxScroll = std::max(0.0f, contentHeight - (PH - 120.0f)); if (helpScroll < 0.0) helpScroll = 0.0; if (helpScroll > maxScroll) helpScroll = maxScroll;