R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
KeyBindingsMenu.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** r-type
4** File description:
5** KeyBindingsMenu - Menu for remapping key bindings
6*/
7
8#pragma once
9
10#include <functional>
11#include <memory>
12#include <string>
13#include <vector>
14
16#include "Input/KeyBindings.hpp"
17#include "Menu/BaseMenu.hpp"
18#include "UI/IUIFactory.hpp"
19
20namespace Game {
21
28 class KeyBindingsMenu : public BaseMenu {
29 public:
33 enum class Mode {
35 OVERLAY
36 };
37
43 explicit KeyBindingsMenu(UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics);
44 ~KeyBindingsMenu() override = default;
45
49 void Initialize() override;
50
51 void Update() override;
52 void Render() override;
53
54 // --- Display Mode ---
55 void SetMode(Mode mode);
56 [[nodiscard]] Mode GetMode() const;
57
58 void SetOverlayDimColor(unsigned int color);
59 [[nodiscard]] unsigned int GetOverlayDimColor() const;
60 [[nodiscard]] bool ShouldDimBackground() const;
61
62 // --- Callbacks ---
63
67 void SetOnBack(std::function<void()> callback);
68
72 void SetOnBindingsChanged(std::function<void()> callback);
73
74 private:
80 void CreateBindingRow(Input::GameAction action, float yOffset);
81
87 void UpdateBindingButtonText(Input::GameAction action, bool isPrimary);
88
94 void StartKeyCapture(Input::GameAction action, bool isPrimary);
95
99 void CancelKeyCapture();
100
105 void HandleCapturedKey(int key);
106
110 void RefreshAllBindings();
111
113
114 // Display mode
116 unsigned int _overlayDimColor{0x80000000}; // Semi-transparent black
117
118 // Callbacks
119 std::function<void()> _onBack;
120 std::function<void()> _onBindingsChanged;
121
122 // Key capture state
123 bool _isCapturing{false};
125 bool _capturePrimary{true};
126
127 // Binding buttons (for updating text)
129 std::shared_ptr<UI::IButton> primaryButton;
130 std::shared_ptr<UI::IButton> secondaryButton;
131 };
132 std::unordered_map<Input::GameAction, BindingButtons> _bindingButtons;
133
134 // UI Elements
135 std::shared_ptr<UI::IButton> _backButton;
136 std::shared_ptr<UI::IButton> _resetButton;
137 };
138
139} // namespace Game
Base class for all menu implementations.
Definition BaseMenu.hpp:26
Menu for viewing and remapping key bindings.
Input::GameAction _captureAction
void CreateBindingRow(Input::GameAction action, float yOffset)
Create a binding row for an action.
unsigned int GetOverlayDimColor() const
void HandleCapturedKey(int key)
Handle a key press during capture mode.
void Render() override
Render menu (should be called every frame).
std::function< void()> _onBindingsChanged
Graphics::IGraphics & _graphics
void Initialize() override
Initialize UI elements.
void Update() override
Update menu state (should be called every frame).
void RefreshAllBindings()
Refresh all binding button texts.
std::function< void()> _onBack
std::shared_ptr< UI::IButton > _backButton
~KeyBindingsMenu() override=default
Mode
Display mode for the menu.
@ OVERLAY
Displays over the game with dimmed background.
@ FULLSCREEN
Takes the whole window.
std::unordered_map< Input::GameAction, BindingButtons > _bindingButtons
void UpdateBindingButtonText(Input::GameAction action, bool isPrimary)
Update the display text for a binding button.
void SetOverlayDimColor(unsigned int color)
void StartKeyCapture(Input::GameAction action, bool isPrimary)
Start listening for a new key press to remap.
void SetOnBindingsChanged(std::function< void()> callback)
Set callback for when bindings are changed.
void SetOnBack(std::function< void()> callback)
Set callback for when back button is pressed.
std::shared_ptr< UI::IButton > _resetButton
void CancelKeyCapture()
Cancel key capture mode.
Abstract interface for graphics rendering operations.
Definition IGraphics.hpp:32
Abstract factory interface for creating UI elements.
GameAction
Enumeration of all bindable game actions.
std::shared_ptr< UI::IButton > secondaryButton
std::shared_ptr< UI::IButton > primaryButton