fix
This commit is contained in:
@ -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) {
|
||||
|
||||
24
src/main.cpp
24
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)))
|
||||
{
|
||||
|
||||
@ -1314,14 +1314,15 @@ void MenuState::render(SDL_Renderer* renderer, float logicalScale, SDL_Rect logi
|
||||
}
|
||||
};
|
||||
|
||||
float leftCursor = panelY + 48.0f - static_cast<float>(helpScroll);
|
||||
float rightCursor = panelY + 48.0f - static_cast<float>(helpScroll);
|
||||
const float contentTopY = panelY + 30.0f;
|
||||
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, "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;
|
||||
|
||||
Reference in New Issue
Block a user