This commit is contained in:
2025-12-19 16:48:26 +01:00
parent 989b98002c
commit fe0cd289e2
3 changed files with 34 additions and 20 deletions

View File

@ -328,6 +328,26 @@ bool ApplicationManager::initializeManagers() {
// Global hotkeys (handled across all states) // Global hotkeys (handled across all states)
if (pressed) { 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) // Toggle fullscreen on F, F11 or Alt+Enter (or Alt+KP_Enter)
if (sc == SDL_SCANCODE_F || sc == SDL_SCANCODE_F11 || if (sc == SDL_SCANCODE_F || sc == SDL_SCANCODE_F11 ||
((sc == SDL_SCANCODE_RETURN || sc == SDL_SCANCODE_RETURN2 || sc == SDL_SCANCODE_KP_ENTER) && ((sc == SDL_SCANCODE_RETURN || sc == SDL_SCANCODE_RETURN2 || sc == SDL_SCANCODE_KP_ENTER) &&
@ -362,8 +382,9 @@ bool ApplicationManager::initializeManagers() {
consume = true; consume = true;
} }
if (!consume && sc == SDL_SCANCODE_F1) { if (!consume && (sc == SDL_SCANCODE_F1)) {
AppState currentState = m_stateManager ? m_stateManager->getState() : AppState::Loading; AppState currentState = m_stateManager ? m_stateManager->getState() : AppState::Loading;
// F1 is global (except Loading).
if (currentState != AppState::Loading) { if (currentState != AppState::Loading) {
m_showHelpOverlay = !m_showHelpOverlay; m_showHelpOverlay = !m_showHelpOverlay;
if (currentState == AppState::Playing && m_game) { if (currentState == AppState::Playing && m_game) {

View File

@ -849,7 +849,9 @@ int main(int, char **)
Settings::instance().setSoundEnabled(SoundEffectManager::instance().isEnabled()); Settings::instance().setSoundEnabled(SoundEffectManager::instance().isEnabled());
} }
// Help overlay toggle: F1 (keep it disabled on Loading/Menu) // 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; showHelpOverlay = !showHelpOverlay;
if (state == AppState::Playing) { if (state == AppState::Playing) {
@ -868,24 +870,14 @@ int main(int, char **)
helpOverlayPausedGame = false; 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) { if (e.key.scancode == SDL_SCANCODE_ESCAPE && showHelpOverlay) {
showHelpOverlay = false; showHelpOverlay = false;
// Unpause only if the overlay paused the game.
if (state == AppState::Playing && helpOverlayPausedGame) {
game.setPaused(false);
}
helpOverlayPausedGame = 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))) if (e.key.key == SDLK_F11 || (e.key.key == SDLK_RETURN && (e.key.mod & SDL_KMOD_ALT)))
{ {

View File

@ -1314,14 +1314,15 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi
} }
}; };
float leftCursor = panelY + 48.0f - static_cast<float>(helpScroll); const float contentTopY = panelY + 30.0f;
float rightCursor = panelY + 48.0f - static_cast<float>(helpScroll); float leftCursor = contentTopY - static_cast<float>(helpScroll);
float rightCursor = contentTopY - static_cast<float>(helpScroll);
drawSection(leftX, leftCursor, "GENERAL", generalShortcuts, (int)(sizeof(generalShortcuts)/sizeof(generalShortcuts[0]))); drawSection(leftX, leftCursor, "GENERAL", generalShortcuts, (int)(sizeof(generalShortcuts)/sizeof(generalShortcuts[0])));
drawSection(leftX, leftCursor, "MENUS", menuShortcuts, (int)(sizeof(menuShortcuts)/sizeof(menuShortcuts[0]))); drawSection(leftX, leftCursor, "MENUS", menuShortcuts, (int)(sizeof(menuShortcuts)/sizeof(menuShortcuts[0])));
drawSection(rightX, rightCursor, "GAMEPLAY", gameplayShortcuts, (int)(sizeof(gameplayShortcuts)/sizeof(gameplayShortcuts[0]))); drawSection(rightX, rightCursor, "GAMEPLAY", gameplayShortcuts, (int)(sizeof(gameplayShortcuts)/sizeof(gameplayShortcuts[0])));
// Ensure helpScroll bounds (simple clamp) // 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)); float maxScroll = std::max(0.0f, contentHeight - (PH - 120.0f));
if (helpScroll < 0.0) helpScroll = 0.0; if (helpScroll < 0.0) helpScroll = 0.0;
if (helpScroll > maxScroll) helpScroll = maxScroll; if (helpScroll > maxScroll) helpScroll = maxScroll;