summaryrefslogtreecommitdiffstats
path: root/src/common/restext.cpp
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-19 18:32:18 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-19 18:32:18 +0200
commit51884cef8e015bccbe1fa96dc56dc2f32439ccc5 (patch)
tree53974a01650d52101c96dd11da5e2235c61a02d6 /src/common/restext.cpp
parent4a639cf543c15d45a37674d7eadaf09c23c2203d (diff)
downloadcolobot-51884cef8e015bccbe1fa96dc56dc2f32439ccc5.tar.gz
colobot-51884cef8e015bccbe1fa96dc56dc2f32439ccc5.tar.bz2
colobot-51884cef8e015bccbe1fa96dc56dc2f32439ccc5.zip
Input bindings rewrite
- moved input bindings to CRobotMain - added virtual keymod and joystick button key presses - fixed putenv error; other minor fixes
Diffstat (limited to 'src/common/restext.cpp')
-rw-r--r--src/common/restext.cpp61
1 files changed, 31 insertions, 30 deletions
diff --git a/src/common/restext.cpp b/src/common/restext.cpp
index 5a8e6ba..40d11b7 100644
--- a/src/common/restext.cpp
+++ b/src/common/restext.cpp
@@ -21,6 +21,7 @@
#include "common/logger.h"
#include "CBot/resource.h"
#include "object/object.h"
+#include "object/robotmain.h"
#include <libintl.h>
#include <SDL/SDL_keyboard.h>
@@ -37,39 +38,38 @@ void SetGlobalGamerName(char *name)
struct KeyDesc
{
- KeyRank key;
+ InputSlot key;
char name[20];
};
static KeyDesc keyTable[22] =
{
- { KEYRANK_LEFT, "left;" },
- { KEYRANK_RIGHT, "right;" },
- { KEYRANK_UP, "up;" },
- { KEYRANK_DOWN, "down;" },
- { KEYRANK_GUP, "gup;" },
- { KEYRANK_GDOWN, "gdown;" },
- { KEYRANK_CAMERA, "camera;" },
- { KEYRANK_DESEL, "desel;" },
- { KEYRANK_ACTION, "action;" },
- { KEYRANK_NEAR, "near;" },
- { KEYRANK_AWAY, "away;" },
- { KEYRANK_NEXT, "next;" },
- { KEYRANK_HUMAN, "human;" },
- { KEYRANK_QUIT, "quit;" },
- { KEYRANK_HELP, "help;" },
- { KEYRANK_PROG, "prog;" },
- { KEYRANK_CBOT, "cbot;" },
- { KEYRANK_VISIT, "visit;" },
- { KEYRANK_SPEED10, "speed10;" },
- { KEYRANK_SPEED15, "speed15;" },
- { KEYRANK_SPEED20, "speed20;" },
- { KEYRANK_SPEED30, "speed30;" },
+ { INPUT_SLOT_LEFT, "left;" },
+ { INPUT_SLOT_RIGHT, "right;" },
+ { INPUT_SLOT_UP, "up;" },
+ { INPUT_SLOT_DOWN, "down;" },
+ { INPUT_SLOT_GUP, "gup;" },
+ { INPUT_SLOT_GDOWN, "gdown;" },
+ { INPUT_SLOT_CAMERA, "camera;" },
+ { INPUT_SLOT_DESEL, "desel;" },
+ { INPUT_SLOT_ACTION, "action;" },
+ { INPUT_SLOT_NEAR, "near;" },
+ { INPUT_SLOT_AWAY, "away;" },
+ { INPUT_SLOT_NEXT, "next;" },
+ { INPUT_SLOT_HUMAN, "human;" },
+ { INPUT_SLOT_QUIT, "quit;" },
+ { INPUT_SLOT_HELP, "help;" },
+ { INPUT_SLOT_PROG, "prog;" },
+ { INPUT_SLOT_CBOT, "cbot;" },
+ { INPUT_SLOT_VISIT, "visit;" },
+ { INPUT_SLOT_SPEED10, "speed10;" },
+ { INPUT_SLOT_SPEED15, "speed15;" },
+ { INPUT_SLOT_SPEED20, "speed20;" }
};
// Seeks a key.
-bool SearchKey(const char *cmd, KeyRank &key)
+bool SearchKey(const char *cmd, InputSlot &key)
{
int i;
@@ -88,9 +88,10 @@ bool SearchKey(const char *cmd, KeyRank &key)
static void PutKeyName(char* dst, const char* src)
{
- KeyRank key;
+ InputSlot key;
char name[50];
- int s, d, n, res;
+ int s, d, n;
+ unsigned int res;
s = d = 0;
while ( src[s] != 0 )
@@ -103,9 +104,8 @@ static void PutKeyName(char* dst, const char* src)
{
if ( SearchKey(src+s+5, key) )
{
- // FIXME: res = g_engine->RetKey(key, 0);
- res = 0;
- if ( res != 0 )
+ res = CRobotMain::GetInstancePointer()->GetInputBinding(key).key;
+ if (res != KEY_INVALID)
{
if ( GetResource(RES_KEY, res, name) )
{
@@ -144,7 +144,7 @@ static const char* GetResourceBase(ResType type, int num)
// assert(num < strings_event_len);
if (num >= strings_event_len)
{
- GetLogger()->Error("GetResource invalid event num: %d\n", num);
+ GetLogger()->Warn("GetResource invalid event num: %d\n", num);
return "";
}
str = strings_event[num];
@@ -165,6 +165,7 @@ static const char* GetResourceBase(ResType type, int num)
break;
case RES_KEY:
assert(num < SDLK_LAST);
+ // TODO: virtual keys
str = SDL_GetKeyName(static_cast<SDLKey>(num));
break;
default: