/// <summary> /// Public method called when the user wants to leave the network session. /// Displays a confirmation message box, then disposes the session, removes /// the NetworkSessionComponent, and returns them to the main menu screen. /// </summary> public static void LeaveSession(ScreenManager screenManager) { // Search through Game.Components to find the NetworkSessionComponent. foreach (IGameComponent component in screenManager.Game.Components) { NetworkSessionComponent self = component as NetworkSessionComponent; if (self != null) { // Display a message box to confirm the user really wants to leave. string message; if (self.networkSession.IsHost) { message = Resources.ConfirmEndSession; } else { message = Resources.ConfirmLeaveSession; } MessageBoxScreen confirmMessageBox = new MessageBoxScreen(message); // Hook the messge box ok event to actually leave the session. confirmMessageBox.Accepted += delegate { self.LeaveSession(); }; screenManager.AddScreen(confirmMessageBox); break; } } }
/// <summary> /// Event handler for when the End/Leave Session menu entry is selected. /// </summary> void LeaveSessionMenuEntrySelected(object sender, EventArgs e) { NetworkSessionComponent.LeaveSession(ScreenManager); }