2020-01-18 03:41:45 +00:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
namespace SemiColinGames {
|
|
|
|
static class Debug {
|
|
|
|
struct DebugRect {
|
2020-01-23 19:31:00 +00:00
|
|
|
public Rectangle Rect;
|
|
|
|
public Color Color;
|
2020-01-18 03:41:45 +00:00
|
|
|
|
|
|
|
public DebugRect(Rectangle rect, Color color) {
|
2020-01-23 19:31:00 +00:00
|
|
|
Rect = rect;
|
|
|
|
Color = color;
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-23 16:40:32 +00:00
|
|
|
struct DebugLine {
|
2020-01-23 19:31:00 +00:00
|
|
|
public Point Start;
|
|
|
|
public Point End;
|
|
|
|
public Color Color;
|
2020-01-23 16:40:32 +00:00
|
|
|
|
|
|
|
public DebugLine(Point start, Point end, Color color) {
|
2020-01-23 19:31:00 +00:00
|
|
|
Start = start;
|
|
|
|
End = end;
|
|
|
|
Color = color;
|
2020-01-23 16:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 03:41:45 +00:00
|
|
|
public static bool Enabled;
|
2020-01-23 17:19:16 +00:00
|
|
|
// This is a LinkedList instead of a List because SetFpsText() adds to its front.
|
|
|
|
static LinkedList<string> toasts = new LinkedList<string>();
|
2020-01-18 03:41:45 +00:00
|
|
|
static List<DebugRect> rects = new List<DebugRect>();
|
2020-01-23 16:40:32 +00:00
|
|
|
static List<DebugLine> lines = new List<DebugLine>();
|
2020-01-23 17:19:16 +00:00
|
|
|
|
2020-01-18 03:41:45 +00:00
|
|
|
static Texture2D whiteTexture;
|
|
|
|
|
2020-01-23 17:19:16 +00:00
|
|
|
public static void Initialize(GraphicsDevice graphics) {
|
|
|
|
whiteTexture = new Texture2D(graphics, 1, 1);
|
|
|
|
whiteTexture.SetData(new Color[] { Color.White });
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void WriteLine(string s) {
|
|
|
|
System.Diagnostics.Debug.WriteLine(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void WriteLine(string s, params object[] args) {
|
|
|
|
System.Diagnostics.Debug.WriteLine(s, args);
|
|
|
|
}
|
2020-01-23 17:19:16 +00:00
|
|
|
|
2020-01-18 03:41:45 +00:00
|
|
|
public static void Clear() {
|
2020-01-23 17:19:16 +00:00
|
|
|
toasts.Clear();
|
2020-01-18 03:41:45 +00:00
|
|
|
rects.Clear();
|
2020-01-23 16:40:32 +00:00
|
|
|
lines.Clear();
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 17:19:16 +00:00
|
|
|
public static void AddToast(string s) {
|
|
|
|
toasts.AddLast(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FPS text is always displayed as the first toast (if set).
|
|
|
|
public static void SetFpsText(string s) {
|
|
|
|
toasts.AddFirst(s);
|
|
|
|
}
|
|
|
|
|
2020-01-18 03:41:45 +00:00
|
|
|
public static void AddRect(Rectangle rect, Color color) {
|
|
|
|
rects.Add(new DebugRect(rect, color));
|
|
|
|
}
|
|
|
|
|
2020-01-23 16:40:32 +00:00
|
|
|
public static void AddLine(Point start, Point end, Color color) {
|
|
|
|
lines.Add(new DebugLine(start, end, color));
|
|
|
|
}
|
|
|
|
|
2020-01-23 17:19:16 +00:00
|
|
|
public static void DrawToasts(SpriteBatch spriteBatch, SpriteFont font) {
|
|
|
|
int y = 10;
|
|
|
|
foreach (var toast in toasts) {
|
|
|
|
spriteBatch.DrawString(font, toast, new Vector2(10, y), Color.Teal);
|
|
|
|
y += 30;
|
2020-01-18 03:41:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Draw(SpriteBatch spriteBatch, Camera camera) {
|
|
|
|
if (!Enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
foreach (var debugRect in rects) {
|
2020-01-23 19:31:00 +00:00
|
|
|
var rect = debugRect.Rect;
|
2020-01-18 03:41:45 +00:00
|
|
|
rect.Offset(-camera.Left, 0);
|
2020-01-23 19:31:00 +00:00
|
|
|
var color = debugRect.Color;
|
2020-01-18 03:41:45 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|