ManaPlus
src
input
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
46
class
InputManager
final
47
{
48
public
:
49
InputManager
();
50
51
A_DELETE_COPY
(
InputManager
)
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
58
restrict2
A_WARN_UNUSED
;
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
68
bool
hasConflicts
(
InputActionT
&
restrict
key1,
69
InputActionT
&
restrict
key2)
const
70
restrict2
A_WARN_UNUSED
;
71
72
void
callbackNewKey
()
restrict2
;
73
74
InputFunction
&
getKey
(
InputActionT
index)
75
restrict2
A_CONST
A_WARN_UNUSED
;
76
77
std::string
getKeyValueString
(
const
InputActionT
index)
78
const
restrict2
A_WARN_UNUSED
;
79
80
std::string
getKeyStringLong
(
const
InputActionT
index)
81
const
restrict2
A_WARN_UNUSED
;
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
99
restrict2
A_WARN_UNUSED
;
100
104
void
setNewKeyIndex
(
const
InputActionT
value)
restrict2
noexcept2
105
{
mNewKeyIndex
= value; }
106
110
void
setSetupInput
(
Setup_Input
*
restrict
const
setupInput)
111
restrict2
noexcept2
A_NONNULL
(2)
112
{
mSetupInput
= setupInput; }
113
117
InputActionT
getNewKeyIndex
() const
restrict2
noexcept2
A_WARN_UNUSED
118
{
return
mNewKeyIndex
; }
119
120
void
updateKeyActionMap
(
KeyToActionMap
&
restrict
actionMap,
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
138
restrict2
A_WARN_UNUSED
;
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
174
Setup_Input
*
mSetupInput
A_NONNULLPOINTER
;
176
InputActionT
mNewKeyIndex
;
177
178
int
mMask
;
179
180
StringInpActionMap
mNameMap
;
181
StringIntMap
mChatMap
;
182
183
InputFunction
mKey
[
CAST_SIZE
(
InputAction::TOTAL
)];
184
std::string
mKeyStr
[
CAST_SIZE
(
InputAction::TOTAL
)];
185
};
186
187
extern
InputManager
inputManager
;
188
189
#endif
// INPUT_INPUTMANAGER_H
cast.h
CAST_SIZE
#define CAST_SIZE
Definition:
cast.h:34
ChatTab
Definition:
chattab.h:63
InputManager
Definition:
inputmanager.h:47
InputManager::addChatCommands
static void addChatCommands(std::list< std::string > &arr)
Definition:
inputmanager.cpp:1082
InputManager::resetKeys
void resetKeys()
Definition:
inputmanager.cpp:294
InputManager::executeAction
void executeAction(const InputActionT keyNum)
Definition:
inputmanager.cpp:884
InputManager::updateConditionMask
void updateConditionMask(const bool pressed)
Definition:
inputmanager.cpp:761
InputManager::update
static void update()
Definition:
inputmanager.cpp:116
InputManager::getActionByConfigField
static InputActionT getActionByConfigField(const std::string &field)
Definition:
inputmanager.cpp:1071
InputManager::mMask
int mMask
Definition:
inputmanager.h:178
InputManager::updateKeyString
void updateKeyString(const InputFunction &ki, const size_t actionIdx)
Definition:
inputmanager.cpp:439
InputManager::mNameMap
StringInpActionMap mNameMap
Definition:
inputmanager.h:180
InputManager::updateKeyActionMap
void updateKeyActionMap(KeyToActionMap &actionMap, KeyToIdMap &idMap, KeyTimeMap &keyTimeMap, const InputTypeT type) const
Definition:
inputmanager.cpp:961
InputManager::checkKey
bool checkKey(const InputActionData *const key) const
Definition:
inputmanager.cpp:857
InputManager::getKeyIndex
InputActionT getKeyIndex(const int value, const int grp, const InputTypeT type) const
Definition:
inputmanager.cpp:1034
InputManager::init
void init()
Definition:
inputmanager.cpp:90
InputManager::mKeyStr
std::string mKeyStr[static_cast< size_t >(InputAction::TOTAL)]
Definition:
inputmanager.h:184
InputManager::executeRemoteChatCommand
bool executeRemoteChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)
Definition:
inputmanager.cpp:922
InputManager::handleAssignKey
bool handleAssignKey(const SDL_Event &event, const InputTypeT type)
Definition:
inputmanager.cpp:576
InputManager::store
void store() const
Definition:
inputmanager.cpp:195
InputManager::setSetupInput
void setSetupInput(Setup_Input *const setupInput)
Definition:
inputmanager.h:110
InputManager::unassignKey
void unassignKey()
Definition:
inputmanager.cpp:562
InputManager::mChatMap
StringIntMap mChatMap
Definition:
inputmanager.h:181
InputManager::mKey
InputFunction mKey[static_cast< size_t >(InputAction::TOTAL)]
Definition:
inputmanager.h:183
InputManager::getKey
InputFunction & getKey(InputActionT index) A_CONST
Definition:
inputmanager.cpp:388
InputManager::handleEvent
bool handleEvent(const SDL_Event &event)
Definition:
inputmanager.cpp:598
InputManager::getNewKeyIndex
InputActionT getNewKeyIndex() const
Definition:
inputmanager.h:117
InputManager::getActionByKey
InputActionT getActionByKey(const SDL_Event &event) const
Definition:
inputmanager.cpp:1055
InputManager::mSetupInput
Setup_Input * mSetupInput
Definition:
inputmanager.h:174
InputManager::resetKey
void resetKey(const InputActionT i)
Definition:
inputmanager.cpp:253
InputManager::setNewKey
void setNewKey(const SDL_Event &event, const InputTypeT type)
Definition:
inputmanager.cpp:546
InputManager::getKeyValueByNameLong
std::string getKeyValueByNameLong(const std::string &keyName)
Definition:
inputmanager.cpp:501
InputManager::handleRepeat
static void handleRepeat()
Definition:
inputmanager.cpp:753
InputManager::callbackNewKey
void callbackNewKey()
Definition:
inputmanager.cpp:358
InputManager::getKeyValueByName
std::string getKeyValueByName(const std::string &keyName)
Definition:
inputmanager.cpp:491
InputManager::getKeyStringLong
std::string getKeyStringLong(const InputActionT index) const
Definition:
inputmanager.cpp:395
InputManager::hasConflicts
bool hasConflicts(InputActionT &key1, InputActionT &key2) const
Definition:
inputmanager.cpp:309
InputManager::isActionActive0
static bool isActionActive0(const InputActionT index)
Definition:
inputmanager.cpp:379
InputManager::InputManager
InputManager()
Definition:
inputmanager.cpp:80
InputManager::triggerAction
bool triggerAction(const KeysVector *const ptrs)
Definition:
inputmanager.cpp:1014
InputManager::mNewKeyIndex
InputActionT mNewKeyIndex
Definition:
inputmanager.h:176
InputManager::invokeKey
bool invokeKey(const InputActionData *const key, const InputActionT keyNum)
Definition:
inputmanager.cpp:868
InputManager::executeChatCommand
bool executeChatCommand(const std::string &cmd, const std::string &args, ChatTab *const tab)
Definition:
inputmanager.cpp:898
InputManager::isActionActive
bool isActionActive(const InputActionT index) const
Definition:
inputmanager.cpp:365
InputManager::retrieve
void retrieve()
Definition:
inputmanager.cpp:123
InputManager::makeDefault
void makeDefault(const InputActionT i)
Definition:
inputmanager.cpp:300
InputManager::addActionKey
void addActionKey(const InputActionT action, const InputTypeT type, const int val)
Definition:
inputmanager.cpp:511
InputManager::getKeyValueString
std::string getKeyValueString(const InputActionT index) const
Definition:
inputmanager.cpp:485
InputManager::setNewKeyIndex
void setNewKeyIndex(const InputActionT value)
Definition:
inputmanager.h:104
Setup_Input
Definition:
setup_input.h:41
InputActionT
InputAction ::T InputActionT
Definition:
inputaction.h:717
inputevent.h
KeyToActionMap
std::map< int, KeysVector > KeyToActionMap
Definition:
inputevent.h:40
KeyToIdMap
std::map< int, InputActionT > KeyToIdMap
Definition:
inputevent.h:43
KeysVector
std::vector< InputActionT > KeysVector
Definition:
inputevent.h:34
KeyTimeMap
std::map< int, int > KeyTimeMap
Definition:
inputevent.h:46
inputfunction.h
inputManager
InputManager inputManager
Definition:
inputmanager.cpp:69
StringInpActionMap
std::map< std::string, InputActionT > StringInpActionMap
Definition:
inputmanager.h:41
StringInpActionMapCIter
StringInpActionMap::const_iterator StringInpActionMapCIter
Definition:
inputmanager.h:44
InputTypeT
InputType ::T InputTypeT
Definition:
inputtype.h:42
restrict
#define restrict
Definition:
localconsts.h:165
restrict2
#define restrict2
Definition:
localconsts.h:166
A_WARN_UNUSED
#define A_WARN_UNUSED
Definition:
localconsts.h:161
A_NONNULL
#define A_NONNULL(...)
Definition:
localconsts.h:168
A_NONNULLPOINTER
#define A_NONNULLPOINTER
Definition:
localconsts.h:266
noexcept2
#define noexcept2
Definition:
localconsts.h:50
final
#define final
Definition:
localconsts.h:46
PRAGMA48
#define PRAGMA48(str)
Definition:
localconsts.h:199
A_DELETE_COPY
#define A_DELETE_COPY(func)
Definition:
localconsts.h:53
InputAction::TOTAL
@ TOTAL
Definition:
inputaction.h:715
stringmap.h
StringIntMap
std::map< std::string, int > StringIntMap
Definition:
stringmap.h:28
InputActionData
Definition:
inputactiondata.h:35
InputFunction
Definition:
inputfunction.h:32
Generated on Wed Mar 17 2021 19:19:08 for ManaPlus by
1.9.1