1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #ifndef TWINE_KEYBOARD_H
24 #define TWINE_KEYBOARD_H
25
26 #include "common/events.h"
27 #include "common/keyboard.h"
28 #include "common/scummsys.h"
29 #include "common/util.h"
30 #include "common/rect.h"
31
32 namespace TwinE {
33
34 class TwinEEngine;
35
36 extern const char *mainKeyMapId;
37 extern const char *uiKeyMapId;
38 extern const char *cutsceneKeyMapId;
39 extern const char *holomapKeyMapId;
40
41 enum TwinEActionType {
42 Pause,
43 NextRoom,
44 PreviousRoom,
45 ApplyCellingGrid,
46 IncreaseCellingGridIndex,
47 DecreaseCellingGridIndex,
48 DebugGridCameraPressUp,
49 DebugGridCameraPressDown,
50 DebugGridCameraPressLeft,
51 DebugGridCameraPressRight,
52 DebugPlaceActorAtCenterOfScreen,
53 DebugMenu,
54 DebugMenuActivate,
55 QuickBehaviourNormal,
56 QuickBehaviourAthletic,
57 QuickBehaviourAggressive,
58 QuickBehaviourDiscreet,
59 ChangeBehaviourNormal,
60 ChangeBehaviourAthletic,
61 ChangeBehaviourAggressive,
62 ChangeBehaviourDiscreet,
63 ExecuteBehaviourAction,
64 BehaviourMenu,
65 OptionsMenu,
66 RecenterScreenOnTwinsen,
67 UseSelectedObject,
68 ThrowMagicBall,
69 MoveForward,
70 MoveBackward,
71 TurnRight,
72 TurnLeft,
73 UseProtoPack,
74 OpenHolomap,
75 InventoryMenu,
76 SpecialAction,
77 Escape,
78
79 UIEnter,
80 UIAbort,
81 UILeft,
82 UIRight,
83 UIUp,
84 UIDown,
85 UINextPage,
86
87 CutsceneAbort,
88
89 HolomapAbort,
90 HolomapLeft,
91 HolomapRight,
92 HolomapUp,
93 HolomapDown,
94 HolomapNext,
95 HolomapPrev,
96
97 Max
98 };
99
100 /**
101 * @brief Activates the given key map id that is registered in the meta engine
102 */
103 class ScopedKeyMap {
104 private:
105 TwinEEngine* _engine;
106 bool _changed;
107 Common::String _keymap;
108 public:
109 ScopedKeyMap(TwinEEngine* engine, const char *id);
110 ~ScopedKeyMap();
111 };
112
113 class Input {
114 private:
115 TwinEEngine *_engine;
116 Common::String _currentKeyMap;
117
118 uint8 _actionStates[TwinEActionType::Max]{false};
119 public:
120 Input(TwinEEngine *engine);
121
122 /**
123 * @brief Dependent on the context we are currently in the game, we might want to disable certain keymaps.
124 * Like disabling ui keymaps when we are in-game - or vice versa.
125 */
126 void enableKeyMap(const char *id);
127 bool enableAdditionalKeyMap(const char *id, bool enable);
128
129 const Common::String currentKeyMap() const;
130
131 /**
132 * @param onlyFirstTime If this is set to @c true, repeating key press events are not taken into account here
133 * This means, that even if the key is held down, this will return @c false. @c false as value for this parameter
134 * will return @c true also for repeating key presses.
135 *
136 * @sa isPressed()
137 */
138 bool isActionActive(TwinEActionType actionType, bool onlyFirstTime = true) const;
139
140 bool isMouseHovering(const Common::Rect &rect) const;
141
142 /**
143 * @brief If the action is active, the internal state is reset and a following call of this method won't return
144 * @c true anymore
145 */
146 bool toggleActionIfActive(TwinEActionType actionType);
147
148 bool toggleAbortAction();
149
150 bool isQuickBehaviourActionActive() const;
151 bool isMoveOrTurnActionActive() const;
152 bool isHeroActionActive() const;
153 bool resetHeroActions();
154
155 /**
156 * Gets mouse positions
157 * @param mouseData structure that contains mouse position info
158 */
159 Common::Point getMousePositions() const;
160
161 /**
162 * @brief Updates the internal action states
163 */
164 void readKeys();
165 void processCustomEngineEventStart(const Common::Event& event);
166 void processCustomEngineEventEnd(const Common::Event& event);
167 };
168
currentKeyMap()169 inline const Common::String Input::currentKeyMap() const {
170 return _currentKeyMap;
171 }
172
173 } // namespace TwinE
174
175 #endif
176