/** * @brief Unsets the key. */ static void opt_unsetKey( unsigned int wid, char *str ) { (void) str; unsigned int parent; /* Unsets the keybind. */ input_setKeybind( opt_selectedKeybind, KEYBIND_NULL, 0, 0 ); /* Close window. */ window_close( wid, NULL ); /* Update parent window. */ parent = window_getParent( wid ); window_destroyWidget( parent, "lstKeybinds" ); menuKeybinds_genList( parent ); }
/** * @brief Tries to set the key from an event. */ static int opt_setKeyEvent( unsigned int wid, SDL_Event *event ) { unsigned int parent; KeybindType type; int key; SDLMod mod, ev_mod; const char *str; int pos, off; /* See how to handle it. */ switch (event->type) { case SDL_KEYDOWN: key = event->key.keysym.sym; /* If control key make player hit twice. */ if (((key == SDLK_NUMLOCK) || (key == SDLK_CAPSLOCK) || (key == SDLK_SCROLLOCK) || (key == SDLK_RSHIFT) || (key == SDLK_LSHIFT) || (key == SDLK_RCTRL) || (key == SDLK_LCTRL) || (key == SDLK_RALT) || (key == SDLK_LALT) || (key == SDLK_RMETA) || (key == SDLK_LMETA) || (key == SDLK_LSUPER) || (key == SDLK_RSUPER)) && (opt_lastKeyPress != key)) { opt_lastKeyPress = key; return 0; } type = KEYBIND_KEYBOARD; if (window_checkboxState( wid, "chkAny" )) mod = NMOD_ALL; else { ev_mod = event->key.keysym.mod; mod = 0; if (ev_mod & (KMOD_LSHIFT | KMOD_RSHIFT)) mod |= NMOD_SHIFT; if (ev_mod & (KMOD_LCTRL | KMOD_RCTRL)) mod |= NMOD_CTRL; if (ev_mod & (KMOD_LALT | KMOD_RALT)) mod |= NMOD_ALT; if (ev_mod & (KMOD_LMETA | KMOD_RMETA)) mod |= NMOD_META; } /* Set key. */ opt_lastKeyPress = key; break; case SDL_JOYAXISMOTION: if (event->jaxis.value > 0) type = KEYBIND_JAXISPOS; else if (event->jaxis.value < 0) type = KEYBIND_JAXISNEG; else return 0; /* Not handled. */ key = event->jaxis.axis; mod = NMOD_ALL; break; case SDL_JOYBUTTONDOWN: type = KEYBIND_JBUTTON; key = event->jbutton.button; mod = NMOD_ALL; break; /* Not handled. */ default: return 0; } /* Warn if already bound. */ str = input_keyAlreadyBound( type, key, mod ); if ((str != NULL) && strcmp(str, opt_selectedKeybind)) dialogue_alert( "Key '%s' overlaps with key '%s' that was just set. " "You may want to correct this.", str, opt_selectedKeybind ); /* Set keybinding. */ input_setKeybind( opt_selectedKeybind, type, key, mod ); /* Close window. */ window_close( wid, NULL ); /* Update parent window. */ parent = window_getParent( wid ); pos = toolkit_getListPos( parent, "lstKeybinds" ); off = toolkit_getListOffset( parent, "lstKeybinds" ); window_destroyWidget( parent, "lstKeybinds" ); menuKeybinds_genList( parent ); toolkit_setListPos( parent, "lstKeybinds", pos ); toolkit_setListOffset( parent, "lstKeybinds", off ); return 0; }
/** * @brief Sets the default input keys. * * @param wasd Whether to use the WASD layout. */ void input_setDefault ( int wasd ) { /* Movement */ if (wasd) { input_setKeybind( "accel", KEYBIND_KEYBOARD, SDLK_w, NMOD_ALL ); input_setKeybind( "left", KEYBIND_KEYBOARD, SDLK_a, NMOD_ALL ); input_setKeybind( "right", KEYBIND_KEYBOARD, SDLK_d, NMOD_ALL ); input_setKeybind( "reverse", KEYBIND_KEYBOARD, SDLK_s, NMOD_NONE ); } else { input_setKeybind( "accel", KEYBIND_KEYBOARD, SDLK_UP, NMOD_ALL ); input_setKeybind( "left", KEYBIND_KEYBOARD, SDLK_LEFT, NMOD_ALL ); input_setKeybind( "right", KEYBIND_KEYBOARD, SDLK_RIGHT, NMOD_ALL ); input_setKeybind( "reverse", KEYBIND_KEYBOARD, SDLK_DOWN, NMOD_ALL ); } /* Targeting */ if (wasd) { input_setKeybind( "target_next", KEYBIND_KEYBOARD, SDLK_e, NMOD_CTRL ); input_setKeybind( "target_prev", KEYBIND_KEYBOARD, SDLK_q, NMOD_CTRL ); input_setKeybind( "target_nearest", KEYBIND_KEYBOARD, SDLK_t, NMOD_ALL ); input_setKeybind( "target_nextHostile", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); input_setKeybind( "target_prevHostile", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); input_setKeybind( "target_hostile", KEYBIND_KEYBOARD, SDLK_r, NMOD_ALL ); input_setKeybind( "target_clear", KEYBIND_KEYBOARD, SDLK_c, NMOD_ALL ); } else { input_setKeybind( "target_next", KEYBIND_KEYBOARD, SDLK_t, NMOD_NONE ); input_setKeybind( "target_prev", KEYBIND_KEYBOARD, SDLK_t, NMOD_CTRL ); input_setKeybind( "target_nearest", KEYBIND_KEYBOARD, SDLK_n, NMOD_NONE ); input_setKeybind( "target_nextHostile", KEYBIND_KEYBOARD, SDLK_r, NMOD_CTRL ); input_setKeybind( "target_prevHostile", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); input_setKeybind( "target_hostile", KEYBIND_KEYBOARD, SDLK_r, NMOD_NONE ); input_setKeybind( "target_clear", KEYBIND_KEYBOARD, SDLK_BACKSPACE, NMOD_ALL ); } /* Combat */ input_setKeybind( "primary", KEYBIND_KEYBOARD, SDLK_SPACE, NMOD_ALL ); if (wasd) input_setKeybind( "face", KEYBIND_KEYBOARD, SDLK_q, NMOD_NONE ); else input_setKeybind( "face", KEYBIND_KEYBOARD, SDLK_a, NMOD_ALL ); input_setKeybind( "board", KEYBIND_KEYBOARD, SDLK_b, NMOD_NONE ); /* Secondary Weapons */ input_setKeybind( "secondary", KEYBIND_KEYBOARD, SDLK_LSHIFT, NMOD_ALL ); input_setKeybind( "weapset1", KEYBIND_KEYBOARD, SDLK_1, NMOD_ALL ); input_setKeybind( "weapset2", KEYBIND_KEYBOARD, SDLK_2, NMOD_ALL ); input_setKeybind( "weapset3", KEYBIND_KEYBOARD, SDLK_3, NMOD_ALL ); input_setKeybind( "weapset4", KEYBIND_KEYBOARD, SDLK_4, NMOD_ALL ); input_setKeybind( "weapset5", KEYBIND_KEYBOARD, SDLK_5, NMOD_ALL ); input_setKeybind( "weapset6", KEYBIND_KEYBOARD, SDLK_6, NMOD_ALL ); input_setKeybind( "weapset7", KEYBIND_KEYBOARD, SDLK_7, NMOD_ALL ); input_setKeybind( "weapset8", KEYBIND_KEYBOARD, SDLK_8, NMOD_ALL ); input_setKeybind( "weapset9", KEYBIND_KEYBOARD, SDLK_9, NMOD_ALL ); input_setKeybind( "weapset0", KEYBIND_KEYBOARD, SDLK_0, NMOD_ALL ); /* Escorts */ input_setKeybind( "e_targetNext", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); input_setKeybind( "e_targetPrev", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); input_setKeybind( "e_attack", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); input_setKeybind( "e_hold", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); input_setKeybind( "e_return", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); input_setKeybind( "e_clear", KEYBIND_NULL, SDLK_UNKNOWN, NMOD_NONE ); /* Space Navigation */ input_setKeybind( "autonav", KEYBIND_KEYBOARD, SDLK_j, NMOD_CTRL ); input_setKeybind( "target_planet", KEYBIND_KEYBOARD, SDLK_p, NMOD_NONE ); input_setKeybind( "land", KEYBIND_KEYBOARD, SDLK_l, NMOD_NONE ); input_setKeybind( "thyperspace", KEYBIND_KEYBOARD, SDLK_h, NMOD_NONE ); input_setKeybind( "starmap", KEYBIND_KEYBOARD, SDLK_m, NMOD_NONE ); input_setKeybind( "jump", KEYBIND_KEYBOARD, SDLK_j, NMOD_NONE ); input_setKeybind( "overlay", KEYBIND_KEYBOARD, SDLK_TAB, NMOD_ALL ); input_setKeybind( "mousefly", KEYBIND_KEYBOARD, SDLK_x, NMOD_CTRL ); input_setKeybind( "autobrake", KEYBIND_KEYBOARD, SDLK_s, NMOD_CTRL ); /* Communication */ input_setKeybind( "log_up", KEYBIND_KEYBOARD, SDLK_PAGEUP, NMOD_ALL ); input_setKeybind( "log_down", KEYBIND_KEYBOARD, SDLK_PAGEDOWN, NMOD_ALL ); input_setKeybind( "hail", KEYBIND_KEYBOARD, SDLK_y, NMOD_NONE ); input_setKeybind( "autohail", KEYBIND_KEYBOARD, SDLK_y, NMOD_CTRL ); /* Misc. */ input_setKeybind( "mapzoomin", KEYBIND_KEYBOARD, SDLK_KP_PLUS, NMOD_ALL ); input_setKeybind( "mapzoomout", KEYBIND_KEYBOARD, SDLK_KP_MINUS, NMOD_ALL ); input_setKeybind( "screenshot", KEYBIND_KEYBOARD, SDLK_KP_MULTIPLY, NMOD_ALL ); input_setKeybind( "togglefullscreen", KEYBIND_KEYBOARD, SDLK_F11, NMOD_ALL ); input_setKeybind( "pause", KEYBIND_KEYBOARD, SDLK_PAUSE, NMOD_ALL ); input_setKeybind( "speed", KEYBIND_KEYBOARD, SDLK_BACKQUOTE, NMOD_ALL ); input_setKeybind( "menu", KEYBIND_KEYBOARD, SDLK_ESCAPE, NMOD_ALL ); input_setKeybind( "info", KEYBIND_KEYBOARD, SDLK_i, NMOD_NONE ); input_setKeybind( "console", KEYBIND_KEYBOARD, SDLK_F2, NMOD_ALL ); input_setKeybind( "switchtab1", KEYBIND_KEYBOARD, SDLK_1, NMOD_ALT ); input_setKeybind( "switchtab2", KEYBIND_KEYBOARD, SDLK_2, NMOD_ALT ); input_setKeybind( "switchtab3", KEYBIND_KEYBOARD, SDLK_3, NMOD_ALT ); input_setKeybind( "switchtab4", KEYBIND_KEYBOARD, SDLK_4, NMOD_ALT ); input_setKeybind( "switchtab5", KEYBIND_KEYBOARD, SDLK_5, NMOD_ALT ); input_setKeybind( "switchtab6", KEYBIND_KEYBOARD, SDLK_6, NMOD_ALT ); input_setKeybind( "switchtab7", KEYBIND_KEYBOARD, SDLK_7, NMOD_ALT ); input_setKeybind( "switchtab8", KEYBIND_KEYBOARD, SDLK_8, NMOD_ALT ); input_setKeybind( "switchtab9", KEYBIND_KEYBOARD, SDLK_9, NMOD_ALT ); input_setKeybind( "switchtab0", KEYBIND_KEYBOARD, SDLK_0, NMOD_ALT ); }