Refactoring of input and input bindings, CInput class
parent
e3e551de22
commit
eec6041104
|
@ -61,6 +61,7 @@ endif()
|
||||||
# Source files
|
# Source files
|
||||||
set(BASE_SOURCES
|
set(BASE_SOURCES
|
||||||
app/app.cpp
|
app/app.cpp
|
||||||
|
app/input.cpp
|
||||||
app/pausemanager.cpp
|
app/pausemanager.cpp
|
||||||
app/system.cpp
|
app/system.cpp
|
||||||
app/${SYSTEM_CPP_MODULE}
|
app/${SYSTEM_CPP_MODULE}
|
||||||
|
|
116
src/app/app.cpp
116
src/app/app.cpp
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
|
|
||||||
|
#include "app/input.h"
|
||||||
#include "app/system.h"
|
#include "app/system.h"
|
||||||
|
|
||||||
#include "common/logger.h"
|
#include "common/logger.h"
|
||||||
|
@ -104,6 +105,7 @@ CApplication::CApplication()
|
||||||
m_objMan = new CObjectManager();
|
m_objMan = new CObjectManager();
|
||||||
m_eventQueue = new CEventQueue();
|
m_eventQueue = new CEventQueue();
|
||||||
m_profile = new CProfile();
|
m_profile = new CProfile();
|
||||||
|
m_input = new CInput();
|
||||||
|
|
||||||
m_engine = nullptr;
|
m_engine = nullptr;
|
||||||
m_device = nullptr;
|
m_device = nullptr;
|
||||||
|
@ -147,10 +149,6 @@ CApplication::CApplication()
|
||||||
|
|
||||||
m_mouseMode = MOUSE_SYSTEM;
|
m_mouseMode = MOUSE_SYSTEM;
|
||||||
|
|
||||||
m_kmodState = 0;
|
|
||||||
m_mouseButtonsState = 0;
|
|
||||||
m_trackedKeys = 0;
|
|
||||||
|
|
||||||
#ifdef PORTABLE
|
#ifdef PORTABLE
|
||||||
m_dataPath = "./data";
|
m_dataPath = "./data";
|
||||||
m_langPath = "./lang";
|
m_langPath = "./lang";
|
||||||
|
@ -181,6 +179,9 @@ CApplication::~CApplication()
|
||||||
{
|
{
|
||||||
delete m_private;
|
delete m_private;
|
||||||
m_private = nullptr;
|
m_private = nullptr;
|
||||||
|
|
||||||
|
delete m_input;
|
||||||
|
m_input = nullptr;
|
||||||
|
|
||||||
delete m_objMan;
|
delete m_objMan;
|
||||||
m_objMan = nullptr;
|
m_objMan = nullptr;
|
||||||
|
@ -890,7 +891,7 @@ void CApplication::UpdateMouse()
|
||||||
{
|
{
|
||||||
Math::IntPoint pos;
|
Math::IntPoint pos;
|
||||||
SDL_GetMouseState(&pos.x, &pos.y);
|
SDL_GetMouseState(&pos.x, &pos.y);
|
||||||
m_mousePos = m_engine->WindowToInterfaceCoords(pos);
|
m_input->MouseMove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CApplication::Run()
|
int CApplication::Run()
|
||||||
|
@ -1082,9 +1083,7 @@ Event CApplication::ProcessSystemEvent()
|
||||||
event.key.virt = false;
|
event.key.virt = false;
|
||||||
event.key.key = m_private->currentEvent.key.keysym.sym;
|
event.key.key = m_private->currentEvent.key.keysym.sym;
|
||||||
event.key.unicode = m_private->currentEvent.key.keysym.unicode;
|
event.key.unicode = m_private->currentEvent.key.keysym.unicode;
|
||||||
|
event.kmodState = m_private->currentEvent.key.keysym.mod;
|
||||||
// Use the occasion to update kmods
|
|
||||||
m_kmodState = m_private->currentEvent.key.keysym.mod;
|
|
||||||
}
|
}
|
||||||
else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) ||
|
else if ( (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN) ||
|
||||||
(m_private->currentEvent.type == SDL_MOUSEBUTTONUP) )
|
(m_private->currentEvent.type == SDL_MOUSEBUTTONUP) )
|
||||||
|
@ -1109,24 +1108,13 @@ Event CApplication::ProcessSystemEvent()
|
||||||
event.type = EVENT_MOUSE_BUTTON_UP;
|
event.type = EVENT_MOUSE_BUTTON_UP;
|
||||||
|
|
||||||
event.mouseButton.button = static_cast<MouseButton>(1 << m_private->currentEvent.button.button);
|
event.mouseButton.button = static_cast<MouseButton>(1 << m_private->currentEvent.button.button);
|
||||||
|
|
||||||
// Use the occasion to update mouse button state
|
|
||||||
if (m_private->currentEvent.type == SDL_MOUSEBUTTONDOWN)
|
|
||||||
m_mouseButtonsState |= event.mouseButton.button;
|
|
||||||
else
|
|
||||||
m_mouseButtonsState &= ~event.mouseButton.button;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the occasion to update mouse pos
|
|
||||||
m_mousePos = m_engine->WindowToInterfaceCoords(
|
|
||||||
Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
|
|
||||||
}
|
}
|
||||||
else if (m_private->currentEvent.type == SDL_MOUSEMOTION)
|
else if (m_private->currentEvent.type == SDL_MOUSEMOTION)
|
||||||
{
|
{
|
||||||
event.type = EVENT_MOUSE_MOVE;
|
event.type = EVENT_MOUSE_MOVE;
|
||||||
|
|
||||||
m_mousePos = m_engine->WindowToInterfaceCoords(
|
m_input->MouseMove(Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
|
||||||
Math::IntPoint(m_private->currentEvent.button.x, m_private->currentEvent.button.y));
|
|
||||||
}
|
}
|
||||||
else if (m_private->currentEvent.type == SDL_JOYAXISMOTION)
|
else if (m_private->currentEvent.type == SDL_JOYAXISMOTION)
|
||||||
{
|
{
|
||||||
|
@ -1158,51 +1146,8 @@ Event CApplication::ProcessSystemEvent()
|
||||||
|
|
||||||
event.active.gain = m_private->currentEvent.active.gain == 1;
|
event.active.gain = m_private->currentEvent.active.gain == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_input->EventProcess(event);
|
||||||
if (event.type == EVENT_KEY_DOWN)
|
|
||||||
{
|
|
||||||
if (event.key.key == KEY(KP8))
|
|
||||||
m_trackedKeys |= TRKEY_NUM_UP;
|
|
||||||
else if (event.key.key == KEY(KP2))
|
|
||||||
m_trackedKeys |= TRKEY_NUM_DOWN;
|
|
||||||
else if (event.key.key == KEY(KP4))
|
|
||||||
m_trackedKeys |= TRKEY_NUM_LEFT;
|
|
||||||
else if (event.key.key == KEY(KP6))
|
|
||||||
m_trackedKeys |= TRKEY_NUM_RIGHT;
|
|
||||||
else if (event.key.key == KEY(KP_PLUS))
|
|
||||||
m_trackedKeys |= TRKEY_NUM_PLUS;
|
|
||||||
else if (event.key.key == KEY(KP_MINUS))
|
|
||||||
m_trackedKeys |= TRKEY_NUM_MINUS;
|
|
||||||
else if (event.key.key == KEY(PAGEUP))
|
|
||||||
m_trackedKeys |= TRKEY_PAGE_UP;
|
|
||||||
else if (event.key.key == KEY(PAGEDOWN))
|
|
||||||
m_trackedKeys |= TRKEY_PAGE_DOWN;
|
|
||||||
}
|
|
||||||
else if (event.type == EVENT_KEY_UP)
|
|
||||||
{
|
|
||||||
if (event.key.key == KEY(KP8))
|
|
||||||
m_trackedKeys &= ~TRKEY_NUM_UP;
|
|
||||||
else if (event.key.key == KEY(KP2))
|
|
||||||
m_trackedKeys &= ~TRKEY_NUM_DOWN;
|
|
||||||
else if (event.key.key == KEY(KP4))
|
|
||||||
m_trackedKeys &= ~TRKEY_NUM_LEFT;
|
|
||||||
else if (event.key.key == KEY(KP6))
|
|
||||||
m_trackedKeys &= ~TRKEY_NUM_RIGHT;
|
|
||||||
else if (event.key.key == KEY(KP_PLUS))
|
|
||||||
m_trackedKeys &= ~TRKEY_NUM_PLUS;
|
|
||||||
else if (event.key.key == KEY(KP_MINUS))
|
|
||||||
m_trackedKeys &= ~TRKEY_NUM_MINUS;
|
|
||||||
else if (event.key.key == KEY(PAGEUP))
|
|
||||||
m_trackedKeys &= ~TRKEY_PAGE_UP;
|
|
||||||
else if (event.key.key == KEY(PAGEDOWN))
|
|
||||||
m_trackedKeys &= ~TRKEY_PAGE_DOWN;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.trackedKeysState = m_trackedKeys;
|
|
||||||
event.kmodState = m_kmodState;
|
|
||||||
event.mousePos = m_mousePos;
|
|
||||||
event.mouseButtonsState = m_mouseButtonsState;
|
|
||||||
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
@ -1398,10 +1343,7 @@ Event CApplication::CreateUpdateEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
Event frameEvent(EVENT_FRAME);
|
Event frameEvent(EVENT_FRAME);
|
||||||
frameEvent.trackedKeysState = m_trackedKeys;
|
m_input->EventProcess(frameEvent);
|
||||||
frameEvent.kmodState = m_kmodState;
|
|
||||||
frameEvent.mousePos = m_mousePos;
|
|
||||||
frameEvent.mouseButtonsState = m_mouseButtonsState;
|
|
||||||
frameEvent.rTime = m_relTime;
|
frameEvent.rTime = m_relTime;
|
||||||
|
|
||||||
return frameEvent;
|
return frameEvent;
|
||||||
|
@ -1541,34 +1483,6 @@ bool CApplication::ParseDebugModes(const std::string& str, int& debugModes)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CApplication::GetKmods() const
|
|
||||||
{
|
|
||||||
return m_kmodState;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CApplication::GetKmodState(int kmod) const
|
|
||||||
{
|
|
||||||
return (m_kmodState & kmod) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CApplication::GetTrackedKeyState(TrackedKey key) const
|
|
||||||
{
|
|
||||||
return (m_trackedKeys & key) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CApplication::GetMouseButtonState(int index) const
|
|
||||||
{
|
|
||||||
return (m_mouseButtonsState & (1<<index)) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CApplication::ResetKeyStates()
|
|
||||||
{
|
|
||||||
GetLogger()->Trace("Reset key states\n");
|
|
||||||
m_trackedKeys = 0;
|
|
||||||
m_kmodState = 0;
|
|
||||||
m_robotMain->ResetKeyStates();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CApplication::SetGrabInput(bool grab)
|
void CApplication::SetGrabInput(bool grab)
|
||||||
{
|
{
|
||||||
SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
|
SDL_WM_GrabInput(grab ? SDL_GRAB_ON : SDL_GRAB_OFF);
|
||||||
|
@ -1594,16 +1508,10 @@ MouseMode CApplication::GetMouseMode() const
|
||||||
return m_mouseMode;
|
return m_mouseMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Math::Point CApplication::GetMousePos() const
|
|
||||||
{
|
|
||||||
return m_mousePos;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CApplication::MoveMouse(Math::Point pos)
|
void CApplication::MoveMouse(Math::Point pos)
|
||||||
{
|
{
|
||||||
m_mousePos = pos;
|
|
||||||
|
|
||||||
Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos);
|
Math::IntPoint windowPos = m_engine->InterfaceToWindowCoords(pos);
|
||||||
|
m_input->MouseMove(windowPos);
|
||||||
SDL_WarpMouse(windowPos.x, windowPos.y);
|
SDL_WarpMouse(windowPos.x, windowPos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ class CInstanceManager;
|
||||||
class CEventQueue;
|
class CEventQueue;
|
||||||
class CRobotMain;
|
class CRobotMain;
|
||||||
class CSoundInterface;
|
class CSoundInterface;
|
||||||
|
class CInput;
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
class CModelManager;
|
class CModelManager;
|
||||||
|
@ -80,23 +81,6 @@ enum VideoQueryResult
|
||||||
VIDEO_QUERY_OK
|
VIDEO_QUERY_OK
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \enum TrackedKey
|
|
||||||
* \brief Additional keys whose state (pressed/released) is tracked by CApplication
|
|
||||||
*/
|
|
||||||
enum TrackedKey
|
|
||||||
{
|
|
||||||
TRKEY_NUM_UP = (1<<0),
|
|
||||||
TRKEY_NUM_DOWN = (1<<1),
|
|
||||||
TRKEY_NUM_LEFT = (1<<2),
|
|
||||||
TRKEY_NUM_RIGHT = (1<<3),
|
|
||||||
TRKEY_NUM_PLUS = (1<<4),
|
|
||||||
TRKEY_NUM_MINUS = (1<<5),
|
|
||||||
TRKEY_PAGE_UP = (1<<6),
|
|
||||||
TRKEY_PAGE_DOWN = (1<<7)
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \enum ParseArgsStatus
|
* \enum ParseArgsStatus
|
||||||
* \brief State of parsing commandline arguments
|
* \brief State of parsing commandline arguments
|
||||||
|
@ -296,20 +280,6 @@ public:
|
||||||
//! Updates the mouse position explicitly
|
//! Updates the mouse position explicitly
|
||||||
void UpdateMouse();
|
void UpdateMouse();
|
||||||
|
|
||||||
//! Returns the current key modifiers
|
|
||||||
int GetKmods() const;
|
|
||||||
//! Returns whether the given kmod is active
|
|
||||||
bool GetKmodState(int kmod) const;
|
|
||||||
|
|
||||||
//! Returns whether the tracked key is pressed
|
|
||||||
bool GetTrackedKeyState(TrackedKey key) const;
|
|
||||||
|
|
||||||
//! Returns whether the mouse button is pressed
|
|
||||||
bool GetMouseButtonState(int index) const;
|
|
||||||
|
|
||||||
//! Resets tracked key states and modifiers
|
|
||||||
void ResetKeyStates();
|
|
||||||
|
|
||||||
//! Management of the grab mode for input (keyboard & mouse)
|
//! Management of the grab mode for input (keyboard & mouse)
|
||||||
//@{
|
//@{
|
||||||
void SetGrabInput(bool grab);
|
void SetGrabInput(bool grab);
|
||||||
|
@ -322,9 +292,6 @@ public:
|
||||||
MouseMode GetMouseMode() const;
|
MouseMode GetMouseMode() const;
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
//! Returns the position of mouse cursor (in interface coords)
|
|
||||||
Math::Point GetMousePos() const;
|
|
||||||
|
|
||||||
//! Moves (warps) the mouse cursor to the specified position (in interface coords)
|
//! Moves (warps) the mouse cursor to the specified position (in interface coords)
|
||||||
void MoveMouse(Math::Point pos);
|
void MoveMouse(Math::Point pos);
|
||||||
|
|
||||||
|
@ -411,6 +378,8 @@ protected:
|
||||||
CRobotMain* m_robotMain;
|
CRobotMain* m_robotMain;
|
||||||
//! Profile (INI) reader/writer
|
//! Profile (INI) reader/writer
|
||||||
CProfile* m_profile;
|
CProfile* m_profile;
|
||||||
|
//! Input manager
|
||||||
|
CInput* m_input;
|
||||||
|
|
||||||
//! Code to return at exit
|
//! Code to return at exit
|
||||||
int m_exitCode;
|
int m_exitCode;
|
||||||
|
@ -456,17 +425,8 @@ protected:
|
||||||
bool m_simulationSuspended;
|
bool m_simulationSuspended;
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
//! Current state of key modifiers (bitmask of SDLMod)
|
|
||||||
unsigned int m_kmodState;
|
|
||||||
//! Current state of some tracked keys (bitmask of TrackedKey enum values)
|
|
||||||
unsigned int m_trackedKeys;
|
|
||||||
|
|
||||||
//! Current mode of mouse
|
//! Current mode of mouse
|
||||||
MouseMode m_mouseMode;
|
MouseMode m_mouseMode;
|
||||||
//! Current position of mouse cursor
|
|
||||||
Math::Point m_mousePos;
|
|
||||||
//! Current state of mouse buttons (bitmask of MouseButton enum values)
|
|
||||||
unsigned int m_mouseButtonsState;
|
|
||||||
|
|
||||||
//! Info about current joystick device
|
//! Info about current joystick device
|
||||||
JoystickDevice m_joystick;
|
JoystickDevice m_joystick;
|
||||||
|
|
|
@ -0,0 +1,401 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the Colobot: Gold Edition source code
|
||||||
|
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||||
|
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "app/input.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "common/logger.h"
|
||||||
|
#include "common/restext.h"
|
||||||
|
|
||||||
|
#include "graphics/engine/engine.h"
|
||||||
|
|
||||||
|
#include "object/robotmain.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
|
template<> CInput* CSingleton<CInput>::m_instance = nullptr;
|
||||||
|
|
||||||
|
CInput::CInput()
|
||||||
|
{
|
||||||
|
m_kmodState = 0;
|
||||||
|
m_trackedKeys = 0;
|
||||||
|
m_mousePos = Math::Point();
|
||||||
|
m_mouseButtonsState = 0;
|
||||||
|
|
||||||
|
m_joystickDeadzone = 0.2f;
|
||||||
|
SetDefaultInputBindings();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInput::EventProcess(Event& event)
|
||||||
|
{
|
||||||
|
if(event.type == EVENT_KEY_DOWN ||
|
||||||
|
event.type == EVENT_KEY_UP)
|
||||||
|
{
|
||||||
|
// Use the occasion to update kmods
|
||||||
|
m_kmodState = event.kmodState;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the occasion to update mouse button state
|
||||||
|
if (event.type == EVENT_MOUSE_BUTTON_DOWN)
|
||||||
|
{
|
||||||
|
m_mouseButtonsState |= event.mouseButton.button;
|
||||||
|
}
|
||||||
|
if(event.type == EVENT_MOUSE_BUTTON_UP)
|
||||||
|
{
|
||||||
|
m_mouseButtonsState &= ~event.mouseButton.button;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type == EVENT_KEY_DOWN)
|
||||||
|
{
|
||||||
|
if (event.key.key == KEY(KP8))
|
||||||
|
m_trackedKeys |= TRKEY_NUM_UP;
|
||||||
|
else if (event.key.key == KEY(KP2))
|
||||||
|
m_trackedKeys |= TRKEY_NUM_DOWN;
|
||||||
|
else if (event.key.key == KEY(KP4))
|
||||||
|
m_trackedKeys |= TRKEY_NUM_LEFT;
|
||||||
|
else if (event.key.key == KEY(KP6))
|
||||||
|
m_trackedKeys |= TRKEY_NUM_RIGHT;
|
||||||
|
else if (event.key.key == KEY(KP_PLUS))
|
||||||
|
m_trackedKeys |= TRKEY_NUM_PLUS;
|
||||||
|
else if (event.key.key == KEY(KP_MINUS))
|
||||||
|
m_trackedKeys |= TRKEY_NUM_MINUS;
|
||||||
|
else if (event.key.key == KEY(PAGEUP))
|
||||||
|
m_trackedKeys |= TRKEY_PAGE_UP;
|
||||||
|
else if (event.key.key == KEY(PAGEDOWN))
|
||||||
|
m_trackedKeys |= TRKEY_PAGE_DOWN;
|
||||||
|
}
|
||||||
|
else if (event.type == EVENT_KEY_UP)
|
||||||
|
{
|
||||||
|
if (event.key.key == KEY(KP8))
|
||||||
|
m_trackedKeys &= ~TRKEY_NUM_UP;
|
||||||
|
else if (event.key.key == KEY(KP2))
|
||||||
|
m_trackedKeys &= ~TRKEY_NUM_DOWN;
|
||||||
|
else if (event.key.key == KEY(KP4))
|
||||||
|
m_trackedKeys &= ~TRKEY_NUM_LEFT;
|
||||||
|
else if (event.key.key == KEY(KP6))
|
||||||
|
m_trackedKeys &= ~TRKEY_NUM_RIGHT;
|
||||||
|
else if (event.key.key == KEY(KP_PLUS))
|
||||||
|
m_trackedKeys &= ~TRKEY_NUM_PLUS;
|
||||||
|
else if (event.key.key == KEY(KP_MINUS))
|
||||||
|
m_trackedKeys &= ~TRKEY_NUM_MINUS;
|
||||||
|
else if (event.key.key == KEY(PAGEUP))
|
||||||
|
m_trackedKeys &= ~TRKEY_PAGE_UP;
|
||||||
|
else if (event.key.key == KEY(PAGEDOWN))
|
||||||
|
m_trackedKeys &= ~TRKEY_PAGE_DOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(event.type == EVENT_KEY_DOWN ||
|
||||||
|
event.type == EVENT_KEY_UP)
|
||||||
|
{
|
||||||
|
event.key.slot = FindBinding(event.key.key);
|
||||||
|
}
|
||||||
|
|
||||||
|
event.trackedKeysState = m_trackedKeys;
|
||||||
|
event.kmodState = m_kmodState;
|
||||||
|
event.mousePos = m_mousePos;
|
||||||
|
event.mouseButtonsState = m_mouseButtonsState;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Motion vector management */
|
||||||
|
|
||||||
|
if (event.type == EVENT_KEY_DOWN)
|
||||||
|
{
|
||||||
|
if (event.key.slot == INPUT_SLOT_UP ) m_keyMotion.y = 1.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_DOWN ) m_keyMotion.y = -1.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_LEFT ) m_keyMotion.x = -1.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 1.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_GUP ) m_keyMotion.z = 1.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_GDOWN) m_keyMotion.z = -1.0f;
|
||||||
|
}
|
||||||
|
else if (event.type == EVENT_KEY_UP)
|
||||||
|
{
|
||||||
|
if (event.key.slot == INPUT_SLOT_UP ) m_keyMotion.y = 0.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_DOWN ) m_keyMotion.y = 0.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_LEFT ) m_keyMotion.x = 0.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_RIGHT) m_keyMotion.x = 0.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_GUP ) m_keyMotion.z = 0.0f;
|
||||||
|
if (event.key.slot == INPUT_SLOT_GDOWN) m_keyMotion.z = 0.0f;
|
||||||
|
}
|
||||||
|
else if (event.type == EVENT_JOY_AXIS)
|
||||||
|
{
|
||||||
|
if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_X).axis)
|
||||||
|
{
|
||||||
|
m_joyMotion.x = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone);
|
||||||
|
if (GetJoyAxisBinding(JOY_AXIS_SLOT_X).invert)
|
||||||
|
m_joyMotion.x *= -1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Y).axis)
|
||||||
|
{
|
||||||
|
m_joyMotion.y = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone);
|
||||||
|
if (GetJoyAxisBinding(JOY_AXIS_SLOT_Y).invert)
|
||||||
|
m_joyMotion.y *= -1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Z).axis)
|
||||||
|
{
|
||||||
|
m_joyMotion.z = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone);
|
||||||
|
if (GetJoyAxisBinding(JOY_AXIS_SLOT_Z).invert)
|
||||||
|
m_joyMotion.z *= -1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInput::MouseMove(Math::IntPoint pos)
|
||||||
|
{
|
||||||
|
m_mousePos = Gfx::CEngine::GetInstancePointer()->WindowToInterfaceCoords(pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CInput::GetKmods() const
|
||||||
|
{
|
||||||
|
return m_kmodState;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CInput::GetKmodState(int kmod) const
|
||||||
|
{
|
||||||
|
return (m_kmodState & kmod) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CInput::GetTrackedKeyState(TrackedKey key) const
|
||||||
|
{
|
||||||
|
return (m_trackedKeys & key) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CInput::GetMouseButtonState(int index) const
|
||||||
|
{
|
||||||
|
return (m_mouseButtonsState & (1<<index)) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInput::ResetKeyStates()
|
||||||
|
{
|
||||||
|
CLogger::GetInstancePointer()->Trace("Reset key states\n");
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Math::Point CInput::GetMousePos() const
|
||||||
|
{
|
||||||
|
return m_mousePos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInput::SetDefaultInputBindings()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
||||||
|
{
|
||||||
|
m_inputBindings[i].primary = m_inputBindings[i].secondary = KEY_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++)
|
||||||
|
{
|
||||||
|
m_joyAxisBindings[i].axis = AXIS_INVALID;
|
||||||
|
m_joyAxisBindings[i].invert = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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_LEFT ].secondary = KEY(a);
|
||||||
|
m_inputBindings[INPUT_SLOT_RIGHT ].secondary = KEY(d);
|
||||||
|
m_inputBindings[INPUT_SLOT_UP ].secondary = KEY(w);
|
||||||
|
m_inputBindings[INPUT_SLOT_DOWN ].secondary = KEY(s);
|
||||||
|
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_ACTION ].secondary = KEY(e);
|
||||||
|
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;
|
||||||
|
m_joyAxisBindings[JOY_AXIS_SLOT_Z].axis = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInput::SetInputBinding(InputSlot slot, InputBinding binding)
|
||||||
|
{
|
||||||
|
unsigned int index = static_cast<unsigned int>(slot);
|
||||||
|
m_inputBindings[index] = binding;
|
||||||
|
}
|
||||||
|
|
||||||
|
const InputBinding& CInput::GetInputBinding(InputSlot slot)
|
||||||
|
{
|
||||||
|
unsigned int index = static_cast<unsigned int>(slot);
|
||||||
|
return m_inputBindings[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInput::SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding)
|
||||||
|
{
|
||||||
|
unsigned int index = static_cast<unsigned int>(slot);
|
||||||
|
m_joyAxisBindings[index] = binding;
|
||||||
|
}
|
||||||
|
|
||||||
|
const JoyAxisBinding& CInput::GetJoyAxisBinding(JoyAxisSlot slot)
|
||||||
|
{
|
||||||
|
unsigned int index = static_cast<unsigned int>(slot);
|
||||||
|
return m_joyAxisBindings[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInput::SetJoystickDeadzone(float zone)
|
||||||
|
{
|
||||||
|
m_joystickDeadzone = zone;
|
||||||
|
}
|
||||||
|
|
||||||
|
float CInput::GetJoystickDeadzone()
|
||||||
|
{
|
||||||
|
return m_joystickDeadzone;
|
||||||
|
}
|
||||||
|
|
||||||
|
InputSlot CInput::FindBinding(unsigned int key)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
||||||
|
{
|
||||||
|
InputSlot slot = static_cast<InputSlot>(i);
|
||||||
|
InputBinding b = GetInputBinding(slot);
|
||||||
|
if(b.primary == key || b.secondary == key)
|
||||||
|
return slot;
|
||||||
|
}
|
||||||
|
return INPUT_SLOT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CInput::SaveKeyBindings()
|
||||||
|
{
|
||||||
|
std::stringstream key;
|
||||||
|
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
||||||
|
{
|
||||||
|
InputBinding b = GetInputBinding(static_cast<InputSlot>(i));
|
||||||
|
|
||||||
|
key << b.primary << " ";
|
||||||
|
key << b.secondary << " ";
|
||||||
|
}
|
||||||
|
return key.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CInput::LoadKeyBindings(std::string keys)
|
||||||
|
{
|
||||||
|
std::stringstream skey;
|
||||||
|
skey.str(keys);
|
||||||
|
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
||||||
|
{
|
||||||
|
InputBinding b;
|
||||||
|
skey >> b.primary;
|
||||||
|
skey >> b.secondary;
|
||||||
|
SetInputBinding(static_cast<InputSlot>(i), b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::map<InputSlot, std::string> keyTable =
|
||||||
|
{
|
||||||
|
{ 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" }
|
||||||
|
};
|
||||||
|
|
||||||
|
InputSlot CInput::SearchKeyById(std::string id)
|
||||||
|
{
|
||||||
|
for(auto& key : keyTable)
|
||||||
|
{
|
||||||
|
if ( id == key.second )
|
||||||
|
{
|
||||||
|
return key.first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return INPUT_SLOT_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string CInput::GetKeysString(InputBinding b)
|
||||||
|
{
|
||||||
|
std::ostringstream ss;
|
||||||
|
if ( b.primary != KEY_INVALID )
|
||||||
|
{
|
||||||
|
std::string iNameStr;
|
||||||
|
if ( GetResource(RES_KEY, b.primary, iNameStr) )
|
||||||
|
{
|
||||||
|
ss << iNameStr;
|
||||||
|
|
||||||
|
if ( b.secondary != KEY_INVALID )
|
||||||
|
{
|
||||||
|
if ( GetResource(RES_KEY, b.secondary, iNameStr) )
|
||||||
|
{
|
||||||
|
std::string textStr;
|
||||||
|
GetResource(RES_TEXT, RT_KEY_OR, textStr);
|
||||||
|
|
||||||
|
ss << textStr << iNameStr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return "?";
|
||||||
|
}
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string CInput::GetKeysString(InputSlot slot)
|
||||||
|
{
|
||||||
|
InputBinding b = GetInputBinding(slot);
|
||||||
|
return GetKeysString(b);
|
||||||
|
}
|
|
@ -0,0 +1,177 @@
|
||||||
|
/*
|
||||||
|
* This file is part of the Colobot: Gold Edition source code
|
||||||
|
* Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
|
||||||
|
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see http://gnu.org/licenses
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file app/input.h
|
||||||
|
* \brief CInput class
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/event.h"
|
||||||
|
#include "common/key.h"
|
||||||
|
#include "common/singleton.h"
|
||||||
|
|
||||||
|
#include "math/intpoint.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \enum TrackedKey
|
||||||
|
* \brief Additional keys whose state (pressed/released) is tracked by CInput
|
||||||
|
*/
|
||||||
|
enum TrackedKey
|
||||||
|
{
|
||||||
|
TRKEY_NUM_UP = (1<<0),
|
||||||
|
TRKEY_NUM_DOWN = (1<<1),
|
||||||
|
TRKEY_NUM_LEFT = (1<<2),
|
||||||
|
TRKEY_NUM_RIGHT = (1<<3),
|
||||||
|
TRKEY_NUM_PLUS = (1<<4),
|
||||||
|
TRKEY_NUM_MINUS = (1<<5),
|
||||||
|
TRKEY_PAGE_UP = (1<<6),
|
||||||
|
TRKEY_PAGE_DOWN = (1<<7)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \struct InputBinding
|
||||||
|
* \brief Binding for input slot
|
||||||
|
*/
|
||||||
|
struct InputBinding
|
||||||
|
{
|
||||||
|
//! Primary and secondary bindings
|
||||||
|
//! Can be regular key, virtual key or virtual joystick button
|
||||||
|
unsigned int primary, secondary;
|
||||||
|
|
||||||
|
InputBinding(unsigned int p = KEY_INVALID, unsigned int s = KEY_INVALID)
|
||||||
|
: primary(p), secondary(s) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \struct JoyAxisBinding
|
||||||
|
* \brief Binding for joystick axis
|
||||||
|
*/
|
||||||
|
struct JoyAxisBinding
|
||||||
|
{
|
||||||
|
//! Axis index or AXIS_INVALID
|
||||||
|
int axis;
|
||||||
|
//! True to invert axis value
|
||||||
|
bool invert;
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Invalid value for axis binding (no axis assigned)
|
||||||
|
const int AXIS_INVALID = -1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class CInput
|
||||||
|
* \brief Management of mouse, keyboard and joystick
|
||||||
|
*/
|
||||||
|
class CInput : public CSingleton<CInput>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
CInput();
|
||||||
|
|
||||||
|
//! Process an incoming event, also sets .trackedKeysState, .kmodState, .mousePos, .mouseButtonsState and .key.slot
|
||||||
|
void EventProcess(Event &event);
|
||||||
|
|
||||||
|
//! Called by CApplication on SDL MOUSE_MOTION event
|
||||||
|
void MouseMove(Math::IntPoint pos);
|
||||||
|
|
||||||
|
|
||||||
|
//! Returns the current key modifiers
|
||||||
|
int GetKmods() const;
|
||||||
|
|
||||||
|
//! Returns whether the given kmod is active
|
||||||
|
bool GetKmodState(int kmod) const;
|
||||||
|
|
||||||
|
//! Returns whether the tracked key is pressed
|
||||||
|
bool GetTrackedKeyState(TrackedKey key) const;
|
||||||
|
|
||||||
|
//! Returns whether the mouse button is pressed
|
||||||
|
bool GetMouseButtonState(int index) const;
|
||||||
|
|
||||||
|
//! Resets tracked key states and modifiers
|
||||||
|
void ResetKeyStates();
|
||||||
|
|
||||||
|
//! Returns the position of mouse cursor (in interface coords)
|
||||||
|
Math::Point GetMousePos() const;
|
||||||
|
|
||||||
|
|
||||||
|
//! Sets the default input bindings (key and axes)
|
||||||
|
void SetDefaultInputBindings();
|
||||||
|
|
||||||
|
//! Management of input bindings
|
||||||
|
//@{
|
||||||
|
void SetInputBinding(InputSlot slot, InputBinding binding);
|
||||||
|
const InputBinding& GetInputBinding(InputSlot slot);
|
||||||
|
//@}
|
||||||
|
|
||||||
|
//! Management of joystick axis bindings
|
||||||
|
//@{
|
||||||
|
void SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding);
|
||||||
|
const JoyAxisBinding& GetJoyAxisBinding(JoyAxisSlot slot);
|
||||||
|
//@}
|
||||||
|
|
||||||
|
//! Management of joystick deadzone
|
||||||
|
//@{
|
||||||
|
void SetJoystickDeadzone(float zone);
|
||||||
|
float GetJoystickDeadzone();
|
||||||
|
//@}
|
||||||
|
|
||||||
|
//! Get binding slot for given key
|
||||||
|
InputSlot FindBinding(unsigned int key);
|
||||||
|
|
||||||
|
//! Saving/loading key bindings to string (for storing in colobot.ini)
|
||||||
|
//@{
|
||||||
|
std::string SaveKeyBindings();
|
||||||
|
void LoadKeyBindings(std::string keys);
|
||||||
|
//@}
|
||||||
|
|
||||||
|
//! Seeks a InputSlot by id. Returns INPUT_SLOT_MAX if not found
|
||||||
|
InputSlot SearchKeyById(std::string name);
|
||||||
|
|
||||||
|
//! Returns string describing keys to pressed
|
||||||
|
//@{
|
||||||
|
std::string GetKeysString(InputBinding binding);
|
||||||
|
std::string GetKeysString(InputSlot slot);
|
||||||
|
//@}
|
||||||
|
|
||||||
|
private:
|
||||||
|
//! Current state of key modifiers (bitmask of SDLMod)
|
||||||
|
unsigned int m_kmodState;
|
||||||
|
//! Current state of some tracked keys (bitmask of TrackedKey enum values)
|
||||||
|
unsigned int m_trackedKeys;
|
||||||
|
|
||||||
|
|
||||||
|
//! Current position of mouse cursor
|
||||||
|
Math::Point m_mousePos;
|
||||||
|
//! Current state of mouse buttons (bitmask of MouseButton enum values)
|
||||||
|
unsigned int m_mouseButtonsState;
|
||||||
|
|
||||||
|
|
||||||
|
//! Motion vector set by keyboard or joystick buttons
|
||||||
|
Math::Vector m_keyMotion;
|
||||||
|
//! Motion vector set by joystick axes
|
||||||
|
Math::Vector m_joyMotion;
|
||||||
|
|
||||||
|
|
||||||
|
//! Bindings for user inputs
|
||||||
|
InputBinding m_inputBindings[INPUT_SLOT_MAX];
|
||||||
|
JoyAxisBinding m_joyAxisBindings[JOY_AXIS_SLOT_MAX];
|
||||||
|
float m_joystickDeadzone;
|
||||||
|
};
|
|
@ -579,6 +579,8 @@ struct KeyEventData
|
||||||
//! Unicode character
|
//! Unicode character
|
||||||
//! NOTE: applicable only to EVENT_KEY_DOWN events!
|
//! NOTE: applicable only to EVENT_KEY_DOWN events!
|
||||||
unsigned int unicode;
|
unsigned int unicode;
|
||||||
|
//! Input binding slot for this key
|
||||||
|
InputSlot slot;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -229,53 +229,6 @@ enum ResearchType
|
||||||
RESEARCH_SNIFFER = (1<<12) //! < sniffer
|
RESEARCH_SNIFFER = (1<<12) //! < sniffer
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* \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
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \enum JoyAxisSlot
|
|
||||||
* \brief Slots for joystick axes inputs
|
|
||||||
*/
|
|
||||||
enum JoyAxisSlot
|
|
||||||
{
|
|
||||||
JOY_AXIS_SLOT_X,
|
|
||||||
JOY_AXIS_SLOT_Y,
|
|
||||||
JOY_AXIS_SLOT_Z,
|
|
||||||
|
|
||||||
JOY_AXIS_SLOT_MAX
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: move to CRobotMain
|
// TODO: move to CRobotMain
|
||||||
extern long g_id; // unique identifier
|
extern long g_id; // unique identifier
|
||||||
|
|
|
@ -65,3 +65,49 @@ enum VirtualKmod
|
||||||
//! Special value for invalid key bindings
|
//! Special value for invalid key bindings
|
||||||
const unsigned int KEY_INVALID = SDLK_LAST + 1000;
|
const unsigned int KEY_INVALID = SDLK_LAST + 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \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
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \enum JoyAxisSlot
|
||||||
|
* \brief Slots for joystick axes inputs
|
||||||
|
*/
|
||||||
|
enum JoyAxisSlot
|
||||||
|
{
|
||||||
|
JOY_AXIS_SLOT_X,
|
||||||
|
JOY_AXIS_SLOT_Y,
|
||||||
|
JOY_AXIS_SLOT_Z,
|
||||||
|
|
||||||
|
JOY_AXIS_SLOT_MAX
|
||||||
|
};
|
|
@ -20,6 +20,8 @@
|
||||||
|
|
||||||
#include "common/restext.h"
|
#include "common/restext.h"
|
||||||
|
|
||||||
|
#include "app/input.h"
|
||||||
|
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
|
|
||||||
#include "common/global.h"
|
#include "common/global.h"
|
||||||
|
@ -745,53 +747,6 @@ void SetGlobalGamerName(std::string name)
|
||||||
strcpy(g_gamerName, name.c_str());
|
strcpy(g_gamerName, name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct KeyDesc
|
|
||||||
{
|
|
||||||
InputSlot key;
|
|
||||||
char name[20];
|
|
||||||
};
|
|
||||||
|
|
||||||
static KeyDesc keyTable[22] =
|
|
||||||
{
|
|
||||||
{ 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, InputSlot &key)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 22 ;i++)
|
|
||||||
{
|
|
||||||
if ( strstr(cmd, keyTable[i].name) == cmd )
|
|
||||||
{
|
|
||||||
key = keyTable[i].key;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replaces the commands "\key name;" in a text.
|
// Replaces the commands "\key name;" in a text.
|
||||||
|
|
||||||
static void PutKeyName(std::string& dst, const char* src)
|
static void PutKeyName(std::string& dst, const char* src)
|
||||||
|
@ -807,21 +762,12 @@ static void PutKeyName(std::string& dst, const char* src)
|
||||||
src[s+3] == 'y' &&
|
src[s+3] == 'y' &&
|
||||||
src[s+4] == ' ' )
|
src[s+4] == ' ' )
|
||||||
{
|
{
|
||||||
InputSlot key;
|
int count;
|
||||||
if ( SearchKey(src+s+5, key) )
|
for(count = 0; src[s+5+count] != ';'; count++);
|
||||||
{
|
CInput* input = CInput::GetInstancePointer();
|
||||||
unsigned int res = CRobotMain::GetInstancePointer()->GetInputBinding(key).primary;
|
InputSlot key = input->SearchKeyById(std::string(&src[s+5], count));
|
||||||
if (res != KEY_INVALID)
|
dst.append(input->GetKeysString(key));
|
||||||
{
|
s = s+5+count+1;
|
||||||
std::string keyName;
|
|
||||||
if ( GetResource(RES_KEY, res, keyName) )
|
|
||||||
{
|
|
||||||
dst.append(keyName);
|
|
||||||
while ( src[s++] != ';' );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dst.append(1, src[s++]);
|
dst.append(1, src[s++]);
|
||||||
|
|
|
@ -154,6 +154,5 @@ enum ResTextType
|
||||||
void InitializeRestext();
|
void InitializeRestext();
|
||||||
|
|
||||||
void SetGlobalGamerName(std::string name);
|
void SetGlobalGamerName(std::string name);
|
||||||
bool SearchKey(const char *cmd, InputSlot& slot);
|
|
||||||
bool GetResource(ResType type, int num, std::string& text);
|
bool GetResource(ResType type, int num, std::string& text);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "graphics/engine/camera.h"
|
#include "graphics/engine/camera.h"
|
||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
|
#include "app/input.h"
|
||||||
|
|
||||||
#include "common/iman.h"
|
#include "common/iman.h"
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "graphics/engine/engine.h"
|
#include "graphics/engine/engine.h"
|
||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
|
#include "app/input.h"
|
||||||
|
|
||||||
#include "common/image.h"
|
#include "common/image.h"
|
||||||
#include "common/key.h"
|
#include "common/key.h"
|
||||||
|
@ -4292,7 +4293,7 @@ void CEngine::DrawMouse()
|
||||||
|
|
||||||
int index = static_cast<int>(m_mouseType);
|
int index = static_cast<int>(m_mouseType);
|
||||||
|
|
||||||
Math::Point pos = m_app->GetMousePos();
|
Math::Point pos = CInput::GetInstancePointer()->GetMousePos();
|
||||||
pos.x = pos.x - (m_mice[index].hotPoint.x * m_mouseSize.x) / 32.0f;
|
pos.x = pos.x - (m_mice[index].hotPoint.x * m_mouseSize.x) / 32.0f;
|
||||||
pos.y = pos.y - ((32.0f - m_mice[index].hotPoint.y) * m_mouseSize.y) / 32.0f;
|
pos.y = pos.y - ((32.0f - m_mice[index].hotPoint.y) * m_mouseSize.y) / 32.0f;
|
||||||
|
|
||||||
|
|
|
@ -226,8 +226,7 @@ bool CBrain::EventProcess(const Event &event)
|
||||||
action = EVENT_NULL;
|
action = EVENT_NULL;
|
||||||
|
|
||||||
if ( event.type == EVENT_KEY_DOWN &&
|
if ( event.type == EVENT_KEY_DOWN &&
|
||||||
(event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).primary ||
|
event.key.slot == INPUT_SLOT_ACTION &&
|
||||||
event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).secondary ) &&
|
|
||||||
!m_main->GetEditLock() )
|
!m_main->GetEditLock() )
|
||||||
{
|
{
|
||||||
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
|
pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include "CBot/CBotDll.h"
|
#include "CBot/CBotDll.h"
|
||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
|
#include "app/input.h"
|
||||||
|
|
||||||
#include "common/event.h"
|
#include "common/event.h"
|
||||||
#include "common/global.h"
|
#include "common/global.h"
|
||||||
|
@ -629,6 +630,7 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
|
||||||
m_lightning = m_engine->GetLightning();
|
m_lightning = m_engine->GetLightning();
|
||||||
m_planet = m_engine->GetPlanet();
|
m_planet = m_engine->GetPlanet();
|
||||||
m_pause = CPauseManager::GetInstancePointer();
|
m_pause = CPauseManager::GetInstancePointer();
|
||||||
|
m_input = CInput::GetInstancePointer();
|
||||||
|
|
||||||
m_interface = new Ui::CInterface();
|
m_interface = new Ui::CInterface();
|
||||||
m_terrain = new Gfx::CTerrain();
|
m_terrain = new Gfx::CTerrain();
|
||||||
|
@ -714,9 +716,6 @@ CRobotMain::CRobotMain(CApplication* app, bool loadProfile)
|
||||||
m_autosaveSlots = 3;
|
m_autosaveSlots = 3;
|
||||||
m_autosaveLast = 0.0f;
|
m_autosaveLast = 0.0f;
|
||||||
|
|
||||||
m_joystickDeadzone = 0.2f;
|
|
||||||
SetDefaultInputBindings();
|
|
||||||
|
|
||||||
FlushDisplayInfo();
|
FlushDisplayInfo();
|
||||||
|
|
||||||
m_fontSize = 19.0f;
|
m_fontSize = 19.0f;
|
||||||
|
@ -935,6 +934,8 @@ CRobotMain::~CRobotMain()
|
||||||
delete m_map;
|
delete m_map;
|
||||||
m_map = nullptr;
|
m_map = nullptr;
|
||||||
|
|
||||||
|
m_input = nullptr;
|
||||||
|
m_pause = nullptr;
|
||||||
m_app = nullptr;
|
m_app = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1002,98 +1003,6 @@ void CRobotMain::CreateIni()
|
||||||
GetProfile().Save();
|
GetProfile().Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CRobotMain::SetDefaultInputBindings()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
|
||||||
{
|
|
||||||
m_inputBindings[i].primary = m_inputBindings[i].secondary = KEY_INVALID;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < JOY_AXIS_SLOT_MAX; i++)
|
|
||||||
{
|
|
||||||
m_joyAxisBindings[i].axis = AXIS_INVALID;
|
|
||||||
m_joyAxisBindings[i].invert = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
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_LEFT ].secondary = KEY(a);
|
|
||||||
m_inputBindings[INPUT_SLOT_RIGHT ].secondary = KEY(d);
|
|
||||||
m_inputBindings[INPUT_SLOT_UP ].secondary = KEY(w);
|
|
||||||
m_inputBindings[INPUT_SLOT_DOWN ].secondary = KEY(s);
|
|
||||||
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_ACTION ].secondary = KEY(e);
|
|
||||||
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;
|
|
||||||
m_joyAxisBindings[JOY_AXIS_SLOT_Z].axis = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CRobotMain::SetInputBinding(InputSlot slot, InputBinding binding)
|
|
||||||
{
|
|
||||||
unsigned int index = static_cast<unsigned int>(slot);
|
|
||||||
m_inputBindings[index] = binding;
|
|
||||||
}
|
|
||||||
|
|
||||||
const InputBinding& CRobotMain::GetInputBinding(InputSlot slot)
|
|
||||||
{
|
|
||||||
unsigned int index = static_cast<unsigned int>(slot);
|
|
||||||
return m_inputBindings[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
void CRobotMain::SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding)
|
|
||||||
{
|
|
||||||
unsigned int index = static_cast<unsigned int>(slot);
|
|
||||||
m_joyAxisBindings[index] = binding;
|
|
||||||
}
|
|
||||||
|
|
||||||
const JoyAxisBinding& CRobotMain::GetJoyAxisBinding(JoyAxisSlot slot)
|
|
||||||
{
|
|
||||||
unsigned int index = static_cast<unsigned int>(slot);
|
|
||||||
return m_joyAxisBindings[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
void CRobotMain::SetJoystickDeadzone(float zone)
|
|
||||||
{
|
|
||||||
m_joystickDeadzone = zone;
|
|
||||||
}
|
|
||||||
|
|
||||||
float CRobotMain::GetJoystickDeadzone()
|
|
||||||
{
|
|
||||||
return m_joystickDeadzone;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CRobotMain::ResetKeyStates()
|
|
||||||
{
|
|
||||||
m_keyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
||||||
m_joyMotion = Math::Vector(0.0f, 0.0f, 0.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! Changes phase
|
//! Changes phase
|
||||||
void CRobotMain::ChangePhase(Phase phase)
|
void CRobotMain::ChangePhase(Phase phase)
|
||||||
{
|
{
|
||||||
|
@ -1345,66 +1254,6 @@ void CRobotMain::ChangePhase(Phase phase)
|
||||||
//! Processes an event
|
//! Processes an event
|
||||||
bool CRobotMain::ProcessEvent(Event &event)
|
bool CRobotMain::ProcessEvent(Event &event)
|
||||||
{
|
{
|
||||||
/* Motion vector management */
|
|
||||||
|
|
||||||
if (event.type == EVENT_KEY_DOWN)
|
|
||||||
{
|
|
||||||
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 ).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)
|
|
||||||
{
|
|
||||||
if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_X).axis)
|
|
||||||
{
|
|
||||||
m_joyMotion.x = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone);
|
|
||||||
if (GetJoyAxisBinding(JOY_AXIS_SLOT_X).invert)
|
|
||||||
m_joyMotion.x *= -1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Y).axis)
|
|
||||||
{
|
|
||||||
m_joyMotion.y = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone);
|
|
||||||
if (GetJoyAxisBinding(JOY_AXIS_SLOT_Y).invert)
|
|
||||||
m_joyMotion.y *= -1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.joyAxis.axis == GetJoyAxisBinding(JOY_AXIS_SLOT_Z).axis)
|
|
||||||
{
|
|
||||||
m_joyMotion.z = Math::Neutral(event.joyAxis.value / 32768.0f, m_joystickDeadzone);
|
|
||||||
if (GetJoyAxisBinding(JOY_AXIS_SLOT_Z).invert)
|
|
||||||
m_joyMotion.z *= -1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event.motionInput = Math::Clamp(m_joyMotion + m_keyMotion, Math::Vector(-1.0f, -1.0f, -1.0f), Math::Vector(1.0f, 1.0f, 1.0f));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (event.type == EVENT_FRAME)
|
if (event.type == EVENT_FRAME)
|
||||||
{
|
{
|
||||||
if (!m_movie->EventProcess(event)) // end of the movie?
|
if (!m_movie->EventProcess(event)) // end of the movie?
|
||||||
|
@ -1494,10 +1343,8 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
|
|
||||||
if (event.type == EVENT_KEY_DOWN)
|
if (event.type == EVENT_KEY_DOWN)
|
||||||
{
|
{
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).primary ||
|
if (event.key.slot == INPUT_SLOT_HELP ||
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_HELP).secondary ||
|
event.key.slot == INPUT_SLOT_PROG ||
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_PROG).primary ||
|
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_PROG).secondary ||
|
|
||||||
event.key.key == KEY(ESCAPE))
|
event.key.key == KEY(ESCAPE))
|
||||||
{
|
{
|
||||||
StopDisplayInfo();
|
StopDisplayInfo();
|
||||||
|
@ -1521,7 +1368,7 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case EVENT_KEY_DOWN:
|
case EVENT_KEY_DOWN:
|
||||||
KeyCamera(event.type, event.key.key);
|
KeyCamera(event.type, event.key.slot);
|
||||||
HiliteClear();
|
HiliteClear();
|
||||||
if (event.key.key == KEY(F11))
|
if (event.key.key == KEY(F11))
|
||||||
{
|
{
|
||||||
|
@ -1530,14 +1377,12 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
}
|
}
|
||||||
if (m_editLock) // current edition?
|
if (m_editLock) // current edition?
|
||||||
{
|
{
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).primary ||
|
if (event.key.slot == INPUT_SLOT_HELP)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_HELP).secondary)
|
|
||||||
{
|
{
|
||||||
StartDisplayInfo(SATCOM_HUSTON, false);
|
StartDisplayInfo(SATCOM_HUSTON, false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_PROG).primary ||
|
if (event.key.slot == INPUT_SLOT_PROG)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_PROG).secondary)
|
|
||||||
{
|
{
|
||||||
StartDisplayInfo(SATCOM_PROG, false);
|
StartDisplayInfo(SATCOM_PROG, false);
|
||||||
return false;
|
return false;
|
||||||
|
@ -1546,8 +1391,7 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
}
|
}
|
||||||
if (m_movieLock) // current movie?
|
if (m_movieLock) // current movie?
|
||||||
{
|
{
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).primary ||
|
if (event.key.slot == INPUT_SLOT_QUIT ||
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_QUIT).secondary ||
|
|
||||||
event.key.key == KEY(ESCAPE))
|
event.key.key == KEY(ESCAPE))
|
||||||
{
|
{
|
||||||
AbortMovie();
|
AbortMovie();
|
||||||
|
@ -1556,21 +1400,18 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
}
|
}
|
||||||
if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT)
|
if (m_camera->GetType() == Gfx::CAM_TYPE_VISIT)
|
||||||
{
|
{
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_VISIT).primary ||
|
if (event.key.slot == INPUT_SLOT_VISIT)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_VISIT).secondary)
|
|
||||||
{
|
{
|
||||||
StartDisplayVisit(EVENT_NULL);
|
StartDisplayVisit(EVENT_NULL);
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).primary ||
|
if (event.key.slot == INPUT_SLOT_QUIT ||
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_QUIT).secondary ||
|
|
||||||
event.key.key == KEY(ESCAPE))
|
event.key.key == KEY(ESCAPE))
|
||||||
{
|
{
|
||||||
StopDisplayVisit();
|
StopDisplayVisit();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_QUIT).primary ||
|
if (event.key.slot == INPUT_SLOT_QUIT)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_QUIT).secondary)
|
|
||||||
{
|
{
|
||||||
if (m_movie->IsExist())
|
if (m_movie->IsExist())
|
||||||
StartDisplayInfo(SATCOM_HUSTON, false);
|
StartDisplayInfo(SATCOM_HUSTON, false);
|
||||||
|
@ -1581,7 +1422,7 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
else if (!m_cmdEdit)
|
else if (!m_cmdEdit)
|
||||||
m_dialog->StartAbort(); // do you want to leave?
|
m_dialog->StartAbort(); // do you want to leave?
|
||||||
}
|
}
|
||||||
if (event.key.key == KEY(PAUSE))
|
if (event.key.key == KEY(PAUSE)) //TODO: key binding
|
||||||
{
|
{
|
||||||
if (!m_movieLock && !m_editLock && !m_cmdEdit &&
|
if (!m_movieLock && !m_editLock && !m_cmdEdit &&
|
||||||
m_camera->GetType() != Gfx::CAM_TYPE_VISIT &&
|
m_camera->GetType() != Gfx::CAM_TYPE_VISIT &&
|
||||||
|
@ -1590,62 +1431,52 @@ bool CRobotMain::ProcessEvent(Event &event)
|
||||||
ChangePause(m_pause->GetPause(PAUSE_USER) ? PAUSE_NONE : PAUSE_USER);
|
ChangePause(m_pause->GetPause(PAUSE_USER) ? PAUSE_NONE : PAUSE_USER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).primary ||
|
if (event.key.slot == INPUT_SLOT_CAMERA)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_CAMERA).secondary)
|
|
||||||
{
|
{
|
||||||
ChangeCamera();
|
ChangeCamera();
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_DESEL).primary ||
|
if (event.key.slot == INPUT_SLOT_DESEL)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_DESEL).secondary)
|
|
||||||
{
|
{
|
||||||
if (m_shortCut)
|
if (m_shortCut)
|
||||||
DeselectObject();
|
DeselectObject();
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_HUMAN).primary ||
|
if (event.key.slot == INPUT_SLOT_HUMAN)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_HUMAN).secondary)
|
|
||||||
{
|
{
|
||||||
SelectHuman();
|
SelectHuman();
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_NEXT).primary ||
|
if (event.key.slot == INPUT_SLOT_NEXT)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_NEXT).secondary)
|
|
||||||
{
|
{
|
||||||
if (m_shortCut)
|
if (m_shortCut)
|
||||||
m_short->SelectNext();
|
m_short->SelectNext();
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_HELP).primary ||
|
if (event.key.slot == INPUT_SLOT_HELP)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_HELP).secondary)
|
|
||||||
{
|
{
|
||||||
StartDisplayInfo(SATCOM_HUSTON, true);
|
StartDisplayInfo(SATCOM_HUSTON, true);
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_PROG).primary ||
|
if (event.key.slot == INPUT_SLOT_PROG)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_PROG).secondary)
|
|
||||||
{
|
{
|
||||||
StartDisplayInfo(SATCOM_PROG, true);
|
StartDisplayInfo(SATCOM_PROG, true);
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_VISIT).primary ||
|
if (event.key.slot == INPUT_SLOT_VISIT)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_VISIT).secondary)
|
|
||||||
{
|
{
|
||||||
StartDisplayVisit(EVENT_NULL);
|
StartDisplayVisit(EVENT_NULL);
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED10).primary ||
|
if (event.key.slot == INPUT_SLOT_SPEED10)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_SPEED10).secondary)
|
|
||||||
{
|
{
|
||||||
SetSpeed(1.0f);
|
SetSpeed(1.0f);
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED15).primary ||
|
if (event.key.slot == INPUT_SLOT_SPEED15)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_SPEED15).secondary)
|
|
||||||
{
|
{
|
||||||
SetSpeed(1.5f);
|
SetSpeed(1.5f);
|
||||||
}
|
}
|
||||||
if (event.key.key == GetInputBinding(INPUT_SLOT_SPEED20).primary ||
|
if (event.key.slot == INPUT_SLOT_SPEED20)
|
||||||
event.key.key == GetInputBinding(INPUT_SLOT_SPEED20).secondary)
|
|
||||||
{
|
{
|
||||||
SetSpeed(2.0f);
|
SetSpeed(2.0f);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_KEY_UP:
|
case EVENT_KEY_UP:
|
||||||
KeyCamera(event.type, event.key.key);
|
KeyCamera(event.type, event.key.slot);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_MOUSE_BUTTON_DOWN:
|
case EVENT_MOUSE_BUTTON_DOWN:
|
||||||
|
@ -3263,32 +3094,26 @@ void CRobotMain::ChangeCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Remote control the camera using the arrow keys
|
//! Remote control the camera using the arrow keys
|
||||||
void CRobotMain::KeyCamera(EventType type, unsigned int key)
|
void CRobotMain::KeyCamera(EventType type, InputSlot key)
|
||||||
{
|
{
|
||||||
// TODO: rewrite key handling to input bindings
|
|
||||||
|
|
||||||
if (type == EVENT_KEY_UP)
|
if (type == EVENT_KEY_UP)
|
||||||
{
|
{
|
||||||
if (key == GetInputBinding(INPUT_SLOT_LEFT).primary ||
|
if (key == INPUT_SLOT_LEFT)
|
||||||
key == GetInputBinding(INPUT_SLOT_LEFT).secondary)
|
|
||||||
{
|
{
|
||||||
m_cameraPan = 0.0f;
|
m_cameraPan = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == GetInputBinding(INPUT_SLOT_RIGHT).primary ||
|
if (key == INPUT_SLOT_RIGHT)
|
||||||
key == GetInputBinding(INPUT_SLOT_RIGHT).secondary)
|
|
||||||
{
|
{
|
||||||
m_cameraPan = 0.0f;
|
m_cameraPan = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == GetInputBinding(INPUT_SLOT_UP).primary ||
|
if (key == INPUT_SLOT_UP)
|
||||||
key == GetInputBinding(INPUT_SLOT_UP).secondary)
|
|
||||||
{
|
{
|
||||||
m_cameraZoom = 0.0f;
|
m_cameraZoom = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == GetInputBinding(INPUT_SLOT_DOWN).primary ||
|
if (key == INPUT_SLOT_DOWN)
|
||||||
key == GetInputBinding(INPUT_SLOT_DOWN).secondary)
|
|
||||||
{
|
{
|
||||||
m_cameraZoom = 0.0f;
|
m_cameraZoom = 0.0f;
|
||||||
}
|
}
|
||||||
|
@ -3304,26 +3129,22 @@ void CRobotMain::KeyCamera(EventType type, unsigned int key)
|
||||||
|
|
||||||
if (type == EVENT_KEY_DOWN)
|
if (type == EVENT_KEY_DOWN)
|
||||||
{
|
{
|
||||||
if (key == GetInputBinding(INPUT_SLOT_LEFT).primary ||
|
if (key == INPUT_SLOT_LEFT)
|
||||||
key == GetInputBinding(INPUT_SLOT_LEFT).secondary)
|
|
||||||
{
|
{
|
||||||
m_cameraPan = -1.0f;
|
m_cameraPan = -1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == GetInputBinding(INPUT_SLOT_RIGHT).primary ||
|
if (key == INPUT_SLOT_RIGHT)
|
||||||
key == GetInputBinding(INPUT_SLOT_RIGHT).secondary)
|
|
||||||
{
|
{
|
||||||
m_cameraPan = 1.0f;
|
m_cameraPan = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == GetInputBinding(INPUT_SLOT_UP).primary ||
|
if (key == INPUT_SLOT_UP)
|
||||||
key == GetInputBinding(INPUT_SLOT_UP).secondary)
|
|
||||||
{
|
{
|
||||||
m_cameraZoom = -1.0f;
|
m_cameraZoom = -1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == GetInputBinding(INPUT_SLOT_DOWN).primary ||
|
if (key == INPUT_SLOT_DOWN)
|
||||||
key == GetInputBinding(INPUT_SLOT_DOWN).secondary)
|
|
||||||
{
|
{
|
||||||
m_cameraZoom = 1.0f;
|
m_cameraZoom = 1.0f;
|
||||||
}
|
}
|
||||||
|
@ -4750,7 +4571,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
||||||
CreateShortcuts();
|
CreateShortcuts();
|
||||||
m_map->UpdateMap();
|
m_map->UpdateMap();
|
||||||
// TODO: m_engine->TimeInit(); ??
|
// TODO: m_engine->TimeInit(); ??
|
||||||
m_app->ResetKeyStates();
|
m_input->ResetKeyStates();
|
||||||
m_time = 0.0f;
|
m_time = 0.0f;
|
||||||
m_gameTime = 0.0f;
|
m_gameTime = 0.0f;
|
||||||
m_autosaveLast = 0.0f;
|
m_autosaveLast = 0.0f;
|
||||||
|
@ -6828,7 +6649,7 @@ void CRobotMain::SetEditLock(bool lock, bool edit)
|
||||||
m_map->ShowMap(!m_editLock && m_mapShow);
|
m_map->ShowMap(!m_editLock && m_mapShow);
|
||||||
|
|
||||||
m_displayText->HideText(lock);
|
m_displayText->HideText(lock);
|
||||||
m_app->ResetKeyStates();
|
m_input->ResetKeyStates();
|
||||||
|
|
||||||
if (m_editLock)
|
if (m_editLock)
|
||||||
HiliteClear();
|
HiliteClear();
|
||||||
|
|
|
@ -77,6 +77,7 @@ enum Phase
|
||||||
class CEventQueue;
|
class CEventQueue;
|
||||||
class CSoundInterface;
|
class CSoundInterface;
|
||||||
class CLevelParserLine;
|
class CLevelParserLine;
|
||||||
|
class CInput;
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
class CEngine;
|
class CEngine;
|
||||||
|
@ -166,36 +167,6 @@ const int SATCOM_PROG = 4;
|
||||||
const int SATCOM_SOLUCE = 5;
|
const int SATCOM_SOLUCE = 5;
|
||||||
const int SATCOM_MAX = 6;
|
const int SATCOM_MAX = 6;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \struct InputBinding
|
|
||||||
* \brief Binding for input slot
|
|
||||||
*/
|
|
||||||
struct InputBinding
|
|
||||||
{
|
|
||||||
//! Primary and secondary bindings
|
|
||||||
//! Can be regular key, virtual key or virtual joystick button
|
|
||||||
unsigned int primary, secondary;
|
|
||||||
|
|
||||||
InputBinding(unsigned int p = KEY_INVALID, unsigned int s = KEY_INVALID)
|
|
||||||
: primary(p), secondary(s) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \struct JoyAxisBinding
|
|
||||||
* \brief Binding for joystick axis
|
|
||||||
*/
|
|
||||||
struct JoyAxisBinding
|
|
||||||
{
|
|
||||||
//! Axis index or AXIS_INVALID
|
|
||||||
int axis;
|
|
||||||
//! True to invert axis value
|
|
||||||
bool invert;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! Invalid value for axis binding (no axis assigned)
|
|
||||||
const int AXIS_INVALID = -1;
|
|
||||||
|
|
||||||
class CRobotMain : public CSingleton<CRobotMain>
|
class CRobotMain : public CSingleton<CRobotMain>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -214,30 +185,6 @@ public:
|
||||||
|
|
||||||
void ResetAfterDeviceChanged();
|
void ResetAfterDeviceChanged();
|
||||||
|
|
||||||
//! Sets the default input bindings (key and axes)
|
|
||||||
void SetDefaultInputBindings();
|
|
||||||
|
|
||||||
//! Management of input bindings
|
|
||||||
//@{
|
|
||||||
void SetInputBinding(InputSlot slot, InputBinding binding);
|
|
||||||
const InputBinding& GetInputBinding(InputSlot slot);
|
|
||||||
//@}
|
|
||||||
|
|
||||||
//! Management of joystick axis bindings
|
|
||||||
//@{
|
|
||||||
void SetJoyAxisBinding(JoyAxisSlot slot, JoyAxisBinding binding);
|
|
||||||
const JoyAxisBinding& GetJoyAxisBinding(JoyAxisSlot slot);
|
|
||||||
//@}
|
|
||||||
|
|
||||||
//! Management of joystick deadzone
|
|
||||||
//@{
|
|
||||||
void SetJoystickDeadzone(float zone);
|
|
||||||
float GetJoystickDeadzone();
|
|
||||||
//@}
|
|
||||||
|
|
||||||
//! Resets tracked key states (motion vectors)
|
|
||||||
void ResetKeyStates();
|
|
||||||
|
|
||||||
void ChangePhase(Phase phase);
|
void ChangePhase(Phase phase);
|
||||||
bool ProcessEvent(Event &event);
|
bool ProcessEvent(Event &event);
|
||||||
|
|
||||||
|
@ -421,7 +368,7 @@ protected:
|
||||||
CObject* DetectObject(Math::Point pos);
|
CObject* DetectObject(Math::Point pos);
|
||||||
void ChangeCamera();
|
void ChangeCamera();
|
||||||
void RemoteCamera(float pan, float zoom, float rTime);
|
void RemoteCamera(float pan, float zoom, float rTime);
|
||||||
void KeyCamera(EventType event, unsigned int key);
|
void KeyCamera(EventType event, InputSlot key);
|
||||||
void AbortMovie();
|
void AbortMovie();
|
||||||
bool IsSelectable(CObject* pObj);
|
bool IsSelectable(CObject* pObj);
|
||||||
void SelectOneObject(CObject* pObj, bool displayError=true);
|
void SelectOneObject(CObject* pObj, bool displayError=true);
|
||||||
|
@ -462,15 +409,7 @@ protected:
|
||||||
Ui::CDisplayInfo* m_displayInfo;
|
Ui::CDisplayInfo* m_displayInfo;
|
||||||
CSoundInterface* m_sound;
|
CSoundInterface* m_sound;
|
||||||
CPauseManager* m_pause;
|
CPauseManager* m_pause;
|
||||||
|
CInput* m_input;
|
||||||
//! Bindings for user inputs
|
|
||||||
InputBinding m_inputBindings[INPUT_SLOT_MAX];
|
|
||||||
JoyAxisBinding m_joyAxisBindings[JOY_AXIS_SLOT_MAX];
|
|
||||||
float m_joystickDeadzone;
|
|
||||||
//! Motion vector set by keyboard or joystick buttons
|
|
||||||
Math::Vector m_keyMotion;
|
|
||||||
//! Motion vector set by joystick axes
|
|
||||||
Math::Vector m_joyMotion;
|
|
||||||
|
|
||||||
|
|
||||||
float m_time;
|
float m_time;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "ui/edit.h"
|
#include "ui/edit.h"
|
||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
|
#include "app/input.h"
|
||||||
|
|
||||||
#include "clipboard/clipboard.h"
|
#include "clipboard/clipboard.h"
|
||||||
|
|
||||||
|
@ -1443,9 +1444,8 @@ void CEdit::LoadImage(std::string name)
|
||||||
bool CEdit::ReadText(std::string filename, int addSize)
|
bool CEdit::ReadText(std::string filename, int addSize)
|
||||||
{
|
{
|
||||||
char *buffer;
|
char *buffer;
|
||||||
int len, i, j, n, font, iIndex, iLines, iCount, iLink, res;
|
int len, i, j, n, font, iIndex, iLines, iCount, iLink;
|
||||||
char iName[50];
|
char iName[50];
|
||||||
char text[50];
|
|
||||||
float iWidth;
|
float iWidth;
|
||||||
InputSlot slot;
|
InputSlot slot;
|
||||||
bool bInSoluce, bBOL;
|
bool bInSoluce, bBOL;
|
||||||
|
@ -1782,71 +1782,36 @@ bool CEdit::ReadText(std::string filename, int addSize)
|
||||||
buffer[i+3] == 'y' &&
|
buffer[i+3] == 'y' &&
|
||||||
buffer[i+4] == ' ' )
|
buffer[i+4] == ' ' )
|
||||||
{
|
{
|
||||||
if ( m_bSoluce || !bInSoluce )
|
int count;
|
||||||
|
for(count = 0; buffer[i+5+count] != ';'; count++);
|
||||||
|
if ( m_bSoluce || !bInSoluce ) //TODO: ???
|
||||||
{
|
{
|
||||||
if ( SearchKey(buffer+i+5, slot) )
|
CInput* input = CInput::GetInstancePointer();
|
||||||
|
slot = input->SearchKeyById(std::string(&buffer[i+5], count));
|
||||||
|
if ( slot != INPUT_SLOT_MAX )
|
||||||
{
|
{
|
||||||
CRobotMain* main = CRobotMain::GetInstancePointer();
|
std::string iNameStr = input->GetKeysString(slot);
|
||||||
res = main->GetInputBinding(slot).primary;
|
strcpy(iName, iNameStr.c_str());
|
||||||
if ( res != 0 )
|
m_text[j] = ' ';
|
||||||
|
m_format[j] = font;
|
||||||
|
j ++;
|
||||||
|
n = 0;
|
||||||
|
while ( iName[n] != 0 )
|
||||||
{
|
{
|
||||||
std::string iNameStr;
|
m_text[j] = iName[n++];
|
||||||
if ( GetResource(RES_KEY, res, iNameStr) )
|
m_format[j] = font;
|
||||||
{
|
j ++;
|
||||||
strcpy(iName, iNameStr.c_str());
|
|
||||||
m_text[j] = ' ';
|
|
||||||
m_format[j] = font;
|
|
||||||
j ++;
|
|
||||||
n = 0;
|
|
||||||
while ( iName[n] != 0 )
|
|
||||||
{
|
|
||||||
m_text[j] = iName[n++];
|
|
||||||
m_format[j] = font;
|
|
||||||
j ++;
|
|
||||||
}
|
|
||||||
m_text[j] = ' ';
|
|
||||||
m_format[j] = font;
|
|
||||||
j ++;
|
|
||||||
|
|
||||||
res = main->GetInputBinding(slot).secondary;
|
|
||||||
if ( res != 0 )
|
|
||||||
{
|
|
||||||
if ( GetResource(RES_KEY, res, iNameStr) )
|
|
||||||
{
|
|
||||||
strcpy(iName, iNameStr.c_str());
|
|
||||||
|
|
||||||
std::string textStr;
|
|
||||||
GetResource(RES_TEXT, RT_KEY_OR, textStr);
|
|
||||||
strcpy(text, textStr.c_str());
|
|
||||||
n = 0;
|
|
||||||
while ( text[n] != 0 )
|
|
||||||
{
|
|
||||||
m_text[j] = text[n++];
|
|
||||||
m_format[j] = font&~Gfx::FONT_MASK_HIGHLIGHT;
|
|
||||||
j ++;
|
|
||||||
}
|
|
||||||
n = 0;
|
|
||||||
while ( iName[n] != 0 )
|
|
||||||
{
|
|
||||||
m_text[j] = iName[n++];
|
|
||||||
m_format[j] = font;
|
|
||||||
j ++;
|
|
||||||
}
|
|
||||||
m_text[j] = ' ';
|
|
||||||
m_format[j] = font;
|
|
||||||
j ++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while ( buffer[i++] != ';' );
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
m_text[j] = ' ';
|
||||||
|
m_format[j] = font;
|
||||||
|
j ++;
|
||||||
|
} else {
|
||||||
|
m_text[j] = '?';
|
||||||
|
m_format[j] = font;
|
||||||
|
j ++;
|
||||||
}
|
}
|
||||||
m_text[j] = '?';
|
|
||||||
m_format[j] = font;
|
|
||||||
j ++;
|
|
||||||
}
|
}
|
||||||
while ( buffer[i++] != ';' );
|
i = i+5+count+1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,25 +28,16 @@
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
|
|
||||||
static void GetKeyName(std::string& name, unsigned int key)
|
|
||||||
{
|
|
||||||
if (!GetResource(RES_KEY, key, name))
|
|
||||||
{
|
|
||||||
name = StrUtils::Format("Code %d", key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CKey::CKey() : CControl()
|
CKey::CKey() : CControl()
|
||||||
{
|
{
|
||||||
m_catch = false;
|
m_catch = false;
|
||||||
|
|
||||||
m_robotMain = CRobotMain::GetInstancePointer();
|
m_input = CInput::GetInstancePointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
CKey::~CKey()
|
CKey::~CKey()
|
||||||
{
|
{
|
||||||
m_robotMain = nullptr;
|
m_input = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
bool CKey::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg)
|
||||||
|
@ -110,17 +101,19 @@ bool CKey::EventProcess(const Event &event)
|
||||||
|
|
||||||
bool CKey::TestKey(unsigned 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) || key == KEY(ESCAPE)) return true; // blocked key
|
||||||
|
|
||||||
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
||||||
{
|
{
|
||||||
InputSlot slot = static_cast<InputSlot>(i);
|
InputSlot slot = static_cast<InputSlot>(i);
|
||||||
InputBinding b = m_robotMain->GetInputBinding(slot);
|
InputBinding b = m_input->GetInputBinding(slot);
|
||||||
if (key == b.primary || key == b.secondary)
|
if (key == b.primary)
|
||||||
m_robotMain->SetInputBinding(slot, InputBinding()); // nothing!
|
m_input->SetInputBinding(slot, InputBinding(b.secondary, KEY_INVALID)); // nothing!
|
||||||
|
if (key == b.secondary)
|
||||||
|
m_input->SetInputBinding(slot, InputBinding(b.primary, KEY_INVALID)); // nothing!
|
||||||
|
|
||||||
if (b.primary == KEY_INVALID) // first free option?
|
if (b.primary == KEY_INVALID) // first free option?
|
||||||
m_robotMain->SetInputBinding(slot, InputBinding(b.secondary, b.primary)); // shift
|
m_input->SetInputBinding(slot, InputBinding(b.secondary, b.primary)); // shift
|
||||||
}
|
}
|
||||||
|
|
||||||
return false; // not used
|
return false; // not used
|
||||||
|
@ -139,7 +132,7 @@ void CKey::Draw()
|
||||||
|
|
||||||
|
|
||||||
m_engine->SetTexture("textures/interface/button1.png");
|
m_engine->SetTexture("textures/interface/button1.png");
|
||||||
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL); // was D3DSTATENORMAL
|
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
|
||||||
|
|
||||||
float zoomExt = 1.00f;
|
float zoomExt = 1.00f;
|
||||||
float zoomInt = 0.95f;
|
float zoomInt = 0.95f;
|
||||||
|
@ -181,18 +174,7 @@ void CKey::Draw()
|
||||||
|
|
||||||
float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f;
|
float h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f;
|
||||||
|
|
||||||
std::string keyName;
|
std::string keyName = m_input->GetKeysString(m_binding);
|
||||||
GetKeyName(keyName, m_binding.primary);
|
|
||||||
if (m_binding.secondary != KEY_INVALID)
|
|
||||||
{
|
|
||||||
std::string orText;
|
|
||||||
GetResource(RES_TEXT, RT_KEY_OR, orText);
|
|
||||||
keyName.append(orText);
|
|
||||||
|
|
||||||
std::string secondaryKeyName;
|
|
||||||
GetKeyName(secondaryKeyName, m_binding.secondary);
|
|
||||||
keyName.append(secondaryKeyName);
|
|
||||||
}
|
|
||||||
|
|
||||||
Math::Point pos;
|
Math::Point pos;
|
||||||
pos.x = m_pos.x + m_dim.x * 0.5f;
|
pos.x = m_pos.x + m_dim.x * 0.5f;
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
|
|
||||||
#include "ui/control.h"
|
#include "ui/control.h"
|
||||||
|
|
||||||
|
#include "app/input.h"
|
||||||
|
|
||||||
#include "common/event.h"
|
#include "common/event.h"
|
||||||
#include "common/restext.h"
|
#include "common/restext.h"
|
||||||
#include "common/key.h"
|
#include "common/key.h"
|
||||||
|
@ -58,7 +60,7 @@ protected:
|
||||||
bool TestKey(unsigned int key);
|
bool TestKey(unsigned int key);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CRobotMain* m_robotMain;
|
CInput* m_input;
|
||||||
|
|
||||||
InputBinding m_binding;
|
InputBinding m_binding;
|
||||||
bool m_catch;
|
bool m_catch;
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "ui/maindialog.h"
|
#include "ui/maindialog.h"
|
||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
|
#include "app/input.h"
|
||||||
#include "app/system.h"
|
#include "app/system.h"
|
||||||
|
|
||||||
#include "common/config.h"
|
#include "common/config.h"
|
||||||
|
@ -2657,7 +2658,7 @@ bool CMainDialog::EventProcess(const Event &event)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EVENT_INTERFACE_KDEF:
|
case EVENT_INTERFACE_KDEF:
|
||||||
m_main->SetDefaultInputBindings();
|
CInput::GetInstancePointer()->SetDefaultInputBindings();
|
||||||
UpdateKey();
|
UpdateKey();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -4085,13 +4086,13 @@ void CMainDialog::IOReadList()
|
||||||
pl->SetSelect(m_saveList.size());
|
pl->SetSelect(m_saveList.size());
|
||||||
pl->ShowSelect(false); // shows the selected columns
|
pl->ShowSelect(false); // shows the selected columns
|
||||||
|
|
||||||
int i;
|
unsigned int i;
|
||||||
std::string screenName;
|
std::string screenName;
|
||||||
|
|
||||||
for ( i=0; i < m_saveList.size(); i++ )
|
for ( i=0; i < m_saveList.size(); i++ )
|
||||||
{
|
{
|
||||||
screenName = "textures/../" + m_saveList.at(i) + "/screen.png";
|
screenName = "textures/../" + m_saveList.at(i) + "/screen.png";
|
||||||
m_engine->DeleteTexture(screenName);
|
m_engine->DeleteTexture(screenName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5050,16 +5051,7 @@ void CMainDialog::SetupMemorize()
|
||||||
// TODO: Default value
|
// TODO: Default value
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stringstream key;
|
GetProfile().SetStringProperty("Setup", "KeyMap", CInput::GetInstancePointer()->SaveKeyBindings());
|
||||||
for (int i = 0; i < INPUT_SLOT_MAX; i++)
|
|
||||||
{
|
|
||||||
InputBinding b = m_main->GetInputBinding(static_cast<InputSlot>(i));
|
|
||||||
|
|
||||||
key << b.primary << " ";
|
|
||||||
key << b.secondary << " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
GetProfile().SetStringProperty("Setup", "KeyMap", key.str());
|
|
||||||
|
|
||||||
GetProfile().SetIntProperty("Setup", "DeleteGamer", m_bDeleteGamer);
|
GetProfile().SetIntProperty("Setup", "DeleteGamer", m_bDeleteGamer);
|
||||||
}
|
}
|
||||||
|
@ -5270,15 +5262,7 @@ void CMainDialog::SetupRecall()
|
||||||
|
|
||||||
if (GetProfile().GetStringProperty("Setup", "KeyMap", key))
|
if (GetProfile().GetStringProperty("Setup", "KeyMap", key))
|
||||||
{
|
{
|
||||||
std::stringstream skey;
|
CInput::GetInstancePointer()->LoadKeyBindings(key);
|
||||||
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<InputSlot>(i), b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( GetProfile().GetIntProperty("Setup", "DeleteGamer", iValue) )
|
if ( GetProfile().GetIntProperty("Setup", "DeleteGamer", iValue) )
|
||||||
|
@ -5426,7 +5410,7 @@ void CMainDialog::UpdateKey()
|
||||||
CKey* pk = static_cast<CKey*>(pw->SearchControl(key_event[first+i]));
|
CKey* pk = static_cast<CKey*>(pw->SearchControl(key_event[first+i]));
|
||||||
if (pk == nullptr) break;
|
if (pk == nullptr) break;
|
||||||
|
|
||||||
pk->SetBinding(m_main->GetInputBinding(key_table[first+i]));
|
pk->SetBinding(CInput::GetInstancePointer()->GetInputBinding(key_table[first+i]));
|
||||||
pos.y -= dim.y;
|
pos.y -= dim.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5448,7 +5432,7 @@ void CMainDialog::ChangeKey(EventType event)
|
||||||
CKey* pk = static_cast<CKey*>(pw->SearchControl(key_event[i]));
|
CKey* pk = static_cast<CKey*>(pw->SearchControl(key_event[i]));
|
||||||
if (pk == nullptr) break;
|
if (pk == nullptr) break;
|
||||||
|
|
||||||
m_main->SetInputBinding(key_table[i], pk->GetBinding());
|
CInput::GetInstancePointer()->SetInputBinding(key_table[i], pk->GetBinding());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,9 +128,8 @@ bool CStudio::EventProcess(const Event &event)
|
||||||
|
|
||||||
if ( event.type == EVENT_KEY_DOWN )
|
if ( event.type == EVENT_KEY_DOWN )
|
||||||
{
|
{
|
||||||
if ( (event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).primary ||
|
if ( event.key.slot == INPUT_SLOT_ACTION &&
|
||||||
event.key.key == m_main->GetInputBinding(INPUT_SLOT_ACTION).secondary) &&
|
(event.kmodState & KEY_MOD(CTRL)) != 0 )
|
||||||
(event.kmodState & KEY_MOD(CTRL)) != 0 )
|
|
||||||
{
|
{
|
||||||
Event newEvent = event;
|
Event newEvent = event;
|
||||||
newEvent.type = EVENT_STUDIO_OK;
|
newEvent.type = EVENT_STUDIO_OK;
|
||||||
|
@ -256,8 +255,7 @@ bool CStudio::EventProcess(const Event &event)
|
||||||
|
|
||||||
if ( event.type == EVENT_KEY_DOWN )
|
if ( event.type == EVENT_KEY_DOWN )
|
||||||
{
|
{
|
||||||
if ( event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).primary ||
|
if ( event.key.slot == INPUT_SLOT_CBOT )
|
||||||
event.key.key == m_main->GetInputBinding(INPUT_SLOT_CBOT).secondary )
|
|
||||||
{
|
{
|
||||||
if ( m_helpFilename.length() > 0 )
|
if ( m_helpFilename.length() > 0 )
|
||||||
{
|
{
|
||||||
|
@ -1411,10 +1409,10 @@ void CStudio::UpdateChangeList()
|
||||||
void CStudio::SetFilenameField(CEdit* edit, const std::string& filename)
|
void CStudio::SetFilenameField(CEdit* edit, const std::string& filename)
|
||||||
{
|
{
|
||||||
std::string name = filename;
|
std::string name = filename;
|
||||||
if(name.length() > edit->GetMaxChar()) {
|
if(name.length() > static_cast<unsigned int>(edit->GetMaxChar())) {
|
||||||
if(name.substr(name.length()-4) == ".txt")
|
if(name.substr(name.length()-4) == ".txt")
|
||||||
name = name.substr(0, name.length()-4);
|
name = name.substr(0, name.length()-4);
|
||||||
if(name.length() > edit->GetMaxChar()) {
|
if(name.length() > static_cast<unsigned int>(edit->GetMaxChar())) {
|
||||||
CLogger::GetInstancePointer()->Warn("Tried to load too long filename!\n");
|
CLogger::GetInstancePointer()->Warn("Tried to load too long filename!\n");
|
||||||
name = name.substr(0, edit->GetMaxChar()); // truncates according to max length
|
name = name.substr(0, edit->GetMaxChar()); // truncates according to max length
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue