ScummVM API documentation
input.h
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 modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (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, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef HARVESTER_INPUT_H
23#define HARVESTER_INPUT_H
24
25#include "common/array.h"
26#include "common/error.h"
27#include "common/events.h"
28#include "common/rect.h"
29#include "common/str.h"
30
31namespace Harvester {
32
33class Art;
34class CheatSystem;
35class DialogueSystem;
36class Entity;
37class Flow;
38class HarvesterEngine;
39class InventorySystem;
40class Interaction;
41class ItemInteractions;
42class Scene;
43struct CheatActivation;
44struct InteractionResult;
45struct InventorySecondaryAction;
46struct MenuTextConfig;
47struct NpcRecord;
48struct ObjectRecord;
49struct RegionRecord;
50struct ResolvedText;
51struct RoomHoverState;
52struct RoomPresentationState;
53struct RoomSetupState;
54struct SceneState;
55
56enum GameAction {
57 kActionMoveLeft,
58 kActionMoveRight,
59 kActionMoveUp,
60 kActionMoveDown,
61 kActionAttackModifier,
62 kActionEvasiveModifier,
63 kActionSpeedUp,
64 kActionInventory,
65 kActionMenu,
66 kActionHelp,
67 kActionHighAttack,
68 kActionMediumAttack,
69 kActionLowAttack,
70 kActionDuck,
71 kActionJump
72};
73
74struct InputState {
75 bool moveLeft = false;
76 bool moveRight = false;
77 bool moveUp = false;
78 bool moveDown = false;
79 bool attackModifierHeld = false;
80 bool evasiveModifierHeld = false;
81 bool speedUpActive = false;
82 bool highAttackHeld = false;
83 bool mediumAttackHeld = false;
84 bool lowAttackHeld = false;
85 bool duckHeld = false;
86 bool jumpHeld = false;
87 uint32 lastLeftButtonReleaseTick = 0;
88 uint32 nextKeyboardAttackAllowedTick = 0;
89
90 void clearHeldActions() {
91 moveLeft = moveRight = moveUp = moveDown = false;
92 attackModifierHeld = evasiveModifierHeld = speedUpActive = false;
93 highAttackHeld = mediumAttackHeld = lowAttackHeld = duckHeld = jumpHeld = false;
94 }
95};
96
97// Enter and closeup exits return from runRoomLoop even when the error is kNoError.
99 Common::Error error;
100 bool returnFromRoom = false;
101
102 static InputResult leaveRoom(const Common::Error &error) {
103 InputResult result;
104 result.error = error;
105 result.returnFromRoom = true;
106 return result;
107 }
108};
109
110class Input {
111public:
112 Input(HarvesterEngine &engine, Flow &flow, Scene &session, SceneState &scene,
113 InventorySystem &inventory, CheatSystem &cheats,
114 ItemInteractions &roomItems, Interaction &interactionProcessor,
115 RoomPresentationState &presentationState,
116 const Art &art, bool canExitCloseupToParent);
117
118 InputResult handleEvent(const Common::Event &event, bool &needsRedraw);
119
120 static const ObjectRecord *findRoomObjectAtPoint(HarvesterEngine &engine,
121 const Common::Array<ObjectRecord> &sceneObjects, const Common::Point &point);
122 static RoomHoverState resolveRoomHoverState(HarvesterEngine &engine, const RoomSetupState &state,
123 const Common::Array<ObjectRecord> &sceneObjects,
124 const Common::Array<NpcRecord> &npcs,
125 const Common::Array<RegionRecord> &regions,
126 const Common::Point &mousePos, const MenuTextConfig &menuTextConfig,
127 const DialogueSystem *dialogue = nullptr);
128
129private:
130 void handleMouseMove(bool &needsRedraw);
131 InputResult handleRightButtonDown(bool &needsRedraw);
132 void handleLeftButtonUp();
133 InputResult handleLeftButtonDown(bool &needsRedraw);
134 InputResult handleSceneClick(bool isFastExitClick, bool &needsRedraw);
135 InputResult handleSelectedItemClick(const RoomHoverState &clickHoverState,
136 const Entity *itemTarget, bool &needsRedraw);
137 InputResult handleSceneTargetClick(const RoomHoverState &hoverState,
138 bool isFastExitClick, bool &needsRedraw);
139 InputResult handleWalkClick(const RoomHoverState &hoverState, bool &needsRedraw);
140 InputResult handleObjectClick(ObjectRecord &object, bool &needsRedraw);
141 InputResult handleInventoryLeftClick(bool &needsRedraw);
142 InputResult handleInventoryRightClick(bool &needsRedraw);
143 InputResult applyInventorySecondaryAction(const ObjectRecord &object,
144 const InventorySecondaryAction &secondaryAction, bool &needsRedraw);
145 InputResult handleInventoryKeyDown(const Common::KeyState &key, bool &needsRedraw);
146 InputResult handleKeyDown(const Common::KeyState &key, bool &needsRedraw, bool gameAction = false);
147 InputResult handleGameplayKeyDown(const Common::KeyState &key, bool &needsRedraw, bool gameAction);
148 void handleKeyUp(const Common::KeyState &key, bool gameAction = false);
149 InputResult handleGameAction(GameAction action, bool pressed, bool &needsRedraw);
150 InputResult applyCheatActivation(InteractionResult &cheatInteraction,
151 const CheatActivation &cheatActivation, bool &needsRedraw);
152 InputResult openRoomMenu(bool &needsRedraw);
153 InputResult openHelpScreen(bool &needsRedraw);
154 void beginInspectText(const ObjectRecord &object, const ResolvedText &text);
155 InputResult finishInspectText(bool &needsRedraw);
156 InputResult applyObjectInteraction(InteractionResult &interaction, bool &needsRedraw);
157 void queueCombatLoadoutStatusMessage(const Common::String &message, bool &needsRedraw);
158 bool openInventoryOverlay();
159 void capturePlayerAttackTarget();
160
161 HarvesterEngine &_engine;
162 Flow &_flow;
163 Scene &_session;
164 SceneState &_scene;
165 InventorySystem &_inventory;
166 CheatSystem &_cheats;
167 ItemInteractions &_roomItems;
168 Interaction &_interactionProcessor;
169 RoomPresentationState &_presentationState;
170 const Art &_art;
171 bool _canExitCloseupToParent;
172 Common::String _pendingInspectObjectName;
173 bool _inspectDismissPressed = false;
174};
175
176} // End of namespace Harvester
177
178#endif // HARVESTER_INPUT_H
Definition: array.h:52
Definition: error.h:81
Definition: str.h:59
Definition: art.h:35
Definition: cheats.h:52
Definition: dialogue.h:44
Definition: entity.h:66
Definition: flow.h:45
Definition: harvester.h:47
Definition: input.h:110
Definition: interaction.h:104
Definition: inventory.h:54
Definition: interaction.h:63
Definition: scene.h:62
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: events.h:218
Definition: keyboard.h:294
Definition: rect.h:144
Definition: cheats.h:44
Definition: input.h:98
Definition: input.h:74
Definition: script.h:311
Definition: inventory.h:49
Definition: menu.h:45
Definition: script.h:86
Definition: script.h:306
Definition: room_support.h:57
Definition: room_presentation.h:51
Definition: script.h:237
Definition: room_support.h:46