* 1.0.1.9 - 5/20/2013
* - Adding mono support * * 1.0.1.10 - 11/29/2014 * - Adding prompt factory class to generate a Final Fantasy type text prompt * - Updating Gleed2D support to work with latest version of Gleed2D
This commit is contained in:
@@ -12,8 +12,15 @@ using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using GameStateManagement;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using Axios.Engine.Gleed2D;
|
||||
using Axios.Engine.Extensions;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using Gleed2D.InGame;
|
||||
using Axios.Engine.File;
|
||||
using System.Xml.Linq;
|
||||
using Gleed2D.Core;
|
||||
using System.Diagnostics;
|
||||
using Axios.Engine.Gleed2D;
|
||||
|
||||
namespace Axios.Engine
|
||||
{
|
||||
@@ -36,6 +43,12 @@ namespace Axios.Engine
|
||||
private List<AxiosTimer> _timers;
|
||||
private List<AxiosUIObject> _uiobjects;
|
||||
|
||||
protected Dictionary<string, PathItem> PathItems = new Dictionary<string, PathItem>();
|
||||
protected Dictionary<string, TextureItem> TextureItems = new Dictionary<string, TextureItem>();
|
||||
//protected List<TextureItem> TextureItems = new List<TextureItem>();
|
||||
|
||||
protected Dictionary<string, Texture2D> cache = new Dictionary<string, Texture2D>();
|
||||
|
||||
private AxiosUIObject prevuiobj;
|
||||
private AxiosUIObject prevuifocusobj;
|
||||
|
||||
@@ -68,6 +81,56 @@ namespace Axios.Engine
|
||||
|
||||
}
|
||||
|
||||
public void LoadLevelFromStream(Stream s)
|
||||
{
|
||||
XElement xml = XElement.Load(s);
|
||||
Level level = LevelLoader.Load(xml);
|
||||
this.Level = level;
|
||||
|
||||
foreach (Layer layer in level.Layers)
|
||||
{
|
||||
foreach (LayerItem item in layer.Items)
|
||||
{
|
||||
//Debug.WriteLine(item.PropertyType);
|
||||
switch (item.PropertyType)
|
||||
{
|
||||
case "Gleed2D.InGame.PathItemProperties":
|
||||
this.LoadPathItem((PathItemProperties)item.Properties, layer);
|
||||
break;
|
||||
case "Gleed2D.InGame.TextureItemProperties":
|
||||
this.LoadTextureItem((TextureItemProperties)item.Properties, layer);
|
||||
break;
|
||||
case "Gleed2D.InGame.RectangleItemProperties":
|
||||
this.LoadRectangleItem((RectangleItemProperties)item.Properties, layer);
|
||||
break;
|
||||
case "Gleed2D.InGame.CircleItemProperties":
|
||||
this.LoadCircleItem((CircleItemProperties)item.Properties, layer);
|
||||
break;
|
||||
default:
|
||||
this.LoadOtherItem(item.Properties, item.PropertyType, layer);
|
||||
break;
|
||||
}
|
||||
/*Debug.WriteLine(item.Properties.Id);
|
||||
Debug.WriteLine(item.Properties.Name);
|
||||
Debug.WriteLine(item.PropertyType);*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadLevelFromFile(string s)
|
||||
{
|
||||
AxiosTitleFile file = new AxiosTitleFile(s);
|
||||
this.LoadLevelFromStream(file.GetStream(FileMode.Open));
|
||||
}
|
||||
|
||||
public void LoadLevelFromGZFile(string s)
|
||||
{
|
||||
AxiosTitleFile file = new AxiosTitleFile(s);
|
||||
GZipStream zipstream = new GZipStream(file.GetStream(FileMode.Open), CompressionMode.Decompress);
|
||||
this.LoadLevelFromStream(zipstream);
|
||||
}
|
||||
|
||||
public Vector2 MouseAimVector(MouseState ms, Vector2 relativeposition)
|
||||
{
|
||||
Vector2 ret;
|
||||
@@ -234,10 +297,16 @@ namespace Axios.Engine
|
||||
foreach (Layer layer in Level.Layers)
|
||||
{
|
||||
Vector2 oldcameraposition = camera.Position;
|
||||
camera.Position *= layer.ScrollSpeed;
|
||||
//camera.Position *= layer.ScrollSpeed;
|
||||
|
||||
ScreenManager.SpriteBatch.Begin(0, null, null, null, null, null, Camera.View);
|
||||
layer.draw(ScreenManager.SpriteBatch);
|
||||
foreach (TextureItem i in TextureItems.Values)
|
||||
{
|
||||
if (i.LayerItem.Visible == true)
|
||||
{
|
||||
i.draw(ScreenManager.SpriteBatch);
|
||||
}
|
||||
}
|
||||
ScreenManager.SpriteBatch.End();
|
||||
|
||||
camera.Position = oldcameraposition;
|
||||
@@ -250,6 +319,8 @@ namespace Axios.Engine
|
||||
foreach(AxiosUIObject g in (from x in _uiobjects orderby x.DrawOrder select x))
|
||||
((IDrawableAxiosGameObject)g).Draw(this, gameTime);
|
||||
|
||||
|
||||
|
||||
base.Draw(gameTime); //This is placed at the end so that Farseer debug information is visible
|
||||
|
||||
}
|
||||
@@ -459,25 +530,31 @@ namespace Axios.Engine
|
||||
/// </summary>
|
||||
/// <param name="circleitem"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool LoadCircleItem(CircleItem circleitem)
|
||||
public virtual void LoadCircleItem(CircleItemProperties circleitem, Layer l)
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public virtual bool LoadPathItem(PathItem pathitem)
|
||||
public virtual void LoadPathItem(PathItemProperties pathitem, Layer l)
|
||||
{
|
||||
return true;
|
||||
PathItem p = new PathItem((PathItemProperties)pathitem);
|
||||
p.load(this, ref cache);
|
||||
PathItems[pathitem.Name] = p;
|
||||
}
|
||||
|
||||
public virtual bool LoadRectangleItem(RectangleItem rectangleitem)
|
||||
public virtual void LoadRectangleItem(RectangleItemProperties rectangleitem, Layer l)
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
public virtual bool LoadTextureItem(TextureItem textureitem)
|
||||
public virtual void LoadTextureItem(TextureItemProperties textureitem, Layer l)
|
||||
{
|
||||
return true;
|
||||
TextureItem i = new TextureItem((TextureItemProperties)textureitem);
|
||||
i.load(this, ref cache);
|
||||
TextureItems[textureitem.Name] = i;
|
||||
}
|
||||
|
||||
public virtual void LoadOtherItem(ItemProperties prop, string type, Layer l) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -8,48 +8,19 @@ using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using FarseerPhysics.Dynamics;
|
||||
using Gleed2D.InGame;
|
||||
|
||||
namespace Axios.Engine.Gleed2D
|
||||
{
|
||||
[XmlInclude(typeof(TextureItem))]
|
||||
[XmlInclude(typeof(RectangleItem))]
|
||||
[XmlInclude(typeof(CircleItem))]
|
||||
[XmlInclude(typeof(PathItem))]
|
||||
public partial class Item
|
||||
public class Item
|
||||
{
|
||||
/// <summary>
|
||||
/// The name of this item.
|
||||
/// </summary>
|
||||
[XmlAttribute()]
|
||||
public String Name;
|
||||
|
||||
/// <summary>
|
||||
/// Should this item be visible?
|
||||
/// </summary>
|
||||
[XmlAttribute()]
|
||||
public bool Visible;
|
||||
|
||||
/// <summary>
|
||||
/// The item's position in world space.
|
||||
/// </summary>
|
||||
public Vector2 Position;
|
||||
|
||||
/// <summary>
|
||||
/// A Dictionary containing any user-defined Properties.
|
||||
/// </summary>
|
||||
public SerializableDictionary CustomProperties;
|
||||
|
||||
|
||||
public Item()
|
||||
{
|
||||
CustomProperties = new SerializableDictionary();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by Level.FromFile(filename) on each Item after the deserialization process.
|
||||
/// Should be overriden and can be used to load anything needed by the Item (e.g. a texture).
|
||||
/// </summary>
|
||||
public virtual void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache, Layer layer)
|
||||
public virtual void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache)
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -9,36 +9,39 @@ using FarseerPhysics.Factories;
|
||||
using Microsoft.Xna.Framework.Content;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Gleed2D.InGame;
|
||||
|
||||
namespace Axios.Engine.Gleed2D
|
||||
{
|
||||
public partial class PathItem : Item
|
||||
public class PathItem : Item
|
||||
{
|
||||
public Vector2[] LocalPoints;
|
||||
public Vector2[] WorldPoints;
|
||||
public bool IsPolygon;
|
||||
public int LineWidth;
|
||||
public Color LineColor;
|
||||
private PathItemProperties _item;
|
||||
|
||||
public PathItemProperties LayerItem
|
||||
{
|
||||
get { return _item; }
|
||||
set { }
|
||||
}
|
||||
|
||||
Body _body;
|
||||
|
||||
public PathItem()
|
||||
public PathItem(PathItemProperties i)
|
||||
{
|
||||
this._item = i;
|
||||
}
|
||||
|
||||
public override void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache, Layer layer)
|
||||
public override void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache)
|
||||
{
|
||||
base.load(gameScreen, ref cache, layer);
|
||||
if (gameScreen.LoadPathItem(this))
|
||||
{
|
||||
Vertices v = new Vertices(LocalPoints.Length);
|
||||
foreach (Vector2 vec in LocalPoints)
|
||||
v.Add(new Vector2(ConvertUnits.ToSimUnits(vec.X), ConvertUnits.ToSimUnits(vec.Y)));
|
||||
base.load(gameScreen, ref cache);
|
||||
|
||||
Vertices v = new Vertices(LayerItem.LocalPoints.Count);
|
||||
foreach (Vector2 vec in LayerItem.LocalPoints)
|
||||
v.Add(new Vector2(ConvertUnits.ToSimUnits(vec.X), ConvertUnits.ToSimUnits(vec.Y)));
|
||||
|
||||
_body = BodyFactory.CreateLoopShape(gameScreen.World, v);
|
||||
_body.Position = ConvertUnits.ToSimUnits(this.Position);
|
||||
_body.UserData = this;
|
||||
}
|
||||
_body = BodyFactory.CreateLoopShape(gameScreen.World, v);
|
||||
_body.Position = ConvertUnits.ToSimUnits(this.LayerItem.Position);
|
||||
_body.UserData = this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -12,65 +12,25 @@ using FarseerPhysics.Dynamics;
|
||||
using FarseerPhysics.Common;
|
||||
using FarseerPhysics.SamplesFramework;
|
||||
using FarseerPhysics.Factories;
|
||||
using Gleed2D.InGame;
|
||||
|
||||
namespace Axios.Engine.Gleed2D
|
||||
{
|
||||
public partial class TextureItem : Item
|
||||
{
|
||||
/// <summary>
|
||||
/// The item's rotation in radians.
|
||||
/// </summary>
|
||||
public float Rotation;
|
||||
|
||||
/// <summary>
|
||||
/// The item's scale factor.
|
||||
/// </summary>
|
||||
public Vector2 Scale;
|
||||
|
||||
/// <summary>
|
||||
/// The color to tint the item's texture with (use white for no tint).
|
||||
/// </summary>
|
||||
public Color TintColor;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the texture is flipped horizontally when drawn.
|
||||
/// </summary>
|
||||
public bool FlipHorizontally;
|
||||
|
||||
/// <summary>
|
||||
/// If true, the texture is flipped vertically when drawn.
|
||||
/// </summary>
|
||||
public bool FlipVertically;
|
||||
|
||||
/// <summary>
|
||||
/// The path to the texture's filename (including the extension) relative to ContentRootFolder.
|
||||
/// </summary>
|
||||
public String texture_filename;
|
||||
|
||||
/// <summary>
|
||||
/// The texture_filename without extension. For using in Content.Load<Texture2D>().
|
||||
/// </summary>
|
||||
public String asset_name;
|
||||
|
||||
/// <summary>
|
||||
/// The XNA texture to be drawn. Can be loaded either from file (using "texture_filename")
|
||||
/// or via the Content Pipeline (using "asset_name") - then you must ensure that the texture
|
||||
/// exists as an asset in your project.
|
||||
/// Loading is done in the Item's load() method.
|
||||
/// </summary>
|
||||
public Texture2D texture;
|
||||
|
||||
/// <summary>
|
||||
/// The item's origin relative to the upper left corner of the texture. Usually the middle of the texture.
|
||||
/// Used for placing and rotating the texture when drawn.
|
||||
/// </summary>
|
||||
public Vector2 Origin;
|
||||
private TextureItemProperties _item;
|
||||
|
||||
public Layer Layer;
|
||||
|
||||
|
||||
public TextureItem()
|
||||
public TextureItemProperties LayerItem
|
||||
{
|
||||
get { return _item; }
|
||||
set { }
|
||||
}
|
||||
|
||||
public TextureItem(TextureItemProperties i)
|
||||
{
|
||||
this._item = i;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -79,22 +39,21 @@ namespace Axios.Engine.Gleed2D
|
||||
/// You must provide your own implementation. However, you can rely on all public fields being
|
||||
/// filled by the level deserialization process.
|
||||
/// </summary>
|
||||
public override void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache, Layer layer)
|
||||
public override void load(AxiosGameScreen gameScreen, ref Dictionary<string, Texture2D> cache)
|
||||
{
|
||||
this.Layer = layer;
|
||||
base.load(gameScreen, ref cache, layer);
|
||||
base.load(gameScreen, ref cache);
|
||||
//throw new NotImplementedException();
|
||||
|
||||
//TODO: provide your own implementation of how a TextureItem loads its assets
|
||||
//for example:
|
||||
//this.texture = Texture2D.FromFile(<GraphicsDevice>, texture_filename);
|
||||
//or by using the Content Pipeline:
|
||||
if (!cache.ContainsKey(asset_name))
|
||||
if (!cache.ContainsKey(LayerItem.AssetName))
|
||||
{
|
||||
cache[asset_name] = gameScreen.ScreenManager.Game.Content.Load<Texture2D>(asset_name);
|
||||
cache[LayerItem.AssetName] = gameScreen.ScreenManager.Game.Content.Load<Texture2D>(LayerItem.AssetName);
|
||||
}
|
||||
this.texture = cache[asset_name];
|
||||
Visible = gameScreen.LoadTextureItem(this);
|
||||
this.texture = cache[LayerItem.AssetName];
|
||||
//Visible = gameScreen.LoadTextureItem(this);
|
||||
|
||||
//this.texture = cm.Load<Texture2D>(asset_name);
|
||||
|
||||
@@ -102,11 +61,11 @@ namespace Axios.Engine.Gleed2D
|
||||
|
||||
public override void draw(SpriteBatch sb)
|
||||
{
|
||||
if (!Visible) return;
|
||||
if (!LayerItem.Visible) return;
|
||||
SpriteEffects effects = SpriteEffects.None;
|
||||
if (FlipHorizontally) effects |= SpriteEffects.FlipHorizontally;
|
||||
if (FlipVertically) effects |= SpriteEffects.FlipVertically;
|
||||
sb.Draw(texture, Position, null, TintColor, Rotation, Origin, Scale, effects, 0);
|
||||
if (LayerItem.FlipHorizontally) effects |= SpriteEffects.FlipHorizontally;
|
||||
if (LayerItem.FlipVertically) effects |= SpriteEffects.FlipVertically;
|
||||
sb.Draw(texture, LayerItem.Position, null, LayerItem.TintColor, LayerItem.Rotation, LayerItem.Origin, LayerItem.Scale, effects, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user