Experimental menus, messy code...
This commit is contained in:
parent
0701aa50ea
commit
897a9be0de
@ -15,6 +15,7 @@
|
||||
|
||||
#include <xolatile/chads.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <raylib.h>
|
||||
|
||||
|
@ -17,9 +17,15 @@ int main (void) {
|
||||
|
||||
render_map ();
|
||||
|
||||
render_menu (menu_traits);
|
||||
render_menu (menu_skills);
|
||||
render_menu (menu_values);
|
||||
menu_show [menu_resources] = 1;
|
||||
menu_show [menu_traits] = 1;
|
||||
menu_show [menu_skills] = 1;
|
||||
menu_show [menu_values] = 1;
|
||||
|
||||
render_menu (menu_resources, 1, 0, 0);
|
||||
render_menu (menu_traits, 0, 0, 0);
|
||||
render_menu (menu_skills, 0, 200, 0);
|
||||
render_menu (menu_values, 0, 400, 0);
|
||||
|
||||
//~Rectangle source = { 0, 0, BASE_SIZE * 15, BASE_SIZE * 10 };
|
||||
//~Rectangle destination = { 128, 128, BASE_SIZE * 15 * zoom, BASE_SIZE * 10 * zoom };
|
||||
|
@ -3,18 +3,6 @@
|
||||
#include "engine.h"
|
||||
#include "menu.h"
|
||||
|
||||
int define_menu (char * title,
|
||||
int x,
|
||||
int y) {
|
||||
menu_title [menu_count] = title;
|
||||
menu_items [menu_count] = 0;
|
||||
menu_x [menu_count] = x;
|
||||
menu_y [menu_count] = y;
|
||||
menu_show [menu_count] = 0;
|
||||
|
||||
return (menu_count++);
|
||||
}
|
||||
|
||||
int define_menu_item (int menu,
|
||||
char * text,
|
||||
int icon,
|
||||
@ -26,49 +14,78 @@ int define_menu_item (int menu,
|
||||
return (menu_items [menu]++);
|
||||
}
|
||||
|
||||
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_icon (u, v, ICON_SIZE, ICON_SIZE, x, y + item * ICON_SIZE);
|
||||
render_text (menu_text [menu] [item], x + ICON_SIZE, y + item * ICON_SIZE);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
menu_traits = define_menu ("Traits", 0, 0);
|
||||
menu_traits = define_menu (1);
|
||||
menu_skills = define_menu (1);
|
||||
menu_values = define_menu (1);
|
||||
menu_resources = define_menu (0);
|
||||
|
||||
for (index = 0; index < chad_trait_count; ++index) {
|
||||
(void) define_menu_item (menu_traits, chad_trait_name [index], index, 0);
|
||||
}
|
||||
|
||||
menu_skills = define_menu ("Skills", 200, 0);
|
||||
|
||||
for (index = 0; index < chad_skill_count; ++index) {
|
||||
(void) define_menu_item (menu_skills, chad_skill_name [index], 3 + index, 0);
|
||||
}
|
||||
|
||||
menu_values = define_menu ("Values", 400, 0);
|
||||
|
||||
for (index = 0; index < chad_value_count; ++index) {
|
||||
(void) define_menu_item (menu_values, chad_value_name [index], 27 + index, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void render_menu (int menu) {
|
||||
int index;
|
||||
|
||||
for (index = 0; index < menu_items [menu]; ++index) {
|
||||
int x = (menu_icon [menu] [index] / 10) * ICON_SIZE;
|
||||
int y = (menu_icon [menu] [index] % 10) * ICON_SIZE;
|
||||
render_icon (x, y, ICON_SIZE, ICON_SIZE, menu_x [menu], menu_y [menu] + index * ICON_SIZE);
|
||||
render_text (menu_text [menu] [index], menu_x [menu] + ICON_SIZE, menu_y [menu] + index * ICON_SIZE);
|
||||
}
|
||||
(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;
|
||||
|
||||
char * menu_title [24];
|
||||
int menu_items [24];
|
||||
int menu_x [24];
|
||||
int menu_y [24];
|
||||
int menu_show [24];
|
||||
int menu_alpha [24];
|
||||
|
||||
char * menu_text [24] [24];
|
||||
int menu_icon [24] [24];
|
||||
void (* menu_action [24] [24]) (void);
|
||||
|
||||
int menu_traits, menu_skills, menu_values;
|
||||
int menu_traits, menu_skills, menu_values, menu_resources;
|
||||
|
@ -1,19 +1,18 @@
|
||||
extern void menu_configure (void);
|
||||
|
||||
extern int define_menu (char * title, int x, int y);
|
||||
extern int define_menu_item (int menu, char * text, int icon, void (* action) (void));
|
||||
extern void render_menu (int menu);
|
||||
extern int define_menu (int alpha);
|
||||
extern void render_menu_item (int menu, int item, int x, int y);
|
||||
extern void render_menu (int menu, int align, int x, int y);
|
||||
|
||||
extern int menu_count;
|
||||
|
||||
extern char * menu_title [24];
|
||||
extern int menu_items [24];
|
||||
extern int menu_x [24];
|
||||
extern int menu_y [24];
|
||||
extern int menu_show [24];
|
||||
extern int menu_alpha [24];
|
||||
|
||||
extern char * menu_text [24] [24];
|
||||
extern int menu_icon [24] [24];
|
||||
extern void (* menu_action [24] [24]) (void);
|
||||
|
||||
extern int menu_traits, menu_skills, menu_values;
|
||||
extern int menu_traits, menu_skills, menu_values, menu_resources;
|
||||
|
Loading…
Reference in New Issue
Block a user