PageRenderTime 225ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/MonoGame.Framework/Windows/GamerServices/Guide.cs

https://github.com/notJUSTguitar/MonoGame
C# | 375 lines | 219 code | 53 blank | 103 comment | 8 complexity | aaabe17d4b92459c9f5312a7067c7159 MD5 | raw file
  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. using Microsoft.Xna.Framework.Storage;
  43. #endregion Using clause
  44. namespace Microsoft.Xna.Framework.GamerServices
  45. {
  46. public static class Guide
  47. {
  48. private static bool isScreenSaverEnabled;
  49. private static bool isTrialMode;
  50. private static bool isVisible;
  51. private static bool simulateTrialMode;
  52. delegate string ShowKeyboardInputDelegate(
  53. PlayerIndex player,
  54. string title,
  55. string description,
  56. string defaultText,
  57. bool usePasswordMode);
  58. public static string ShowKeyboardInput(
  59. PlayerIndex player,
  60. string title,
  61. string description,
  62. string defaultText,
  63. bool usePasswordMode)
  64. {
  65. string result = defaultText;
  66. //TextFieldAlertView myAlertView = new TextFieldAlertView(usePasswordMode, title, defaultText);
  67. //myAlertView.Title = title;
  68. //myAlertView.Message = description;
  69. //myAlertView.Clicked += delegate(object sender, UIButtonEventArgs e)
  70. // {
  71. // if (e.ButtonIndex == 1)
  72. // {
  73. // result = ((UIAlertView) sender).Subviews.OfType<UITextField>().Single().Text;
  74. // }
  75. // };
  76. //myAlertView.Transform = MonoTouch.CoreGraphics.CGAffineTransform.MakeTranslation (0f, 110f);
  77. //myAlertView.Show();
  78. return result;
  79. }
  80. public static IAsyncResult BeginShowKeyboardInput (
  81. PlayerIndex player,
  82. string title,
  83. string description,
  84. string defaultText,
  85. AsyncCallback callback,
  86. Object state)
  87. {
  88. return BeginShowKeyboardInput(player, title, description, defaultText, callback, state, false );
  89. }
  90. public static IAsyncResult BeginShowKeyboardInput (
  91. PlayerIndex player,
  92. string title,
  93. string description,
  94. string defaultText,
  95. AsyncCallback callback,
  96. Object state,
  97. bool usePasswordMode)
  98. {
  99. isVisible = true;
  100. ShowKeyboardInputDelegate ski = ShowKeyboardInput;
  101. return ski.BeginInvoke(player, title, description, defaultText, usePasswordMode, callback, ski);
  102. }
  103. public static string EndShowKeyboardInput (IAsyncResult result)
  104. {
  105. try
  106. {
  107. ShowKeyboardInputDelegate ski = (ShowKeyboardInputDelegate)result.AsyncState;
  108. return ski.EndInvoke(result);
  109. }
  110. finally
  111. {
  112. isVisible = false;
  113. }
  114. }
  115. delegate Nullable<int> ShowMessageBoxDelegate( string title,
  116. string text,
  117. IEnumerable<string> buttons,
  118. int focusButton,
  119. MessageBoxIcon icon);
  120. public static Nullable<int> ShowMessageBox( string title,
  121. string text,
  122. IEnumerable<string> buttons,
  123. int focusButton,
  124. MessageBoxIcon icon)
  125. {
  126. Nullable<int> result = null;
  127. return result;
  128. }
  129. public static IAsyncResult BeginShowMessageBox(
  130. PlayerIndex player,
  131. string title,
  132. string text,
  133. IEnumerable<string> buttons,
  134. int focusButton,
  135. MessageBoxIcon icon,
  136. AsyncCallback callback,
  137. Object state
  138. )
  139. {
  140. isVisible = true;
  141. ShowMessageBoxDelegate smb = ShowMessageBox;
  142. return smb.BeginInvoke(title, text, buttons, focusButton, icon, callback, smb);
  143. }
  144. public static IAsyncResult BeginShowMessageBox (
  145. string title,
  146. string text,
  147. IEnumerable<string> buttons,
  148. int focusButton,
  149. MessageBoxIcon icon,
  150. AsyncCallback callback,
  151. Object state
  152. )
  153. {
  154. return BeginShowMessageBox(PlayerIndex.One, title, text, buttons, focusButton, icon, callback, state);
  155. }
  156. public static Nullable<int> EndShowMessageBox (IAsyncResult result)
  157. {
  158. try
  159. {
  160. ShowMessageBoxDelegate smbd = (ShowMessageBoxDelegate)result.AsyncState;
  161. return smbd.EndInvoke(result);
  162. }
  163. finally
  164. {
  165. isVisible = false;
  166. }
  167. }
  168. public static void ShowMarketplace (PlayerIndex player )
  169. {
  170. }
  171. public static void Show ()
  172. {
  173. ShowSignIn(1, false);
  174. }
  175. public static void ShowSignIn (int paneCount, bool onlineOnly)
  176. {
  177. if ( paneCount != 1 && paneCount != 2 && paneCount != 4)
  178. {
  179. new ArgumentException("paneCount Can only be 1, 2 or 4 on Windows");
  180. return;
  181. }
  182. Microsoft.Xna.Framework.GamerServices.MonoGameGamerServicesHelper.ShowSigninSheet();
  183. if (GamerServicesComponent.LocalNetworkGamer == null)
  184. {
  185. GamerServicesComponent.LocalNetworkGamer = new LocalNetworkGamer();
  186. }
  187. else
  188. {
  189. GamerServicesComponent.LocalNetworkGamer.SignedInGamer.BeginAuthentication(null, null);
  190. }
  191. }
  192. public static void ShowLeaderboard()
  193. {
  194. //if ( ( Gamer.SignedInGamers.Count > 0 ) && ( Gamer.SignedInGamers[0].IsSignedInToLive ) )
  195. //{
  196. // // Lazy load it
  197. // if ( leaderboardController == null )
  198. // {
  199. // leaderboardController = new GKLeaderboardViewController();
  200. // }
  201. // if (leaderboardController != null)
  202. // {
  203. // leaderboardController.DidFinish += delegate(object sender, EventArgs e)
  204. // {
  205. // leaderboardController.DismissModalViewControllerAnimated(true);
  206. // isVisible = false;
  207. // };
  208. // if (Window !=null)
  209. // {
  210. // if(viewController == null)
  211. // {
  212. // viewController = new UIViewController();
  213. // Window.Add(viewController.View);
  214. // viewController.View.Hidden = true;
  215. // }
  216. // viewController.PresentModalViewController(leaderboardController, true);
  217. // isVisible = true;
  218. // }
  219. // }
  220. //}
  221. }
  222. public static void ShowAchievements()
  223. {
  224. //if ( ( Gamer.SignedInGamers.Count > 0 ) && ( Gamer.SignedInGamers[0].IsSignedInToLive ) )
  225. //{
  226. // // Lazy load it
  227. // if ( achievementController == null )
  228. // {
  229. // achievementController = new GKAchievementViewController();
  230. // }
  231. // if (achievementController != null)
  232. // {
  233. // achievementController.DidFinish += delegate(object sender, EventArgs e)
  234. // {
  235. // leaderboardController.DismissModalViewControllerAnimated(true);
  236. // isVisible = false;
  237. // };
  238. // if (Window !=null)
  239. // {
  240. // if(viewController == null)
  241. // {
  242. // viewController = new UIViewController();
  243. // Window.Add(viewController.View);
  244. // viewController.View.Hidden = true;
  245. // }
  246. // viewController.PresentModalViewController(achievementController, true);
  247. // isVisible = true;
  248. // }
  249. // }
  250. //}
  251. }
  252. public static IAsyncResult BeginShowStorageDeviceSelector( AsyncCallback callback, object state )
  253. {
  254. return null;
  255. }
  256. public static StorageDevice EndShowStorageDeviceSelector( IAsyncResult result )
  257. {
  258. return null;
  259. }
  260. #region Properties
  261. public static bool IsScreenSaverEnabled
  262. {
  263. get
  264. {
  265. return isScreenSaverEnabled;
  266. }
  267. set
  268. {
  269. isScreenSaverEnabled = value;
  270. }
  271. }
  272. public static bool IsTrialMode
  273. {
  274. get
  275. {
  276. return isTrialMode;
  277. }
  278. set
  279. {
  280. isTrialMode = value;
  281. }
  282. }
  283. public static bool IsVisible
  284. {
  285. get
  286. {
  287. return isVisible;
  288. }
  289. set
  290. {
  291. isVisible = value;
  292. }
  293. }
  294. public static bool SimulateTrialMode
  295. {
  296. get
  297. {
  298. return simulateTrialMode;
  299. }
  300. set
  301. {
  302. simulateTrialMode = value;
  303. }
  304. }
  305. public static GameWindow Window
  306. {
  307. get;
  308. set;
  309. }
  310. #endregion
  311. internal static void Initialise(Game game)
  312. {
  313. MonoGameGamerServicesHelper.Initialise(game);
  314. }
  315. }
  316. }