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

/Big McGreed/Big McGreed/content/gameinterface/InterfaceManager.cs

http://big-mcgreed.googlecode.com/
C# | 290 lines | 179 code | 26 blank | 85 comment | 22 complexity | 9a8c1f22b5865697419866e42b55c009 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Big_McGreed.content.gameinterface.buttons;
  6. using Microsoft.Xna.Framework.Input;
  7. using Big_McGreed.logic.map;
  8. using Microsoft.Xna.Framework;
  9. using Big_McGreed.content.gameframe;
  10. using Microsoft.Xna.Framework.Graphics;
  11. using Big_McGreed.content.gameinterface.interfaces;
  12. namespace Big_McGreed.content.gameinterface
  13. {
  14. /// <summary>
  15. /// Menu v2 ^^
  16. /// </summary>
  17. public class InterfaceManager
  18. {
  19. private LinkedList<InterfaceComponent> activeComponents;
  20. /// <summary>
  21. /// Gets or sets the active interface.
  22. /// </summary>
  23. /// <value>
  24. /// The active interface.
  25. /// </value>
  26. public GameInterface activeInterface { get; set; }
  27. private bool released = false;
  28. /// <summary>
  29. /// Gets the font.
  30. /// </summary>
  31. public SpriteFont font { get; private set; }
  32. /// <summary>
  33. /// Gets the tiny font.
  34. /// </summary>
  35. public SpriteFont tinyFont { get; private set; }
  36. /// <summary>
  37. /// Gets the new game.
  38. /// </summary>
  39. public NewGame newGame { get; private set; }
  40. /// <summary>
  41. /// Gets the high score.
  42. /// </summary>
  43. public HighScoreButton highScore { get; private set; }
  44. /// <summary>
  45. /// Gets the quit.
  46. /// </summary>
  47. public Quit quit { get; private set; }
  48. /// <summary>
  49. /// Gets the upgrade.
  50. /// </summary>
  51. public UpgradeButton upgrade { get; private set; }
  52. /// <summary>
  53. /// Gets the resume.
  54. /// </summary>
  55. public Resume resume { get; private set; }
  56. /// <summary>
  57. /// Gets the menu button klein.
  58. /// </summary>
  59. public MenuButtonKlein menuButtonKlein { get; private set; }
  60. /// <summary>
  61. /// Gets the resume klein.
  62. /// </summary>
  63. public ResumeKlein resumeKlein { get; private set; }
  64. /// <summary>
  65. /// Gets the main menu.
  66. /// </summary>
  67. public MainMenu mainMenu { get; private set; }
  68. /// <summary>
  69. /// Gets the yes button.
  70. /// </summary>
  71. public YesButton yesButton { get; private set; }
  72. /// <summary>
  73. /// Gets the no button.
  74. /// </summary>
  75. public NoButton noButton { get; private set; }
  76. /// <summary>
  77. /// Gets the upgrade Eco Wall.
  78. /// </summary>
  79. public UpgradeEcoWall upgradeEcoWall { get; private set; }
  80. /// <summary>
  81. /// Gets the yes no select.
  82. /// </summary>
  83. public UpgradeEcoHelp upgradeEcoHelp { get; private set; }
  84. public UpgradeOilWall upgradeOilWall { get; private set; }
  85. public UpgradeOilHelp upgradeOilHelp { get; private set; }
  86. public UpgradeWeaponMagnum upgradeWeaponMagnum { get; private set; }
  87. public UpgradeWeaponRifle upgradeWeaponRifle { get; private set; }
  88. public UpgradeWeaponShotgun upgradeWeaponShotgun { get; private set; }
  89. public YesNoSelect yesNoSelect { get; private set; }
  90. /// <summary>
  91. /// Gets the upgrade achtergrond.
  92. /// </summary>
  93. public UpgradeAchtergrond upgradeAchtergrond { get; private set; }
  94. /// <summary>
  95. /// Gets the submit highscore.
  96. /// </summary>
  97. public SubmitHighscore submitHighscore { get; private set; }
  98. /// <summary>
  99. /// Gets the highscore display.
  100. /// </summary>
  101. public HighscoreDisplay highscoreDisplay { get; private set; }
  102. public GameOverInterface gameOverInterface { get; private set; }
  103. public Logo logo { get; private set; }
  104. public UpgradeButtonInGame upgradeButtonIG { get; private set; }
  105. /// <summary>
  106. /// Initializes a new instance of the <see cref="InterfaceManager"/> class.
  107. /// </summary>
  108. public InterfaceManager()
  109. {
  110. activeComponents = new LinkedList<InterfaceComponent>();
  111. font = Program.INSTANCE.Content.Load<SpriteFont>("ButtonFont");
  112. tinyFont = Program.INSTANCE.Content.Load<SpriteFont>("TinyButtonFont");
  113. }
  114. /// <summary>
  115. /// Initializes this instance.
  116. /// </summary>
  117. public void Initialize()
  118. {
  119. InitializeInterfaces(); //First all the interfaces.
  120. InitializeButtons(); //Second all buttons.
  121. updateButtons();
  122. }
  123. /// <summary>
  124. /// Initializes the interfaces.
  125. /// </summary>
  126. private void InitializeInterfaces() {
  127. yesNoSelect = new YesNoSelect();
  128. upgradeAchtergrond = new UpgradeAchtergrond();
  129. highscoreDisplay = new HighscoreDisplay();
  130. gameOverInterface = new GameOverInterface();
  131. logo = new Logo();
  132. }
  133. /// <summary>
  134. /// Initializes the buttons.
  135. /// </summary>
  136. private void InitializeButtons() {
  137. newGame = new NewGame();
  138. activeComponents.AddFirst(newGame);
  139. highScore = new HighScoreButton();
  140. activeComponents.AddAfter(activeComponents.Find(newGame), highScore);
  141. quit = new Quit();
  142. activeComponents.AddLast(quit);
  143. resume = new Resume();
  144. upgrade = new UpgradeButton();
  145. menuButtonKlein = new MenuButtonKlein();
  146. resumeKlein = new ResumeKlein();
  147. mainMenu = new MainMenu();
  148. yesButton = new YesButton();
  149. noButton = new NoButton();
  150. upgradeEcoWall = new UpgradeEcoWall();
  151. upgradeEcoHelp = new UpgradeEcoHelp();
  152. upgradeOilWall = new UpgradeOilWall();
  153. upgradeOilHelp = new UpgradeOilHelp();
  154. upgradeWeaponMagnum = new UpgradeWeaponMagnum();
  155. upgradeWeaponRifle = new UpgradeWeaponRifle();
  156. upgradeWeaponShotgun = new UpgradeWeaponShotgun();
  157. submitHighscore = new SubmitHighscore();
  158. upgradeButtonIG = new UpgradeButtonInGame();
  159. }
  160. /// <summary>
  161. /// Updates this instance.
  162. /// </summary>
  163. public void Update()
  164. {
  165. InterfaceComponent buttonNearMouse = null;
  166. yesNoSelect.YesNoSelectUpdate();
  167. lock (activeComponents)
  168. {
  169. Rectangle mouse = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1);
  170. foreach (InterfaceComponent button in activeComponents)
  171. {
  172. Rectangle rectangleButton = new Rectangle((int)button.Location.X, (int)button.Location.Y, button.Normal.Width, button.Normal.Height);
  173. if (PrimitivePathFinder.intersects(mouse, rectangleButton))
  174. {
  175. buttonNearMouse = button;
  176. }
  177. else
  178. {
  179. if (button.Current != button.Normal)
  180. button.Current = button.Normal;
  181. }
  182. }
  183. }
  184. switch(Mouse.GetState().LeftButton) {
  185. case ButtonState.Released:
  186. if (buttonNearMouse != null)
  187. {
  188. if (released)
  189. {
  190. buttonNearMouse.action();
  191. released = false;
  192. }
  193. else
  194. {
  195. if (buttonNearMouse.Current != buttonNearMouse.Hover)
  196. {
  197. buttonNearMouse.Current = buttonNearMouse.Hover;
  198. }
  199. }
  200. }
  201. break;
  202. case ButtonState.Pressed:
  203. if (buttonNearMouse != null)
  204. {
  205. if (buttonNearMouse.Current != buttonNearMouse.Pressed)
  206. buttonNearMouse.Current = buttonNearMouse.Pressed;
  207. released = true;
  208. }
  209. break;
  210. }
  211. }
  212. /// <summary>
  213. /// Draws this instance.
  214. /// </summary>
  215. public void Draw(SpriteBatch batch)
  216. {
  217. if (activeInterface != null)
  218. {
  219. activeInterface.Draw(batch);
  220. }
  221. lock (activeComponents)
  222. {
  223. foreach (InterfaceComponent button in activeComponents)
  224. {
  225. button.Draw(batch);
  226. }
  227. }
  228. }
  229. /// <summary>
  230. /// Gets the active components.
  231. /// </summary>
  232. /// <returns></returns>
  233. public LinkedList<InterfaceComponent> getActiveComponents()
  234. {
  235. return activeComponents;
  236. }
  237. /// <summary>
  238. /// Updates the buttons.
  239. /// </summary>
  240. public void updateButtons()
  241. {
  242. float startY;
  243. if (Program.INSTANCE.CurrentGameState == GameWorld.GameState.Menu)
  244. {
  245. startY = GameFrame.Height / 2;
  246. }
  247. else
  248. {
  249. startY = GameFrame.Height / 4;
  250. }
  251. lock (activeComponents)
  252. {
  253. foreach (InterfaceComponent button in activeComponents)
  254. {
  255. if (button != upgrade && button != resumeKlein && button != menuButtonKlein )
  256. {
  257. button.Location = new Vector2(GameFrame.Width / 2 - button.Current.Width / 2, startY);
  258. startY += button.Normal.Height + 15;
  259. }
  260. }
  261. }
  262. }
  263. }
  264. }