[Change] Improved the mod state handling and allow two keybindings on the same key.
This commit is contained in:
parent
b8991b37df
commit
0914172c53
79
src/input.c
79
src/input.c
@ -62,37 +62,37 @@ extern unsigned int player_target;
|
|||||||
*/
|
*/
|
||||||
void input_setDefault(void) {
|
void input_setDefault(void) {
|
||||||
/* Movement. */
|
/* Movement. */
|
||||||
input_setKeybind("accel", KEYBIND_KEYBOARD, SDLK_w, KMOD_NONE, 0);
|
input_setKeybind("accel", KEYBIND_KEYBOARD, SDLK_w, KMOD_ALL, 0);
|
||||||
input_setKeybind("afterburn", KEYBIND_KEYBOARD, SDLK_UNKNOWN, KMOD_NONE, 0); /*Not set.*/
|
input_setKeybind("afterburn", KEYBIND_KEYBOARD, SDLK_UNKNOWN, KMOD_ALL, 0);
|
||||||
input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, KMOD_NONE, 0);
|
input_setKeybind("left", KEYBIND_KEYBOARD, SDLK_a, KMOD_ALL, 0);
|
||||||
input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, KMOD_NONE, 0);
|
input_setKeybind("right", KEYBIND_KEYBOARD, SDLK_d, KMOD_ALL, 0);
|
||||||
input_setKeybind("reverse", KEYBIND_KEYBOARD, SDLK_s, KMOD_NONE, 0);
|
input_setKeybind("reverse", KEYBIND_KEYBOARD, SDLK_s, KMOD_ALL, 0);
|
||||||
/* Targetting. */
|
/* Targetting. */
|
||||||
input_setKeybind("target", KEYBIND_KEYBOARD, SDLK_TAB, KMOD_NONE, 0);
|
input_setKeybind("target", KEYBIND_KEYBOARD, SDLK_TAB, KMOD_NONE, 0);
|
||||||
input_setKeybind("target_nearest", KEYBIND_KEYBOARD, SDLK_t, KMOD_NONE, 0);
|
input_setKeybind("target_nearest", KEYBIND_KEYBOARD, SDLK_t, KMOD_NONE, 0);
|
||||||
input_setKeybind("target_hostile", KEYBIND_KEYBOARD, SDLK_r, KMOD_NONE, 0);
|
input_setKeybind("target_hostile", KEYBIND_KEYBOARD, SDLK_r, KMOD_NONE, 0);
|
||||||
/* Combat. */
|
/* Combat. */
|
||||||
input_setKeybind("primary", KEYBIND_KEYBOARD, SDLK_SPACE, KMOD_NONE, 0);
|
input_setKeybind("primary", KEYBIND_KEYBOARD, SDLK_SPACE, KMOD_NONE, 0);
|
||||||
input_setKeybind("face", KEYBIND_KEYBOARD, SDLK_f, KMOD_NONE, 0);
|
input_setKeybind("face", KEYBIND_KEYBOARD, SDLK_f, KMOD_NONE, 0);
|
||||||
input_setKeybind("board", KEYBIND_KEYBOARD, SDLK_b, KMOD_NONE, 0);
|
input_setKeybind("board", KEYBIND_KEYBOARD, SDLK_b, KMOD_NONE, 0);
|
||||||
/* Secondary weapon. */
|
/* Secondary weapon. */
|
||||||
input_setKeybind("secondary", KEYBIND_KEYBOARD, SDLK_LSHIFT, KMOD_NONE, 0);
|
input_setKeybind("secondary", KEYBIND_KEYBOARD, SDLK_LSHIFT, KMOD_NONE, 0);
|
||||||
input_setKeybind("secondary_next", KEYBIND_KEYBOARD, SDLK_e, KMOD_NONE, 0);
|
input_setKeybind("secondary_next", KEYBIND_KEYBOARD, SDLK_e, KMOD_NONE, 0);
|
||||||
/* Space */
|
/* 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("target_planet", KEYBIND_KEYBOARD, SDLK_p, KMOD_NONE, 0);
|
||||||
input_setKeybind("land", KEYBIND_KEYBOARD, SDLK_l, KMOD_NONE, 0);
|
input_setKeybind("land", KEYBIND_KEYBOARD, SDLK_l, KMOD_NONE, 0);
|
||||||
input_setKeybind("thyperspace", KEYBIND_KEYBOARD, SDLK_h, KMOD_NONE, 0);
|
input_setKeybind("thyperspace", KEYBIND_KEYBOARD, SDLK_h, KMOD_NONE, 0);
|
||||||
input_setKeybind("starmap", KEYBIND_KEYBOARD, SDLK_m, KMOD_NONE, 0);
|
input_setKeybind("starmap", KEYBIND_KEYBOARD, SDLK_m, KMOD_NONE, 0);
|
||||||
input_setKeybind("jump", KEYBIND_KEYBOARD, SDLK_j, KMOD_NONE, 0);
|
input_setKeybind("jump", KEYBIND_KEYBOARD, SDLK_j, KMOD_NONE, 0);
|
||||||
|
|
||||||
/* Misc. */
|
/* Misc. */
|
||||||
input_setKeybind("mapzoomin", KEYBIND_KEYBOARD, SDLK_KP_PLUS, KMOD_NONE, 0);
|
input_setKeybind("mapzoomin", KEYBIND_KEYBOARD, SDLK_KP_PLUS, KMOD_NONE, 0);
|
||||||
input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_KP_MINUS, KMOD_NONE, 0);
|
input_setKeybind("mapzoomout", KEYBIND_KEYBOARD, SDLK_KP_MINUS, KMOD_NONE, 0);
|
||||||
input_setKeybind("screenshot", KEYBIND_KEYBOARD, SDLK_KP_MULTIPLY, KMOD_NONE, 0);
|
input_setKeybind("screenshot", KEYBIND_KEYBOARD, SDLK_KP_MULTIPLY, KMOD_NONE, 0);
|
||||||
input_setKeybind("pause", KEYBIND_KEYBOARD, SDLK_F1, KMOD_NONE, 0);
|
input_setKeybind("pause", KEYBIND_KEYBOARD, SDLK_F1, KMOD_NONE, 0);
|
||||||
input_setKeybind("menu", KEYBIND_KEYBOARD, SDLK_ESCAPE, KMOD_NONE, 0);
|
input_setKeybind("menu", KEYBIND_KEYBOARD, SDLK_ESCAPE, KMOD_NONE, 0);
|
||||||
input_setKeybind("info", KEYBIND_KEYBOARD, SDLK_i, KMOD_NONE, 0);
|
input_setKeybind("info", KEYBIND_KEYBOARD, SDLK_i, KMOD_NONE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +111,8 @@ void input_init(void) {
|
|||||||
tmp = MALLOC_L(Keybind);
|
tmp = MALLOC_L(Keybind);
|
||||||
tmp->name = (char*)keybindNames[i];
|
tmp->name = (char*)keybindNames[i];
|
||||||
tmp->type = KEYBIND_NULL;
|
tmp->type = KEYBIND_NULL;
|
||||||
tmp->key = 0;
|
tmp->key = SDLK_UNKNOWN;
|
||||||
|
tmp->mod = KMOD_NONE;
|
||||||
tmp->reverse = 1.;
|
tmp->reverse = 1.;
|
||||||
input_keybinds[i] = tmp;
|
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 value The value of the keypress (defined above).
|
||||||
* @param abs Whether or not it's an absolute value (for the joystick).
|
* @param abs Whether or not it's an absolute value (for the joystick).
|
||||||
*/
|
*/
|
||||||
#define KEY(s) (((input_keybinds[keynum]->mod & mod) || \
|
#define KEY(s) (((input_keybinds[keynum]->mod == mod) || \
|
||||||
(input_keybinds[keynum]->mod == mod) || \
|
(input_keybinds[keynum]->mod==KMOD_ALL)) && \
|
||||||
(input_keybinds[keynum]->mod == KMOD_ALL)) && \
|
|
||||||
(strcmp(input_keybinds[keynum]->name, s)==0)) /**< Shortcut for ease. */
|
(strcmp(input_keybinds[keynum]->name, s)==0)) /**< Shortcut for ease. */
|
||||||
#define INGAME() (!toolkit) /**< Make sure player is in game. */
|
#define INGAME() (!toolkit) /**< Make sure player is in game. */
|
||||||
#define NOHYP() \
|
#define NOHYP() \
|
||||||
@ -194,6 +194,7 @@ static void input_key(int keynum, double value, int kabs) {
|
|||||||
SDLMod mod;
|
SDLMod mod;
|
||||||
|
|
||||||
mod = SDL_GetModState(); /* Yes, we always get it just in case. */
|
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. */
|
/* Accelerating. */
|
||||||
if(KEY("accel")) {
|
if(KEY("accel")) {
|
||||||
@ -389,10 +390,8 @@ static void input_joyaxis(const unsigned int axis, const int value) {
|
|||||||
int i;
|
int i;
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||||
if(input_keybinds[i]->type == KEYBIND_JAXIS &&
|
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);
|
input_key(i, -(input_keybinds[i]->reverse) * (double)value / 32767., 1);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Joystick button down. */
|
/* Joystick button down. */
|
||||||
@ -400,10 +399,8 @@ static void input_joydown(const unsigned int button) {
|
|||||||
int i;
|
int i;
|
||||||
for(i = 0; strcmp(keybindNames[i], "end");i++)
|
for(i = 0; strcmp(keybindNames[i], "end");i++)
|
||||||
if(input_keybinds[i]->type == KEYBIND_JBUTTON &&
|
if(input_keybinds[i]->type == KEYBIND_JBUTTON &&
|
||||||
input_keybinds[i]->key == button) {
|
input_keybinds[i]->key == button)
|
||||||
input_key(i, KEY_RELEASE, 0);
|
input_key(i, KEY_RELEASE, 0);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Joystick button up. */
|
/* Joystick button up. */
|
||||||
@ -411,10 +408,8 @@ static void input_joyup(const unsigned int button) {
|
|||||||
int i;
|
int i;
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||||
if(input_keybinds[i]->type == KEYBIND_JBUTTON &&
|
if(input_keybinds[i]->type == KEYBIND_JBUTTON &&
|
||||||
input_keybinds[i]->key == button) {
|
input_keybinds[i]->key == button)
|
||||||
input_key(i, KEY_RELEASE, 0);
|
input_key(i, KEY_RELEASE, 0);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keyboard. */
|
/* Keyboard. */
|
||||||
@ -424,10 +419,8 @@ static void input_keydown(SDLKey key) {
|
|||||||
int i;
|
int i;
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||||
if(input_keybinds[i]->type == KEYBIND_KEYBOARD &&
|
if(input_keybinds[i]->type == KEYBIND_KEYBOARD &&
|
||||||
input_keybinds[i]->key == key) {
|
input_keybinds[i]->key == key)
|
||||||
input_key(i, KEY_PRESS, 0);
|
input_key(i, KEY_PRESS, 0);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Key up. */
|
/* Key up. */
|
||||||
@ -435,10 +428,8 @@ static void input_keyup(SDLKey key) {
|
|||||||
int i;
|
int i;
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
||||||
if(input_keybinds[i]->type == KEYBIND_KEYBOARD &&
|
if(input_keybinds[i]->type == KEYBIND_KEYBOARD &&
|
||||||
input_keybinds[i]->key == key) {
|
input_keybinds[i]->key == key)
|
||||||
input_key(i, KEY_RELEASE, 0);
|
input_key(i, KEY_RELEASE, 0);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user