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

Exposes functions for outputing to the screen while in the inventory mode. More...

#include "../../../character/character_fw.h"
#include "../../../common.h"
#include <stdbool.h>

Go to the source code of this file.

Functions

vector2d_t draw_inventory_view (vector2d_t anchor, const character_t *player)
 Draws the inventory view UI.
void draw_inventory_menu (vector2d_t anchor, const char *menu_name, const char *header_msg, char **menu_options, int menu_option_count, int selected_index, const char *key_msg, const char *tail_msg)
 Draws the inventory menu.
void draw_inventory_log (vector2d_t anchor, const char *inventory_log_message)
 Draws the inventory log.
int draw_inventory_resource_bar (vector2d_t anchor, const character_t *c)
 Draws the resource bar for a character in the inventory view.

Detailed Description

Exposes functions for outputing to the screen while in the inventory mode.

Definition in file inventory_output.h.

Function Documentation

◆ draw_inventory_log()

void draw_inventory_log ( vector2d_t anchor,
const char * inventory_log_message )

Draws the inventory log.

This function displays an inventory log message and waits for user input.

Parameters
anchorThe anchor point of the inventory log, representing the top-left corner
inventory_log_messageThe message to be displayed in the inventory log

Definition at line 84 of file inventory_output.c.

84 {
85 // Validate parameters
86 if (inventory_log_message == NULL) {
87 log_msg(ERROR, "Inventory Output", "Given inventory log message is NULL");
88 return;
89 }
90
91 // Display the log message
92 print_text_default(anchor.dy, anchor.dx, inventory_log_message);
93 anchor.dy++;
94 print_text_default(anchor.dy, anchor.dx, "Press any key to continue...");
95 anchor.dy++;
96
97 // Render the frame
99
100 // Use our input handler to get any key press
101 input_event_t input_event;
102 get_input_blocking(&input_event);
103}
bool get_input_blocking(input_event_t *event)
Get the next input event (blocking)
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.
Definition logger.c:246
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.
Structure for advanced input events with context data.
Definition input_types.h:43

◆ draw_inventory_menu()

void draw_inventory_menu ( vector2d_t anchor,
const char * menu_name,
const char * header_msg,
char ** menu_options,
int menu_option_count,
int selected_index,
const char * key_msg,
const char * tail_msg )

Draws the inventory menu.

This function renders a menu for the inventory mode with selectable options.

Parameters
anchorThe anchor point of the inventory menu, representing the top left corner
menu_nameThe name of the menu
header_msgThe message to display at the top of the menu (can be NULL)
menu_optionsThe options of the menu
menu_option_countThe number of options in the menu
selected_indexThe index of the selected option
key_msgFirst message to display at the bottom of the menu (can be NULL)
tail_msgSecond message to display at the bottom of the menu (can be NULL)

Definition at line 33 of file inventory_output.c.

35 {
36 // Validate parameters
37 if (menu_name == NULL || menu_options == NULL) {
38 log_msg(ERROR, "Inventory Output", "Menu options are NULL");
39 return;
40 }
41
42 vector2d_t vec = {anchor.dx, anchor.dy};
43
44 // Draw menu title
45 print_text_default(vec.dy, 1, menu_name);
46 vec.dy++;
47
48 // Draw header message if provided
49 if (header_msg != NULL) {
50 print_text_default(vec.dy++, vec.dx, header_msg);
51 }
52
53 // Draw menu items highlighting the selected one
54 for (int i = 0; i < menu_option_count; i++) {
55 if (i == selected_index) {
56 // Use > to indicate selected item and bold styling
57 char buffer[MAX_STRING_LENGTH];
58 snprintf(buffer, sizeof(buffer), "> %s", menu_options[i]);
59 // For selected items, use inverted colors
60 print_text(vec.dy, anchor.dx, buffer, INVERTED_COLORS);
61 } else {
62 // Use regular formatting for non-selected items
63 char buffer[MAX_STRING_LENGTH];
64 snprintf(buffer, sizeof(buffer), " %s", menu_options[i]);
65 print_text_default(vec.dy, anchor.dx, buffer);
66 }
67 vec.dy++;
68 }
69
70 // Draw key message if provided
71 if (key_msg != NULL) {
72 print_text_default(vec.dy + 1, vec.dx, key_msg);
73 }
74
75 // Draw tail message if provided
76 if (tail_msg != NULL) {
77 print_text_default(vec.dy + 2, vec.dx, tail_msg);
78 }
79
80 // Render the frame
82}
void print_text(int y, int x, const char *text, uint64_t ncchannel)
Print text at a specific position.
2-dimensional vector struct
Definition common.h:164

◆ draw_inventory_resource_bar()

int draw_inventory_resource_bar ( vector2d_t anchor,
const character_t * c )

Draws the resource bar for a character in the inventory view.

This function displays the character's name, health, mana, and stamina.

Parameters
anchorThe anchor point for the resource bar, representing the top-left corner
cA pointer to the character whose resources are to be displayed
Returns
The updated y-coordinate after drawing the resource bar

Definition at line 105 of file inventory_output.c.

105 {
106 char c_info[MAX_STRING_LENGTH];
107 snprintf(c_info, sizeof(c_info), "%-20s | HP: %4d/%-4d | Mana: %4d/%-4d | Stamina: %4d/%-4d",
108 c->name,
109 c->current_resources.health, c->max_resources.health,
110 c->current_resources.mana, c->max_resources.mana,
111 c->current_resources.stamina, c->max_resources.stamina);
112
113 // Display the resource bar
114 print_text_default(anchor.dy, anchor.dx, c_info);
115 anchor.dy++;
116
117 return anchor.dy;
118}

◆ draw_inventory_view()

vector2d_t draw_inventory_view ( vector2d_t anchor,
const character_t * player )

Draws the inventory view UI.

This function renders the inventory view including player resources and inventory space.

Parameters
anchorThe anchor point of the inventory view, representing the top left corner
playerThe player character
Returns
The new anchor point after drawing the inventory view

Definition at line 15 of file inventory_output.c.

15 {
16 // Clear the screen
18
19 // Copy of the anchor
20 vector2d_t vec = {anchor.dx, anchor.dy};
21
22 // Draw the character's resource bar
23 vec.dy = draw_inventory_resource_bar(vec, player);
24 vec.dy += 2;
25
26 // Render the frame
28
29 return vec;
30}
int draw_inventory_resource_bar(vector2d_t anchor, const character_t *c)
Draws the resource bar for a character in the inventory view.
void clear_screen(void)
Clear the screen.