R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
Game::MainMenu Class Reference

Main menu of the game. More...

#include <MainMenu.hpp>

Inheritance diagram for Game::MainMenu:
Inheritance graph
Collaboration diagram for Game::MainMenu:
Collaboration graph

Public Member Functions

 MainMenu (UI::IUIFactory &uiFactory)
 
 ~MainMenu () override=default
 
void SetOnQuit (std::function< void()> onQuit)
 Set callback triggered when the Quit button is clicked.
 
void SetOnSettings (std::function< void()> onSettings)
 Set callback triggered when the Settings button is clicked.
 
void SetOnPlay (std::function< void()> onPlay)
 Set callback triggered when the Play button is clicked.
 
void SetOnProfile (std::function< void()> onProfile)
 Set callback triggered when the Profile/Guest button is clicked.
 
void SetOnSelectServer (std::function< void()> onSelectServer)
 Set callback triggered when the Select Server button is clicked.
 
void SetProfileName (const std::string &name)
 Update the text of the Profile button (e.g. "GUEST" -> "PlayerName").
 
void SetScreenSize (float width, float height)
 Set screen size for layout calculations.
 
void Initialize () override
 Initialize menu (must be implemented by derived classes).
 
void Show () override
 Show the menu and play the open sound effect.
 
- Public Member Functions inherited from Game::BaseMenu
 BaseMenu (UI::IUIFactory &uiFactory)
 Constructor with UI factory reference.
 
virtual ~BaseMenu ()=default
 Virtual destructor.
 
virtual void Update ()
 Update menu state (should be called every frame).
 
virtual void Render ()
 Render menu (should be called every frame).
 
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

void OnPlayClicked ()
 
void OnQuitClicked ()
 
void OnSettingsClicked ()
 
void OnProfileClicked ()
 
void OnSelectServerClicked ()
 

Private Attributes

std::function< void()> _onPlay {}
 
std::function< void()> _onQuit {}
 
std::function< void()> _onSettings {}
 
std::function< void()> _onProfile {}
 
std::function< void()> _onSelectServer {}
 
std::shared_ptr< UI::IButton_profileButton
 
std::shared_ptr< UI::IButton_selectServerButton
 
float _screenWidth = 800.0f
 
float _screenHeight = 600.0f
 

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::IButtonCreateCenteredButton (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}
 

Detailed Description

Main menu of the game.

Business-level class: it uses the UI library, but does not belong to it.

Definition at line 22 of file MainMenu.hpp.

Constructor & Destructor Documentation

◆ MainMenu()

Game::MainMenu::MainMenu ( UI::IUIFactory uiFactory)
explicit

Definition at line 12 of file MainMenu.cpp.

◆ ~MainMenu()

Game::MainMenu::~MainMenu ( )
overridedefault

Member Function Documentation

◆ Initialize()

void Game::MainMenu::Initialize ( )
overridevirtual

◆ OnPlayClicked()

void Game::MainMenu::OnPlayClicked ( )
private

Definition at line 97 of file MainMenu.cpp.

References _onPlay, and LOG_INFO.

Referenced by Initialize().

◆ OnProfileClicked()

void Game::MainMenu::OnProfileClicked ( )
private

Definition at line 121 of file MainMenu.cpp.

References _onProfile, and LOG_INFO.

Referenced by Initialize().

◆ OnQuitClicked()

void Game::MainMenu::OnQuitClicked ( )
private

Definition at line 112 of file MainMenu.cpp.

References _onQuit, LOG_INFO, and LOG_WARNING.

Referenced by Initialize().

◆ OnSelectServerClicked()

void Game::MainMenu::OnSelectServerClicked ( )
private

Definition at line 128 of file MainMenu.cpp.

References _onSelectServer, and LOG_INFO.

Referenced by Initialize().

◆ OnSettingsClicked()

void Game::MainMenu::OnSettingsClicked ( )
private

Definition at line 105 of file MainMenu.cpp.

References _onSettings, and LOG_INFO.

Referenced by Initialize().

◆ SetOnPlay()

void Game::MainMenu::SetOnPlay ( std::function< void()>  onPlay)

Set callback triggered when the Play button is clicked.

Definition at line 22 of file MainMenu.cpp.

References _onPlay.

◆ SetOnProfile()

void Game::MainMenu::SetOnProfile ( std::function< void()>  onProfile)

Set callback triggered when the Profile/Guest button is clicked.

Definition at line 26 of file MainMenu.cpp.

References _onProfile.

◆ SetOnQuit()

void Game::MainMenu::SetOnQuit ( std::function< void()>  onQuit)

Set callback triggered when the Quit button is clicked.

This keeps the menu class in the business layer (no direct dependency on Graphics/window APIs).

Definition at line 14 of file MainMenu.cpp.

References _onQuit.

◆ SetOnSelectServer()

void Game::MainMenu::SetOnSelectServer ( std::function< void()>  onSelectServer)

Set callback triggered when the Select Server button is clicked.

Definition at line 30 of file MainMenu.cpp.

References _onSelectServer.

◆ SetOnSettings()

void Game::MainMenu::SetOnSettings ( std::function< void()>  onSettings)

Set callback triggered when the Settings button is clicked.

Definition at line 18 of file MainMenu.cpp.

References _onSettings.

◆ SetProfileName()

void Game::MainMenu::SetProfileName ( const std::string &  name)

Update the text of the Profile button (e.g. "GUEST" -> "PlayerName").

Definition at line 34 of file MainMenu.cpp.

References _profileButton.

◆ SetScreenSize()

void Game::MainMenu::SetScreenSize ( float  width,
float  height 
)

Set screen size for layout calculations.

Definition at line 40 of file MainMenu.cpp.

References _screenHeight, and _screenWidth.

◆ Show()

void Game::MainMenu::Show ( )
overridevirtual

Show the menu and play the open sound effect.

Reimplemented from Game::BaseMenu.

Definition at line 45 of file MainMenu.cpp.

References Game::BaseMenu::_soundService, Audio::ISoundEffectService::PlayMainMenuOpenSound(), and Game::BaseMenu::Show().

Here is the call graph for this function:

Member Data Documentation

◆ _onPlay

std::function<void()> Game::MainMenu::_onPlay {}
private

Definition at line 78 of file MainMenu.hpp.

Referenced by OnPlayClicked(), and SetOnPlay().

◆ _onProfile

std::function<void()> Game::MainMenu::_onProfile {}
private

Definition at line 81 of file MainMenu.hpp.

Referenced by OnProfileClicked(), and SetOnProfile().

◆ _onQuit

std::function<void()> Game::MainMenu::_onQuit {}
private

Definition at line 79 of file MainMenu.hpp.

Referenced by OnQuitClicked(), and SetOnQuit().

◆ _onSelectServer

std::function<void()> Game::MainMenu::_onSelectServer {}
private

Definition at line 82 of file MainMenu.hpp.

Referenced by OnSelectServerClicked(), and SetOnSelectServer().

◆ _onSettings

std::function<void()> Game::MainMenu::_onSettings {}
private

Definition at line 80 of file MainMenu.hpp.

Referenced by OnSettingsClicked(), and SetOnSettings().

◆ _profileButton

std::shared_ptr<UI::IButton> Game::MainMenu::_profileButton
private

Definition at line 84 of file MainMenu.hpp.

Referenced by Initialize(), and SetProfileName().

◆ _screenHeight

float Game::MainMenu::_screenHeight = 600.0f
private

Definition at line 88 of file MainMenu.hpp.

Referenced by SetScreenSize().

◆ _screenWidth

float Game::MainMenu::_screenWidth = 800.0f
private

Definition at line 87 of file MainMenu.hpp.

Referenced by SetScreenSize().

◆ _selectServerButton

std::shared_ptr<UI::IButton> Game::MainMenu::_selectServerButton
private

Definition at line 85 of file MainMenu.hpp.


The documentation for this class was generated from the following files: