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 /*
23  * This code is based on the CRAB engine
24  *
25  * Copyright (c) Arvind Raja Yadav
26  *
27  * Licensed under MIT
28  *
29  */
30 
31 #ifndef CRAB_INPUT_H
32 #define CRAB_INPUT_H
33 
34 #include "backends/keymapper/action.h"
35 #include "backends/keymapper/keymapper.h"
37 
38 namespace Crab {
39 
40 namespace pyrodactyl {
41 namespace input {
42 enum InputType {
43  IT_NONE = -1,
44 
45  // Game related input values
46  IG_UP,
47  IG_DOWN,
48  IG_RIGHT,
49  IG_LEFT,
50  IG_TALK,
51  IG_MAP,
52  IG_JOURNAL,
53  IG_INVENTORY,
54  IG_CHARACTER,
55  IG_PAUSE,
56  IG_QUICKSAVE,
57  IG_QUICKLOAD,
58  IG_ATTACK,
59  IG_BLOCK,
60 
61  // UI related input values
62  IU_UP,
63  IU_DOWN,
64  IU_RIGHT,
65  IU_LEFT,
66  IU_ACCEPT,
67  IU_BACK,
68  IU_NEXT,
69  IU_PREV,
70  IU_REPLY_0,
71  IU_REPLY_1,
72  IU_REPLY_2,
73  IU_REPLY_3,
74  IU_REPLY_4,
75  IU_REPLY_5,
76  IU_PAGE_NEXT,
77  IU_PAGE_PREV,
78 
79  IT_TOTAL
80 };
81 
82 enum KeyBindingMode {
83  KBM_NONE = 0,
84  KBM_GAME = 1,
85  KBM_UI = 2
86 };
87 
88 // Constants related to menu size
89 const int IG_START = IG_UP, IG_SIZE = IG_BLOCK - IG_START + 1;
90 const int IU_START = IU_UP, IU_SIZE = IT_TOTAL - IU_START;
91 
92 class InputManager {
93  // Load key configuration from file
94  void load(const Common::String &filename);
95 
96  // The current version of the input scheme
97  uint _version;
98 
99  // The current mode of keymap applied
100  KeyBindingMode _keyMode;
101 
102  // The keybinds in string format for hotkeys and other places
103  Common::String _keyDescs[IT_TOTAL];
104 
105 public:
106  InputManager() {
107  _version = 0;
108  _keyMode = KBM_GAME;
109 
110  clearInputs();
111  }
112 
113  ~InputManager() {}
114 
115  static Common::Keymap *getDefaultKeyMapsForGame();
116  static Common::Keymap *getDefaultKeyMapsForUI();
117  static Common::Keymap *getDefaultKeyMapsForHUD();
118 
119  void clearInputs() {
120  for (int i = 0; i < IT_TOTAL; i++)
121  _ivState[i] = false;
122  }
123 
124  void populateKeyTable();
125 
126  void setKeyBindingMode(KeyBindingMode mode);
127 
128  KeyBindingMode getKeyBindingMode() const {
129  return _keyMode;
130  }
131 
132  // NOTE: The lower level arrays can have buttons in common, but buttons cannot be common within these arrays
133  // Ex. UI and Fight can have buttons in common, but not two keys within UI
134 
135  // Inputs used in the game
136  Common::String _iv[IT_TOTAL];
137  bool _ivState[IT_TOTAL];
138 
139  // These functions return true if key is pressed, false otherwise
140  bool state(const InputType &val);
141 
142  Common::String getAssociatedKey(const InputType &type);
143 
144  // Save and flush the keymaps to disk
145  void save();
146 };
147 
148 } // End of namespace input
149 } // End of namespace pyrodactyl
150 
151 } // End of namespace Crab
152 
153 #endif // CRAB_INPUT_H
Definition: keymap.h:66
Definition: str.h:59
A set of well known keymapper actions.
Definition: moveeffect.h:37