From 533d74447f5bf03f65f10ac60e99d2a14f3b6c06 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Thu, 21 May 2015 18:49:04 -0400 Subject: [PATCH] Made auto-pausing an option. --- src/defs.h | 1 + src/init.cpp | 11 ++++++++--- src/player.cpp | 5 +++-- src/structs.h | 1 + src/title.cpp | 14 ++++++++++++-- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/defs.h b/src/defs.h index df70309..da0c8f3 100644 --- a/src/defs.h +++ b/src/defs.h @@ -273,6 +273,7 @@ enum { TS_SOUND, TS_MUSIC, TS_FULLSCREEN, + TS_AUTOPAUSE, TS_BACK_TO_MAIN_MENU, TS_SAVESLOT_0, TS_SAVESLOT_1, diff --git a/src/init.cpp b/src/init.cpp index 661d0bb..89a2665 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -146,7 +146,10 @@ void initSystem() } char filename[PATH_MAX]; - int fullScreen = 0, useSound = 1, useMusic = 1; + int fullScreen = 0; + int useSound = 1; + int useMusic = 1; + int autoPause = 0; FILE *fp; sprintf(filename, "%sconf", engine.userHomeDirectory); @@ -154,7 +157,7 @@ void initSystem() if (fp != NULL) { - if (fscanf(fp, "%d %d %d", &fullScreen, &useSound, &useMusic) < 3) + if (fscanf(fp, "%d %d %d %d", &fullScreen, &useSound, &useMusic, &autoPause) < 4) printf("Warning: Config file \"%s\" is not correctly formatted\n", filename); fclose(fp); } @@ -162,6 +165,7 @@ void initSystem() engine.fullScreen = fullScreen; engine.useSound = useSound; engine.useMusic = useMusic; + engine.autoPause = autoPause; screen = SDL_CreateRGBSurface(0, screenWidth, screenHeight, 32, 0xff0000, 0xff00, 0xff, 0xff000000); @@ -259,7 +263,8 @@ void cleanUp() fp = fopen(filename, "wb"); if (fp != NULL) { - fprintf(fp, "%d %d %d\n", engine.fullScreen, engine.useSound, engine.useMusic); + fprintf(fp, "%d %d %d %d\n", engine.fullScreen, engine.useSound, + engine.useMusic, engine.autoPause); fclose(fp); } else diff --git a/src/player.cpp b/src/player.cpp index c01748a..188cbe1 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -252,8 +252,9 @@ void getPlayerInput() break; case SDL_WINDOWEVENT: - if(engine.event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) - engine.paused = 1; + if (engine.autoPause && + (engine.event.window.event == SDL_WINDOWEVENT_FOCUS_LOST)) + engine.paused = true; break; } diff --git a/src/structs.h b/src/structs.h index 1c4d76f..58ca24c 100644 --- a/src/structs.h +++ b/src/structs.h @@ -301,6 +301,7 @@ struct Engine { bool useSound; bool useMusic; bool fullScreen; + bool autoPause; char userHomeDirectory[1024]; diff --git a/src/title.cpp b/src/title.cpp index 4bae8c5..b4506b3 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -106,18 +106,24 @@ static void createOptionsMenu() textSurface(TS_FULLSCREEN, "FULLSCREEN - ON", -1, 390, FONT_WHITE); else textSurface(TS_FULLSCREEN, "FULLSCREEN - OFF", -1, 390, FONT_WHITE); + + if (engine.autoPause) + textSurface(TS_AUTOPAUSE, "AUTOPAUSE - ON", -1, 410, FONT_WHITE); + else + textSurface(TS_AUTOPAUSE, "AUTOPAUSE - OFF", -1, 410, FONT_WHITE); } static signed char showOptionsMenu() { - textShape[TS_BACK_TO_MAIN_MENU].y = 430; + textShape[TS_BACK_TO_MAIN_MENU].y = 450; blitText(TS_SOUND); blitText(TS_MUSIC); blitText(TS_FULLSCREEN); + blitText(TS_AUTOPAUSE); blitText(TS_BACK_TO_MAIN_MENU); - return 4; + return 5; } static void createCheatMenu() @@ -480,6 +486,10 @@ int doTitle() (engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)); } + else if (selectedOption == 4) + { + engine.autoPause = !engine.autoPause; + } else if (selectedOption == listLength) { menuType = MENU_MAIN;