2015-10-20 13:51:49 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2015 Parallel Realities
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stats.h"
|
|
|
|
|
2015-11-26 09:16:29 +01:00
|
|
|
static void prevPage(void);
|
|
|
|
static void nextPage(void);
|
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
static char *statDescription[] = {
|
|
|
|
"Missions Started",
|
|
|
|
"Missons Completed",
|
|
|
|
"Shots Fired",
|
|
|
|
"Shots Hit",
|
|
|
|
"Missiles Fired",
|
|
|
|
"Missiles Hit",
|
|
|
|
"Enemies Killed",
|
|
|
|
"Enemies Killed (Player)",
|
|
|
|
"Allies Killed",
|
|
|
|
"Times Killed",
|
|
|
|
"Enemies Disabled",
|
2015-10-29 17:18:41 +01:00
|
|
|
"Enemies Escaped",
|
2015-11-17 08:23:50 +01:00
|
|
|
"ECM Used",
|
|
|
|
"Boost Used",
|
|
|
|
"Missiles Evaded",
|
|
|
|
"Missiles Struck Player",
|
|
|
|
"Civilians Rescued",
|
|
|
|
"Civilians Killed",
|
|
|
|
"Times used Tug",
|
|
|
|
"Times used Shuttle",
|
|
|
|
"Craft Towed",
|
|
|
|
"Items Collected",
|
|
|
|
"Longest Epic Kill Streak",
|
2015-10-25 01:01:46 +02:00
|
|
|
"STAT_TIME"
|
|
|
|
};
|
|
|
|
|
|
|
|
static int page;
|
|
|
|
static int maxPages;
|
2015-11-26 09:16:29 +01:00
|
|
|
static Widget *prev;
|
|
|
|
static Widget *next;
|
2015-10-25 01:01:46 +02:00
|
|
|
|
|
|
|
void initStatsDisplay(void)
|
|
|
|
{
|
|
|
|
page = 0;
|
|
|
|
maxPages = (STAT_MAX / MAX_STAT_ITEMS);
|
|
|
|
|
2015-11-26 09:16:29 +01:00
|
|
|
prev = getWidget("prev", "stats");
|
|
|
|
prev->action = prevPage;
|
2015-11-24 23:33:25 +01:00
|
|
|
|
2015-11-26 09:16:29 +01:00
|
|
|
next = getWidget("next", "stats");
|
|
|
|
next->action = nextPage;
|
2015-10-25 01:01:46 +02:00
|
|
|
}
|
|
|
|
|
2015-10-20 13:51:49 +02:00
|
|
|
void drawStats(void)
|
|
|
|
{
|
2015-10-25 01:01:46 +02:00
|
|
|
int i, y, hours, minutes, seconds, startIndex;
|
2015-10-20 13:51:49 +02:00
|
|
|
SDL_Rect r;
|
|
|
|
char timePlayed[MAX_NAME_LENGTH];
|
|
|
|
|
|
|
|
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 = 500;
|
|
|
|
r.h = 600;
|
|
|
|
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);
|
|
|
|
|
|
|
|
drawText(SCREEN_WIDTH / 2, 70, 28, TA_CENTER, colors.white, "Stats");
|
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
drawText(SCREEN_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, "Page %d / %d", page + 1, maxPages + 1);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
y = 170;
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
startIndex = (page * MAX_STAT_ITEMS);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
for (i = startIndex ; i < startIndex + MAX_STAT_ITEMS ; i++)
|
|
|
|
{
|
|
|
|
if (i < STAT_TIME)
|
|
|
|
{
|
|
|
|
drawText(r.x + 20, y, 18, TA_LEFT, colors.white, statDescription[i]);
|
|
|
|
drawText(r.x + r.w - 20, y, 18, TA_RIGHT, colors.white, "%d", game.stats[i]);
|
|
|
|
y += 40;
|
|
|
|
}
|
|
|
|
}
|
2015-10-20 13:51:49 +02:00
|
|
|
|
2015-10-25 01:01:46 +02:00
|
|
|
seconds = game.stats[STAT_TIME] / FPS;
|
2015-10-20 13:51:49 +02:00
|
|
|
minutes = (seconds / 60) % 60;
|
|
|
|
hours = seconds / (60 * 60);
|
|
|
|
|
|
|
|
seconds %= 60;
|
|
|
|
|
|
|
|
sprintf(timePlayed, "%dh:%02dm:%02ds", hours, minutes, seconds);
|
2015-10-25 01:01:46 +02:00
|
|
|
drawText(r.x + 20, 565, 18, TA_LEFT, colors.white, "Time Played");
|
|
|
|
drawText(r.x + r.w - 20, 565, 18, TA_RIGHT, colors.white, timePlayed);
|
2015-10-20 13:51:49 +02:00
|
|
|
|
|
|
|
drawWidgets("stats");
|
|
|
|
}
|
2015-11-26 09:16:29 +01:00
|
|
|
|
|
|
|
static void nextPage(void)
|
|
|
|
{
|
|
|
|
page = MIN(page + 1, maxPages);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prevPage(void)
|
|
|
|
{
|
|
|
|
page = MAX(0, page - 1);
|
|
|
|
}
|