[Add] Making a start on making keybindings viewable with descriptions,

through a dialogue.
This commit is contained in:
Allanis 2014-03-15 19:54:25 +00:00
parent 77afa506e4
commit 1a8c08c4c2
3 changed files with 107 additions and 7 deletions

View File

@ -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)
*

View File

@ -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);

View File

@ -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);
}