Fade from main menu to gameplay

This commit is contained in:
2025-11-22 20:18:00 +01:00
parent c0bee9296a
commit 3c3a85d6d4
7 changed files with 167 additions and 17 deletions

View File

@ -40,6 +40,14 @@ void MenuState::onExit() {
void MenuState::handleEvent(const SDL_Event& e) {
// Keyboard navigation for menu buttons
if (e.type == SDL_EVENT_KEY_DOWN && !e.key.repeat) {
auto triggerPlay = [&]() {
if (ctx.startPlayTransition) {
ctx.startPlayTransition();
} else if (ctx.stateManager) {
ctx.stateManager->setState(AppState::Playing);
}
};
auto setExitSelection = [&](int value) {
if (ctx.exitPopupSelectedButton) {
*ctx.exitPopupSelectedButton = value;
@ -115,7 +123,7 @@ void MenuState::handleEvent(const SDL_Event& e) {
}
switch (selectedButton) {
case 0:
ctx.stateManager->setState(AppState::Playing);
triggerPlay();
break;
case 1:
ctx.stateManager->setState(AppState::LevelSelector);

View File

@ -55,6 +55,7 @@ struct StateContext {
std::function<void(bool)> applyFullscreen; // Allows states to request fullscreen changes
std::function<bool()> queryFullscreen; // Optional callback if fullscreenFlag is not reliable
std::function<void()> requestQuit; // Allows menu/option states to close the app gracefully
std::function<void()> startPlayTransition; // Optional fade hook when transitioning from menu to gameplay
// Pointer to the application's StateManager so states can request transitions
StateManager* stateManager = nullptr;
};