Nicer labels in many places.
This commit is contained in:
parent
b88318097f
commit
6d5acc698e
16
.travis.yml
16
.travis.yml
|
@ -45,6 +45,20 @@ addons:
|
|||
name: "LiquidityC/breakhack"
|
||||
description: "Build submitted via Travis CI"
|
||||
notification_email: linus.probert@gmail.com
|
||||
build_command_prepend: "mkdir -p build; cd build; cmake .."
|
||||
build_command_prepend: "mkdir -p _build; cd _build; cmake .."
|
||||
build_command: "make"
|
||||
branch_pattern: coverity_scan
|
||||
|
||||
before_deploy:
|
||||
- cmake package
|
||||
|
||||
deploy:
|
||||
provider: releases
|
||||
api_key:
|
||||
secure: "KeT/BC2ck2eqs1q4keoLe/Y9KIk+AR5shiAnA2oMQzbLWoZmxUx3Kol7rLPJ0Hfgb+aCpSpTM1njX6Kw7Nl8j4NrOkgadb3ZmfqRthFazzb93reRt+0dZZcurilHpWtMeteaZLWGWaG0j09xnI3CPPjmth6BB+/roGRsQyo1QKk0pZYsQD6ZKfGAUR1576dFyRzvsIrnfLd7rZVSNZ8HtPwN2rmSLD/cGxMCf+IafcBInPyv9p6bCoVLIDFnDdCr+kwBuSlGudT15EtDx3d9Abab3ZIS3NUpnXr2s0BmknCpyb59YsG9V0YXIQsIkwioEWiJskcAznXT/yB4XqDCq693b+0sxldsUVPw2JkMU+40V5ay2itH3SeP/LyXVFUARdWB+nn6avaFRVaZ1nHYP95CrBXC8JGB1bd7ejeEm9+cOvBOgvsZp71uRJ2OdEXN5Z3i373cyvWXPFHVbQRJS5l1dRBJR0sozYcPe8BMQ4Pv+xahFWIeyDAErUwJSiOf1Uv/x6PNxJaZTTZKCYGSRo6Ywb15bw4YnlOzDXllBxNg3IsJjJes1qFBJGR1eRMq/U9Ne+eHLk7cn2r7Fa77DtFsbONTDHftXDFHk46LDLF+HlL2wHIoTJVzLl/tXyBm3MJuaghGEvvZSwalWS3UnvMTQOBlDG0qC/ww6mlkv+Y="
|
||||
file:
|
||||
- "package/breakhack*.tar.gz"
|
||||
- "package/breakhack*.tar.Z"
|
||||
skip_cleanup: true
|
||||
on:
|
||||
tags: true
|
||||
|
|
|
@ -29,7 +29,7 @@ actiontext_create(Sprite *sprite)
|
|||
t->sprite = sprite;
|
||||
t->timer = timer_create();
|
||||
t->dead = false;
|
||||
t->velocity = (Vector2d) { 100, -100 };
|
||||
t->velocity = (Vector2d) { 0, -100 };
|
||||
t->color = (SDL_Color) { 255, 255, 255, 255 };
|
||||
return t;
|
||||
}
|
||||
|
|
|
@ -34,13 +34,15 @@ actiontextbuilder_init(SDL_Renderer *renderer)
|
|||
void
|
||||
actiontextbuilder_create_text(const char *msg, SDL_Color color, Position *p)
|
||||
{
|
||||
static SDL_Color o_color = { 0, 0, 0, 255 };
|
||||
|
||||
assert (gRenderer != NULL);
|
||||
Sprite *sprite = sprite_create();
|
||||
sprite->pos = *p;
|
||||
sprite_load_text_texture(sprite, "GUI/SDS_8x8.ttf", 0, 14);
|
||||
texture_load_from_text(sprite->textures[0], msg, color, gRenderer);
|
||||
sprite_load_text_texture(sprite, "GUI/SDS_8x8.ttf", 0, 11, 1);
|
||||
texture_load_from_text(sprite->textures[0], msg, color, o_color, gRenderer);
|
||||
sprite->dim = sprite->textures[0]->dim;
|
||||
linkedlist_push(&actiontexts, actiontext_create(sprite));
|
||||
linkedlist_append(&actiontexts, actiontext_create(sprite));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -53,7 +55,7 @@ actiontextbuilder_update(UpdateData *data)
|
|||
actiontext_destroy(text);
|
||||
} else {
|
||||
actiontext_update(text, data);
|
||||
linkedlist_push(&remaining, text);
|
||||
linkedlist_append(&remaining, text);
|
||||
}
|
||||
}
|
||||
actiontexts = remaining;
|
||||
|
|
23
src/gui.c
23
src/gui.c
|
@ -103,7 +103,7 @@ create_label_sprite(Position pos)
|
|||
Sprite *s = sprite_create();
|
||||
s->fixed = true;
|
||||
s->pos = pos;
|
||||
sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, LABEL_FONT_SIZE);
|
||||
sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, LABEL_FONT_SIZE, 0);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -195,12 +195,12 @@ gui_create(Camera *cam)
|
|||
|
||||
for (i = 0; i < LOG_LINES_COUNT; ++i) {
|
||||
t = texture_create();
|
||||
texture_load_font(t, "GUI/SDS_8x8.ttf", LOG_FONT_SIZE);
|
||||
texture_load_font(t, "GUI/SDS_8x8.ttf", LOG_FONT_SIZE, 0);
|
||||
gui->log_lines[i] = t;
|
||||
}
|
||||
|
||||
gui->event_message = texture_create();
|
||||
texture_load_font(gui->event_message, "GUI/SDS_8x8.ttf", EVENT_MESSAGE_FONT_SIZE);
|
||||
texture_load_font(gui->event_message, "GUI/SDS_8x8.ttf", EVENT_MESSAGE_FONT_SIZE, 2);
|
||||
gui->event_message_timer = timer_create();
|
||||
|
||||
gui->labels[CURRENT_XP_LABEL] = create_label_sprite((Position) { 16, POS_Y_XPBAR + 18 });
|
||||
|
@ -361,42 +361,42 @@ gui_update_player_stats(Gui *gui, Player *player, Map *map, SDL_Renderer *render
|
|||
|
||||
if (dungeon_level != (unsigned int) map->level) {
|
||||
m_sprintf(buffer, 200, "Dungeon level: %d", map->level);
|
||||
texture_load_from_text(gui->labels[DUNGEON_LEVEL_LABEL]->textures[0], buffer, color, renderer);
|
||||
texture_load_from_text(gui->labels[DUNGEON_LEVEL_LABEL]->textures[0], buffer, color, color, renderer);
|
||||
gui->labels[DUNGEON_LEVEL_LABEL]->dim = gui->labels[DUNGEON_LEVEL_LABEL]->textures[0]->dim;
|
||||
dungeon_level = (unsigned int) map->level;
|
||||
}
|
||||
|
||||
if (current_potion_sips != (int) player->potion_sips) {
|
||||
m_sprintf(buffer, 200, "x %u", (unsigned int) player->potion_sips);
|
||||
texture_load_from_text(gui->labels[HEALTH_POTION_LABEL]->textures[0], buffer, color, renderer);
|
||||
texture_load_from_text(gui->labels[HEALTH_POTION_LABEL]->textures[0], buffer, color, color, renderer);
|
||||
gui->labels[HEALTH_POTION_LABEL]->dim = gui->labels[HEALTH_POTION_LABEL]->textures[0]->dim;
|
||||
current_potion_sips = player->potion_sips;
|
||||
}
|
||||
|
||||
if (current_dagger_count != (int) player->daggers) {
|
||||
m_sprintf(buffer, 200, "x %u", (unsigned int) player->daggers);
|
||||
texture_load_from_text(gui->labels[DAGGER_LABEL]->textures[0], buffer, color, renderer);
|
||||
texture_load_from_text(gui->labels[DAGGER_LABEL]->textures[0], buffer, color, color, renderer);
|
||||
gui->labels[DAGGER_LABEL]->dim = gui->labels[DAGGER_LABEL]->textures[0]->dim;
|
||||
current_dagger_count = (int) player->daggers;
|
||||
}
|
||||
|
||||
if (last_gold != player->gold) {
|
||||
m_sprintf(buffer, 200, "x %.2f", player->gold);
|
||||
texture_load_from_text(gui->labels[GOLD_LABEL]->textures[0], buffer, color, renderer);
|
||||
texture_load_from_text(gui->labels[GOLD_LABEL]->textures[0], buffer, color, color, renderer);
|
||||
gui->labels[GOLD_LABEL]->dim = gui->labels[GOLD_LABEL]->textures[0]->dim;
|
||||
last_gold = player->gold;
|
||||
}
|
||||
|
||||
if (last_xp != (int) data.current) {
|
||||
m_sprintf(buffer, 200, "XP: %u / %u", data.current, data.nextLevel);
|
||||
texture_load_from_text(gui->labels[CURRENT_XP_LABEL]->textures[0], buffer, color, renderer);
|
||||
texture_load_from_text(gui->labels[CURRENT_XP_LABEL]->textures[0], buffer, color, color, renderer);
|
||||
gui->labels[CURRENT_XP_LABEL]->dim = gui->labels[CURRENT_XP_LABEL]->textures[0]->dim;
|
||||
last_xp = data.current;
|
||||
}
|
||||
|
||||
if (last_level != data.level) {
|
||||
m_sprintf(buffer, 200, "Level: %u", data.level);
|
||||
texture_load_from_text(gui->labels[LEVEL_LABEL]->textures[0], buffer, color, renderer);
|
||||
texture_load_from_text(gui->labels[LEVEL_LABEL]->textures[0], buffer, color, color, renderer);
|
||||
gui->labels[LEVEL_LABEL]->dim = gui->labels[LEVEL_LABEL]->textures[0]->dim;
|
||||
last_level = data.level;
|
||||
}
|
||||
|
@ -563,6 +563,7 @@ void
|
|||
gui_render_log(Gui *gui, Camera *cam)
|
||||
{
|
||||
static SDL_Color color = { 255, 255, 255, 255 };
|
||||
static SDL_Color ocolor = { 0, 0, 0, 255 };
|
||||
|
||||
unsigned int i;
|
||||
unsigned int render_count;
|
||||
|
@ -576,7 +577,7 @@ gui_render_log(Gui *gui, Camera *cam)
|
|||
Texture *t;
|
||||
box.y = 16 + ((LOG_FONT_SIZE+5) * i);
|
||||
t = gui->log_lines[i];
|
||||
texture_load_from_text(t, log_data.log[i], color, cam->renderer);
|
||||
texture_load_from_text(t, log_data.log[i], color, ocolor, cam->renderer);
|
||||
box.w = t->dim.width;
|
||||
box.h = t->dim.height;
|
||||
texture_render(t, &box, cam);
|
||||
|
@ -587,6 +588,7 @@ void
|
|||
gui_render_event_message(Gui *gui, Camera *cam)
|
||||
{
|
||||
static SDL_Color fg_color = { 255, 255, 255, 255 };
|
||||
static SDL_Color o_color = { 0, 0, 0, 255 };
|
||||
static SDL_Rect box = { 0, 0, 150, 50 };
|
||||
|
||||
if (timer_started(gui->event_message_timer)
|
||||
|
@ -600,6 +602,7 @@ gui_render_event_message(Gui *gui, Camera *cam)
|
|||
texture_load_from_text(gui->event_message,
|
||||
event_messages.messages[0],
|
||||
fg_color,
|
||||
o_color,
|
||||
cam->renderer);
|
||||
|
||||
box.x = (GAME_VIEW_WIDTH/2) - (gui->event_message->dim.width/2);
|
||||
|
|
13
src/main.c
13
src/main.c
|
@ -77,8 +77,9 @@ static SDL_Rect rightGuiViewport;
|
|||
static SDL_Rect menuViewport;
|
||||
static Turn currentTurn = PLAYER;
|
||||
|
||||
static SDL_Color C_MENU_DEFAULT = { 255, 255, 0, 0 };
|
||||
static SDL_Color C_MENU_HOVER = { 255, 0, 0, 0 };
|
||||
static SDL_Color C_MENU_DEFAULT = { 255, 255, 0 };
|
||||
static SDL_Color C_MENU_OUTLINE_DEFAULT = { 0, 0, 0, };
|
||||
static SDL_Color C_MENU_HOVER = { 255, 0, 0 };
|
||||
|
||||
struct MENU_ITEM {
|
||||
char label[20];
|
||||
|
@ -260,9 +261,9 @@ createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size)
|
|||
unsigned int hcenter;
|
||||
|
||||
Sprite *s1 = sprite_create();
|
||||
sprite_load_text_texture(s1, "GUI/SDS_8x8.ttf", 0, 25);
|
||||
sprite_load_text_texture(s1, "GUI/SDS_8x8.ttf", 0, 25, 2);
|
||||
texture_load_from_text(s1->textures[0], menu_items[i].label,
|
||||
C_MENU_DEFAULT, gRenderer);
|
||||
C_MENU_DEFAULT, C_MENU_OUTLINE_DEFAULT, gRenderer);
|
||||
|
||||
hcenter = (SCREEN_WIDTH/2) - (s1->textures[0]->dim.width/2);
|
||||
s1->pos = (Position) { (int) hcenter, (int) 200 + (i*50) };
|
||||
|
@ -270,9 +271,9 @@ createMenu(Menu **menu, struct MENU_ITEM menu_items[], unsigned int size)
|
|||
s1->fixed = true;
|
||||
|
||||
Sprite *s2 = sprite_create();
|
||||
sprite_load_text_texture(s2, "GUI/SDS_8x8.ttf", 0, 25);
|
||||
sprite_load_text_texture(s2, "GUI/SDS_8x8.ttf", 0, 25, 2);
|
||||
texture_load_from_text(s2->textures[0], menu_items[i].label,
|
||||
C_MENU_HOVER, gRenderer);
|
||||
C_MENU_HOVER, C_MENU_OUTLINE_DEFAULT, gRenderer);
|
||||
|
||||
s2->pos = (Position) { (int) hcenter, (int) 200 + (i*50) };
|
||||
s2->dim = s2->textures[0]->dim;
|
||||
|
|
|
@ -279,8 +279,8 @@ monster_hit(Monster *monster, unsigned int dmg)
|
|||
p.y += 8;
|
||||
Dimension d = { 8, 8 };
|
||||
particle_engine_bloodspray(p, d, dmg);
|
||||
char msg[5];
|
||||
m_sprintf(msg, 5, "-%d", dmg);
|
||||
char msg[10];
|
||||
m_sprintf(msg, 10, "-%d", dmg);
|
||||
actiontextbuilder_create_text(msg,
|
||||
c_red,
|
||||
&monster->sprite->pos);
|
||||
|
|
12
src/player.c
12
src/player.c
|
@ -76,7 +76,7 @@ player_gain_xp(Player *player, unsigned int xp_gain)
|
|||
{
|
||||
static SDL_Color c_green = { 0, 255, 0, 255 };
|
||||
char msg[10];
|
||||
m_sprintf(msg, 5, "+%dxp", xp_gain);
|
||||
m_sprintf(msg, 10, "+%dxp", xp_gain);
|
||||
actiontextbuilder_create_text(msg, c_green, &player->sprite->pos);
|
||||
|
||||
player->xp += xp_gain;
|
||||
|
@ -121,6 +121,11 @@ has_collided(Player *player, RoomMatrix *matrix, Vector2d direction)
|
|||
RoomSpace *space = &matrix->spaces[matrixPos.x][matrixPos.y];
|
||||
collided = space->occupied;
|
||||
|
||||
if (collided) {
|
||||
player->sprite->pos.x -= TILE_DIMENSION * (int)direction.x;
|
||||
player->sprite->pos.y -= TILE_DIMENSION * (int)direction.y;
|
||||
}
|
||||
|
||||
if (space->monster != NULL) {
|
||||
unsigned int hit = stats_fight(&player->stats,
|
||||
&space->monster->stats);
|
||||
|
@ -185,10 +190,7 @@ move(Player *player, RoomMatrix *matrix, Vector2d direction)
|
|||
set_clip_for_direction(player, &direction);
|
||||
player->sprite->pos.x += TILE_DIMENSION * (int) direction.x;
|
||||
player->sprite->pos.y += TILE_DIMENSION * (int) direction.y;
|
||||
if (has_collided(player, matrix, direction)) {
|
||||
player->sprite->pos.x -= TILE_DIMENSION * (int) direction.x;
|
||||
player->sprite->pos.y -= TILE_DIMENSION * (int) direction.y;
|
||||
} else {
|
||||
if (!has_collided(player, matrix, direction)) {
|
||||
player_step(player);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer)
|
|||
s->pos = (Position) { i * 32 + 20, 20 };
|
||||
s->dim = (Dimension) { 8, 8 };
|
||||
s->fixed = true;
|
||||
sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, 8);
|
||||
sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, 8, 0);
|
||||
m_sprintf(buffer, 4, "%u", i+1 < 10 ? i+1 : 0);
|
||||
texture_load_from_text(s->textures[0], buffer, c_yellow, renderer);
|
||||
texture_load_from_text(s->textures[0], buffer, c_yellow, c_yellow, renderer);
|
||||
linkedlist_append(&bar->sprites, s);
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ load_countdown_sprites(SkillBar *bar)
|
|||
{
|
||||
for (int i = 0; i < PLAYER_SKILL_COUNT; ++i) {
|
||||
Sprite *s = sprite_create();
|
||||
sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, 16);
|
||||
sprite_load_text_texture(s, "GUI/SDS_8x8.ttf", 0, 16, 0);
|
||||
s->fixed = true;
|
||||
s->pos = (Position) { 8 + (32 * i), 8 };
|
||||
s->dim = (Dimension) { 16, 16 };
|
||||
|
@ -151,7 +151,7 @@ render_skill_countdown(SkillBar *bar, int index, unsigned int count, Camera *cam
|
|||
Sprite *s = bar->countdowns[index];
|
||||
|
||||
m_sprintf(buffer, 5, "%u", count);
|
||||
texture_load_from_text(s->textures[0], buffer, color, cam->renderer);
|
||||
texture_load_from_text(s->textures[0], buffer, color, color, cam->renderer);
|
||||
sprite_render(s, cam);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ sprite_load_texture(Sprite *sprite,
|
|||
sprite->destroyTextures = true;
|
||||
}
|
||||
|
||||
void sprite_load_text_texture(Sprite *sprite, char * path, int index, int size)
|
||||
void sprite_load_text_texture(Sprite *sprite, char * path, int index, int size, int outline)
|
||||
{
|
||||
if (index > 1)
|
||||
fatal("in sprite_load_texture() index out of bounds");
|
||||
|
@ -79,7 +79,7 @@ void sprite_load_text_texture(Sprite *sprite, char * path, int index, int size)
|
|||
}
|
||||
|
||||
sprite->textures[index] = texture_create();
|
||||
texture_load_font(sprite->textures[index], path, size);
|
||||
texture_load_font(sprite->textures[index], path, size, outline);
|
||||
sprite->destroyTextures = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ Sprite* sprite_create(void);
|
|||
|
||||
void sprite_load_texture(Sprite *, char *path, int index, SDL_Renderer *);
|
||||
|
||||
void sprite_load_text_texture(Sprite *, char *path, int index, int size);
|
||||
void sprite_load_text_texture(Sprite *, char *path, int index, int size, int outline);
|
||||
|
||||
void sprite_set_texture(Sprite *, Texture *, int index);
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ texture_create(void)
|
|||
t->dim.width = 0;
|
||||
t->texture = NULL;
|
||||
t->font = NULL;
|
||||
t->outlineFont = NULL;
|
||||
t->lastAccess = SDL_GetTicks();
|
||||
t->path = "";
|
||||
t->textureAccessType = SDL_TEXTUREACCESS_STATIC;
|
||||
|
@ -107,12 +108,18 @@ texture_load_from_file(Texture *texture,
|
|||
}
|
||||
|
||||
void
|
||||
texture_load_font(Texture *t, const char *path, unsigned int size)
|
||||
texture_load_font(Texture *t, const char *path, unsigned int size, int outline)
|
||||
{
|
||||
if (t->font)
|
||||
TTF_CloseFont(t->font);
|
||||
if (t->outlineFont)
|
||||
TTF_CloseFont(t->outlineFont);
|
||||
|
||||
t->font = TTF_OpenFontRW(io_load_rwops(path), true, size);
|
||||
if (outline) {
|
||||
t->outlineFont = TTF_OpenFontRW(io_load_rwops(path), true, size);
|
||||
TTF_SetFontOutline(t->outlineFont, outline);
|
||||
}
|
||||
|
||||
if (t->font == NULL) {
|
||||
error("Failed to load font %s: %s",
|
||||
|
@ -148,9 +155,28 @@ void
|
|||
texture_load_from_text(Texture *t,
|
||||
const char *text,
|
||||
SDL_Color c,
|
||||
SDL_Color oc,
|
||||
SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_Surface *surface = TTF_RenderText_Solid( t->font, text, c );
|
||||
SDL_Surface *bg_surface = NULL;
|
||||
SDL_Surface *fg_surface = NULL;
|
||||
if (t->outlineFont) {
|
||||
bg_surface = TTF_RenderText_Blended(t->outlineFont, text, oc);
|
||||
fg_surface = TTF_RenderText_Blended(t->font, text, c);
|
||||
}
|
||||
else {
|
||||
fg_surface = TTF_RenderText_Solid(t->font, text, c);
|
||||
}
|
||||
SDL_Surface *surface = fg_surface;
|
||||
if (bg_surface) {
|
||||
int outline = TTF_GetFontOutline(t->outlineFont);
|
||||
SDL_Rect rect = { outline, outline, fg_surface->w, fg_surface->h };
|
||||
SDL_SetSurfaceBlendMode(fg_surface, SDL_BLENDMODE_BLEND);
|
||||
SDL_BlitSurface(fg_surface, NULL, bg_surface, &rect);
|
||||
surface = bg_surface;
|
||||
SDL_FreeSurface(fg_surface);
|
||||
}
|
||||
|
||||
if (surface == NULL)
|
||||
{
|
||||
error("Unable to create texture from rendered text: %s",
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
typedef struct {
|
||||
SDL_Texture *texture;
|
||||
TTF_Font *font;
|
||||
TTF_Font *outlineFont;
|
||||
Dimension dim;
|
||||
const char *path;
|
||||
unsigned long lastAccess;
|
||||
|
@ -53,13 +54,14 @@ void
|
|||
texture_load_from_file(Texture*, const char *path, SDL_Renderer*);
|
||||
|
||||
void
|
||||
texture_load_font(Texture*, const char *path, unsigned int size);
|
||||
texture_load_font(Texture*, const char *path, unsigned int size, int outline);
|
||||
|
||||
void
|
||||
texture_load_from_text(Texture*,
|
||||
const char *text,
|
||||
SDL_Color,
|
||||
SDL_Renderer*);
|
||||
const char *text,
|
||||
SDL_Color,
|
||||
SDL_Color,
|
||||
SDL_Renderer*);
|
||||
|
||||
void
|
||||
texture_load_from_text_shaded(Texture*,
|
||||
|
|
Loading…
Reference in New Issue