quakeforge/libs/client/cl_input.c
Bill Currie 3f299155a3 [client] Reimplement legacy bind and unbind commands
This allows id1/qw config files, and to a certain extent scripts, to
work with the new binding system. It does highlight just how limited the
original system was (many keys could not bound).

Mouse axis input does not work yet as that needs a little more work to
support +strafe and +mlook.
2021-11-25 13:36:02 +09:00

143 lines
2.8 KiB
C

/*
cl_legacy.c
Client legacy commands
Copyright (C) 2021 Bill Currie <bill@taniwha.org>
Author: Bill Currie <bill@taniwha.org>
Date: 2021/11/24
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/input.h"
#include "QF/plist.h"
#include "QF/sys.h"
#include "old_keys.h"
#include "client/input.h"
static const char *default_input_config = ""
"{"
" input = {"
" contexts = ("
" {"
" name = key_game;"
" imts = ("
" {"
" name = imt_mod;"
" }"
" );"
" default_imt = imt_mod;"
" },"
" {"
" name = key_demo;"
" }"
" );"
" devices = ("
" {"
" name = mouse;"
" devname = core:mouse;"
" num_axes = 2;"
" num_buttons = 32;"
" },"
" {"
" name = key;"
" devname = core:keyboard;"
" num_axes = 0;"
" num_buttons = 256;"
" },"
" );"
" };"
"};";
static void
cl_bind_f (void)
{
int c, i;
const char *key;
static dstring_t *cmd_buf;
if (!cmd_buf) {
cmd_buf = dstring_newstr ();
}
c = Cmd_Argc ();
if (c < 2) {
Sys_Printf ("bind <key> [command] : attach a command to a key\n");
return;
}
if (!(key = OK_TranslateKeyName (Cmd_Argv (1)))) {
return;
}
dsprintf (cmd_buf, "in_bind imt_mod %s", key);
if (c >= 3) {
for (i = 2; i < c; i++) {
dasprintf (cmd_buf, " \"%s\"", Cmd_Argv (i));
}
}
Cmd_ExecuteString (cmd_buf->str, src_command);
}
static void
cl_unbind_f (void)
{
int c;
const char *key;
static dstring_t *cmd_buf;
if (!cmd_buf) {
cmd_buf = dstring_newstr ();
}
c = Cmd_Argc ();
if (c < 2) {
Sys_Printf ("bind <key> [command] : attach a command to a key\n");
return;
}
if (!(key = OK_TranslateKeyName (Cmd_Argv (1)))) {
return;
}
dsprintf (cmd_buf, "in_unbind imt_mod %s", key);
Cmd_ExecuteString (cmd_buf->str, src_command);
}
void
CL_Legacy_Init (void)
{
OK_Init ();
Cmd_AddCommand ("bind", cl_bind_f, "compatibility wrapper for in_bind");
Cmd_AddCommand ("unbind", cl_unbind_f, "compatibility wrapper for in_bind");
// FIXME hashlinks
IN_LoadConfig (PL_GetPropertyList (default_input_config, 0));
}