group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
MainMenu Class Reference

IScreen implementation for the main menu/join screen; hosts the server join form. More...

#include <MainMenu.hpp>

Inheritance diagram for MainMenu:
[legend]
Collaboration diagram for MainMenu:
[legend]

Public Member Functions

bool init (AppContext &ctx, ServerBrowserTab initialTab=ServerBrowserTab::LocalListing)
 Bind renderer, window, and discovery configuration; must be called before iterate().
SDL_AppResult event (SDL_Event *event) override
 Handle an incoming SDL event.
SDL_AppResult iterate () override
 Update the screen state and render the next frame.
void quit () override
 Perform any necessary cleanup before the screen is destroyed.
std::optional< JoinRequestconsumeJoinRequest ()
 Take the pending join request set when the user clicks "Join", clearing it.
bool consumeHostRequest ()
 Take the pending host request set when the user clicks "Host", clearing it.
bool consumeReturnToTitleScreenRequest ()
 Take the pending title-screen request set when the user clicks "Return to Title Screen", clearing it.
bool consumeExitRequest ()
 True if the user requested closing the application, then clear that request.
void setJoinError (const std::string &error)
 Display an error string on the join form (e.g. from a failed connection attempt).
void setLaunchError (const std::string &error)
 Display a launch or connection error on the host tab.
void setJoinInProgress (bool joining, const std::string &label={})
 Show or clear the in-progress connection indicator.
void setPopupMessage (const std::string &message)
 Display a modal message on the next main menu screen frame.
bool consumeLaunchRequest ()
 True if the user requested server launch, then clear that request.
bool consumeShutdownRequest ()
 True if the user requested hosted-server shutdown, then clear that request.
bool consumeGoToLobbyRequest ()
 True if the user requested entering the hosted lobby, then clear that request.
HostConfigState consumeDraftConfig () const
 Current host-screen draft settings.
Public Member Functions inherited from IScreen
virtual ~IScreen ()=default
virtual void shutdownAfterRenderer ()
 Perform cleanup that must happen after the App-owned renderer shuts down.

Private Types

enum class  PendingConfirmAction { None , DiscardMatchChanges , ShutdownServer }

Private Member Functions

bool canManageCurrentServer () const
 True if the client is connected and is the current lobby host.
bool hasUnsavedServerChanges () const
 True if the current draft differs from the last settings sent to or received from the server.
HostConfigState draftConfig () const
 Current host-screen draft settings, clamped and sanitized.
bool updateServerSettings ()
 Send the current host-managed settings to the hosted server.
void requestDiscardMatchChangesConfirm ()
 Ask the host whether to discard unsaved match setting changes before leaving this screen.
void requestShutdownConfirm ()
 Ask the host to confirm server shutdown.
void startGlobalRefresh (bool force=false)
 Start an asynchronous global server-browser refresh when allowed by throttling.
void joinRefreshThreadIfFinished ()
 Join the global browser worker once it has finished.

Private Attributes

NewRendererrenderer = nullptr
 Renderer; not owned.
SDL_Window * window = nullptr
 Application window; not owned.
Clientclient = nullptr
 Network client owned by App; not owned.
HostedServerhostedServer = nullptr
 Hosted server owned by App; not owned.
HostConfigStatedraft = nullptr
 Persistent draft state owned by App; not owned.
NetworkConfignetworkConfig = nullptr
 Runtime network config owned by App; not owned.
UserSettingssettings = nullptr
 Live user settings; not owned.
std::string_view settingsPath
 Save path for user settings.
SystemMenuOverlay systemMenu_
 Shared Escape menu for front-end screens.
GlobalDiscoveryConfig discoveryConfig
JoinMenuState joinMenuState
 Mutable state backing the join form widgets.
std::string lastHostError
 Error message shown on the host form; empty when no error.
std::optional< MatchConfiglastSyncedMatchConfig
 Last match config acknowledged locally as server state.
std::optional< DiscoverySettingslastSyncedDiscoverySettings
 Last discovery settings acknowledged locally.
ConfirmModal confirm_
 Reusable confirmation modal for host tab actions.
PendingConfirmAction pendingConfirmAction = PendingConfirmAction::None
 Action to run after modal confirm.
std::optional< JoinRequestpendingJoinRequest
 Set when the user clicks "Join", cleared on App transition to Lobby.
bool pendingHostRequest = false
 Set when the user clicks "Host", cleared on App transition.
bool pendingLaunch = false
 Set when the user clicks "Launch", cleared by App.
bool pendingShutdown = false
 Set when the user clicks "Shutdown", cleared by App.
bool pendingGoToLobby = false
 Set when the user clicks "Go to Lobby", cleared by App.
bool pendingReturnToTitleScreenRequest
 Set when the user clicks "Return to Title Screen", cleared on transition.
bool pendingExitRequest = false
 Set when the user confirms "Exit to Desktop", cleared by App.
std::string joinError
 Error message shown on the join form; empty when no error.
std::string popupMessage
 Modal message shown once after returning to the main menu.
bool openPopupMessage = false
 True when the modal should be opened next frame.
std::unique_ptr< DiscoveryClientlocalDiscoveryClient = std::make_unique<DiscoveryClient>()
std::vector< net::discovery::ServerInfoglobalServers
 Latest directory-server browser snapshot.
std::vector< DiscoveryClient::DiscoveredServerlocalServers
 Latest LAN browser snapshot.
std::string browserError
 Last global browser error, empty when none.
std::mutex browserMutex
 Guards global browser results from worker thread.
std::thread browserThread
 Worker used for global server-browser requests.
std::atomic< bool > browserRefreshing {false}
 True while browserThread is fetching.
uint64_t lastBrowserRefreshMs = 0
 SDL tick timestamp of the last global refresh.

Additional Inherited Members

Static Protected Member Functions inherited from IScreen
static SDL_AppResult processCommonImguiEvent (SDL_Event *event)
 Forward event to ImGui and detect SDL_EVENT_QUIT.
static bool handleSystemMenuEvent (SDL_Event *event, SystemMenuOverlay &menu, UserSettings *settings)
 Handle Escape-toggle of a SystemMenuOverlay and forward consumed events.
static void beginMenuFrame (NewRenderer *renderer)
 Start a new ImGui frame and paint the shared menu background.
static void presentMenuFrame (NewRenderer &renderer)
 Render the ImGui draw data and present a default-camera frame.

Detailed Description

IScreen implementation for the main menu/join screen; hosts the server join form.

Member Enumeration Documentation

◆ PendingConfirmAction

enum class MainMenu::PendingConfirmAction
strongprivate
Enumerator
None 
DiscardMatchChanges 
ShutdownServer 

Member Function Documentation

◆ canManageCurrentServer()

bool MainMenu::canManageCurrentServer ( ) const
private

True if the client is connected and is the current lobby host.

Here is the caller graph for this function:

◆ consumeDraftConfig()

HostConfigState MainMenu::consumeDraftConfig ( ) const

Current host-screen draft settings.

Here is the call graph for this function:

◆ consumeExitRequest()

bool MainMenu::consumeExitRequest ( )

True if the user requested closing the application, then clear that request.

◆ consumeGoToLobbyRequest()

bool MainMenu::consumeGoToLobbyRequest ( )

True if the user requested entering the hosted lobby, then clear that request.

◆ consumeHostRequest()

bool MainMenu::consumeHostRequest ( )

Take the pending host request set when the user clicks "Host", clearing it.

Returns
True if a host request was pending.

◆ consumeJoinRequest()

std::optional< JoinRequest > MainMenu::consumeJoinRequest ( )

Take the pending join request set when the user clicks "Join", clearing it.

Returns
The request, or nullopt if none is pending.

◆ consumeLaunchRequest()

bool MainMenu::consumeLaunchRequest ( )

True if the user requested server launch, then clear that request.

◆ consumeReturnToTitleScreenRequest()

bool MainMenu::consumeReturnToTitleScreenRequest ( )

Take the pending title-screen request set when the user clicks "Return to Title Screen", clearing it.

Returns
True if a title-screen request was pending.

◆ consumeShutdownRequest()

bool MainMenu::consumeShutdownRequest ( )

True if the user requested hosted-server shutdown, then clear that request.

◆ draftConfig()

HostConfigState MainMenu::draftConfig ( ) const
private

Current host-screen draft settings, clamped and sanitized.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ event()

SDL_AppResult MainMenu::event ( SDL_Event * event)
overridevirtual

Handle an incoming SDL event.

Parameters
eventThe SDL event to process.
Returns
SDL_APP_CONTINUE to keep running, SDL_APP_FAILURE to exit.

Implements IScreen.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasUnsavedServerChanges()

bool MainMenu::hasUnsavedServerChanges ( ) const
private

True if the current draft differs from the last settings sent to or received from the server.

Here is the caller graph for this function:

◆ init()

bool MainMenu::init ( AppContext & ctx,
ServerBrowserTab initialTab = ServerBrowserTab::LocalListing )

Bind renderer, window, and discovery configuration; must be called before iterate().

Returns
False if either pointer is null.
Here is the call graph for this function:

◆ iterate()

SDL_AppResult MainMenu::iterate ( )
overridevirtual

Update the screen state and render the next frame.

Returns
SDL_APP_CONTINUE to keep running, SDL_APP_FAILURE to exit.

Implements IScreen.

Here is the call graph for this function:

◆ joinRefreshThreadIfFinished()

void MainMenu::joinRefreshThreadIfFinished ( )
private

Join the global browser worker once it has finished.

Here is the caller graph for this function:

◆ quit()

void MainMenu::quit ( )
overridevirtual

Perform any necessary cleanup before the screen is destroyed.

Implements IScreen.

◆ requestDiscardMatchChangesConfirm()

void MainMenu::requestDiscardMatchChangesConfirm ( )
private

Ask the host whether to discard unsaved match setting changes before leaving this screen.

Here is the caller graph for this function:

◆ requestShutdownConfirm()

void MainMenu::requestShutdownConfirm ( )
private

Ask the host to confirm server shutdown.

Here is the caller graph for this function:

◆ setJoinError()

void MainMenu::setJoinError ( const std::string & error)

Display an error string on the join form (e.g. from a failed connection attempt).

Here is the call graph for this function:

◆ setJoinInProgress()

void MainMenu::setJoinInProgress ( bool joining,
const std::string & label = {} )

Show or clear the in-progress connection indicator.

◆ setLaunchError()

void MainMenu::setLaunchError ( const std::string & error)

Display a launch or connection error on the host tab.

Here is the call graph for this function:

◆ setPopupMessage()

void MainMenu::setPopupMessage ( const std::string & message)

Display a modal message on the next main menu screen frame.

◆ startGlobalRefresh()

void MainMenu::startGlobalRefresh ( bool force = false)
private

Start an asynchronous global server-browser refresh when allowed by throttling.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateServerSettings()

bool MainMenu::updateServerSettings ( )
private

Send the current host-managed settings to the hosted server.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ browserError

std::string MainMenu::browserError
private

Last global browser error, empty when none.

◆ browserMutex

std::mutex MainMenu::browserMutex
private

Guards global browser results from worker thread.

◆ browserRefreshing

std::atomic<bool> MainMenu::browserRefreshing {false}
private

True while browserThread is fetching.

◆ browserThread

std::thread MainMenu::browserThread
private

Worker used for global server-browser requests.

◆ client

Client* MainMenu::client = nullptr
private

Network client owned by App; not owned.

◆ confirm_

ConfirmModal MainMenu::confirm_
private

Reusable confirmation modal for host tab actions.

◆ discoveryConfig

GlobalDiscoveryConfig MainMenu::discoveryConfig
private

◆ draft

HostConfigState* MainMenu::draft = nullptr
private

Persistent draft state owned by App; not owned.

◆ globalServers

std::vector<net::discovery::ServerInfo> MainMenu::globalServers
private

Latest directory-server browser snapshot.

◆ hostedServer

HostedServer* MainMenu::hostedServer = nullptr
private

Hosted server owned by App; not owned.

◆ joinError

std::string MainMenu::joinError
private

Error message shown on the join form; empty when no error.

◆ joinMenuState

JoinMenuState MainMenu::joinMenuState
private

Mutable state backing the join form widgets.

◆ lastBrowserRefreshMs

uint64_t MainMenu::lastBrowserRefreshMs = 0
private

SDL tick timestamp of the last global refresh.

◆ lastHostError

std::string MainMenu::lastHostError
private

Error message shown on the host form; empty when no error.

◆ lastSyncedDiscoverySettings

std::optional<DiscoverySettings> MainMenu::lastSyncedDiscoverySettings
private

Last discovery settings acknowledged locally.

◆ lastSyncedMatchConfig

std::optional<MatchConfig> MainMenu::lastSyncedMatchConfig
private

Last match config acknowledged locally as server state.

◆ localDiscoveryClient

std::unique_ptr<DiscoveryClient> MainMenu::localDiscoveryClient = std::make_unique<DiscoveryClient>()
private

◆ localServers

std::vector<DiscoveryClient::DiscoveredServer> MainMenu::localServers
private

Latest LAN browser snapshot.

◆ networkConfig

NetworkConfig* MainMenu::networkConfig = nullptr
private

Runtime network config owned by App; not owned.

◆ openPopupMessage

bool MainMenu::openPopupMessage = false
private

True when the modal should be opened next frame.

◆ pendingConfirmAction

PendingConfirmAction MainMenu::pendingConfirmAction = PendingConfirmAction::None
private

Action to run after modal confirm.

◆ pendingExitRequest

bool MainMenu::pendingExitRequest = false
private

Set when the user confirms "Exit to Desktop", cleared by App.

◆ pendingGoToLobby

bool MainMenu::pendingGoToLobby = false
private

Set when the user clicks "Go to Lobby", cleared by App.

◆ pendingHostRequest

bool MainMenu::pendingHostRequest = false
private

Set when the user clicks "Host", cleared on App transition.

◆ pendingJoinRequest

std::optional<JoinRequest> MainMenu::pendingJoinRequest
private

Set when the user clicks "Join", cleared on App transition to Lobby.

◆ pendingLaunch

bool MainMenu::pendingLaunch = false
private

Set when the user clicks "Launch", cleared by App.

◆ pendingReturnToTitleScreenRequest

bool MainMenu::pendingReturnToTitleScreenRequest
private
Initial value:
=
false

Set when the user clicks "Return to Title Screen", cleared on transition.

◆ pendingShutdown

bool MainMenu::pendingShutdown = false
private

Set when the user clicks "Shutdown", cleared by App.

◆ popupMessage

std::string MainMenu::popupMessage
private

Modal message shown once after returning to the main menu.

◆ renderer

NewRenderer* MainMenu::renderer = nullptr
private

Renderer; not owned.

◆ settings

UserSettings* MainMenu::settings = nullptr
private

Live user settings; not owned.

◆ settingsPath

std::string_view MainMenu::settingsPath
private

Save path for user settings.

◆ systemMenu_

SystemMenuOverlay MainMenu::systemMenu_
private

Shared Escape menu for front-end screens.

◆ window

SDL_Window* MainMenu::window = nullptr
private

Application window; not owned.


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