/// <summary> /// The main game constructor. /// </summary> public NetworkStateManagementGame() { Content.RootDirectory = "Content"; graphics = new GraphicsDeviceManager(this); // Create components. screenManager = new ScreenManager(this); Components.Add(screenManager); Components.Add(new MessageDisplayComponent(this)); Components.Add(new GamerServicesComponent(this)); // Activate the first screens. screenManager.AddScreen(new BackgroundScreen(), null); screenManager.AddScreen(new MainMenuScreen(), null); // Listen for invite notification events. NetworkSession.InviteAccepted += (sender, e) => NetworkSessionComponent.InviteAccepted(screenManager, e); // To test the trial mode behavior while developing your game, // uncomment this line: // Guide.SimulateTrialMode = true; if (NetworkStateManagementGame.MainGame == null) NetworkStateManagementGame.MainGame = this; }
public NetworkStateManagementGame () #endif { Content.RootDirectory = "Content"; graphics = new GraphicsDeviceManager (this); #if ANDROID graphics.IsFullScreen = true; #else graphics.PreferredBackBufferWidth = 1067; graphics.PreferredBackBufferHeight = 600; #endif // Create components. screenManager = new ScreenManager (this); Components.Add (screenManager); Components.Add (new MessageDisplayComponent (this)); Components.Add (new GamerServicesComponent (this)); // Activate the first screens. screenManager.AddScreen (new BackgroundScreen (), null); screenManager.AddScreen (new MainMenuScreen (), null); // Listen for invite notification events. NetworkSession.InviteAccepted += (sender, e) => NetworkSessionComponent.InviteAccepted (screenManager, e); // To test the trial mode behavior while developing your game, // uncomment this line: // Guide.SimulateTrialMode = true; }
/// <summary> /// The constructor is private: loading screens should /// be activated via the static Load method instead. /// </summary> private LoadingScreen (ScreenManager screenManager,bool loadingIsSlow, GameScreen[] screensToLoad) { this.loadingIsSlow = loadingIsSlow; this.screensToLoad = screensToLoad; TransitionOnTime = TimeSpan.FromSeconds (0.5); // If this is going to be a slow load operation, create a background // thread that will update the network session and draw the load screen // animation while the load is taking place. if (loadingIsSlow) { backgroundThread = new Thread (BackgroundWorkerThread); backgroundThreadExit = new ManualResetEvent (false); graphicsDevice = screenManager.GraphicsDevice; // Look up some services that will be used by the background thread. IServiceProvider services = screenManager.Game.Services; networkSession = (NetworkSession)services.GetService ( typeof(NetworkSession)); messageDisplay = (IMessageDisplay)services.GetService ( typeof(IMessageDisplay)); } }
/// <summary> /// The constructor is private: external callers should use the Create method. /// </summary> NetworkSessionComponent(ScreenManager screenManager, NetworkSession networkSession) : base(screenManager.Game) { this.screenManager = screenManager; this.networkSession = networkSession; // Hook up our session event handlers. networkSession.GamerJoined += GamerJoined; networkSession.GamerLeft += GamerLeft; networkSession.SessionEnded += NetworkSessionEnded; }
/// <summary> /// Creates a new NetworkSessionComponent. /// </summary> public static void Create (ScreenManager screenManager, NetworkSession networkSession) { Game game = screenManager.Game; // Register this network session as a service. game.Services.AddService (typeof(NetworkSession), networkSession); // Create a NetworkSessionComponent, and add it to the Game. game.Components.Add (new NetworkSessionComponent (screenManager, networkSession)); }
/// <summary> /// Activates the loading screen. /// </summary> public static void Load (ScreenManager screenManager, bool loadingIsSlow, PlayerIndex? controllingPlayer, params GameScreen[] screensToLoad) { // Tell all the current screens to transition off. foreach (GameScreen screen in screenManager.GetScreens ()) screen.ExitScreen (); // Create and activate the loading screen. LoadingScreen loadingScreen = new LoadingScreen (screenManager, loadingIsSlow, screensToLoad); screenManager.AddScreen (loadingScreen, controllingPlayer); }
// Конструктор public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferredBackBufferWidth = SizeScreen.Width; graphics.PreferredBackBufferHeight = SizeScreen.Height; /////////////////////////////////////////////////////////////////////////////////// //// Graphics.PreferredBackBufferFormat = SurfaceFormat.HalfSingle; дуже обережно ж цим!!! ////////////////////////////////////////////////////////////////////////////////////////// Content.RootDirectory = "Bin"; screenManager = new ScreenManager(this); Components.Add(screenManager); Components.Add(new MessageDisplayComponent(this)); // Components.Add(new GamerServicesComponent(this)); screenManager.AddScreen(new BackgroundScreen(), null); songLiberty.musicLevel = new Song[5]; background = new Texture2D[5]; SetSetting = new Setting(); }
/// <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, PlayerIndex playerIndex) { NetworkSessionComponent self = FindSessionComponent(screenManager.Game); 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, playerIndex); } }
/// <summary> /// Event handler called when the system delivers an invite notification. /// This can occur when the user accepts an invite that was sent to them by /// a friend (pull mode), or if they choose the "Join Session In Progress" /// option in their friends screen (push mode). The handler leaves the /// current session (if any), then joins the session referred to by the /// invite. It is not necessary to prompt the user before doing this, as /// the Guide will already have taken care of the necessary confirmations /// before the invite was delivered to you. /// </summary> public static void InviteAccepted(ScreenManager screenManager, InviteAcceptedEventArgs e) { // If we are already in a network session, leave it now. NetworkSessionComponent self = FindSessionComponent(screenManager.Game); if (self != null) self.Dispose(); try { // Which local profiles should we include in this session? IEnumerable<SignedInGamer> localGamers = ChooseGamers(NetworkSessionType.PlayerMatch, e.Gamer.PlayerIndex); // Begin an asynchronous join-from-invite operation. IAsyncResult asyncResult = NetworkSession.BeginJoinInvited(localGamers, null, null); // Use the loading screen to replace whatever screens were previously // active. This will completely reset the screen state, regardless of // whether we were in the menus or playing a game when the invite was // delivered. When the loading screen finishes, it will activate the // network busy screen, which displays an animation as it waits for // the join operation to complete. NetworkBusyScreen busyScreen = new NetworkBusyScreen(asyncResult); busyScreen.OperationCompleted += JoinInvitedOperationCompleted; LoadingScreen.Load(screenManager, false, null, new BackgroundScreen(), busyScreen); } catch (Exception exception) { NetworkErrorScreen errorScreen = new NetworkErrorScreen(exception); LoadingScreen.Load(screenManager, false, null, new BackgroundScreen(), new MainMenuScreen(), errorScreen); } }