PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/MonoGame.Framework/DesktopGL/GamerServices/Guide.cs

http://github.com/mono/MonoGame
C# | 330 lines | 199 code | 40 blank | 91 comment | 18 complexity | ccfaced4a04fad7190ec4dad1c63fa7d MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. #region License
  2. /*
  3. Microsoft Public License (Ms-PL)
  4. MonoGame - Copyright © 2009 The MonoGame Team
  5. All rights reserved.
  6. This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
  7. accept the license, do not use the software.
  8. 1. Definitions
  9. The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under
  10. U.S. copyright law.
  11. A "contribution" is the original software, or any additions or changes to the software.
  12. A "contributor" is any person that distributes its contribution under this license.
  13. "Licensed patents" are a contributor's patent claims that read directly on its contribution.
  14. 2. Grant of Rights
  15. (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
  16. each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
  17. (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
  18. each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
  19. 3. Conditions and Limitations
  20. (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
  21. (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
  22. your patent license from such contributor to the software ends automatically.
  23. (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
  24. notices that are present in the software.
  25. (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
  26. a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
  27. code form, you may only do so under a license that complies with this license.
  28. (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
  29. or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
  30. permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
  31. purpose and non-infringement.
  32. */
  33. #endregion License
  34. #region Using clause
  35. using System;
  36. using System.Collections;
  37. using System.Collections.Generic;
  38. using System.Linq;
  39. using System.Threading;
  40. using System.Runtime.Remoting.Messaging;
  41. using Microsoft.Xna.Framework.Net;
  42. #endregion Using clause
  43. namespace Microsoft.Xna.Framework.GamerServices
  44. {
  45. public static class Guide
  46. {
  47. private static bool isScreenSaverEnabled;
  48. private static bool isTrialMode;
  49. private static bool isVisible;
  50. private static bool simulateTrialMode;
  51. delegate string ShowKeyboardInputDelegate(
  52. PlayerIndex player,
  53. string title,
  54. string description,
  55. string defaultText,
  56. bool usePasswordMode);
  57. public static string ShowKeyboardInput(
  58. PlayerIndex player,
  59. string title,
  60. string description,
  61. string defaultText,
  62. bool usePasswordMode)
  63. {
  64. throw new NotImplementedException();
  65. }
  66. public static IAsyncResult BeginShowKeyboardInput (
  67. PlayerIndex player,
  68. string title,
  69. string description,
  70. string defaultText,
  71. AsyncCallback callback,
  72. Object state)
  73. {
  74. return BeginShowKeyboardInput(player, title, description, defaultText, callback, state, false );
  75. }
  76. public static IAsyncResult BeginShowKeyboardInput (
  77. PlayerIndex player,
  78. string title,
  79. string description,
  80. string defaultText,
  81. AsyncCallback callback,
  82. Object state,
  83. bool usePasswordMode)
  84. {
  85. return BeginShowKeyboardInput(player, title, description, defaultText, callback, state, false );
  86. }
  87. public static string EndShowKeyboardInput (IAsyncResult result)
  88. {
  89. ShowKeyboardInputDelegate ski = (ShowKeyboardInputDelegate)result.AsyncState;
  90. return ski.EndInvoke(result);
  91. }
  92. delegate Nullable<int> ShowMessageBoxDelegate( string title,
  93. string text,
  94. IEnumerable<string> buttons,
  95. int focusButton,
  96. MessageBoxIcon icon);
  97. public static Nullable<int> ShowMessageBox( string title,
  98. string text,
  99. IEnumerable<string> buttons,
  100. int focusButton,
  101. MessageBoxIcon icon)
  102. {
  103. int? result = null;
  104. IsVisible = true;
  105. IsVisible = false;
  106. return result;
  107. }
  108. public static IAsyncResult BeginShowMessageBox(
  109. PlayerIndex player,
  110. string title,
  111. string text,
  112. IEnumerable<string> buttons,
  113. int focusButton,
  114. MessageBoxIcon icon,
  115. AsyncCallback callback,
  116. Object state
  117. )
  118. {
  119. if (IsVisible)
  120. throw new Exception("The function cannot be completed at this time: the Guide UI is already active. Wait until Guide.IsVisible is false before issuing this call.");
  121. if (player != PlayerIndex.One)
  122. throw new ArgumentOutOfRangeException("player", "Specified argument was out of the range of valid values.");
  123. if (title == null)
  124. throw new ArgumentNullException("title", "This string cannot be null or empty, and must be less than 256 characters long.");
  125. if (text == null)
  126. throw new ArgumentNullException("text", "This string cannot be null or empty, and must be less than 256 characters long.");
  127. if (buttons == null)
  128. throw new ArgumentNullException("buttons", "Value can not be null.");
  129. ShowMessageBoxDelegate smb = ShowMessageBox;
  130. return smb.BeginInvoke(title, text, buttons, focusButton, icon, callback, smb);
  131. }
  132. public static IAsyncResult BeginShowMessageBox (
  133. string title,
  134. string text,
  135. IEnumerable<string> buttons,
  136. int focusButton,
  137. MessageBoxIcon icon,
  138. AsyncCallback callback,
  139. Object state
  140. )
  141. {
  142. return BeginShowMessageBox(PlayerIndex.One, title, text, buttons, focusButton, icon, callback, state);
  143. }
  144. public static Nullable<int> EndShowMessageBox (IAsyncResult result)
  145. {
  146. return ((ShowMessageBoxDelegate)result.AsyncState).EndInvoke(result);
  147. }
  148. public static void ShowMarketplace (PlayerIndex player )
  149. {
  150. }
  151. public static void Show ()
  152. {
  153. ShowSignIn(1, false);
  154. }
  155. public static void ShowSignIn (int paneCount, bool onlineOnly)
  156. {
  157. if ( paneCount != 1 && paneCount != 2 && paneCount != 4)
  158. {
  159. new ArgumentException("paneCount Can only be 1, 2 or 4 on Windows");
  160. return;
  161. }
  162. Microsoft.Xna.Framework.GamerServices.MonoGameGamerServicesHelper.ShowSigninSheet();
  163. if (GamerServicesComponent.LocalNetworkGamer == null)
  164. {
  165. GamerServicesComponent.LocalNetworkGamer = new LocalNetworkGamer();
  166. }
  167. else
  168. {
  169. GamerServicesComponent.LocalNetworkGamer.SignedInGamer.BeginAuthentication(null, null);
  170. }
  171. }
  172. public static void ShowLeaderboard()
  173. {
  174. //if ( ( Gamer.SignedInGamers.Count > 0 ) && ( Gamer.SignedInGamers[0].IsSignedInToLive ) )
  175. //{
  176. // // Lazy load it
  177. // if ( leaderboardController == null )
  178. // {
  179. // leaderboardController = new GKLeaderboardViewController();
  180. // }
  181. // if (leaderboardController != null)
  182. // {
  183. // leaderboardController.DidFinish += delegate(object sender, EventArgs e)
  184. // {
  185. // leaderboardController.DismissModalViewControllerAnimated(true);
  186. // isVisible = false;
  187. // };
  188. // if (Window !=null)
  189. // {
  190. // if(viewController == null)
  191. // {
  192. // viewController = new UIViewController();
  193. // Window.Add(viewController.View);
  194. // viewController.View.Hidden = true;
  195. // }
  196. // viewController.PresentModalViewController(leaderboardController, true);
  197. // isVisible = true;
  198. // }
  199. // }
  200. //}
  201. }
  202. public static void ShowAchievements()
  203. {
  204. //if ( ( Gamer.SignedInGamers.Count > 0 ) && ( Gamer.SignedInGamers[0].IsSignedInToLive ) )
  205. //{
  206. // // Lazy load it
  207. // if ( achievementController == null )
  208. // {
  209. // achievementController = new GKAchievementViewController();
  210. // }
  211. // if (achievementController != null)
  212. // {
  213. // achievementController.DidFinish += delegate(object sender, EventArgs e)
  214. // {
  215. // leaderboardController.DismissModalViewControllerAnimated(true);
  216. // isVisible = false;
  217. // };
  218. // if (Window !=null)
  219. // {
  220. // if(viewController == null)
  221. // {
  222. // viewController = new UIViewController();
  223. // Window.Add(viewController.View);
  224. // viewController.View.Hidden = true;
  225. // }
  226. // viewController.PresentModalViewController(achievementController, true);
  227. // isVisible = true;
  228. // }
  229. // }
  230. //}
  231. }
  232. #region Properties
  233. public static bool IsScreenSaverEnabled
  234. {
  235. get
  236. {
  237. return isScreenSaverEnabled;
  238. }
  239. set
  240. {
  241. isScreenSaverEnabled = value;
  242. }
  243. }
  244. public static bool IsTrialMode
  245. {
  246. get
  247. {
  248. return simulateTrialMode || isTrialMode;
  249. }
  250. }
  251. public static bool IsVisible
  252. {
  253. get
  254. {
  255. return isVisible;
  256. }
  257. set
  258. {
  259. isVisible = value;
  260. }
  261. }
  262. public static bool SimulateTrialMode
  263. {
  264. get
  265. {
  266. return simulateTrialMode;
  267. }
  268. set
  269. {
  270. simulateTrialMode = value;
  271. }
  272. }
  273. public static GameWindow Window
  274. {
  275. get;
  276. set;
  277. }
  278. #endregion
  279. internal static void Initialise(Game game)
  280. {
  281. MonoGameGamerServicesHelper.Initialise(game);
  282. }
  283. }
  284. }