[Add] Some nice additions to keybinds menu, showing bindings in both
naviation/information pane.
This commit is contained in:
parent
9a61e0281a
commit
2be9749940
@ -212,7 +212,7 @@ void input_setKeybind(char* keybind, KeybindType type, int key,
|
|||||||
/**
|
/**
|
||||||
* @brief Get the value of a keybind.
|
* @brief Get the value of a keybind.
|
||||||
*/
|
*/
|
||||||
SDLKey input_getKeybind(char* keybind, KeybindType* type, SDLMod* mod, int* reverse) {
|
SDLKey input_getKeybind(const char* keybind, KeybindType* type, SDLMod* mod, int* reverse) {
|
||||||
int i;
|
int i;
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||||
if(strcmp(keybind, input_keybinds[i]->name)==0) {
|
if(strcmp(keybind, input_keybinds[i]->name)==0) {
|
||||||
|
@ -14,7 +14,7 @@ typedef enum {
|
|||||||
/* Set input. */
|
/* Set input. */
|
||||||
void input_setDefault(void);
|
void input_setDefault(void);
|
||||||
void input_setKeybind(char* keybind, KeybindType type, int key, SDLMod mod, int reverse);
|
void input_setKeybind(char* keybind, KeybindType type, int key, SDLMod mod, int reverse);
|
||||||
SDLKey input_getKeybind(char* keybind, KeybindType* type, SDLMod* mod, int* reverse);
|
SDLKey input_getKeybind(const char* keybind, KeybindType* type, SDLMod* mod, int* reverse);
|
||||||
const char* input_getKeybindDescription(char* keybind);
|
const char* input_getKeybindDescription(char* keybind);
|
||||||
|
|
||||||
/* Handle the events. */
|
/* Handle the events. */
|
||||||
|
@ -32,6 +32,10 @@ void opt_menuKeybinds(void) {
|
|||||||
int i, j;
|
int i, j;
|
||||||
unsigned int wid;
|
unsigned int wid;
|
||||||
char** str;
|
char** str;
|
||||||
|
SDLKey key;
|
||||||
|
KeybindType type;
|
||||||
|
SDLMod mod;
|
||||||
|
int reverse;
|
||||||
|
|
||||||
/* Create the window. */
|
/* Create the window. */
|
||||||
wid = window_create("Keybindings", -1, -1, KEYBINDS_WIDTH, KEYBINDS_HEIGHT);
|
wid = window_create("Keybindings", -1, -1, KEYBINDS_WIDTH, KEYBINDS_HEIGHT);
|
||||||
@ -48,8 +52,27 @@ void opt_menuKeybinds(void) {
|
|||||||
/* Create the list. */
|
/* Create the list. */
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++);
|
for(i = 0; strcmp(keybindNames[i], "end"); i++);
|
||||||
str = malloc(sizeof(char*) * (i-1));
|
str = malloc(sizeof(char*) * (i-1));
|
||||||
for(j = 0; j < i; j++)
|
for(j = 0; j < i; j++) {
|
||||||
str[j] = strdup(keybindNames[j]);
|
str[j] = malloc(sizeof(char) * 64);
|
||||||
|
key = input_getKeybind(keybindNames[j], &type, &mod, &reverse);
|
||||||
|
switch(type) {
|
||||||
|
case KEYBIND_KEYBOARD:
|
||||||
|
if(isalpha(key))
|
||||||
|
snprintf(str[j], 64, "%s <%c>", keybindNames[j], toupper(key));
|
||||||
|
else
|
||||||
|
snprintf(str[j], 64, "%s <%s>", keybindNames[j], SDL_GetKeyName(key));
|
||||||
|
break;
|
||||||
|
case KEYBIND_JAXIS:
|
||||||
|
snprintf(str[j], 64, "%s <jb%d>", keybindNames[j], key);
|
||||||
|
break;
|
||||||
|
case KEYBIND_JBUTTON:
|
||||||
|
snprintf(str[j], 64, "%s <ja%d>", keybindNames[j], key);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
snprintf(str[j], 64, keybindNames[j]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
window_addList(wid, 20, -40, 160, KEYBINDS_HEIGHT-60, "lstKeybinds",
|
window_addList(wid, 20, -40, 160, KEYBINDS_HEIGHT-60, "lstKeybinds",
|
||||||
str, i-1, 0, menuKeybinds_update);
|
str, i-1, 0, menuKeybinds_update);
|
||||||
|
|
||||||
@ -80,7 +103,8 @@ static const char* modToText(SDLMod mod) {
|
|||||||
*/
|
*/
|
||||||
static void menuKeybinds_update(unsigned int wid, char* name) {
|
static void menuKeybinds_update(unsigned int wid, char* name) {
|
||||||
(void) name;
|
(void) name;
|
||||||
char* keybind;
|
int i;
|
||||||
|
char* selected, keybind[32];
|
||||||
const char* desc;
|
const char* desc;
|
||||||
|
|
||||||
SDLKey key;
|
SDLKey key;
|
||||||
@ -92,7 +116,12 @@ static void menuKeybinds_update(unsigned int wid, char* name) {
|
|||||||
char bind[32];
|
char bind[32];
|
||||||
|
|
||||||
/* Get the keybind. */
|
/* Get the keybind. */
|
||||||
keybind = toolkit_getList(wid, "lstKeybinds");
|
selected = toolkit_getList(wid, "lstKeybinds");
|
||||||
|
|
||||||
|
/* Remove the axcess. */
|
||||||
|
for(i = 0; (selected[i] != '\0') && (selected[i] != ' '); i++)
|
||||||
|
keybind[i] = selected[i];
|
||||||
|
keybind[i] = '\0';
|
||||||
window_modifyText(wid, "txtName", keybind);
|
window_modifyText(wid, "txtName", keybind);
|
||||||
|
|
||||||
/* Get information. */
|
/* Get information. */
|
||||||
@ -105,15 +134,16 @@ static void menuKeybinds_update(unsigned int wid, char* name) {
|
|||||||
snprintf(bind, 64, "Not bound");
|
snprintf(bind, 64, "Not bound");
|
||||||
break;
|
break;
|
||||||
case KEYBIND_KEYBOARD:
|
case KEYBIND_KEYBOARD:
|
||||||
snprintf(pre, 32, "keyboard: %s%s",
|
if(isalpha(key))
|
||||||
|
snprintf(bind, 32, "keyboard: %s%s%c",
|
||||||
(mod != KMOD_NONE) ? modToText(mod) : "",
|
(mod != KMOD_NONE) ? modToText(mod) : "",
|
||||||
(mod != KMOD_NONE) ? " + " : "");
|
(mod != KMOD_NONE) ? " + " : "",
|
||||||
|
toupper(key));
|
||||||
/* Is key. */
|
|
||||||
if(isalnum(key))
|
|
||||||
snprintf(bind, 32, "%s%c", pre, toupper((char)key));
|
|
||||||
else
|
else
|
||||||
snprintf(bind, 32, "%s<%d>", pre, key);
|
snprintf(bind, 32, "keyboard: %s%s%s",
|
||||||
|
(mod != KMOD_NONE) ? modToText(mod) : "",
|
||||||
|
(mod != KMOD_NONE) ? " + " : "",
|
||||||
|
SDL_GetKeyName(key));
|
||||||
break;
|
break;
|
||||||
case KEYBIND_JAXIS:
|
case KEYBIND_JAXIS:
|
||||||
snprintf(bind, 64, "joy axis: <%d>%s", key, (reverse) ? " rev" : "");
|
snprintf(bind, 64, "joy axis: <%d>%s", key, (reverse) ? " rev" : "");
|
||||||
|
Loading…
Reference in New Issue
Block a user