Add scene stack menu flow and restore stable TFT sync refresh

This commit is contained in:
Adolfo Reyna
2026-02-18 15:10:20 -05:00
parent a06e0d69fe
commit ebc58d7e4d
4 changed files with 366 additions and 69 deletions

View File

@@ -129,6 +129,7 @@ bool GameLauncher::update(const InputEvent& event) {
if (event.y >= y - 5 && event.y < y + MENU_ITEM_HEIGHT - 5) {
// Game selected - create instance
printf("Selected game: %s\n", games[i].name);
selected_index = i;
selected_game = games[i].factory(width, height, renderer, gui, input_manager);
if (selected_game) {
selected_game->init();
@@ -298,6 +299,30 @@ bool GameLauncher::select_game_by_name(const char* name) {
return false;
}
bool GameLauncher::restart_selected_game() {
if (selected_index < 0 || selected_index >= (int)games.size()) {
return false;
}
if (selected_game) {
delete selected_game;
selected_game = nullptr;
}
selected_game = games[selected_index].factory(width, height, renderer, gui, input_manager);
if (!selected_game) {
return false;
}
selected_game->init();
current_page = selected_index / GAMES_PER_PAGE;
return true;
}
void GameLauncher::return_to_menu() {
reset();
}
int GameLauncher::get_total_pages() const {
if (games.empty()) return 1;
return (games.size() + GAMES_PER_PAGE - 1) / GAMES_PER_PAGE;

View File

@@ -97,6 +97,17 @@ public:
*/
bool select_game_by_name(const char* name);
/**
* @brief Restart the currently selected game.
* @return true if restart succeeded, false otherwise
*/
bool restart_selected_game();
/**
* @brief Exit current game and return to launcher menu.
*/
void return_to_menu();
private:
uint16_t width;
uint16_t height;

45
lib/scene_stack.h Normal file
View File

@@ -0,0 +1,45 @@
#ifndef SCENE_STACK_H
#define SCENE_STACK_H
#include <vector>
enum class SceneId {
LAUNCHER = 0,
GAME,
IN_GAME_MENU
};
class SceneStack {
public:
SceneStack() {
stack.push_back(SceneId::LAUNCHER);
}
SceneId current() const {
return stack.empty() ? SceneId::LAUNCHER : stack.back();
}
bool is(SceneId scene) const {
return current() == scene;
}
void push(SceneId scene) {
stack.push_back(scene);
}
void pop() {
if (stack.size() > 1) {
stack.pop_back();
}
}
void clear_to_launcher() {
stack.clear();
stack.push_back(SceneId::LAUNCHER);
}
private:
std::vector<SceneId> stack;
};
#endif // SCENE_STACK_H