//----------------------------------------------------------------------------- // MainMenuScreen.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Net; namespace CatapultGame { class MainMenuScreen : MenuScreen { public MainMenuScreen() : base(String.Empty) { IsPopup = true; // Create our menu entries. MenuEntry startGameMenuEntry = new MenuEntry("Single Player vs AI"); MenuEntry startMultiPlayerGameMenuEntry = new MenuEntry("Multi Player on LAN"); MenuEntry exitMenuEntry = new MenuEntry("Exit"); // Hook up menu event handlers. startGameMenuEntry.Selected += StartGameMenuEntrySelected; startMultiPlayerGameMenuEntry.Selected += StartMultiPlayerGameMenuEntrySelected; exitMenuEntry.Selected += OnCancel; // Add entries to the menu. MenuEntries.Add(startGameMenuEntry); MenuEntries.Add(startMultiPlayerGameMenuEntry); MenuEntries.Add(exitMenuEntry); } protected override void UpdateMenuEntryLocations() { base.UpdateMenuEntryLocations(); foreach (var entry in MenuEntries) { Vector2 position = entry.Position; position.Y += 60; entry.Position = position; } } /// /// Handles "Play" menu item selection /// /// /// void StartGameMenuEntrySelected(object sender, EventArgs e) { // Lets make sure we get rid of our network session // so we can start up clean ScreenManager.Game.Services.RemoveService(typeof(NetworkSession)); ScreenManager.AddScreen(new InstructionsScreen(), null); } /// /// Handles "Exit" menu item selection /// /// protected override void OnCancel(PlayerIndex playerIndex) { ScreenManager.Game.Exit(); } void StartMultiPlayerGameMenuEntrySelected(object sender, PlayerIndexEventArgs e) { CreateOrFindSession(NetworkSessionType.SystemLink, e.PlayerIndex); } /// /// Helper method shared by the Live and System Link menu event handlers. /// void CreateOrFindSession(NetworkSessionType sessionType, PlayerIndex playerIndex) { // First, we need to make sure a suitable gamer profile is signed in. ProfileSignInScreen profileSignIn = new ProfileSignInScreen(sessionType); // Hook up an event so once the ProfileSignInScreen is happy, // it will activate the CreateOrFindSessionScreen. profileSignIn.ProfileSignedIn += delegate { GameScreen createOrFind = new CreateOrFindSessionScreen(sessionType); ScreenManager.AddScreen(createOrFind, playerIndex); }; // Activate the ProfileSignInScreen. ScreenManager.AddScreen(profileSignIn, playerIndex); } } }