Added menu to challenges screen.

This commit is contained in:
Steve 2016-02-29 09:54:03 +00:00
parent 0e159402e9
commit bf7d6dc921
3 changed files with 185 additions and 3 deletions

View File

@ -8,5 +8,45 @@
"y" : 680,
"w" : 250,
"h": 34
},
{
"name" : "resume",
"group" : "challengesMenu",
"type" : "WT_BUTTON",
"text" : "Resume",
"x" : -1,
"y" : 215,
"w" : 200,
"h": 34
},
{
"name" : "stats",
"group" : "challengesMenu",
"type" : "WT_BUTTON",
"text" : "Stats",
"x" : -1,
"y" : 315,
"w" : 200,
"h": 34
},
{
"name" : "options",
"group" : "challengesMenu",
"type" : "WT_BUTTON",
"text" : "Options",
"x" : -1,
"y" : 415,
"w" : 200,
"h": 34
},
{
"name" : "quit",
"group" : "challengesMenu",
"type" : "WT_BUTTON",
"text" : "Return to Title",
"x" : -1,
"y" : 515,
"w" : 200,
"h": 34
}
]

View File

@ -27,12 +27,20 @@ static void drawChallenges(void);
static void updateChallengeMissions(void);
static void doChallenges(void);
static void startChallengeMission(void);
static void drawMenu(void);
static void resume(void);
static void stats(void);
static void options(void);
static void statsOK(void);
static void returnFromOptions(void);
static void quit(void);
static SDL_Texture *background;
static int startIndex;
static Widget *start;
static int completedChallenges;
static int totalChallenges;
static int show;
void initChallengeHome(void)
{
@ -56,12 +64,21 @@ void initChallengeHome(void)
startIndex = 0;
show = SHOW_CHALLENGES;
initBackground();
start = getWidget("start", "challenges");
start->enabled = 0;
start->action = startChallengeMission;
getWidget("resume", "challengesMenu")->action = resume;
getWidget("stats", "challengesMenu")->action = stats;
getWidget("options", "challengesMenu")->action = options;
getWidget("quit", "challengesMenu")->action = quit;
getWidget("ok", "stats")->action = statsOK;
setMouse(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
endSectionTransition();
@ -106,7 +123,21 @@ static void logic(void)
doStars(0.5, 0);
doChallenges();
switch (show)
{
case SHOW_CHALLENGES:
doChallenges();
break;
case SHOW_MENU:
break;
case SHOW_STATS:
break;
case SHOW_OPTIONS:
break;
}
doWidgets();
}
@ -149,7 +180,24 @@ static void draw(void)
drawChallenges();
drawWidgets("challenges");
switch (show)
{
case SHOW_CHALLENGES:
drawWidgets("challenges");
break;
case SHOW_MENU:
drawMenu();
break;
case SHOW_STATS:
drawStats();
break;
case SHOW_OPTIONS:
drawOptions();
break;
}
}
static void drawChallenges(void)
@ -216,11 +264,94 @@ static void drawChallenges(void)
}
}
static void drawMenu(void)
{
SDL_Rect r;
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_BLEND);
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 128);
SDL_RenderFillRect(app.renderer, NULL);
SDL_SetRenderDrawBlendMode(app.renderer, SDL_BLENDMODE_NONE);
r.w = 400;
r.h = 400;
r.x = (SCREEN_WIDTH / 2) - r.w / 2;
r.y = (SCREEN_HEIGHT / 2) - r.h / 2;
SDL_SetRenderDrawColor(app.renderer, 0, 0, 0, 0);
SDL_RenderFillRect(app.renderer, &r);
SDL_SetRenderDrawColor(app.renderer, 200, 200, 200, 255);
SDL_RenderDrawRect(app.renderer, &r);
drawWidgets("challengesMenu");
}
static void resume(void)
{
show = SHOW_CHALLENGES;
}
static void options(void)
{
show = SHOW_OPTIONS;
initOptions(returnFromOptions);
}
static void stats(void)
{
selectWidget("ok", "stats");
show = SHOW_STATS;
initStatsDisplay();
}
static void statsOK(void)
{
selectWidget("resume", "challengesMenu");
show = SHOW_MENU;
}
static void returnFromOptions(void)
{
show = SHOW_MENU;
selectWidget("resume", "challengesMenu");
}
static void quit(void)
{
initTitle();
}
static void handleKeyboard(void)
{
if (app.keyboard[SDL_SCANCODE_ESCAPE])
{
initTitle();
switch (show)
{
case SHOW_CHALLENGES:
selectWidget("resume", "challengesMenu");
show = SHOW_MENU;
playSound(SND_GUI_CLOSE);
break;
case SHOW_MENU:
show = SHOW_CHALLENGES;
break;
case SHOW_OPTIONS:
case SHOW_STATS:
show = SHOW_MENU;
selectWidget("resume", "challengesMenu");
break;
}
playSound(SND_GUI_CLOSE);
memset(app.keyboard, 0, sizeof(int) * MAX_KEYBOARD_KEYS);
}
}

View File

@ -22,6 +22,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define MAX_ITEMS 21
#define SHOW_CHALLENGES 0
#define SHOW_MENU 1
#define SHOW_OPTIONS 2
#define SHOW_STATS 3
extern void startSectionTransition(void);
extern void endSectionTransition(void);
extern void stopMusic(void);
@ -41,6 +46,12 @@ extern int collision(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int
extern Widget *getWidget(const char *name, const char *group);
extern void saveGame(void);
extern void initTitle(void);
extern void initStatsDisplay(void);
extern void drawOptions(void);
extern void initOptions(void (*returnFromOptions)(void));
extern void drawStats(void);
extern void playSound(int sound);
extern void selectWidget(const char *name, const char *group);
extern App app;
extern Battle battle;