2021-08-26 01:17:48 +02:00
|
|
|
#include <gint/display.h>
|
|
|
|
#include <gint/keyboard.h>
|
2022-03-22 23:16:37 +01:00
|
|
|
#include <gint/cpu.h>
|
2021-08-26 01:17:48 +02:00
|
|
|
#include <string.h>
|
2022-03-22 23:16:37 +01:00
|
|
|
#include <ctype.h>
|
2022-04-22 00:32:31 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-08-27 02:11:05 +02:00
|
|
|
|
2021-08-26 01:17:48 +02:00
|
|
|
#include "talkable.h"
|
|
|
|
#include "util.h"
|
2022-04-02 01:57:54 +02:00
|
|
|
#include "event.h"
|
|
|
|
#include "player.h"
|
2022-05-16 23:57:25 +02:00
|
|
|
#include "draw_util.h"
|
2021-08-26 01:17:48 +02:00
|
|
|
|
|
|
|
struct Talkable default_value = {
|
|
|
|
.x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.name = "default name",
|
2022-05-22 23:58:00 +02:00
|
|
|
.text = "default dialog",
|
|
|
|
.text_after = "",
|
|
|
|
.exclusive = 0
|
2021-08-26 01:17:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/*draw the dialog of a specified talkable tile*/
|
2022-04-02 01:57:54 +02:00
|
|
|
void draw_dialog(struct Game *game) {
|
2021-08-26 01:17:48 +02:00
|
|
|
const char *delim = ";";
|
|
|
|
|
2022-04-02 01:57:54 +02:00
|
|
|
int direction = game->player->direction;
|
|
|
|
int dx = (direction == DIR_RIGHT) - (direction == DIR_LEFT);
|
|
|
|
int dy = (direction == DIR_DOWN) - (direction == DIR_UP);
|
|
|
|
struct Talkable *talk = get_dialog_xy(game->map, game->player->pos.x + dx, game->player->pos.y + dy);
|
|
|
|
|
|
|
|
char *str = strdup(talk->text);
|
2022-05-22 23:58:00 +02:00
|
|
|
if(talk->exclusive) {
|
|
|
|
if(check_eventdialog(game->player, talk->id)) {
|
|
|
|
str = strdup(talk->text_after);
|
|
|
|
} else {
|
|
|
|
addDialogToPlayer(game->player, talk->id);
|
|
|
|
}
|
|
|
|
}
|
2021-08-26 01:17:48 +02:00
|
|
|
char *curr_line = strtok(str, delim);
|
|
|
|
|
|
|
|
while(curr_line != NULL) {
|
2022-04-02 01:57:54 +02:00
|
|
|
char *event = strchr(curr_line, '~');
|
|
|
|
if(event) handle_event(game, curr_line+1);
|
|
|
|
else {
|
2022-05-16 23:57:25 +02:00
|
|
|
draw_text(50, 58, C_BLACK, curr_line);
|
2022-04-23 00:47:27 +02:00
|
|
|
dprint(50,40, C_BLACK, "%s", talk->name);
|
2022-01-21 21:40:12 +01:00
|
|
|
|
2022-04-02 01:57:54 +02:00
|
|
|
dupdate();
|
|
|
|
wait_for_input(KEY_SHIFT);
|
|
|
|
}
|
2021-08-26 01:17:48 +02:00
|
|
|
curr_line = strtok(NULL, delim);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*find the talkable tile using the player's position*/
|
|
|
|
struct Talkable* get_dialog_xy(struct Map *map, int x, int y) {
|
|
|
|
int i = 0;
|
|
|
|
while(i < map->dialog_count) {
|
|
|
|
if(map->dialogs[i].x == x && map->dialogs[i].y == y) return &map->dialogs[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return &default_value;
|
2022-05-22 23:58:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void addDialogToPlayer(struct Player *player, int id) {
|
|
|
|
player->eventListDialog[get_nb_eventdialog(player)] = id;
|
2021-08-26 01:17:48 +02:00
|
|
|
}
|