LevelSelectScreen.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //-----------------------------------------------------------------------------
  2. // LevelSelectScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using Microsoft.Xna.Framework;
  8. using Microsoft.Xna.Framework.Content;
  9. using Microsoft.Xna.Framework.Graphics;
  10. using UserInterfaceSample.Controls;
  11. namespace UserInterfaceSample
  12. {
  13. public class LevelInfo
  14. {
  15. public string Name;
  16. public string Description;
  17. public string Image;
  18. }
  19. // This class demonstrates the PageFlipControl, by letting the player choose from a
  20. // set of game levels. Each level is shown with an
  21. public class LevelSelectScreen : SingleControlScreen
  22. {
  23. // Descriptions of the different levels.
  24. LevelInfo[] LevelInfos = new LevelInfo[] {
  25. new LevelInfo
  26. {
  27. Name="House",
  28. Description="Find a way out of your house--if you dare!",
  29. Image="Levels\\House"
  30. },
  31. new LevelInfo
  32. {
  33. Name="Pasture",
  34. Description="Locate your magical cow",
  35. Image="Levels\\Pasture"
  36. },
  37. new LevelInfo
  38. {
  39. Name="Hills",
  40. Description="Graze across the hills",
  41. Image="Levels\\Hills"
  42. },
  43. new LevelInfo
  44. {
  45. Name="Castle",
  46. Description="Explore the old ruined castle",
  47. Image="Levels\\Castle"
  48. },
  49. new LevelInfo
  50. {
  51. Name="Dungeon",
  52. Description="Conquer the dreaded Dungeon Critter",
  53. Image="Levels\\Dungeon"
  54. },
  55. };
  56. public override void LoadContent()
  57. {
  58. EnabledGestures = PageFlipTracker.GesturesNeeded;
  59. ContentManager content = ScreenManager.Game.Content;
  60. RootControl = new PageFlipControl();
  61. foreach (LevelInfo info in LevelInfos)
  62. {
  63. RootControl.AddChild(new LevelDescriptionPanel(content, info));
  64. }
  65. }
  66. }
  67. public class LevelDescriptionPanel : PanelControl
  68. {
  69. const float MarginLeft = 20;
  70. const float MarginTop = 20;
  71. const float DescriptionTop = 440;
  72. public LevelDescriptionPanel(ContentManager content, LevelInfo info)
  73. {
  74. Texture2D backgroundTexture = content.Load<Texture2D>(info.Image);
  75. ImageControl background = new ImageControl(backgroundTexture, Vector2.Zero);
  76. AddChild(background);
  77. SpriteFont titleFont = content.Load<SpriteFont>("Font\\MenuTitle");
  78. TextControl title = new TextControl(info.Name, titleFont, Color.Black, new Vector2(MarginLeft, MarginTop));
  79. AddChild(title);
  80. SpriteFont descriptionFont = content.Load<SpriteFont>("Font\\MenuDetail");
  81. TextControl description = new TextControl(info.Description, descriptionFont, Color.Black, new Vector2(MarginLeft, DescriptionTop));
  82. AddChild(description);
  83. }
  84. }
  85. }