Fixing a bug with the dialog holder callback and adding the fisherman

This commit is contained in:
Anonymus Raccoon
2020-05-01 17:31:49 +02:00
parent 9874cc20f9
commit b217494352
11 changed files with 85 additions and 13 deletions
+1 -1
View File
@@ -298,7 +298,7 @@ add_executable(my_rpg
include/components/attack_component.h
src/systems/combat_methods.c
src/combat/attacks.c
src/player_utilities.c include/player_utilities.h src/systems/inventory.c include/systems/inventory.h src/systems/game_over.c include/systems/game_over.h src/npc/mia.c lib/gamacon/src/scene/scene_constructor.c)
src/player_utilities.c include/player_utilities.h src/systems/inventory.c include/systems/inventory.h src/systems/game_over.c include/systems/game_over.h src/npc/mia.c lib/gamacon/src/scene/scene_constructor.c src/npc/fisherman.c)
add_compile_options(-W -Wall -Wextra -Wshadow)
+2 -1
View File
@@ -42,7 +42,8 @@ SRC = src/main.c \
src/player_utilities.c \
src/systems/inventory.c \
src/systems/game_over.c \
src/npc/mia.c
src/npc/mia.c \
src/npc/fisherman.c
OBJ = $(SRC:%.c=%.o)
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

+1
View File
@@ -50,5 +50,6 @@ void dialog_next(gc_engine *engine);
struct dialog_line *dialog_add_line(struct dialog_holder *this, char *name, \
char *text, struct dialog_input *inputs);
void show_dialog_if_hidden(gc_engine *engine);
struct dialog_holder *dialog_get_current(gc_engine *engine);
#endif //MY_RPG_DIALOG_HOLDER_H
+4
View File
@@ -72,5 +72,9 @@ gc_vector2 pos, enum gc_mousekeys key);
bool mia_fish(gc_engine *engine, gc_entity *entity, \
gc_vector2 pos, enum gc_mousekeys key);
void fisherman_setup(gc_engine *engine);
bool fisherman_next(gc_engine *engine, gc_entity *entity, \
gc_vector2 pos, enum gc_mousekeys key);
void load_data(gc_scene *scene, const gc_data *datas);
extern const struct gc_data game_data[];
+21
View File
@@ -145,6 +145,7 @@
<sprite name="farmer1" src="assets/sprites/npc/farmer1.png" />
<sprite name="mayor" src="assets/sprites/npc/mayor.png" />
<sprite name="mia" src="assets/sprites/npc/mia.png" />
<sprite name="fisherman" src="assets/sprites/npc/fisherman.png" />
<enemies>
<enemy name="bee" src="prefabs/enemies/bee.gcprefab" spawn_rate="17%" />
@@ -236,6 +237,26 @@
</dialog_holder>
</gc_entity>
<gc_entity>
<transform_component>
<Position x="0" y="0" />
<Size x="70" y="90" />
</transform_component>
<renderer src="fisherman">
<Rect height="32" width="24" top="64" left="24" />
</renderer>
<map_linker x="15" y="51" />
<dialog_holder x="15" y="50" tile_texture="npc_interact">
<Fisherman line="Hello dear hero!\nI caught some fish for you." />
<Fisherman line="Do you want some?" callback="fisherman_setup" >
<input text="Yes" click="fisherman_next" />
<input text="Of course" click="fisherman_next" />
<input text="No" />
<input text="Bye" />
</Fisherman>
</dialog_holder>
</gc_entity>
<gc_entity>
<transform_component>
<Position x="0" y="0" />
+8 -5
View File
@@ -79,17 +79,20 @@ bool dialog_parse_inputs(struct dialog_line *txt, gc_scene *scene, node *n)
struct dialog_line *dialog_parse_text(gc_scene *scene, node *n)
{
struct dialog_line *txt = malloc(sizeof(struct dialog_line));
char *callback;
char *clb;
if (!txt)
return (NULL);
txt->name = my_strdup(n->name);
txt->text = xml_getproperty(n, "line");
txt->input_count = xml_getchildcount_filtered(n, "input");
callback = xml_gettempprop(n, "callback");
txt->callback = scene->get_data(scene, "dialog_callback", callback);
if (callback && !txt->callback)
my_printf("Couldn't find an callback with the name: %s.\n", callback);
clb = xml_gettempprop(n, "clb");
if (clb) {
txt->callback = scene->get_data(scene, "dialog_callback", clb);
if (!txt->callback)
my_printf("Couldn't find an clb with the name: %s.\n", clb);
} else
txt->callback = NULL;
txt->inputs = NULL;
if (txt->input_count == 0)
return (txt);
+7
View File
@@ -32,4 +32,11 @@ struct dialog_input *inputs)
this->text[count] = line;
this->text[count + 1] = NULL;
return (line);
}
struct dialog_holder *dialog_get_current(gc_engine *engine)
{
struct dialog_manager *manager = GETSYS(engine, dialog_manager);
return (manager->current_dialog);
}
+2
View File
@@ -58,6 +58,8 @@ const struct gc_data game_data[] = {
{"input", "mia_save", &mia_save, NULL},
{"input", "mia_fish", &mia_fish, NULL},
{"dialog_callback", "mia_setup", &mia_setup, NULL},
{"dialog_callback", "fisherman_setup", &fisherman_setup, NULL},
{"input", "fisherman_next", &fisherman_next, NULL},
{NULL, NULL, NULL, NULL}
};
+39
View File
@@ -0,0 +1,39 @@
/*
** EPITECH PROJECT, 2020
** my_rpg
** File description:
** fisherman.c
*/
#include "components/dialog_holder.h"
#include "systems/game_manager_system.h"
#include "engine.h"
void fisherman_setup(gc_engine *engine)
{
struct dialog_holder *holder = dialog_get_current(engine);
holder->text[2] = NULL;
}
bool fisherman_next(gc_engine *engine, gc_entity *entity, \
gc_vector2 pos, enum gc_mousekeys key)
{
struct dialog_holder *dialog = dialog_get_current(engine);
if (!dialog)
return (false);
dialog_add_line(dialog, "Fisherman", "Sometimes I catch \
fishes with\na strange ability:", NULL);
dialog_add_line(dialog, "Fisherman", "they can throw a powerful Water\n\
Jet at their enemies.", NULL);
dialog_add_line(dialog, "Fisherman", "This kind of fish seems \
to come from the\nsource of the river, something must be there.", NULL);
dialog_add_line(dialog, "Fisherman", "You should check it out!", NULL);
dialog_add_line(dialog, "Fisherman", "If you pass nearby Mia, tell her\n\
that I will show up at...", NULL);
dialog_add_line(dialog, "Fisherman", "her house for dinner tonight.", NULL);
GETSYS(engine, game_manager_system)->has_message = true;
return (true);
}
-6
View File
@@ -10,12 +10,6 @@
#include <systems/game_manager_system.h>
#include "engine.h"
struct dialog_holder *dialog_get_current(gc_engine *engine)
{
struct dialog_manager *manager = GETSYS(engine, dialog_manager);
return (manager->current_dialog);
}
void mia_setup(gc_engine *engine)
{