//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using DW.UserInterface_2D;
using System.Xml;
using Microsoft.Xna.Framework.Content;
using DWGame.Globals;
using Microsoft.Xna.Framework;
namespace DWGame.UserInterface_2D
{
public class HUDFrame
{
Viewport view;
int count;
public static List HUDList;
Texture2D horizontalBar, verticalBar;
///
/// HUDFrame is the container class for all HUDs - creates a physical container
///
/// Number of players = number of HUDs required, max size is 4
/// The viewport - needed for the frame math to place each HUD
public HUDFrame(int numPlayers, Viewport viewport)
{
count = numPlayers;
view = viewport;
HUDList = new List();
}
///
/// Adds a newly created HUD based on XML file
///
/// Number of players = number of HUDs required, max size is 4
/// Location of the XML file(s) the HUD loads from
public void add(int numPlayers, string fileName)
{
for (int x = 0; x < numPlayers; x++)
{
try
{
XmlDocument reader = new XmlDocument();
reader.Load(fileName);
HUD hud = new HUD(view);
foreach (XmlNode node in reader.ChildNodes)
{
if (node.Name == "HUDSettings")
{
hud.LoadScreenObjects(node);
}
}
HUDList.Add(hud);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Error reading xml");
throw e;
}
}
// Once the HUDs are created, call resize to juggle the pieces into place
Resize(HUDList.Count);
// Physical representation of the frame - game/HUD dividors
horizontalBar = Globals.Statics.SystemSettings.content.Load("_textures/hud/horbar");
verticalBar = Globals.Statics.SystemSettings.content.Load("_textures/hud/vertbar");
}
///
/// Find the quadrant viewport for the individual HUDS
///
public void Resize(int numPlayers)
{
// Quad Ordering (aka - HudList.Count)
//------------------
// Quad 1 | Quad 2 |
// Quad 3 | Quad 4 |
// -----------------
Rectangle viewSpace = new Rectangle();
switch (HUDList.Count)
{
case 1:
HUDList[0].Resize(new Rectangle(0, 0, view.Width, view.Height));
break;
case 2: // 2 players split vertically
HUDList[0].Resize(new Rectangle(0, 0, view.Width/2, view.Height));
HUDList[1].Resize(new Rectangle(view.Width/2, 0, view.Width/2, view.Height));
break;
case 3: // 3 player split
HUDList[0].Resize(new Rectangle(0, 0, view.Width/2, view.Height/2));
HUDList[1].Resize(new Rectangle(view.Width/2, 0, view.Width/2, view.Height/2));
HUDList[2].Resize(new Rectangle(0, view.Height/2, view.Width/2, view.Height/2));
break;
case 4: // 4 players
HUDList[0].Resize(new Rectangle(0, 0, view.Width/2, view.Height/2));
HUDList[1].Resize(new Rectangle(view.Width/2, 0, view.Width/2, view.Height/2));
HUDList[2].Resize(new Rectangle(0, view.Height/2, view.Width/2, view.Height/2));
HUDList[3].Resize(new Rectangle(view.Width/2, view.Height/2, view.Width/2, view.Height/2));
break;
default: // only one player
HUDList[0].Resize(new Rectangle(0, 0, view.Width, view.Height));
break;
}
}
public void Draw(SpriteBatch spritebatch)
{
spritebatch.Begin();
for (int x = 0; x < HUDList.Count; x++)
{
HUDList[x].Draw(spritebatch);
}
spritebatch.Draw(verticalBar, new Rectangle(view.Width / 2 - verticalBar.Width / 2, 0, verticalBar.Width, verticalBar.Height), Color.Green);
spritebatch.Draw(horizontalBar, new Rectangle(0, view.Height / 2 - horizontalBar.Height / 2, horizontalBar.Width, horizontalBar.Height), Color.Pink);
spritebatch.End();
}
}
}