mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-01-24 17:26:41 +00:00
Turns out using IDs was a bad idea, reverting to KEY_* strings
This commit is contained in:
parent
3dda97d32a
commit
eccadf5bd7
6 changed files with 75 additions and 81 deletions
|
@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
#include "ActionMapper.h"
|
||||
#include "Core.h"
|
||||
#include "SDL.h"
|
||||
#include "LegacyKeycodes.h"
|
||||
#include "GameKeyNames.h"
|
||||
|
||||
|
||||
static std::string inputcode2string(int k)
|
||||
|
@ -32,35 +32,34 @@ static std::string inputcode2string(int k)
|
|||
return std::string();
|
||||
if(k < KEY_MAXARRAY)
|
||||
{
|
||||
// See parseKey() below
|
||||
std::stringstream os;
|
||||
os << "K:";
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
int keycode = SDL_GetKeyFromScancode((SDL_Scancode)k);
|
||||
os << keycode << "," << k;
|
||||
#else
|
||||
os << k;
|
||||
#endif
|
||||
// Returns KEY_* or NULL
|
||||
const std::string& str = getKeyNameFromInputCode(k);
|
||||
if(str.length())
|
||||
return str;
|
||||
|
||||
// fallback
|
||||
std::ostringstream os;
|
||||
os << "K:" << k;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
if(k >= JOY_BUTTON_0 && k < JOY_BUTTON_END)
|
||||
{
|
||||
std::stringstream os;
|
||||
std::ostringstream os;
|
||||
os << "JB:" << (k - JOY_BUTTON_0);
|
||||
return os.str();
|
||||
}
|
||||
|
||||
if(k >= JOY_AXIS_0_POS && k < JOY_AXIS_END_POS)
|
||||
{
|
||||
std::stringstream os;
|
||||
std::ostringstream os;
|
||||
os << "AX:+" << (k - JOY_AXIS_0_POS);
|
||||
return os.str();
|
||||
}
|
||||
|
||||
if(k >= JOY_AXIS_0_NEG && k < JOY_AXIS_END_NEG)
|
||||
{
|
||||
std::stringstream os;
|
||||
std::ostringstream os;
|
||||
os << "AX:-" << (k - JOY_AXIS_0_NEG);
|
||||
return os.str();
|
||||
}
|
||||
|
@ -97,14 +96,10 @@ static const char *jbtnname(int joystickID, int btn)
|
|||
return j ? j->getButtonName(btn) : NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string getInputCodeToString(int k)
|
||||
{
|
||||
std::string s = inputcode2string(k);
|
||||
if(s.empty())
|
||||
return "NONE";
|
||||
return spacesToUnderscores(s);
|
||||
return s.empty() ? "0" : s;
|
||||
}
|
||||
|
||||
std::string getInputCodeToUserString(unsigned int k, size_t joystickID)
|
||||
|
@ -117,6 +112,7 @@ std::string getInputCodeToUserString(unsigned int k, size_t joystickID)
|
|||
if(k < KEY_MAXARRAY)
|
||||
{
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
pretty = SDL_GetScancodeName((SDL_Scancode)k);
|
||||
const SDL_Keycode kcode = SDL_GetKeyFromScancode((SDL_Scancode)k);
|
||||
if(kcode != SDLK_UNKNOWN)
|
||||
pretty = SDL_GetKeyName(kcode);
|
||||
|
@ -145,38 +141,8 @@ std::string getInputCodeToUserString(unsigned int k, size_t joystickID)
|
|||
return s;
|
||||
}
|
||||
|
||||
return inputcode2string(k);
|
||||
}
|
||||
|
||||
// two comma-separated ints
|
||||
// first is the keycode, second the scancode
|
||||
// (Keymap-independent) Scancodes are used when built with SDL2 support and specified
|
||||
// (Keymap-dependent) Keycode is used otherwise
|
||||
static int parseKey(const char *ks)
|
||||
{
|
||||
int k = 0;
|
||||
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
if(const char *comma = strchr(ks, ','))
|
||||
{
|
||||
k = atoi(comma + 1);
|
||||
if(k && k < KEY_MAXARRAY)
|
||||
return k;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Use the keycode
|
||||
k = atoi(ks);
|
||||
if(k < KEY_MAXARRAY)
|
||||
{
|
||||
#ifdef BBGE_BUILD_SDL2
|
||||
// But when we're on SDL2, don't forget to turn they keycode back into a scancode, since we work with scancodes internally
|
||||
k = SDL_GetScancodeFromKey(k);
|
||||
#endif
|
||||
return k;
|
||||
}
|
||||
|
||||
return 0;
|
||||
std::string s = inputcode2string(k);
|
||||
return s.empty() ? "-" : s;
|
||||
}
|
||||
|
||||
int getStringToInputCode(const std::string& s)
|
||||
|
@ -188,7 +154,7 @@ int getStringToInputCode(const std::string& s)
|
|||
if(s == "MMB")
|
||||
return MOUSE_BUTTON_MIDDLE;
|
||||
if(!strncmp(s.c_str(), "K:", 2))
|
||||
return parseKey(s.c_str() + 2);
|
||||
return atoi(s.c_str() + 2);
|
||||
if(!strncmp(s.c_str(), "JB:", 3))
|
||||
return JOY_BUTTON_0 + atoi(s.c_str() + 3);
|
||||
if(!strncmp(s.c_str(), "MB:", 3))
|
||||
|
@ -203,12 +169,10 @@ int getStringToInputCode(const std::string& s)
|
|||
default: return 0;
|
||||
}
|
||||
}
|
||||
if(s == "NONE")
|
||||
return 0;
|
||||
|
||||
// Maybe we're upgrading from an old config?
|
||||
// Note that this returns 0 for "0", which was considered "no key"
|
||||
if(int k = getInputCodeFromLegacyName(s.c_str()))
|
||||
// This handles KEY_* and some old mouse/joystick names.
|
||||
if(int k = getInputCodeFromKeyName(s.c_str()))
|
||||
return k;
|
||||
|
||||
return 0;
|
||||
|
@ -218,9 +182,8 @@ int getStringToInputCode(const std::string& s)
|
|||
|
||||
ActionInput::ActionInput()
|
||||
{
|
||||
for (int i = 0; i < INP_MSESIZE; i++) data.single.mse[i] = 0;
|
||||
for (int i = 0; i < INP_KEYSIZE; i++) data.single.key[i] = 0;
|
||||
for (int i = 0; i < INP_JOYSIZE; i++) data.single.joy[i] = 0;
|
||||
for (int i = 0; i < INP_COMBINED_SIZE; i++)
|
||||
data.all[i] = 0;
|
||||
}
|
||||
|
||||
std::string ActionInput::toString() const
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#include "LegacyKeycodes.h"
|
||||
#include "GameKeyNames.h"
|
||||
#include "ActionStatus.h"
|
||||
#include <stdio.h>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
|
||||
typedef std::map<std::string, int> InputCodeMap;
|
||||
|
||||
InputCodeMap inputCodeMap;
|
||||
static std::string keyNames[KEY_MAXARRAY];
|
||||
|
||||
static void initInputCodeMap()
|
||||
{
|
||||
|
@ -84,6 +85,22 @@ static void initInputCodeMap()
|
|||
K(KEY_RETURN)
|
||||
K(KEY_TAB)
|
||||
K(KEY_ESCAPE)
|
||||
K(KEY_SPACE)
|
||||
K(KEY_BACKSPACE)
|
||||
K(KEY_NUMPADMINUS)
|
||||
K(KEY_NUMPADPERIOD)
|
||||
K(KEY_NUMPADPLUS)
|
||||
K(KEY_NUMPADSLASH)
|
||||
K(KEY_NUMPADSTAR)
|
||||
K(KEY_PGDN)
|
||||
K(KEY_PGUP)
|
||||
K(KEY_APOSTROPHE)
|
||||
K(KEY_EQUALS)
|
||||
K(KEY_SEMICOLON)
|
||||
K(KEY_LBRACKET)
|
||||
K(KEY_RBRACKET)
|
||||
K(KEY_TILDE)
|
||||
|
||||
|
||||
K(MOUSE_BUTTON_LEFT)
|
||||
K(MOUSE_BUTTON_RIGHT)
|
||||
|
@ -92,20 +109,30 @@ static void initInputCodeMap()
|
|||
|
||||
for (int jb = JOY_BUTTON_0; jb < JOY_BUTTON_END; jb++)
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << "JOY_BUTTON_" << jb - JOY_BUTTON_0;
|
||||
inputCodeMap[os.str()] = jb;
|
||||
char buf[32];
|
||||
sprintf(buf, "JOY_BUTTON_%d", jb - JOY_BUTTON_0);
|
||||
inputCodeMap[buf] = jb;
|
||||
}
|
||||
|
||||
// ----------------------
|
||||
|
||||
// Can just use pointers to the strings in the map; they'll stay where they are in memory
|
||||
for(InputCodeMap::iterator it = inputCodeMap.begin(); it != inputCodeMap.end(); ++it)
|
||||
keyNames[it->second] = it->first;
|
||||
}
|
||||
|
||||
int getInputCodeFromLegacyName(const char *name)
|
||||
int getInputCodeFromKeyName(const char *name)
|
||||
{
|
||||
return inputCodeMap[name];
|
||||
}
|
||||
|
||||
const std::string& getKeyNameFromInputCode(int k)
|
||||
{
|
||||
return keyNames[k];
|
||||
}
|
||||
|
||||
struct LegacyKeymapInitializer
|
||||
struct KeyNameInitializer
|
||||
{
|
||||
LegacyKeymapInitializer() { initInputCodeMap(); }
|
||||
KeyNameInitializer() { initInputCodeMap(); }
|
||||
};
|
||||
static LegacyKeymapInitializer s_kinit;
|
||||
static KeyNameInitializer s_kinit;
|
9
BBGE/GameKeyNames.h
Normal file
9
BBGE/GameKeyNames.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef BBGE_LEGACYKEYCODES_H
|
||||
#define BBGE_LEGACYKEYCODES_H
|
||||
|
||||
#include <string>
|
||||
|
||||
int getInputCodeFromKeyName(const char *name);
|
||||
const std::string& getKeyNameFromInputCode(int k);
|
||||
|
||||
#endif
|
|
@ -1,6 +0,0 @@
|
|||
#ifndef BBGE_LEGACYKEYCODES_H
|
||||
#define BBGE_LEGACYKEYCODES_H
|
||||
|
||||
int getInputCodeFromLegacyName(const char *name);
|
||||
|
||||
#endif
|
|
@ -432,6 +432,7 @@ SET(AQUARIA_SRCS
|
|||
${SRCDIR}/Entity.cpp
|
||||
${SRCDIR}/FlockEntity.cpp
|
||||
${SRCDIR}/Game.cpp
|
||||
${SRCDIR}/GameKeyNames.cpp
|
||||
${SRCDIR}/GameStructs.cpp
|
||||
${SRCDIR}/GameplayVariables.cpp
|
||||
${SRCDIR}/GasCloud.cpp
|
||||
|
|
|
@ -362,6 +362,14 @@
|
|||
RelativePath="..\..\BBGE\FrameBuffer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\BBGE\GameKeyNames.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\BBGE\GameKeyNames.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\BBGE\GameKeys.h"
|
||||
>
|
||||
|
@ -390,14 +398,6 @@
|
|||
RelativePath="..\..\BBGE\Joystick.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\BBGE\LegacyKeycodes.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\BBGE\LegacyKeycodes.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\..\BBGE\LensFlare.cpp"
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue