forked from twobitcoder101/Flat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stats.cs
100 lines (80 loc) · 2.59 KB
/
Stats.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Flat.Graphics;
using System.Collections.Generic;
namespace Flat
{
public sealed class Stats
{
private static Lazy<Stats> LazyInstance = new Lazy<Stats>(() => new Stats());
public static Stats Instance
{
get { return LazyInstance.Value; }
}
private Sprites sprites;
private SpriteFont font;
private bool started;
private float y;
private Stats()
{
this.sprites = null;
this.font = null;
this.started = false;
this.y = 0f;
}
public void Begin(Sprites sprites, SpriteFont font)
{
if(this.started)
{
throw new Exception("Already started.");
}
this.sprites = sprites ?? throw new ArgumentNullException("sprites");
this.font = font ?? throw new ArgumentNullException("font");
this.y = 0;
this.started = true;
this.sprites.Begin(textureFiltering: true);
}
public void End()
{
if(!this.started)
{
throw new Exception("Never started.");
}
this.started = false;
this.sprites.End();
}
public void Draw(object obj)
{
this.Draw(obj, Color.White);
}
public void Draw(object obj, Color color)
{
if(!this.started)
{
throw new Exception("Not started.");
}
string text = obj.ToString();
Vector2 size = this.font.MeasureString(text);
this.sprites.DrawString(this.font, text, new Vector2(2, this.y - 2), Color.Black);
this.sprites.DrawString(this.font, text, new Vector2(0, this.y), color);
this.y += size.Y;
}
public void Draw(string text)
{
this.Draw(text, Color.White);
}
public void Draw(string text, Color color)
{
if (!this.started)
{
throw new Exception("Not started.");
}
Vector2 size = this.font.MeasureString(text);
this.sprites.DrawString(this.font, text, new Vector2(2, this.y - 2), Color.Black);
this.sprites.DrawString(this.font, text, new Vector2(0, this.y), color);
this.y += size.Y;
}
}
}