21int selected_save_file_id = -1;
22char last_save_name[50] = {0};
25 save_menu_strings = malloc(
sizeof(
char*) * MAX_SAVE_MENU_STRINGS);
26 RETURN_WHEN_NULL(save_menu_strings, 1,
"Save Menu",
"Failed to allocate memory for save menu strings.");
28 for (
int i = 0; i < MAX_SAVE_MENU_STRINGS; i++) {
29 save_menu_strings[i] = NULL;
41 return selected_save_file_id;
45 if (last_save_name[0] ==
'\0') {
48 return last_save_name;
52 char save_name[50] = {0};
53 menu_result_t result = MENU_CONTINUE;
57 save_menu_strings[SAVE_NAME_REQUEST],
60 save_menu_strings[PRESS_ENTER_CONFIRM],
66 strncpy(last_save_name, save_name,
sizeof(last_save_name) - 1);
67 last_save_name[
sizeof(last_save_name) - 1] =
'\0';
71 save_menu_strings[SAVING],
76 result = MENU_SAVE_GAME;
83 menu_result_t result = MENU_CONTINUE;
85 if (game_in_progress && !
show_confirmation(save_menu_strings[CONFIRM_QUESTION])) {
94 if (save_infos == NULL) {
95 log_msg(ERROR,
"Menu",
"Failed to get save files");
99 if (save_infos->count == 0) {
102 save_menu_strings[SAVES_NOT_FOUND],
103 save_menu_strings[PRESS_ANY_RETURN],
108 return MENU_CONTINUE;
112 const char** save_options = malloc(save_infos->count *
sizeof(
char*));
114 log_msg(ERROR,
"Menu",
"Failed to allocate memory for save options");
116 return MENU_CONTINUE;
120 for (
int i = 0; i < save_infos->count; i++) {
121 save_options[i] = malloc(MAX_STRING_LENGTH + TIMESTAMP_LENGTH + 5);
122 if (!save_options[i]) {
124 for (
int j = 0; j < i; j++) {
125 free((
void*) save_options[j]);
129 log_msg(ERROR,
"Menu",
"Failed to allocate memory for save option");
130 return MENU_CONTINUE;
132 snprintf((
char*) save_options[i], MAX_STRING_LENGTH + TIMESTAMP_LENGTH + 5,
133 "%s (%s)", save_infos->infos[i].name, save_infos->infos[i].timestamp);
137 int selected_save_index = 0;
138 bool selection_active =
true;
140 while (selection_active) {
148 for (
int i = 0; i < save_infos->count; i++) {
149 if (i == selected_save_index) {
151 print_text(MENU_START_Y + 2 + (i * MENU_ITEM_SPACING),
166 save_menu_strings[NAVIGATE_INSTRUCTIONS]);
178 switch (input_event.type) {
180 selected_save_index = (selected_save_index - 1 + save_infos->count) % save_infos->count;
183 selected_save_index = (selected_save_index + 1) % save_infos->count;
187 result = MENU_LOAD_GAME;
188 selected_save_file_id = save_infos->infos[selected_save_index].id;
189 selection_active =
false;
192 selection_active =
false;
200 for (
int i = 0; i < save_infos->count; i++) {
201 free((
void*) save_options[i]);
210 if (save_menu_strings != NULL) {
211 for (
int i = 0; i < MAX_SAVE_MENU_STRINGS; i++) {
212 if (save_menu_strings[i] != NULL) {
213 free(save_menu_strings[i]);
216 free(save_menu_strings);
Defines common macros, types, and global variables for color schemes and utilities.
Exposes functions for working with the database.
save_info_container_t * get_save_infos(const db_connection_t *db_connection)
Get the info of the saves.
void free_save_infos(save_info_container_t *save_infos)
Free the resources associated with a save_info_container.
Declares functions to create, save, load, and manage game state data in the SQLite database.
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.
void print_text(int y, int x, const char *text, uint64_t ncchannel)
Print text at a specific position.
bool get_text_input(const char *prompt, char *buffer, int buffer_size, const char *confirm_msg, int y, int x)
Get a text input from the user.
void print_text_default(int y, int x, const char *text)
Print text at a specific position with default colors.
bool render_frame(void)
Render the current frame.
void clear_screen(void)
Clear the screen.
void show_message_screen(const char *message, const char *continue_message, int y, int x)
Show a message screen.
Exposes functions for outputting to the console.
This struct is used for the database connection in SQLite.