Controller button rendering based on controller type

Also added in the last button textures that I'd left out previously.
This commit is contained in:
Linus Probert 2018-10-11 20:12:11 +02:00
parent 06d2da164a
commit c8900e8ddf
8 changed files with 36 additions and 28 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -91,4 +91,9 @@ typedef enum Direction_t {
UP, DOWN, LEFT, RIGHT UP, DOWN, LEFT, RIGHT
} Direction; } Direction;
#define CONTROLLER_BTN(xindex, mode) CLIP16(xindex, mode == 1 ? 0 : 16)
#define CONTROLLER_TRIGGER(xindex, mode) CLIP16(xindex + (mode == 1 ? 16 : 0), 32)
#define CONTROLLER_BUMPER(xindex, mode) CLIP16(xindex + (mode == 1 ? 16 : 0), 48)
#define CONTROLLER_OPT(xindex, mode) CLIP16(xindex + (mode == 2 ? 16 : 0), 64)
#endif // DEFINES_H_ #endif // DEFINES_H_

View File

@ -119,6 +119,7 @@ get_event_button(SDL_Event *event)
case SDL_CONTROLLER_BUTTON_BACK: case SDL_CONTROLLER_BUTTON_BACK:
key = KEY_ESC; break; key = KEY_ESC; break;
case SDL_CONTROLLER_BUTTON_LEFTSTICK: case SDL_CONTROLLER_BUTTON_LEFTSTICK:
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
key = KEY_SPACE; break; key = KEY_SPACE; break;
default: default:
key = 0; break; key = 0; break;
@ -142,11 +143,6 @@ get_axis_motion(SDL_Event *event)
return key; return key;
} }
static Uint32
get_button_modkey(SDL_Event *event) {
}
static Uint32 static Uint32
get_event_modkey(SDL_Event *event) get_event_modkey(SDL_Event *event)
{ {

View File

@ -170,6 +170,7 @@ static SDL_Rect statsGuiViewport;
static SDL_Rect minimapViewport; static SDL_Rect minimapViewport;
static SDL_Rect menuViewport; static SDL_Rect menuViewport;
static Input input; static Input input;
static Uint8 controllerMode = 0;
#ifdef DEBUG #ifdef DEBUG
static Sprite *fpsSprite = NULL; static Sprite *fpsSprite = NULL;
@ -217,7 +218,13 @@ bool initSDL(void)
gController = SDL_GameControllerOpen(i); gController = SDL_GameControllerOpen(i);
if (gController) { if (gController) {
info("Game controller connected: %s", SDL_GameControllerName(gController)); const char *ctrlName = SDL_GameControllerName(gController);
info("Game controller connected: %s", ctrlName);
if (ctrlName[0] == 'P' && ctrlName[1] == 'S' && ctrlName[2] == '4')
controllerMode = 2;
else
controllerMode = 1;
break; break;
} }
} }
@ -301,7 +308,7 @@ initGame(void)
gCamera = camera_create(gRenderer); gCamera = camera_create(gRenderer);
gRoomMatrix = roommatrix_create(); gRoomMatrix = roommatrix_create();
gGui = gui_create(gCamera); gGui = gui_create(gCamera);
skillbar_set_controller_mode(gController != NULL); skillbar_set_controller_mode(controllerMode);
gSkillBar = skillbar_create(gCamera); gSkillBar = skillbar_create(gCamera);
item_builder_init(gRenderer); item_builder_init(gRenderer);
#ifdef DEBUG #ifdef DEBUG
@ -543,7 +550,7 @@ init(void)
hiscore_init(); hiscore_init();
initMainMenu(); initMainMenu();
tooltip_set_controller_mode(gController != NULL); tooltip_set_controller_mode(controllerMode);
howto_tooltip = tooltip_create(how_to_play_tooltip, gCamera); howto_tooltip = tooltip_create(how_to_play_tooltip, gCamera);
new_skill_tooltip = tooltip_create(skills_tooltip, gCamera); new_skill_tooltip = tooltip_create(skills_tooltip, gCamera);
new_artifact_tooltip = tooltip_create(artifacts_tooltip, gCamera); new_artifact_tooltip = tooltip_create(artifacts_tooltip, gCamera);

View File

@ -28,10 +28,10 @@
#include "update_data.h" #include "update_data.h"
#include "gui.h" #include "gui.h"
static bool controller_mode = false; static Uint8 controller_mode = 0;
void void
skillbar_set_controller_mode(bool ctrl_mode) skillbar_set_controller_mode(Uint8 ctrl_mode)
{ {
controller_mode = ctrl_mode; controller_mode = ctrl_mode;
} }
@ -70,11 +70,11 @@ load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer)
} }
} else { } else {
Uint8 i = 0; 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), CONTROLLER_BTN(0, controller_mode)));
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), CONTROLLER_BTN(16, controller_mode)));
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), CONTROLLER_BTN(32, controller_mode)));
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, 16), CONTROLLER_BTN(48, controller_mode)));
linkedlist_append(&bar->sprites, create_controller_button_sprite(POS(i++ * 32 + 16, 20), CLIP16(48, 48))); linkedlist_append(&bar->sprites, create_controller_button_sprite(POS(i++ * 32 + 16, 20), CONTROLLER_BUMPER(32, controller_mode)));
} }
} }

View File

@ -46,7 +46,7 @@ typedef struct SkillBar {
} SkillBar; } SkillBar;
void void
skillbar_set_controller_mode(bool ctrl_mode); skillbar_set_controller_mode(Uint8 ctrl_mode);
SkillBar * SkillBar *
skillbar_create(Camera*); skillbar_create(Camera*);

View File

@ -23,7 +23,7 @@
#include "gui.h" #include "gui.h"
#include "texturecache.h" #include "texturecache.h"
static bool controller_mode = false; static Uint8 controller_mode = 0;
static bool static bool
render_button_texture_for(const char *text, Position pos, Camera *cam) render_button_texture_for(const char *text, Position pos, Camera *cam)
@ -35,21 +35,21 @@ render_button_texture_for(const char *text, Position pos, Camera *cam)
Texture *t = texturecache_add("Extras/Controller.png"); Texture *t = texturecache_add("Extras/Controller.png");
SDL_Rect clip; SDL_Rect clip;
if (strcmp(text, "1") == 0) { if (strcmp(text, "1") == 0) {
clip = CLIP16(0, 0); clip = CONTROLLER_BTN(0, controller_mode);
} else if (strcmp(text, "2") == 0) { } else if (strcmp(text, "2") == 0) {
clip = CLIP16(16, 0); clip = CONTROLLER_BTN(16, controller_mode);
} else if (strcmp(text, "3") == 0) { } else if (strcmp(text, "3") == 0) {
clip = CLIP16(32, 0); clip = CONTROLLER_BTN(32, controller_mode);
} else if (strcmp(text, "4") == 0) { } else if (strcmp(text, "4") == 0) {
clip = CLIP16(48, 0); clip = CONTROLLER_BTN(48, controller_mode);
} else if (strcmp(text, "5") == 0) { } else if (strcmp(text, "5") == 0) {
clip = CLIP16(48, 48); clip = CONTROLLER_BUMPER(32, controller_mode);
} else if (strcmp(text, "ESC") == 0) { } else if (strcmp(text, "ESC") == 0) {
clip = CLIP16(0, 64); clip = CONTROLLER_OPT(32, controller_mode);
} else if (strcmp(text, "SHIFT") == 0) { } else if (strcmp(text, "ENTER") == 0) {
clip = CLIP16(16, 48); clip = CONTROLLER_OPT(0, controller_mode);
} else if (strcmp(text, "SPACE") == 0) { } else if (strcmp(text, "SPACE") == 0) {
clip = CLIP16(16, 32); clip = CLIP16(0, 80);
} else { } else {
return false; return false;
} }
@ -118,7 +118,7 @@ tooltip_create(char **content, Camera *cam)
} }
void void
tooltip_set_controller_mode(bool ctrl_mode) tooltip_set_controller_mode(Uint8 ctrl_mode)
{ {
controller_mode = ctrl_mode; controller_mode = ctrl_mode;
} }

View File

@ -25,4 +25,4 @@ Sprite *
tooltip_create(char **content, Camera*); tooltip_create(char **content, Camera*);
void void
tooltip_set_controller_mode(bool); tooltip_set_controller_mode(Uint8 ctrl_mode);