Adds controller button support for skillbar

This commit is contained in:
Linus Probert 2018-10-10 22:54:43 +02:00
parent c3b2b6f214
commit 2919ebf97f
2 changed files with 42 additions and 10 deletions

View File

@ -28,6 +28,26 @@
#include "update_data.h" #include "update_data.h"
#include "gui.h" #include "gui.h"
static bool controller_mode = false;
void
skillbar_set_controller_mode(bool ctrl_mode)
{
controller_mode = ctrl_mode;
}
static Sprite *
create_controller_button_sprite(Position pos, SDL_Rect clip)
{
Texture *t = texturecache_add("Extras/Controller.png");
Sprite *s = sprite_create();
sprite_set_texture(s, t, 0);
s->pos = pos;
s->clip = clip;
s->dim = DIM(16, 16);
return s;
}
static void static void
load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer) load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer)
{ {
@ -35,6 +55,7 @@ load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer)
t->dim.width = 16; t->dim.width = 16;
t->dim.height = 16; t->dim.height = 16;
if (!controller_mode) {
for (unsigned int i = 0; i < 5; ++i) { for (unsigned int i = 0; i < 5; ++i) {
char buffer[4]; char buffer[4];
Sprite *s = sprite_create(); Sprite *s = sprite_create();
@ -46,6 +67,14 @@ load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer)
texture_load_from_text(s->textures[0], buffer, C_YELLOW, C_BLACK, renderer); texture_load_from_text(s->textures[0], buffer, C_YELLOW, C_BLACK, renderer);
linkedlist_append(&bar->sprites, s); linkedlist_append(&bar->sprites, s);
} }
} else {
Uint8 i = 0;
linkedlist_append(&bar->sprites, create_controller_button_sprite(POS(i++ * 32 + 16, 16), CLIP16(0, 0)));
linkedlist_append(&bar->sprites, create_controller_button_sprite(POS(i++ * 32 + 16, 16), CLIP16(16, 0)));
linkedlist_append(&bar->sprites, create_controller_button_sprite(POS(i++ * 32 + 16, 16), CLIP16(32, 0)));
linkedlist_append(&bar->sprites, create_controller_button_sprite(POS(i++ * 32 + 16, 16), CLIP16(48, 0)));
linkedlist_append(&bar->sprites, create_controller_button_sprite(POS(i++ * 32 + 16, 20), CLIP16(48, 48)));
}
} }
static void static void

View File

@ -45,6 +45,9 @@ typedef struct SkillBar {
Uint32 lastActivation; Uint32 lastActivation;
} SkillBar; } SkillBar;
void
skillbar_set_controller_mode(bool ctrl_mode);
SkillBar * SkillBar *
skillbar_create(Camera*); skillbar_create(Camera*);