diff --git a/src/input.c b/src/input.c index 527c590..5c50b5d 100644 --- a/src/input.c +++ b/src/input.c @@ -39,10 +39,10 @@ const char* keybindNames[] = { "target", "target_prev", "target_nearest", "target_hostile", /* Fighting. */ "primary", "face", "board", - /* Escorts. */ - "e_attack", "e_hold", "e_return", "e_clear", /* Secondary weapons. */ "secondary", "secondary_next", + /* Escorts. */ + "e_attack", "e_hold", "e_return", "e_clear", /* Space Navigation. */ "autonav", "target_planet", "land", "thyperspace","starmap", "jump", /* Communication. */ @@ -52,6 +52,48 @@ const char* keybindNames[] = { "end" /* Must terminate at the end. */ }; +const char* keybindDescription[] = { + /* Movement. */ + "Makes your ship accelerate forward.", + "Makes your ship turn left.", + "Makes your ship turn right.", + "Makes your ship turn around and face the direction you're moving from. Good for braking.", + "Makes your ship afterburn if you have an afterburner installed.", + /* Targetting. */ + "Cycles through ship targets.", + "Cycles backwards through ship targets.", + "Targets the nearest non-disabled ship.", + "Targets the nearest hostile ship.", + /* Fighting. */ + "Fires your primary weapons.", + "Faces your target (ship target if you have one, otherwise planet target).", + "Attempts to board your target ship.", + /* Secondary weapons. */ + "Fires your secondary weapon.", + "Cycles through secondary weapons.", + /* Escorts. */ + "Tells your escorts to attack your target.", + "Tells your escorts to hold their posistion.", + "Tells your escorts to return to your ships hanger.", + "Clears your escorts commands.", + /* Space navigation. */ + "Initializes the autonavigation system.", + "Cycles through hyperspace targets.", + "Attempt to land on your targetted planet or targets nearest landable planet. \ + Requests for landing if you don't have permission yet.", + "Cycles through hyperspace targets.", + "Opens the Star Map.", + /* Communication. */ + "Attempts to initialize communication with your taretted ship.", + /* Misc. */ + "Zooms in on your radar.", + "Zooms out on your radar.", + "Takes a screenshot.", + "Pauses the game.", + "Opens the small ingame menu.", + "Opens the information menu." +}; + /* Accel hacks. */ static unsigned int input_accelLast = 0; /**< Used to see if double tap. */ unsigned int input_afterburnSensibility = 200; /**< ms between taps to afterburn. */ @@ -85,8 +127,6 @@ void input_setDefault(void) { input_setKeybind("e_hold", KEYBIND_KEYBOARD, SDLK_2, KMOD_NONE, 0); input_setKeybind("e_return", KEYBIND_KEYBOARD, SDLK_3, KMOD_NONE, 0); input_setKeybind("e_clear", KEYBIND_KEYBOARD, SDLK_4, KMOD_NONE, 0); - - /* Secondary weapon. */ input_setKeybind("secondary", KEYBIND_KEYBOARD, SDLK_LALT, KMOD_ALL, 0); input_setKeybind("secondary_next", KEYBIND_KEYBOARD, SDLK_e, KMOD_NONE, 0); @@ -186,6 +226,18 @@ int input_getKeybind(char* keybind, KeybindType* type, SDLMod* mod, int* reverse return -1; } +/** + * + */ +const char* input_getKeybindDescription(char* keybind) { + int i; + for(i = 0; strcmp(keybindNames[i], "end"); i++) + if(strcmp(keybind, input_keybinds[i]->name)==0) + return keybindDescription[i]; + WARN("Unable to key keybinding description '%s', that cmmand doesn't exist", keybind); + return NULL; +} + /** * @fn static void input_key(int keynum, double value, int kabs) * diff --git a/src/input.h b/src/input.h index 96a3d0c..9e3db67 100644 --- a/src/input.h +++ b/src/input.h @@ -15,6 +15,7 @@ typedef enum { void input_setDefault(void); void input_setKeybind(char* keybind, KeybindType type, int key, SDLMod mod, int reverse); int input_getKeybind(char* keybind, KeybindType* type, SDLMod* mod, int* reverse); +const char* input_getKeybindDescription(char* keybind); /* Handle the events. */ void input_handle(SDL_Event* event); diff --git a/src/options.c b/src/options.c index 1b332a2..0fe7c55 100644 --- a/src/options.c +++ b/src/options.c @@ -13,13 +13,60 @@ #include "toolkit.h" #include "options.h" -#define KEYBIND_WIDTH 130 /**< Options menu width. */ -#define KEYBIND_HEIGHT 150 /**< Options menu height. */ +#define KEYBINDS_WIDTH 400 /**< Options menu width. */ +#define KEYBINDS_HEIGHT 300 /**< Options menu height. */ #define BUTTON_WIDTH 90 /**< Button width, standard across menus. */ #define BUTTON_HEIGHT 30 /**< Button height, standard across menus. */ -void opt_menuKeybinds(void) { +/* Extern. */ +extern const char* keybindNames[]; +static void menuKeybinds_update(unsigned int wid, char* name); + +/** + * @brief Opens the keybindings menu. + */ +void opt_menuKeybinds(void) { + int i, j; + unsigned int wid; + char** str; + + /* Create the window. */ + wid = window_create("Keybindings", -1, -1, KEYBINDS_WIDTH, KEYBINDS_HEIGHT); + window_addButton(wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, + "btnClose", "Close", window_close); + + /* Text stuff. */ + window_addText(wid, 200, -40, KEYBINDS_WIDTH-220, 30, 1, "txtName", + NULL, &cDConsole, NULL); + window_addText(wid, 200, -90, + KEYBINDS_WIDTH-220, KEYBINDS_HEIGHT-70-60-BUTTON_HEIGHT, + 0, "txtDesc", &gl_smallFont, NULL, NULL); + + /* 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]); + window_addList(wid, 20, -40, 160, KEYBINDS_HEIGHT-60, "lstKeybinds", + str, i-1, 0, menuKeybinds_update); + + /* Update the list. */ + menuKeybinds_update(wid, NULL); +} + +/** + * + */ +static void menuKeybinds_update(unsigned int wid, char* name) { + (void) name; + char* keybind; + const char* desc; + + keybind = toolkit_getList(wid, "lstKeybinds"); + window_modifyText(wid, "txtName", keybind); + desc = input_getKeybindDescription(keybind); + window_modifyText(wid, "txtDesc", (char*)desc); }