Integrate trophy display.
This commit is contained in:
parent
dc85abac77
commit
edde9fac2f
|
@ -70,7 +70,7 @@ void doStats(void)
|
|||
if (isControl(CONTROL_RIGHT) || app.keyboard[SDL_SCANCODE_RIGHT])
|
||||
{
|
||||
page = limit(page + 1, 0, maxPages - 1);
|
||||
app.keyboard[SDL_SCANCODE_LEFT] = 0;
|
||||
app.keyboard[SDL_SCANCODE_RIGHT] = 0;
|
||||
clearControl(CONTROL_RIGHT);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,6 @@ extern float limit(float i, float low, float high);
|
|||
extern int isControl(int type);
|
||||
extern void clearControl(int type);
|
||||
extern Atlas *getImageFromAtlas(char *filename);
|
||||
extern void blitRectScaled(SDL_Texture *texture, int x, int y, int w, int h, SDL_Rect *srcRect, int center);
|
||||
extern Texture *getTexture(const char *filename);
|
||||
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
||||
extern void doWidgets(void);
|
||||
|
|
|
@ -35,6 +35,10 @@ static Atlas *sparkle;
|
|||
static Atlas *alertSphere;
|
||||
static Texture *atlasTexture;
|
||||
static int awarded;
|
||||
static Atlas *left;
|
||||
static Atlas *right;
|
||||
static int page;
|
||||
static float maxPages;
|
||||
|
||||
void initTrophies(void)
|
||||
{
|
||||
|
@ -47,6 +51,8 @@ void initTrophies(void)
|
|||
trophyIcons[TROPHY_UNEARNED] = getImageFromAtlas("gfx/trophies/unearned.png");
|
||||
sparkle = getImageFromAtlas("gfx/trophies/sparkle.png");
|
||||
alertSphere = getImageFromAtlas("gfx/trophies/alertSphere.png");
|
||||
left = getImageFromAtlas("gfx/ui/left.png");
|
||||
right = getImageFromAtlas("gfx/ui/right.png");
|
||||
|
||||
alertRect.h = 90;
|
||||
alertRect.y = 10;
|
||||
|
@ -56,12 +62,124 @@ void initTrophies(void)
|
|||
awarded = 0;
|
||||
|
||||
sparkleAngle = 0;
|
||||
|
||||
page = 0;
|
||||
|
||||
maxPages = STAT_TIME_PLAYED;
|
||||
maxPages /= TROPHIES_PER_PAGE;
|
||||
maxPages = ceil(maxPages);
|
||||
|
||||
loadTrophyData();
|
||||
|
||||
resetAlert();
|
||||
}
|
||||
|
||||
void doTrophies(void)
|
||||
{
|
||||
if (isControl(CONTROL_LEFT) || app.keyboard[SDL_SCANCODE_LEFT])
|
||||
{
|
||||
page = limit(page - 1, 0, maxPages - 1);
|
||||
app.keyboard[SDL_SCANCODE_LEFT] = 0;
|
||||
clearControl(CONTROL_LEFT);
|
||||
}
|
||||
|
||||
if (isControl(CONTROL_RIGHT) || app.keyboard[SDL_SCANCODE_RIGHT])
|
||||
{
|
||||
page = limit(page + 1, 0, maxPages - 1);
|
||||
app.keyboard[SDL_SCANCODE_RIGHT] = 0;
|
||||
clearControl(CONTROL_RIGHT);
|
||||
}
|
||||
|
||||
doWidgets();
|
||||
}
|
||||
|
||||
void drawTrophies(void)
|
||||
{
|
||||
Trophy *t;
|
||||
SDL_Rect r;
|
||||
int start, end, i, x, y;
|
||||
|
||||
drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0, 128);
|
||||
|
||||
r.w = 600;
|
||||
r.h = 650;
|
||||
r.x = (SCREEN_WIDTH / 2) - r.w / 2;
|
||||
r.y = (SCREEN_HEIGHT / 2) - r.h / 2;
|
||||
|
||||
r.y += 15;
|
||||
|
||||
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);
|
||||
|
||||
drawText(SCREEN_WIDTH / 2, 60, 28, TA_CENTER, colors.white, "Trophies");
|
||||
|
||||
drawText(SCREEN_WIDTH / 2, 100, 16, TA_CENTER, colors.lightGrey, "Page %d / %d", page + 1, (int)maxPages);
|
||||
|
||||
if (page > 0)
|
||||
{
|
||||
blitRect(atlasTexture->texture, SCREEN_WIDTH / 2 - 100, 110, &left->rect, 1);
|
||||
}
|
||||
|
||||
if (page < maxPages - 1)
|
||||
{
|
||||
blitRect(atlasTexture->texture, SCREEN_WIDTH / 2 + 100, 110, &right->rect, 1);
|
||||
}
|
||||
|
||||
x = r.x + 15;
|
||||
y = 160;
|
||||
start = page * TROPHIES_PER_PAGE;
|
||||
end = start + TROPHIES_PER_PAGE;
|
||||
i = 0;
|
||||
|
||||
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
|
||||
{
|
||||
if (i >= start && i < end)
|
||||
{
|
||||
if (t->awardDate)
|
||||
{
|
||||
setSparkleColor(t);
|
||||
blitRectRotated(atlasTexture->texture, x + 32, y + 32, &sparkle->rect, sparkleAngle);
|
||||
blitRectRotated(atlasTexture->texture, x + 32, y + 32, &sparkle->rect, -sparkleAngle);
|
||||
|
||||
blitRectScaled(atlasTexture->texture, x, y, 64, 64, &trophyIcons[t->value]->rect, 0);
|
||||
drawText(x + 85, y - 10, 20, TA_LEFT, colors.yellow, t->title);
|
||||
drawText(x + 85, y + 20, 18, TA_LEFT, colors.white, t->description);
|
||||
|
||||
if (strlen(t->awardDateStr) == 0)
|
||||
{
|
||||
STRNCPY(t->awardDateStr, timeToDate(t->awardDate), MAX_NAME_LENGTH);
|
||||
}
|
||||
|
||||
drawText(x + 85, y + 48, 18, TA_LEFT, colors.white, t->awardDateStr);
|
||||
}
|
||||
else
|
||||
{
|
||||
blitRectScaled(atlasTexture->texture, x, y, 64, 64, &trophyIcons[TROPHY_UNEARNED]->rect, 0);
|
||||
|
||||
if (!t->hidden)
|
||||
{
|
||||
drawText(x + 85, y - 10, 20, TA_LEFT, colors.lightGrey, t->title);
|
||||
drawText(x + 85, y + 20, 18, TA_LEFT, colors.darkGrey, t->description);
|
||||
drawText(x + 85, y + 48, 18, TA_LEFT, colors.darkGrey, "-");
|
||||
}
|
||||
else
|
||||
{
|
||||
drawText(x + 85, y + 20, 20, TA_LEFT, colors.darkGrey, "Hidden");
|
||||
}
|
||||
}
|
||||
|
||||
y += 120;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 255);
|
||||
|
||||
drawWidgets();
|
||||
}
|
||||
|
||||
void awardTrophy(char *id)
|
||||
{
|
||||
Trophy *t;
|
||||
|
@ -211,7 +329,6 @@ void drawTrophyAlert(void)
|
|||
blitRectRotated(atlasTexture->texture, x + 24, y + 24, &sparkle->rect, sparkleAngle);
|
||||
blitRectRotated(atlasTexture->texture, x + 24, y + 24, &sparkle->rect, -sparkleAngle);
|
||||
blitRectScaled(atlasTexture->texture, x, y, 48, 48, &trophyIcons[alertTrophy->value]->rect, 0);
|
||||
|
||||
SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 255);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "../json/cJSON.h"
|
||||
#include <time.h>
|
||||
|
||||
#define TROPHIES_PER_PAGE 4
|
||||
|
||||
extern char *readFile(const char *filename);
|
||||
extern long lookup(const char *name);
|
||||
extern void textSize(char *text, int size, int *w, int *h);
|
||||
|
@ -36,6 +38,14 @@ extern void blitRectRotated(SDL_Texture *texture, int x, int y, SDL_Rect *srcRec
|
|||
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);
|
||||
extern void doWidgets(void);
|
||||
extern char *timeToDate(long millis);
|
||||
|
||||
extern App app;
|
||||
extern Colors colors;
|
||||
extern Game game;
|
||||
|
|
|
@ -38,7 +38,7 @@ static void options(void);
|
|||
static void stats(void);
|
||||
static void trophies(void);
|
||||
static void quit(void);
|
||||
static void returnFromStats(void);
|
||||
static void returnFromTrophyStats(void);
|
||||
static void doCursor(void);
|
||||
static void doMissionSelect(void);
|
||||
static void doMissionInfo(void);
|
||||
|
@ -104,7 +104,8 @@ void initHub(void)
|
|||
getWidget("trophies", "hub")->action = trophies;
|
||||
getWidget("quit", "hub")->action = quit;
|
||||
|
||||
getWidget("ok", "stats")->action = returnFromStats;
|
||||
getWidget("ok", "stats")->action = returnFromTrophyStats;
|
||||
getWidget("ok", "trophies")->action = returnFromTrophyStats;
|
||||
|
||||
loadMissions();
|
||||
|
||||
|
@ -238,15 +239,19 @@ static void logic(void)
|
|||
break;
|
||||
|
||||
case SHOW_STATS:
|
||||
drawStats();
|
||||
doStats();
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
returnFromStats();
|
||||
returnFromTrophyStats();
|
||||
}
|
||||
break;
|
||||
|
||||
case SHOW_TROPHIES:
|
||||
doTrophies();
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
returnFromTrophyStats();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -361,6 +366,7 @@ static void draw(void)
|
|||
break;
|
||||
|
||||
case SHOW_TROPHIES:
|
||||
drawTrophies();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -637,7 +643,8 @@ static void stats(void)
|
|||
|
||||
static void trophies(void)
|
||||
{
|
||||
|
||||
showing = SHOW_TROPHIES;
|
||||
showWidgetGroup("trophies");
|
||||
}
|
||||
|
||||
static void quit(void)
|
||||
|
@ -645,7 +652,7 @@ static void quit(void)
|
|||
|
||||
}
|
||||
|
||||
static void returnFromStats(void)
|
||||
static void returnFromTrophyStats(void)
|
||||
{
|
||||
showWidgetGroup("hub");
|
||||
showing = SHOW_WIDGETS;
|
||||
|
|
|
@ -65,6 +65,8 @@ extern void doWidgets(void);
|
|||
extern void drawStats(void);
|
||||
extern void doStats(void);
|
||||
extern void awardTrophy(char *id);
|
||||
extern void doTrophies(void);
|
||||
extern void drawTrophies(void);
|
||||
|
||||
extern App app;
|
||||
extern Colors colors;
|
||||
|
|
|
@ -21,8 +21,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "../common.h"
|
||||
#include "../json/cJSON.h"
|
||||
|
||||
extern Texture *getTexture(const char *filename);
|
||||
extern char *readFile(const char *filename);
|
||||
extern unsigned long hashcode(const char *str);
|
||||
|
||||
extern Dev dev;
|
||||
|
|
|
@ -81,6 +81,19 @@ char *timeToString(int seconds, int showHours)
|
|||
return TIME_STRING;
|
||||
}
|
||||
|
||||
char *timeToDate(long millis)
|
||||
{
|
||||
static char DATE[MAX_NAME_LENGTH];
|
||||
|
||||
struct tm *timeinfo;
|
||||
|
||||
timeinfo = localtime(&millis);
|
||||
|
||||
strftime(DATE, MAX_NAME_LENGTH, "%d %b %Y, %I:%M%p", timeinfo);
|
||||
|
||||
return DATE;
|
||||
}
|
||||
|
||||
void *resize(void *array, int oldSize, int newSize)
|
||||
{
|
||||
void **newArray;
|
||||
|
|
|
@ -19,3 +19,4 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
*/
|
||||
|
||||
#include "../common.h"
|
||||
#include "time.h"
|
||||
|
|
|
@ -42,7 +42,7 @@ static void options(void);
|
|||
static void stats(void);
|
||||
static void trophies(void);
|
||||
static void quit(void);
|
||||
static void returnFromStats(void);
|
||||
static void returnFromTrophyStats(void);
|
||||
int getMissionStatus(void);
|
||||
|
||||
static Texture *background;
|
||||
|
@ -191,6 +191,10 @@ static void draw(void)
|
|||
case SHOW_STATS:
|
||||
drawStats();
|
||||
break;
|
||||
|
||||
case SHOW_TROPHIES:
|
||||
drawTrophies();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -350,7 +354,16 @@ static void doWorldInProgress(void)
|
|||
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
returnFromStats();
|
||||
returnFromTrophyStats();
|
||||
}
|
||||
}
|
||||
else if (showing == SHOW_TROPHIES)
|
||||
{
|
||||
doTrophies();
|
||||
|
||||
if (app.keyboard[SDL_SCANCODE_ESCAPE])
|
||||
{
|
||||
returnFromTrophyStats();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -699,13 +712,15 @@ static void stats(void)
|
|||
|
||||
static void trophies(void)
|
||||
{
|
||||
showing = SHOW_TROPHIES;
|
||||
showWidgetGroup("trophies");
|
||||
}
|
||||
|
||||
static void quit(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void returnFromStats(void)
|
||||
static void returnFromTrophyStats(void)
|
||||
{
|
||||
showWidgetGroup("hub");
|
||||
showing = SHOW_WIDGETS;
|
||||
|
|
|
@ -99,6 +99,8 @@ extern void initPostMission(void);
|
|||
extern void addKeysFromStash(void);
|
||||
extern void drawStats(void);
|
||||
extern void doStats(void);
|
||||
extern void doTrophies(void);
|
||||
extern void drawTrophies(void);
|
||||
|
||||
extern App app;
|
||||
extern Colors colors;
|
||||
|
|
Loading…
Reference in New Issue