DungeonCrawl
Loading...
Searching...
No Matches
menu.c
Go to the documentation of this file.
1
5#include "menu.h"
6
7#include "../common.h"
10#include "../logging/logger.h"
12
13#include <string.h>
14
15void draw_menu(const char** menu_options, int menu_count, int selected_index) {
16 // Clear the screen
18
19 // Draw title
20 print_text(MENU_START_Y, MENU_START_X, TITLE, RED_TEXT_COLORS);
21
22 // Draw menu options
23 int y = MENU_START_Y + 3;
24 for (int i = 0; i < menu_count; i++) {
25 if (i == selected_index) {
26 // Highlight selected option
27 print_text(y, MENU_START_X, menu_options[i], INVERTED_COLORS);
28 } else {
29 // Normal option
30 print_text_default(y, MENU_START_X, menu_options[i]);
31 }
32 y += MENU_ITEM_SPACING;
33 }
34
35 // Render the frame
37}
38
39bool show_confirmation(const char* message) {
40 // Clear the screen
42
43 // Print confirmation messages
44 print_text_default(MENU_START_Y, MENU_START_X, save_menu_strings[WARNING_LOST_PROGRESS]);
45 print_text_default(MENU_START_Y + 2, MENU_START_X, message);
46 print_text_default(MENU_START_Y + 4, MENU_START_X, "(Y/N)");
47
48 // Render the frame
50
51 // Wait for Y/N input
52 while (1) {
53 input_event_t input_event;
54 if (get_input_blocking(&input_event)) {
55 if (input_event.raw_input.id == 'y' || input_event.raw_input.id == 'Y') {
56 return true;
57 } else if (input_event.raw_input.id == 'n' || input_event.raw_input.id == 'N') {
58 return false;
59 }
60 }
61 }
62}
Defines common macros, types, and global variables for color schemes and utilities.
bool get_input_blocking(input_event_t *event)
Get the next input event (blocking)
Exposes functions for working with input.
Header file for logging functionality of the game.
bool show_confirmation(const char *message)
Shows a confirmation dialog with the given message.
Definition menu.c:39
void draw_menu(const char **menu_options, int menu_count, int selected_index)
Draws a menu with the given options.
Definition menu.c:15
Exposes helper functions to work with menus.
void print_text(int y, int x, const char *text, uint64_t ncchannel)
Print text at a specific position.
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.
Exposes functions for outputting to the console.
Declares functions and data for localized save menu UI.
Structure for advanced input events with context data.
Definition input_types.h:43