Widget and trophy updates.
This commit is contained in:
parent
a47e932024
commit
203183edc1
|
@ -329,17 +329,19 @@ enum
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
WT_BUTTON,
|
WT_BUTTON,
|
||||||
|
WT_SLIDER,
|
||||||
WT_SPINNER,
|
WT_SPINNER,
|
||||||
WT_PLAIN_BUTTON,
|
|
||||||
WT_INPUT
|
WT_INPUT
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
TROPHY_UNEARNED,
|
||||||
TROPHY_BRONZE,
|
TROPHY_BRONZE,
|
||||||
TROPHY_SILVER,
|
TROPHY_SILVER,
|
||||||
TROPHY_GOLD,
|
TROPHY_GOLD,
|
||||||
TROPHY_PLATINUM
|
TROPHY_PLATINUM,
|
||||||
|
TROPHY_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -20,27 +20,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "trophies.h"
|
#include "trophies.h"
|
||||||
|
|
||||||
|
static void setSparkleColor(Trophy *t);
|
||||||
static void loadTrophyData(void);
|
static void loadTrophyData(void);
|
||||||
static void resetAlert(void);
|
static void resetAlert(void);
|
||||||
static void nextAlert(void);
|
static void nextAlert(void);
|
||||||
|
|
||||||
static Trophy trophyHead, *trophyTail;
|
|
||||||
static int numTrophies;
|
static int numTrophies;
|
||||||
static SDL_Rect alertRect;
|
static SDL_Rect alertRect;
|
||||||
static int alertTimer;
|
static int alertTimer;
|
||||||
static Trophy *alertTrophy;
|
static Trophy *alertTrophy;
|
||||||
static float sparkleAngle;
|
static float sparkleAngle;
|
||||||
/*
|
static Atlas *trophyIcons[TROPHY_MAX];
|
||||||
static SDL_Texture *trophyIcons[TROPHY_MAX];
|
static Atlas *sparkle;
|
||||||
static SDL_Texture *sparkle;
|
static Atlas *alertSphere;
|
||||||
static SDL_Texture *alertSphere;
|
static Texture *atlasTexture;
|
||||||
*/
|
|
||||||
static int awarded;
|
static int awarded;
|
||||||
|
|
||||||
void initTrophies(void)
|
void initTrophies(void)
|
||||||
{
|
{
|
||||||
memset(&trophyHead, 0, sizeof(Trophy));
|
atlasTexture = getTexture("gfx/atlas/atlas.png");
|
||||||
trophyTail = &trophyHead;
|
|
||||||
|
trophyIcons[TROPHY_BRONZE] = getImageFromAtlas("gfx/trophies/bronze.png");
|
||||||
|
trophyIcons[TROPHY_SILVER] = getImageFromAtlas("gfx/trophies/silver.png");
|
||||||
|
trophyIcons[TROPHY_GOLD] = getImageFromAtlas("gfx/trophies/gold.png");
|
||||||
|
trophyIcons[TROPHY_PLATINUM] = getImageFromAtlas("gfx/trophies/platinum.png");
|
||||||
|
trophyIcons[TROPHY_UNEARNED] = getImageFromAtlas("gfx/trophies/unearned.png");
|
||||||
|
sparkle = getImageFromAtlas("gfx/trophies/sparkle.png");
|
||||||
|
alertSphere = getImageFromAtlas("gfx/trophies/alertSphere.png");
|
||||||
|
|
||||||
alertRect.h = 90;
|
alertRect.h = 90;
|
||||||
alertRect.y = 10;
|
alertRect.y = 10;
|
||||||
|
@ -63,7 +69,7 @@ void awardTrophy(char *id)
|
||||||
|
|
||||||
numRemaining = 0;
|
numRemaining = 0;
|
||||||
|
|
||||||
for (t = trophyHead.next ; t != NULL ; t = t->next)
|
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
|
||||||
{
|
{
|
||||||
if (t->awardDate == 0 && strcmp(t->id, id) == 0)
|
if (t->awardDate == 0 && strcmp(t->id, id) == 0)
|
||||||
{
|
{
|
||||||
|
@ -88,12 +94,28 @@ void awardTrophy(char *id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Trophy *getTrophy(char *id)
|
||||||
|
{
|
||||||
|
Trophy *t;
|
||||||
|
|
||||||
|
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
|
||||||
|
{
|
||||||
|
if (strcmp(t->id, id) == 0)
|
||||||
|
{
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR, "No such trophy '%s'", t->id);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
void awardTrophies(void)
|
void awardTrophies(void)
|
||||||
{
|
{
|
||||||
int val;
|
int val;
|
||||||
Trophy *t;
|
Trophy *t;
|
||||||
|
|
||||||
for (t = trophyHead.next ; t != NULL ; t = t->next)
|
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
|
||||||
{
|
{
|
||||||
if (t->awardDate == 0 && t->statValue != 0)
|
if (t->awardDate == 0 && t->statValue != 0)
|
||||||
{
|
{
|
||||||
|
@ -137,7 +159,7 @@ static void nextAlert(void)
|
||||||
int w, h;
|
int w, h;
|
||||||
Trophy *t;
|
Trophy *t;
|
||||||
|
|
||||||
for (t = trophyHead.next ; t != NULL ; t = t->next)
|
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
|
||||||
{
|
{
|
||||||
if (t->notify)
|
if (t->notify)
|
||||||
{
|
{
|
||||||
|
@ -170,27 +192,26 @@ static void resetAlert(void)
|
||||||
|
|
||||||
void drawTrophyAlert(void)
|
void drawTrophyAlert(void)
|
||||||
{
|
{
|
||||||
/*int x, y;*/
|
int x, y;
|
||||||
|
|
||||||
if (alertTrophy)
|
if (alertTrophy)
|
||||||
{
|
{
|
||||||
drawRect(alertRect.x, alertRect.y, alertRect.w, alertRect.h, 0, 0, 0, 255);
|
drawRect(alertRect.x, alertRect.y, alertRect.w, alertRect.h, 0, 0, 0, 255);
|
||||||
|
drawOutlineRect(alertRect.x, alertRect.y, alertRect.w, alertRect.h, 255, 255, 255, 255);
|
||||||
drawOutlineRect(alertRect.x, alertRect.y, alertRect.w, alertRect.h, 64, 64, 64, 255);
|
|
||||||
|
|
||||||
drawText(alertRect.x + 15, alertRect.y + 5, 30, TA_LEFT, colors.white, alertTrophy->title);
|
drawText(alertRect.x + 15, alertRect.y + 5, 30, TA_LEFT, colors.white, alertTrophy->title);
|
||||||
drawText(alertRect.x + 15, alertRect.y + 45, 20, TA_LEFT, colors.white, alertTrophy->description);
|
drawText(alertRect.x + 15, alertRect.y + 45, 20, TA_LEFT, colors.white, alertTrophy->description);
|
||||||
|
|
||||||
/*
|
x = alertRect.x + alertRect.w - 72;
|
||||||
x = alertRect.x alertRect.w - 72;
|
y = alertRect.y + 20;
|
||||||
y = alertRect.y 20;
|
|
||||||
|
|
||||||
setSparkleColor(alertTrophy);
|
setSparkleColor(alertTrophy);
|
||||||
blit(alertSphere, x 24, y 24, 1);
|
blitRect(atlasTexture->texture, x + 24, y + 24, &alertSphere->rect, 1);
|
||||||
blitRotated(sparkle, x 24, y 24, sparkleAngle);
|
blitRectRotated(atlasTexture->texture, x + 24, y + 24, &sparkle->rect, sparkleAngle);
|
||||||
blitRotated(sparkle, x 24, y 24, -sparkleAngle);
|
blitRectRotated(atlasTexture->texture, x + 24, y + 24, &sparkle->rect, -sparkleAngle);
|
||||||
blitScaled(trophyIcons[alertTrophy->value], x, y, 48, 48, 0);
|
blitRectScaled(atlasTexture->texture, x, y, 48, 48, &trophyIcons[alertTrophy->value]->rect, 0);
|
||||||
*/
|
|
||||||
|
SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,8 +233,8 @@ static void loadTrophyData(void)
|
||||||
{
|
{
|
||||||
t = malloc(sizeof(Trophy));
|
t = malloc(sizeof(Trophy));
|
||||||
memset(t, 0, sizeof(Trophy));
|
memset(t, 0, sizeof(Trophy));
|
||||||
trophyTail->next = t;
|
game.trophyTail->next = t;
|
||||||
trophyTail = t;
|
game.trophyTail = t;
|
||||||
|
|
||||||
STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH);
|
STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH);
|
||||||
STRNCPY(t->title, _(cJSON_GetObjectItem(node, "title")->valuestring), MAX_DESCRIPTION_LENGTH);
|
STRNCPY(t->title, _(cJSON_GetObjectItem(node, "title")->valuestring), MAX_DESCRIPTION_LENGTH);
|
||||||
|
@ -238,3 +259,27 @@ static void loadTrophyData(void)
|
||||||
free(text);
|
free(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void setSparkleColor(Trophy *t)
|
||||||
|
{
|
||||||
|
switch (t->value)
|
||||||
|
{
|
||||||
|
case TROPHY_BRONZE:
|
||||||
|
SDL_SetTextureColorMod(atlasTexture->texture, 255, 128, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TROPHY_SILVER:
|
||||||
|
SDL_SetTextureColorMod(atlasTexture->texture, 192, 192, 192);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TROPHY_GOLD:
|
||||||
|
SDL_SetTextureColorMod(atlasTexture->texture, 255, 255, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TROPHY_PLATINUM:
|
||||||
|
SDL_SetTextureColorMod(atlasTexture->texture, 0, 128, 255);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -30,6 +30,11 @@ extern void drawText(int x, int y, int size, int align, SDL_Color c, const char
|
||||||
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
||||||
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
||||||
extern float mod(float n, float x);
|
extern float mod(float n, float x);
|
||||||
|
extern Atlas *getImageFromAtlas(char *filename);
|
||||||
|
extern void blitRect(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, int center);
|
||||||
|
extern void blitRectRotated(SDL_Texture *texture, int x, int y, SDL_Rect *srcRect, float angle);
|
||||||
|
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 Colors colors;
|
extern Colors colors;
|
||||||
extern Game game;
|
extern Game game;
|
||||||
|
|
|
@ -294,6 +294,20 @@ struct Tuple {
|
||||||
Tuple *next;
|
Tuple *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Trophy {
|
||||||
|
char id[MAX_NAME_LENGTH];
|
||||||
|
char title[MAX_DESCRIPTION_LENGTH];
|
||||||
|
char description[MAX_DESCRIPTION_LENGTH];
|
||||||
|
char awardDateStr[MAX_NAME_LENGTH];
|
||||||
|
int value;
|
||||||
|
int hidden;
|
||||||
|
int stat;
|
||||||
|
int statValue;
|
||||||
|
unsigned long awardDate;
|
||||||
|
int notify;
|
||||||
|
Trophy *next;
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float shakeAmount;
|
float shakeAmount;
|
||||||
int x;
|
int x;
|
||||||
|
@ -357,6 +371,7 @@ typedef struct {
|
||||||
int isComplete;
|
int isComplete;
|
||||||
Tuple keys[MAX_KEY_TYPES];
|
Tuple keys[MAX_KEY_TYPES];
|
||||||
Tuple missionStatusHead, *missionStatusTail;
|
Tuple missionStatusHead, *missionStatusTail;
|
||||||
|
Trophy trophyHead, *trophyTail;
|
||||||
} Game;
|
} Game;
|
||||||
|
|
||||||
struct Marker {
|
struct Marker {
|
||||||
|
@ -473,11 +488,14 @@ struct Widget {
|
||||||
int y;
|
int y;
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
|
int value;
|
||||||
|
int minValue;
|
||||||
|
int maxValue;
|
||||||
int visible;
|
int visible;
|
||||||
int enabled;
|
int enabled;
|
||||||
int numOptions;
|
int numOptions;
|
||||||
char **options;
|
char **options;
|
||||||
int value;
|
void (*action)(void);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Atlas {
|
struct Atlas {
|
||||||
|
@ -486,21 +504,6 @@ struct Atlas {
|
||||||
Atlas *next;
|
Atlas *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Trophy {
|
|
||||||
char id[MAX_NAME_LENGTH];
|
|
||||||
char title[MAX_DESCRIPTION_LENGTH];
|
|
||||||
char description[MAX_DESCRIPTION_LENGTH];
|
|
||||||
char awardDateStr[MAX_NAME_LENGTH];
|
|
||||||
int value;
|
|
||||||
int hidden;
|
|
||||||
int stat;
|
|
||||||
int statValue;
|
|
||||||
int awarded;
|
|
||||||
unsigned long awardDate;
|
|
||||||
int notify;
|
|
||||||
Trophy *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* ===== i18n stuff ==== */
|
/* ===== i18n stuff ==== */
|
||||||
|
|
||||||
struct Bucket {
|
struct Bucket {
|
||||||
|
|
|
@ -135,10 +135,11 @@ void initGameSystem(void)
|
||||||
initFonts,
|
initFonts,
|
||||||
initAtlas,
|
initAtlas,
|
||||||
initWidgets,
|
initWidgets,
|
||||||
initTrophies,
|
initGame,
|
||||||
initSounds,
|
initSounds,
|
||||||
initSprites,
|
initSprites,
|
||||||
initEntityFactory
|
initEntityFactory,
|
||||||
|
initTrophies
|
||||||
};
|
};
|
||||||
|
|
||||||
numInitFuns = sizeof(initFuncs) / sizeof(void*);
|
numInitFuns = sizeof(initFuncs) / sizeof(void*);
|
||||||
|
|
|
@ -36,6 +36,7 @@ extern void initSounds(void);
|
||||||
extern void initSprites(void);
|
extern void initSprites(void);
|
||||||
extern void initWidgets(void);
|
extern void initWidgets(void);
|
||||||
extern void initTrophies(void);
|
extern void initTrophies(void);
|
||||||
|
extern void initGame(void);
|
||||||
extern void initEntityFactory(void);
|
extern void initEntityFactory(void);
|
||||||
extern void destroyLookups(void);
|
extern void destroyLookups(void);
|
||||||
extern void destroyFonts(void);
|
extern void destroyFonts(void);
|
||||||
|
|
|
@ -51,7 +51,14 @@ void initLookups(void)
|
||||||
|
|
||||||
addLookup("WT_BUTTON", WT_BUTTON);
|
addLookup("WT_BUTTON", WT_BUTTON);
|
||||||
addLookup("WT_SPINNER", WT_SPINNER);
|
addLookup("WT_SPINNER", WT_SPINNER);
|
||||||
addLookup("WT_PLAIN_BUTTON", WT_PLAIN_BUTTON);
|
addLookup("WT_SLIDER", WT_SLIDER);
|
||||||
|
addLookup("WT_INPUT", WT_INPUT);
|
||||||
|
|
||||||
|
addLookup("MS_LOCKED", MS_LOCKED);
|
||||||
|
addLookup("MS_INCOMPLETE", MS_INCOMPLETE);
|
||||||
|
addLookup("MS_PARTIAL", MS_PARTIAL);
|
||||||
|
addLookup("MS_MISSING_HEART_CELL", MS_MISSING_HEART_CELL);
|
||||||
|
addLookup("MS_COMPLETE", MS_COMPLETE);
|
||||||
|
|
||||||
addLookup("TROPHY_BRONZE", TROPHY_BRONZE);
|
addLookup("TROPHY_BRONZE", TROPHY_BRONZE);
|
||||||
addLookup("TROPHY_SILVER", TROPHY_SILVER);
|
addLookup("TROPHY_SILVER", TROPHY_SILVER);
|
||||||
|
|
|
@ -24,6 +24,7 @@ static void loadWidgetGroup(char *filename);
|
||||||
static void loadWidgets(void);
|
static void loadWidgets(void);
|
||||||
static void createWidgetOptions(Widget *w, char *options);
|
static void createWidgetOptions(Widget *w, char *options);
|
||||||
static void selectWidget(int dir);
|
static void selectWidget(int dir);
|
||||||
|
static void updateWidgetValue(int dir);
|
||||||
|
|
||||||
static Widget widgets[MAX_WIDGETS];
|
static Widget widgets[MAX_WIDGETS];
|
||||||
static Widget *selectedWidget;
|
static Widget *selectedWidget;
|
||||||
|
@ -55,12 +56,33 @@ void doWidgets(void)
|
||||||
app.keyboard[SDL_SCANCODE_DOWN] = 0;
|
app.keyboard[SDL_SCANCODE_DOWN] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.keyboard[SDL_SCANCODE_LEFT] && selectedWidget->type == WT_SPINNER)
|
if (app.keyboard[SDL_SCANCODE_LEFT])
|
||||||
{
|
{
|
||||||
|
updateWidgetValue(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (app.keyboard[SDL_SCANCODE_RIGHT] && selectedWidget->type == WT_SPINNER)
|
if (app.keyboard[SDL_SCANCODE_RIGHT])
|
||||||
{
|
{
|
||||||
|
updateWidgetValue(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (app.keyboard[SDL_SCANCODE_RETURN])
|
||||||
|
{
|
||||||
|
selectedWidget->action();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void updateWidgetValue(int dir)
|
||||||
|
{
|
||||||
|
if (selectedWidget->type == WT_SLIDER)
|
||||||
|
{
|
||||||
|
selectedWidget->value = limit(selectedWidget->value + dir, selectedWidget->minValue, selectedWidget->maxValue);
|
||||||
|
selectedWidget->action();
|
||||||
|
}
|
||||||
|
else if (selectedWidget->type == WT_SPINNER)
|
||||||
|
{
|
||||||
|
selectedWidget->value = limit(selectedWidget->value + dir, 0, selectedWidget->numOptions - 1);
|
||||||
|
selectedWidget->action();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +114,7 @@ void drawWidgets(void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WT_PLAIN_BUTTON:
|
case WT_SLIDER:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WT_SPINNER:
|
case WT_SPINNER:
|
||||||
|
|
|
@ -27,6 +27,7 @@ extern long lookup(const char *name);
|
||||||
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
|
extern void drawText(int x, int y, int size, int align, SDL_Color c, const char *format, ...);
|
||||||
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
extern void drawRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
||||||
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
extern void drawOutlineRect(int x, int y, int w, int h, int r, int g, int b, int a);
|
||||||
|
extern float limit(float i, float a, float b);
|
||||||
|
|
||||||
extern App app;
|
extern App app;
|
||||||
extern Colors colors;
|
extern Colors colors;
|
||||||
|
|
Loading…
Reference in New Issue