#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Adafruit_ILI9341.h>
#include <Wire.h>
#include <Adafruit_FT6206.h>
#include <EEPROM.h>

#define TFT_CS 10
#define TFT_DC 9
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);

/*#define TFT_DC 40
#define TFT_CS 36
#define TFT_RST 38
#define TFT_MOSI 51
#define TFT_MISO 50
#define TFT_CLK 52

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);*/
Adafruit_FT6206 ctp = Adafruit_FT6206();

#define DEBUG

// Size of the color selection boxes and the paintbrush size
#define BUTTON_HEIGHT 40
#define CORNER_RADIUS 10
#define TEXT_SIZE 2
#define TEXT_LOWER_LIMIT 160
#define MESSAGES_SPACING 10
boolean was_touched = false;
boolean buttons_available = false;
int reputation = 10;

#define MESSAGE dialogs[index]
#define HEIGHT (int)dialogs[index+1]
#define OPTIONA dialogs[index+2]
#define OPTIONB dialogs[index+3]
#define OPTIONC dialogs[index+4]
#define NEXTA (int)dialogs[index+5]
#define NEXTB (int)dialogs[index+6]
#define NEXTC (int)dialogs[index+7]
#define IMAGE (int)dialogs[index+8]
#define SIDE (int)dialogs[index+9]
#define TIMER (int)dialogs[index+10]
#define TIMEOUT (int)dialogs[index+11]
#define FAME (int)dialogs[index+12]
#define DATA_LENGHT 13

#define NARRATEUR 0
#define JOUEUR 1
#define IA 2

#define ENDPOINT_INDEX 2

int possible_endpoints[] = {0,1,2,3};
// max pages : 253 (l'octet d'autosave va pas aimer sinon)
char *dialogs[] = {
//message, hauteur du message (en lignes) optionA, optionB, optionC, renvoi optionA, renvoi optionB, renvoi optionC, image, coté, timer, timeout, fame impact

"  Previous Save \n  detected, would\n    you like to\n    use it ?",4,"\n     NO","","\n                                YES",1,-1,1,-1,NARRATEUR,0,0,0,
"      Dany \n       and \n     Jonathan \n    present ...",4,"","","",-1,-1,-1,-1,NARRATEUR,3,2,0,
"\n     Hero  Path",4,"","","",-1,-1,-1,-1,NARRATEUR,3,3,0,
"",12,"","","",-1,-1,-1,-1,NARRATEUR,1,4,0,
"  BEEP BEEP BEEP",1,"",""," Wake up",-1,-1,5,-1,NARRATEUR,0,0,0, // image d'un réveil
"  Ah $£IT, here\n  we go again ...",2,"","","Go to work",-1,-1,6,2,JOUEUR,0,0,0, // image de quelqu'un qui sort d'un lit
"",12,"","","",-1,-1,-1,0,NARRATEUR,1,7,0,
" Whoopsy, he died !",1,"","","    F",-1,-1,8,-1,JOUEUR,0,0,-8,
"",12,"","","",-1,-1,-1,0,NARRATEUR,1,9,0,
" Thank you for\n  for your service",2,"","","",-1,-1,-1,3,IA,0,0,13,
" Unfortunately, due\n  to a little\n  restructuring of\n  the company, your\n  position has\n  been terminated",6,"","","",-1,-1,-1,-1,IA,0,0,-8,
" yeah",1,"","","",-1,-1,-1,0,JOUEUR,3,4,0,
" yup , it all\n  comes  to\n  this afterall ...",3,"optionA","optionB","optionC",1,2,3,5,IA,0,0,-1,
" yeah",1,"optionA","optionB","optionC",1,2,3,5,NARRATEUR,0,0,-1,

"error"
};

//"",height,"","","",renvoi,renvoi,renvoi,image,perso,timer,timout,fame