implemented the special drawable interface.

This commit is contained in:
Harrison Deng 2018-12-14 00:42:51 -06:00
parent 28d4f48b51
commit 4fd37b6675
3 changed files with 37 additions and 15 deletions

View File

@ -9,7 +9,7 @@ using System.Xml.Serialization;
namespace RecrownedAthenaeum.DataTypes
{
public class NinePatch
public class NinePatch : ISpecialDrawable
{
public Color color;
public Rectangle textureRegion;
@ -38,7 +38,7 @@ namespace RecrownedAthenaeum.DataTypes
color = Color.White;
}
public void Draw(SpriteBatch batch, Rectangle destination)
public void Draw(SpriteBatch spriteBatch, Rectangle destination)
{
Rectangle sourceRectangle;
Rectangle drawnRectangle;
@ -57,7 +57,7 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x1
drawnRectangle.X = destination.X + a;
@ -72,7 +72,7 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x1
drawnRectangle.X = destination.X + destination.Width - b;
@ -87,7 +87,7 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//1x2
drawnRectangle.X = destination.X;
@ -102,7 +102,7 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x2
drawnRectangle.X = destination.X + a;
@ -117,7 +117,7 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x2
drawnRectangle.X = destination.X + destination.Width - b;
@ -132,7 +132,7 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//1x3
drawnRectangle.X = destination.X;
@ -147,7 +147,7 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//2x3
drawnRectangle.X = destination.X + a;
@ -162,7 +162,7 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
//3x3
drawnRectangle.X = destination.X + destination.Width - b;
@ -177,7 +177,13 @@ namespace RecrownedAthenaeum.DataTypes
sourceRectangle.X += textureRegion.X;
sourceRectangle.Y += textureRegion.Y;
batch.Draw(texture, drawnRectangle, sourceRectangle, color);
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
}
public void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
{
this.color = color;
Draw(spriteBatch, destination);
}
}
}

View File

@ -16,7 +16,7 @@ namespace RecrownedAthenaeum.DataTypes
private Texture2D texture;
private Dictionary<string, TextureAtlasRegion> dictionaryOfRegions = new Dictionary<string, TextureAtlasRegion>();
public TextureAtlasRegion this[string name] { get { if (name != null && dictionaryOfRegions.ContainsKey(name)) return dictionaryOfRegions[name]; else return null; } }
public TextureAtlas(Texture2D texture, TextureAtlasRegion[] regions)
{
this.texture = texture;
@ -57,7 +57,7 @@ namespace RecrownedAthenaeum.DataTypes
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice);
}
public class TextureAtlasRegion : IComparable<TextureAtlasRegion>, IDisposable
public class TextureAtlasRegion : IComparable<TextureAtlasRegion>, ISpecialDrawable, IDisposable
{
public readonly string name;
public readonly Rectangle sourceRectangle;
@ -82,7 +82,13 @@ namespace RecrownedAthenaeum.DataTypes
public void Draw(SpriteBatch batch, Rectangle destination, Color color, float rotation, Vector2 origin)
{
batch.Draw(atlasTexture, destination, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0f);
if (ninepatch != null)
{
ninepatch.Draw(batch, destination);
} else
{
batch.Draw(atlasTexture, destination, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0f);
}
}
/// <summary>

View File

@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RecrownedAthenaeum.DataTypes;
using RecrownedAthenaeum.UI.Modular;
using System;
using System.Collections.Generic;
@ -9,7 +10,7 @@ using System.Threading.Tasks;
namespace RecrownedAthenaeum.UI.Modular.Modules
{
public class Image : UIModule
public class Image : UIModule, ISpecialDrawable
{
public float rotation = 0f;
public Texture2D Texture { get; set; }
@ -59,5 +60,14 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
batch.Draw(Texture, bounds, null, color, rotation, origin, SpriteEffects.None, 0f);
base.Draw(batch);
}
public void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
{
this.color = color;
this.rotation = rotation;
this.origin = origin;
bounds = destination;
Draw(spriteBatch);
}
}
}