/// <summary> /// Constructs a menu screen listing the available network sessions. /// </summary> public JoinSessionScreen(AvailableNetworkSessionCollection availableSessions) : base(Resources.JoinSession) { this.availableSessions = availableSessions; foreach (AvailableNetworkSession availableSession in availableSessions) { // Create menu entries for each available session. MenuEntry menuEntry = new AvailableSessionMenuEntry(availableSession); menuEntry.Selected += AvailableSessionMenuEntrySelected; MenuEntries.Add(menuEntry); // Matchmaking can return up to 25 available sessions at a time, but // we don't have room to fit that many on the screen. In a perfect // world we should make the menu scroll if there are too many, but it // is easier to just not bother displaying more than we have room for. if (MenuEntries.Count >= MaxSearchResults) { break; } } // Add the Back menu entry. MenuEntry backMenuEntry = new MenuEntry(Resources.Back); backMenuEntry.Selected += BackMenuEntrySelected; MenuEntries.Add(backMenuEntry); }
/// <summary> /// Event handler for when an available session menu entry is selected. /// </summary> void AvailableSessionMenuEntrySelected(object sender, PlayerIndexEventArgs e) { // Which menu entry was selected? AvailableSessionMenuEntry menuEntry = (AvailableSessionMenuEntry)sender; AvailableNetworkSession availableSession = menuEntry.AvailableSession; try { // Begin an asynchronous join network session operation. IAsyncResult asyncResult = NetworkSession.BeginJoin(availableSession, null, null); // Activate the network busy screen, which will display // an animation until this operation has completed. NetworkBusyScreen busyScreen = new NetworkBusyScreen(asyncResult); busyScreen.OperationCompleted += JoinSessionOperationCompleted; ScreenManager.AddScreen(busyScreen, ControllingPlayer); } catch (Exception exception) { NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception); ScreenManager.AddScreen(errorScreen, ControllingPlayer); } }
/// <summary> /// Constructs a menu screen listing the available network sessions. /// </summary> public JoinSessionScreen(AvailableNetworkSessionCollection availableSessions) : base(Resources.JoinSession) { this.availableSessions = availableSessions; foreach (AvailableNetworkSession availableSession in availableSessions) { // Create menu entries for each available session. MenuEntry menuEntry = new AvailableSessionMenuEntry(availableSession); menuEntry.Selected += AvailableSessionMenuEntrySelected; MenuEntries.Add(menuEntry); // Matchmaking can return up to 25 available sessions at a time, but // we don't have room to fit that many on the screen. In a perfect // world we should make the menu scroll if there are too many, but it // is easier to just not bother displaying more than we have room for. if (MenuEntries.Count >= MaxSearchResults) break; } // Add the Back menu entry. MenuEntry backMenuEntry = new MenuEntry(Resources.Back); backMenuEntry.Selected += BackMenuEntrySelected; MenuEntries.Add(backMenuEntry); }