2019-12-11 22:57:30 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
2020-01-08 22:56:57 +00:00
|
|
|
|
namespace SemiColinGames {
|
2019-12-11 22:57:30 +00:00
|
|
|
|
static class Debug {
|
|
|
|
|
struct DebugRect {
|
|
|
|
|
public Rectangle rect;
|
|
|
|
|
public Color color;
|
|
|
|
|
|
|
|
|
|
public DebugRect(Rectangle rect, Color color) {
|
|
|
|
|
this.rect = rect;
|
|
|
|
|
this.color = color;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool Enabled;
|
|
|
|
|
static List<DebugRect> rects = new List<DebugRect>();
|
|
|
|
|
static Texture2D whiteTexture;
|
2019-12-17 20:37:32 +00:00
|
|
|
|
static string toast = null;
|
|
|
|
|
|
|
|
|
|
public static void Toast(string s) {
|
|
|
|
|
toast = s;
|
|
|
|
|
}
|
2019-12-11 22:57:30 +00:00
|
|
|
|
|
2019-12-17 03:02:36 +00:00
|
|
|
|
public static void WriteLine(string s) {
|
|
|
|
|
System.Diagnostics.Debug.WriteLine(s);
|
|
|
|
|
}
|
2019-12-11 22:57:30 +00:00
|
|
|
|
|
2019-12-17 03:02:36 +00:00
|
|
|
|
public static void WriteLine(string s, params object[] args) {
|
|
|
|
|
System.Diagnostics.Debug.WriteLine(s, args);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-11 22:57:30 +00:00
|
|
|
|
public static void Initialize(GraphicsDevice graphics) {
|
|
|
|
|
whiteTexture = new Texture2D(graphics, 1, 1);
|
|
|
|
|
whiteTexture.SetData(new Color[] { Color.White });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Clear() {
|
|
|
|
|
rects.Clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void AddRect(Rectangle rect, Color color) {
|
|
|
|
|
rects.Add(new DebugRect(rect, color));
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-17 20:37:32 +00:00
|
|
|
|
public static void DrawToast(SpriteBatch spriteBatch, SpriteFont font) {
|
|
|
|
|
if (toast == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-17 23:04:06 +00:00
|
|
|
|
spriteBatch.DrawString(font, toast, new Vector2(10, 40), Color.Teal);
|
2019-12-17 20:37:32 +00:00
|
|
|
|
toast = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Draw(SpriteBatch spriteBatch, Camera camera) {
|
2019-12-11 22:57:30 +00:00
|
|
|
|
if (!Enabled) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
foreach (var debugRect in rects) {
|
|
|
|
|
var rect = debugRect.rect;
|
2019-12-17 20:37:32 +00:00
|
|
|
|
rect.Offset(-camera.Left, 0);
|
2019-12-11 22:57:30 +00:00
|
|
|
|
var color = debugRect.color;
|
|
|
|
|
// top side
|
|
|
|
|
spriteBatch.Draw(
|
|
|
|
|
whiteTexture, new Rectangle(rect.Left, rect.Top, rect.Width, 1), color);
|
|
|
|
|
// bottom side
|
|
|
|
|
spriteBatch.Draw(
|
|
|
|
|
whiteTexture, new Rectangle(rect.Left, rect.Bottom - 1, rect.Width, 1), color);
|
|
|
|
|
// left side
|
|
|
|
|
spriteBatch.Draw(
|
|
|
|
|
whiteTexture, new Rectangle(rect.Left, rect.Top, 1, rect.Height), color);
|
|
|
|
|
// right side
|
|
|
|
|
spriteBatch.Draw(
|
|
|
|
|
whiteTexture, new Rectangle(rect.Right - 1, rect.Top, 1, rect.Height), color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|