Implemented input handling for scenes (skip, fullscreen, quit), and pulled input handling for textboxes out into its own function
This commit is contained in:
parent
8b1e4cafdf
commit
bff466bba7
4 changed files with 98 additions and 54 deletions
36
Scene.c
36
Scene.c
|
@ -68,6 +68,41 @@ void buildScene(Scene* self, SLayer* sprite)
|
|||
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)
|
||||
{
|
||||
int i, j;
|
||||
|
@ -88,6 +123,7 @@ void playScene(Scene* self)
|
|||
for (i = 0; i < self->time; i++)
|
||||
{
|
||||
timeStart(fps);
|
||||
sceneInput(self, &i);
|
||||
for (j = 0; j < self->nSprites; j++)
|
||||
{
|
||||
applySurface(self->sprites[j]->x, self->sprites[j]->y, self->sprites[j]->sprite, screen, NULL);
|
||||
|
|
1
Scene.h
1
Scene.h
|
@ -27,4 +27,5 @@ void deleteSLayer(SLayer* target);
|
|||
Scene* newScene(int in, int out, int time, SDL_Color incolor, SDL_Color outcolor);
|
||||
void buildScene(Scene* self, SLayer* sprite);
|
||||
void playScene(Scene* self);
|
||||
void sceneInput(Scene* self, int* counter);
|
||||
void deleteScene(Scene* target);
|
114
TextBox.c
114
TextBox.c
|
@ -64,6 +64,65 @@ void addText(TextBox* self, char* text)
|
|||
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)
|
||||
{
|
||||
int textIsRelevent = 1;
|
||||
|
@ -92,61 +151,8 @@ void displayTextBox(TextBox* self)
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
textBoxInput(self, &textIsRelevent);
|
||||
|
||||
|
||||
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();
|
||||
|
||||
|
|
|
@ -15,3 +15,4 @@ void deleteTextBox(TextBox* target);
|
|||
|
||||
void addText(TextBox* self, char* text);
|
||||
void displayTextBox(TextBox* self);
|
||||
void textBoxInput(TextBox* self, int* textIsRelevent);
|
||||
|
|
Loading…
Reference in a new issue