Implemented mission quit option.

This commit is contained in:
Steve 2018-02-20 08:14:35 +00:00
parent edde9fac2f
commit e745a287f4
8 changed files with 93 additions and 32 deletions

View File

@ -233,7 +233,6 @@ enum
WS_PAUSED,
WS_GAME_COMPLETE,
WS_OBSERVING,
WS_QUIT,
WS_COMPLETE,
WS_MISSION_COMPLETE,
WS_GAME_OVER

View File

@ -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);

View File

@ -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();
}

View File

@ -33,7 +33,7 @@ void initAtlasTest(void)
loadGame();
/*
STRNCPY(game.worldId, "", MAX_NAME_LENGTH);
STRNCPY(game.worldId, "beachFront1", MAX_NAME_LENGTH);
initWorld();
*/

View File

@ -25,3 +25,4 @@ extern void initHub(void);
extern void loadGame(void);
extern Dev dev;
extern Game game;

View File

@ -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;

View File

@ -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;

View File

@ -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;