Pressing ESCAPE blocks when awaiting widget input.
This commit is contained in:
parent
d2a234839b
commit
f55a4e57c8
|
@ -685,7 +685,7 @@ static void moveToItem(void)
|
|||
{
|
||||
if (self->target->alive == ALIVE_ALIVE)
|
||||
{
|
||||
faceTarget(self->target);
|
||||
faceTarget(self->target);
|
||||
applyFighterThrust();
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ static void drawMenu(void)
|
|||
|
||||
static void handleKeyboard(void)
|
||||
{
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE] && !app.awaitingWidgetInput)
|
||||
{
|
||||
switch (show)
|
||||
{
|
||||
|
|
|
@ -413,7 +413,7 @@ static void quit(void)
|
|||
|
||||
static void handleKeyboard(void)
|
||||
{
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE] && !app.awaitingWidgetInput)
|
||||
{
|
||||
switch (show)
|
||||
{
|
||||
|
|
|
@ -588,7 +588,7 @@ static void fallenOK(void)
|
|||
|
||||
static void handleKeyboard(void)
|
||||
{
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE] && !app.awaitingWidgetInput)
|
||||
{
|
||||
switch (show)
|
||||
{
|
||||
|
|
|
@ -140,6 +140,9 @@ void drawStats(void)
|
|||
|
||||
drawText(SCREEN_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, _("Page %d / %d"), page + 1, (int)maxPages);
|
||||
|
||||
SDL_SetRenderDrawColor(app.renderer, 128, 128, 128, 255);
|
||||
SDL_RenderDrawLine(app.renderer, r.x, 150, r.x + r.w, 150);
|
||||
|
||||
y = 170;
|
||||
|
||||
startIndex = (page * STATS_PER_PAGE);
|
||||
|
@ -171,7 +174,7 @@ void drawStats(void)
|
|||
drawText(r.x + 20, 565, 18, TA_LEFT, colors.white, statDescription[STAT_TIME]);
|
||||
drawText(r.x + r.w - 20, 565, 18, TA_RIGHT, colors.white, timeToString(game.stats[STAT_TIME], 1));
|
||||
|
||||
drawWidgets("stats");
|
||||
drawWidgets("stats");
|
||||
}
|
||||
|
||||
static void nextPage(void)
|
||||
|
|
|
@ -198,16 +198,10 @@ static void drawFighters(void)
|
|||
|
||||
static void handleKeyboard(void)
|
||||
{
|
||||
switch (show)
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE] && !app.awaitingWidgetInput)
|
||||
{
|
||||
case SHOW_STATS:
|
||||
returnFromOptions();
|
||||
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
|
||||
playSound(SND_GUI_CLOSE);
|
||||
break;
|
||||
|
||||
case SHOW_OPTIONS:
|
||||
break;
|
||||
returnFromOptions();
|
||||
playSound(SND_GUI_CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -423,6 +423,7 @@ typedef struct {
|
|||
SDL_Window *window;
|
||||
Delegate delegate;
|
||||
ModalDialog modalDialog;
|
||||
int awaitingWidgetInput;
|
||||
int lastKeyPressed;
|
||||
int lastButtonPressed;
|
||||
int keyControls[CONTROL_MAX];
|
||||
|
|
|
@ -151,7 +151,7 @@ void drawControls(void)
|
|||
|
||||
for (i = 0 ; i < CONTROL_MAX ; i++)
|
||||
{
|
||||
drawText(r.x, r.y, 20, TA_LEFT, colors.white, controlName[i]);
|
||||
drawText(r.x, r.y + 2, 20, TA_LEFT, colors.white, controlName[i]);
|
||||
|
||||
controlWidget[i]->rect.x = r.x + 175;
|
||||
controlWidget[i]->rect.y = r.y;
|
||||
|
|
|
@ -104,17 +104,9 @@ void drawMouse(void)
|
|||
void clearInput(void)
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < MAX_KEYBOARD_KEYS ; i++)
|
||||
{
|
||||
app.keyboard[i] = 0;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < MAX_MOUSE_BUTTONS ; i++)
|
||||
{
|
||||
app.mouse.button[i] = 0;
|
||||
}
|
||||
|
||||
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
|
||||
memset(app.mouse.button, 0, sizeof(int) * MAX_MOUSE_BUTTONS);
|
||||
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
|
|
|
@ -35,7 +35,6 @@ static Widget *selectedWidget;
|
|||
static SDL_Texture *optionsLeft;
|
||||
static SDL_Texture *optionsRight;
|
||||
static int drawingWidgets;
|
||||
static int waitingForInput;
|
||||
|
||||
void initWidgets(void)
|
||||
{
|
||||
|
@ -50,7 +49,7 @@ void initWidgets(void)
|
|||
|
||||
loadWidgets();
|
||||
|
||||
waitingForInput = drawingWidgets = 0;
|
||||
app.awaitingWidgetInput = drawingWidgets = 0;
|
||||
}
|
||||
|
||||
void doWidgets(void)
|
||||
|
@ -61,7 +60,7 @@ void doWidgets(void)
|
|||
|
||||
handleKeyboard();
|
||||
|
||||
if (waitingForInput)
|
||||
if (app.awaitingWidgetInput)
|
||||
{
|
||||
handleControlWidgets();
|
||||
}
|
||||
|
@ -104,7 +103,7 @@ void drawWidgets(const char *group)
|
|||
{
|
||||
if ((app.modalDialog.type == MD_NONE || (app.modalDialog.type != MD_NONE && w->isModal)) && w->visible && strcmp(w->group, group) == 0)
|
||||
{
|
||||
if (!mouseOver && !waitingForInput)
|
||||
if (!mouseOver && !app.awaitingWidgetInput)
|
||||
{
|
||||
mouseOver = (w->type != WT_SELECT && w->enabled && collision(w->rect.x, w->rect.y, w->rect.w, w->rect.h, app.mouse.x, app.mouse.y, 1, 1));
|
||||
|
||||
|
@ -157,7 +156,7 @@ void drawWidgets(const char *group)
|
|||
case WT_CONTROL_CONFIG:
|
||||
SDL_RenderDrawRect(app.renderer, &w->rect);
|
||||
|
||||
if (!waitingForInput || (waitingForInput && w != selectedWidget))
|
||||
if (!app.awaitingWidgetInput || (app.awaitingWidgetInput && w != selectedWidget))
|
||||
{
|
||||
if (strlen(w->options[0]) && strlen(w->options[1]))
|
||||
{
|
||||
|
@ -259,9 +258,9 @@ static void handleMouse(void)
|
|||
break;
|
||||
|
||||
case WT_CONTROL_CONFIG:
|
||||
if (!waitingForInput)
|
||||
if (!app.awaitingWidgetInput)
|
||||
{
|
||||
waitingForInput = 1;
|
||||
app.awaitingWidgetInput = 1;
|
||||
app.lastKeyPressed = app.lastButtonPressed = -1;
|
||||
}
|
||||
app.mouse.button[SDL_BUTTON_LEFT] = 0;
|
||||
|
@ -302,11 +301,11 @@ static void handleControlWidgets(void)
|
|||
{
|
||||
clearControlConfig(selectedWidget->name);
|
||||
|
||||
waitingForInput = 0;
|
||||
app.awaitingWidgetInput = 0;
|
||||
}
|
||||
else if (app.lastKeyPressed == SDL_SCANCODE_ESCAPE)
|
||||
{
|
||||
waitingForInput = 0;
|
||||
app.awaitingWidgetInput = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -314,18 +313,18 @@ static void handleControlWidgets(void)
|
|||
{
|
||||
updateControlKey(selectedWidget->name);
|
||||
|
||||
waitingForInput = 0;
|
||||
app.awaitingWidgetInput = 0;
|
||||
}
|
||||
|
||||
if (app.lastButtonPressed != -1)
|
||||
{
|
||||
updateControlButton(selectedWidget->name);
|
||||
|
||||
waitingForInput = 0;
|
||||
app.awaitingWidgetInput = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!waitingForInput)
|
||||
if (!app.awaitingWidgetInput)
|
||||
{
|
||||
clearInput();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue