1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_CLIENT_COMPONENTS_BINDS_H
4#define GAME_CLIENT_COMPONENTS_BINDS_H
5
6#include <engine/console.h>
7#include <engine/keys.h>
8
9#include <game/client/component.h>
10
11class IConfigManager;
12
13class CBinds : public CComponent
14{
15 int GetKeyId(const char *pKeyName);
16
17 static void ConBind(IConsole::IResult *pResult, void *pUserData);
18 static void ConBinds(IConsole::IResult *pResult, void *pUserData);
19 static void ConUnbind(IConsole::IResult *pResult, void *pUserData);
20 static void ConUnbindAll(IConsole::IResult *pResult, void *pUserData);
21 class IConsole *GetConsole() const { return Console(); }
22
23 static void ConfigSaveCallback(IConfigManager *pConfigManager, void *pUserData);
24
25public:
26 CBinds();
27 ~CBinds();
28 virtual int Sizeof() const override { return sizeof(*this); }
29
30 class CBindsSpecial : public CComponent
31 {
32 public:
33 CBinds *m_pBinds;
34 virtual int Sizeof() const override { return sizeof(*this); }
35 virtual bool OnInput(const IInput::CEvent &Event) override;
36 };
37
38 bool m_MouseOnAction;
39
40 enum
41 {
42 MODIFIER_NONE = 0,
43 MODIFIER_CTRL,
44 MODIFIER_ALT,
45 MODIFIER_SHIFT,
46 MODIFIER_GUI,
47 MODIFIER_COUNT,
48 MODIFIER_COMBINATION_COUNT = 1 << MODIFIER_COUNT
49 };
50
51 CBindsSpecial m_SpecialBinds;
52
53 void Bind(int KeyId, const char *pStr, bool FreeOnly = false, int ModifierCombination = MODIFIER_NONE);
54 void SetDefaults();
55 void UnbindAll();
56 const char *Get(int KeyId, int ModifierCombination);
57 void GetKey(const char *pBindStr, char *pBuf, size_t BufSize);
58 int GetBindSlot(const char *pBindString, int *pModifierCombination);
59 static int GetModifierMask(IInput *pInput);
60 static int GetModifierMaskOfKey(int Key);
61 static const char *GetModifierName(int Modifier);
62 static const char *GetKeyBindModifiersName(int ModifierCombination);
63
64 virtual void OnConsoleInit() override;
65 virtual bool OnInput(const IInput::CEvent &Event) override;
66
67 // DDRace
68
69 void SetDDRaceBinds(bool FreeOnly);
70
71private:
72 char *m_aapKeyBindings[MODIFIER_COMBINATION_COUNT][KEY_LAST];
73};
74#endif
75