27 titleLabel->SetSize(400, 30);
29 titleLabel->ApplyAlignment();
32 titleLabel->GetPosition(labelX, labelY);
33 titleLabel->SetPosition(labelX, 15);
34 titleLabel->SetBackgroundColor(0x00000000);
35 titleLabel->SetHoverColor(0x00000000);
36 titleLabel->SetText(
"Key Bindings");
37 titleLabel->SetTextSize(22);
38 titleLabel->SetTextColor(0xFFFFFFFF);
39 titleLabel->SetFont(-1);
40 _menu->AddButton(titleLabel);
44 instructionsLabel->SetSize(500, 20);
46 instructionsLabel->ApplyAlignment();
47 instructionsLabel->GetPosition(labelX, labelY);
48 instructionsLabel->SetPosition(labelX, 50);
49 instructionsLabel->SetBackgroundColor(0x00000000);
50 instructionsLabel->SetHoverColor(0x00000000);
51 instructionsLabel->SetText(
"Click a key to remap. Press ESC to cancel.");
52 instructionsLabel->SetTextSize(14);
53 instructionsLabel->SetTextColor(0xFFAAAAAA);
54 instructionsLabel->SetFont(-1);
55 _menu->AddButton(instructionsLabel);
78 startY + rowHeight *
static_cast<float>(rowIndex++));
80 startY + rowHeight *
static_cast<float>(rowIndex++));
84 float bottomY = startY + rowHeight *
static_cast<float>(rowIndex) + 15;
89 0xFF505050, 0xFF707070, [
this]() {
90 Input::KeyBindings::getInstance().ResetToDefaults();
92 if (_onBindingsChanged) {
96 _resetButton->SetPosition(_graphics.GetWindowWidth() / 2.0f - 200, bottomY);
97 _menu->AddButton(_resetButton);
100 _backButton = CreateCenteredButton(
"Back", bottomY - (_graphics.GetWindowHeight() / 2.0f), 120, 40,
101 0xFF404040, 0xFF606060, [
this]() {
106 _backButton->SetPosition(_graphics.GetWindowWidth() / 2.0f + 80, bottomY);
107 _menu->AddButton(_backButton);
112 float centerX =
static_cast<float>(_graphics.GetWindowWidth()) / 2.0f;
115 std::shared_ptr<UI::IButton> actionLabel = _uiFactory.CreateButton();
116 actionLabel->SetSize(150, 28);
117 actionLabel->SetPosition(centerX - 280, yOffset);
118 actionLabel->SetBackgroundColor(0x00000000);
119 actionLabel->SetHoverColor(0x00000000);
121 actionLabel->SetTextSize(16);
122 actionLabel->SetTextColor(0xFFFFFFFF);
123 actionLabel->SetFont(-1);
124 _menu->AddButton(actionLabel);
127 std::shared_ptr<UI::IButton> primaryButton = _uiFactory.CreateButton();
128 primaryButton->SetSize(120, 28);
129 primaryButton->SetPosition(centerX - 100, yOffset);
130 primaryButton->SetBackgroundColor(0xFF404040);
131 primaryButton->SetHoverColor(0xFF606060);
133 primaryButton->SetTextSize(14);
134 primaryButton->SetTextColor(0xFFFFFFFF);
135 primaryButton->SetFont(-1);
136 primaryButton->SetCallback([
this, action]() { StartKeyCapture(action,
true); });
137 _menu->AddButton(primaryButton);
140 std::shared_ptr<UI::IButton> secondaryButton = _uiFactory.CreateButton();
141 secondaryButton->SetSize(120, 28);
142 secondaryButton->SetPosition(centerX + 40, yOffset);
143 secondaryButton->SetBackgroundColor(0xFF404040);
144 secondaryButton->SetHoverColor(0xFF606060);
145 int secondaryBinding = bindings.GetSecondaryKey(action);
146 secondaryButton->SetText(
148 secondaryButton->SetTextSize(14);
149 secondaryButton->SetTextColor(0xFFCCCCCC);
150 secondaryButton->SetFont(-1);
151 secondaryButton->SetCallback([
this, action]() { StartKeyCapture(action,
false); });
152 _menu->AddButton(secondaryButton);
155 std::shared_ptr<UI::IButton> clearButton = _uiFactory.CreateButton();
156 clearButton->SetSize(30, 28);
157 clearButton->SetPosition(centerX + 170, yOffset);
158 clearButton->SetBackgroundColor(0xFF603030);
159 clearButton->SetHoverColor(0xFF804040);
160 clearButton->SetText(
"X");
161 clearButton->SetTextSize(14);
162 clearButton->SetTextColor(0xFFFFFFFF);
163 clearButton->SetFont(-1);
164 clearButton->SetCallback([
this, action]() {
166 UpdateBindingButtonText(action,
false);
167 if (_onBindingsChanged) {
168 _onBindingsChanged();
171 _menu->AddButton(clearButton);
174 _bindingButtons[action] = {primaryButton, secondaryButton};
177 void KeyBindingsMenu::Update() {
178 if (!_menu || !_menu->IsVisible()) {
185 if (_graphics.IsKeyPressed(KEY_ESCAPE)) {
191 for (
int gp = 0; gp < 4; ++gp) {
192 if (_graphics.IsGamepadAvailable(gp)) {
193 for (
int button = 0; button <= GAMEPAD_BUTTON_RIGHT_THUMB; ++button) {
194 if (_graphics.IsGamepadButtonPressed(gp, button)) {
197 HandleCapturedKey(binding);
205 for (
int key = KEY_SPACE; key <= KEY_KP_EQUAL; ++key) {
206 if (_graphics.IsKeyPressed(key)) {
207 HandleCapturedKey(key);
212 for (
int key = KEY_A; key <= KEY_Z; ++key) {
213 if (_graphics.IsKeyPressed(key)) {
214 HandleCapturedKey(key);
226 void KeyBindingsMenu::Render() {
227 if (!_menu || !_menu->IsVisible()) {
232 if (_mode == Mode::OVERLAY) {
233 _graphics.DrawRectFilled(0, 0, _graphics.GetWindowWidth(), _graphics.GetWindowHeight(),
242 _graphics.DrawRectFilled(0, 0, _graphics.GetWindowWidth(), _graphics.GetWindowHeight(),
248 int boxX = (_graphics.GetWindowWidth() - boxWidth) / 2;
249 int boxY = (_graphics.GetWindowHeight() - boxHeight) / 2;
251 _graphics.DrawRectFilled(boxX, boxY, boxWidth, boxHeight, 0xFF303030);
252 _graphics.DrawRect(boxX, boxY, boxWidth, boxHeight, 0xFF4080FF);
255 std::string slotName = _capturePrimary ?
"Primary" :
"Secondary";
256 std::string msg =
"Press a key for: " + actionName +
" (" + slotName +
")";
258 _graphics.DrawText(msg.c_str(), boxX + 20, boxY + 30, 18, 0xFFFFFFFF);
259 _graphics.DrawText(
"Press ESC to cancel", boxX + 120, boxY + 60, 14, 0xFFAAAAAA);
299 auto it = _bindingButtons.find(action);
300 if (it == _bindingButtons.end()) {
306 if (isPrimary && it->second.primaryButton) {
307 it->second.primaryButton->SetText(
309 }
else if (!isPrimary && it->second.secondaryButton) {
310 int secondaryBinding = bindings.GetSecondaryKey(action);
311 it->second.secondaryButton->SetText(