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_MENUS_SETTINGS_CONTROLS_H
4#define GAME_CLIENT_COMPONENTS_MENUS_SETTINGS_CONTROLS_H
5
6#include <game/client/component.h>
7#include <game/client/components/binds.h>
8#include <game/client/lineinput.h>
9#include <game/client/ui.h>
10#include <game/client/ui_scrollregion.h>
11
12#include <vector>
13
14enum class EBindOptionGroup
15{
16 MOVEMENT,
17 WEAPON,
18 VOTING,
19 CHAT,
20 DUMMY,
21 MISCELLANEOUS,
22 CUSTOM,
23 NUM,
24};
25
26class CBindSlotUiElement
27{
28public:
29 CBindSlot m_Bind;
30 CButtonContainer m_KeyReaderButton;
31 CButtonContainer m_KeyResetButton;
32 bool m_ToBeDeleted = false;
33
34 bool operator<(const CBindSlotUiElement &Other) const;
35};
36
37class CBindOption
38{
39public:
40 EBindOptionGroup m_Group;
41 const char *m_pLabel;
42 std::string m_Command;
43 std::vector<CBindSlotUiElement> m_vCurrentBinds;
44 CButtonContainer m_AddBindButtonContainer;
45 char m_TooltipButtonId;
46 bool m_AddNewBind = false;
47 bool m_AddNewBindActivate = false;
48 bool m_ToBeDeleted = false;
49
50 std::vector<CBindSlotUiElement>::iterator GetBindSlotElement(const CBindSlot &BindSlot);
51 bool MatchesSearch(const char *pSearch) const;
52};
53
54class CMenusSettingsControls : public CComponentInterfaces
55{
56public:
57 void OnInterfacesInit(CGameClient *pClient) override;
58 void Render(CUIRect MainView);
59
60private:
61 bool m_aBindGroupExpanded[(int)EBindOptionGroup::NUM];
62 CButtonContainer m_aBindGroupExpandButtons[(int)EBindOptionGroup::NUM];
63 std::vector<CBindOption> m_vBindOptions;
64 size_t m_NumPredefinedBindOptions;
65 void UpdateBindOptions();
66
67 CScrollRegion m_SettingsScrollRegion;
68 CButtonContainer m_ResetToDefaultButton;
69 CLineInputBuffered<128> m_FilterInput;
70 int m_CurrentSearchMatch = 0;
71 std::vector<int> m_vSearchMatches;
72 bool m_SearchMatchReveal = false;
73 void UpdateSearchMatches();
74
75 void RenderSettingsBlock(float Height, CUIRect *pParentRect, const char *pTitle,
76 bool *pExpanded, CButtonContainer *pExpandButton, const std::function<void(CUIRect Rect)> &RenderContentFunction);
77
78 void RenderSettingsBindsBlock(EBindOptionGroup Group, CUIRect *pParentRect, const char *pTitle);
79 float MeasureSettingsBindsHeight(EBindOptionGroup Group) const;
80 void RenderSettingsBinds(EBindOptionGroup Group, CUIRect View);
81
82 float MeasureSettingsMouseHeight() const;
83 void RenderSettingsMouse(CUIRect View);
84
85 std::vector<CButtonContainer> m_vJoystickIngameModeButtonContainers = {{}, {}};
86 char m_aaJoystickAxisCheckboxIds[NUM_JOYSTICK_AXES][2]; // 2 for X and Y buttons
87 CScrollRegion m_JoystickDropDownScrollRegion;
88 CUi::SDropDownState m_JoystickDropDownState;
89 float MeasureSettingsJoystickHeight() const;
90 void RenderSettingsJoystick(CUIRect View);
91 void RenderJoystickAxisPicker(CUIRect View);
92 void RenderJoystickBar(const CUIRect *pRect, float Current, float Tolerance, bool Active);
93};
94
95#endif
96