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

Server list menu for selecting and managing servers. More...

#include <ServerListMenu.hpp>

Inheritance diagram for Game::ServerListMenu:
Inheritance graph
Collaboration diagram for Game::ServerListMenu:
Collaboration graph

Classes

struct  ServerInfo
 

Public Member Functions

 ServerListMenu (UI::IUIFactory &uiFactory, Graphics::IGraphics &graphics)
 
 ~ServerListMenu () override=default
 
void SetOnServerSelected (std::function< void(const std::string &, uint16_t)> onServerSelected)
 Set callback triggered when a server is selected.
 
void SetOnAddServer (std::function< void()> onAddServer)
 Set callback triggered when "Add Server" button is clicked.
 
void SetOnBack (std::function< void()> onBack)
 Set callback triggered when the Back button is clicked.
 
void AddServer (const std::string &name, const std::string &ip, uint16_t port)
 Add a server to the list.
 
void RemoveServer (size_t index)
 Remove a server from the list.
 
const std::vector< ServerInfo > & GetServers () const
 Get the list of servers.
 
void SetConnectionError (const std::string &errorMsg)
 Set connection error message.
 
void ClearConnectionError ()
 Clear connection error message.
 
void SetConnecting (bool connecting, const std::string &serverName="")
 Set connecting state.
 
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 Member Functions

void OnServerClicked (size_t index)
 
void OnAddServerClicked ()
 
void OnBackClicked ()
 
void OnDeleteServerClicked (size_t index)
 
void RebuildServerList ()
 
void UpdateAddServerButtonState ()
 

Private Attributes

std::function< void(const std::string &, uint16_t)> _onServerSelected {}
 
std::function< void()> _onAddServer {}
 
std::function< void()> _onBack {}
 
Graphics::IGraphics_graphics
 
std::vector< ServerInfo_servers
 
std::vector< std::shared_ptr< UI::IButton > > _serverButtons
 
std::vector< std::shared_ptr< UI::IButton > > _deleteButtons
 
std::shared_ptr< UI::IButton_addServerButton
 
std::shared_ptr< UI::IButton_backButton
 
std::string _connectionError
 
bool _hasConnectionError {false}
 
bool _isConnecting {false}
 
std::string _connectingServerName
 

Static Private Attributes

static constexpr size_t MAX_SERVERS = 5
 
static constexpr float SERVER_BUTTON_WIDTH = 400.0f
 
static constexpr float SERVER_BUTTON_HEIGHT = 50.0f
 
static constexpr float SERVER_BUTTON_SPACING = 15.0f
 
static constexpr float LIST_START_Y = 100.0f
 
static constexpr int MAX_VISIBLE_SERVERS = 8
 

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

Server list menu for selecting and managing servers.

This menu displays a list of saved servers and allows:

  • Selecting a server to connect to
  • Adding a new server (opens AddServerMenu)
  • Going back to main menu

Definition at line 28 of file ServerListMenu.hpp.

Constructor & Destructor Documentation

◆ ServerListMenu()

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

Definition at line 14 of file ServerListMenu.cpp.

References _servers.

◆ ~ServerListMenu()

Game::ServerListMenu::~ServerListMenu ( )
overridedefault

Member Function Documentation

◆ AddServer()

void Game::ServerListMenu::AddServer ( const std::string &  name,
const std::string &  ip,
uint16_t  port 
)

Add a server to the list.

Parameters
nameServer display name
ipServer IP address
portServer port

Definition at line 33 of file ServerListMenu.cpp.

References _servers, LOG_WARNING, MAX_SERVERS, RebuildServerList(), and UpdateAddServerButtonState().

Here is the call graph for this function:

◆ ClearConnectionError()

void Game::ServerListMenu::ClearConnectionError ( )

Clear connection error message.

Definition at line 287 of file ServerListMenu.cpp.

References _connectionError, and _hasConnectionError.

Referenced by OnServerClicked(), and SetConnecting().

◆ GetServers()

const std::vector< ServerInfo > & Game::ServerListMenu::GetServers ( ) const
inline

Get the list of servers.

Definition at line 74 of file ServerListMenu.hpp.

References _servers.

◆ Initialize()

void Game::ServerListMenu::Initialize ( )
overridevirtual

◆ OnAddServerClicked()

void Game::ServerListMenu::OnAddServerClicked ( )
private

Definition at line 243 of file ServerListMenu.cpp.

References _onAddServer, and LOG_INFO.

Referenced by Initialize(), and UpdateAddServerButtonState().

◆ OnBackClicked()

void Game::ServerListMenu::OnBackClicked ( )
private

Definition at line 250 of file ServerListMenu.cpp.

References _onBack, and LOG_INFO.

Referenced by Initialize().

◆ OnDeleteServerClicked()

void Game::ServerListMenu::OnDeleteServerClicked ( size_t  index)
private

Definition at line 257 of file ServerListMenu.cpp.

References LOG_INFO, and RemoveServer().

Referenced by RebuildServerList().

Here is the call graph for this function:

◆ OnServerClicked()

void Game::ServerListMenu::OnServerClicked ( size_t  index)
private

Definition at line 226 of file ServerListMenu.cpp.

References _onServerSelected, _servers, ClearConnectionError(), LOG_ERROR, and LOG_INFO.

Referenced by RebuildServerList().

Here is the call graph for this function:

◆ RebuildServerList()

◆ RemoveServer()

void Game::ServerListMenu::RemoveServer ( size_t  index)

Remove a server from the list.

Parameters
indexIndex of the server to remove

Definition at line 43 of file ServerListMenu.cpp.

References _servers, LOG_ERROR, LOG_INFO, RebuildServerList(), and UpdateAddServerButtonState().

Referenced by OnDeleteServerClicked().

Here is the call graph for this function:

◆ Render()

void Game::ServerListMenu::Render ( )
overridevirtual

Render menu (should be called every frame).

Reimplemented from Game::BaseMenu.

Definition at line 191 of file ServerListMenu.cpp.

References _connectingServerName, _connectionError, _graphics, _hasConnectionError, _isConnecting, Game::BaseMenu::_menu, Graphics::IGraphics::DrawText(), Graphics::IGraphics::GetScreenWidth(), and Game::BaseMenu::Render().

Here is the call graph for this function:

◆ SetConnecting()

void Game::ServerListMenu::SetConnecting ( bool  connecting,
const std::string &  serverName = "" 
)

Set connecting state.

Parameters
connectingTrue if currently connecting
serverNameName of server being connected to

Definition at line 292 of file ServerListMenu.cpp.

References _connectingServerName, _isConnecting, and ClearConnectionError().

Here is the call graph for this function:

◆ SetConnectionError()

void Game::ServerListMenu::SetConnectionError ( const std::string &  errorMsg)

Set connection error message.

Parameters
errorMsgError message to display

Definition at line 281 of file ServerListMenu.cpp.

References _connectionError, _hasConnectionError, and LOG_ERROR.

◆ SetOnAddServer()

void Game::ServerListMenu::SetOnAddServer ( std::function< void()>  onAddServer)

Set callback triggered when "Add Server" button is clicked.

Definition at line 25 of file ServerListMenu.cpp.

References _onAddServer.

◆ SetOnBack()

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

Set callback triggered when the Back button is clicked.

Definition at line 29 of file ServerListMenu.cpp.

References _onBack.

◆ SetOnServerSelected()

void Game::ServerListMenu::SetOnServerSelected ( std::function< void(const std::string &, uint16_t)>  onServerSelected)

Set callback triggered when a server is selected.

Parameters
onServerSelectedCallback receiving (ip, port) as parameters

Definition at line 20 of file ServerListMenu.cpp.

References _onServerSelected.

◆ Update()

void Game::ServerListMenu::Update ( )
overridevirtual

Update menu state (should be called every frame).

Reimplemented from Game::BaseMenu.

Definition at line 187 of file ServerListMenu.cpp.

References Game::BaseMenu::Update().

Here is the call graph for this function:

◆ UpdateAddServerButtonState()

void Game::ServerListMenu::UpdateAddServerButtonState ( )
private

Definition at line 262 of file ServerListMenu.cpp.

References _addServerButton, _servers, LOG_WARNING, MAX_SERVERS, OnAddServerClicked(), and Game::BaseMenu::WrapWithClickSound().

Referenced by AddServer(), Initialize(), and RemoveServer().

Here is the call graph for this function:

Member Data Documentation

◆ _addServerButton

std::shared_ptr<UI::IButton> Game::ServerListMenu::_addServerButton
private

Definition at line 116 of file ServerListMenu.hpp.

Referenced by Initialize(), RebuildServerList(), and UpdateAddServerButtonState().

◆ _backButton

std::shared_ptr<UI::IButton> Game::ServerListMenu::_backButton
private

Definition at line 117 of file ServerListMenu.hpp.

Referenced by Initialize(), and RebuildServerList().

◆ _connectingServerName

std::string Game::ServerListMenu::_connectingServerName
private

Definition at line 123 of file ServerListMenu.hpp.

Referenced by Render(), and SetConnecting().

◆ _connectionError

std::string Game::ServerListMenu::_connectionError
private

Definition at line 119 of file ServerListMenu.hpp.

Referenced by ClearConnectionError(), Render(), and SetConnectionError().

◆ _deleteButtons

std::vector<std::shared_ptr<UI::IButton> > Game::ServerListMenu::_deleteButtons
private

Definition at line 114 of file ServerListMenu.hpp.

Referenced by RebuildServerList().

◆ _graphics

Graphics::IGraphics& Game::ServerListMenu::_graphics
private

Definition at line 110 of file ServerListMenu.hpp.

Referenced by Initialize(), and Render().

◆ _hasConnectionError

bool Game::ServerListMenu::_hasConnectionError {false}
private

Definition at line 120 of file ServerListMenu.hpp.

Referenced by ClearConnectionError(), Render(), and SetConnectionError().

◆ _isConnecting

bool Game::ServerListMenu::_isConnecting {false}
private

Definition at line 122 of file ServerListMenu.hpp.

Referenced by Render(), and SetConnecting().

◆ _onAddServer

std::function<void()> Game::ServerListMenu::_onAddServer {}
private

Definition at line 107 of file ServerListMenu.hpp.

Referenced by OnAddServerClicked(), and SetOnAddServer().

◆ _onBack

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

Definition at line 108 of file ServerListMenu.hpp.

Referenced by OnBackClicked(), and SetOnBack().

◆ _onServerSelected

std::function<void(const std::string &, uint16_t)> Game::ServerListMenu::_onServerSelected {}
private

Definition at line 106 of file ServerListMenu.hpp.

Referenced by OnServerClicked(), and SetOnServerSelected().

◆ _serverButtons

std::vector<std::shared_ptr<UI::IButton> > Game::ServerListMenu::_serverButtons
private

Definition at line 113 of file ServerListMenu.hpp.

Referenced by Initialize(), and RebuildServerList().

◆ _servers

std::vector<ServerInfo> Game::ServerListMenu::_servers
private

◆ LIST_START_Y

constexpr float Game::ServerListMenu::LIST_START_Y = 100.0f
staticconstexprprivate

Definition at line 129 of file ServerListMenu.hpp.

Referenced by RebuildServerList().

◆ MAX_SERVERS

constexpr size_t Game::ServerListMenu::MAX_SERVERS = 5
staticconstexprprivate

Definition at line 125 of file ServerListMenu.hpp.

Referenced by AddServer(), and UpdateAddServerButtonState().

◆ MAX_VISIBLE_SERVERS

constexpr int Game::ServerListMenu::MAX_VISIBLE_SERVERS = 8
staticconstexprprivate

Definition at line 130 of file ServerListMenu.hpp.

Referenced by RebuildServerList().

◆ SERVER_BUTTON_HEIGHT

constexpr float Game::ServerListMenu::SERVER_BUTTON_HEIGHT = 50.0f
staticconstexprprivate

Definition at line 127 of file ServerListMenu.hpp.

Referenced by RebuildServerList().

◆ SERVER_BUTTON_SPACING

constexpr float Game::ServerListMenu::SERVER_BUTTON_SPACING = 15.0f
staticconstexprprivate

Definition at line 128 of file ServerListMenu.hpp.

Referenced by RebuildServerList().

◆ SERVER_BUTTON_WIDTH

constexpr float Game::ServerListMenu::SERVER_BUTTON_WIDTH = 400.0f
staticconstexprprivate

Definition at line 126 of file ServerListMenu.hpp.

Referenced by RebuildServerList().


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