DungeonCrawl
Loading...
Searching...
No Matches
inventory_output.c
Go to the documentation of this file.
1
5#include "inventory_output.h"
6
8#include "../../../common.h"
11#include "../../io_handler.h"
13
14
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}
31
32
33void draw_inventory_menu(const vector2d_t anchor, const char* menu_name, const char* header_msg,
34 char** menu_options, const int menu_option_count,
35 const int selected_index, const char* key_msg, const char* tail_msg) {
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}
83
84void draw_inventory_log(vector2d_t anchor, const char* inventory_log_message) {
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}
104
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}
Exposes functions for working working with the character.
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.
void draw_inventory_menu(const vector2d_t anchor, const char *menu_name, const char *header_msg, char **menu_options, const int menu_option_count, const int selected_index, const char *key_msg, const char *tail_msg)
Draws the inventory menu.
int draw_inventory_resource_bar(vector2d_t anchor, const character_t *c)
Draws the resource bar for a character in the inventory view.
vector2d_t draw_inventory_view(const vector2d_t anchor, const character_t *player)
Draws the inventory view UI.
void draw_inventory_log(vector2d_t anchor, const char *inventory_log_message)
Draws the inventory log.
Exposes functions for outputing to the screen while in the inventory mode.
Exposes functions for the IO-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.
Definition logger.c:246
Header file for logging functionality of the game.
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.
Structure for advanced input events with context data.
Definition input_types.h:43
2-dimensional vector struct
Definition common.h:164