DungeonCrawl
Loading...
Searching...
No Matches
menu.h File Reference

Exposes helper functions to work with menus. More...

#include <stdbool.h>

Go to the source code of this file.

Macros

#define NEW_GAME_OPTION   "New Game"
#define CONTINUE_OPTION   "Continue"
#define SAVE_GAME_OPTION   "Save Game"
#define LOAD_GAME_OPTION   "Load Game"
#define CHANGE_LANGUAGE_OPTION   "Change Language"
#define EXIT_OPTION   "Exit"
#define TITLE   "DUNGEON CRAWL"
#define TITLE_COLOR   TB_RED
#define MENU_START_Y   5
#define MENU_START_X   10
#define MENU_ITEM_SPACING   2

Enumerations

enum  menu_result_t {
  MENU_START_GAME , MENU_CONTINUE , MENU_SAVE_GAME , MENU_LOAD_GAME ,
  MENU_CHANGE_LANGUAGE , MENU_EXIT
}

Functions

bool show_confirmation (const char *message)
 Shows a confirmation dialog with the given message.
void draw_menu (const char **menu_options, int menu_count, int selected_index)
 Draws a menu with the given options.

Detailed Description

Exposes helper functions to work with menus.

Definition in file menu.h.

Macro Definition Documentation

◆ CHANGE_LANGUAGE_OPTION

#define CHANGE_LANGUAGE_OPTION   "Change Language"

Definition at line 16 of file menu.h.

◆ CONTINUE_OPTION

#define CONTINUE_OPTION   "Continue"

Definition at line 13 of file menu.h.

◆ EXIT_OPTION

#define EXIT_OPTION   "Exit"

Definition at line 17 of file menu.h.

◆ LOAD_GAME_OPTION

#define LOAD_GAME_OPTION   "Load Game"

Definition at line 15 of file menu.h.

◆ MENU_ITEM_SPACING

#define MENU_ITEM_SPACING   2

Definition at line 24 of file menu.h.

◆ MENU_START_X

#define MENU_START_X   10

Definition at line 23 of file menu.h.

◆ MENU_START_Y

#define MENU_START_Y   5

Definition at line 22 of file menu.h.

◆ NEW_GAME_OPTION

#define NEW_GAME_OPTION   "New Game"

Definition at line 12 of file menu.h.

◆ SAVE_GAME_OPTION

#define SAVE_GAME_OPTION   "Save Game"

Definition at line 14 of file menu.h.

◆ TITLE

#define TITLE   "DUNGEON CRAWL"

Definition at line 20 of file menu.h.

◆ TITLE_COLOR

#define TITLE_COLOR   TB_RED

Definition at line 21 of file menu.h.

Enumeration Type Documentation

◆ menu_result_t

enum menu_result_t

Definition at line 26 of file menu.h.

26 {
27 MENU_START_GAME,
28 MENU_CONTINUE,
29 MENU_SAVE_GAME,
30 MENU_LOAD_GAME,
31 MENU_CHANGE_LANGUAGE,
32 MENU_EXIT
33} menu_result_t;

Function Documentation

◆ draw_menu()

void draw_menu ( const char ** menu_options,
int menu_count,
int selected_index )

Draws a menu with the given options.

Parameters
menu_optionsArray of menu option strings
menu_countNumber of menu options
selected_indexCurrently selected menu index

Definition at line 15 of file menu.c.

15 {
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}
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.

◆ show_confirmation()

bool show_confirmation ( const char * message)

Shows a confirmation dialog with the given message.

Parameters
messageThe message to display
Returns
true if the user confirmed, false otherwise

Definition at line 39 of file menu.c.

39 {
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}
bool get_input_blocking(input_event_t *event)
Get the next input event (blocking)
Structure for advanced input events with context data.
Definition input_types.h:43