summaryrefslogtreecommitdiff
path: root/src/client/inputhandler.h
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
committerest31 <MTest31@outlook.com>2016-12-22 23:16:00 +0100
commit81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch)
tree1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /src/client/inputhandler.h
parent8077612dcb48221281e726a60eb97bf73fde462b (diff)
parent231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff)
downloadminetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.gz
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.bz2
minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.zip
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'src/client/inputhandler.h')
-rw-r--r--src/client/inputhandler.h50
1 files changed, 45 insertions, 5 deletions
diff --git a/src/client/inputhandler.h b/src/client/inputhandler.h
index 69e4b25fa..824b0da2e 100644
--- a/src/client/inputhandler.h
+++ b/src/client/inputhandler.h
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define INPUT_HANDLER_H
#include "irrlichttypes_extrabloated.h"
+#include "joystick_controller.h"
class MyEventReceiver : public IEventReceiver
{
@@ -42,11 +43,15 @@ public:
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT) {
- if (event.KeyInput.PressedDown) {
- keyIsDown.set(event.KeyInput);
- keyWasDown.set(event.KeyInput);
- } else {
- keyIsDown.unset(event.KeyInput);
+ const KeyPress &keyCode = event.KeyInput;
+ if (keysListenedFor[keyCode]) {
+ if (event.KeyInput.PressedDown) {
+ keyIsDown.set(keyCode);
+ keyWasDown.set(keyCode);
+ } else {
+ keyIsDown.unset(keyCode);
+ }
+ return true;
}
}
@@ -58,6 +63,14 @@ public:
return true;
}
#endif
+
+ if (event.EventType == irr::EET_JOYSTICK_INPUT_EVENT) {
+ /* TODO add a check like:
+ if (event.JoystickEvent != joystick_we_listen_for)
+ return false;
+ */
+ return joystick->handleEvent(event.JoystickEvent);
+ }
// handle mouse events
if (event.EventType == irr::EET_MOUSE_INPUT_EVENT) {
if (noMenuActive() == false) {
@@ -116,6 +129,15 @@ public:
return b;
}
+ void listenForKey(const KeyPress &keyCode)
+ {
+ keysListenedFor.set(keyCode);
+ }
+ void dontListenForKeys()
+ {
+ keysListenedFor.clear();
+ }
+
s32 getMouseWheel()
{
s32 a = mouse_wheel;
@@ -159,6 +181,8 @@ public:
s32 mouse_wheel;
+ JoystickController *joystick;
+
#ifdef HAVE_TOUCHSCREENGUI
TouchScreenGUI* m_touchscreengui;
#endif
@@ -168,6 +192,12 @@ private:
KeyList keyIsDown;
// Whether a key has been pressed or not
KeyList keyWasDown;
+ // List of keys we listen for
+ // TODO perhaps the type of this is not really
+ // performant as KeyList is designed for few but
+ // often changing keys, and keysListenedFor is expected
+ // to change seldomly but contain lots of keys.
+ KeyList keysListenedFor;
};
@@ -183,6 +213,7 @@ public:
m_receiver(receiver),
m_mousepos(0,0)
{
+ m_receiver->joystick = &joystick;
}
virtual bool isKeyDown(const KeyPress &keyCode)
{
@@ -192,6 +223,14 @@ public:
{
return m_receiver->WasKeyDown(keyCode);
}
+ virtual void listenForKey(const KeyPress &keyCode)
+ {
+ m_receiver->listenForKey(keyCode);
+ }
+ virtual void dontListenForKeys()
+ {
+ m_receiver->dontListenForKeys();
+ }
virtual v2s32 getMousePos()
{
if (m_device->getCursorControl()) {
@@ -261,6 +300,7 @@ public:
void clear()
{
+ joystick.clear();
m_receiver->clearInput();
}
private: