From 97f44035f1b3ebd2681236c23f14c4d3ea7f09ac Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 7 Oct 2012 00:46:46 +0200 Subject: Changing and saving input bindings --- src/app/app.h | 2 +- src/common/restext.cpp | 6 +- src/object/brain.cpp | 4 +- src/object/robotmain.cpp | 210 +++++++++++++++++++++++------------------------ src/object/robotmain.h | 10 +-- src/script/script.cpp | 1 + src/ui/edit.cpp | 4 +- src/ui/key.cpp | 169 ++++++++++++++++---------------------- src/ui/key.h | 45 +++++----- src/ui/maindialog.cpp | 114 ++++++++++--------------- src/ui/mainshort.cpp | 2 +- src/ui/mainshort.h | 2 +- src/ui/studio.cpp | 4 +- 13 files changed, 268 insertions(+), 305 deletions(-) diff --git a/src/app/app.h b/src/app/app.h index e887a63..32f03f8 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -38,7 +38,7 @@ class CInstanceManager; -class CEvent; +class CEventQueue; class CRobotMain; class CSoundInterface; diff --git a/src/common/restext.cpp b/src/common/restext.cpp index 0f33f52..9a3d964 100644 --- a/src/common/restext.cpp +++ b/src/common/restext.cpp @@ -105,7 +105,7 @@ static void PutKeyName(char* dst, const char* src) { if ( SearchKey(src+s+5, key) ) { - res = CRobotMain::GetInstancePointer()->GetInputBinding(key).key; + res = CRobotMain::GetInstancePointer()->GetInputBinding(key).primary; if (res != KEY_INVALID) { if ( GetResource(RES_KEY, res, name) ) @@ -172,7 +172,9 @@ static const char* GetResourceBase(ResType type, int num) case RES_KEY: - if (num == VIRTUAL_KMOD_CTRL) + if (num == KEY_INVALID) + return ""; + else if (num == VIRTUAL_KMOD_CTRL) return "Ctrl"; else if (num == VIRTUAL_KMOD_SHIFT) return "Shift"; diff --git a/src/object/brain.cpp b/src/object/brain.cpp index 7b580d7..5403903 100644 --- a/src/object/brain.cpp +++ b/src/object/brain.cpp @@ -203,8 +203,8 @@ bool CBrain::EventProcess(const Event &event) action = EVENT_NULL; if ( event.type == EVENT_KEY_DOWN && - (event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).key || - event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).joy ) && + (event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).primary || + event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).secondary ) && !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 1a8c934..954d676 100644 --- a/src/object/robotmain.cpp +++ b/src/object/robotmain.cpp @@ -878,7 +878,7 @@ void CRobotMain::SetDefaultInputBindings() { for (int i = 0; i < INPUT_SLOT_MAX; i++) { - m_inputBindings[i].key = m_inputBindings[i].joy = KEY_INVALID; + m_inputBindings[i].primary = m_inputBindings[i].secondary = KEY_INVALID; } for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++) @@ -887,34 +887,34 @@ void CRobotMain::SetDefaultInputBindings() m_joyAxisBindings[i].invert = false; } - 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); + m_inputBindings[INPUT_SLOT_LEFT ].primary = KEY(LEFT); + m_inputBindings[INPUT_SLOT_RIGHT ].primary = KEY(RIGHT); + m_inputBindings[INPUT_SLOT_UP ].primary = KEY(UP); + m_inputBindings[INPUT_SLOT_DOWN ].primary = KEY(DOWN); + m_inputBindings[INPUT_SLOT_GUP ].primary = VIRTUAL_KMOD(SHIFT); + m_inputBindings[INPUT_SLOT_GDOWN ].primary = VIRTUAL_KMOD(CTRL); + m_inputBindings[INPUT_SLOT_CAMERA ].primary = KEY(SPACE); + m_inputBindings[INPUT_SLOT_CAMERA ].secondary = VIRTUAL_JOY(2); + m_inputBindings[INPUT_SLOT_DESEL ].primary = KEY(KP0); + m_inputBindings[INPUT_SLOT_DESEL ].secondary = VIRTUAL_JOY(6); + m_inputBindings[INPUT_SLOT_ACTION ].primary = KEY(RETURN); + m_inputBindings[INPUT_SLOT_ACTION ].secondary = VIRTUAL_JOY(1); + m_inputBindings[INPUT_SLOT_NEAR ].primary = KEY(KP_PLUS); + m_inputBindings[INPUT_SLOT_NEAR ].secondary = VIRTUAL_JOY(5); + m_inputBindings[INPUT_SLOT_AWAY ].primary = KEY(KP_MINUS); + m_inputBindings[INPUT_SLOT_AWAY ].secondary = VIRTUAL_JOY(4); + m_inputBindings[INPUT_SLOT_NEXT ].primary = KEY(TAB); + m_inputBindings[INPUT_SLOT_NEXT ].secondary = VIRTUAL_JOY(3); + m_inputBindings[INPUT_SLOT_HUMAN ].primary = KEY(HOME); + m_inputBindings[INPUT_SLOT_HUMAN ].secondary = VIRTUAL_JOY(7); + m_inputBindings[INPUT_SLOT_QUIT ].primary = KEY(ESCAPE); + m_inputBindings[INPUT_SLOT_HELP ].primary = KEY(F1); + m_inputBindings[INPUT_SLOT_PROG ].primary = KEY(F2); + m_inputBindings[INPUT_SLOT_CBOT ].primary = KEY(F3); + m_inputBindings[INPUT_SLOT_VISIT ].primary = KEY(KP_PERIOD); + m_inputBindings[INPUT_SLOT_SPEED10].primary = KEY(F4); + m_inputBindings[INPUT_SLOT_SPEED15].primary = KEY(F5); + m_inputBindings[INPUT_SLOT_SPEED20].primary = KEY(F6); m_joyAxisBindings[JOY_AXIS_SLOT_X].axis = 0; m_joyAxisBindings[JOY_AXIS_SLOT_Y].axis = 1; @@ -1214,33 +1214,33 @@ bool CRobotMain::EventProcess(Event &event) if (event.type == EVENT_KEY_DOWN) { - if (event.key.key == GetInputBinding(INPUT_SLOT_UP ).key) m_keyMotion.y = 1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_UP ).joy) m_keyMotion.y = 1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_DOWN ).key) m_keyMotion.y = -1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_DOWN ).joy) m_keyMotion.y = -1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_LEFT ).key) m_keyMotion.x = -1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_LEFT ).joy) m_keyMotion.x = -1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_RIGHT).key) m_keyMotion.x = 1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_RIGHT).joy) m_keyMotion.x = 1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_GUP ).key) m_keyMotion.z = 1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_GUP ).joy) m_keyMotion.z = 1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_GDOWN).key) m_keyMotion.z = -1.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_GDOWN).joy) m_keyMotion.z = -1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_UP ).primary) m_keyMotion.y = 1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_UP ).secondary) m_keyMotion.y = 1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_DOWN ).primary) m_keyMotion.y = -1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_DOWN ).secondary) m_keyMotion.y = -1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_LEFT ).primary) m_keyMotion.x = -1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_LEFT ).secondary) m_keyMotion.x = -1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_RIGHT).primary) m_keyMotion.x = 1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_RIGHT).secondary) m_keyMotion.x = 1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_GUP ).primary) m_keyMotion.z = 1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_GUP ).secondary) m_keyMotion.z = 1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_GDOWN).primary) m_keyMotion.z = -1.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_GDOWN).secondary) m_keyMotion.z = -1.0f; } else if (event.type == EVENT_KEY_UP) { - if (event.key.key == GetInputBinding(INPUT_SLOT_UP ).key) m_keyMotion.y = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_UP ).joy) m_keyMotion.y = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_DOWN ).key) m_keyMotion.y = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_DOWN ).joy) m_keyMotion.y = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_LEFT ).key) m_keyMotion.x = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_LEFT ).joy) m_keyMotion.x = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_RIGHT).key) m_keyMotion.x = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_RIGHT).joy) m_keyMotion.x = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_GUP ).key) m_keyMotion.z = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_GUP ).joy) m_keyMotion.z = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_GDOWN).key) m_keyMotion.z = 0.0f; - if (event.key.key == GetInputBinding(INPUT_SLOT_GDOWN).joy) m_keyMotion.z = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_UP ).primary) m_keyMotion.y = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_UP ).secondary) m_keyMotion.y = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_DOWN ).primary) m_keyMotion.y = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_DOWN ).secondary) m_keyMotion.y = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_LEFT ).primary) m_keyMotion.x = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_LEFT ).secondary) m_keyMotion.x = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_RIGHT).primary) m_keyMotion.x = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_RIGHT).secondary) m_keyMotion.x = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_GUP ).primary) m_keyMotion.z = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_GUP ).secondary) m_keyMotion.z = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_GDOWN).primary) m_keyMotion.z = 0.0f; + if (event.key.key == GetInputBinding(INPUT_SLOT_GDOWN).secondary) m_keyMotion.z = 0.0f; } else if (event.type == EVENT_JOY_AXIS) { @@ -1356,10 +1356,10 @@ bool CRobotMain::EventProcess(Event &event) if (event.type == EVENT_KEY_DOWN) { - 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 || + if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).primary || + event.key.key == GetInputBinding(INPUT_SLOT_HELP).secondary || + event.key.key == GetInputBinding(INPUT_SLOT_PROG).primary || + event.key.key == GetInputBinding(INPUT_SLOT_PROG).secondary || event.key.key == KEY(ESCAPE)) { StopDisplayInfo(); @@ -1394,14 +1394,14 @@ bool CRobotMain::EventProcess(Event &event) } if (m_editLock) // current edition? { - if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).key || - event.key.key == GetInputBinding(INPUT_SLOT_HELP).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).primary || + event.key.key == GetInputBinding(INPUT_SLOT_HELP).secondary) { StartDisplayInfo(SATCOM_HUSTON, false); return false; } - if (event.key.key == GetInputBinding(INPUT_SLOT_PROG).key || - event.key.key == GetInputBinding(INPUT_SLOT_PROG).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_PROG).primary || + event.key.key == GetInputBinding(INPUT_SLOT_PROG).secondary) { StartDisplayInfo(SATCOM_PROG, false); return false; @@ -1410,8 +1410,8 @@ bool CRobotMain::EventProcess(Event &event) } if (m_movieLock) // current movie? { - if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).key || - event.key.key == GetInputBinding(INPUT_SLOT_QUIT).joy || + if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).primary || + event.key.key == GetInputBinding(INPUT_SLOT_QUIT).secondary || event.key.key == KEY(ESCAPE)) { AbortMovie(); @@ -1420,21 +1420,21 @@ bool CRobotMain::EventProcess(Event &event) } if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT) { - if (event.key.key == GetInputBinding(INPUT_SLOT_VISIT).key || - event.key.key == GetInputBinding(INPUT_SLOT_VISIT).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_VISIT).primary || + event.key.key == GetInputBinding(INPUT_SLOT_VISIT).secondary) { StartDisplayVisit(EVENT_NULL); } - if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).key || - event.key.key == GetInputBinding(INPUT_SLOT_QUIT).joy || + if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).primary || + event.key.key == GetInputBinding(INPUT_SLOT_QUIT).secondary || event.key.key == KEY(ESCAPE)) { StopDisplayVisit(); } return false; } - if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).key || - event.key.key == GetInputBinding(INPUT_SLOT_QUIT).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).primary || + event.key.key == GetInputBinding(INPUT_SLOT_QUIT).secondary) { if (m_movie->IsExist()) StartDisplayInfo(SATCOM_HUSTON, false); @@ -1454,55 +1454,55 @@ bool CRobotMain::EventProcess(Event &event) ChangePause(!m_engine->GetPause()); } } - if (event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).key || - event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).primary || + event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).secondary) { ChangeCamera(); } - if (event.key.key == GetInputBinding(INPUT_SLOT_DESEL).key || - event.key.key == GetInputBinding(INPUT_SLOT_DESEL).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_DESEL).primary || + event.key.key == GetInputBinding(INPUT_SLOT_DESEL).secondary) { if (m_shortCut) DeselectObject(); } - if (event.key.key == GetInputBinding(INPUT_SLOT_HUMAN).key || - event.key.key == GetInputBinding(INPUT_SLOT_HUMAN).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_HUMAN).primary || + event.key.key == GetInputBinding(INPUT_SLOT_HUMAN).secondary) { SelectHuman(); } - if (event.key.key == GetInputBinding(INPUT_SLOT_NEXT).key || - event.key.key == GetInputBinding(INPUT_SLOT_NEXT).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_NEXT).primary || + event.key.key == GetInputBinding(INPUT_SLOT_NEXT).secondary) { if (m_shortCut) m_short->SelectNext(); } - if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).key || - event.key.key == GetInputBinding(INPUT_SLOT_HELP).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).primary || + event.key.key == GetInputBinding(INPUT_SLOT_HELP).secondary) { StartDisplayInfo(SATCOM_HUSTON, true); } - if (event.key.key == GetInputBinding(INPUT_SLOT_PROG).key || - event.key.key == GetInputBinding(INPUT_SLOT_PROG).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_PROG).primary || + event.key.key == GetInputBinding(INPUT_SLOT_PROG).secondary) { StartDisplayInfo(SATCOM_PROG, true); } - if (event.key.key == GetInputBinding(INPUT_SLOT_VISIT).key || - event.key.key == GetInputBinding(INPUT_SLOT_VISIT).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_VISIT).primary || + event.key.key == GetInputBinding(INPUT_SLOT_VISIT).secondary) { StartDisplayVisit(EVENT_NULL); } - if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED10).key || - event.key.key == GetInputBinding(INPUT_SLOT_SPEED10).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED10).primary || + event.key.key == GetInputBinding(INPUT_SLOT_SPEED10).secondary) { SetSpeed(1.0f); } - if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED15).key || - event.key.key == GetInputBinding(INPUT_SLOT_SPEED15).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED15).primary || + event.key.key == GetInputBinding(INPUT_SLOT_SPEED15).secondary) { SetSpeed(1.5f); } - if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED20).key || - event.key.key == GetInputBinding(INPUT_SLOT_SPEED20).joy) + if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED20).primary || + event.key.key == GetInputBinding(INPUT_SLOT_SPEED20).secondary) { SetSpeed(2.0f); } @@ -3109,26 +3109,26 @@ void CRobotMain::KeyCamera(EventType type, unsigned int key) if (type == EVENT_KEY_UP) { - if (key == GetInputBinding(INPUT_SLOT_LEFT).key || - key == GetInputBinding(INPUT_SLOT_LEFT).joy) + if (key == GetInputBinding(INPUT_SLOT_LEFT).primary || + key == GetInputBinding(INPUT_SLOT_LEFT).secondary) { m_cameraPan = 0.0f; } - if (key == GetInputBinding(INPUT_SLOT_RIGHT).key || - key == GetInputBinding(INPUT_SLOT_RIGHT).joy) + if (key == GetInputBinding(INPUT_SLOT_RIGHT).primary || + key == GetInputBinding(INPUT_SLOT_RIGHT).secondary) { m_cameraPan = 0.0f; } - if (key == GetInputBinding(INPUT_SLOT_UP).key || - key == GetInputBinding(INPUT_SLOT_UP).joy) + if (key == GetInputBinding(INPUT_SLOT_UP).primary || + key == GetInputBinding(INPUT_SLOT_UP).secondary) { m_cameraZoom = 0.0f; } - if (key == GetInputBinding(INPUT_SLOT_DOWN).key || - key == GetInputBinding(INPUT_SLOT_DOWN).joy) + if (key == GetInputBinding(INPUT_SLOT_DOWN).primary || + key == GetInputBinding(INPUT_SLOT_DOWN).secondary) { m_cameraZoom = 0.0f; } @@ -3144,26 +3144,26 @@ void CRobotMain::KeyCamera(EventType type, unsigned int key) if (type == EVENT_KEY_DOWN) { - if (key == GetInputBinding(INPUT_SLOT_LEFT).key || - key == GetInputBinding(INPUT_SLOT_LEFT).joy) + if (key == GetInputBinding(INPUT_SLOT_LEFT).primary || + key == GetInputBinding(INPUT_SLOT_LEFT).secondary) { m_cameraPan = -1.0f; } - if (key == GetInputBinding(INPUT_SLOT_RIGHT).key || - key == GetInputBinding(INPUT_SLOT_RIGHT).joy) + if (key == GetInputBinding(INPUT_SLOT_RIGHT).primary || + key == GetInputBinding(INPUT_SLOT_RIGHT).secondary) { m_cameraPan = 1.0f; } - if (key == GetInputBinding(INPUT_SLOT_UP).key || - key == GetInputBinding(INPUT_SLOT_UP).joy) + if (key == GetInputBinding(INPUT_SLOT_UP).primary || + key == GetInputBinding(INPUT_SLOT_UP).secondary) { m_cameraZoom = -1.0f; } - if (key == GetInputBinding(INPUT_SLOT_DOWN).key || - key == GetInputBinding(INPUT_SLOT_DOWN).joy) + if (key == GetInputBinding(INPUT_SLOT_DOWN).primary || + key == GetInputBinding(INPUT_SLOT_DOWN).secondary) { m_cameraZoom = 1.0f; } diff --git a/src/object/robotmain.h b/src/object/robotmain.h index dddd6d4..e475c43 100644 --- a/src/object/robotmain.h +++ b/src/object/robotmain.h @@ -148,12 +148,12 @@ const int SATCOM_MAX = 6; */ struct InputBinding { - //! Keyboard binding code (can be regular or virtual) - unsigned int key; - //! Joystick binding code (virtual) - unsigned int joy; + //! Primary and secondary bindings + //! Can be regular key, virtual key or virtual joystick button + unsigned int primary, secondary; - InputBinding() : key(KEY_INVALID), joy(KEY_INVALID) {} + InputBinding(unsigned int p = KEY_INVALID, unsigned int s = KEY_INVALID) + : primary(p), secondary(s) {} }; /** diff --git a/src/script/script.cpp b/src/script/script.cpp index 2d76ad3..face9b7 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -19,6 +19,7 @@ #include "script/script.h" +#include "app/app.h" #include "common/global.h" #include "common/iman.h" #include "common/restext.h" diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp index ca53a7a..45e564d 100644 --- a/src/ui/edit.cpp +++ b/src/ui/edit.cpp @@ -1796,7 +1796,7 @@ bool CEdit::ReadText(const char *filename, int addSize) if ( SearchKey(buffer+i+5, slot) ) { CRobotMain* main = CRobotMain::GetInstancePointer(); - res = main->GetInputBinding(slot).key; + res = main->GetInputBinding(slot).primary; if ( res != 0 ) { if ( GetResource(RES_KEY, res, iName) ) @@ -1815,7 +1815,7 @@ bool CEdit::ReadText(const char *filename, int addSize) m_format[j] = font; j ++; - res = main->GetInputBinding(slot).joy; + res = main->GetInputBinding(slot).secondary; if ( res != 0 ) { if ( GetResource(RES_KEY, res, iName) ) diff --git a/src/ui/key.cpp b/src/ui/key.cpp index 26d99ac..9a76127 100644 --- a/src/ui/key.cpp +++ b/src/ui/key.cpp @@ -15,65 +15,48 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// key.cpp - - #include "ui/key.h" -#include +#include "common/global.h" + +#include namespace Ui { -void GetKeyName(char *name, int key) + +void GetKeyName(char* name, unsigned int key) { - if ( !GetResource(RES_KEY, key, name) ) { - if (isalnum(key)) { - name[0] = key; - name[1] = 0; - } - else { - sprintf(name, "Code %d", key); - } - } + if (!GetResource(RES_KEY, key, name)) + sprintf(name, "Code %d", key); } -// Object's constructor. - CKey::CKey() : CControl() { - m_key[0] = 0; - m_key[1] = 0; - m_bCatch = false; + m_catch = false; - m_app = CApplication::GetInstancePointer(); + m_robotMain = CRobotMain::GetInstancePointer(); } -// Object's destructor. - CKey::~CKey() { + m_robotMain = nullptr; } - -// Creates a new button. - bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg) { - char name[100]; if (eventMsg == EVENT_NULL) eventMsg = GetUniqueEventType(); CControl::Create(pos, dim, icon, eventMsg); + + char name[100]; GetResource(RES_EVENT, eventMsg, name); SetName(std::string(name)); return true; } - -// Management of an event. - bool CKey::EventProcess(const Event &event) { if (m_state & STATE_DEAD) @@ -81,24 +64,31 @@ bool CKey::EventProcess(const Event &event) CControl::EventProcess(event); - if (event.type == EVENT_MOUSE_BUTTON_DOWN) { + if (event.type == EVENT_MOUSE_BUTTON_DOWN) + { if (event.mouseButton.button == MOUSE_BUTTON_LEFT) // left - m_bCatch = Detect(event.mousePos); + m_catch = Detect(event.mousePos); } - if (event.type == EVENT_KEY_DOWN && m_bCatch) { - m_bCatch = false; + if (event.type == EVENT_KEY_DOWN && m_catch) + { + m_catch = false; - if ( TestKey(event.key.key) ) { // impossible ? + if (TestKey(event.key.key)) // impossible ? + { m_sound->Play(SOUND_TZOING); - } else { - // TODO: test for virtual, joystick, etc. - if ( event.key.key == m_key[0] || event.key.key == m_key[1] ) { - m_key[0] = event.key.key; - m_key[1] = 0; - } else { - m_key[1] = m_key[0]; - m_key[0] = event.key.key; + } + else + { + if (event.key.key == m_binding.primary || event.key.key == m_binding.secondary) + { + m_binding.secondary = KEY_INVALID; + m_binding.primary = event.key.key; + } + else + { + m_binding.secondary = m_binding.primary; + m_binding.primary = event.key.key; } m_sound->Play(SOUND_CLICK); @@ -112,96 +102,88 @@ bool CKey::EventProcess(const Event &event) return true; } - -// Seeks when a key is already used. - -bool CKey::TestKey(int key) +bool CKey::TestKey(unsigned int key) { - if ( key == KEY(PAUSE) || key == KEY(PRINT) ) return true; // blocked key + if (key == KEY(PAUSE) || key == KEY(PRINT)) return true; // blocked key - /* TODO: input bindings - for (int i = 0; i < 20; i++) { - for (int j = 0; j < 2; j++) { - if (key == m_app->GetKey(i, j) ) // key used? - m_app->SetKey(i, j, 0); // nothing! - } + for (int i = 0; i < INPUT_SLOT_MAX; i++) + { + InputSlot slot = static_cast(i); + InputBinding b = m_robotMain->GetInputBinding(slot); + if (key == b.primary || key == b.secondary) + m_robotMain->SetInputBinding(slot, InputBinding()); // nothing! - if ( m_app->GetKey(i, 0) == 0 ) { // first free option? - m_app->SetKey(i, 0, m_app->GetKey(i, 1)); // shift - m_app->SetKey(i, 1, 0); - } - } */ + if (b.primary == KEY_INVALID) // first free option? + m_robotMain->SetInputBinding(slot, InputBinding(b.secondary, b.primary)); // shift + } return false; // not used } - -// Draws button. - void CKey::Draw() { - Math::Point iDim, pos; - float zoomExt, zoomInt, h; - int icon; - char text[100]; - - if ( (m_state & STATE_VISIBLE) == 0 ) + if ((m_state & STATE_VISIBLE) == 0) return; - iDim = m_dim; + Math::Point iDim = m_dim; m_dim.x = 200.0f/640.0f; - if ( m_state & STATE_SHADOW ) + if (m_state & STATE_SHADOW) DrawShadow(m_pos, m_dim); m_engine->SetTexture("button1.png"); m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); // was D3DSTATENORMAL - zoomExt = 1.00f; - zoomInt = 0.95f; + float zoomExt = 1.00f; + float zoomInt = 0.95f; - icon = 2; - if ( m_key[0] == 0 && m_key[1] == 0 ) // no shortcut? + int icon = 2; + if (m_binding.primary == KEY_INVALID && m_binding.secondary == KEY_INVALID) // no shortcut? icon = 3; - if ( m_state & STATE_DEFAULT ) { + if (m_state & STATE_DEFAULT) + { DrawPart(23, 1.3f, 0.0f); zoomExt *= 1.15f; zoomInt *= 1.15f; } - if ( m_state & STATE_HILIGHT ) + if (m_state & STATE_HILIGHT) icon = 1; - if ( m_state & STATE_CHECK ) + if (m_state & STATE_CHECK) icon = 0; - if ( m_state & STATE_PRESS ) { + if (m_state & STATE_PRESS) + { icon = 3; zoomInt *= 0.9f; } - if ( (m_state & STATE_ENABLE) == 0 ) + if ((m_state & STATE_ENABLE) == 0) icon = 7; - if ( m_state & STATE_DEAD ) + if (m_state & STATE_DEAD) icon = 17; - if ( m_bCatch ) + if (m_catch) icon = 23; DrawPart(icon, zoomExt, 8.0f / 256.0f); // draws the button - h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f; + float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f; - GetKeyName(text, m_key[0]); - if ( m_key[1] != 0 ) { + char text[100]; + GetKeyName(text, m_binding.primary); + if (m_binding.secondary != KEY_INVALID) + { GetResource(RES_TEXT, RT_KEY_OR, text+strlen(text)); - GetKeyName(text+strlen(text), m_key[1]); + GetKeyName(text+strlen(text), m_binding.secondary); } + Math::Point pos; pos.x = m_pos.x + m_dim.x * 0.5f; pos.y = m_pos.y + m_dim.y * 0.5f; pos.y -= h; @@ -209,7 +191,7 @@ void CKey::Draw() m_dim = iDim; - if ( m_state & STATE_DEAD ) + if (m_state & STATE_DEAD) return; // Draws the name. @@ -219,20 +201,15 @@ void CKey::Draw() m_engine->GetText()->DrawText(std::string(m_name), m_fontType, m_fontSize, pos, m_dim.x, Gfx::TEXT_ALIGN_LEFT, 0); } - - -void CKey::SetKey(int option, int key) +void CKey::SetBinding(InputBinding b) { - if ( option < 0 || option > 1 ) return; - - m_key[option] = key; + m_binding = b; } -int CKey::GetKey(int option) +InputBinding CKey::GetBinding() { - if ( option < 0 || option > 1 ) return 0; - - return m_key[option]; + return m_binding; } -} + +} // namespace Ui diff --git a/src/ui/key.h b/src/ui/key.h index 1943f61..2332c9b 100644 --- a/src/ui/key.h +++ b/src/ui/key.h @@ -15,13 +15,13 @@ // * You should have received a copy of the GNU General Public License // * along with this program. If not, see http://www.gnu.org/licenses/. -// key.h +/** + * \file ui/key.h + * \brief Key slot control + */ #pragma once -#include -#include - #include "ui/control.h" #include "common/iman.h" @@ -29,33 +29,40 @@ #include "common/restext.h" #include "common/key.h" -#include "app/app.h" namespace Ui { class CKey : public CControl { - public: - CKey(); - virtual ~CKey(); +public: + CKey(); + virtual ~CKey(); - bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); - bool EventProcess(const Event &event); + //! Creates a new key slot button + bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg); + //! Management of an event + bool EventProcess(const Event &event); - void Draw(); + //! Draws button + void Draw(); - void SetKey(int option, int key); - int GetKey(int option); + //! Management of binding + //@{ + void SetBinding(InputBinding b); + InputBinding GetBinding(); + //@} - protected: - bool TestKey(int key); +protected: + //! Checks if a key is already used + bool TestKey(unsigned int key); - unsigned int m_key[2]; - bool m_bCatch; +protected: + CRobotMain* m_robotMain; - CApplication *m_app; + InputBinding m_binding; + bool m_catch; }; -} +} // namespace Ui diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp index d7295eb..21a2c50 100644 --- a/src/ui/maindialog.cpp +++ b/src/ui/maindialog.cpp @@ -5476,7 +5476,6 @@ void CMainDialog::SetupMemorize() { float fValue; int iValue, i, j; - char key[500]; char num[10]; GetProfile().SetLocalProfileString("Directory", "scene", m_sceneDir); @@ -5518,21 +5517,16 @@ void CMainDialog::SetupMemorize() // GetProfile()->SetLocalProfileInt("Setup", "UseJoystick", m_engine->GetJoystick()); // GetProfile()->SetLocalProfileInt("Setup", "MidiVolume", m_sound->GetMidiVolume()); - // key[0] = 0; - // for ( i=0 ; i<100 ; i++ ) - // { - // if ( m_engine->GetKey(i, 0) == 0 ) break; - - // for ( j=0 ; j<2 ; j++ ) - // { - // iValue = m_engine->GetKey(i, j); - // sprintf(num, "%d%c", iValue, j==0?'+':' '); - // strcat(key, num); - // } - // } + std::stringstream key; + for (int i = 0; i < INPUT_SLOT_MAX; i++) + { + InputBinding b = m_main->GetInputBinding(static_cast(i)); - /* TODO: profile - SetLocalProfileString("Setup", "KeyMap", key); */ + key << b.primary << " "; + key << b.secondary << " "; + } + + GetProfile().SetLocalProfileString("Setup", "KeyMap", key.str()); #if _NET if ( m_accessEnable ) @@ -5556,9 +5550,8 @@ void CMainDialog::SetupMemorize() void CMainDialog::SetupRecall() { float fValue; - int iValue, i, j; + int iValue; std::string key; - char* p; if ( GetProfile().GetLocalProfileString("Directory", "scene", key) ) { @@ -5747,22 +5740,18 @@ void CMainDialog::SetupRecall() m_engine->SetEditIndentValue(iValue); } - // if ( GetLocalProfileString("Setup", "KeyMap", key, 500) ) - // { - // p = key; - // for ( i=0 ; i<100 ; i++ ) - // { - // if ( p[0] == 0 ) break; - - // for ( j=0 ; j<2 ; j++ ) - // { - // sscanf(p, "%d", &iValue); - // m_engine->SetKey(i, j, iValue); - // while ( *p >= '0' && *p <= '9' ) p++; - // while ( *p == ' ' || *p == '+' ) p++; - // } - // } - // } + if (GetProfile().GetLocalProfileString("Setup", "KeyMap", key)) + { + std::stringstream skey; + skey.str(key); + for (int i = 0; i < INPUT_SLOT_MAX; i++) + { + InputBinding b; + skey >> b.primary; + skey >> b.secondary; + m_main->SetInputBinding(static_cast(i), b); + } + } #if _NET if ( m_accessEnable ) @@ -5837,7 +5826,7 @@ void CMainDialog::ChangeSetupQuality(int quality) // Redefinable keys: -static int key_table[KEY_TOTAL] = +static InputSlot key_table[KEY_TOTAL] = { INPUT_SLOT_LEFT, INPUT_SLOT_RIGHT, @@ -5891,37 +5880,30 @@ static EventType key_event[KEY_TOTAL] = void CMainDialog::UpdateKey() { - CWindow* pw; - CScroll* ps; - CKey* pk; - Math::Point pos, dim; - int first, i; + CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); + if (pw == nullptr) return; - pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); - if ( pw == 0 ) return; - - ps = static_cast(pw->SearchControl(EVENT_INTERFACE_KSCROLL)); - if ( ps == 0 ) return; + CScroll* ps = static_cast(pw->SearchControl(EVENT_INTERFACE_KSCROLL)); + if (ps == nullptr) return; - first = static_cast(ps->GetVisibleValue()*(KEY_TOTAL-KEY_VISIBLE)); + int first = static_cast(ps->GetVisibleValue()*(KEY_TOTAL-KEY_VISIBLE)); - for ( i=0 ; iDeleteControl(key_event[i]); - } + Math::Point dim; dim.x = 400.0f/640.0f; dim.y = 20.0f/480.0f; + Math::Point pos; pos.x = 110.0f/640.0f; pos.y = 168.0f/480.0f + dim.y*(KEY_VISIBLE-1); - for ( i=0 ; iCreateKey(pos, dim, -1, key_event[first+i]); - pk = static_cast(pw->SearchControl(key_event[first+i])); - if ( pk == 0 ) break; - /* TODO: set input bindings - pk->SetKey(0, m_engine->GetKey(key_table[first+i], 0)); - pk->SetKey(1, m_engine->GetKey(key_table[first+i], 1)); */ + CKey* pk = static_cast(pw->SearchControl(key_event[first+i])); + if (pk == nullptr) break; + + pk->SetBinding(m_main->GetInputBinding(key_table[first+i])); pos.y -= dim.y; } } @@ -5930,26 +5912,20 @@ void CMainDialog::UpdateKey() void CMainDialog::ChangeKey(EventType event) { - CWindow* pw; - CScroll* ps; - CKey* pk; - int i; - - pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); - if ( pw == 0 ) return; + CWindow* pw = static_cast(m_interface->SearchControl(EVENT_WINDOW5)); + if (pw == nullptr) return; - ps = static_cast(pw->SearchControl(EVENT_INTERFACE_KSCROLL)); - if ( ps == 0 ) return; + CScroll* ps = static_cast(pw->SearchControl(EVENT_INTERFACE_KSCROLL)); + if (ps == nullptr) return; - for ( i=0 ; i(pw->SearchControl(key_event[i])); - if ( pk == 0 ) break; - /* TODO: set key binding - m_engine->SetKey(key_table[i], 0, pk->GetKey(0)); - m_engine->SetKey(key_table[i], 1, pk->GetKey(1)); */ + CKey* pk = static_cast(pw->SearchControl(key_event[i])); + if (pk == nullptr) break; + + m_main->SetInputBinding(key_table[i], pk->GetBinding()); } } } diff --git a/src/ui/mainshort.cpp b/src/ui/mainshort.cpp index ac6d7fc..55b9612 100644 --- a/src/ui/mainshort.cpp +++ b/src/ui/mainshort.cpp @@ -30,7 +30,7 @@ CMainShort::CMainShort() m_iMan->AddInstance(CLASS_SHORT, this); m_interface = static_cast(m_iMan->SearchInstance(CLASS_INTERFACE)); - m_event = static_cast(m_iMan->SearchInstance(CLASS_EVENT)); + m_event = static_cast(m_iMan->SearchInstance(CLASS_EVENT)); m_engine = static_cast(m_iMan->SearchInstance(CLASS_ENGINE)); m_main = static_cast(m_iMan->SearchInstance(CLASS_MAIN)); diff --git a/src/ui/mainshort.h b/src/ui/mainshort.h index e97bdcc..0912e68 100644 --- a/src/ui/mainshort.h +++ b/src/ui/mainshort.h @@ -47,7 +47,7 @@ class CMainShort protected: CInstanceManager* m_iMan; - CEvent* m_event; + CEventQueue* m_event; Gfx::CEngine* m_engine; CInterface* m_interface; CRobotMain* m_main; diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp index a581baa..2f58c95 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_main->GetInputBinding(INPUT_SLOT_CBOT).key || - event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).joy ) + if ( event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).primary || + event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).secondary ) { if ( m_helpFilename.length() > 0 ) { -- cgit v1.2.3-1-g7c22