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

Connection menu for entering player nickname, server IP, and port. More...

#include <ConnectionMenu.hpp>

Inheritance diagram for Game::ConnectionMenu:
Inheritance graph
Collaboration diagram for Game::ConnectionMenu:
Collaboration graph

Public Member Functions

 ConnectionMenu (UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics)
 
 ~ConnectionMenu () override=default
 
void SetOnJoin (std::function< void(const std::string &, const std::string &, const std::string &)> onJoin)
 Set callback triggered when the Join button is clicked.
 
void SetOnBack (std::function< void()> onBack)
 Set callback triggered when the Back button is clicked.
 
void Initialize () override
 Initialize menu (must be implemented by derived classes).
 
void Update () override
 Update menu state (should be called every frame).
 
void Render () override
 Render menu (should be called every frame).
 
- 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 Types

enum class  ErrorField { NONE , NICKNAME , IP , PORT }
 

Private Member Functions

void OnJoinClicked ()
 
void OnBackClicked ()
 
bool ValidateNickname (const std::string &nickname, std::string &errorMsg)
 
bool ValidateIP (const std::string &ip, std::string &errorMsg)
 
bool ValidatePort (const std::string &port, std::string &errorMsg)
 
void ClearError ()
 

Private Attributes

std::function< void(const std::string &, const std::string &, const std::string &)> _onJoin {}
 
std::function< void()> _onBack {}
 
Graphics::IGraphics_graphics
 
std::unique_ptr< UI::ITextInput_nicknameInput
 
std::unique_ptr< UI::ITextInput_ipInput
 
std::unique_ptr< UI::ITextInput_portInput
 
std::string _errorMessage
 
bool _hasError {false}
 
ErrorField _errorField {ErrorField::NONE}
 
float _buttonsY {0.0f}
 
float _buttonHeight {0.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

Connection menu for entering player nickname, server IP, and port.

This menu is displayed when the user clicks "Play" and allows them to:

  • Enter their nickname
  • Enter server IP address
  • Enter server port
  • Join the game (triggers callback with entered values)
  • Go back to main menu

Definition at line 29 of file ConnectionMenu.hpp.

Member Enumeration Documentation

◆ ErrorField

enum class Game::ConnectionMenu::ErrorField
strongprivate
Enumerator
NONE 
NICKNAME 
IP 
PORT 

Definition at line 73 of file ConnectionMenu.hpp.

Constructor & Destructor Documentation

◆ ConnectionMenu()

Game::ConnectionMenu::ConnectionMenu ( UI::IUIFactory uiFactory,
Graphics::IGraphics graphics 
)
explicit

Definition at line 14 of file ConnectionMenu.cpp.

◆ ~ConnectionMenu()

Game::ConnectionMenu::~ConnectionMenu ( )
overridedefault

Member Function Documentation

◆ ClearError()

void Game::ConnectionMenu::ClearError ( )
private

Definition at line 333 of file ConnectionMenu.cpp.

References _errorField, _errorMessage, _hasError, _ipInput, _nicknameInput, _portInput, and NONE.

Referenced by Initialize().

◆ Initialize()

void Game::ConnectionMenu::Initialize ( )
overridevirtual

◆ OnBackClicked()

void Game::ConnectionMenu::OnBackClicked ( )
private

Definition at line 266 of file ConnectionMenu.cpp.

References _onBack, and LOG_INFO.

Referenced by Initialize().

◆ OnJoinClicked()

void Game::ConnectionMenu::OnJoinClicked ( )
private

Definition at line 201 of file ConnectionMenu.cpp.

References _errorField, _errorMessage, _hasError, _ipInput, _nicknameInput, _onJoin, _portInput, IP, LOG_INFO, NICKNAME, PORT, ValidateIP(), ValidateNickname(), and ValidatePort().

Referenced by Initialize().

Here is the call graph for this function:

◆ Render()

void Game::ConnectionMenu::Render ( )
overridevirtual

Render menu (should be called every frame).

Reimplemented from Game::BaseMenu.

Definition at line 164 of file ConnectionMenu.cpp.

References _buttonHeight, _buttonsY, _errorMessage, _graphics, _hasError, _ipInput, Game::BaseMenu::_menu, _nicknameInput, _portInput, Graphics::IGraphics::DrawText(), Graphics::IGraphics::GetScreenWidth(), and Game::BaseMenu::Render().

Here is the call graph for this function:

◆ SetOnBack()

void Game::ConnectionMenu::SetOnBack ( std::function< void()>  onBack)

Set callback triggered when the Back button is clicked.

Definition at line 22 of file ConnectionMenu.cpp.

References _onBack.

◆ SetOnJoin()

void Game::ConnectionMenu::SetOnJoin ( std::function< void(const std::string &, const std::string &, const std::string &)>  onJoin)

Set callback triggered when the Join button is clicked.

Parameters
onJoinCallback receiving (nickname, ip, port) as parameters.

Definition at line 17 of file ConnectionMenu.cpp.

References _onJoin.

◆ Update()

void Game::ConnectionMenu::Update ( )
overridevirtual

Update menu state (should be called every frame).

Reimplemented from Game::BaseMenu.

Definition at line 151 of file ConnectionMenu.cpp.

References _ipInput, _nicknameInput, _portInput, and Game::BaseMenu::Update().

Here is the call graph for this function:

◆ ValidateIP()

bool Game::ConnectionMenu::ValidateIP ( const std::string &  ip,
std::string &  errorMsg 
)
private

Definition at line 285 of file ConnectionMenu.cpp.

Referenced by OnJoinClicked().

◆ ValidateNickname()

bool Game::ConnectionMenu::ValidateNickname ( const std::string &  nickname,
std::string &  errorMsg 
)
private

Definition at line 273 of file ConnectionMenu.cpp.

Referenced by OnJoinClicked().

◆ ValidatePort()

bool Game::ConnectionMenu::ValidatePort ( const std::string &  port,
std::string &  errorMsg 
)
private

Definition at line 304 of file ConnectionMenu.cpp.

Referenced by OnJoinClicked().

Member Data Documentation

◆ _buttonHeight

float Game::ConnectionMenu::_buttonHeight {0.0f}
private

Definition at line 78 of file ConnectionMenu.hpp.

Referenced by Initialize(), and Render().

◆ _buttonsY

float Game::ConnectionMenu::_buttonsY {0.0f}
private

Definition at line 77 of file ConnectionMenu.hpp.

Referenced by Initialize(), and Render().

◆ _errorField

ErrorField Game::ConnectionMenu::_errorField {ErrorField::NONE}
private

Definition at line 74 of file ConnectionMenu.hpp.

Referenced by ClearError(), and OnJoinClicked().

◆ _errorMessage

std::string Game::ConnectionMenu::_errorMessage
private

Definition at line 71 of file ConnectionMenu.hpp.

Referenced by ClearError(), OnJoinClicked(), and Render().

◆ _graphics

Graphics::IGraphics& Game::ConnectionMenu::_graphics
private

Definition at line 63 of file ConnectionMenu.hpp.

Referenced by Render().

◆ _hasError

bool Game::ConnectionMenu::_hasError {false}
private

Definition at line 72 of file ConnectionMenu.hpp.

Referenced by ClearError(), OnJoinClicked(), and Render().

◆ _ipInput

std::unique_ptr<UI::ITextInput> Game::ConnectionMenu::_ipInput
private

Definition at line 67 of file ConnectionMenu.hpp.

Referenced by ClearError(), Initialize(), OnJoinClicked(), Render(), and Update().

◆ _nicknameInput

std::unique_ptr<UI::ITextInput> Game::ConnectionMenu::_nicknameInput
private

Definition at line 66 of file ConnectionMenu.hpp.

Referenced by ClearError(), Initialize(), OnJoinClicked(), Render(), and Update().

◆ _onBack

std::function<void()> Game::ConnectionMenu::_onBack {}
private

Definition at line 61 of file ConnectionMenu.hpp.

Referenced by OnBackClicked(), and SetOnBack().

◆ _onJoin

std::function<void(const std::string &, const std::string &, const std::string &)> Game::ConnectionMenu::_onJoin {}
private

Definition at line 60 of file ConnectionMenu.hpp.

Referenced by OnJoinClicked(), and SetOnJoin().

◆ _portInput

std::unique_ptr<UI::ITextInput> Game::ConnectionMenu::_portInput
private

Definition at line 68 of file ConnectionMenu.hpp.

Referenced by ClearError(), Initialize(), OnJoinClicked(), Render(), and Update().


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