[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.
|
||||
*/
|
||||
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;
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||
if(strcmp(keybind, input_keybinds[i]->name)==0) {
|
||||
|
@ -14,7 +14,7 @@ typedef enum {
|
||||
/* Set input. */
|
||||
void input_setDefault(void);
|
||||
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);
|
||||
|
||||
/* Handle the events. */
|
||||
|
@ -32,6 +32,10 @@ void opt_menuKeybinds(void) {
|
||||
int i, j;
|
||||
unsigned int wid;
|
||||
char** str;
|
||||
SDLKey key;
|
||||
KeybindType type;
|
||||
SDLMod mod;
|
||||
int reverse;
|
||||
|
||||
/* Create the window. */
|
||||
wid = window_create("Keybindings", -1, -1, KEYBINDS_WIDTH, KEYBINDS_HEIGHT);
|
||||
@ -48,8 +52,27 @@ void opt_menuKeybinds(void) {
|
||||
/* Create the list. */
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++);
|
||||
str = malloc(sizeof(char*) * (i-1));
|
||||
for(j = 0; j < i; j++)
|
||||
str[j] = strdup(keybindNames[j]);
|
||||
for(j = 0; j < i; 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",
|
||||
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) {
|
||||
(void) name;
|
||||
char* keybind;
|
||||
int i;
|
||||
char* selected, keybind[32];
|
||||
const char* desc;
|
||||
|
||||
SDLKey key;
|
||||
@ -92,7 +116,12 @@ static void menuKeybinds_update(unsigned int wid, char* name) {
|
||||
char bind[32];
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Get information. */
|
||||
@ -105,15 +134,16 @@ static void menuKeybinds_update(unsigned int wid, char* name) {
|
||||
snprintf(bind, 64, "Not bound");
|
||||
break;
|
||||
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) ? " + " : "");
|
||||
|
||||
/* Is key. */
|
||||
if(isalnum(key))
|
||||
snprintf(bind, 32, "%s%c", pre, toupper((char)key));
|
||||
(mod != KMOD_NONE) ? " + " : "",
|
||||
toupper(key));
|
||||
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;
|
||||
case KEYBIND_JAXIS:
|
||||
snprintf(bind, 64, "joy axis: <%d>%s", key, (reverse) ? " rev" : "");
|
||||
|
Loading…
Reference in New Issue
Block a user