R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
SettingsMenu.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2026
3** r-type
4** File description:
5** SettingsMenu - Settings menu (business logic)
6*/
7
8#pragma once
9
10#include <functional>
11#include <memory>
12
14#include "Menu/BaseMenu.hpp"
15#include "UI/ISlider.hpp"
16#include "UI/IUIFactory.hpp"
17
18namespace Game {
25 class SettingsMenu : public BaseMenu {
26 public:
30 enum class Mode {
32 OVERLAY
33 };
34
40 explicit SettingsMenu(UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics);
41 ~SettingsMenu() override = default;
42
46 void Initialize() override;
47
48 void Update() override;
49 void Render() override;
50
54 void SetMode(Mode mode);
55 [[nodiscard]] Mode GetMode() const;
56
60 void SetShowPing(bool enabled);
61
66 void SetAutoMatchmaking(bool enabled);
67
72 void ApplyAutoMatchmakingPreference(bool enabled);
73
74 [[nodiscard]] bool GetAutoMatchmaking() const;
75 void SetOnAutoMatchmakingChanged(std::function<void(bool)> cb);
76 [[nodiscard]] bool GetShowPing() const;
77
82 void SetOnShowPingChanged(std::function<void(bool)> cb);
83
87 void SetOnBack(std::function<void()> cb);
88
94 void SetOnMainMenu(std::function<void()> cb);
95
99 void SetOnAccessibility(std::function<void()> cb);
100
105 void SetOverlayDimColor(unsigned int color);
106
111 [[nodiscard]] unsigned int GetOverlayDimColor() const;
112
117 [[nodiscard]] bool ShouldDimBackground() const;
118
122 void SetShowFps(bool enabled);
123 [[nodiscard]] bool GetShowFps() const;
124
129 void SetOnShowFpsChanged(std::function<void(bool)> cb);
130
136 void SetTargetFps(uint32_t targetFps);
137
141 [[nodiscard]] uint32_t GetTargetFps() const;
142
146 void SetOnTargetFpsChanged(std::function<void(uint32_t)> callback);
147
154 void RefreshVisuals();
155
161 void SetShowPingSilent(bool enabled);
162
166 void SetShowFpsSilent(bool enabled);
167
171 void SetTargetFpsSilent(uint32_t targetFps);
172
176 void SetVolume(float volume);
177
181 [[nodiscard]] float GetVolume() const;
182
186 void SetOnVolumeChanged(std::function<void(float)> callback);
187
191 void SetVolumeSilent(float volume);
192
197 void SetShowChat(bool enabled);
198
203 bool GetShowChat() const;
204
209 void SetOnShowChatChanged(std::function<void(bool)> cb);
210
215 void SetShowChatSilent(bool enabled);
216
221
222 private:
223 [[nodiscard]] uint32_t ValidateTargetFps(uint32_t targetFps) const;
224 void UpdateToggleVisuals();
228 [[nodiscard]] uint32_t NextTargetFps(uint32_t current) const;
229
231 std::unique_ptr<UI::ISlider> _volumeSlider;
232
234 bool _showPing{true};
235 bool _showFps{true};
236 bool _showChat{false}; // Désactivé par défaut
237 bool _autoMatchmaking{false}; // Auto-matchmaking disabled by default
238 unsigned int _overlayDimColor{0x88000000};
239 uint32_t _targetFps{60};
240 float _volume{50.0F}; // Default volume 50%
241
242 std::function<void(bool)> _onShowPingChanged{};
243 std::function<void()> _onBack{};
244 std::function<void()> _onMainMenu{};
245 std::function<void()> _onAccessibility{};
246 std::function<void(bool)> _onShowFpsChanged{};
247 std::function<void(bool)> _onShowChatChanged{};
248 std::function<void(uint32_t)> _onTargetFpsChanged{};
249 std::function<void(float)> _onVolumeChanged{};
250 std::function<void(bool)> _onAutoMatchmakingChanged{};
251
252 static constexpr size_t TOGGLE_PING_INDEX = 0;
253 static constexpr size_t TOGGLE_FPS_INDEX = 1;
254 static constexpr size_t TOGGLE_CHAT_INDEX = 2;
255 static constexpr size_t AUTO_MATCHMAKING_INDEX = 3;
256 static constexpr size_t TARGET_FPS_INDEX = 4;
257 static constexpr size_t ACCESSIBILITY_INDEX = 5;
258 static constexpr size_t BACK_INDEX = 6;
259 static constexpr size_t MAIN_MENU_INDEX = 7;
260 };
261} // namespace Game
Base class for all menu implementations.
Definition BaseMenu.hpp:26
Settings menu of the game.
void SetShowFps(bool enabled)
Toggle whether FPS should be displayed.
void Initialize() override
Initialize UI elements.
void SetTargetFpsSilent(uint32_t targetFps)
Set targetFps without emitting callbacks/logs.
void SetOnShowFpsChanged(std::function< void(bool)> cb)
Set callback invoked when the FPS toggle changes.
bool GetShowPing() const
bool GetAutoMatchmaking() const
void SetShowChat(bool enabled)
Set chat visibility.
uint32_t GetTargetFps() const
Get the target FPS for the client.
void SetTargetFps(uint32_t targetFps)
Set the target FPS for the client.
void SetAutoMatchmaking(bool enabled)
Toggle auto-matchmaking feature. This triggers the callback to notify the server.
std::function< void(bool)> _onAutoMatchmakingChanged
unsigned int GetOverlayDimColor() const
Get the dim color used when this menu is displayed in overlay mode.
void SetOverlayDimColor(unsigned int color)
Set the dim color used when this menu is displayed in overlay mode.
std::function< void(bool)> _onShowPingChanged
void SetShowPingSilent(bool enabled)
Set showPing without emitting callbacks/logs.
static constexpr size_t AUTO_MATCHMAKING_INDEX
void SetShowPing(bool enabled)
Toggle whether ping should be displayed.
bool GetShowChat() const
Get chat visibility.
void SetShowChatSilent(bool enabled)
Set chat visibility without emitting callbacks/logs.
void UpdateAutoMatchmakingVisuals()
unsigned int _overlayDimColor
void RefreshVisuals()
Refresh button labels/colors to match current internal state.
Graphics::IGraphics & _graphics
static constexpr size_t ACCESSIBILITY_INDEX
void SetVolume(float volume)
Set the volume level (0-100).
void SetVolumeSilent(float volume)
Set volume without emitting callbacks/logs.
~SettingsMenu() override=default
static constexpr size_t BACK_INDEX
void SetMode(Mode mode)
Set display mode (fullscreen or overlay).
static constexpr size_t TOGGLE_FPS_INDEX
static constexpr size_t TOGGLE_PING_INDEX
void SetOnShowPingChanged(std::function< void(bool)> cb)
Set callback invoked when the ping toggle changes.
std::unique_ptr< UI::ISlider > _volumeSlider
std::function< void()> _onMainMenu
float GetVolume() const
Get the current volume level.
void SetOnShowChatChanged(std::function< void(bool)> cb)
Set callback invoked when the chat visibility changes.
void UpdateChatToggleVisuals()
Updates the visuals of the chat toggle button.
void Render() override
Render menu (should be called every frame).
void ApplyAutoMatchmakingPreference(bool enabled)
Apply auto-matchmaking preference silently (without triggering callback). Used when loading preferenc...
uint32_t NextTargetFps(uint32_t current) const
static constexpr size_t TARGET_FPS_INDEX
void SetShowFpsSilent(bool enabled)
Set showFps without emitting callbacks/logs.
uint32_t ValidateTargetFps(uint32_t targetFps) const
void SetOnTargetFpsChanged(std::function< void(uint32_t)> callback)
Set callback invoked when the target FPS changes.
std::function< void()> _onAccessibility
void SetOnAutoMatchmakingChanged(std::function< void(bool)> cb)
void SetOnAccessibility(std::function< void()> cb)
Set callback invoked when "Accessibility" button is clicked.
void Update() override
Update menu state (should be called every frame).
std::function< void(bool)> _onShowFpsChanged
bool ShouldDimBackground() const
Whether the background should be dimmed when the menu is visible.
void SetOnBack(std::function< void()> cb)
Set callback invoked when Back is clicked.
std::function< void()> _onBack
Mode
Display mode for the settings menu.
@ OVERLAY
Displays over the game with a dimmed background.
@ FULLSCREEN
Takes the whole window (main menu context)
bool GetShowFps() const
static constexpr size_t TOGGLE_CHAT_INDEX
std::function< void(uint32_t)> _onTargetFpsChanged
std::function< void(bool)> _onShowChatChanged
void SetOnVolumeChanged(std::function< void(float)> callback)
Set callback invoked when the volume changes.
static constexpr size_t MAIN_MENU_INDEX
std::function< void(float)> _onVolumeChanged
void SetOnMainMenu(std::function< void()> cb)
Set callback invoked when "Main Menu" is clicked.
Abstract interface for graphics rendering operations.
Definition IGraphics.hpp:32
Abstract factory interface for creating UI elements.