Преглед на файлове

Remove #if defines and replaced with Runtime checks.

Dominique Louis преди 3 седмици
родител
ревизия
e532814d4f

+ 21 - 8
NetworkStateManagement/Core/NetworkStateManagementGame.cs

@@ -5,6 +5,7 @@
 // Copyright (C) Microsoft Corporation. All rights reserved.
 //-----------------------------------------------------------------------------
 
+using System;
 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Graphics;
 using Microsoft.Xna.Framework.GamerServices;
@@ -25,7 +26,7 @@ namespace NetworkStateManagement
 		const int screenWidth = 480;
 		const int screenHeight = 540;
 
-		GraphicsDeviceManager graphics;
+		GraphicsDeviceManager graphicsDeviceManager;
 		ScreenManager screenManager;
 
 
@@ -48,12 +49,24 @@ namespace NetworkStateManagement
 		{
 			Content.RootDirectory = "Content";
 
-			graphics = new GraphicsDeviceManager(this);
-#if MOBILE
-			graphics.IsFullScreen = true;
-#endif
-			graphics.PreferredBackBufferWidth = screenWidth;
-			graphics.PreferredBackBufferHeight = screenHeight;
+			graphicsDeviceManager = new GraphicsDeviceManager(this);
+			graphicsDeviceManager.PreferredBackBufferWidth = screenWidth;
+			graphicsDeviceManager.PreferredBackBufferHeight = screenHeight;
+
+			if (UIUtility.IsMobile)
+			{
+				graphicsDeviceManager.IsFullScreen = true;
+				IsMouseVisible = false;
+			}
+			else if (UIUtility.IsDesktop)
+			{
+				graphicsDeviceManager.IsFullScreen = false;
+				IsMouseVisible = true;
+			}
+			else
+			{
+				throw new PlatformNotSupportedException();
+			}
 
 			// Create components.
 			screenManager = new ScreenManager(this);
@@ -91,7 +104,7 @@ namespace NetworkStateManagement
 		/// </summary>
 		protected override void Draw(GameTime gameTime)
 		{
-			graphics.GraphicsDevice.Clear(Color.Black);
+			graphicsDeviceManager.GraphicsDevice.Clear(Color.Black);
 
 			// The real drawing happens inside the screen manager component.
 			base.Draw(gameTime);

+ 2 - 1
NetworkStateManagement/Core/Networking/NetworkBusyScreen.cs

@@ -6,10 +6,11 @@
 //-----------------------------------------------------------------------------
 
 using System;
+using System.Threading;
+using System.Threading.Tasks;
 using Microsoft.Xna.Framework;
 using Microsoft.Xna.Framework.Content;
 using Microsoft.Xna.Framework.Graphics;
-using System.Threading.Tasks;
 using Microsoft.Xna.Framework.Input;
 
 

+ 8 - 6
NetworkStateManagement/Core/Screens/MenuEntry.cs

@@ -103,9 +103,10 @@ namespace NetworkStateManagement
         {
             // there is no such thing as a selected item on Windows Phone, so we always
             // force isSelected to be false
-#if MOBILE
-            isSelected = false;
-#endif
+            if (UIUtility.IsMobile)
+            {
+                isSelected = false;
+            }
 
             // When the menu selection changes, entries gradually fade between
             // their selected and deselected appearance, rather than instantly
@@ -126,9 +127,10 @@ namespace NetworkStateManagement
         {
             // there is no such thing as a selected item on Windows Phone, so we always
             // force isSelected to be false
-#if MOBILE
-            isSelected = false;
-#endif
+            if (UIUtility.IsMobile)
+            {
+                isSelected = false;
+            }
 
             // Draw the selected entry in yellow, otherwise white.
             Color color = isSelected ? Color.Yellow : Color.White;

+ 27 - 0
NetworkStateManagement/Core/Utils/UIUtility.cs

@@ -0,0 +1,27 @@
+//-----------------------------------------------------------------------------
+// UIUtilty.cs
+//
+// Microsoft XNA Community Game Platform
+// Copyright (C) Microsoft Corporation. All rights reserved.
+//-----------------------------------------------------------------------------
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace NetworkStateManagement
+{
+    public static class UIUtility
+    {
+        /// <summary>
+        /// Indicates if the game is running on a mobile platform.
+        /// </summary>
+        public readonly static bool IsMobile = OperatingSystem.IsAndroid() || OperatingSystem.IsIOS();
+
+        /// <summary>
+        /// Indicates if the game is running on a desktop platform.
+        /// </summary>
+        public readonly static bool IsDesktop = OperatingSystem.IsMacOS() || OperatingSystem.IsLinux() || OperatingSystem.IsWindows();
+
+    }
+}