Adding names of the person who talks on the dialog

This commit is contained in:
Anonymus Raccoon
2020-04-15 15:13:36 +02:00
parent 34e8091682
commit c11962b462
6 changed files with 70 additions and 55 deletions
+7 -2
View File
@@ -10,9 +10,14 @@
#include "component.h"
struct dialog_line {
char *name;
char *text;
};
struct dialog_holder {
gc_component base;
char **text;
struct dialog_line **text;
bool single_usage;
bool has_seen;
struct tile *tile;
@@ -24,7 +29,7 @@ struct dialog_manager {
gc_system base;
int dialog_id;
int current_line;
char *current_text;
struct dialog_line *current_text;
struct dialog_holder *current_dialog;
};
+2 -2
View File
@@ -1,5 +1,5 @@
<gc_entities>
<panel src="text_box" x="50%" y="87%" width="60%" height="15%" />
<text text="Gamacon" x="25%" y="80%" centered="false" y_top="true" text_id="1336" />
<text text="Fatal error:\nNo dialog found." x="32%" y="85%" centered="false" text_id="1337" y_top="true" />
<text text="Gamacon" x="25%" y="80%" centered="false" y_top="true" text_id="1336" size="17" />
<text text="Fatal error:\nNo dialog found." x="29%" y="84%" centered="false" text_id="1337" y_top="true" size="25" />
</gc_entities>
+2 -2
View File
@@ -149,8 +149,8 @@
</renderer>
<map_linker x="2" y="6" />
<dialog_holder x="2" y="5" tile_texture="dirt_top_1">
<test_dialog line="Hello dirt block,\nI am the mighty cobble block." />
<test_dialog line="Can I do something\n for you?" />
<??? line="Hello dirt block,\nI am the mighty cobble block." />
<Cobble_block line="Can I do something\n for you?" />
</dialog_holder>
</gc_entity>
+39 -39
View File
@@ -1,41 +1,41 @@
<gc_entities>
<gc_entity id="50">
<transform_component>
<Position x="0" y="0" />
<Size x="100" y="100" />
</transform_component>
<renderer src="player">
<Rect height="147" width="138" top="0" left="0" />
<animation name="walk_down_left" frame_count="6" frame_rate="10">
<Rect top="192" left="138" />
</animation>
<animation name="walk_up_left" frame_count="6" frame_rate="10">
<Rect top="576" left="138" />
</animation>
<animation name="walk_up_right" frame_count="6" frame_rate="10">
<Rect top="960" left="138" />
</animation>
<animation name="walk_down_right" frame_count="6" frame_rate="10">
<Rect top="1344" left="138" />
</animation>
<gc_entity id="50">
<transform_component>
<Position x="0" y="0" />
<Size x="100" y="100" />
</transform_component>
<renderer src="player">
<Rect height="147" width="138" top="0" left="0" />
<animation name="walk_down_left" frame_count="6" frame_rate="10">
<Rect top="192" left="138" />
</animation>
<animation name="walk_up_left" frame_count="6" frame_rate="10">
<Rect top="576" left="138" />
</animation>
<animation name="walk_up_right" frame_count="6" frame_rate="10">
<Rect top="960" left="138" />
</animation>
<animation name="walk_down_right" frame_count="6" frame_rate="10">
<Rect top="1344" left="138" />
</animation>
<animation name="walk_down" frame_count="6" frame_rate="10">
<Rect top="0" left="138" />
</animation>
<animation name="walk_up" frame_count="6" frame_rate="10">
<Rect top="768" left="138" />
</animation>
<animation name="walk_right" frame_count="6" frame_rate="10">
<Rect top="1152" left="138" />
</animation>
<animation name="walk_left" frame_count="6" frame_rate="10">
<Rect top="384" left="138" />
</animation>
</renderer>
<camerafollow_component/>
<controllable_component />
<keyboard_controller left="16" right="3" up="25" down="18" />
<map_movement />
<map_linker x="1" y="1" solid="false" />
</gc_entity>
</gc_entities>
<animation name="walk_down" frame_count="6" frame_rate="10">
<Rect top="0" left="138" />
</animation>
<animation name="walk_up" frame_count="6" frame_rate="10">
<Rect top="768" left="138" />
</animation>
<animation name="walk_right" frame_count="6" frame_rate="10">
<Rect top="1152" left="138" />
</animation>
<animation name="walk_left" frame_count="6" frame_rate="10">
<Rect top="384" left="138" />
</animation>
</renderer>
<camerafollow_component/>
<controllable_component />
<keyboard_controller left="16" right="3" up="25" down="18" />
<map_movement />
<map_linker x="1" y="1" solid="false" />
</gc_entity>
</gc_entities>
+6 -3
View File
@@ -64,12 +64,15 @@ static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
char *texture = xml_gettmpstring(n, "tile_texture", NULL);
cmp->single_usage = xml_getbool(n, "single_usage", false);
cmp->text = malloc(sizeof(char *) * (count + 1));
cmp->text = malloc(sizeof(struct dialog_line *) * (count + 1));
if (!cmp->text)
return;
n = n->child;
for (int i = 0; n; n = n->next, i++)
cmp->text[i] = xml_getproperty(n, "line");
for (int i = 0; n; n = n->next, i++) {
cmp->text[i] = malloc(sizeof(struct dialog_line));
cmp->text[i]->name = my_strdup(n->name);
cmp->text[i]->text = xml_getproperty(n, "line");
}
cmp->text[count] = NULL;
setup_tile_interactions(cmp, scene, (gc_vector2i){x, y}, texture);
}
+14 -7
View File
@@ -41,20 +41,25 @@ my_strcmp(link->tile->type, "dialog"))
}
bool update_dialog(struct dialog_manager *this, gc_entity *text, \
gc_scene *scene)
gc_entity *name, gc_scene *scene)
{
struct renderer *rend;
if (!text)
if (!text || !name)
return (true);
this->current_text = this->current_dialog->text[this->current_line];
rend = GETCMP(name, renderer);
if (!rend || rend->type != GC_TXTREND || !rend->data)
return (true);
if (this->current_text)
((gc_text *)rend->data)->text = this->current_text->name;
else
((gc_text *)rend->data)->text = NULL;
rend = GETCMP(text, renderer);
if (!rend || rend->type != GC_TXTREND || !rend->data)
return (true);
if (((gc_text *)rend->data)->text)
free(((gc_text *)rend->data)->text);
this->current_text = this->current_dialog->text[this->current_line];
if (this->current_text)
((gc_text *)rend->data)->text = my_strdup(this->current_text);
((gc_text *)rend->data)->text = this->current_text->text;
else
((gc_text *)rend->data)->text = NULL;
this->current_line++;
@@ -67,13 +72,15 @@ static void check_for_dialog(gc_engine *engine, va_list args)
gc_keybindings key = va_arg(args, gc_keybindings);
gc_scene *scene = engine->scene;
gc_entity *entity = scene->get_entity(scene, 50);
gc_entity *holder_name;
if (key != SPACE || !entity)
return;
if (this->dialog_id == -1)
load_dialog(this, engine, entity);
holder_name = scene->get_entity(scene, 1336);
entity = scene->get_entity(scene, 1337);
if (!update_dialog(this, entity, scene))
if (!update_dialog(this, entity, holder_name, scene))
return;
for (gc_list *li = scene->entities; li; li = li->next) {
if (((gc_entity *) li->data)->prefab_id == this->dialog_id)