summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/app.cpp182
-rw-r--r--src/app/app.h105
-rw-r--r--src/common/event.h26
-rw-r--r--src/common/global.h57
-rw-r--r--src/common/key.h25
-rw-r--r--src/common/restext.cpp61
-rw-r--r--src/common/restext.h2
-rw-r--r--src/graphics/opengl/gldevice.cpp1
-rw-r--r--src/object/brain.cpp7
-rw-r--r--src/object/robotmain.cpp160
-rw-r--r--src/object/robotmain.h32
-rw-r--r--src/ui/edit.cpp12
-rw-r--r--src/ui/edit.h3
-rw-r--r--src/ui/maindialog.cpp68
-rw-r--r--src/ui/studio.cpp4
15 files changed, 397 insertions, 348 deletions
diff --git a/src/app/app.cpp b/src/app/app.cpp
index 5567e42..0d34811 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -23,6 +23,7 @@
#include "common/logger.h"
#include "common/iman.h"
#include "common/image.h"
+#include "common/key.h"
#include "graphics/opengl/gldevice.h"
#include "object/robotmain.h"
@@ -38,6 +39,9 @@
template<> CApplication* CSingleton<CApplication>::mInstance = nullptr;
+//! Static buffer for putenv locale
+static char S_LANGUAGE[50] = { 0 };
+
//! Interval of timer called to update joystick state
const int JOYSTICK_TIMER_INTERVAL = 1000/30;
@@ -114,9 +118,7 @@ CApplication::CApplication()
m_kmodState = 0;
m_mouseButtonsState = 0;
-
- for (int i = 0; i < TRKEY_MAX; ++i)
- m_trackedKeysState[i] = false;
+ m_trackedKeys = 0;
m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
@@ -124,8 +126,6 @@ CApplication::CApplication()
m_dataPath = "./data";
m_language = LANG_ENGLISH;
-
- SetDefaultInputBindings();
}
CApplication::~CApplication()
@@ -261,7 +261,6 @@ bool CApplication::Create()
/* Gettext initialization */
- m_locale = "LANGUAGE=";
std::string locale = "C";
switch (m_language)
{
@@ -282,8 +281,10 @@ bool CApplication::Create()
break;
}
- m_locale += locale;
- putenv(m_locale.c_str());
+ std::string langStr = "LANGUAGE=";
+ langStr += locale;
+ strcpy(S_LANGUAGE, langStr.c_str());
+ putenv(S_LANGUAGE);
setlocale(LC_ALL, locale.c_str());
std::string trPath = m_dataPath + std::string("/i18n");
@@ -704,6 +705,18 @@ int CApplication::Run()
if (passOn)
m_eventQueue->AddEvent(event);
}
+
+ Event virtualEvent = CreateVirtualEvent(event);
+ if (virtualEvent.type != EVENT_NULL)
+ {
+ bool passOn = ProcessEvent(virtualEvent);
+
+ if (m_engine != nullptr && passOn)
+ passOn = m_engine->ProcessEvent(virtualEvent);
+
+ if (passOn)
+ m_eventQueue->AddEvent(virtualEvent);
+ }
}
}
@@ -788,6 +801,7 @@ Event CApplication::ParseEvent()
else
event.type = EVENT_KEY_UP;
+ event.key.virt = false;
event.key.key = m_private->currentEvent.key.keysym.sym;
event.key.mod = m_private->currentEvent.key.keysym.mod;
event.key.state = TranslatePressState(m_private->currentEvent.key.state);
@@ -849,13 +863,23 @@ Event CApplication::ParseEvent()
return event;
}
-/** Processes incoming events. It is the first function called after an event is captures.
- Function returns \c true if the event is to be passed on to other processing functions
- or \c false if not. */
-bool CApplication::ProcessEvent(const Event &event)
+/**
+ * Processes incoming events. It is the first function called after an event is captured.
+ * Event is modified, updating its tracked keys state and mouse position to current values.
+ * Function returns \c true if the event is to be passed on to other processing functions
+ * or \c false if not. */
+bool CApplication::ProcessEvent(Event &event)
{
CLogger *l = GetLogger();
+ event.trackedKeys = m_trackedKeys;
+ if (GetSystemMouseVisibile())
+ event.mousePos = m_systemMousePos;
+ else
+ event.mousePos = m_engine->GetMousePos();
+
+ // TODO: mouse pos
+
if (event.type == EVENT_ACTIVE)
{
if (m_debugMode)
@@ -876,50 +900,50 @@ bool CApplication::ProcessEvent(const Event &event)
m_kmodState = event.key.mod;
if ((m_kmodState & KEY_MOD(SHIFT)) != 0)
- m_trackedKeysState[TRKEY_SHIFT] = true;
+ m_trackedKeys |= TRKEY_SHIFT;
else if ((m_kmodState & KEY_MOD(CTRL)) != 0)
- m_trackedKeysState[TRKEY_CONTROL] = true;
+ m_trackedKeys |= TRKEY_CONTROL;
else if (event.key.key == KEY(KP8))
- m_trackedKeysState[TRKEY_NUM_UP] = true;
+ m_trackedKeys |= TRKEY_NUM_UP;
else if (event.key.key == KEY(KP2))
- m_trackedKeysState[TRKEY_NUM_DOWN] = true;
+ m_trackedKeys |= TRKEY_NUM_DOWN;
else if (event.key.key == KEY(KP4))
- m_trackedKeysState[TRKEY_NUM_LEFT] = true;
+ m_trackedKeys |= TRKEY_NUM_LEFT;
else if (event.key.key == KEY(KP6))
- m_trackedKeysState[TRKEY_NUM_RIGHT] = true;
+ m_trackedKeys |= TRKEY_NUM_RIGHT;
else if (event.key.key == KEY(KP_PLUS))
- m_trackedKeysState[TRKEY_NUM_PLUS] = true;
+ m_trackedKeys |= TRKEY_NUM_PLUS;
else if (event.key.key == KEY(KP_MINUS))
- m_trackedKeysState[TRKEY_NUM_MINUS] = true;
+ m_trackedKeys |= TRKEY_NUM_MINUS;
else if (event.key.key == KEY(PAGEUP))
- m_trackedKeysState[TRKEY_PAGE_UP] = true;
+ m_trackedKeys |= TRKEY_PAGE_UP;
else if (event.key.key == KEY(PAGEDOWN))
- m_trackedKeysState[TRKEY_PAGE_DOWN] = true;
+ m_trackedKeys |= TRKEY_PAGE_DOWN;
}
else if (event.type == EVENT_KEY_UP)
{
m_kmodState = event.key.mod;
if ((m_kmodState & KEY_MOD(SHIFT)) != 0)
- m_trackedKeysState[TRKEY_SHIFT] = false;
+ m_trackedKeys &= ~TRKEY_SHIFT;
else if ((m_kmodState & KEY_MOD(CTRL)) != 0)
- m_trackedKeysState[TRKEY_CONTROL] = false;
+ m_trackedKeys &= ~TRKEY_CONTROL;
else if (event.key.key == KEY(KP8))
- m_trackedKeysState[TRKEY_NUM_UP] = false;
+ m_trackedKeys &= ~TRKEY_NUM_UP;
else if (event.key.key == KEY(KP2))
- m_trackedKeysState[TRKEY_NUM_DOWN] = false;
+ m_trackedKeys &= ~TRKEY_NUM_DOWN;
else if (event.key.key == KEY(KP4))
- m_trackedKeysState[TRKEY_NUM_LEFT] = false;
+ m_trackedKeys &= ~TRKEY_NUM_LEFT;
else if (event.key.key == KEY(KP6))
- m_trackedKeysState[TRKEY_NUM_RIGHT] = false;
+ m_trackedKeys &= ~TRKEY_NUM_RIGHT;
else if (event.key.key == KEY(KP_PLUS))
- m_trackedKeysState[TRKEY_NUM_PLUS] = false;
+ m_trackedKeys &= ~TRKEY_NUM_PLUS;
else if (event.key.key == KEY(KP_MINUS))
- m_trackedKeysState[TRKEY_NUM_MINUS] = false;
+ m_trackedKeys &= ~TRKEY_NUM_MINUS;
else if (event.key.key == KEY(PAGEUP))
- m_trackedKeysState[TRKEY_PAGE_UP] = false;
+ m_trackedKeys &= ~TRKEY_PAGE_UP;
else if (event.key.key == KEY(PAGEDOWN))
- m_trackedKeysState[TRKEY_PAGE_DOWN] = false;
+ m_trackedKeys &= ~TRKEY_PAGE_DOWN;
}
else if (event.type == EVENT_MOUSE_BUTTON_DOWN)
{
@@ -938,6 +962,7 @@ bool CApplication::ProcessEvent(const Event &event)
case EVENT_KEY_DOWN:
case EVENT_KEY_UP:
l->Info("EVENT_KEY_%s:\n", (event.type == EVENT_KEY_DOWN) ? "DOWN" : "UP");
+ l->Info(" virt = %s\n", (event.key.virt) ? "true" : "false");
l->Info(" key = %4x\n", event.key.key);
l->Info(" state = %s\n", (event.key.state == STATE_PRESSED) ? "STATE_PRESSED" : "STATE_RELEASED");
l->Info(" mod = %4x\n", event.key.mod);
@@ -980,6 +1005,48 @@ bool CApplication::ProcessEvent(const Event &event)
return true;
}
+
+Event CApplication::CreateVirtualEvent(const Event& sourceEvent)
+{
+ Event virtualEvent;
+ virtualEvent.systemEvent = true;
+
+ if ((sourceEvent.type == EVENT_KEY_DOWN) || (sourceEvent.type == EVENT_KEY_UP))
+ {
+ virtualEvent.type = sourceEvent.type;
+ virtualEvent.key = sourceEvent.key;
+ virtualEvent.key.virt = true;
+
+ if (sourceEvent.key.key == KEY(LCTRL) || sourceEvent.key.key == KEY(RCTRL))
+ virtualEvent.key.key = VIRTUAL_KMOD(CTRL);
+ else if (sourceEvent.key.key == KEY(LSHIFT) || sourceEvent.key.key == KEY(RSHIFT))
+ virtualEvent.key.key = VIRTUAL_KMOD(SHIFT);
+ else if (sourceEvent.key.key == KEY(LALT) || sourceEvent.key.key == KEY(RALT))
+ virtualEvent.key.key = VIRTUAL_KMOD(ALT);
+ else if (sourceEvent.key.key == KEY(LMETA) || sourceEvent.key.key == KEY(RMETA))
+ virtualEvent.key.key = VIRTUAL_KMOD(META);
+ else
+ virtualEvent.type = EVENT_NULL;
+ }
+ else if ((sourceEvent.type == EVENT_JOY_BUTTON_DOWN) || (sourceEvent.type == EVENT_JOY_BUTTON_UP))
+ {
+ if (sourceEvent.type == EVENT_JOY_BUTTON_DOWN)
+ virtualEvent.type = EVENT_KEY_DOWN;
+ else
+ virtualEvent.type = EVENT_KEY_UP;
+ virtualEvent.key.virt = true;
+ virtualEvent.key.key = VIRTUAL_JOY(sourceEvent.joyButton.button);
+ virtualEvent.key.mod = 0;
+ virtualEvent.key.unicode = 0;
+ }
+ else
+ {
+ virtualEvent.type = EVENT_NULL;
+ }
+
+ return virtualEvent;
+}
+
/** Renders the frame and swaps buffers as necessary */
void CApplication::Render()
{
@@ -1144,41 +1211,6 @@ bool CApplication::GetDebugMode()
return m_debugMode;
}
-void CApplication::SetDefaultInputBindings()
-{
- for (int i = 0; i < KEYRANK_MAX; i++)
- m_inputBindings[i].Reset();
-
- m_inputBindings[KEYRANK_LEFT ].key = KEY(LEFT);
- m_inputBindings[KEYRANK_RIGHT ].key = KEY(RIGHT);
- m_inputBindings[KEYRANK_UP ].key = KEY(UP);
- m_inputBindings[KEYRANK_DOWN ].key = KEY(DOWN);
- m_inputBindings[KEYRANK_GUP ].kmod = KEY_MOD(SHIFT);
- m_inputBindings[KEYRANK_GDOWN ].kmod = KEY_MOD(CTRL);
- m_inputBindings[KEYRANK_CAMERA ].key = KEY(SPACE);
- m_inputBindings[KEYRANK_CAMERA ].joy = 2;
- m_inputBindings[KEYRANK_DESEL ].key = KEY(KP0);
- m_inputBindings[KEYRANK_DESEL ].kmod = 6;
- m_inputBindings[KEYRANK_ACTION ].key = KEY(RETURN);
- m_inputBindings[KEYRANK_ACTION ].joy = 1;
- m_inputBindings[KEYRANK_NEAR ].key = KEY(KP_PLUS);
- m_inputBindings[KEYRANK_NEAR ].joy = 5;
- m_inputBindings[KEYRANK_AWAY ].key = KEY(KP_MINUS);
- m_inputBindings[KEYRANK_AWAY ].joy = 4;
- m_inputBindings[KEYRANK_NEXT ].key = KEY(TAB);
- m_inputBindings[KEYRANK_NEXT ].joy = 3;
- m_inputBindings[KEYRANK_HUMAN ].key = KEY(HOME);
- m_inputBindings[KEYRANK_HUMAN ].joy = 7;
- m_inputBindings[KEYRANK_QUIT ].key = KEY(ESCAPE);
- m_inputBindings[KEYRANK_HELP ].key = KEY(F1);
- m_inputBindings[KEYRANK_PROG ].key = KEY(F2);
- m_inputBindings[KEYRANK_CBOT ].key = KEY(F3);
- m_inputBindings[KEYRANK_VISIT ].key = KEY(KP_PERIOD);
- m_inputBindings[KEYRANK_SPEED10].key = KEY(F4);
- m_inputBindings[KEYRANK_SPEED15].key = KEY(F5);
- m_inputBindings[KEYRANK_SPEED20].key = KEY(F6);
-}
-
int CApplication::GetKmods()
{
return m_kmodState;
@@ -1191,7 +1223,7 @@ bool CApplication::GetKmodState(int kmod)
bool CApplication::GetTrackedKeyState(TrackedKey key)
{
- return m_trackedKeysState[key];
+ return (m_trackedKeys & key) != 0;
}
bool CApplication::GetMouseButtonState(int index)
@@ -1201,24 +1233,12 @@ bool CApplication::GetMouseButtonState(int index)
void CApplication::ResetKeyStates()
{
- for (int i = 0; i < TRKEY_MAX; ++i)
- m_trackedKeysState[i] = false;
-
+ m_trackedKeys = 0;
m_kmodState = 0;
m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
}
-void CApplication::SetInputBinding(InputSlot slot, const InputBinding& binding)
-{
- m_inputBindings[slot] = binding;
-}
-
-const InputBinding& CApplication::GetInputBinding(InputSlot slot)
-{
- return m_inputBindings[slot];
-}
-
void CApplication::SetGrabInput(bool grab)
{
SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
diff --git a/src/app/app.h b/src/app/app.h
index d3fa647..8429e0e 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -75,75 +75,16 @@ enum VideoQueryResult
*/
enum TrackedKey
{
- TRKEY_SHIFT,
- TRKEY_CONTROL,
- TRKEY_NUM_UP,
- TRKEY_NUM_DOWN,
- TRKEY_NUM_LEFT,
- TRKEY_NUM_RIGHT,
- TRKEY_NUM_PLUS,
- TRKEY_NUM_MINUS,
- TRKEY_PAGE_UP,
- TRKEY_PAGE_DOWN,
- TRKEY_MAX
-};
-
-/**
- * \enum InputSlot
- * \brief Available slots for input bindings
- */
-enum InputSlot
-{
- INPUT_SLOT_LEFT = 0,
- INPUT_SLOT_RIGHT = 1,
- INPUT_SLOT_UP = 2,
- INPUT_SLOT_DOWN = 3,
- INPUT_SLOT_GUP = 4,
- INPUT_SLOT_GDOWN = 5,
- INPUT_SLOT_CAMERA = 6,
- INPUT_SLOT_DESEL = 7,
- INPUT_SLOT_ACTION = 8,
- INPUT_SLOT_NEAR = 9,
- INPUT_SLOT_AWAY = 10,
- INPUT_SLOT_NEXT = 11,
- INPUT_SLOT_HUMAN = 12,
- INPUT_SLOT_QUIT = 13,
- INPUT_SLOT_HELP = 14,
- INPUT_SLOT_PROG = 15,
- INPUT_SLOT_VISIT = 16,
- INPUT_SLOT_SPEED10 = 17,
- INPUT_SLOT_SPEED15 = 18,
- INPUT_SLOT_SPEED20 = 19,
- INPUT_SLOT_SPEED30 = 20,
- INPUT_SLOT_AIMUP = 21,
- INPUT_SLOT_AIMDOWN = 22,
- INPUT_SLOT_CBOT = 23,
-
- INPUT_SLOT_MAX
-};
-
-/**
- * \struct InputBinding
- * \brief Settable binding for user input
- */
-struct InputBinding
-{
- //! Key
- unsigned int key;
- //! Key modifier (e.g. shift, control)
- unsigned int kmod;
- //! Joystick button
- unsigned int joy;
-
- inline InputBinding()
- {
- Reset();
- }
-
- inline void Reset()
- {
- key = kmod = joy = static_cast<unsigned int>(-1);
- }
+ TRKEY_SHIFT = (1<<0),
+ TRKEY_CONTROL = (1<<1),
+ TRKEY_NUM_UP = (1<<2),
+ TRKEY_NUM_DOWN = (1<<3),
+ TRKEY_NUM_LEFT = (1<<4),
+ TRKEY_NUM_RIGHT = (1<<5),
+ TRKEY_NUM_PLUS = (1<<6),
+ TRKEY_NUM_MINUS = (1<<7),
+ TRKEY_PAGE_UP = (1<<8),
+ TRKEY_PAGE_DOWN = (1<<9)
};
/**
@@ -303,19 +244,6 @@ public:
//! Resets tracked key states, modifiers and motion vectors
void ResetKeyStates();
-
- // TODO move input binding and motion vectors to CRobotMain
-
- //! Sets the default input bindings
- void SetDefaultInputBindings();
-
- //! Management of input bindings
- //@{
- void SetInputBinding(InputSlot slot, const InputBinding& binding);
- const InputBinding& GetInputBinding(InputSlot slot);
- //@}
-
-
//! Management of the grab mode for input (keyboard & mouse)
//@{
void SetGrabInput(bool grab);
@@ -355,8 +283,10 @@ protected:
//! Processes the captured SDL event to Event struct
Event ParseEvent();
+ //! If applicable, creates a virtual event to match the changed state as of new event
+ Event CreateVirtualEvent(const Event& sourceEvent);
//! Handles some incoming events
- bool ProcessEvent(const Event &event);
+ bool ProcessEvent(Event &event);
//! Renders the image in window
void Render();
@@ -423,13 +353,10 @@ protected:
//! Current state of key modifiers (mask of SDLMod)
unsigned int m_kmodState;
//! Current state of some tracked keys (mask of TrackedKey)
- bool m_trackedKeysState[TRKEY_MAX];
+ unsigned int m_trackedKeys;
//! Current state of mouse buttons (mask of button indexes)
unsigned int m_mouseButtonsState;
- //! Bindings for user inputs
- InputBinding m_inputBindings[INPUT_SLOT_MAX];
-
//! Motion vector set by keyboard
Math::Vector m_keyMotion;
//! Motion vector set by joystick
@@ -452,9 +379,5 @@ protected:
//! Application language
Language m_language;
-
-private:
- //! Set locale, needed for putenv/setenv
- std::string m_locale;
};
diff --git a/src/common/event.h b/src/common/event.h
index 4df1e6d..73950af 100644
--- a/src/common/event.h
+++ b/src/common/event.h
@@ -44,7 +44,9 @@ struct KeyEventData
{
//! STATE_PRESSED or STATE_RELEASED */
PressState state;
- //! Key symbol: KEY(...) macro value (from common/key.h)
+ //! If true, the key is a virtual code generated by key modifier press or joystick button press
+ bool virt;
+ //! Key symbol: KEY(...) macro value or virtual key VIRTUAL_... (from common/key.h)
unsigned int key;
//! Keyboard modifiers: a bitmask made of KEY_MOD(...) macro values (from common/key.h)
unsigned int mod;
@@ -52,7 +54,7 @@ struct KeyEventData
unsigned int unicode;
KeyEventData()
- : state(STATE_PRESSED), key(0), mod(0), unicode(0) {}
+ : state(STATE_PRESSED), virt(false), key(0), mod(0), unicode(0) {}
};
/** \struct MouseMotionEventData
@@ -60,7 +62,7 @@ struct KeyEventData
struct MouseMoveEventData
{
//! Current button state
- unsigned char state;
+ PressState state;
//! Position of mouse in normalized coordinates (0..1)
Math::Point pos;
@@ -171,17 +173,25 @@ struct Event
ActiveEventData active;
};
+ //! State of tracked keys (mask of TrackedKey enum values)
+ unsigned int trackedKeys;
+
+ //! Mouse position is provided also for other types of events besides mouse events
+ Math::Point mousePos;
+
+ // TODO: remove and replace references with trackedKeys
+ short keyState;
+
+ // TODO: remove and replace references with mousePos
+ Math::Point pos;
+
// TODO: remove
long param; // parameter
- // TODO: remove?
- Math::Point pos; // mouse position (0 .. 1)
-
// TODO: ?
float axeX; // control the X axis (-1 .. 1)
float axeY; // control of the Y axis (-1 .. 1)
float axeZ; // control the Z axis (-1 .. 1)
- short keyState; // state of the keyboard (KS_ *)
// TODO: remove in longer term (use CApplication's new time functions instead)
float rTime; // relative time
@@ -190,10 +200,10 @@ struct Event
{
type = aType;
systemEvent = false;
+ trackedKeys = 0;
param = 0;
axeX = axeY = axeZ = 0.0f;
- keyState = 0;
rTime = 0.0f;
}
};
diff --git a/src/common/global.h b/src/common/global.h
index 9cb3dd9..addb56d 100644
--- a/src/common/global.h
+++ b/src/common/global.h
@@ -82,38 +82,37 @@ enum ResearchType
};
/**
- * \enum KeyRank
- * \brief Slots for key assignment of user controls
+ * \enum InputSlot
+ * \brief Available slots for input bindings
*/
-// TODO: remove (use the new InputSlot enum from app/app.h)
-enum KeyRank
+enum InputSlot
{
- KEYRANK_LEFT = 0,
- KEYRANK_RIGHT = 1,
- KEYRANK_UP = 2,
- KEYRANK_DOWN = 3,
- KEYRANK_GUP = 4,
- KEYRANK_GDOWN = 5,
- KEYRANK_CAMERA = 6,
- KEYRANK_DESEL = 7,
- KEYRANK_ACTION = 8,
- KEYRANK_NEAR = 9,
- KEYRANK_AWAY = 10,
- KEYRANK_NEXT = 11,
- KEYRANK_HUMAN = 12,
- KEYRANK_QUIT = 13,
- KEYRANK_HELP = 14,
- KEYRANK_PROG = 15,
- KEYRANK_VISIT = 16,
- KEYRANK_SPEED10 = 17,
- KEYRANK_SPEED15 = 18,
- KEYRANK_SPEED20 = 19,
- KEYRANK_SPEED30 = 20,
- KEYRANK_AIMUP = 21,
- KEYRANK_AIMDOWN = 22,
- KEYRANK_CBOT = 23,
+ INPUT_SLOT_LEFT = 0,
+ INPUT_SLOT_RIGHT = 1,
+ INPUT_SLOT_UP = 2,
+ INPUT_SLOT_DOWN = 3,
+ INPUT_SLOT_GUP = 4,
+ INPUT_SLOT_GDOWN = 5,
+ INPUT_SLOT_CAMERA = 6,
+ INPUT_SLOT_DESEL = 7,
+ INPUT_SLOT_ACTION = 8,
+ INPUT_SLOT_NEAR = 9,
+ INPUT_SLOT_AWAY = 10,
+ INPUT_SLOT_NEXT = 11,
+ INPUT_SLOT_HUMAN = 12,
+ INPUT_SLOT_QUIT = 13,
+ INPUT_SLOT_HELP = 14,
+ INPUT_SLOT_PROG = 15,
+ INPUT_SLOT_VISIT = 16,
+ INPUT_SLOT_SPEED10 = 17,
+ INPUT_SLOT_SPEED15 = 18,
+ INPUT_SLOT_SPEED20 = 19,
+ INPUT_SLOT_SPEED30 = 20,
+ INPUT_SLOT_AIMUP = 21,
+ INPUT_SLOT_AIMDOWN = 22,
+ INPUT_SLOT_CBOT = 23,
- KEYRANK_MAX
+ INPUT_SLOT_MAX
};
// TODO: move to CRobotMain
diff --git a/src/common/key.h b/src/common/key.h
index 1d03a47..11076a3 100644
--- a/src/common/key.h
+++ b/src/common/key.h
@@ -33,3 +33,28 @@
// Key modifier defined as concatenation to KMOD_...
// If need arises, it can be changed to custom function or anything else
#define KEY_MOD(x) KMOD_ ## x
+
+/**
+ * \enum VirtualKmod
+ * \brief Virtual key codes generated on kmod presses
+ *
+ * These are provided here because left and right pair of keys generate different codes.
+ */
+enum VirtualKmod
+{
+ VIRTUAL_KMOD_CTRL = SDLK_LAST + 100, //! < control (left or right)
+ VIRTUAL_KMOD_SHIFT = SDLK_LAST + 101, //! < shift (left or right)
+ VIRTUAL_KMOD_ALT = SDLK_LAST + 102, //! < alt (left or right)
+ VIRTUAL_KMOD_META = SDLK_LAST + 103 //! < win key (left or right)
+};
+
+// Just syntax sugar
+// So it is the same as other macros
+#define VIRTUAL_KMOD(x) VIRTUAL_KMOD_ ## x
+
+// Virtual key code generated on joystick button presses
+// num is number of joystick button
+#define VIRTUAL_JOY(num) (SDLK_LAST + 200 + num)
+
+//! Special value for invalid key bindings
+const unsigned int KEY_INVALID = SDLK_LAST + 1000;
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:
diff --git a/src/common/restext.h b/src/common/restext.h
index 4b565ba..6abb7f5 100644
--- a/src/common/restext.h
+++ b/src/common/restext.h
@@ -43,7 +43,7 @@ enum ResType
// TODO: move to CRobotMain
extern void SetGlobalGamerName(char *name);
-extern bool SearchKey(const char *cmd, KeyRank &key);
+extern bool SearchKey(const char *cmd, InputSlot& slot);
extern bool GetResource(ResType type, int num, char* text);
extern const char * const strings_text[];
diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp
index 881e273..416b506 100644
--- a/src/graphics/opengl/gldevice.cpp
+++ b/src/graphics/opengl/gldevice.cpp
@@ -184,7 +184,6 @@ void Gfx::CGLDevice::BeginScene()
void Gfx::CGLDevice::EndScene()
{
- glFlush();
}
void Gfx::CGLDevice::Clear()
diff --git a/src/object/brain.cpp b/src/object/brain.cpp
index 3f2dcb2..c395c6a 100644
--- a/src/object/brain.cpp
+++ b/src/object/brain.cpp
@@ -202,12 +202,9 @@ bool CBrain::EventProcess(const Event &event)
action = EVENT_NULL;
- CApplication* app = CApplication::GetInstancePointer();
-
if ( event.type == EVENT_KEY_DOWN &&
- (event.key.key == app->GetInputBinding(INPUT_SLOT_ACTION).key
- /* TODO joystick input binding
- event.param == app->GetInputBinding(INPUT_SLOT_ACTION).joy*/ ) &&
+ (event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).key ||
+ event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).joy ) &&
!m_main->GetEditLock() )
{
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
diff --git a/src/object/robotmain.cpp b/src/object/robotmain.cpp
index 3d1aff0..9dca371 100644
--- a/src/object/robotmain.cpp
+++ b/src/object/robotmain.cpp
@@ -73,6 +73,8 @@
#include "ui/window.h"
+template<> CRobotMain* CSingleton<CRobotMain>::mInstance = nullptr;
+
// TODO: remove once using std::string
const int MAX_FNAME = 255;
@@ -811,6 +813,8 @@ CRobotMain::CRobotMain(CInstanceManager* iMan, CApplication* app)
InitClassFILE();
CScript::InitFonctions();
+
+ SetDefaultInputBindings();
}
//! Destructor of robot application
@@ -858,6 +862,56 @@ void CRobotMain::CreateIni()
m_dialog->SetupMemorize();*/
}
+void CRobotMain::SetDefaultInputBindings()
+{
+ for (int i = 0; i < INPUT_SLOT_MAX; i++)
+ {
+ m_inputBindings[i].key = m_inputBindings[i].joy = KEY_INVALID;
+ }
+
+ m_inputBindings[INPUT_SLOT_LEFT ].key = KEY(LEFT);
+ m_inputBindings[INPUT_SLOT_RIGHT ].key = KEY(RIGHT);
+ m_inputBindings[INPUT_SLOT_UP ].key = KEY(UP);
+ m_inputBindings[INPUT_SLOT_DOWN ].key = KEY(DOWN);
+ m_inputBindings[INPUT_SLOT_GUP ].key = VIRTUAL_KMOD(SHIFT);
+ m_inputBindings[INPUT_SLOT_GDOWN ].key = VIRTUAL_KMOD(CTRL);
+ m_inputBindings[INPUT_SLOT_CAMERA ].key = KEY(SPACE);
+ m_inputBindings[INPUT_SLOT_CAMERA ].joy = VIRTUAL_JOY(2);
+ m_inputBindings[INPUT_SLOT_DESEL ].key = KEY(KP0);
+ m_inputBindings[INPUT_SLOT_DESEL ].joy = VIRTUAL_JOY(6);
+ m_inputBindings[INPUT_SLOT_ACTION ].key = KEY(RETURN);
+ m_inputBindings[INPUT_SLOT_ACTION ].joy = VIRTUAL_JOY(1);
+ m_inputBindings[INPUT_SLOT_NEAR ].key = KEY(KP_PLUS);
+ m_inputBindings[INPUT_SLOT_NEAR ].joy = VIRTUAL_JOY(5);
+ m_inputBindings[INPUT_SLOT_AWAY ].key = KEY(KP_MINUS);
+ m_inputBindings[INPUT_SLOT_AWAY ].joy = VIRTUAL_JOY(4);
+ m_inputBindings[INPUT_SLOT_NEXT ].key = KEY(TAB);
+ m_inputBindings[INPUT_SLOT_NEXT ].joy = VIRTUAL_JOY(3);
+ m_inputBindings[INPUT_SLOT_HUMAN ].key = KEY(HOME);
+ m_inputBindings[INPUT_SLOT_HUMAN ].joy = VIRTUAL_JOY(7);
+ m_inputBindings[INPUT_SLOT_QUIT ].key = KEY(ESCAPE);
+ m_inputBindings[INPUT_SLOT_HELP ].key = KEY(F1);
+ m_inputBindings[INPUT_SLOT_PROG ].key = KEY(F2);
+ m_inputBindings[INPUT_SLOT_CBOT ].key = KEY(F3);
+ m_inputBindings[INPUT_SLOT_VISIT ].key = KEY(KP_PERIOD);
+ m_inputBindings[INPUT_SLOT_SPEED10].key = KEY(F4);
+ m_inputBindings[INPUT_SLOT_SPEED15].key = KEY(F5);
+ m_inputBindings[INPUT_SLOT_SPEED20].key = KEY(F6);
+}
+
+void CRobotMain::SetInputBinding(InputSlot slot, InputBinding binding)
+{
+ unsigned int index = static_cast<unsigned int>(slot);
+ assert(index >= 0 && index < INPUT_SLOT_MAX);
+ m_inputBindings[index] = binding;
+}
+
+const InputBinding& CRobotMain::GetInputBinding(InputSlot slot)
+{
+ unsigned int index = static_cast<unsigned int>(slot);
+ assert(index >= 0 && index < INPUT_SLOT_MAX);
+ return m_inputBindings[index];
+}
//! Changes phase
void CRobotMain::ChangePhase(Phase phase)
@@ -1109,8 +1163,6 @@ void CRobotMain::ChangePhase(Phase phase)
//! Processes an event
bool CRobotMain::EventProcess(const Event &event)
{
- // TODO: rewrite key handling to input bindings
-
if (event.type == EVENT_FRAME)
{
if (!m_movie->EventProcess(event)) // end of the movie?
@@ -1197,10 +1249,10 @@ bool CRobotMain::EventProcess(const Event &event)
if (event.type == EVENT_KEY_DOWN)
{
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_HELP).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_HELP).joy */ ||
- event.key.key == m_app->GetInputBinding(INPUT_SLOT_PROG).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_PROG).joy */ ||
+ if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_HELP).joy ||
+ event.key.key == GetInputBinding(INPUT_SLOT_PROG).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_PROG).joy ||
event.key.key == KEY(ESCAPE))
{
StopDisplayInfo();
@@ -1235,14 +1287,14 @@ bool CRobotMain::EventProcess(const Event &event)
}
if (m_editLock) // current edition?
{
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_HELP).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_HELP).joy*/ )
+ if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_HELP).joy)
{
StartDisplayInfo(SATCOM_HUSTON, false);
return false;
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_PROG).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_PROG).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_PROG).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_PROG).joy)
{
StartDisplayInfo(SATCOM_PROG, false);
return false;
@@ -1251,8 +1303,8 @@ bool CRobotMain::EventProcess(const Event &event)
}
if (m_movieLock) // current movie?
{
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_QUIT).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_QUIT).joy */ ||
+ if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_QUIT).joy ||
event.key.key == KEY(ESCAPE))
{
AbortMovie();
@@ -1261,21 +1313,21 @@ bool CRobotMain::EventProcess(const Event &event)
}
if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT)
{
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_VISIT).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_VISIT).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_VISIT).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_VISIT).joy)
{
StartDisplayVisit(EVENT_NULL);
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_QUIT).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_QUIT).joy */ ||
+ if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_QUIT).joy ||
event.key.key == KEY(ESCAPE))
{
StopDisplayVisit();
}
return false;
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_QUIT).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_QUIT).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_QUIT).joy)
{
if (m_movie->IsExist())
StartDisplayInfo(SATCOM_HUSTON, false);
@@ -1295,55 +1347,55 @@ bool CRobotMain::EventProcess(const Event &event)
ChangePause(!m_engine->GetPause());
}
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_CAMERA).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_CAMERA).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).joy)
{
ChangeCamera();
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_DESEL).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_DESEL).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_DESEL).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_DESEL).joy)
{
if (m_shortCut)
DeselectObject();
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_HUMAN).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_HUMAN).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_HUMAN).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_HUMAN).joy)
{
SelectHuman();
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_NEXT).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_NEXT).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_NEXT).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_NEXT).joy)
{
if (m_shortCut)
m_short->SelectNext();
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_HELP).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_HELP).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_HELP).joy)
{
StartDisplayInfo(SATCOM_HUSTON, true);
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_PROG).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_PROG).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_PROG).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_PROG).joy)
{
StartDisplayInfo(SATCOM_PROG, true);
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_VISIT).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_VISIT).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_VISIT).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_VISIT).joy)
{
StartDisplayVisit(EVENT_NULL);
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_SPEED10).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_SPEED10).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED10).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_SPEED10).joy)
{
SetSpeed(1.0f);
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_SPEED15).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_SPEED15).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED15).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_SPEED15).joy)
{
SetSpeed(1.5f);
}
- if (event.key.key == m_app->GetInputBinding(INPUT_SLOT_SPEED20).key /* TODO: joystick
- || event.key.key == m_app->GetInputBinding(INPUT_SLOT_SPEED20).joy*/)
+ if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED20).key ||
+ event.key.key == GetInputBinding(INPUT_SLOT_SPEED20).joy)
{
SetSpeed(2.0f);
}
@@ -2925,26 +2977,26 @@ void CRobotMain::KeyCamera(EventType type, unsigned int key)
if (type == EVENT_KEY_UP)
{
- if (key == m_app->GetInputBinding(INPUT_SLOT_LEFT).key /* TODO: joystick
- || key == m_app->GetInputBinding(INPUT_SLOT_LEFT).joy*/)
+ if (key == GetInputBinding(INPUT_SLOT_LEFT).key ||
+ key == GetInputBinding(INPUT_SLOT_LEFT).joy)
{
m_cameraPan = 0.0f;
}
- if (key == m_app->GetInputBinding(INPUT_SLOT_RIGHT).key /* TODO: joystick
- || key == m_app->GetInputBinding(INPUT_SLOT_RIGHT).joy*/)
+ if (key == GetInputBinding(INPUT_SLOT_RIGHT).key ||
+ key == GetInputBinding(INPUT_SLOT_RIGHT).joy)
{
m_cameraPan = 0.0f;
}
- if (key == m_app->GetInputBinding(INPUT_SLOT_UP).key /* TODO: joystick
- || key == m_app->GetInputBinding(INPUT_SLOT_UP).joy*/ )
+ if (key == GetInputBinding(INPUT_SLOT_UP).key ||
+ key == GetInputBinding(INPUT_SLOT_UP).joy)
{
m_cameraZoom = 0.0f;
}
- if (key == m_app->GetInputBinding(INPUT_SLOT_DOWN).key /* TODO: joystick
- || key == m_app->GetInputBinding(INPUT_SLOT_DOWN).joy*/ )
+ if (key == GetInputBinding(INPUT_SLOT_DOWN).key ||
+ key == GetInputBinding(INPUT_SLOT_DOWN).joy)
{
m_cameraZoom = 0.0f;
}
@@ -2960,26 +3012,26 @@ void CRobotMain::KeyCamera(EventType type, unsigned int key)
if (type == EVENT_KEY_DOWN)
{
- if (key == m_app->GetInputBinding(INPUT_SLOT_LEFT).key /* TODO: joystick
- || key == m_app->GetInputBinding(INPUT_SLOT_LEFT).joy*/)
+ if (key == GetInputBinding(INPUT_SLOT_LEFT).key ||
+ key == GetInputBinding(INPUT_SLOT_LEFT).joy)
{
m_cameraPan = -1.0f;
}
- if (key == m_app->GetInputBinding(INPUT_SLOT_RIGHT).key /* TODO: joystick
- || key == m_app->GetInputBinding(INPUT_SLOT_RIGHT).joy*/)
+ if (key == GetInputBinding(INPUT_SLOT_RIGHT).key ||
+ key == GetInputBinding(INPUT_SLOT_RIGHT).joy)
{
m_cameraPan = 1.0f;
}
- if (key == m_app->GetInputBinding(INPUT_SLOT_UP).key /* TODO: joystick
- || key == m_app->GetInputBinding(INPUT_SLOT_UP).joy*/)
+ if (key == GetInputBinding(INPUT_SLOT_UP).key ||
+ key == GetInputBinding(INPUT_SLOT_UP).joy)
{
m_cameraZoom = -1.0f;
}
- if (key == m_app->GetInputBinding(INPUT_SLOT_DOWN).key /* TODO: joystick
- || key == m_app->GetInputBinding(INPUT_SLOT_DOWN).joy*/)
+ if (key == GetInputBinding(INPUT_SLOT_DOWN).key ||
+ key == GetInputBinding(INPUT_SLOT_DOWN).joy)
{
m_cameraZoom = 1.0f;
}
diff --git a/src/object/robotmain.h b/src/object/robotmain.h
index 25c55f6..bce8e17 100644
--- a/src/object/robotmain.h
+++ b/src/object/robotmain.h
@@ -19,8 +19,10 @@
#pragma once
#include "common/global.h"
-#include "common/misc.h"
+#include "common/singleton.h"
+
#include "graphics/engine/particle.h"
+
#include "object/object.h"
#include "object/mainmovie.h"
@@ -140,8 +142,22 @@ const int SATCOM_SOLUCE = 5;
const int SATCOM_MAX = 6;
+/**
+ * \enum InputBinding
+ * \brief Binding for input slot
+ */
+struct InputBinding
+{
+ //! Keyboard binding code (can be regular or virtual)
+ unsigned int key;
+ //! Joystick binding code (virtual)
+ unsigned int joy;
+
+ InputBinding() : key(KEY_INVALID), joy(KEY_INVALID) {}
+};
-class CRobotMain
+
+class CRobotMain : public CSingleton<CRobotMain>
{
public:
CRobotMain(CInstanceManager* iMan, CApplication* app);
@@ -149,6 +165,15 @@ public:
void CreateIni();
+ //! Sets the default input bindings
+ void SetDefaultInputBindings();
+
+ //! Management of input bindings
+ //@{
+ void SetInputBinding(InputSlot slot, InputBinding binding);
+ const InputBinding& GetInputBinding(InputSlot slot);
+ //@}
+
void ChangePhase(Phase phase);
bool EventProcess(const Event &event);
@@ -352,6 +377,9 @@ protected:
Ui::CDisplayInfo* m_displayInfo;
CSoundInterface* m_sound;
+ //! Bindings for user inputs
+ InputBinding m_inputBindings[INPUT_SLOT_MAX];
+
float m_time;
float m_gameTime;
float m_checkEndTime;
diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp
index 4c558f4..123f985 100644
--- a/src/ui/edit.cpp
+++ b/src/ui/edit.cpp
@@ -82,7 +82,6 @@ CEdit::CEdit () : CControl ()
m_text = new char[m_maxChar+1];
memset(m_text, 0, m_maxChar+1);
m_len = 0;
- m_app = CApplication::GetInstancePointer();
memset(m_lineOffset, 0, sizeof(int) * EDITLINEMAX);
@@ -1465,7 +1464,7 @@ bool CEdit::ReadText(const char *filename, int addSize)
char iName[50];
char text[50];
float iWidth;
- KeyRank key;
+ InputSlot slot;
bool bInSoluce, bBOL;
if ( filename[0] == 0 ) return false;
@@ -1795,10 +1794,10 @@ bool CEdit::ReadText(const char *filename, int addSize)
{
if ( m_bSoluce || !bInSoluce )
{
- if ( SearchKey(buffer+i+5, key) )
+ if ( SearchKey(buffer+i+5, slot) )
{
- res = 0;
- //res = m_app->GetInputBinding(key).key; // TODO input bindings
+ CRobotMain* main = CRobotMain::GetInstancePointer();
+ res = main->GetInputBinding(slot).key;
if ( res != 0 )
{
if ( GetResource(RES_KEY, res, iName) )
@@ -1817,8 +1816,7 @@ bool CEdit::ReadText(const char *filename, int addSize)
m_format[j] = font;
j ++;
- // res = m_app->GetInputBinding(key).joy; // TODO input bindings
- res = 0;
+ res = main->GetInputBinding(slot).joy;
if ( res != 0 )
{
if ( GetResource(RES_KEY, res, iName) )
diff --git a/src/ui/edit.h b/src/ui/edit.h
index b6766f8..c5c6cf6 100644
--- a/src/ui/edit.h
+++ b/src/ui/edit.h
@@ -35,8 +35,6 @@
#include "common/iman.h"
#include "common/restext.h"
-#include "app/app.h"
-
#include <vector>
@@ -246,7 +244,6 @@ protected:
int m_len; // length used in m_text
int m_cursor1; // offset cursor
int m_cursor2; // offset cursor
- CApplication *m_app;
bool m_bMulti; // true -> multi-line
bool m_bEdit; // true -> editable
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index a2fc733..a40cc27 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -5956,41 +5956,41 @@ void CMainDialog::ChangeSetupQuality(int quality)
static int key_table[KEY_TOTAL] =
{
/* TODO: #if _SCHOOL & _TEEN
- KEYRANK_LEFT,
- KEYRANK_RIGHT,
- KEYRANK_UP,
- KEYRANK_DOWN,
- KEYRANK_CAMERA,
- KEYRANK_NEAR,
- KEYRANK_AWAY,
- KEYRANK_HELP,
- KEYRANK_PROG,
- KEYRANK_SPEED10,
- KEYRANK_SPEED15,
- KEYRANK_SPEED20,
- KEYRANK_QUIT,
+ INPUT_SLOT_LEFT,
+ INPUT_SLOT_RIGHT,
+ INPUT_SLOT_UP,
+ INPUT_SLOT_DOWN,
+ INPUT_SLOT_CAMERA,
+ INPUT_SLOT_NEAR,
+ INPUT_SLOT_AWAY,
+ INPUT_SLOT_HELP,
+ INPUT_SLOT_PROG,
+ INPUT_SLOT_SPEED10,
+ INPUT_SLOT_SPEED15,
+ INPUT_SLOT_SPEED20,
+ INPUT_SLOT_QUIT,
#else */
- KEYRANK_LEFT,
- KEYRANK_RIGHT,
- KEYRANK_UP,
- KEYRANK_DOWN,
- KEYRANK_GUP,
- KEYRANK_GDOWN,
- KEYRANK_ACTION,
- KEYRANK_CAMERA,
- KEYRANK_VISIT,
- KEYRANK_NEXT,
- KEYRANK_HUMAN,
- KEYRANK_DESEL,
- KEYRANK_NEAR,
- KEYRANK_AWAY,
- KEYRANK_HELP,
- KEYRANK_PROG,
- KEYRANK_CBOT,
- KEYRANK_SPEED10,
- KEYRANK_SPEED15,
- KEYRANK_SPEED20,
- KEYRANK_QUIT,
+ INPUT_SLOT_LEFT,
+ INPUT_SLOT_RIGHT,
+ INPUT_SLOT_UP,
+ INPUT_SLOT_DOWN,
+ INPUT_SLOT_GUP,
+ INPUT_SLOT_GDOWN,
+ INPUT_SLOT_ACTION,
+ INPUT_SLOT_CAMERA,
+ INPUT_SLOT_VISIT,
+ INPUT_SLOT_NEXT,
+ INPUT_SLOT_HUMAN,
+ INPUT_SLOT_DESEL,
+ INPUT_SLOT_NEAR,
+ INPUT_SLOT_AWAY,
+ INPUT_SLOT_HELP,
+ INPUT_SLOT_PROG,
+ INPUT_SLOT_CBOT,
+ INPUT_SLOT_SPEED10,
+ INPUT_SLOT_SPEED15,
+ INPUT_SLOT_SPEED20,
+ INPUT_SLOT_QUIT,
// #endif
};
diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp
index 809ed0c..c546c57 100644
--- a/src/ui/studio.cpp
+++ b/src/ui/studio.cpp
@@ -241,8 +241,8 @@ bool CStudio::EventProcess(const Event &event)
if ( event.type == EVENT_KEY_DOWN )
{
- if ( event.key.key == m_app->GetInputBinding(INPUT_SLOT_CBOT).key // ||
- /*TODO event.param == m_app->GetKey(KEYRANK_CBOT, 1)*/ )
+ if ( event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).key ||
+ event.param == m_main->GetInputBinding(INPUT_SLOT_CBOT).joy )
{
if ( m_helpFilename.length() > 0 )
{