DungeonCrawl
Loading...
Searching...
No Matches
stats_output.c
Go to the documentation of this file.
1
5#include "stats_output.h"
6
13#include "../../io_handler.h"
15
16// Store menu options for stats menu
17static string_max_t* stats_menu_options;
18
19
21 stats_mode_strings = (char**) malloc(sizeof(char*) * MAX_STATS_STRINGS);
22 RETURN_WHEN_NULL(stats_mode_strings, 1, "Stats Mode", "Failed to allocate memory for stats mode strings.")
23
24 for (int i = 0; i < MAX_STATS_STRINGS; i++) {
25 stats_mode_strings[i] = NULL;
26 }
27
28 // Allocate memory for menu options
29 stats_menu_options = memory_pool_alloc(main_memory_pool, sizeof(string_max_t) * MAX_ABILITY_LIMIT);
30 RETURN_WHEN_NULL(stats_menu_options, -1, "Stats Mode",
31 "Allocated memory for stats window options in memory pool is NULL");
32
33 // Initialize localized strings
35
36 // Register for locale changes
38 return 0;
39}
40
41
42void render_stats_window(const character_t* player) {
43 // Clear the screen
45
46 int y = 0;
47 int x = 0;
48 char stats_info[MAX_STRING_LENGTH];
49
50 // Display stats title
51 print_text_default(y++, x, stats_mode_strings[PLAYER_MENU_TITLE]);
52
53 // Display player resources
54 snprintf(stats_info, sizeof(stats_info), "%s: %4d / %-4d| %s: %4d / %-4d | %s: %4d / %-4d",
55 stats_mode_strings[HEALTH_STR], player->current_resources.health, player->max_resources.health,
56 stats_mode_strings[MANA_STR], player->current_resources.mana, player->max_resources.mana,
57 stats_mode_strings[STAMINA_STR], player->current_resources.stamina, player->max_resources.stamina);
58 print_text_default(y++, x, stats_info);
59
60 // Display player attributes
61 snprintf(stats_info, sizeof(stats_info), "%s: %-4d | %s: %-4d | %s: %-4d | %s: %-4d",
62 stats_mode_strings[STRENGTH_STR], player->base_stats.strength,
63 stats_mode_strings[INTELLIGENCE_STR], player->base_stats.intelligence,
64 stats_mode_strings[DEXTERITY_STR], player->base_stats.dexterity,
65 stats_mode_strings[CONSTITUTION_STR], player->base_stats.constitution);
66 print_text_default(y++, x, stats_info);
67
68 // Display player level and XP
69 snprintf(stats_info, sizeof(stats_info), "%s: %-4d | %s: %4d / %-4d",
70 stats_mode_strings[LEVEL_STR], player->level,
71 stats_mode_strings[EXP_STR], player->xp, calculate_xp_for_next_level(player->level));
72 print_text_default(y++, x, stats_info);
73
74 // Display equipment header
75 snprintf(stats_info, sizeof(stats_info), "%s:", stats_mode_strings[INVENTORY_MENU_TITLE]);
76 print_text_default(y++, x, stats_info);
77
78 // Display equipped items
79 for (int i = 0; i < MAX_SLOT; i++) {
80 if (player->equipment[i] != NULL) {
81 snprintf(stats_info, sizeof(stats_info), "%s: %s | %s: %-4d, %s: %-4d",
82 stats_mode_strings[EQUIPPED_ARMOR_STR], player->equipment[i]->local_key,
83 stats_mode_strings[ARMOR_STR], player->equipment[i]->defenses.armor,
84 stats_mode_strings[MAGIC_RESISTANCE_STR], player->equipment[i]->defenses.magic_resist);
85 } else {
86 snprintf(stats_info, sizeof(stats_info), "%s %d", stats_mode_strings[EMPTY_ARMOR_SLOT_STR], i);
87 }
88 print_text_default(y++, x, stats_info);
89 }
90
91 y += 2;// Add space
92
93 // Display skill points
94 snprintf(stats_info, sizeof(stats_info), "%s: %d", stats_mode_strings[AVAILABLE_SKILL_POINTS_STR], player->skill_points);
95 print_text_default(y, x, stats_info);
96}
97
98void draw_stats_menu(const char* title, const char** options, int option_count, int selected_index, const char* footer) {
99 // Set menu position
100 int y = 20;
101 int x = 2;
102
103 // Draw menu options using centralized print_menu
104 print_menu(title, options, option_count, selected_index, y, x,
105 DEFAULT_COLORS, DEFAULT_COLORS, INVERTED_COLORS);
106
107 // Draw footer at the bottom
108 y += option_count + 1;
109 print_text_default(y, x, footer);
110}
111
112void draw_stats_log(const char* message) {
113 // Display message
114 print_text_default(1, 2, message);
115
116 // Render the frame
117 render_frame();
118}
119
121 if (stats_mode_strings != NULL) {
122 for (int i = 0; i < MAX_STATS_STRINGS; i++) {
123 if (stats_mode_strings[i] != NULL) {
124 free(stats_mode_strings[i]);
125 }
126 }
127 free(stats_mode_strings);
128 }
129}
Exposes functions for working working with the character.
memory_pool_t * main_memory_pool
Global memory pool for the application.
Definition common.c:7
Exposes functions for the IO-Handler.
int calculate_xp_for_next_level(int level)
Calculates the XP required for the next level.
Definition level.c:11
Exposes functions for working with the character.
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.
Header file for logging functionality of the game.
void * memory_pool_alloc(memory_pool_t *pool, size_t size)
Allocates memory on the given memory pool.
Exposes functions for working with the memory management.
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 print_menu(const char *title, const char **options, int option_count, int selected_index, int y, int x, uint64_t title_channel, uint64_t option_channel, uint64_t selected_channel)
Print a menu with selection highlighting.
void clear_screen(void)
Clear the screen.
Exposes functions for outputting to the console.
Exposes functions and enums for working with localization in the map mode.
void draw_stats_log(const char *message)
Display a message in the stats log.
void shutdown_stats_mode()
Shutdown the stats mode.
void draw_stats_menu(const char *title, const char **options, int option_count, int selected_index, const char *footer)
Draw the stats menu.
int init_stats_mode()
Initialize the stats mode.
void render_stats_window(const character_t *player)
Render the stats window.
Exposes functions for outputing to the screen in stats mode.
void update_stats_local(void)
Update localized strings for the stats mode.
String struct with a fixed maximum length, it is directly linked to the macro MAX_STRING_LENGTH.
Definition common.h:172