diff --git a/src/defs.h b/src/defs.h index fbe2e59..fa36d5a 100644 --- a/src/defs.h +++ b/src/defs.h @@ -233,7 +233,6 @@ enum WS_PAUSED, WS_GAME_COMPLETE, WS_OBSERVING, - WS_QUIT, WS_COMPLETE, WS_MISSION_COMPLETE, WS_GAME_OVER diff --git a/src/game/trophies.h b/src/game/trophies.h index 2be82de..54778bf 100644 --- a/src/game/trophies.h +++ b/src/game/trophies.h @@ -39,7 +39,6 @@ extern Texture *getTexture(const char *filename); extern void blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL_Rect *srcRect, int center); extern void saveScreenshot(char *name); extern void drawWidgets(void); -extern char *timeToString(int seconds, int showHours); extern float limit(float i, float low, float high); extern int isControl(int type); extern void clearControl(int type); diff --git a/src/hub/postMission.c b/src/hub/postMission.c index 718f879..30eac94 100644 --- a/src/hub/postMission.c +++ b/src/hub/postMission.c @@ -22,17 +22,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. static void logic(void); static void draw(void); -static void doPostMission(void); static void updateMissionStatus(void); +static int status; void initPostMission(void) { startSectionTransition(); - if (world.state != WS_QUIT) - { - updateMissionStatus(); - } + updateMissionStatus(); app.delegate.logic = logic; app.delegate.draw = draw; @@ -48,7 +45,7 @@ static void updateMissionStatus(void) { if (strcmp(t->key, world.id) == 0) { - t->value.i = getMissionStatus(); + t->value.i = status = getMissionStatus(); return; } } @@ -59,32 +56,22 @@ static void updateMissionStatus(void) game.missionStatusTail = t; STRNCPY(t->key, world.id, MAX_NAME_LENGTH); - t->value.i = getMissionStatus(); + t->value.i = status = getMissionStatus(); + + if (status != MS_INCOMPLETE) + { + saveGame(); + saveWorld(); + } } static void logic(void) { - if (world.state != WS_QUIT) - { - doPostMission(); - } - else - { - doPostMission(); - } + destroyWorld(); + + initHub(); } static void draw(void) { } - -static void doPostMission(void) -{ - saveGame(); - - saveWorld(); - - destroyWorld(); - - initHub(); -} diff --git a/src/test/atlasTest.c b/src/test/atlasTest.c index c10ec7b..68afc7b 100644 --- a/src/test/atlasTest.c +++ b/src/test/atlasTest.c @@ -33,7 +33,7 @@ void initAtlasTest(void) loadGame(); /* - STRNCPY(game.worldId, "", MAX_NAME_LENGTH); + STRNCPY(game.worldId, "beachFront1", MAX_NAME_LENGTH); initWorld(); */ diff --git a/src/test/atlasTest.h b/src/test/atlasTest.h index d3824a0..5faa15d 100644 --- a/src/test/atlasTest.h +++ b/src/test/atlasTest.h @@ -25,3 +25,4 @@ extern void initHub(void); extern void loadGame(void); extern Dev dev; +extern Game game; diff --git a/src/world/hud.c b/src/world/hud.c index cc158bd..25f0e57 100644 --- a/src/world/hud.c +++ b/src/world/hud.c @@ -226,7 +226,7 @@ void drawMissionStatus(void) drawRect(x, (SCREEN_HEIGHT - h) / 2, w, h, 0, 0, 0, 128); drawOutlineRect(x, (SCREEN_HEIGHT - h) / 2, w, h, 255, 255, 255, 200); - drawText(SCREEN_WIDTH / 2, 100, 40, TA_CENTER, colors.white, "OBJECTIVES"); + drawText(SCREEN_WIDTH / 2, 100, 40, TA_CENTER, colors.white, _("Objectives")); y = 180; diff --git a/src/world/world.c b/src/world/world.c index 73925fd..8ac990c 100644 --- a/src/world/world.c +++ b/src/world/world.c @@ -43,6 +43,8 @@ static void stats(void); static void trophies(void); static void quit(void); static void returnFromTrophyStats(void); +static void drawQuit(void); +static void quitMission(void); int getMissionStatus(void); static Texture *background; @@ -94,6 +96,11 @@ void initWorld(void) getWidget("stats", "gamePaused")->action = stats; getWidget("trophies", "gamePaused")->action = trophies; getWidget("quit", "gamePaused")->action = quit; + + getWidget("ok", "stats")->action = returnFromTrophyStats; + getWidget("ok", "trophies")->action = returnFromTrophyStats; + getWidget("ok", "gameQuit")->action = quitMission; + getWidget("cancel", "gameQuit")->action = returnFromTrophyStats; if (world.missionType == MT_BOSS) { @@ -127,24 +134,31 @@ static void logic(void) case WS_START: doWorldStart(); break; + case WS_IN_PROGRESS: doWorldInProgress(); break; + case WS_OBSERVING: doWorldObserving(); break; + case WS_PAUSED: doWorldPaused(); break; + case WS_COMPLETE: doWorldComplete(); break; + case WS_GAME_OVER: doGameOver(); break; + case WS_GAME_COMPLETE: doGameComplete(); break; + default: break; } @@ -195,6 +209,10 @@ static void draw(void) case SHOW_TROPHIES: drawTrophies(); break; + + case SHOW_QUIT: + drawQuit(); + break; } } @@ -361,6 +379,15 @@ static void doWorldInProgress(void) { doTrophies(); + if (app.keyboard[SDL_SCANCODE_ESCAPE]) + { + returnFromTrophyStats(); + } + } + else if (showing == SHOW_QUIT) + { + handleWidgets(); + if (app.keyboard[SDL_SCANCODE_ESCAPE]) { returnFromTrophyStats(); @@ -683,6 +710,42 @@ void observeActivation(Entity *e) } } +void drawQuit(void) +{ + SDL_Rect r; + + drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 128); + + r.w = 650; + r.h = 325; + r.x = (SCREEN_WIDTH / 2) - r.w / 2; + r.y = (SCREEN_HEIGHT / 2) - r.h / 2; + + drawRect(r.x, r.y, r.w, r.h, 0, 0, 0, 192); + + drawOutlineRect(r.x, r.y, r.w, r.h, 200, 200, 200, 255); + + limitTextWidth(r.w - 100); + drawText(SCREEN_WIDTH / 2, r.y + 10, 26, TA_CENTER, colors.white, "Quit and return to hub?"); + + if (world.missionType == MT_TRAINING) + { + drawText(SCREEN_WIDTH / 2, r.y + 65, 26, TA_CENTER, colors.white, "As this is a tutorial mission, you can skip it and move onto the main game."); + } + else if (world.isReturnVisit) + { + drawText(SCREEN_WIDTH / 2, r.y + 65, 26, TA_CENTER, colors.white, "Your progress on this mission will be saved."); + } + else + { + drawText(SCREEN_WIDTH / 2, r.y + 65, 26, TA_CENTER, colors.white, "Warning: if you quit now, you will lose all progress on this level."); + } + + limitTextWidth(0); + + drawWidgets(); +} + void exitRadar(void) { startSectionTransition(); @@ -718,15 +781,25 @@ static void trophies(void) static void quit(void) { + showing = SHOW_QUIT; + showWidgetGroup("gameQuit"); } static void returnFromTrophyStats(void) { - showWidgetGroup("hub"); + showWidgetGroup("gamePaused"); showing = SHOW_WIDGETS; app.keyboard[SDL_SCANCODE_ESCAPE] = 0; } +static void quitMission(void) +{ + resume(); + stopMusic(); + world.state = WS_COMPLETE; + world.missionCompleteTimer = (FPS * 1.5) + 1; +} + void destroyWorld(void) { int i; diff --git a/src/world/world.h b/src/world/world.h index af735f4..3644321 100644 --- a/src/world/world.h +++ b/src/world/world.h @@ -25,7 +25,8 @@ enum SHOW_NONE, SHOW_WIDGETS, SHOW_STATS, - SHOW_TROPHIES + SHOW_TROPHIES, + SHOW_QUIT }; extern Texture *getTexture(const char *filename); @@ -101,6 +102,7 @@ extern void drawStats(void); extern void doStats(void); extern void doTrophies(void); extern void drawTrophies(void); +extern void limitTextWidth(int width); extern App app; extern Colors colors;