2018-09-20 01:27:47 +00:00
|
|
|
#include "SDL/SDL.h"
|
|
|
|
#include "SDL/SDL_image.h"
|
|
|
|
#include "SDL/SDL_ttf.h"
|
|
|
|
#include "SDL/SDL_mixer.h"
|
|
|
|
#include "Engine.h"
|
|
|
|
#include "Timer.h"
|
|
|
|
#include "Player.h"
|
|
|
|
#include "TextBox.h"
|
|
|
|
|
2018-09-24 18:41:09 +00:00
|
|
|
typedef struct room Room;
|
|
|
|
typedef struct kaos Kaos;
|
|
|
|
typedef struct scene Scene;
|
2018-09-20 01:27:47 +00:00
|
|
|
|
2018-09-24 18:41:09 +00:00
|
|
|
#include "extern.h"
|
2018-09-20 01:27:47 +00:00
|
|
|
|
|
|
|
TextBox* newTextBox()
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
TextBox* self = malloc(sizeof(TextBox));
|
2018-09-20 01:27:47 +00:00
|
|
|
self->portrait = NULL;
|
2018-09-21 19:57:07 +00:00
|
|
|
self->message = malloc(4*sizeof(SDL_Surface*));
|
2018-09-20 01:27:47 +00:00
|
|
|
self->lines = 0;
|
|
|
|
self->cursor = 0;
|
|
|
|
self->scroll = 0;
|
|
|
|
self->scrollFrom = 0;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
TextBox* newGTextBox(SDL_Surface* image)
|
|
|
|
{
|
2018-09-21 19:57:07 +00:00
|
|
|
TextBox* self = malloc(sizeof(TextBox));
|
2018-09-20 01:27:47 +00:00
|
|
|
self->portrait = image;
|
2018-09-21 19:57:07 +00:00
|
|
|
self->message = malloc(4*sizeof(SDL_Surface*));
|
2018-09-20 01:27:47 +00:00
|
|
|
self->lines = 0;
|
|
|
|
self->cursor = 0;
|
|
|
|
self->scroll = 0;
|
|
|
|
self->scrollFrom = 0;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void deleteTextBox(TextBox* target)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (target->portrait) SDL_FreeSurface(target->portrait);
|
|
|
|
for (i = 0; i < target->lines; i++)
|
|
|
|
{
|
|
|
|
SDL_FreeSurface(target->message[i]);
|
|
|
|
}
|
|
|
|
free(target->message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addText(TextBox* self, char* text)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if ( self->lines != 0 && self->lines%4 == 0)
|
|
|
|
{
|
|
|
|
SDL_Surface** templines = (SDL_Surface**)malloc((self->lines+4)*sizeof(SDL_Surface*));
|
|
|
|
for (i = 0; i < self->lines; i++)
|
|
|
|
templines[i] = self->message[i];
|
|
|
|
free(self->message);
|
|
|
|
self->message = templines;
|
|
|
|
templines = NULL;
|
|
|
|
}
|
|
|
|
self->message[self->lines] = TTF_RenderText_Solid(font, text, textColor);
|
|
|
|
self->lines++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void displayTextBox(TextBox* self)
|
|
|
|
{
|
|
|
|
int textIsRelevent = 1;
|
|
|
|
int offset = -32;
|
|
|
|
int i;
|
|
|
|
SDL_Rect textScroller = {0, 0, 0, 14};
|
|
|
|
actionbutton = 0;
|
|
|
|
while (textIsRelevent)
|
|
|
|
{
|
|
|
|
timeStart(fps);
|
|
|
|
renderBackground();
|
|
|
|
renderForeground();
|
|
|
|
|
|
|
|
applySurface(22, 51, textBoxBG, screen, NULL);
|
|
|
|
if (self->portrait)
|
|
|
|
{
|
|
|
|
applySurface(32, 58, self->portrait, screen, NULL);
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = self->scrollFrom; i < self->scroll; i++)
|
|
|
|
{
|
|
|
|
applySurface(106 + offset, 64+(14*(i%4)), self->message[i], screen, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
textScroller.w = self->cursor*10;
|
|
|
|
applySurface(106 + offset, 64+(14*(self->scroll%4)), self->message[self->scroll], screen, &textScroller);
|
|
|
|
|
|
|
|
if (self->cursor != 17)
|
|
|
|
{
|
|
|
|
self->cursor++;
|
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT: quit=1; playing = 0; textIsRelevent = 0; break;
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch (event.key.keysym.sym)
|
|
|
|
{
|
|
|
|
case SDLK_j:
|
|
|
|
if (self->cursor < 15) self->cursor += 3;
|
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (self->cursor == 17 && self->scroll+1 != self->lines && (self->scroll+1)%4 != 0)
|
|
|
|
{
|
|
|
|
self->cursor = 0;
|
|
|
|
self->scroll++;
|
|
|
|
}
|
|
|
|
if (self->cursor == 17 && ((self->scroll+1)%4 == 0 || self->scroll+1 == self->lines))
|
|
|
|
{
|
|
|
|
applySurface(274, 120, nextArrow, screen, NULL);
|
|
|
|
while (SDL_PollEvent(&event))
|
|
|
|
{
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case SDL_QUIT: quit = 1; playing = 0; textIsRelevent = 0; break;
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch (event.key.keysym.sym)
|
|
|
|
{
|
|
|
|
case SDLK_j:
|
|
|
|
if (self->scroll + 1 != self->lines)
|
|
|
|
{
|
|
|
|
self->cursor = 0;
|
|
|
|
self->scroll++;
|
|
|
|
self->scrollFrom += 4;
|
|
|
|
}
|
|
|
|
else textIsRelevent = 0;
|
|
|
|
break;
|
|
|
|
case SDLK_f:
|
|
|
|
toggleFullscreen();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SDL_Flip(screen);
|
|
|
|
timeDilation();
|
|
|
|
|
|
|
|
}
|
|
|
|
self->scroll = 0;
|
|
|
|
self->cursor = 0;
|
|
|
|
self->scrollFrom = 0;
|
|
|
|
}
|