[Change] Improved the mod state handling and allow two keybindings on the same key.
This commit is contained in:
parent
b8991b37df
commit
0914172c53
41
src/input.c
41
src/input.c
@ -62,11 +62,11 @@ extern unsigned int player_target;
|
||||
*/
|
||||
void input_setDefault(void) {
|
||||
/* Movement. */
|
||||
input_setKeybind("accel", KEYBIND_KEYBOARD, SDLK_w, KMOD_NONE, 0);
|
||||
input_setKeybind("afterburn", KEYBIND_KEYBOARD, SDLK_UNKNOWN, KMOD_NONE, 0); /*Not set.*/
|
||||
input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, KMOD_NONE, 0);
|
||||
input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, KMOD_NONE, 0);
|
||||
input_setKeybind("reverse", KEYBIND_KEYBOARD, SDLK_s, KMOD_NONE, 0);
|
||||
input_setKeybind("accel", KEYBIND_KEYBOARD, SDLK_w, KMOD_ALL, 0);
|
||||
input_setKeybind("afterburn", KEYBIND_KEYBOARD, SDLK_UNKNOWN, KMOD_ALL, 0);
|
||||
input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, KMOD_ALL, 0);
|
||||
input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, KMOD_ALL, 0);
|
||||
input_setKeybind("reverse", KEYBIND_KEYBOARD, SDLK_s, KMOD_ALL, 0);
|
||||
/* Targetting. */
|
||||
input_setKeybind("target", KEYBIND_KEYBOARD, SDLK_TAB, KMOD_NONE, 0);
|
||||
input_setKeybind("target_nearest", KEYBIND_KEYBOARD, SDLK_t, KMOD_NONE, 0);
|
||||
@ -79,7 +79,7 @@ void input_setDefault(void) {
|
||||
input_setKeybind("secondary", KEYBIND_KEYBOARD, SDLK_LSHIFT, KMOD_NONE, 0);
|
||||
input_setKeybind("secondary_next", KEYBIND_KEYBOARD, SDLK_e, KMOD_NONE, 0);
|
||||
/* Space */
|
||||
input_setKeybind("autonav", KEYBIND_KEYBOARD, SDLK_n, KMOD_CTRL, 0);
|
||||
input_setKeybind("autonav", KEYBIND_KEYBOARD, SDLK_j, KMOD_LCTRL, 0);
|
||||
input_setKeybind("target_planet", KEYBIND_KEYBOARD, SDLK_p, KMOD_NONE, 0);
|
||||
input_setKeybind("land", KEYBIND_KEYBOARD, SDLK_l, KMOD_NONE, 0);
|
||||
input_setKeybind("thyperspace", KEYBIND_KEYBOARD, SDLK_h, KMOD_NONE, 0);
|
||||
@ -111,7 +111,8 @@ void input_init(void) {
|
||||
tmp = MALLOC_L(Keybind);
|
||||
tmp->name = (char*)keybindNames[i];
|
||||
tmp->type = KEYBIND_NULL;
|
||||
tmp->key = 0;
|
||||
tmp->key = SDLK_UNKNOWN;
|
||||
tmp->mod = KMOD_NONE;
|
||||
tmp->reverse = 1.;
|
||||
input_keybinds[i] = tmp;
|
||||
}
|
||||
@ -180,9 +181,8 @@ int input_getKeybind(char* keybind, KeybindType* type, SDLMod* mod, int* reverse
|
||||
* @param value The value of the keypress (defined above).
|
||||
* @param abs Whether or not it's an absolute value (for the joystick).
|
||||
*/
|
||||
#define KEY(s) (((input_keybinds[keynum]->mod & mod) || \
|
||||
(input_keybinds[keynum]->mod == mod) || \
|
||||
(input_keybinds[keynum]->mod == KMOD_ALL)) && \
|
||||
#define KEY(s) (((input_keybinds[keynum]->mod == mod) || \
|
||||
(input_keybinds[keynum]->mod==KMOD_ALL)) && \
|
||||
(strcmp(input_keybinds[keynum]->name, s)==0)) /**< Shortcut for ease. */
|
||||
#define INGAME() (!toolkit) /**< Make sure player is in game. */
|
||||
#define NOHYP() \
|
||||
@ -194,6 +194,7 @@ static void input_key(int keynum, double value, int kabs) {
|
||||
SDLMod mod;
|
||||
|
||||
mod = SDL_GetModState(); /* Yes, we always get it just in case. */
|
||||
mod &= ~(KMOD_CAPS | KMOD_NUM | KMOD_MODE); /* We want to ignore "global" modifiers. */
|
||||
|
||||
/* Accelerating. */
|
||||
if(KEY("accel")) {
|
||||
@ -389,10 +390,8 @@ static void input_joyaxis(const unsigned int axis, const int value) {
|
||||
int i;
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||
if(input_keybinds[i]->type == KEYBIND_JAXIS &&
|
||||
input_keybinds[i]->key == axis) {
|
||||
input_keybinds[i]->key == axis)
|
||||
input_key(i, -(input_keybinds[i]->reverse) * (double)value / 32767., 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Joystick button down. */
|
||||
@ -400,10 +399,8 @@ static void input_joydown(const unsigned int button) {
|
||||
int i;
|
||||
for(i = 0; strcmp(keybindNames[i], "end");i++)
|
||||
if(input_keybinds[i]->type == KEYBIND_JBUTTON &&
|
||||
input_keybinds[i]->key == button) {
|
||||
input_keybinds[i]->key == button)
|
||||
input_key(i, KEY_RELEASE, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Joystick button up. */
|
||||
@ -411,10 +408,8 @@ static void input_joyup(const unsigned int button) {
|
||||
int i;
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||
if(input_keybinds[i]->type == KEYBIND_JBUTTON &&
|
||||
input_keybinds[i]->key == button) {
|
||||
input_keybinds[i]->key == button)
|
||||
input_key(i, KEY_RELEASE, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Keyboard. */
|
||||
@ -424,10 +419,8 @@ static void input_keydown(SDLKey key) {
|
||||
int i;
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||
if(input_keybinds[i]->type == KEYBIND_KEYBOARD &&
|
||||
input_keybinds[i]->key == key) {
|
||||
input_keybinds[i]->key == key)
|
||||
input_key(i, KEY_PRESS, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Key up. */
|
||||
@ -435,10 +428,8 @@ static void input_keyup(SDLKey key) {
|
||||
int i;
|
||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||
if(input_keybinds[i]->type == KEYBIND_KEYBOARD &&
|
||||
input_keybinds[i]->key == key) {
|
||||
input_keybinds[i]->key == key)
|
||||
input_key(i, KEY_RELEASE, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user