Implemented input handling for scenes (skip, fullscreen, quit), and pulled input handling for textboxes out into its own function

This commit is contained in:
Iris Lightshard 2018-09-24 13:47:46 -07:00
parent 8b1e4cafdf
commit bff466bba7
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398
4 changed files with 98 additions and 54 deletions

36
Scene.c
View file

@ -68,6 +68,41 @@ void buildScene(Scene* self, SLayer* sprite)
self->nSprites++; self->nSprites++;
} }
void sceneInput(Scene* self, int* counter)
{
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
switch (event.key.keysym.sym)
{
case SDLK_j:
*counter = self->time - 1;
break;
case SDLK_f:
toggleFullscreen();
break;
default: break;
}
break;
case SDL_QUIT:
if (playing)
{
playing = 0;
quit = 1;
}
else
{
*counter = self->time - 1;
playing = 0;
quit = 1;
}
break;
}
}
}
void playScene(Scene* self) void playScene(Scene* self)
{ {
int i, j; int i, j;
@ -88,6 +123,7 @@ void playScene(Scene* self)
for (i = 0; i < self->time; i++) for (i = 0; i < self->time; i++)
{ {
timeStart(fps); timeStart(fps);
sceneInput(self, &i);
for (j = 0; j < self->nSprites; j++) for (j = 0; j < self->nSprites; j++)
{ {
applySurface(self->sprites[j]->x, self->sprites[j]->y, self->sprites[j]->sprite, screen, NULL); applySurface(self->sprites[j]->x, self->sprites[j]->y, self->sprites[j]->sprite, screen, NULL);

View file

@ -27,4 +27,5 @@ void deleteSLayer(SLayer* target);
Scene* newScene(int in, int out, int time, SDL_Color incolor, SDL_Color outcolor); Scene* newScene(int in, int out, int time, SDL_Color incolor, SDL_Color outcolor);
void buildScene(Scene* self, SLayer* sprite); void buildScene(Scene* self, SLayer* sprite);
void playScene(Scene* self); void playScene(Scene* self);
void sceneInput(Scene* self, int* counter);
void deleteScene(Scene* target); void deleteScene(Scene* target);

114
TextBox.c
View file

@ -64,6 +64,65 @@ void addText(TextBox* self, char* text)
self->lines++; self->lines++;
} }
void textBoxInput(TextBox* self, int* textIsRelevent)
{
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;
}
}
}
}
}
void displayTextBox(TextBox* self) void displayTextBox(TextBox* self)
{ {
int textIsRelevent = 1; int textIsRelevent = 1;
@ -92,61 +151,8 @@ void displayTextBox(TextBox* self)
textScroller.w = self->cursor*10; textScroller.w = self->cursor*10;
applySurface(106 + offset, 64+(14*(self->scroll%4)), self->message[self->scroll], screen, &textScroller); applySurface(106 + offset, 64+(14*(self->scroll%4)), self->message[self->scroll], screen, &textScroller);
if (self->cursor != 17) textBoxInput(self, &textIsRelevent);
{
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); SDL_Flip(screen);
timeDilation(); timeDilation();

View file

@ -15,3 +15,4 @@ void deleteTextBox(TextBox* target);
void addText(TextBox* self, char* text); void addText(TextBox* self, char* text);
void displayTextBox(TextBox* self); void displayTextBox(TextBox* self);
void textBoxInput(TextBox* self, int* textIsRelevent);