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:
parent
06d2da164a
commit
c8900e8ddf
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.9 KiB |
|
@ -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_
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
13
src/main.c
13
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);
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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*);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -25,4 +25,4 @@ Sprite *
|
|||
tooltip_create(char **content, Camera*);
|
||||
|
||||
void
|
||||
tooltip_set_controller_mode(bool);
|
||||
tooltip_set_controller_mode(Uint8 ctrl_mode);
|
Loading…
Reference in New Issue