Widget and trophy updates.

This commit is contained in:
Steve 2018-02-15 21:38:26 +00:00
parent a47e932024
commit 203183edc1
9 changed files with 135 additions and 48 deletions

View File

@ -329,17 +329,19 @@ enum
enum
{
WT_BUTTON,
WT_SLIDER,
WT_SPINNER,
WT_PLAIN_BUTTON,
WT_INPUT
};
enum
{
TROPHY_UNEARNED,
TROPHY_BRONZE,
TROPHY_SILVER,
TROPHY_GOLD,
TROPHY_PLATINUM
TROPHY_PLATINUM,
TROPHY_MAX
};
enum

View File

@ -20,27 +20,33 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "trophies.h"
static void setSparkleColor(Trophy *t);
static void loadTrophyData(void);
static void resetAlert(void);
static void nextAlert(void);
static Trophy trophyHead, *trophyTail;
static int numTrophies;
static SDL_Rect alertRect;
static int alertTimer;
static Trophy *alertTrophy;
static float sparkleAngle;
/*
static SDL_Texture *trophyIcons[TROPHY_MAX];
static SDL_Texture *sparkle;
static SDL_Texture *alertSphere;
*/
static Atlas *trophyIcons[TROPHY_MAX];
static Atlas *sparkle;
static Atlas *alertSphere;
static Texture *atlasTexture;
static int awarded;
void initTrophies(void)
{
memset(&trophyHead, 0, sizeof(Trophy));
trophyTail = &trophyHead;
atlasTexture = getTexture("gfx/atlas/atlas.png");
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.y = 10;
@ -63,7 +69,7 @@ void awardTrophy(char *id)
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)
{
@ -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)
{
int val;
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)
{
@ -137,7 +159,7 @@ static void nextAlert(void)
int w, h;
Trophy *t;
for (t = trophyHead.next ; t != NULL ; t = t->next)
for (t = game.trophyHead.next ; t != NULL ; t = t->next)
{
if (t->notify)
{
@ -170,27 +192,26 @@ static void resetAlert(void)
void drawTrophyAlert(void)
{
/*int x, y;*/
int x, y;
if (alertTrophy)
{
drawRect(alertRect.x, alertRect.y, alertRect.w, alertRect.h, 0, 0, 0, 255);
drawOutlineRect(alertRect.x, alertRect.y, alertRect.w, alertRect.h, 64, 64, 64, 255);
drawOutlineRect(alertRect.x, alertRect.y, alertRect.w, alertRect.h, 255, 255, 255, 255);
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);
/*
x = alertRect.x alertRect.w - 72;
y = alertRect.y 20;
x = alertRect.x + alertRect.w - 72;
y = alertRect.y + 20;
setSparkleColor(alertTrophy);
blit(alertSphere, x 24, y 24, 1);
blitRotated(sparkle, x 24, y 24, sparkleAngle);
blitRotated(sparkle, x 24, y 24, -sparkleAngle);
blitScaled(trophyIcons[alertTrophy->value], x, y, 48, 48, 0);
*/
blitRect(atlasTexture->texture, x + 24, y + 24, &alertSphere->rect, 1);
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);
}
}
@ -212,8 +233,8 @@ static void loadTrophyData(void)
{
t = malloc(sizeof(Trophy));
memset(t, 0, sizeof(Trophy));
trophyTail->next = t;
trophyTail = t;
game.trophyTail->next = t;
game.trophyTail = t;
STRNCPY(t->id, cJSON_GetObjectItem(node, "id")->valuestring, MAX_NAME_LENGTH);
STRNCPY(t->title, _(cJSON_GetObjectItem(node, "title")->valuestring), MAX_DESCRIPTION_LENGTH);
@ -238,3 +259,27 @@ static void loadTrophyData(void)
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;
}
}

View File

@ -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 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 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 Game game;

View File

@ -294,6 +294,20 @@ struct Tuple {
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 {
float shakeAmount;
int x;
@ -357,6 +371,7 @@ typedef struct {
int isComplete;
Tuple keys[MAX_KEY_TYPES];
Tuple missionStatusHead, *missionStatusTail;
Trophy trophyHead, *trophyTail;
} Game;
struct Marker {
@ -473,11 +488,14 @@ struct Widget {
int y;
int w;
int h;
int value;
int minValue;
int maxValue;
int visible;
int enabled;
int numOptions;
char **options;
int value;
void (*action)(void);
};
struct Atlas {
@ -486,21 +504,6 @@ struct Atlas {
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 ==== */
struct Bucket {

View File

@ -135,10 +135,11 @@ void initGameSystem(void)
initFonts,
initAtlas,
initWidgets,
initTrophies,
initGame,
initSounds,
initSprites,
initEntityFactory
initEntityFactory,
initTrophies
};
numInitFuns = sizeof(initFuncs) / sizeof(void*);

View File

@ -36,6 +36,7 @@ extern void initSounds(void);
extern void initSprites(void);
extern void initWidgets(void);
extern void initTrophies(void);
extern void initGame(void);
extern void initEntityFactory(void);
extern void destroyLookups(void);
extern void destroyFonts(void);

View File

@ -51,7 +51,14 @@ void initLookups(void)
addLookup("WT_BUTTON", WT_BUTTON);
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_SILVER", TROPHY_SILVER);

View File

@ -24,6 +24,7 @@ static void loadWidgetGroup(char *filename);
static void loadWidgets(void);
static void createWidgetOptions(Widget *w, char *options);
static void selectWidget(int dir);
static void updateWidgetValue(int dir);
static Widget widgets[MAX_WIDGETS];
static Widget *selectedWidget;
@ -55,12 +56,33 @@ void doWidgets(void)
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;
case WT_PLAIN_BUTTON:
case WT_SLIDER:
break;
case WT_SPINNER:

View File

@ -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 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 float limit(float i, float a, float b);
extern App app;
extern Colors colors;