mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-06-09 22:50:53 +00:00
Implementing tooltips
This commit is contained in:
@@ -23,6 +23,7 @@ struct renderer
|
||||
gc_component base;
|
||||
enum gc_texturetype type;
|
||||
void *data;
|
||||
bool is_visible;
|
||||
};
|
||||
|
||||
void sprite_ctr(struct renderer *cmp, va_list args);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** parallax_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
#include "components/transform_component.h"
|
||||
|
||||
struct tooltip_component
|
||||
{
|
||||
gc_component base;
|
||||
struct transform_component *parent_transform;
|
||||
gc_vector2 padding;
|
||||
};
|
||||
|
||||
extern const struct tooltip_component tooltip_component;
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** Gamacon
|
||||
** File description:
|
||||
** movable_component
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
|
||||
extern const gc_system tooltip_system;
|
||||
@@ -13,6 +13,9 @@ gc_entity *new_text(gc_engine *engine, gc_scene *scene, node *n);
|
||||
|
||||
gc_entity *new_sprite(gc_engine *engine, gc_scene *scene, node *n);
|
||||
|
||||
gc_entity *tooltip_make(gc_engine *engine, gc_scene *scene, node *n, \
|
||||
gc_entity *parent);
|
||||
|
||||
void ui_setup(gc_engine *engine);
|
||||
|
||||
#endif //_UI_H_
|
||||
|
||||
@@ -21,6 +21,7 @@ static void ctr(void *component, va_list args)
|
||||
|
||||
cmp->data = NULL;
|
||||
cmp->type = type;
|
||||
cmp->is_visible = true;
|
||||
if (type == GC_TEXTUREREND)
|
||||
sprite_ctr(cmp, args);
|
||||
if (type == GC_ANIMREND)
|
||||
@@ -48,6 +49,7 @@ static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
gc_texturetype type = renderer_get_type(n);
|
||||
|
||||
cmp->type = type;
|
||||
cmp->is_visible = true;
|
||||
if (type == GC_TEXTUREREND)
|
||||
sprite_fdctr(scene, cmp, n);
|
||||
if (type == GC_ANIMREND)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** parralax_component
|
||||
*/
|
||||
|
||||
#include "components/tooltip_component.h"
|
||||
#include "xml.h"
|
||||
#include "my.h"
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct tooltip_component *cmp = (struct tooltip_component *)component;
|
||||
|
||||
cmp->parent_transform = va_arg(args, struct transform_component *);
|
||||
cmp->padding.x = va_arg(args, double);
|
||||
cmp->padding.y = va_arg(args, double);
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
|
||||
{
|
||||
my_printf("Can't create a tooltip component from the fdctr.\n");
|
||||
}
|
||||
|
||||
static void dtr(void *component)
|
||||
{
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct tooltip_component tooltip_component = {
|
||||
base: {
|
||||
name: "tooltip_component",
|
||||
size: sizeof(struct tooltip_component),
|
||||
dependencies: (char *[]) {"renderer", NULL},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: &dtr,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "components/collision_component.h"
|
||||
#include "components/vertex_component.h"
|
||||
#include <stdlib.h>
|
||||
#include <components/tooltip_component.h>
|
||||
#include "components/clickable_component.h"
|
||||
#include "components/tag_component.h"
|
||||
#include "components/input_component.h"
|
||||
@@ -48,4 +49,5 @@ void engine_add_buildin_components(gc_engine *engine)
|
||||
engine->add_component(engine, &vertex_component);
|
||||
engine->add_component(engine, &input_component);
|
||||
engine->add_component(engine, &tag_component);
|
||||
engine->add_component(engine, &tooltip_component);
|
||||
}
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "systems/friction_system.h"
|
||||
#include "systems/collision_system.h"
|
||||
#include "systems/camerafollow_system.h"
|
||||
#include "systems/tooltip_system.h"
|
||||
#include "sfml_renderer.h"
|
||||
#include "clickable_component.h"
|
||||
|
||||
@@ -36,6 +37,7 @@ void engine_add_builtin_systems(gc_engine *engine)
|
||||
engine->add_system(engine, ¶llax_system);
|
||||
engine->add_system(engine, &keyboard_controller_system);
|
||||
engine->add_system(engine, &friction_system);
|
||||
engine->add_system(engine, new_system(&tooltip_system));
|
||||
engine->add_system(engine, new_system(&collision_system, engine->scene));
|
||||
clickable_manager_init(engine);
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ gc_text *txt)
|
||||
sfText_setFont(renderer->text, txt->font);
|
||||
sfText_setCharacterSize(renderer->text, txt->size / size);
|
||||
bounds = sfText_getLocalBounds(renderer->text);
|
||||
tra->size.x = bounds.width;
|
||||
tra->size.y = bounds.height;
|
||||
sfText_setColor(renderer->text, *(sfColor*)&txt->color);
|
||||
sfText_setPosition(renderer->text, (sfVector2f){
|
||||
tra->position.x - bounds.width / 2,
|
||||
|
||||
@@ -34,7 +34,7 @@ gc_entity *entity, float dt)
|
||||
struct renderer *text = GETCMP(entity, renderer);
|
||||
struct sfml_renderer_system *rend = (struct sfml_renderer_system *)system;
|
||||
|
||||
if (!text->data)
|
||||
if (!text->data || !text->is_visible)
|
||||
return;
|
||||
switch (text->type) {
|
||||
case GC_TEXTUREREND:
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** friction
|
||||
*/
|
||||
|
||||
#include "entity.h"
|
||||
#include "system.h"
|
||||
#include "vector2.h"
|
||||
#include "utility.h"
|
||||
#include "components/transform_component.h"
|
||||
#include "components/tooltip_component.h"
|
||||
#include "systems/camerafollow_system.h"
|
||||
#include "math.h"
|
||||
#include <stddef.h>
|
||||
#include <components/renderer.h>
|
||||
|
||||
static void update_entity(gc_engine *engine, void *system, \
|
||||
gc_entity *entity, float dtime)
|
||||
{
|
||||
struct tooltip_component *tt = GETCMP(entity, tooltip_component);
|
||||
struct transform_component *tra = tt->parent_transform;
|
||||
struct renderer *rend = GETCMP(entity, renderer);
|
||||
gc_vector2 pad = tt->padding;
|
||||
gc_vector2 position = engine->get_cursor_pos(engine);
|
||||
|
||||
if (!tra)
|
||||
return;
|
||||
rend->is_visible = (tra->position.x - tra->size.x / 2 - pad.x) <= position.x
|
||||
&& (tra->position.y + tra->size.y / 2 + pad.y) >= position.y
|
||||
&& (tra->position.x + tra->size.x / 2 + pad.x) >= position.x
|
||||
&& (tra->position.y - tra->size.y / 2 - pad.y) <= position.y;
|
||||
}
|
||||
|
||||
static void ctr(void *system, va_list args)
|
||||
{
|
||||
}
|
||||
|
||||
const gc_system tooltip_system = {
|
||||
name: "tooltip_system",
|
||||
component_name: "tooltip_component",
|
||||
size: sizeof(gc_system),
|
||||
ctr: &ctr,
|
||||
dtr: NULL,
|
||||
check_dependencies: &system_check_dependencies,
|
||||
update_entity: &update_entity,
|
||||
destroy: &system_destroy
|
||||
};
|
||||
+6
-1
@@ -65,8 +65,11 @@ gc_data *sprite_make(gc_engine *engine, gc_scene *scene, node *n)
|
||||
{
|
||||
gc_list *list = NULL;
|
||||
gc_data *data = malloc(sizeof(*data));
|
||||
gc_entity *sprite = new_sprite(engine, scene, n);
|
||||
|
||||
LISTADD(list, new_sprite(engine, scene, n));
|
||||
LISTADD(list, sprite);
|
||||
if (xml_hasproperty(n, "tooltip"))
|
||||
LISTADD(list, tooltip_make(engine, scene, n, sprite));
|
||||
data->name = "sprite";
|
||||
data->type = "ui";
|
||||
data->destroy = NULL;
|
||||
@@ -82,6 +85,8 @@ gc_data *text_make(gc_engine *engine, gc_scene *scene, node *n)
|
||||
gc_entity *txt = new_text(engine, scene, n);
|
||||
|
||||
LISTADD(list, txt);
|
||||
if (xml_hasproperty(n, "tooltip"))
|
||||
LISTADD(list, tooltip_make(engine, scene, n, txt));
|
||||
for (n = n->child; n; n = n->next) {
|
||||
cmp = deserialize_component(engine, txt, scene, n);
|
||||
txt->add_component(txt, cmp);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Created by anonymus-raccoon on 3/9/20.
|
||||
//
|
||||
|
||||
#include "engine.h"
|
||||
#include "xml.h"
|
||||
#include "ui.h"
|
||||
#include <stddef.h>
|
||||
#include "components/tag_component.h"
|
||||
#include "components/fixed_to_cam_component.h"
|
||||
#include "components/tooltip_component.h"
|
||||
#include "components/renderer.h"
|
||||
#include "components/transform_component.h"
|
||||
|
||||
gc_entity *tooltip_make(gc_engine *engine, gc_scene *scene, node *n, \
|
||||
gc_entity *parent)
|
||||
{
|
||||
gc_entity *entity = entity_create();
|
||||
|
||||
if (!entity)
|
||||
return (NULL);
|
||||
entity->add_component(entity, new_component(&transform_component,
|
||||
(gc_vector2){0, 0}, (gc_vector2){0, 0}));
|
||||
entity->add_component(entity, new_component(&renderer_component,
|
||||
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));
|
||||
entity->add_component(entity, new_component(&tooltip_component,
|
||||
GETCMP(parent, transform_component), xml_getfloatprop(n, "padding_x"),
|
||||
xml_getfloatprop(n, "padding_y")));
|
||||
if (xml_hasproperty(n, "tag"))
|
||||
entity->add_component(entity, new_component(&tag_component,
|
||||
xml_getproperty(n, "tag")));
|
||||
return (entity);
|
||||
}
|
||||
+5
-1
@@ -38,12 +38,16 @@ gc_list *list_remove(gc_list *list, void *obj)
|
||||
|
||||
if (!list)
|
||||
return (NULL);
|
||||
if (list->data == obj)
|
||||
if (list->data == obj) {
|
||||
if (list->next)
|
||||
list->next->prev = NULL;
|
||||
return (list->next);
|
||||
}
|
||||
while (list->next && list->next->data != obj)
|
||||
list = list->next;
|
||||
if (!list->next)
|
||||
return (listconst);
|
||||
list->next = list->next->next;
|
||||
list->next->prev = list;
|
||||
return (listconst);
|
||||
}
|
||||
Reference in New Issue
Block a user