-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathText.cs
77 lines (66 loc) · 2.32 KB
/
Text.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
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RPG
{
class Text
{
private Texture2D text;
//private Texture2D background;
private Color color;
private int[] lengthRef;
private int[] letterPos;
private Point[] locations;
public int width;
//private bool highlighted;
private int highlightWidth;
public Text(ContentManager contentManager, string message, int customWidth = -1) : this(contentManager.Load<Texture2D>("Textbox/Text"), message, customWidth)
{
}
public Text(Texture2D font, string message, int customWidth = -1)
{
lengthRef = new int[] { 2, 2, 3, 2, 5, 9, 7, 2, 3, 3, 3, 5, 2, 2, 2, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 3, 3, 5, 3, 4, 5, 6, 5, 5, 5, 4, 4, 5, 5, 1, 4, 5, 4, 7, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 5, 5, 4, 5, 4, 6, 4, 5, 1, 4, 4, 4, 4, 4, 3, 4, 4, 1, 2, 4, 1, 7, 4, 4, 4, 4, 3, 4, 3, 4, 5, 7, 4, 4, 4, 2, 5, 2, 6, 7, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
letterPos = new int[message.Length];
locations = new Point[message.Length];
text = font;// contentManager.Load<Texture2D>("Textbox/Text");
//background = contentManager.Load<Texture2D>("HighlightColor");
for (int i = 0; i < message.Length; i++)
{
char letter = message.ElementAt(i);
int line, off;
line = (letter - ' ') / 16;
off = (letter - ' ') % 16;
locations[i] = new Point(16 * off, 16 * line);
width += lengthRef[message.ElementAt(i) - ' '] + 1;
if (i < message.Length - 1)
{
letterPos[i + 1] = lengthRef[message.ElementAt(i) - ' '] + 1;
if (i > 0)
letterPos[i + 1] += letterPos[i];
}
}
color = Color.White;
//Custom highlight width
if (customWidth == -1)
highlightWidth = width + 1;
else
highlightWidth = customWidth;
}
public void Draw(SpriteBatch sb, Vector2 pos)
{
for (int i = 0; i < locations.Length; i++)
{
sb.Draw(text, new Rectangle((int)(letterPos[i] + pos.X), (int) pos.Y, 16, 16), new Rectangle(locations[i].X, locations[i].Y, 16, 16), color);
}
}
public void SetColor(Color c)
{
color = c;
}
}
}