Avancée d'UI matinales
This commit is contained in:
parent
50f6376bbf
commit
fd1af14450
1 changed files with 62 additions and 15 deletions
77
src/ui.c
77
src/ui.c
|
@ -41,25 +41,28 @@ void draw_buttons(Widget *widget){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void buttons_do_event(Widget *widget, Game *game, MTEvent event){
|
||||||
|
if(event.type != EV_Mouse || event.click != MOUSE_BUTTON_LEFT)
|
||||||
|
return;
|
||||||
|
for(int i = 0; i < widget->button_n; i++){
|
||||||
|
Button *butt = &widget->buttons[i];
|
||||||
|
if(CheckCollisionPointRec(event.pos, butt->box) && butt->handler)
|
||||||
|
butt->handler(game);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main_menu_draw(Widget *widget, Game *game){
|
void main_menu_draw(Widget *widget, Game *game){
|
||||||
ClearBackground(color_main_brown);
|
ClearBackground(color_main_brown);
|
||||||
|
|
||||||
draw_text_centered("Mineur Tycoon", 50, 100, BLACK);
|
draw_text_centered("Mineur Tycoon", 50, 100, BLACK);
|
||||||
draw_text_centered(VERSION_STR, 160, 30, BLACK);
|
draw_text_centered(VERSION_STR, 160, 30, BLACK);
|
||||||
|
|
||||||
DrawRectangleRounded((Rectangle){500, 200, 280, 260}, 0.1, 3, color_main_brown1);
|
DrawRectangleRounded((Rectangle){500, 200, 280, 260}, 0.1, 3,
|
||||||
|
color_main_brown1);
|
||||||
|
|
||||||
draw_buttons(widget);
|
draw_buttons(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_menu_do_event(Widget *widget, Game *game, MTEvent event){
|
|
||||||
if(event.type == EV_Mouse && event.click == MOUSE_BUTTON_LEFT){
|
|
||||||
gui_info.widget_active[0] = true;
|
|
||||||
gui_info.widget_active[1] = false;
|
|
||||||
game->paused = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void widget_draw_game(Widget *widget, Game *game){
|
void widget_draw_game(Widget *widget, Game *game){
|
||||||
draw_game(game);
|
draw_game(game);
|
||||||
}
|
}
|
||||||
|
@ -68,10 +71,16 @@ void main_menu_exit(Game *game){
|
||||||
game->exit = true;
|
game->exit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void main_menu_new_game(Game *game){
|
||||||
|
gui_info.widget_active[0] = true;
|
||||||
|
gui_info.widget_active[1] = false;
|
||||||
|
game->paused = false;
|
||||||
|
}
|
||||||
|
|
||||||
Widget main_menu = {
|
Widget main_menu = {
|
||||||
.box = {.x = 0, .y = 0, .width = -1, .height = -1},
|
.box = {.x = 0, .y = 0, .width = -1, .height = -1},
|
||||||
.draw = &main_menu_draw,
|
.draw = main_menu_draw,
|
||||||
.do_event = &main_menu_do_event,
|
.do_event = buttons_do_event,
|
||||||
.capt_flags = CF_Mouse | CF_Keyb,
|
.capt_flags = CF_Mouse | CF_Keyb,
|
||||||
.buttons = {
|
.buttons = {
|
||||||
{.box = {520,220,240,40},
|
{.box = {520,220,240,40},
|
||||||
|
@ -79,7 +88,7 @@ Widget main_menu = {
|
||||||
.color_1 = PINK,
|
.color_1 = PINK,
|
||||||
.color_txt = BLACK,
|
.color_txt = BLACK,
|
||||||
.txt = "New game",
|
.txt = "New game",
|
||||||
.handler = NULL
|
.handler = main_menu_new_game
|
||||||
},
|
},
|
||||||
{.box = {520,270,240,40},
|
{.box = {520,270,240,40},
|
||||||
.color_0 = WHITE,
|
.color_0 = WHITE,
|
||||||
|
@ -98,7 +107,7 @@ Widget main_menu = {
|
||||||
{.box = {520,400,240,40},
|
{.box = {520,400,240,40},
|
||||||
.color_0 = WHITE,
|
.color_0 = WHITE,
|
||||||
.color_1 = PINK,
|
.color_1 = PINK,
|
||||||
.color_txt = GRAY,
|
.color_txt = BLACK,
|
||||||
.txt = "Exit",
|
.txt = "Exit",
|
||||||
.handler = main_menu_exit
|
.handler = main_menu_exit
|
||||||
},
|
},
|
||||||
|
@ -106,9 +115,33 @@ Widget main_menu = {
|
||||||
.button_n = 4
|
.button_n = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void worker_widget_draw(Widget *widget, Game *game){
|
||||||
|
DrawRectangleRounded(widget->box, 0.1, 3, color_main_brown);
|
||||||
|
}
|
||||||
|
|
||||||
|
void worker_widget_do_event(Widget *widget, Game *game, MTEvent event){
|
||||||
|
if(event.click == MOUSE_BUTTON_LEFT)
|
||||||
|
gui_info.widget_active[2] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget worker_widget = {
|
||||||
|
.box = {.x = 40, .y = 40, .width = 300, .height = 600},
|
||||||
|
.draw = worker_widget_draw,
|
||||||
|
.do_event = NULL,
|
||||||
|
.capt_flags = CF_Mouse,
|
||||||
|
.buttons = {
|
||||||
|
|
||||||
|
},
|
||||||
|
.button_n = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
Widget machine_widget = {
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
Widget game_widget = {
|
Widget game_widget = {
|
||||||
.box = {0,0,0,0},
|
.box = {0,0,0,0},
|
||||||
.draw = &widget_draw_game,
|
.draw = widget_draw_game,
|
||||||
.do_event = NULL,
|
.do_event = NULL,
|
||||||
.capt_flags = 0,
|
.capt_flags = 0,
|
||||||
.buttons = {},
|
.buttons = {},
|
||||||
|
@ -119,7 +152,12 @@ void init_ui(){
|
||||||
snprintf(_ver_str, 256, "v%d.%d-%d", VERSION_MAJ, VERSION_MIN,
|
snprintf(_ver_str, 256, "v%d.%d-%d", VERSION_MAJ, VERSION_MIN,
|
||||||
VERSION_PATCH);
|
VERSION_PATCH);
|
||||||
|
|
||||||
gui_info = (GUIInfo){{&game_widget, &main_menu}, {false, true}, NULL};
|
// Android exclusive key -> no exit key
|
||||||
|
SetExitKey(KEY_MENU);
|
||||||
|
|
||||||
|
gui_info = (GUIInfo){{&game_widget, &main_menu, &worker_widget},
|
||||||
|
{false, true, false},
|
||||||
|
NULL};
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_widgets(Game *game){
|
void draw_widgets(Game *game){
|
||||||
|
@ -196,6 +234,7 @@ void try_interface(Game *game, V2d pos){
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("found worker\n");
|
printf("found worker\n");
|
||||||
|
gui_info.widget_active[2] = true;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -204,6 +243,12 @@ bool keydown(int key){
|
||||||
return IsKeyDown(key);
|
return IsKeyDown(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void goto_pause_menu(Game *game){
|
||||||
|
memset(gui_info.widget_active, false, sizeof(bool)*WIDGET_N);
|
||||||
|
gui_info.widget_active[1] = true;
|
||||||
|
game->paused = true;
|
||||||
|
}
|
||||||
|
|
||||||
int get_mouse(){
|
int get_mouse(){
|
||||||
for(int i = 0; i < MOUSE_BUTTON_NULL; i++){
|
for(int i = 0; i < MOUSE_BUTTON_NULL; i++){
|
||||||
if(IsMouseButtonPressed(i))
|
if(IsMouseButtonPressed(i))
|
||||||
|
@ -234,4 +279,6 @@ void get_keys(Game *game){
|
||||||
game->camera.zoom *= 1/1.1;
|
game->camera.zoom *= 1/1.1;
|
||||||
if(IsKeyPressed(KEY_P))
|
if(IsKeyPressed(KEY_P))
|
||||||
game->paused = !game->paused;
|
game->paused = !game->paused;
|
||||||
|
if(IsKeyPressed(KEY_ESCAPE))
|
||||||
|
goto_pause_menu(game);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue