Add menu commands + fixes

This commit is contained in:
Johnny on Flame 2013-01-26 17:34:53 -02:00 committed by Bill Currie
parent ee436d89f6
commit e3e0d6aaa9
4 changed files with 111 additions and 5 deletions

View file

@ -146,4 +146,9 @@ int Menu_KeyEvent (knum_t key, short unicode, qboolean down);
void Menu_Enter (void); void Menu_Enter (void);
void Menu_Leave (void); void Menu_Leave (void);
void Menu_Enter_f (void);
void Menu_Leave_f (void);
void Menu_Prev_f (void);
void Menu_Next_f (void);
#endif // __console_h #endif // __console_h

View file

@ -51,6 +51,7 @@ typedef enum {
} js_dest_t; } js_dest_t;
typedef enum { typedef enum {
js_clear,
js_amp, js_amp,
js_pre_amp, js_pre_amp,
js_deadzone, js_deadzone,
@ -94,6 +95,7 @@ extern struct joy_button joy_buttons[JOY_MAX_BUTTONS];
joy_enable->int_val are zero. joy_enable->int_val are zero.
*/ */
void JOY_Command (void); void JOY_Command (void);
void joy_clear_axis (int i);
/* /*
JOY_Move (usercmd_t *) // FIXME: Not anymore! JOY_Move (usercmd_t *) // FIXME: Not anymore!

View file

@ -452,6 +452,26 @@ bi_Menu_Enter (progs_t *pr)
} }
} }
static void
bi_Menu_Leave (progs_t *pr)
{
if (menu) {
if (menu->leave_hook) {
run_menu_pre ();
PR_ExecuteProgram (&menu_pr_state, menu->leave_hook);
run_menu_post ();
}
menu = menu->parent;
if (!menu) {
if (con_data.force_commandline) {
Key_SetKeyDest (key_console);
} else {
Key_SetKeyDest (key_game);
}
}
}
}
static void static void
togglemenu_f (void) togglemenu_f (void)
{ {
@ -517,9 +537,38 @@ static builtin_t builtins[] = {
{"Menu_Next", bi_Menu_Next, -1}, {"Menu_Next", bi_Menu_Next, -1},
{"Menu_Prev", bi_Menu_Prev, -1}, {"Menu_Prev", bi_Menu_Prev, -1},
{"Menu_Enter", bi_Menu_Enter, -1}, {"Menu_Enter", bi_Menu_Enter, -1},
{"Menu_Leave", bi_Menu_Leave, -1},
{0}, {0},
}; };
void
Menu_Enter_f (void)
{
if (!Menu_KeyEvent(QFK_RETURN, '\0', true))
Menu_KeyEvent('y', 'y', true);
}
void
Menu_Leave_f (void)
{
Menu_Leave ();
}
void
Menu_Prev_f (void)
{
Menu_KeyEvent (QFK_UP, '\0', true);
}
void
Menu_Next_f (void)
{
Menu_KeyEvent (QFK_DOWN, '\0', true);
}
void void
Menu_Init (void) Menu_Init (void)
{ {
@ -549,6 +598,10 @@ Menu_Init (void)
"Toggle the display of the menu"); "Toggle the display of the menu");
Cmd_RemoveCommand ("quit"); Cmd_RemoveCommand ("quit");
Cmd_AddCommand ("quit", quit_f, "Exit the program"); Cmd_AddCommand ("quit", quit_f, "Exit the program");
Cmd_AddCommand ("Menu_Enter", Menu_Enter_f, "Do menu action/move up in the menu tree.");
Cmd_AddCommand ("Menu_Leave", Menu_Leave_f, "Move down in the menu tree.");
Cmd_AddCommand ("Menu_Prev", Menu_Prev_f, "Move cursor up.");
Cmd_AddCommand ("Menu_Next", Menu_Next_f, "Move cursor up.");
} }
void void

View file

@ -69,6 +69,21 @@ ocvar_t joy_axes_cvar_init[JOY_MAX_AXES] = {
struct joy_axis joy_axes[JOY_MAX_AXES]; struct joy_axis joy_axes[JOY_MAX_AXES];
struct joy_button joy_buttons[JOY_MAX_BUTTONS]; struct joy_button joy_buttons[JOY_MAX_BUTTONS];
void
joy_clear_axis (int i)
{
joy_axes[i].dest = js_none;
joy_axes[i].amp = 1;
joy_axes[i].pre_amp = 1;
joy_axes[i].deadzone = 12500;
joy_axes[i].num_buttons = 0;
if (joy_axes[i].axis_buttons) {
free (joy_axes[i].axis_buttons);
joy_axes[i].axis_buttons = NULL;
}
}
static void static void
joy_check_axis_buttons (struct joy_axis *ja, float value) joy_check_axis_buttons (struct joy_axis *ja, float value)
{ {
@ -203,6 +218,7 @@ js_dests_t js_dests[] = {
js_opts_t js_opts[] = { js_opts_t js_opts[] = {
{"clear", js_clear},
{"amp", js_amp}, {"amp", js_amp},
{"pre_amp", js_pre_amp}, {"pre_amp", js_pre_amp},
{"deadzone",js_deadzone}, {"deadzone",js_deadzone},
@ -267,6 +283,12 @@ in_joy_f (void)
if (c == 2) { if (c == 2) {
ax = JOY_GetOption_i (Cmd_Argv(1)); ax = JOY_GetOption_i (Cmd_Argv(1));
switch (ax) { switch (ax) {
case js_clear:
Sys_Printf("Clearing all joystick settings...\n");
for (i = 0; i<JOY_MAX_AXES;i++) {
joy_clear_axis (i);
}
break;
case js_amp: case js_amp:
Sys_Printf("[...]<amp> [<#amp>]: Axis sensitivity\n"); Sys_Printf("[...]<amp> [<#amp>]: Axis sensitivity\n");
break; break;
@ -302,15 +324,23 @@ in_joy_f (void)
Sys_Printf ("<====================>\n"); Sys_Printf ("<====================>\n");
break; break;
} }
return;
} }
else if (c < 4) { else if (c < 4) {
if (JOY_GetOption_i (Cmd_Argv(2)) == js_clear) {
ax = strtol(Cmd_Argv(1), NULL ,0);
joy_clear_axis (ax);
return;
} else {
Sys_Printf ("in_joy <axis#> [<var> <value>]* : Configures the joystick behaviour\n"); Sys_Printf ("in_joy <axis#> [<var> <value>]* : Configures the joystick behaviour\n");
return; return;
} }
}
ax = strtol(Cmd_Argv(1), NULL ,0); ax = strtol(Cmd_Argv(1), NULL ,0);
const char *arg;
i = 2; i = 2;
while(i<c) while(i<c)
{ {
@ -338,8 +368,15 @@ in_joy_f (void)
} }
break; break;
case js_axis_button: case js_axis_button:
char *arg = Cmd_Argv(i++); arg = Cmd_Argv(i++);
if (!strcmp("add", arg)) {
int n = joy_axes[ax].num_buttons++;
joy_axes[ax].axis_buttons = realloc(joy_axes[ax].axis_buttons,
/*sizeof*/ n*sizeof(joy_axes[ax].axis_buttons));
joy_axes[ax].axis_buttons[n].key = strtol (Cmd_Argv(i++), NULL, 10) + QFJ_AXIS1;
joy_axes[ax].axis_buttons[n].threshold = strtof(Cmd_Argv(i++), NULL);
}
break; break;
default: default:
Sys_Printf ("Unknown option %s.\n", Cmd_Argv(i-1)); Sys_Printf ("Unknown option %s.\n", Cmd_Argv(i-1));
@ -367,7 +404,7 @@ JOY_Init_Cvars (void)
joy_axes[i].dest = js_none; joy_axes[i].dest = js_none;
joy_axes[i].amp = 1; joy_axes[i].amp = 1;
joy_axes[i].pre_amp = 1; joy_axes[i].pre_amp = 1;
joy_axes[i].deadzone = 7500; joy_axes[i].deadzone = 12500;
} }
} }
@ -381,6 +418,15 @@ Joy_WriteBindings (QFile *f)
Qprintf(f, "in_joy %i amp %f pre_amp %f deadzone %i offset %f type %s %i\n", Qprintf(f, "in_joy %i amp %f pre_amp %f deadzone %i offset %f type %s %i\n",
i, joy_axes[i].amp, joy_axes[i].pre_amp, joy_axes[i].deadzone, i, joy_axes[i].amp, joy_axes[i].pre_amp, joy_axes[i].deadzone,
joy_axes[i].offset, JOY_GetDest_c (joy_axes[i].dest), joy_axes[i].axis); joy_axes[i].offset, JOY_GetDest_c (joy_axes[i].dest), joy_axes[i].axis);
if (joy_axes[i].num_buttons > 0) {
int n;
for (n=0;n<joy_axes[i].num_buttons;n++) {
Qprintf(f, "in_joy %i button add %i %f\n", i,
joy_axes[i].axis_buttons[n].key - QFJ_AXIS1,
joy_axes[i].axis_buttons[n].threshold);
}
}
} }
} }