diff --git a/include/keybindings.h b/include/keybindings.h index 91ba434..6b7b279 100644 --- a/include/keybindings.h +++ b/include/keybindings.h @@ -16,6 +16,6 @@ typedef enum gc_mousekeys { GC_LEFT, GC_RIGHT -}; +} gc_mousekeys; #endif //_KEYBINDINGS_H_ diff --git a/src/entity/entity.c b/src/entity/entity.c index 0e8a1ce..f602490 100644 --- a/src/entity/entity.c +++ b/src/entity/entity.c @@ -60,7 +60,7 @@ static void destroy(gc_entity *entity, gc_scene *scene) for (gc_component *cmp = entity->components; cmp; cmp = next) { for (gc_tupple *tup = scene->entities_by_cmp; tup; tup = tup->next) if (!my_strcmp(tup->name, cmp->name)) - tup_remove(tup, entity->id); + LISTREM(tup->entities, entity); LISTREM(scene->entities, entity); next = cmp->next; cmp->destroy(cmp); diff --git a/src/entity/entity_factory.c b/src/entity/entity_factory.c index d6b43cf..3bda380 100644 --- a/src/entity/entity_factory.c +++ b/src/entity/entity_factory.c @@ -83,7 +83,7 @@ const char *name) return; for (gc_tupple *tup = scene->entities_by_cmp; tup; tup = tup->next) { if (!my_strcmp(tup->name, name)) - tup_remove(tup, entity->id); + LISTREM(tup->entities, entity); } component_destroy(cmp); } \ No newline at end of file diff --git a/src/sfml_renderer/sfml_events.c b/src/sfml_renderer/sfml_events.c index 1549e73..ac9fd3b 100644 --- a/src/sfml_renderer/sfml_events.c +++ b/src/sfml_renderer/sfml_events.c @@ -7,9 +7,6 @@ #include #include "sfml_renderer.h" #include "systems/sfml_renderer_system.h" -#include "systems/camerafollow_system.h" -#include "components/clickable_component.h" -#include "components/transform_component.h" void sfml_handle_events(gc_engine *engine) { diff --git a/src/ui/button.c b/src/ui/button.c index 2d6e893..d9276e3 100644 --- a/src/ui/button.c +++ b/src/ui/button.c @@ -25,10 +25,11 @@ gc_text *text) char *texture_name = xml_gettmpstring(n, "sprite", "button_background"); sfTexture *texture = scene->get_data(scene, "sprite", texture_name); gc_vector2i s = {xml_getintprop(n, "width"), xml_getintprop(n, "height")}; - gc_vector2 ts = rend->get_text_size(rend, text); + gc_vector2 ts; if (!rend) return (NULL); + ts = rend->get_text_size(rend, text); if (!texture) my_printf("No texture defined for the button_background.\n"); entity->add_component(entity, new_component(&transform_component, @@ -62,6 +63,8 @@ gc_list *new_button(gc_engine *engine, gc_scene *scene, node *n) if (xml_hasproperty(n, "tag")) background->add_component(background, new_component(&tag_component, xml_getproperty(n, "tag"))); + if (xml_hasproperty(n, "tooltip")) + LISTADD(entities, tooltip_make(engine, scene, n, background)); LISTADD(entities, background); LISTADD(entities, new_text(engine, scene, n)); return (entities); @@ -70,10 +73,11 @@ gc_list *new_button(gc_engine *engine, gc_scene *scene, node *n) gc_data *button_make(gc_engine *engine, gc_scene *scene, node *n) { gc_data *data = malloc(sizeof(*data)); + gc_list *list = new_button(engine, scene, n); data->name = "button"; data->type = "ui"; data->destroy = NULL; - data->custom = new_button(engine, scene, n); + data->custom = list; return (data); } \ No newline at end of file diff --git a/src/ui/tooltip.c b/src/ui/tooltip.c index e1ea601..0e8944a 100644 --- a/src/ui/tooltip.c +++ b/src/ui/tooltip.c @@ -12,6 +12,18 @@ #include "components/renderer.h" #include "components/transform_component.h" +static void setup_position(gc_entity *entity, gc_scene *scene, node *n) +{ + entity->add_component(entity, new_component(&fixed_to_cam, + (gc_vector2){ + xml_getintprop(n, "x") + xml_getintprop(n, "tooltip_x"), + xml_getintprop(n, "y") - xml_getintprop(n, "tooltip_y") + }, + xml_propcontains(n, "x", "%"), + xml_propcontains(n, "y", "%"), + 0, 0, false, false)); +} + gc_entity *tooltip_make(gc_engine *engine, gc_scene *scene, node *n, \ gc_entity *parent) { @@ -25,10 +37,7 @@ gc_entity *parent) GC_TXTREND, xml_getproperty(n, "tooltip"), scene->get_data(scene, "font", NULL), xml_getintprop(n, "size"), xml_gettempprop(n, "color"), xml_getbool(n, "resize", true))); - entity->add_component(entity, new_component(&fixed_to_cam, - (gc_vector2){xml_getintprop(n, "x") + 10,xml_getintprop(n, "y") - 5}, - xml_propcontains(n, "x", "%"), xml_propcontains(n, "y", "%"), - 0, 0, false, false)); + setup_position(entity, scene, n); entity->add_component(entity, new_component(&tooltip_component, GETCMP(parent, transform_component), xml_getfloatprop(n, "padding_x"), xml_getfloatprop(n, "padding_y"))); diff --git a/src/utility/tupple.c b/src/utility/tupple.c index ffdd560..081b25f 100644 --- a/src/utility/tupple.c +++ b/src/utility/tupple.c @@ -41,20 +41,4 @@ gc_tupple *tupple_add(gc_tupple *list, const char *name, gc_entity *entity) list->entities = list_add(NULL, entity); list->next = NULL; return (listconst); -} - -void tup_remove(gc_tupple *tup, int id) -{ - gc_list *prev = NULL; - - for (gc_list *ent = tup->entities; ent; ent = ent->next) { - if (((gc_entity *)ent->data)->id == id) { - if (prev) - prev->next = ent->next; - else - tup->entities = ent->next; - return; - } - prev = ent; - } } \ No newline at end of file