Initial game launcher
This commit is contained in:
102
lib/game_launcher.h
Normal file
102
lib/game_launcher.h
Normal file
@@ -0,0 +1,102 @@
|
||||
// ============================================================================
|
||||
// GAME LAUNCHER HEADER
|
||||
// ============================================================================
|
||||
// Menu system for selecting and launching games
|
||||
|
||||
#ifndef GAME_LAUNCHER_H
|
||||
#define GAME_LAUNCHER_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include "input_event.h"
|
||||
#include "game.h"
|
||||
|
||||
// Forward declarations
|
||||
class LowLevelRenderer;
|
||||
class LowLevelGUI;
|
||||
|
||||
/**
|
||||
* @brief Game entry in launcher menu
|
||||
*/
|
||||
struct GameEntry {
|
||||
const char* name; // Display name
|
||||
const char* description; // Short description
|
||||
Game* (*factory)(uint16_t width, uint16_t height,
|
||||
LowLevelRenderer* renderer, LowLevelGUI* gui); // Factory function
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Game Launcher - Menu system for game selection
|
||||
*
|
||||
* Displays a list of available games and allows selection via:
|
||||
* - Touch: Tap on game name
|
||||
* - Buttons: KEY0 to navigate, KEY1 to select
|
||||
*
|
||||
* Returns the selected game instance for the main loop to run.
|
||||
*/
|
||||
class GameLauncher {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct GameLauncher
|
||||
* @param width Display width in pixels
|
||||
* @param height Display height in pixels
|
||||
* @param renderer Pointer to low-level rendering interface
|
||||
* @param gui Pointer to GUI drawing primitives
|
||||
*/
|
||||
GameLauncher(uint16_t width, uint16_t height, LowLevelRenderer* renderer, LowLevelGUI* gui);
|
||||
|
||||
/**
|
||||
* @brief Register a game in the launcher
|
||||
* @param name Game display name
|
||||
* @param description Short description
|
||||
* @param factory Function pointer to create game instance
|
||||
*/
|
||||
void register_game(const char* name, const char* description,
|
||||
Game* (*factory)(uint16_t, uint16_t, LowLevelRenderer*, LowLevelGUI*));
|
||||
|
||||
/**
|
||||
* @brief Draw the launcher menu
|
||||
*/
|
||||
void draw();
|
||||
|
||||
/**
|
||||
* @brief Process input event in launcher
|
||||
* @param event Input event from InputManager
|
||||
* @return true if a game was selected (check get_selected_game())
|
||||
*/
|
||||
bool update(const InputEvent& event);
|
||||
|
||||
/**
|
||||
* @brief Get the currently selected game instance
|
||||
* @return Pointer to selected game, or nullptr if none selected
|
||||
*/
|
||||
Game* get_selected_game();
|
||||
|
||||
/**
|
||||
* @brief Reset launcher to show menu again
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/**
|
||||
* @brief Check if a game is currently selected
|
||||
* @return true if game selected, false if in menu
|
||||
*/
|
||||
bool is_game_selected() const { return selected_game != nullptr; }
|
||||
|
||||
private:
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
LowLevelRenderer* renderer;
|
||||
LowLevelGUI* gui;
|
||||
|
||||
std::vector<GameEntry> games;
|
||||
int selected_index; // Currently highlighted game
|
||||
Game* selected_game; // Currently running game (nullptr = in menu)
|
||||
|
||||
// Menu layout constants
|
||||
static const int MENU_Y_START = 60;
|
||||
static const int MENU_ITEM_HEIGHT = 40;
|
||||
static const int MENU_PADDING = 10;
|
||||
};
|
||||
|
||||
#endif // GAME_LAUNCHER_H
|
||||
Reference in New Issue
Block a user