ManaPlus
inputmanager.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2012-2019 The ManaPlus Developers
4  * Copyright (C) 2019-2021 Andrei Karas
5  *
6  * This file is part of The ManaPlus Client.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef INPUT_INPUTMANAGER_H
23 #define INPUT_INPUTMANAGER_H
24 
25 #include "input/inputfunction.h"
26 
27 #include "events/inputevent.h"
28 
29 #include "utils/cast.h"
30 #include "utils/stringmap.h"
31 
32 #include <list>
33 
34 PRAGMA48(GCC diagnostic push)
35 PRAGMA48(GCC diagnostic ignored "-Wshadow")
36 #include <SDL_events.h>
37 PRAGMA48(GCC diagnostic pop)
38 
39 class Setup_Input;
40 
41 struct InputActionData;
42 
43 typedef std::map<std::string, InputActionT> StringInpActionMap;
44 typedef StringInpActionMap::const_iterator StringInpActionMapCIter;
45 
47 {
48  public:
49  InputManager();
50 
52 
53  void init() restrict2;
54 
55  bool handleEvent(const SDL_Event &restrict event) restrict2;
56 
57  bool checkKey(const InputActionData *restrict const key) const
59 
60  void retrieve() restrict2;
61 
62  void store() const restrict2;
63 
64  void resetKeys() restrict2;
65 
66  void makeDefault(const InputActionT i) restrict2;
67 
69  InputActionT &restrict key2) const
71 
73 
75  restrict2 A_CONST A_WARN_UNUSED;
76 
77  std::string getKeyValueString(const InputActionT index)
79 
80  std::string getKeyStringLong(const InputActionT index)
82 
83  std::string getKeyValueByName(const std::string &restrict keyName)
84  restrict2;
85 
86  std::string getKeyValueByNameLong(const std::string &restrict keyName)
87  restrict2;
88 
89  void addActionKey(const InputActionT action,
90  const InputTypeT type,
91  const int val) restrict2;
92 
93  void setNewKey(const SDL_Event &event,
94  const InputTypeT type) restrict2;
95 
96  void unassignKey() restrict2;
97 
98  bool isActionActive(const InputActionT index) const
100 
105  { mNewKeyIndex = value; }
106 
110  void setSetupInput(Setup_Input *restrict const setupInput)
112  { mSetupInput = setupInput; }
113 
118  { return mNewKeyIndex; }
119 
121  KeyToIdMap &restrict idMap,
122  KeyTimeMap &restrict keyTimeMap,
123  const InputTypeT type) const restrict2;
124 
125  bool invokeKey(const InputActionData *restrict const key,
126  const InputActionT keyNum) restrict2;
127 
128  bool handleAssignKey(const SDL_Event &restrict event,
129  const InputTypeT type) restrict2;
130 
131  static void handleRepeat();
132 
133  bool triggerAction(const KeysVector *restrict const ptrs) restrict2;
134 
135  InputActionT getKeyIndex(const int value,
136  const int grp,
137  const InputTypeT type) const
139 
140  static void update();
141 
142  void updateConditionMask(const bool pressed) restrict2;
143 
144  InputActionT getActionByKey(const SDL_Event &restrict event)
145  const restrict2 A_WARN_UNUSED;
146 
147  static InputActionT getActionByConfigField(const std::string &field);
148 
149  void executeAction(const InputActionT keyNum) restrict2;
150 
151  bool executeChatCommand(const std::string &restrict cmd,
152  const std::string &restrict args,
153  ChatTab *restrict const tab) restrict2;
154 
155  bool executeRemoteChatCommand(const std::string &restrict cmd,
156  const std::string &restrict args,
157  ChatTab *restrict const tab) restrict2;
158 
159  bool executeChatCommand(const InputActionT keyNum,
160  const std::string &restrict args,
161  ChatTab *restrict const tab) restrict2;
162 
163  static void addChatCommands(std::list<std::string> &restrict arr);
164 
165  protected:
166  void resetKey(const InputActionT i) restrict2;
167 
168  static bool isActionActive0(const InputActionT index) A_WARN_UNUSED;
169 
170  void updateKeyString(const InputFunction &ki,
171  const size_t actionIdx) restrict2;
172 
177 
178  int mMask;
179 
182 
185 };
186 
188 
189 #endif // INPUT_INPUTMANAGER_H
#define CAST_SIZE
Definition: cast.h:34
static void addChatCommands(std::list< std::string > &arr)
void executeAction(const InputActionT keyNum)
void updateConditionMask(const bool pressed)
static void update()
static InputActionT getActionByConfigField(const std::string &field)
void updateKeyString(const InputFunction &ki, const size_t actionIdx)
StringInpActionMap mNameMap
Definition: inputmanager.h:180
void updateKeyActionMap(KeyToActionMap &actionMap, KeyToIdMap &idMap, KeyTimeMap &keyTimeMap, const InputTypeT type) const
bool checkKey(const InputActionData *const key) const
InputActionT getKeyIndex(const int value, const int grp, const InputTypeT type) const
std::string mKeyStr[static_cast< size_t >(InputAction::TOTAL)]
Definition: inputmanager.h:184
bool executeRemoteChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)
bool handleAssignKey(const SDL_Event &event, const InputTypeT type)
void store() const
void setSetupInput(Setup_Input *const setupInput)
Definition: inputmanager.h:110
void unassignKey()
StringIntMap mChatMap
Definition: inputmanager.h:181
InputFunction mKey[static_cast< size_t >(InputAction::TOTAL)]
Definition: inputmanager.h:183
InputFunction & getKey(InputActionT index) A_CONST
bool handleEvent(const SDL_Event &event)
InputActionT getNewKeyIndex() const
Definition: inputmanager.h:117
InputActionT getActionByKey(const SDL_Event &event) const
Setup_Input * mSetupInput
Definition: inputmanager.h:174
void resetKey(const InputActionT i)
void setNewKey(const SDL_Event &event, const InputTypeT type)
std::string getKeyValueByNameLong(const std::string &keyName)
static void handleRepeat()
void callbackNewKey()
std::string getKeyValueByName(const std::string &keyName)
std::string getKeyStringLong(const InputActionT index) const
bool hasConflicts(InputActionT &key1, InputActionT &key2) const
static bool isActionActive0(const InputActionT index)
bool triggerAction(const KeysVector *const ptrs)
InputActionT mNewKeyIndex
Definition: inputmanager.h:176
bool invokeKey(const InputActionData *const key, const InputActionT keyNum)
bool executeChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)
bool isActionActive(const InputActionT index) const
void makeDefault(const InputActionT i)
void addActionKey(const InputActionT action, const InputTypeT type, const int val)
std::string getKeyValueString(const InputActionT index) const
void setNewKeyIndex(const InputActionT value)
Definition: inputmanager.h:104
InputAction ::T InputActionT
Definition: inputaction.h:717
std::map< int, KeysVector > KeyToActionMap
Definition: inputevent.h:40
std::map< int, InputActionT > KeyToIdMap
Definition: inputevent.h:43
std::vector< InputActionT > KeysVector
Definition: inputevent.h:34
std::map< int, int > KeyTimeMap
Definition: inputevent.h:46
InputManager inputManager
std::map< std::string, InputActionT > StringInpActionMap
Definition: inputmanager.h:41
StringInpActionMap::const_iterator StringInpActionMapCIter
Definition: inputmanager.h:44
InputType ::T InputTypeT
Definition: inputtype.h:42
#define restrict
Definition: localconsts.h:165
#define restrict2
Definition: localconsts.h:166
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define PRAGMA48(str)
Definition: localconsts.h:199
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
std::map< std::string, int > StringIntMap
Definition: stringmap.h:28