umorna/source/menu.c

93 lines
2.4 KiB
C
Raw Normal View History

#include "core.h"
#include "game.h"
//~#include "engine.h"
#include "render.h"
#include "menu.h"
2023-12-20 06:52:13 -05:00
int define_menu_item (int menu,
char * text,
int icon,
void (* action) (void)) {
menu_text [menu] [menu_items [menu]] = text;
menu_icon [menu] [menu_items [menu]] = icon;
menu_action [menu] [menu_items [menu]] = action;
return (menu_items [menu]++);
}
2023-12-20 10:24:43 -05:00
int define_menu (int alpha) {
menu_items [menu_count] = 0;
menu_show [menu_count] = 0;
menu_alpha [menu_count] = alpha;
return (menu_count++);
}
void render_menu_item (int menu, int item, int x, int y) {
int u = (menu_icon [menu] [item] / 10) * ICON_SIZE;
int v = (menu_icon [menu] [item] % 10) * ICON_SIZE;
render_sprite (u, v, ICON_SIZE, ICON_SIZE, x, y + item * ICON_SIZE);
render_string (menu_text [menu] [item], x + ICON_SIZE, y + item * ICON_SIZE);
2023-12-20 10:24:43 -05:00
}
void render_menu (int menu, int align, int x, int y) {
int item;
int u = (int) strlen (menu_text [menu] [0]) * ICON_SIZE;
int v = menu_items [menu] * ICON_SIZE;
if (menu_show [menu] == 0) {
return;
}
if (menu_alpha [menu] != 0) {
DrawRectangle (x, y, u, v, BLACK);
}
for (item = 0; item < menu_items [menu]; ++item) {
if (align == 0) {
render_menu_item (menu, item, x, y);
} else {
render_menu_item (menu, item, (GetScreenWidth () - u) / 2, (GetScreenHeight () - v) / 2);
}
}
}
void menu_configure (void) {
int index;
2023-12-20 10:24:43 -05:00
menu_traits = define_menu (1);
menu_skills = define_menu (1);
menu_values = define_menu (1);
menu_resources = define_menu (0);
2023-12-20 06:52:13 -05:00
for (index = 0; index < chad_trait_count; ++index) {
2023-12-20 06:52:13 -05:00
(void) define_menu_item (menu_traits, chad_trait_name [index], index, 0);
}
for (index = 0; index < chad_skill_count; ++index) {
2023-12-20 06:52:13 -05:00
(void) define_menu_item (menu_skills, chad_skill_name [index], 3 + index, 0);
}
for (index = 0; index < chad_value_count; ++index) {
2023-12-20 06:52:13 -05:00
(void) define_menu_item (menu_values, chad_value_name [index], 27 + index, 0);
}
2023-12-20 10:24:43 -05:00
(void) define_menu_item (menu_resources, "ABC", 1, 0);
(void) define_menu_item (menu_resources, "DEF", 1, 0);
(void) define_menu_item (menu_resources, "GHI", 1, 0);
}
int menu_count = 0;
2023-12-20 10:24:43 -05:00
int menu_items [24];
int menu_show [24];
int menu_alpha [24];
2023-12-20 06:52:13 -05:00
char * menu_text [24] [24];
int menu_icon [24] [24];
void (* menu_action [24] [24]) (void);
2023-12-20 10:24:43 -05:00
int menu_traits, menu_skills, menu_values, menu_resources;