//--------------------------------------------------------------------------------------------------------------------------------------------------- // // Copyright (C)2007 DarkWynter Studios. All rights reserved. // //--------------------------------------------------------------------------------------------------------------------------------------------------- // {Contact : darkwynter.com for licensing information //--------------------------------------------------------------------------------------------------------------------------------------------------- namespace DW.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 DW.Menus.GameScreens; using DW.Globals; /// /// Controls all of the menu screens and menu items, Uses Enums to switch between game screens /// 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); Generic 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 Generic(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 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(); } public List GetProperties() { // Concatenate all ScreenMenu Lists and return List args = new List(); for (int i = 0; i < gameScreens.Count; i++) { args.AddRange(gameScreens[i].GetProperties()); } return args; } public string GetProperty(string propertyName) { List properties = GetProperties(); for (int i = 0; i < properties.Count; i++) if (properties[i].title == propertyName) return properties[i].value; return null; } } }