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