mirror of
https://github.com/zoriya/ForecastingVillage.git
synced 2026-06-03 19:01:20 +00:00
Adding a method to add dialog lines
This commit is contained in:
+1
-1
@@ -289,7 +289,7 @@ add_executable(my_rpg
|
||||
include/systems/combat_manager.h
|
||||
src/components/player_component.c
|
||||
include/components/player_component.h
|
||||
src/enemy_dataloader.c include/enemy.h)
|
||||
src/enemy_dataloader.c include/enemy.h src/components/combat_holder.c include/components/combat_holder.h src/components/dialog_methods.c)
|
||||
|
||||
add_compile_options(-W -Wall -Wextra -Wshadow)
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** combat_holder.h
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MY_RPG_COMBAT_HOLDER_H
|
||||
#define MY_RPG_COMBAT_HOLDER_H
|
||||
|
||||
#include "component.h"
|
||||
|
||||
enum combat_state
|
||||
{
|
||||
STARTUP,
|
||||
IDLE
|
||||
};
|
||||
|
||||
struct combat_holder
|
||||
{
|
||||
gc_component base;
|
||||
enum combat_state state;
|
||||
char *name;
|
||||
};
|
||||
|
||||
extern const struct combat_holder combat_holder;
|
||||
|
||||
#endif //MY_RPG_COMBAT_HOLDER_H
|
||||
@@ -45,5 +45,7 @@ struct dialog_manager {
|
||||
const struct dialog_manager dialog_manager;
|
||||
|
||||
void dialog_next(gc_engine *engine);
|
||||
void dialog_add_line(struct dialog_holder *this, char *name, char *text, \
|
||||
struct dialog_input *inputs);
|
||||
|
||||
#endif //MY_RPG_DIALOG_HOLDER_H
|
||||
|
||||
+1
-1
Submodule lib/xmlparser updated: ad2bcc9a66...828f4170b8
@@ -19,13 +19,7 @@
|
||||
|
||||
<gc_entity>
|
||||
<dialog_holder x="0" y="0" tile_texture="dirt_top_1">
|
||||
<??? line="Hello dirt block,\nI am the mighty cobble block.">
|
||||
<input text="Yes" click="super" />
|
||||
<input text="No" click="super" />
|
||||
<input text="Maybe" click="super" />
|
||||
<input text="Run away" click="super" />
|
||||
</???>
|
||||
<Cobble_block line="Can I do something\n for you?" />
|
||||
<Fight line="An enemy appeared." />
|
||||
</dialog_holder>
|
||||
</gc_entity>
|
||||
|
||||
|
||||
@@ -8,5 +8,7 @@
|
||||
<Rect height="auto" width="auto" top="0" left="0" />
|
||||
</renderer>
|
||||
<fixed_to_cam x="75%" y="20%" />
|
||||
<combat_holder name="bee">
|
||||
</combat_holder>
|
||||
</gc_entity>
|
||||
</gc_entities>
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** combat_holder.c
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "components/combat_holder.h"
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct combat_holder *cmp = component;
|
||||
|
||||
cmp->state = STARTUP;
|
||||
cmp->name = va_arg(args, char *);
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, \
|
||||
void *component, node *n)
|
||||
{
|
||||
struct combat_holder *cmp = component;
|
||||
|
||||
cmp->name = xml_getproperty(n, "name");
|
||||
}
|
||||
|
||||
static void dtr(void *component)
|
||||
{
|
||||
(void)component;
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct combat_holder combat_holder = {
|
||||
base: {
|
||||
name: "combat_holder",
|
||||
size: sizeof(struct combat_holder),
|
||||
dependencies: (char *[]){
|
||||
NULL
|
||||
},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: &dtr,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** dialog_methods.c
|
||||
*/
|
||||
|
||||
#include "components/dialog_holder.h"
|
||||
#include "utility.h"
|
||||
#include <malloc.h>
|
||||
|
||||
void dialog_add_line(struct dialog_holder *this, char *name, char *text, \
|
||||
struct dialog_input *inputs)
|
||||
{
|
||||
struct dialog_line *line = malloc(sizeof(*line));
|
||||
int count = 0;
|
||||
|
||||
if (!line)
|
||||
return;
|
||||
line->name = name;
|
||||
line->text = text;
|
||||
if (inputs)
|
||||
for (count = 0; &inputs[count]; count++);
|
||||
line->input_count = count;
|
||||
line->inputs = inputs;
|
||||
for (count = 0; this->text[count]; count++);
|
||||
this->text = my_realloc(this->text, count, count + sizeof(void *));
|
||||
if (!this->text)
|
||||
return;
|
||||
this->text[count] = line;
|
||||
this->text[count + 1] = NULL;
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <components/health_component.h>
|
||||
#include <components/player_component.h>
|
||||
#include <systems/combat_manager.h>
|
||||
#include <components/combat_holder.h>
|
||||
#include "systems/map_movement_system.h"
|
||||
#include "systems/game_manager_system.h"
|
||||
#include "systems/controllers/keyboard_controller_system.h"
|
||||
@@ -75,6 +76,7 @@ int register_customcmps(gc_engine *engine, bool map_editor)
|
||||
engine->add_system(engine, &game_display_system);
|
||||
engine->add_component(engine, &xp_component);
|
||||
engine->add_component(engine, &player_component);
|
||||
engine->add_component(engine, &combat_holder);
|
||||
engine->add_system(engine, new_system(&combat_manager, engine));
|
||||
engine->finish_physics(engine);
|
||||
engine->add_dataloader(engine, "enemies", &enemies_dataloader);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "engine.h"
|
||||
#include "my.h"
|
||||
#include "components/dialog_holder.h"
|
||||
#include "components/combat_holder.h"
|
||||
#include "enemy.h"
|
||||
|
||||
void combat_start(gc_engine *engine, char *enemy_name)
|
||||
@@ -58,6 +59,22 @@ void entity_moved(gc_engine *engine, va_list args)
|
||||
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
|
||||
float dtime)
|
||||
{
|
||||
struct combat_holder *cmp = GETCMP(entity, combat_holder);
|
||||
gc_scene *scene = engine->scene;
|
||||
gc_list *li = scene->get_entity_by_cmp(scene, "dialog_holder");
|
||||
struct dialog_holder *dialog;
|
||||
|
||||
if (!li)
|
||||
return;
|
||||
dialog = GETCMP(li->data, dialog_holder);
|
||||
switch (cmp->state) {
|
||||
case STARTUP:
|
||||
dialog_add_line(dialog, NULL, "A bee has appeared.", NULL);
|
||||
cmp->state = IDLE;
|
||||
break;
|
||||
case IDLE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void ctr(void *system, va_list list)
|
||||
@@ -79,7 +96,7 @@ static void dtr(void *system, gc_engine *engine)
|
||||
const struct combat_manager combat_manager = {
|
||||
base: {
|
||||
name: "combat_manager",
|
||||
component_name: "player_component",
|
||||
component_name: "combat_holder",
|
||||
size: sizeof(struct combat_manager),
|
||||
ctr: &ctr,
|
||||
dtr: &dtr,
|
||||
|
||||
Reference in New Issue
Block a user