2006-02-24 04:48:15 +00:00
|
|
|
/*
|
|
|
|
** c_bind.cpp
|
|
|
|
** Functions for using and maintaining key bindings
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2006-06-11 01:37:00 +00:00
|
|
|
** Copyright 1998-2006 Randy Heit
|
2006-02-24 04:48:15 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "c_bind.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "hu_stuff.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "configfile.h"
|
|
|
|
#include "i_system.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "d_event.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
struct FBinding
|
|
|
|
{
|
|
|
|
const char *Key;
|
|
|
|
const char *Bind;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Default keybindings for Doom (and all other games)
|
|
|
|
*/
|
|
|
|
static const FBinding DefBindings[] =
|
|
|
|
{
|
|
|
|
{ "`", "toggleconsole" },
|
|
|
|
{ "1", "slot 1" },
|
|
|
|
{ "2", "slot 2" },
|
|
|
|
{ "3", "slot 3" },
|
|
|
|
{ "4", "slot 4" },
|
|
|
|
{ "5", "slot 5" },
|
|
|
|
{ "6", "slot 6" },
|
|
|
|
{ "7", "slot 7" },
|
|
|
|
{ "8", "slot 8" },
|
|
|
|
{ "9", "slot 9" },
|
|
|
|
{ "0", "slot 0" },
|
|
|
|
{ "[", "invprev" },
|
|
|
|
{ "]", "invnext" },
|
|
|
|
{ "enter", "invuse" },
|
|
|
|
{ "-", "sizedown" },
|
|
|
|
{ "=", "sizeup" },
|
|
|
|
{ "ctrl", "+attack" },
|
|
|
|
{ "alt", "+strafe" },
|
|
|
|
{ "shift", "+speed" },
|
|
|
|
{ "space", "+use" },
|
|
|
|
{ "rightarrow", "+right" },
|
|
|
|
{ "leftarrow", "+left" },
|
|
|
|
{ "uparrow", "+forward" },
|
|
|
|
{ "downarrow", "+back" },
|
|
|
|
{ ",", "+moveleft" },
|
|
|
|
{ ".", "+moveright" },
|
|
|
|
{ "mouse1", "+attack" },
|
|
|
|
{ "mouse2", "+strafe" },
|
|
|
|
{ "mouse3", "+forward" },
|
|
|
|
{ "mouse4", "+speed" },
|
|
|
|
{ "joy1", "+attack" },
|
|
|
|
{ "joy2", "+strafe" },
|
|
|
|
{ "joy3", "+speed" },
|
|
|
|
{ "joy4", "+use" },
|
|
|
|
{ "capslock", "toggle cl_run" },
|
|
|
|
{ "f1", "menu_help" },
|
|
|
|
{ "f2", "menu_save" },
|
|
|
|
{ "f3", "menu_load" },
|
|
|
|
{ "f4", "menu_options" },
|
|
|
|
{ "f5", "menu_display" },
|
|
|
|
{ "f6", "quicksave" },
|
|
|
|
{ "f7", "menu_endgame" },
|
|
|
|
{ "f8", "togglemessages" },
|
|
|
|
{ "f9", "quickload" },
|
|
|
|
{ "f11", "bumpgamma" },
|
|
|
|
{ "f10", "menu_quit" },
|
|
|
|
{ "tab", "togglemap" },
|
|
|
|
{ "pause", "pause" },
|
|
|
|
{ "sysrq", "screenshot" },
|
|
|
|
{ "t", "messagemode" },
|
|
|
|
{ "\\", "+showscores" },
|
|
|
|
{ "f12", "spynext" },
|
|
|
|
{ "mwheeldown", "weapnext" },
|
|
|
|
{ "mwheelup", "weapprev" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const FBinding DefRavenBindings[] =
|
|
|
|
{
|
|
|
|
{ "pgup", "+moveup" },
|
|
|
|
{ "insert", "+movedown" },
|
|
|
|
{ "home", "land" },
|
|
|
|
{ "pgdn", "+lookup" },
|
|
|
|
{ "del", "+lookdown" },
|
|
|
|
{ "end", "centerview" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2006-04-11 16:27:41 +00:00
|
|
|
static const FBinding DefHereticBindings[] =
|
|
|
|
{
|
|
|
|
{ "backspace", "use ArtiTomeOfPower" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
static const FBinding DefHexenBindings[] =
|
|
|
|
{
|
|
|
|
{ "/", "+jump" },
|
|
|
|
{ "backspace", "invuseall" },
|
|
|
|
{ "\\", "use ArtiHealth" },
|
|
|
|
{ "0", "useflechette" },
|
|
|
|
{ "9", "use ArtiBlastRadius" },
|
|
|
|
{ "8", "use ArtiTeleport" },
|
|
|
|
{ "7", "use ArtiTeleportOther" },
|
|
|
|
{ "6", "use ArtiEgg" },
|
|
|
|
{ "5", "use ArtiInvulnerability" },
|
|
|
|
{ "scroll", "+showscores" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static const FBinding DefStrifeBindings[] =
|
|
|
|
{
|
|
|
|
{ "a", "+jump" },
|
|
|
|
{ "w", "showpop 1" },
|
|
|
|
{ "backspace", "invdrop" },
|
|
|
|
{ "z", "showpop 3" },
|
|
|
|
{ "k", "showpop 2" },
|
|
|
|
{ NULL }
|
|
|
|
// not done
|
|
|
|
// h - use health
|
|
|
|
// q - query inventory
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *KeyNames[NUM_KEYS] =
|
|
|
|
{
|
|
|
|
// This array is dependant on the particular keyboard input
|
|
|
|
// codes generated in i_input.c. If they change there, they
|
|
|
|
// also need to change here. In this case, we use the
|
|
|
|
// DirectInput codes and assume a qwerty keyboard layout.
|
|
|
|
// See <dinput.h> for the DIK_* codes
|
|
|
|
|
|
|
|
NULL, "escape", "1", "2", "3", "4", "5", "6", //00
|
|
|
|
"7", "8", "9", "0", "-", "=", "backspace","tab", //08
|
|
|
|
"q", "w", "e", "r", "t", "y", "u", "i", //10
|
|
|
|
"o", "p", "[", "]", "enter", "ctrl", "a", "s", //18
|
|
|
|
"d", "f", "g", "h", "j", "k", "l", ";", //20
|
|
|
|
"'", "`", "shift", "\\", "z", "x", "c", "v", //28
|
|
|
|
"b", "n", "m", ",", ".", "/", "rshift", "kp*", //30
|
|
|
|
"alt", "space", "capslock", "f1", "f2", "f3", "f4", "f5", //38
|
|
|
|
"f6", "f7", "f8", "f9", "f10", "numlock", "scroll", "kp7", //40
|
|
|
|
"kp8", "kp9", "kp-", "kp4", "kp5", "kp6", "kp+", "kp1", //48
|
|
|
|
"kp2", "kp3", "kp0", "kp.", NULL, NULL, "oem102", "f11", //50
|
|
|
|
"f12", NULL, NULL, NULL, NULL, NULL, NULL, NULL, //58
|
|
|
|
NULL, NULL, NULL, NULL, "f13", "f14", "f15", NULL, //60
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, //68
|
|
|
|
"kana", NULL, NULL, "abnt_c1", NULL, NULL, NULL, NULL, //70
|
|
|
|
NULL, "convert", NULL, "noconvert",NULL, "yen", "abnt_c2", NULL, //78
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, //80
|
|
|
|
NULL, NULL, NULL, NULL, NULL, "kp=", NULL, NULL, //88
|
|
|
|
"circumflex","@", ":", "_", "kanji", "stop", "ax", "unlabeled",//90
|
|
|
|
NULL, "prevtrack",NULL, NULL, "kp-enter", "rctrl", NULL, NULL, //98
|
|
|
|
"mute", "calculator","play", NULL, "stop", NULL, NULL, NULL, //A0
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, "voldown", NULL, //A8
|
|
|
|
"volup", NULL, "webhome", "kp,", NULL, "kp/", NULL, "sysrq", //B0
|
|
|
|
"ralt", NULL, NULL, NULL, NULL, NULL, NULL, NULL, //B8
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, "home", //C0
|
|
|
|
"uparrow", "pgup", NULL, "leftarrow",NULL, "rightarrow",NULL, "end", //C8
|
|
|
|
"downarrow","pgdn", "ins", "del", NULL, NULL, NULL, NULL, //D0
|
|
|
|
NULL, NULL, NULL, "lwin", "rwin", "apps", "power", "sleep", //D8
|
|
|
|
NULL, NULL, NULL, "wake", NULL, "search", "favorites","refresh", //E0
|
|
|
|
"webstop", "webforward","webback", "mycomputer","mail", "mediaselect",NULL, NULL, //E8
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, //F0
|
|
|
|
NULL, NULL, NULL, NULL, NULL, NULL, NULL, "pause", //F8
|
|
|
|
|
|
|
|
// non-keyboard buttons that can be bound
|
|
|
|
"mouse1", "mouse2", "mouse3", "mouse4", // 8 mouse buttons
|
|
|
|
"mouse5", "mouse6", "mouse7", "mouse8",
|
|
|
|
|
|
|
|
"joy1", "joy2", "joy3", "joy4", // 128 joystick buttons!
|
|
|
|
"joy5", "joy6", "joy7", "joy8",
|
|
|
|
"joy9", "joy10", "joy11", "joy12",
|
|
|
|
"joy13", "joy14", "joy15", "joy16",
|
|
|
|
"joy17", "joy18", "joy19", "joy20",
|
|
|
|
"joy21", "joy22", "joy23", "joy24",
|
|
|
|
"joy25", "joy26", "joy27", "joy28",
|
|
|
|
"joy29", "joy30", "joy31", "joy32",
|
|
|
|
"joy33", "joy34", "joy35", "joy36",
|
|
|
|
"joy37", "joy38", "joy39", "joy40",
|
|
|
|
"joy41", "joy42", "joy43", "joy44",
|
|
|
|
"joy45", "joy46", "joy47", "joy48",
|
|
|
|
"joy49", "joy50", "joy51", "joy52",
|
|
|
|
"joy53", "joy54", "joy55", "joy56",
|
|
|
|
"joy57", "joy58", "joy59", "joy60",
|
|
|
|
"joy61", "joy62", "joy63", "joy64",
|
|
|
|
"joy65", "joy66", "joy67", "joy68",
|
|
|
|
"joy69", "joy70", "joy71", "joy72",
|
|
|
|
"joy73", "joy74", "joy75", "joy76",
|
|
|
|
"joy77", "joy78", "joy79", "joy80",
|
|
|
|
"joy81", "joy82", "joy83", "joy84",
|
|
|
|
"joy85", "joy86", "joy87", "joy88",
|
|
|
|
"joy89", "joy90", "joy91", "joy92",
|
|
|
|
"joy93", "joy94", "joy95", "joy96",
|
|
|
|
"joy97", "joy98", "joy99", "joy100",
|
|
|
|
"joy101", "joy102", "joy103", "joy104",
|
|
|
|
"joy105", "joy106", "joy107", "joy108",
|
|
|
|
"joy109", "joy110", "joy111", "joy112",
|
|
|
|
"joy113", "joy114", "joy115", "joy116",
|
|
|
|
"joy117", "joy118", "joy119", "joy120",
|
|
|
|
"joy121", "joy122", "joy123", "joy124",
|
|
|
|
"joy125", "joy126", "joy127", "joy128",
|
|
|
|
|
|
|
|
"pov1up", "pov1right","pov1down", "pov1left", // First POV hat
|
|
|
|
"pov2up", "pov2right","pov2down", "pov2left", // Second POV hat
|
|
|
|
"pov3up", "pov3right","pov3down", "pov3left", // Third POV hat
|
|
|
|
"pov4up", "pov4right","pov4down", "pov4left", // Fourth POV hat
|
|
|
|
|
|
|
|
"mwheelup", "mwheeldown", // the mouse wheel
|
|
|
|
};
|
|
|
|
|
2006-05-04 03:49:46 +00:00
|
|
|
static FString Bindings[NUM_KEYS];
|
|
|
|
static FString DoubleBindings[NUM_KEYS];
|
2006-04-12 03:03:58 +00:00
|
|
|
static unsigned int DClickTime[NUM_KEYS];
|
2006-09-14 00:02:31 +00:00
|
|
|
static BYTE DClicked[(NUM_KEYS+7)/8];
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
static int GetKeyFromName (const char *name)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Names of the form #xxx are translated to key xxx automatically
|
|
|
|
if (name[0] == '#' && name[1] != 0)
|
|
|
|
{
|
|
|
|
return atoi (name + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we scan the KeyNames[] array for a matching name
|
|
|
|
for (i = 0; i < NUM_KEYS; i++)
|
|
|
|
{
|
|
|
|
if (KeyNames[i] && !stricmp (KeyNames[i], name))
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *KeyName (int key)
|
|
|
|
{
|
|
|
|
static char name[5];
|
|
|
|
|
|
|
|
if (KeyNames[key])
|
|
|
|
return KeyNames[key];
|
|
|
|
|
About a week's worth of changes here. As a heads-up, I wouldn't be
surprised if this doesn't build in Linux right now. The CMakeLists.txt
were checked with MinGW and NMake, but how they fair under Linux is an
unknown to me at this time.
- Converted most sprintf (and all wsprintf) calls to either mysnprintf or
FStrings, depending on the situation.
- Changed the strings in the wbstartstruct to be FStrings.
- Changed myvsnprintf() to output nothing if count is greater than INT_MAX.
This is so that I can use a series of mysnprintf() calls and advance the
pointer for each one. Once the pointer goes beyond the end of the buffer,
the count will go negative, but since it's an unsigned type it will be
seen as excessively huge instead. This should not be a problem, as there's
no reason for ZDoom to be using text buffers larger than 2 GB anywhere.
- Ripped out the disabled bit from FGameConfigFile::MigrateOldConfig().
- Changed CalcMapName() to return an FString instead of a pointer to a static
buffer.
- Changed startmap in d_main.cpp into an FString.
- Changed CheckWarpTransMap() to take an FString& as the first argument.
- Changed d_mapname in g_level.cpp into an FString.
- Changed DoSubstitution() in ct_chat.cpp to place the substitutions in an
FString.
- Fixed: The MAPINFO parser wrote into the string buffer to construct a map
name when given a Hexen map number. This was fine with the old scanner
code, but only a happy coincidence prevents it from crashing with the new
code
- Added the 'B' conversion specifier to StringFormat::VWorker() for printing
binary numbers.
- Added CMake support for building with MinGW, MSYS, and NMake. Linux support
is probably broken until I get around to booting into Linux again. Niceties
provided over the existing Makefiles they're replacing:
* All command-line builds can use the same build system, rather than having
a separate one for MinGW and another for Linux.
* Microsoft's NMake tool is supported as a target.
* Progress meters.
* Parallel makes work from a fresh checkout without needing to be primed
first with a single-threaded make.
* Porting to other architectures should be simplified, whenever that day
comes.
- Replaced the makewad tool with zipdir. This handles the dependency tracking
itself instead of generating an external makefile to do it, since I couldn't
figure out how to generate a makefile with an external tool and include it
with a CMake-generated makefile. Where makewad used a master list of files
to generate the package file, zipdir just zips the entire contents of one or
more directories.
- Added the gdtoa package from netlib's fp library so that ZDoom's printf-style
formatting can be entirely independant of the CRT.
SVN r1082 (trunk)
2008-07-23 04:57:26 +00:00
|
|
|
mysnprintf (name, countof(name), "#%d", key);
|
2006-02-24 04:48:15 +00:00
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C_UnbindAll ()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_KEYS; ++i)
|
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
Bindings[i] = "";
|
|
|
|
DoubleBindings[i] = "";
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (unbindall)
|
|
|
|
{
|
|
|
|
C_UnbindAll ();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (unbind)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
if ( (i = GetKeyFromName (argv[1])) )
|
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
Bindings[i] = "";
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Unknown key \"%s\"\n", argv[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (bind)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
i = GetKeyFromName (argv[1]);
|
|
|
|
if (!i)
|
|
|
|
{
|
|
|
|
Printf ("Unknown key \"%s\"\n", argv[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (argv.argc() == 2)
|
|
|
|
{
|
2006-05-04 12:40:39 +00:00
|
|
|
Printf ("\"%s\" = \"%s\"\n", argv[1], Bindings[i].GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-04 03:49:46 +00:00
|
|
|
Bindings[i] = argv[2];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Current key bindings:\n");
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_KEYS; i++)
|
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
if (!Bindings[i].IsEmpty())
|
|
|
|
Printf ("%s \"%s\"\n", KeyName (i), Bindings[i].GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
//
|
|
|
|
// CCMD defaultbind
|
|
|
|
//
|
|
|
|
// Binds a command to a key if that key is not already bound and if
|
|
|
|
// that command is not already bound to another key.
|
|
|
|
//
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
CCMD (defaultbind)
|
|
|
|
{
|
|
|
|
if (argv.argc() < 3)
|
|
|
|
{
|
|
|
|
Printf ("Usage: defaultbind <key> <command>\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int key = GetKeyFromName (argv[1]);
|
|
|
|
if (key == 0)
|
|
|
|
{
|
|
|
|
Printf ("Unknown key \"%s\"\n", argv[1]);
|
|
|
|
return;
|
|
|
|
}
|
2006-07-09 20:15:38 +00:00
|
|
|
if (!Bindings[key].IsEmpty())
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // This key is already bound.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int i = 0; i < NUM_KEYS; ++i)
|
|
|
|
{
|
2006-07-09 20:15:38 +00:00
|
|
|
if (!Bindings[i].IsEmpty() && stricmp (Bindings[i], argv[2]) == 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // This command is already bound to a key.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// It is safe to do the bind, so do it.
|
2006-07-09 20:15:38 +00:00
|
|
|
Bindings[key] = argv[2];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (undoublebind)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
if ( (i = GetKeyFromName (argv[1])) )
|
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
DoubleBindings[i] = "";
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Unknown key \"%s\"\n", argv[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (doublebind)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
i = GetKeyFromName (argv[1]);
|
|
|
|
if (!i)
|
|
|
|
{
|
|
|
|
Printf ("Unknown key \"%s\"\n", argv[1]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (argv.argc() == 2)
|
|
|
|
{
|
2006-05-04 12:40:39 +00:00
|
|
|
Printf ("\"%s\" = \"%s\"\n", argv[1], DoubleBindings[i].GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-04 03:49:46 +00:00
|
|
|
DoubleBindings[i] = argv[2];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Printf ("Current key doublebindings:\n");
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_KEYS; i++)
|
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
if (!DoubleBindings[i].IsEmpty())
|
|
|
|
Printf ("%s \"%s\"\n", KeyName (i), DoubleBindings[i].GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (rebind)
|
|
|
|
{
|
2006-05-04 03:49:46 +00:00
|
|
|
FString *bindings;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (key == 0)
|
|
|
|
{
|
|
|
|
Printf ("Rebind cannot be used from the console\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (key & KEY_DBLCLICKED)
|
|
|
|
{
|
|
|
|
bindings = DoubleBindings;
|
|
|
|
key &= KEY_DBLCLICKED-1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bindings = Bindings;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
2006-05-04 03:49:46 +00:00
|
|
|
bindings[key] = argv[1];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetBinds (const FBinding *array)
|
|
|
|
{
|
|
|
|
while (array->Key)
|
|
|
|
{
|
|
|
|
C_DoBind (array->Key, array->Bind, false);
|
|
|
|
array++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void C_BindDefaults ()
|
|
|
|
{
|
|
|
|
SetBinds (DefBindings);
|
|
|
|
|
|
|
|
if (gameinfo.gametype & (GAME_Raven|GAME_Strife))
|
|
|
|
{
|
|
|
|
SetBinds (DefRavenBindings);
|
|
|
|
}
|
|
|
|
|
2006-04-11 16:27:41 +00:00
|
|
|
if (gameinfo.gametype == GAME_Heretic)
|
|
|
|
{
|
|
|
|
SetBinds (DefHereticBindings);
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
if (gameinfo.gametype == GAME_Hexen)
|
|
|
|
{
|
|
|
|
SetBinds (DefHexenBindings);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gameinfo.gametype == GAME_Strife)
|
|
|
|
{
|
|
|
|
SetBinds (DefStrifeBindings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD(binddefaults)
|
|
|
|
{
|
|
|
|
C_BindDefaults ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void C_SetDefaultBindings ()
|
|
|
|
{
|
|
|
|
C_UnbindAll ();
|
|
|
|
C_BindDefaults ();
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
bool C_DoKey (event_t *ev)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-16 02:50:18 +00:00
|
|
|
FString binding;
|
2006-02-24 04:48:15 +00:00
|
|
|
bool dclick;
|
|
|
|
int dclickspot;
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE dclickmask;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (ev->type != EV_KeyDown && ev->type != EV_KeyUp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((unsigned int)ev->data1 >= NUM_KEYS)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dclickspot = ev->data1 >> 3;
|
|
|
|
dclickmask = 1 << (ev->data1 & 7);
|
|
|
|
dclick = false;
|
|
|
|
|
|
|
|
// This used level.time which didn't work outside a level.
|
|
|
|
if (DClickTime[ev->data1] > I_MSTime() && ev->type == EV_KeyDown)
|
|
|
|
{
|
|
|
|
// Key pressed for a double click
|
|
|
|
binding = DoubleBindings[ev->data1];
|
|
|
|
DClicked[dclickspot] |= dclickmask;
|
|
|
|
dclick = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ev->type == EV_KeyDown)
|
|
|
|
{ // Key pressed for a normal press
|
|
|
|
binding = Bindings[ev->data1];
|
|
|
|
DClickTime[ev->data1] = I_MSTime() + 571;
|
|
|
|
}
|
|
|
|
else if (DClicked[dclickspot] & dclickmask)
|
|
|
|
{ // Key released from a double click
|
|
|
|
binding = DoubleBindings[ev->data1];
|
|
|
|
DClicked[dclickspot] &= ~dclickmask;
|
|
|
|
DClickTime[ev->data1] = 0;
|
|
|
|
dclick = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ // Key released from a normal press
|
|
|
|
binding = Bindings[ev->data1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-07 00:27:22 +00:00
|
|
|
|
2006-05-16 02:50:18 +00:00
|
|
|
if (binding.IsEmpty())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
binding = Bindings[ev->data1];
|
|
|
|
dclick = false;
|
|
|
|
}
|
|
|
|
|
2006-05-16 02:50:18 +00:00
|
|
|
if (!binding.IsEmpty() && (chatmodeon == 0 || ev->data1 < 256))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-16 02:50:18 +00:00
|
|
|
if (ev->type == EV_KeyUp && binding[0] != '+')
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-16 02:50:18 +00:00
|
|
|
return false;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-05-16 02:50:18 +00:00
|
|
|
char *copy = binding.LockBuffer();
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (ev->type == EV_KeyUp)
|
|
|
|
{
|
2006-05-16 02:50:18 +00:00
|
|
|
copy[0] = '-';
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2006-05-16 02:50:18 +00:00
|
|
|
|
|
|
|
AddCommandString (copy, dclick ? ev->data1 | KEY_DBLCLICKED : ev->data1);
|
2006-02-24 04:48:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-07 01:14:36 +00:00
|
|
|
const char *C_ConfigKeyName(int keynum)
|
|
|
|
{
|
|
|
|
const char *name = KeyName(keynum);
|
|
|
|
if (name[1] == 0) // Make sure given name is config-safe
|
|
|
|
{
|
|
|
|
if (name[0] == '[')
|
|
|
|
return "LeftBracket";
|
|
|
|
else if (name[0] == ']')
|
|
|
|
return "RightBracket";
|
|
|
|
else if (name[0] == '=')
|
|
|
|
return "Equals";
|
|
|
|
else if (strcmp (name, "kp=") == 0)
|
|
|
|
return "KP-Equals";
|
|
|
|
}
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This function is first called for functions in custom key sections.
|
|
|
|
// In this case, matchcmd is non-NULL, and only keys bound to that command
|
|
|
|
// are stored. If a match is found, its binding is set to "\1".
|
|
|
|
// After all custom key sections are saved, it is called one more for the
|
|
|
|
// normal Bindings and DoubleBindings sections for this game. In this case
|
|
|
|
// matchcmd is NULL and all keys will be stored. The config section was not
|
|
|
|
// previously cleared, so all old bindings are still in place. If the binding
|
|
|
|
// for a key is empty, the corresponding key in the config is removed as well.
|
|
|
|
// If a binding is "\1", then the binding itself is cleared, but nothing
|
|
|
|
// happens to the entry in the config.
|
2006-02-24 04:48:15 +00:00
|
|
|
void C_ArchiveBindings (FConfigFile *f, bool dodouble, const char *matchcmd)
|
|
|
|
{
|
2006-05-04 03:49:46 +00:00
|
|
|
FString *bindings;
|
2006-02-24 04:48:15 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
bindings = dodouble ? DoubleBindings : Bindings;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_KEYS; i++)
|
|
|
|
{
|
2009-02-07 01:14:36 +00:00
|
|
|
if (bindings[i].IsEmpty())
|
|
|
|
{
|
|
|
|
if (matchcmd == NULL)
|
|
|
|
{
|
|
|
|
f->ClearKey(C_ConfigKeyName(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (matchcmd == NULL || stricmp(bindings[i], matchcmd) == 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-07 01:14:36 +00:00
|
|
|
if (bindings[i][0] == '\1')
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-07 01:14:36 +00:00
|
|
|
bindings[i] = "";
|
|
|
|
continue;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-07 01:14:36 +00:00
|
|
|
f->SetValueForKey(C_ConfigKeyName(i), bindings[i]);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (matchcmd != NULL)
|
2009-02-07 01:14:36 +00:00
|
|
|
{ // If saving a specific command, set a marker so that
|
|
|
|
// it does not get saved in the general binding list.
|
|
|
|
bindings[i] = "\1";
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void C_DoBind (const char *key, const char *bind, bool dodouble)
|
|
|
|
{
|
|
|
|
int keynum = GetKeyFromName (key);
|
|
|
|
if (keynum == 0)
|
|
|
|
{
|
|
|
|
if (stricmp (key, "LeftBracket") == 0)
|
|
|
|
{
|
|
|
|
keynum = GetKeyFromName ("[");
|
|
|
|
}
|
|
|
|
else if (stricmp (key, "RightBracket") == 0)
|
|
|
|
{
|
|
|
|
keynum = GetKeyFromName ("]");
|
|
|
|
}
|
|
|
|
else if (stricmp (key, "Equals") == 0)
|
|
|
|
{
|
|
|
|
keynum = GetKeyFromName ("=");
|
|
|
|
}
|
|
|
|
else if (stricmp (key, "KP-Equals") == 0)
|
|
|
|
{
|
|
|
|
keynum = GetKeyFromName ("kp=");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (keynum != 0)
|
|
|
|
{
|
2006-05-04 03:49:46 +00:00
|
|
|
(dodouble ? DoubleBindings : Bindings)[keynum] = bind;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_GetKeysForCommand (char *cmd, int *first, int *second)
|
|
|
|
{
|
|
|
|
int c, i;
|
|
|
|
|
|
|
|
*first = *second = c = i = 0;
|
|
|
|
|
|
|
|
while (i < NUM_KEYS && c < 2)
|
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
if (stricmp (cmd, Bindings[i]) == 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (c++ == 0)
|
|
|
|
*first = i;
|
|
|
|
else
|
|
|
|
*second = i;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void C_NameKeys (char *str, int first, int second)
|
|
|
|
{
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
*str = 0;
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
c++;
|
|
|
|
strcpy (str, KeyName (first));
|
|
|
|
if (second)
|
|
|
|
strcat (str, " or ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (second)
|
|
|
|
{
|
|
|
|
c++;
|
|
|
|
strcat (str, KeyName (second));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!c)
|
2008-06-26 17:55:48 +00:00
|
|
|
*str = '\0';
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void C_UnbindACommand (char *str)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_KEYS; i++)
|
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
if (!stricmp (str, Bindings[i]))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
Bindings[i] = "";
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void C_ChangeBinding (const char *str, int newone)
|
|
|
|
{
|
|
|
|
if ((unsigned int)newone < NUM_KEYS)
|
|
|
|
{
|
2006-05-04 06:14:52 +00:00
|
|
|
Bindings[newone] = str;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-16 02:50:18 +00:00
|
|
|
const char *C_GetBinding (int key)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-05-04 03:49:46 +00:00
|
|
|
return (unsigned int)key < NUM_KEYS ? Bindings[key].GetChars() : NULL;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|