26menu_result_t active_menu_state;
29 main_menu_strings = (
char**) malloc(
sizeof(
char*) * MAX_MAIN_MENU_STRINGS);
30 RETURN_WHEN_NULL(main_menu_strings, 1,
"Main Menu",
"Failed to allocate memory for main menu strings.");
32 for (
int i = 0; i < MAX_MAIN_MENU_STRINGS; i++) {
33 main_menu_strings[i] = NULL;
44 const char* menu_options[6];
48 menu_options[0] = main_menu_strings[NEW_GAME_STR];
50 if (game_in_progress) {
52 menu_options[1] = main_menu_strings[CONTINUE_STR];
53 menu_options[2] = main_menu_strings[SAVE_GAME_STR];
54 menu_options[3] = main_menu_strings[LOAD_GAME_STR];
55 menu_options[4] = main_menu_strings[CHANGE_LANGUAGE_STR];
56 menu_options[5] = main_menu_strings[EXIT_STR];
60 menu_options[1] = main_menu_strings[LOAD_GAME_STR];
61 menu_options[2] = main_menu_strings[CHANGE_LANGUAGE_STR];
62 menu_options[3] = main_menu_strings[EXIT_STR];
66 int selected_index = 0;
67 active_menu_state = MENU_CONTINUE;
71 draw_menu(menu_options, menu_count, selected_index);
79 switch (input_event.type) {
81 selected_index = (selected_index - 1 + menu_count) % menu_count;
84 selected_index = (selected_index + 1) % menu_count;
92 active_menu_state = MENU_EXIT;
97 active_menu_state = MENU_CONTINUE;
106 return active_menu_state;
117 const int true_index = selected_index > 0 && !game_in_progress ? selected_index + 2 : selected_index;
119 switch (true_index) {
121 if (!game_in_progress ||
show_confirmation(main_menu_strings[QUESTION_CONTINUE])) {
122 active_menu_state = MENU_START_GAME;
127 active_menu_state = MENU_CONTINUE;
132 if (active_menu_state == MENU_SAVE_GAME) {
138 if (active_menu_state == MENU_LOAD_GAME) {
144 if (active_menu_state == MENU_CHANGE_LANGUAGE) {
150 active_menu_state = MENU_EXIT;
155 log_msg(WARNING,
"Main Menu",
"Invalid menu option selected: %d", selected_index);
161 if (main_menu_strings != NULL) {
162 for (
int i = 0; i < MAX_MAIN_MENU_STRINGS; i++) {
163 if (main_menu_strings[i] != NULL) {
164 free(main_menu_strings[i]);
167 free(main_menu_strings);
Defines common macros, types, and global variables for color schemes and utilities.
void observe_local(void(*update_func)(void))
Registers an observer function to be notified of updates from the local handler.
Exposes public functions for the localization handler.
void log_msg(const log_level_t level, const char *module, const char *format,...)
Logs a formatted message with a specified log level and module.
Header file for logging functionality of the game.
menu_result_t show_main_menu(const bool game_in_progress)
Display and handle the main menu.
void select_menu_option(int selected_index, bool game_in_progress)
Process a selected menu option.
int init_main_menu()
Initializes resources for the main menu, including memory allocation and observer registration for lo...
void shutdown_main_menu(void)
Shuts down the main menu and frees associated data.
Exposes functions for the main menu.
void update_main_menu_local(void)
Updates the localized strings for the main menu.
Exposes functionality for the localization of the main menu.
Exposes functions for outputting to the console.