2020-10-23 13:38:02 +02:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* 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 2
|
|
|
|
* 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "twine/input.h"
|
2020-10-23 20:09:33 +02:00
|
|
|
#include "backends/keymapper/keymapper.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/keyboard.h"
|
2020-10-23 13:38:02 +02:00
|
|
|
#include "common/system.h"
|
2020-10-23 20:09:33 +02:00
|
|
|
#include "twine/actor.h"
|
2020-10-23 13:44:38 +02:00
|
|
|
#include "twine/twine.h"
|
2020-10-23 13:38:02 +02:00
|
|
|
|
|
|
|
namespace TwinE {
|
|
|
|
|
2020-10-23 20:09:33 +02:00
|
|
|
const char *mainKeyMapId = "mainKeyMap";
|
|
|
|
const char *uiKeyMapId = "uiKeyMap";
|
|
|
|
const char *cutsceneKeyMapId = "cutsceneKeyMap";
|
|
|
|
|
|
|
|
ScopedKeyMap::ScopedKeyMap(TwinEEngine* engine, const char *id) : _engine(engine) {
|
|
|
|
_prevKeyMap = _engine->_input->currentKeyMap();
|
2020-11-12 22:03:23 +01:00
|
|
|
_engine->_input->enableKeyMap(id);
|
2020-10-23 20:09:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ScopedKeyMap::~ScopedKeyMap() {
|
2020-10-25 21:55:14 +01:00
|
|
|
_engine->_input->enableKeyMap(_prevKeyMap.c_str());
|
2020-10-23 20:09:33 +02:00
|
|
|
}
|
|
|
|
|
2020-10-23 13:38:02 +02:00
|
|
|
Input::Input(TwinEEngine *engine) : _engine(engine) {}
|
|
|
|
|
2020-10-23 20:09:33 +02:00
|
|
|
bool Input::isActionActive(TwinEActionType actionType, bool onlyFirstTime) const {
|
|
|
|
if (onlyFirstTime) {
|
|
|
|
return actionStates[actionType] == 1;
|
|
|
|
}
|
|
|
|
return actionStates[actionType] > 0;
|
2020-10-23 13:38:02 +02:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:09:33 +02:00
|
|
|
bool Input::toggleActionIfActive(TwinEActionType actionType) {
|
|
|
|
if (actionStates[actionType] > 0) {
|
|
|
|
actionStates[actionType] = 0;
|
|
|
|
return true;
|
2020-10-23 13:38:02 +02:00
|
|
|
}
|
2020-10-23 20:09:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-24 12:32:00 +02:00
|
|
|
bool Input::toggleAbortAction() {
|
2020-10-27 16:21:52 +01:00
|
|
|
bool abortState = false;
|
|
|
|
abortState |= toggleActionIfActive(TwinEActionType::CutsceneAbort);
|
|
|
|
abortState |= toggleActionIfActive(TwinEActionType::UIAbort);
|
|
|
|
abortState |= toggleActionIfActive(TwinEActionType::Escape);
|
|
|
|
return abortState;
|
2020-10-24 12:32:00 +02:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:09:33 +02:00
|
|
|
bool Input::isQuickBehaviourActionActive() const {
|
|
|
|
return isActionActive(TwinEActionType::QuickBehaviourNormal) || isActionActive(TwinEActionType::QuickBehaviourAthletic) || isActionActive(TwinEActionType::QuickBehaviourAggressive) || isActionActive(TwinEActionType::QuickBehaviourDiscreet);
|
|
|
|
}
|
|
|
|
|
2020-10-26 01:32:48 +01:00
|
|
|
bool Input::isMoveOrTurnActionActive() const {
|
|
|
|
return isActionActive(TwinEActionType::TurnLeft) || isActionActive(TwinEActionType::TurnRight) || isActionActive(TwinEActionType::MoveBackward) || isActionActive(TwinEActionType::MoveForward);
|
|
|
|
}
|
|
|
|
|
2020-10-26 01:36:34 +01:00
|
|
|
bool Input::isHeroActionActive() const {
|
|
|
|
return isActionActive(TwinEActionType::ExecuteBehaviourAction) || isActionActive(TwinEActionType::SpecialAction);
|
|
|
|
}
|
|
|
|
|
2020-11-21 12:38:38 +01:00
|
|
|
bool Input::enableAdditionalKeyMap(const char *id, bool enable) {
|
2020-11-20 18:49:52 +01:00
|
|
|
Common::Keymapper *keymapper = g_system->getEventManager()->getKeymapper();
|
|
|
|
Common::Keymap *keymap = keymapper->getKeymap(id);
|
|
|
|
if (keymap == nullptr) {
|
2020-11-21 12:38:38 +01:00
|
|
|
return false;
|
2020-11-20 18:49:52 +01:00
|
|
|
}
|
2020-11-21 12:38:38 +01:00
|
|
|
const bool changed = keymap->isEnabled() != enable;
|
2020-11-20 18:49:52 +01:00
|
|
|
keymap->setEnabled(enable);
|
2020-11-21 12:38:38 +01:00
|
|
|
return changed;
|
2020-11-20 18:49:52 +01:00
|
|
|
}
|
|
|
|
|
2020-10-25 21:55:14 +01:00
|
|
|
void Input::enableKeyMap(const char *id) {
|
2020-10-23 23:10:24 +02:00
|
|
|
if (_currentKeyMap == id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:09:33 +02:00
|
|
|
Common::Keymapper *keymapper = g_system->getEventManager()->getKeymapper();
|
|
|
|
const Common::KeymapArray &keymaps = keymapper->getKeymaps();
|
|
|
|
for (Common::Keymap *keymap : keymaps) {
|
2020-10-25 09:18:37 +01:00
|
|
|
const Common::String& keymapId = keymap->getId();
|
|
|
|
if (keymapId == mainKeyMapId || keymapId == uiKeyMapId || keymapId == cutsceneKeyMapId) {
|
|
|
|
keymap->setEnabled(keymapId == id);
|
|
|
|
}
|
2020-10-23 20:09:33 +02:00
|
|
|
}
|
|
|
|
_currentKeyMap = id;
|
2020-10-23 23:10:24 +02:00
|
|
|
debug("enable keymap %s", id);
|
2020-10-23 20:09:33 +02:00
|
|
|
}
|
|
|
|
|
2020-10-26 00:41:43 +01:00
|
|
|
static constexpr const struct ActionMapping {
|
|
|
|
TwinEActionType action;
|
2020-11-21 14:27:49 +01:00
|
|
|
uint8 mask;
|
|
|
|
} cursorChangeMask[] = {
|
2020-11-21 13:37:56 +01:00
|
|
|
{MoveForward, 0x01},
|
|
|
|
{MoveBackward, 0x02},
|
|
|
|
{TurnLeft, 0x04},
|
2020-11-21 14:27:49 +01:00
|
|
|
{TurnRight, 0x08}
|
|
|
|
};
|
2020-10-26 00:41:43 +01:00
|
|
|
|
2020-10-26 00:13:54 +01:00
|
|
|
uint8 Input::processCustomEngineEventStart(const Common::Event &event) {
|
|
|
|
if (!_engine->cfgfile.Debug) {
|
|
|
|
switch (event.customType) {
|
2020-11-13 21:05:32 +01:00
|
|
|
case TwinEActionType::DebugGridCameraPressUp:
|
|
|
|
case TwinEActionType::DebugGridCameraPressDown:
|
|
|
|
case TwinEActionType::DebugGridCameraPressLeft:
|
|
|
|
case TwinEActionType::DebugGridCameraPressRight:
|
|
|
|
case TwinEActionType::DebugMenu:
|
|
|
|
case TwinEActionType::DebugMenuActivate:
|
2020-10-26 00:13:54 +01:00
|
|
|
case TwinEActionType::NextRoom:
|
|
|
|
case TwinEActionType::PreviousRoom:
|
|
|
|
case TwinEActionType::ApplyCellingGrid:
|
|
|
|
case TwinEActionType::IncreaseCellingGridIndex:
|
|
|
|
case TwinEActionType::DecreaseCellingGridIndex:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
actionStates[event.customType] = 1 + event.kbdRepeat;
|
2020-11-21 14:27:49 +01:00
|
|
|
break;
|
2020-10-26 00:13:54 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
actionStates[event.customType] = 1 + event.kbdRepeat;
|
2020-11-21 14:27:49 +01:00
|
|
|
}
|
|
|
|
for (int i = 0; i < ARRAYSIZE(cursorChangeMask); ++i) {
|
|
|
|
if (event.customType == cursorChangeMask[i].action) {
|
|
|
|
return cursorChangeMask[i].mask;
|
|
|
|
}
|
2020-10-26 00:13:54 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 Input::processCustomEngineEventEnd(const Common::Event &event) {
|
|
|
|
actionStates[event.customType] = 0;
|
2020-11-21 14:27:49 +01:00
|
|
|
for (int i = 0; i < ARRAYSIZE(cursorChangeMask); ++i) {
|
|
|
|
if (event.customType == cursorChangeMask[i].action) {
|
|
|
|
return cursorChangeMask[i].mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2020-10-26 00:13:54 +01:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:09:33 +02:00
|
|
|
void Input::readKeys() {
|
2020-11-21 13:37:56 +01:00
|
|
|
cursorKeyMask = 0;
|
2020-10-23 13:38:02 +02:00
|
|
|
Common::Event event;
|
|
|
|
while (g_system->getEventManager()->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_CUSTOM_ENGINE_ACTION_END:
|
2020-11-21 14:01:44 +01:00
|
|
|
cursorKeyMask |= processCustomEngineEventEnd(event);
|
2020-10-23 13:38:02 +02:00
|
|
|
break;
|
|
|
|
case Common::EVENT_CUSTOM_ENGINE_ACTION_START:
|
2020-11-21 13:37:56 +01:00
|
|
|
cursorKeyMask |= processCustomEngineEventStart(event);
|
2020-10-23 13:38:02 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-23 13:44:38 +02:00
|
|
|
void Input::getMousePositions(MouseStatusStruct *mouseData) {
|
|
|
|
Common::Point point = g_system->getEventManager()->getMousePos();
|
|
|
|
mouseData->x = point.x;
|
|
|
|
mouseData->y = point.y;
|
|
|
|
}
|
2020-10-23 13:38:02 +02:00
|
|
|
|
2020-11-17 22:39:41 +01:00
|
|
|
bool Input::isMouseHovering(int32 left, int32 top, int32 right, int32 bottom) const {
|
|
|
|
Common::Point point = g_system->getEventManager()->getMousePos();
|
|
|
|
return point.x >= left && point.x <= right && point.y >= top && point.y <= bottom;
|
|
|
|
}
|
|
|
|
|
2020-10-23 13:44:38 +02:00
|
|
|
} // namespace TwinE
|