tbftss/src/galaxy/stats.c

152 lines
3.9 KiB
C
Raw Normal View History

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"
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",
"STAT_TIME"
};
static int page;
static int maxPages;
static SDL_Texture *pagePrev;
static SDL_Texture *pageNext;
2015-11-24 23:33:25 +01:00
static SDL_Rect left, right;
void initStatsDisplay(void)
{
page = 0;
maxPages = (STAT_MAX / MAX_STAT_ITEMS);
pagePrev = getTexture("gfx/widgets/optionsLeft.png");
pageNext = getTexture("gfx/widgets/optionsRight.png");
2015-11-24 23:33:25 +01:00
left.x = (SCREEN_WIDTH / 2) - 100;
left.y = 120;
SDL_QueryTexture(pagePrev, NULL, NULL, &left.w, &left.h);
right.x = (SCREEN_WIDTH / 2) + 100;
right.y = 120;
SDL_QueryTexture(pageNext, NULL, NULL, &right.w, &right.h);
}
void doStats(void)
{
if (app.mouse.button[SDL_BUTTON_LEFT])
{
if (collision(app.mouse.x - (app.mouse.w / 2), app.mouse.y - (app.mouse.h / 2), app.mouse.w, app.mouse.h, left.x - (left.w / 2), left.y - (left.h / 2), left.w, left.h))
{
page = MAX(0, page - 1);
app.mouse.button[SDL_BUTTON_LEFT] = 0;
}
if (collision(app.mouse.x - (app.mouse.w / 2), app.mouse.y - (app.mouse.h / 2), app.mouse.w, app.mouse.h, right.x - (right.w / 2), right.y - (right.h / 2), right.w, right.h))
{
page = MIN(page + 1, maxPages);
app.mouse.button[SDL_BUTTON_LEFT] = 0;
}
}
}
2015-10-20 13:51:49 +02:00
void drawStats(void)
{
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");
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
if (page > 0)
{
2015-11-24 23:33:25 +01:00
blit(pagePrev, left.x, left.y, 1);
}
2015-10-20 13:51:49 +02:00
if (page < maxPages)
{
2015-11-24 23:33:25 +01:00
blit(pageNext, right.x, right.y, 1);
}
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
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);
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");
}