3
* Copyright (C) 2012-2013 The ManaPlus Developers
5
* This file is part of The ManaPlus Client.
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 2 of the License, or
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.
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/>.
21
#ifndef INPUT_INPUTMANAGER_H
22
#define INPUT_INPUTMANAGER_H
24
#include "input/inputevent.h"
25
#include "input/keydata.h"
30
#include <SDL_events.h>
32
const unsigned int KeyFunctionSize = 3;
34
// hack to avoid conflicts with windows headers.
58
KeyItem(const int type0, const int value0) :
59
type(type0), value(value0)
67
struct KeyFunction final
69
KeyItem values[KeyFunctionSize];
74
COND_DEFAULT = 1, // default condition
75
COND_ENABLED = 2, // keyboard must be enabled
76
COND_NOINPUT = 4, // input items must be unfocused
77
COND_NOAWAY = 8, // player not in away mode
78
COND_NOSETUP = 16, // setup window is hidde
79
COND_VALIDSPEED = 32, // valid speed
80
COND_NOMODAL = 64, // modal windows inactive
81
COND_NONPCINPUT = 128, // npc input field inactive
82
COND_EMODS = 256, // game modifiers enabled
83
COND_NOTARGET = 512, // no target/untarget keys
85
COND_NOFOLLOW = 1024, // follow mode disabled
86
COND_INGAME = 2048, // game must be started
87
COND_SHORTCUT = 2 + 4 + 16 + 512 + 2048, // flags for shortcut keys
88
COND_SHORTCUT0 = 2 + 4 + 16 + 512, // flags for shortcut keys
89
COND_GAME = 2 + 4 + 8 + 16 + 64 + 2048, // main game key
90
COND_GAME2 = 2 + 8 + 16 + 64 + 2048
93
class InputManager final
98
A_DELETE_COPY(InputManager)
102
bool handleEvent(const SDL_Event &event);
104
bool checkKey(const KeyData *const key) const A_WARN_UNUSED;
112
void makeDefault(const int i);
114
bool hasConflicts(int &key1, int &key2) const A_WARN_UNUSED;
116
void callbackNewKey();
118
KeyFunction &getKey(int index) A_WARN_UNUSED;
120
std::string getKeyValueString(const int index) const A_WARN_UNUSED;
122
std::string getKeyStringLong(const int index) const A_WARN_UNUSED;
124
std::string getKeyValueByName(const std::string &keyName);
126
void addActionKey(const int action, const int type, const int val);
128
void setNewKey(const SDL_Event &event, const int type);
132
static bool isActionActive(const int index) A_WARN_UNUSED;
135
* Set the index of the new key to be assigned.
137
void setNewKeyIndex(const int value)
138
{ mNewKeyIndex = value; }
141
* Set a reference to the key setup window.
143
void setSetupInput(Setup_Input *const setupInput)
144
{ mSetupInput = setupInput; }
147
* Get the index of the new key to be assigned.
149
int getNewKeyIndex() const A_WARN_UNUSED
150
{ return mNewKeyIndex; }
152
void updateKeyActionMap(KeyToActionMap &actionMap,
153
KeyToIdMap &idMap, KeyTimeMap &keyTimeMap,
154
const int type) const;
156
bool invokeKey(const KeyData *const key, const int keyNum);
158
bool handleAssignKey(const SDL_Event &event, const int type);
160
void handleRepeat() const;
162
bool triggerAction(const KeysVector *const ptrs);
164
int getKeyIndex(const int value, const int grp,
165
const int type) const A_WARN_UNUSED;
169
void updateConditionMask();
171
int getActionByKey(const SDL_Event &event) const A_WARN_UNUSED;
173
void executeAction(const int keyNum);
176
Setup_Input *mSetupInput; /**< Reference to setup window */
178
int mNewKeyIndex; /**< Index of new key to be assigned */
182
std::map<std::string, int> mNameMap;
184
KeyFunction mKey[Input::KEY_TOTAL]; /**< Pointer to all the key data */
187
extern InputManager inputManager;
189
#endif // INPUT_INPUTMANAGER_H