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

Dialog menu for adding a new server. More...

#include <AddServerMenu.hpp>

Inheritance diagram for Game::AddServerMenu:
Inheritance graph
Collaboration diagram for Game::AddServerMenu:
Collaboration graph

Public Member Functions

 AddServerMenu (UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics)
 
 ~AddServerMenu () override=default
 
void SetOnAdd (std::function< void(const std::string &, const std::string &, const std::string &)> onAdd)
 Set callback triggered when the Add button is clicked.
 
void SetOnCancel (std::function< void()> onCancel)
 Set callback triggered when the Cancel 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 , NAME , IP , PORT }
 

Private Member Functions

void OnAddClicked ()
 
void OnCancelClicked ()
 
std::unique_ptr< UI::ITextInputCreateInput (float width, float height, float yPos, const std::string &placeholder, int maxLength, const std::string &regex, const std::string &logName)
 
void ClearInputs ()
 
bool ValidateName (const std::string &name, 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 &)> _onAdd {}
 
std::function< void()> _onCancel {}
 
Graphics::IGraphics_graphics
 
std::unique_ptr< UI::ITextInput_nameInput
 
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

Dialog menu for adding a new server.

This menu allows the user to:

  • Enter server name (display name)
  • Enter server IP address
  • Enter server port
  • Confirm or cancel

Definition at line 28 of file AddServerMenu.hpp.

Member Enumeration Documentation

◆ ErrorField

enum class Game::AddServerMenu::ErrorField
strongprivate
Enumerator
NONE 
NAME 
IP 
PORT 

Definition at line 78 of file AddServerMenu.hpp.

Constructor & Destructor Documentation

◆ AddServerMenu()

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

Definition at line 15 of file AddServerMenu.cpp.

◆ ~AddServerMenu()

Game::AddServerMenu::~AddServerMenu ( )
overridedefault

Member Function Documentation

◆ ClearError()

void Game::AddServerMenu::ClearError ( )
private

Definition at line 302 of file AddServerMenu.cpp.

References _errorField, _errorMessage, _hasError, and NONE.

Referenced by ClearInputs(), and CreateInput().

◆ ClearInputs()

void Game::AddServerMenu::ClearInputs ( )
private

Definition at line 228 of file AddServerMenu.cpp.

References _ipInput, _nameInput, _portInput, and ClearError().

Referenced by OnAddClicked(), and OnCancelClicked().

Here is the call graph for this function:

◆ CreateInput()

std::unique_ptr< UI::ITextInput > Game::AddServerMenu::CreateInput ( float  width,
float  height,
float  yPos,
const std::string &  placeholder,
int  maxLength,
const std::string &  regex,
const std::string &  logName 
)
private

Definition at line 198 of file AddServerMenu.cpp.

References Game::BaseMenu::_uiFactory, UI::CENTER_HORIZONTAL, ClearError(), UI::IUIFactory::CreateTextInput(), and LOG_INFO.

Referenced by Initialize().

Here is the call graph for this function:

◆ Initialize()

void Game::AddServerMenu::Initialize ( )
overridevirtual

Initialize menu (must be implemented by derived classes).

Implements Game::BaseMenu.

Definition at line 27 of file AddServerMenu.cpp.

References _buttonHeight, _buttonsY, _ipInput, Game::BaseMenu::_menu, _nameInput, _portInput, Game::BaseMenu::_uiFactory, UI::CENTER_HORIZONTAL, UI::IUIFactory::CreateButton(), CreateInput(), OnAddClicked(), OnCancelClicked(), and Game::BaseMenu::WrapWithClickSound().

Here is the call graph for this function:

◆ OnAddClicked()

void Game::AddServerMenu::OnAddClicked ( )
private

Definition at line 146 of file AddServerMenu.cpp.

References _errorField, _errorMessage, _hasError, _ipInput, _nameInput, _onAdd, _portInput, ClearInputs(), IP, LOG_INFO, NAME, PORT, ValidateIP(), ValidateName(), and ValidatePort().

Referenced by Initialize().

Here is the call graph for this function:

◆ OnCancelClicked()

void Game::AddServerMenu::OnCancelClicked ( )
private

Definition at line 187 of file AddServerMenu.cpp.

References _onCancel, ClearInputs(), and LOG_INFO.

Referenced by Initialize().

Here is the call graph for this function:

◆ Render()

void Game::AddServerMenu::Render ( )
overridevirtual

Render menu (should be called every frame).

Reimplemented from Game::BaseMenu.

Definition at line 106 of file AddServerMenu.cpp.

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

Here is the call graph for this function:

◆ SetOnAdd()

void Game::AddServerMenu::SetOnAdd ( std::function< void(const std::string &, const std::string &, const std::string &)>  onAdd)

Set callback triggered when the Add button is clicked.

Parameters
onAddCallback receiving (name, ip, port) as parameters

Definition at line 18 of file AddServerMenu.cpp.

References _onAdd.

◆ SetOnCancel()

void Game::AddServerMenu::SetOnCancel ( std::function< void()>  onCancel)

Set callback triggered when the Cancel button is clicked.

Definition at line 23 of file AddServerMenu.cpp.

References _onCancel.

◆ Update()

void Game::AddServerMenu::Update ( )
overridevirtual

Update menu state (should be called every frame).

Reimplemented from Game::BaseMenu.

Definition at line 93 of file AddServerMenu.cpp.

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

Here is the call graph for this function:

◆ ValidateIP()

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

Definition at line 250 of file AddServerMenu.cpp.

Referenced by OnAddClicked().

◆ ValidateName()

bool Game::AddServerMenu::ValidateName ( const std::string &  name,
std::string &  errorMsg 
)
private

Definition at line 238 of file AddServerMenu.cpp.

Referenced by OnAddClicked().

◆ ValidatePort()

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

Definition at line 282 of file AddServerMenu.cpp.

Referenced by OnAddClicked().

Member Data Documentation

◆ _buttonHeight

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

Definition at line 83 of file AddServerMenu.hpp.

Referenced by Initialize(), and Render().

◆ _buttonsY

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

Definition at line 82 of file AddServerMenu.hpp.

Referenced by Initialize(), and Render().

◆ _errorField

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

Definition at line 79 of file AddServerMenu.hpp.

Referenced by ClearError(), and OnAddClicked().

◆ _errorMessage

std::string Game::AddServerMenu::_errorMessage
private

Definition at line 76 of file AddServerMenu.hpp.

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

◆ _graphics

Graphics::IGraphics& Game::AddServerMenu::_graphics
private

Definition at line 68 of file AddServerMenu.hpp.

Referenced by Render().

◆ _hasError

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

Definition at line 77 of file AddServerMenu.hpp.

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

◆ _ipInput

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

Definition at line 72 of file AddServerMenu.hpp.

Referenced by ClearInputs(), Initialize(), OnAddClicked(), Render(), and Update().

◆ _nameInput

std::unique_ptr<UI::ITextInput> Game::AddServerMenu::_nameInput
private

Definition at line 71 of file AddServerMenu.hpp.

Referenced by ClearInputs(), Initialize(), OnAddClicked(), Render(), and Update().

◆ _onAdd

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

Definition at line 65 of file AddServerMenu.hpp.

Referenced by OnAddClicked(), and SetOnAdd().

◆ _onCancel

std::function<void()> Game::AddServerMenu::_onCancel {}
private

Definition at line 66 of file AddServerMenu.hpp.

Referenced by OnCancelClicked(), and SetOnCancel().

◆ _portInput

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

Definition at line 73 of file AddServerMenu.hpp.

Referenced by ClearInputs(), Initialize(), OnAddClicked(), Render(), and Update().


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