tbftss/src/galaxy/stats.c

134 lines
3.2 KiB
C
Raw Normal View History

2015-10-20 13:51:49 +02:00
/*
2016-02-21 16:50:27 +01:00
Copyright (C) 2015-2016 Parallel Realities
2015-10-20 13:51:49 +02:00
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);
static char *statDescription[] = {
"Missions Started",
"Missons Completed",
"Shots Fired",
"Shots Hit",
"Rockets Fired",
"Rockets 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-12-19 17:15:57 +01:00
"Capital Ships Destroyed",
"Capital Ships Lost",
"STAT_TIME"
};
static int page;
static int maxPages;
2015-11-26 09:16:29 +01:00
static Widget *prev;
static Widget *next;
void initStatsDisplay(void)
{
page = 0;
2015-12-23 20:22:31 +01:00
maxPages = ceil(STAT_TIME / MAX_STAT_ITEMS);
2015-11-26 09:16:29 +01:00
prev = getWidget("prev", "stats");
prev->action = prevPage;
2015-12-23 20:22:31 +01:00
prev->visible = 0;
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-20 13:51:49 +02:00
void drawStats(void)
{
2016-02-28 14:02:57 +01:00
int i, y, startIndex;
2015-10-20 13:51:49 +02:00
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 = 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-20 13:51:49 +02:00
drawText(SCREEN_WIDTH / 2, 110, 16, TA_CENTER, colors.lightGrey, _("Page %d / %d"), page + 1, maxPages);
2015-10-20 13:51:49 +02:00
y = 170;
2015-10-20 13:51:49 +02:00
startIndex = (page * MAX_STAT_ITEMS);
2015-10-20 13:51:49 +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
drawText(r.x + 20, 565, 18, TA_LEFT, colors.white, _("Time Played"));
2016-02-28 14:02:57 +01:00
drawText(r.x + r.w - 20, 565, 18, TA_RIGHT, colors.white, timeToString(game.stats[STAT_TIME], 1));
2015-10-20 13:51:49 +02:00
drawWidgets("stats");
}
2015-11-26 09:16:29 +01:00
static void nextPage(void)
{
2015-12-23 20:22:31 +01:00
page = MIN(page + 1, maxPages - 1);
next->visible = page < maxPages - 1;
prev->visible = 1;
2015-11-26 09:16:29 +01:00
}
static void prevPage(void)
{
page = MAX(0, page - 1);
2015-12-23 20:22:31 +01:00
next->visible = 1;
prev->visible = page > 0;
2015-11-26 09:16:29 +01:00
}