diff --git a/assets/Extras/Controller.png b/assets/Extras/Controller.png index 8ee96de..d40f97a 100644 Binary files a/assets/Extras/Controller.png and b/assets/Extras/Controller.png differ diff --git a/src/defines.h b/src/defines.h index c465c0f..dc591e0 100644 --- a/src/defines.h +++ b/src/defines.h @@ -91,4 +91,9 @@ typedef enum Direction_t { UP, DOWN, LEFT, RIGHT } 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_ diff --git a/src/input.c b/src/input.c index 1767b65..251c1aa 100644 --- a/src/input.c +++ b/src/input.c @@ -119,6 +119,7 @@ get_event_button(SDL_Event *event) case SDL_CONTROLLER_BUTTON_BACK: key = KEY_ESC; break; case SDL_CONTROLLER_BUTTON_LEFTSTICK: + case SDL_CONTROLLER_BUTTON_RIGHTSTICK: key = KEY_SPACE; break; default: key = 0; break; @@ -142,11 +143,6 @@ get_axis_motion(SDL_Event *event) return key; } -static Uint32 -get_button_modkey(SDL_Event *event) { - -} - static Uint32 get_event_modkey(SDL_Event *event) { diff --git a/src/main.c b/src/main.c index 1356eee..b37fbe9 100644 --- a/src/main.c +++ b/src/main.c @@ -170,6 +170,7 @@ static SDL_Rect statsGuiViewport; static SDL_Rect minimapViewport; static SDL_Rect menuViewport; static Input input; +static Uint8 controllerMode = 0; #ifdef DEBUG static Sprite *fpsSprite = NULL; @@ -217,7 +218,13 @@ bool initSDL(void) gController = SDL_GameControllerOpen(i); 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; } } @@ -301,7 +308,7 @@ initGame(void) gCamera = camera_create(gRenderer); gRoomMatrix = roommatrix_create(); gGui = gui_create(gCamera); - skillbar_set_controller_mode(gController != NULL); + skillbar_set_controller_mode(controllerMode); gSkillBar = skillbar_create(gCamera); item_builder_init(gRenderer); #ifdef DEBUG @@ -543,7 +550,7 @@ init(void) hiscore_init(); initMainMenu(); - tooltip_set_controller_mode(gController != NULL); + tooltip_set_controller_mode(controllerMode); howto_tooltip = tooltip_create(how_to_play_tooltip, gCamera); new_skill_tooltip = tooltip_create(skills_tooltip, gCamera); new_artifact_tooltip = tooltip_create(artifacts_tooltip, gCamera); diff --git a/src/skillbar.c b/src/skillbar.c index 60fa34d..6ebe29d 100644 --- a/src/skillbar.c +++ b/src/skillbar.c @@ -28,10 +28,10 @@ #include "update_data.h" #include "gui.h" -static bool controller_mode = false; +static Uint8 controller_mode = 0; void -skillbar_set_controller_mode(bool ctrl_mode) +skillbar_set_controller_mode(Uint8 ctrl_mode) { controller_mode = ctrl_mode; } @@ -70,11 +70,11 @@ load_texture(SkillBar *bar, const char *path, SDL_Renderer *renderer) } } 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))); + 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), CONTROLLER_BTN(16, controller_mode))); + 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), CONTROLLER_BTN(48, controller_mode))); + linkedlist_append(&bar->sprites, create_controller_button_sprite(POS(i++ * 32 + 16, 20), CONTROLLER_BUMPER(32, controller_mode))); } } diff --git a/src/skillbar.h b/src/skillbar.h index 6c9437f..cd3b839 100644 --- a/src/skillbar.h +++ b/src/skillbar.h @@ -46,7 +46,7 @@ typedef struct SkillBar { } SkillBar; void -skillbar_set_controller_mode(bool ctrl_mode); +skillbar_set_controller_mode(Uint8 ctrl_mode); SkillBar * skillbar_create(Camera*); diff --git a/src/tooltip.c b/src/tooltip.c index 60e309e..aa49c91 100644 --- a/src/tooltip.c +++ b/src/tooltip.c @@ -23,7 +23,7 @@ #include "gui.h" #include "texturecache.h" -static bool controller_mode = false; +static Uint8 controller_mode = 0; static bool 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"); SDL_Rect clip; if (strcmp(text, "1") == 0) { - clip = CLIP16(0, 0); + clip = CONTROLLER_BTN(0, controller_mode); } else if (strcmp(text, "2") == 0) { - clip = CLIP16(16, 0); + clip = CONTROLLER_BTN(16, controller_mode); } else if (strcmp(text, "3") == 0) { - clip = CLIP16(32, 0); + clip = CONTROLLER_BTN(32, controller_mode); } else if (strcmp(text, "4") == 0) { - clip = CLIP16(48, 0); + clip = CONTROLLER_BTN(48, controller_mode); } else if (strcmp(text, "5") == 0) { - clip = CLIP16(48, 48); + clip = CONTROLLER_BUMPER(32, controller_mode); } else if (strcmp(text, "ESC") == 0) { - clip = CLIP16(0, 64); - } else if (strcmp(text, "SHIFT") == 0) { - clip = CLIP16(16, 48); + clip = CONTROLLER_OPT(32, controller_mode); + } else if (strcmp(text, "ENTER") == 0) { + clip = CONTROLLER_OPT(0, controller_mode); } else if (strcmp(text, "SPACE") == 0) { - clip = CLIP16(16, 32); + clip = CLIP16(0, 80); } else { return false; } @@ -118,7 +118,7 @@ tooltip_create(char **content, Camera *cam) } void -tooltip_set_controller_mode(bool ctrl_mode) +tooltip_set_controller_mode(Uint8 ctrl_mode) { controller_mode = ctrl_mode; } diff --git a/src/tooltip.h b/src/tooltip.h index 63fa25a..880a043 100644 --- a/src/tooltip.h +++ b/src/tooltip.h @@ -25,4 +25,4 @@ Sprite * tooltip_create(char **content, Camera*); void -tooltip_set_controller_mode(bool); \ No newline at end of file +tooltip_set_controller_mode(Uint8 ctrl_mode); \ No newline at end of file