From 2919ebf97fdf43056c8223ac5615e13acd36c099 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Wed, 10 Oct 2018 22:54:43 +0200 Subject: [PATCH] Adds controller button support for skillbar --- src/skillbar.c | 49 +++++++++++++++++++++++++++++++++++++++---------- src/skillbar.h | 3 +++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/skillbar.c b/src/skillbar.c index 167a3a5..85608e0 100644 --- a/src/skillbar.c +++ b/src/skillbar.c @@ -28,6 +28,26 @@ #include "update_data.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 load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer) { @@ -35,16 +55,25 @@ load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer) t->dim.width = 16; t->dim.height = 16; - for (unsigned int i = 0; i < 5; ++i) { - char buffer[4]; - Sprite *s = sprite_create(); - 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, 0); - m_sprintf(buffer, 4, "%u", i+1 < 10 ? i+1 : 0); - texture_load_from_text(s->textures[0], buffer, C_YELLOW, C_BLACK, renderer); - linkedlist_append(&bar->sprites, s); + if (!controller_mode) { + for (unsigned int i = 0; i < 5; ++i) { + char buffer[4]; + Sprite *s = sprite_create(); + 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, 0); + m_sprintf(buffer, 4, "%u", i + 1 < 10 ? i + 1 : 0); + texture_load_from_text(s->textures[0], buffer, C_YELLOW, C_BLACK, renderer); + 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))); } } diff --git a/src/skillbar.h b/src/skillbar.h index 2928faf..6c9437f 100644 --- a/src/skillbar.h +++ b/src/skillbar.h @@ -45,6 +45,9 @@ typedef struct SkillBar { Uint32 lastActivation; } SkillBar; +void +skillbar_set_controller_mode(bool ctrl_mode); + SkillBar * skillbar_create(Camera*);