Fade from main menu to gameplay
This commit is contained in:
@ -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);
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user