|
R-Type
Distributed multiplayer game engine in C++
|
Settings menu of the game. More...
#include <SettingsMenu.hpp>


Public Types | |
| enum class | Mode { FULLSCREEN , OVERLAY } |
| Display mode for the settings menu. More... | |
Public Member Functions | |
| SettingsMenu (UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics) | |
| Construct a new SettingsMenu. | |
| ~SettingsMenu () override=default | |
| void | Initialize () override |
| Initialize UI elements. | |
| void | Update () override |
| Update menu state (should be called every frame). | |
| void | Render () override |
| Render menu (should be called every frame). | |
| void | SetMode (Mode mode) |
| Set display mode (fullscreen or overlay). | |
| Mode | GetMode () const |
| void | SetShowPing (bool enabled) |
| Toggle whether ping should be displayed. | |
| void | SetAutoMatchmaking (bool enabled) |
| Toggle auto-matchmaking feature. This triggers the callback to notify the server. | |
| void | ApplyAutoMatchmakingPreference (bool enabled) |
| Apply auto-matchmaking preference silently (without triggering callback). Used when loading preference from server after login. | |
| bool | GetAutoMatchmaking () const |
| void | SetOnAutoMatchmakingChanged (std::function< void(bool)> cb) |
| bool | GetShowPing () const |
| void | SetOnShowPingChanged (std::function< void(bool)> cb) |
| Set callback invoked when the ping toggle changes. | |
| void | SetOnBack (std::function< void()> cb) |
| Set callback invoked when Back is clicked. | |
| void | SetOnMainMenu (std::function< void()> cb) |
| Set callback invoked when "Main Menu" is clicked. | |
| void | SetOnAccessibility (std::function< void()> cb) |
| Set callback invoked when "Accessibility" button is clicked. | |
| void | SetOverlayDimColor (unsigned int color) |
| Set the dim color used when this menu is displayed in overlay mode. | |
| unsigned int | GetOverlayDimColor () const |
| Get the dim color used when this menu is displayed in overlay mode. | |
| bool | ShouldDimBackground () const |
| Whether the background should be dimmed when the menu is visible. | |
| void | SetShowFps (bool enabled) |
| Toggle whether FPS should be displayed. | |
| bool | GetShowFps () const |
| void | SetOnShowFpsChanged (std::function< void(bool)> cb) |
| Set callback invoked when the FPS toggle changes. | |
| void | SetTargetFps (uint32_t targetFps) |
| Set the target FPS for the client. | |
| uint32_t | GetTargetFps () const |
| Get the target FPS for the client. | |
| void | SetOnTargetFpsChanged (std::function< void(uint32_t)> callback) |
| Set callback invoked when the target FPS changes. | |
| void | RefreshVisuals () |
| Refresh button labels/colors to match current internal state. | |
| void | SetShowPingSilent (bool enabled) |
| Set showPing without emitting callbacks/logs. | |
| void | SetShowFpsSilent (bool enabled) |
| Set showFps without emitting callbacks/logs. | |
| void | SetTargetFpsSilent (uint32_t targetFps) |
| Set targetFps without emitting callbacks/logs. | |
| void | SetVolume (float volume) |
| Set the volume level (0-100). | |
| float | GetVolume () const |
| Get the current volume level. | |
| void | SetOnVolumeChanged (std::function< void(float)> callback) |
| Set callback invoked when the volume changes. | |
| void | SetVolumeSilent (float volume) |
| Set volume without emitting callbacks/logs. | |
| void | SetShowChat (bool enabled) |
| Set chat visibility. | |
| bool | GetShowChat () const |
| Get chat visibility. | |
| void | SetOnShowChatChanged (std::function< void(bool)> cb) |
| Set callback invoked when the chat visibility changes. | |
| void | SetShowChatSilent (bool enabled) |
| Set chat visibility without emitting callbacks/logs. | |
| void | UpdateChatToggleVisuals () |
| Updates the visuals of the chat toggle button. | |
Public Member Functions inherited from Game::BaseMenu | |
| BaseMenu (UI::IUIFactory &uiFactory) | |
| Constructor with UI factory reference. | |
| virtual | ~BaseMenu ()=default |
| Virtual destructor. | |
| virtual void | Show () |
| Show the menu. | |
| virtual void | Hide () |
| Hide the menu. | |
| virtual bool | IsVisible () const |
| Check if menu is currently visible. | |
| void | SetSoundEffectService (Audio::ISoundEffectService *soundService) |
| Set the sound effect service for playing UI sounds. | |
Private Member Functions | |
| uint32_t | ValidateTargetFps (uint32_t targetFps) const |
| void | UpdateToggleVisuals () |
| void | UpdateFpsToggleVisuals () |
| void | UpdateAutoMatchmakingVisuals () |
| void | UpdateTargetFpsVisuals () |
| uint32_t | NextTargetFps (uint32_t current) const |
Private Attributes | |
| Graphics::IGraphics & | _graphics |
| std::unique_ptr< UI::ISlider > | _volumeSlider |
| Mode | _mode {Mode::FULLSCREEN} |
| bool | _showPing {true} |
| bool | _showFps {true} |
| bool | _showChat {false} |
| bool | _autoMatchmaking {false} |
| unsigned int | _overlayDimColor {0x88000000} |
| uint32_t | _targetFps {60} |
| float | _volume {50.0F} |
| std::function< void(bool)> | _onShowPingChanged {} |
| std::function< void()> | _onBack {} |
| std::function< void()> | _onMainMenu {} |
| std::function< void()> | _onAccessibility {} |
| std::function< void(bool)> | _onShowFpsChanged {} |
| std::function< void(bool)> | _onShowChatChanged {} |
| std::function< void(uint32_t)> | _onTargetFpsChanged {} |
| std::function< void(float)> | _onVolumeChanged {} |
| std::function< void(bool)> | _onAutoMatchmakingChanged {} |
Static Private Attributes | |
| static constexpr size_t | TOGGLE_PING_INDEX = 0 |
| static constexpr size_t | TOGGLE_FPS_INDEX = 1 |
| static constexpr size_t | TOGGLE_CHAT_INDEX = 2 |
| static constexpr size_t | AUTO_MATCHMAKING_INDEX = 3 |
| static constexpr size_t | TARGET_FPS_INDEX = 4 |
| static constexpr size_t | ACCESSIBILITY_INDEX = 5 |
| static constexpr size_t | BACK_INDEX = 6 |
| static constexpr size_t | MAIN_MENU_INDEX = 7 |
Additional Inherited Members | |
Protected Member Functions inherited from Game::BaseMenu | |
| std::function< void()> | WrapWithClickSound (std::function< void()> callback) |
| Wrap a callback to play click sound before executing. | |
| std::shared_ptr< UI::IButton > | CreateCenteredButton (const char *label, float offsetY, float width, float height, unsigned int backgroundColor, unsigned int hoverColor, std::function< void()> callback) |
| Create a button with standard styling and positioning. | |
Protected Attributes inherited from Game::BaseMenu | |
| UI::IUIFactory & | _uiFactory |
| std::shared_ptr< UI::IMenu > | _menu |
| Audio::ISoundEffectService * | _soundService {nullptr} |
Settings menu of the game.
Business-level class: it uses the UI library but remains decoupled from the graphics backend.
Definition at line 25 of file SettingsMenu.hpp.
|
strong |
Display mode for the settings menu.
| Enumerator | |
|---|---|
| FULLSCREEN | Takes the whole window (main menu context) |
| OVERLAY | Displays over the game with a dimmed background. |
Definition at line 30 of file SettingsMenu.hpp.
|
explicit |
Construct a new SettingsMenu.
| uiFactory | UI factory used to create menus and buttons. |
| graphics | Graphics interface for rendering slider labels. |
Definition at line 13 of file SettingsMenu.cpp.
References Game::BaseMenu::_uiFactory, _volumeSlider, and UI::IUIFactory::CreateSlider().

|
overridedefault |
| void Game::SettingsMenu::ApplyAutoMatchmakingPreference | ( | bool | enabled | ) |
Apply auto-matchmaking preference silently (without triggering callback). Used when loading preference from server after login.
Definition at line 450 of file SettingsMenu.cpp.
References _autoMatchmaking, LOG_INFO, and UpdateAutoMatchmakingVisuals().

| bool Game::SettingsMenu::GetAutoMatchmaking | ( | ) | const |
Definition at line 459 of file SettingsMenu.cpp.
References _autoMatchmaking.
| SettingsMenu::Mode Game::SettingsMenu::GetMode | ( | ) | const |
Definition at line 183 of file SettingsMenu.cpp.
References _mode.
| unsigned int Game::SettingsMenu::GetOverlayDimColor | ( | ) | const |
Get the dim color used when this menu is displayed in overlay mode.
Definition at line 363 of file SettingsMenu.cpp.
References _overlayDimColor.
| bool Game::SettingsMenu::GetShowChat | ( | ) | const |
Get chat visibility.
Definition at line 406 of file SettingsMenu.cpp.
References _showChat.
| bool Game::SettingsMenu::GetShowFps | ( | ) | const |
Definition at line 225 of file SettingsMenu.cpp.
References _showFps.
| bool Game::SettingsMenu::GetShowPing | ( | ) | const |
Definition at line 196 of file SettingsMenu.cpp.
References _showPing.
| uint32_t Game::SettingsMenu::GetTargetFps | ( | ) | const |
Get the target FPS for the client.
Definition at line 294 of file SettingsMenu.cpp.
References _targetFps.
| float Game::SettingsMenu::GetVolume | ( | ) | const |
|
overridevirtual |
Initialize UI elements.
Implements Game::BaseMenu.
Definition at line 18 of file SettingsMenu.cpp.
References _autoMatchmaking, Game::BaseMenu::_menu, _mode, _onAccessibility, _onBack, _onMainMenu, _onVolumeChanged, _showChat, _showFps, _showPing, _targetFps, _volume, _volumeSlider, UI::CENTER_HORIZONTAL, Game::BaseMenu::CreateCenteredButton(), Game::BaseMenu::Hide(), LOG_INFO, NextTargetFps(), OVERLAY, RefreshVisuals(), SetAutoMatchmaking(), SetShowChat(), SetShowFps(), SetShowPing(), and SetTargetFps().

|
private |
Definition at line 233 of file SettingsMenu.cpp.
Referenced by Initialize().
| void Game::SettingsMenu::RefreshVisuals | ( | ) |
Refresh button labels/colors to match current internal state.
Does not rebuild the menu (no Clear/AddButton). Use this when only the visuals need to reflect updated values.
Definition at line 261 of file SettingsMenu.cpp.
References UpdateAutoMatchmakingVisuals(), UpdateChatToggleVisuals(), UpdateFpsToggleVisuals(), UpdateTargetFpsVisuals(), and UpdateToggleVisuals().
Referenced by Initialize().

|
overridevirtual |
Render menu (should be called every frame).
Reimplemented from Game::BaseMenu.
Definition at line 133 of file SettingsMenu.cpp.
References _graphics, Game::BaseMenu::_menu, _volume, _volumeSlider, Graphics::IGraphics::DrawText(), Graphics::IGraphics::GetScreenWidth(), and Game::BaseMenu::Render().

| void Game::SettingsMenu::SetAutoMatchmaking | ( | bool | enabled | ) |
Toggle auto-matchmaking feature. This triggers the callback to notify the server.
Definition at line 440 of file SettingsMenu.cpp.
References _autoMatchmaking, _onAutoMatchmakingChanged, LOG_INFO, and UpdateAutoMatchmakingVisuals().
Referenced by Initialize().

| void Game::SettingsMenu::SetMode | ( | Mode | mode | ) |
Set display mode (fullscreen or overlay).
Definition at line 179 of file SettingsMenu.cpp.
References _mode.
| void Game::SettingsMenu::SetOnAccessibility | ( | std::function< void()> | cb | ) |
Set callback invoked when "Accessibility" button is clicked.
Definition at line 212 of file SettingsMenu.cpp.
References _onAccessibility.
| void Game::SettingsMenu::SetOnAutoMatchmakingChanged | ( | std::function< void(bool)> | cb | ) |
Definition at line 463 of file SettingsMenu.cpp.
References _onAutoMatchmakingChanged.
| void Game::SettingsMenu::SetOnBack | ( | std::function< void()> | cb | ) |
Set callback invoked when Back is clicked.
Definition at line 204 of file SettingsMenu.cpp.
References _onBack.
| void Game::SettingsMenu::SetOnMainMenu | ( | std::function< void()> | cb | ) |
Set callback invoked when "Main Menu" is clicked.
Intended for the in-game overlay mode.
Definition at line 208 of file SettingsMenu.cpp.
References _onMainMenu.
| void Game::SettingsMenu::SetOnShowChatChanged | ( | std::function< void(bool)> | cb | ) |
Set callback invoked when the chat visibility changes.
| cb | Callback invoked when the chat toggle changes. |
Definition at line 410 of file SettingsMenu.cpp.
References _onShowChatChanged.
| void Game::SettingsMenu::SetOnShowFpsChanged | ( | std::function< void(bool)> | cb | ) |
Set callback invoked when the FPS toggle changes.
| cb | Callback taking the new value. |
Definition at line 229 of file SettingsMenu.cpp.
References _onShowFpsChanged.
| void Game::SettingsMenu::SetOnShowPingChanged | ( | std::function< void(bool)> | cb | ) |
Set callback invoked when the ping toggle changes.
| cb | Callback taking the new value. |
Definition at line 200 of file SettingsMenu.cpp.
References _onShowPingChanged.
| void Game::SettingsMenu::SetOnTargetFpsChanged | ( | std::function< void(uint32_t)> | callback | ) |
Set callback invoked when the target FPS changes.
Definition at line 298 of file SettingsMenu.cpp.
References _onTargetFpsChanged.
| void Game::SettingsMenu::SetOnVolumeChanged | ( | std::function< void(float)> | callback | ) |
Set callback invoked when the volume changes.
Definition at line 386 of file SettingsMenu.cpp.
References _onVolumeChanged.
| void Game::SettingsMenu::SetOverlayDimColor | ( | unsigned int | color | ) |
Set the dim color used when this menu is displayed in overlay mode.
| color | Color in 0xAARRGGBB. |
Definition at line 359 of file SettingsMenu.cpp.
References _overlayDimColor.
| void Game::SettingsMenu::SetShowChat | ( | bool | enabled | ) |
Set chat visibility.
| enabled |
Definition at line 397 of file SettingsMenu.cpp.
References _onShowChatChanged, _showChat, LOG_INFO, and UpdateChatToggleVisuals().
Referenced by Initialize().

| void Game::SettingsMenu::SetShowChatSilent | ( | bool | enabled | ) |
Set chat visibility without emitting callbacks/logs.
| enabled | enable or disable chat visibility silently |
Definition at line 414 of file SettingsMenu.cpp.
References _showChat, and UpdateChatToggleVisuals().

| void Game::SettingsMenu::SetShowFps | ( | bool | enabled | ) |
Toggle whether FPS should be displayed.
Definition at line 216 of file SettingsMenu.cpp.
References _onShowFpsChanged, _showFps, LOG_INFO, and UpdateFpsToggleVisuals().
Referenced by Initialize().

| void Game::SettingsMenu::SetShowFpsSilent | ( | bool | enabled | ) |
Set showFps without emitting callbacks/logs.
Definition at line 274 of file SettingsMenu.cpp.
References _showFps, and UpdateFpsToggleVisuals().

| void Game::SettingsMenu::SetShowPing | ( | bool | enabled | ) |
Toggle whether ping should be displayed.
Definition at line 187 of file SettingsMenu.cpp.
References _onShowPingChanged, _showPing, LOG_INFO, and UpdateToggleVisuals().
Referenced by Initialize().

| void Game::SettingsMenu::SetShowPingSilent | ( | bool | enabled | ) |
Set showPing without emitting callbacks/logs.
Intended for initial state synchronization from the rendering system.
Definition at line 269 of file SettingsMenu.cpp.
References _showPing, and UpdateToggleVisuals().

| void Game::SettingsMenu::SetTargetFps | ( | uint32_t | targetFps | ) |
Set the target FPS for the client.
Expected values: 30, 60, 120, 144, 240.
Definition at line 284 of file SettingsMenu.cpp.
References _onTargetFpsChanged, _targetFps, LOG_INFO, UpdateTargetFpsVisuals(), and ValidateTargetFps().
Referenced by Initialize().

| void Game::SettingsMenu::SetTargetFpsSilent | ( | uint32_t | targetFps | ) |
Set targetFps without emitting callbacks/logs.
Definition at line 279 of file SettingsMenu.cpp.
References _targetFps, UpdateTargetFpsVisuals(), and ValidateTargetFps().

| void Game::SettingsMenu::SetVolume | ( | float | volume | ) |
Set the volume level (0-100).
Definition at line 371 of file SettingsMenu.cpp.
References _onVolumeChanged, _volume, _volumeSlider, and LOG_INFO.
| void Game::SettingsMenu::SetVolumeSilent | ( | float | volume | ) |
Set volume without emitting callbacks/logs.
Definition at line 390 of file SettingsMenu.cpp.
References _volume, and _volumeSlider.
| bool Game::SettingsMenu::ShouldDimBackground | ( | ) | const |
Whether the background should be dimmed when the menu is visible.
Definition at line 367 of file SettingsMenu.cpp.
References _mode, Game::BaseMenu::IsVisible(), and OVERLAY.

|
overridevirtual |
Update menu state (should be called every frame).
Reimplemented from Game::BaseMenu.
Definition at line 126 of file SettingsMenu.cpp.
References Game::BaseMenu::_menu, _volumeSlider, and Game::BaseMenu::Update().

|
private |
Definition at line 467 of file SettingsMenu.cpp.
References _autoMatchmaking, Game::BaseMenu::_menu, and AUTO_MATCHMAKING_INDEX.
Referenced by ApplyAutoMatchmakingPreference(), RefreshVisuals(), and SetAutoMatchmaking().
| void Game::SettingsMenu::UpdateChatToggleVisuals | ( | ) |
Updates the visuals of the chat toggle button.
Definition at line 419 of file SettingsMenu.cpp.
References Game::BaseMenu::_menu, _showChat, and TOGGLE_CHAT_INDEX.
Referenced by RefreshVisuals(), SetShowChat(), and SetShowChatSilent().
|
private |
Definition at line 323 of file SettingsMenu.cpp.
References Game::BaseMenu::_menu, _showFps, and TOGGLE_FPS_INDEX.
Referenced by RefreshVisuals(), SetShowFps(), and SetShowFpsSilent().
|
private |
Definition at line 344 of file SettingsMenu.cpp.
References Game::BaseMenu::_menu, _targetFps, and TARGET_FPS_INDEX.
Referenced by RefreshVisuals(), SetTargetFps(), and SetTargetFpsSilent().
|
private |
Definition at line 302 of file SettingsMenu.cpp.
References Game::BaseMenu::_menu, _showPing, and TOGGLE_PING_INDEX.
Referenced by RefreshVisuals(), SetShowPing(), and SetShowPingSilent().
|
private |
Definition at line 248 of file SettingsMenu.cpp.
Referenced by SetTargetFps(), and SetTargetFpsSilent().
|
private |
Definition at line 237 of file SettingsMenu.hpp.
Referenced by ApplyAutoMatchmakingPreference(), GetAutoMatchmaking(), Initialize(), SetAutoMatchmaking(), and UpdateAutoMatchmakingVisuals().
|
private |
Definition at line 230 of file SettingsMenu.hpp.
Referenced by Render().
|
private |
Definition at line 233 of file SettingsMenu.hpp.
Referenced by GetMode(), Initialize(), SetMode(), and ShouldDimBackground().
|
private |
Definition at line 245 of file SettingsMenu.hpp.
Referenced by Initialize(), and SetOnAccessibility().
|
private |
Definition at line 250 of file SettingsMenu.hpp.
Referenced by SetAutoMatchmaking(), and SetOnAutoMatchmakingChanged().
|
private |
Definition at line 243 of file SettingsMenu.hpp.
Referenced by Initialize(), and SetOnBack().
|
private |
Definition at line 244 of file SettingsMenu.hpp.
Referenced by Initialize(), and SetOnMainMenu().
|
private |
Definition at line 247 of file SettingsMenu.hpp.
Referenced by SetOnShowChatChanged(), and SetShowChat().
|
private |
Definition at line 246 of file SettingsMenu.hpp.
Referenced by SetOnShowFpsChanged(), and SetShowFps().
|
private |
Definition at line 242 of file SettingsMenu.hpp.
Referenced by SetOnShowPingChanged(), and SetShowPing().
|
private |
Definition at line 248 of file SettingsMenu.hpp.
Referenced by SetOnTargetFpsChanged(), and SetTargetFps().
|
private |
Definition at line 249 of file SettingsMenu.hpp.
Referenced by Initialize(), SetOnVolumeChanged(), and SetVolume().
|
private |
Definition at line 238 of file SettingsMenu.hpp.
Referenced by GetOverlayDimColor(), and SetOverlayDimColor().
|
private |
Definition at line 236 of file SettingsMenu.hpp.
Referenced by GetShowChat(), Initialize(), SetShowChat(), SetShowChatSilent(), and UpdateChatToggleVisuals().
|
private |
Definition at line 235 of file SettingsMenu.hpp.
Referenced by GetShowFps(), Initialize(), SetShowFps(), SetShowFpsSilent(), and UpdateFpsToggleVisuals().
|
private |
Definition at line 234 of file SettingsMenu.hpp.
Referenced by GetShowPing(), Initialize(), SetShowPing(), SetShowPingSilent(), and UpdateToggleVisuals().
|
private |
Definition at line 239 of file SettingsMenu.hpp.
Referenced by GetTargetFps(), Initialize(), SetTargetFps(), SetTargetFpsSilent(), and UpdateTargetFpsVisuals().
|
private |
Definition at line 240 of file SettingsMenu.hpp.
Referenced by GetVolume(), Initialize(), Render(), SetVolume(), and SetVolumeSilent().
|
private |
Definition at line 231 of file SettingsMenu.hpp.
Referenced by Initialize(), Render(), SettingsMenu(), SetVolume(), SetVolumeSilent(), and Update().
|
staticconstexprprivate |
Definition at line 257 of file SettingsMenu.hpp.
|
staticconstexprprivate |
Definition at line 255 of file SettingsMenu.hpp.
Referenced by UpdateAutoMatchmakingVisuals().
|
staticconstexprprivate |
Definition at line 258 of file SettingsMenu.hpp.
|
staticconstexprprivate |
Definition at line 259 of file SettingsMenu.hpp.
|
staticconstexprprivate |
Definition at line 256 of file SettingsMenu.hpp.
Referenced by UpdateTargetFpsVisuals().
|
staticconstexprprivate |
Definition at line 254 of file SettingsMenu.hpp.
Referenced by UpdateChatToggleVisuals().
|
staticconstexprprivate |
Definition at line 253 of file SettingsMenu.hpp.
Referenced by UpdateFpsToggleVisuals().
|
staticconstexprprivate |
Definition at line 252 of file SettingsMenu.hpp.
Referenced by UpdateToggleVisuals().