//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DarkWynter.Engine.Menus { #region Using Statements using System; using System.Collections.Generic; using System.Diagnostics; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; using System.Threading; using System.Xml; #endregion // using Utilities; using Menus; using DarkWynter.Engine.Menus.GameScreens; using DWGame.Globals; /// /// Controls all of the menu screen and menu items /// public class MenuSystem { private Color _backColor = Color.TransparentBlack; public Color backColor { get { return _backColor; } set { _backColor = value; } } /// /// List of menu screens /// public List gameScreens = new List(); /// /// Constructor /// public MenuSystem(string filename) { LoadScreens(filename); } private void LoadScreens(string filename) { try { // Load the HUD Images, Text, and Values XmlDocument reader = new XmlDocument(); reader.Load(filename); GenericGameScreen ggs; XmlNodeList allNodes = reader.ChildNodes; foreach (XmlNode eventNode in allNodes) { if (eventNode.Name == "MenuScreens") { XmlNodeList eventNodes = eventNode.ChildNodes; foreach (XmlNode node in eventNodes) { if (node.Name == "MenuScreen") { gameScreens.Add(ggs = new GenericGameScreen(node)); } } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Error reading xml"); throw e; } } /// /// Updates the controller and then the current active screen /// public virtual void Update() { for (int i = 0; i < gameScreens.Count; i++) { // Update appropriate menu screen if (Statics.menuState == gameScreens[i].GetEngineState()) { gameScreens[i].Update(); break; } } } /// /// Draws the appropriate screen /// /// SpriteBatch used to draw /// Current ScreenSaver public virtual void Draw(SpriteBatch spriteBatch) { // Begin Sprite Batching for Menusystem spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None); for (int i = 0; i < gameScreens.Count; i++) { // Update appropriate menu screen if (Statics.menuState == gameScreens[i].GetEngineState()) { gameScreens[i].Draw(spriteBatch); break; } } spriteBatch.End(); } } }