Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
TileFont.cs
Go to the documentation of this file.
1using System;
4
6
7public class TileFont
8{
9 public struct DrawMode
10 {
11 public readonly ushort ForegroundTile;
12
13 public readonly ushort BackgroundTile;
14
15 public readonly bool HasBackground;
16
17 public DrawMode(ushort foregroundTile)
18 {
20 HasBackground = false;
22 }
23
30 }
31
33 {
34 {
35 'A',
36 new byte[5] { 124, 68, 68, 124, 68 }
37 },
38 {
39 'B',
40 new byte[5] { 124, 68, 120, 68, 124 }
41 },
42 {
43 'C',
44 new byte[5] { 124, 64, 64, 64, 124 }
45 },
46 {
47 'D',
48 new byte[5] { 120, 68, 68, 68, 120 }
49 },
50 {
51 'E',
52 new byte[5] { 124, 64, 120, 64, 124 }
53 },
54 {
55 'F',
56 new byte[5] { 124, 64, 112, 64, 64 }
57 },
58 {
59 'G',
60 new byte[5] { 124, 64, 76, 68, 124 }
61 },
62 {
63 'H',
64 new byte[5] { 68, 68, 124, 68, 68 }
65 },
66 {
67 'I',
68 new byte[5] { 124, 16, 16, 16, 124 }
69 },
70 {
71 'J',
72 new byte[5] { 12, 4, 4, 68, 124 }
73 },
74 {
75 'K',
76 new byte[5] { 68, 72, 112, 72, 68 }
77 },
78 {
79 'L',
80 new byte[5] { 64, 64, 64, 64, 124 }
81 },
82 {
83 'M',
84 new byte[5] { 68, 108, 84, 68, 68 }
85 },
86 {
87 'N',
88 new byte[5] { 68, 100, 84, 76, 68 }
89 },
90 {
91 'O',
92 new byte[5] { 124, 68, 68, 68, 124 }
93 },
94 {
95 'P',
96 new byte[5] { 120, 68, 120, 64, 64 }
97 },
98 {
99 'Q',
100 new byte[5] { 124, 68, 68, 124, 16 }
101 },
102 {
103 'R',
104 new byte[5] { 120, 68, 120, 68, 68 }
105 },
106 {
107 'S',
108 new byte[5] { 124, 64, 124, 4, 124 }
109 },
110 {
111 'T',
112 new byte[5] { 124, 16, 16, 16, 16 }
113 },
114 {
115 'U',
116 new byte[5] { 68, 68, 68, 68, 124 }
117 },
118 {
119 'V',
120 new byte[5] { 68, 68, 40, 40, 16 }
121 },
122 {
123 'W',
124 new byte[5] { 68, 68, 84, 84, 40 }
125 },
126 {
127 'X',
128 new byte[5] { 68, 40, 16, 40, 68 }
129 },
130 {
131 'Y',
132 new byte[5] { 68, 68, 40, 16, 16 }
133 },
134 {
135 'Z',
136 new byte[5] { 124, 8, 16, 32, 124 }
137 },
138 {
139 'a',
140 new byte[5] { 56, 4, 60, 68, 60 }
141 },
142 {
143 'b',
144 new byte[5] { 64, 120, 68, 68, 120 }
145 },
146 {
147 'c',
148 new byte[5] { 56, 68, 64, 68, 56 }
149 },
150 {
151 'd',
152 new byte[5] { 4, 60, 68, 68, 60 }
153 },
154 {
155 'e',
156 new byte[5] { 56, 68, 124, 64, 60 }
157 },
158 {
159 'f',
160 new byte[5] { 28, 32, 120, 32, 32 }
161 },
162 {
163 'g',
164 new byte[5] { 56, 68, 60, 4, 120 }
165 },
166 {
167 'h',
168 new byte[5] { 64, 64, 120, 68, 68 }
169 },
170 {
171 'i',
172 new byte[5] { 16, 0, 16, 16, 16 }
173 },
174 {
175 'j',
176 new byte[5] { 4, 4, 4, 4, 120 }
177 },
178 {
179 'k',
180 new byte[5] { 64, 72, 112, 72, 68 }
181 },
182 {
183 'l',
184 new byte[5] { 64, 64, 64, 64, 60 }
185 },
186 {
187 'm',
188 new byte[5] { 40, 84, 84, 84, 84 }
189 },
190 {
191 'n',
192 new byte[5] { 120, 68, 68, 68, 68 }
193 },
194 {
195 'o',
196 new byte[5] { 56, 68, 68, 68, 56 }
197 },
198 {
199 'p',
200 new byte[5] { 56, 68, 68, 120, 64 }
201 },
202 {
203 'q',
204 new byte[5] { 56, 68, 68, 60, 4 }
205 },
206 {
207 'r',
208 new byte[5] { 88, 100, 64, 64, 64 }
209 },
210 {
211 's',
212 new byte[5] { 60, 64, 56, 4, 120 }
213 },
214 {
215 't',
216 new byte[5] { 64, 112, 64, 68, 56 }
217 },
218 {
219 'u',
220 new byte[5] { 0, 68, 68, 68, 56 }
221 },
222 {
223 'v',
224 new byte[5] { 0, 68, 68, 40, 16 }
225 },
226 {
227 'w',
228 new byte[5] { 84, 84, 84, 84, 40 }
229 },
230 {
231 'x',
232 new byte[5] { 68, 68, 56, 68, 68 }
233 },
234 {
235 'y',
236 new byte[5] { 68, 68, 60, 4, 120 }
237 },
238 {
239 'z',
240 new byte[5] { 124, 4, 56, 64, 124 }
241 },
242 {
243 '0',
244 new byte[5] { 124, 76, 84, 100, 124 }
245 },
246 {
247 '1',
248 new byte[5] { 16, 48, 16, 16, 56 }
249 },
250 {
251 '2',
252 new byte[5] { 120, 4, 56, 64, 124 }
253 },
254 {
255 '3',
256 new byte[5] { 124, 4, 56, 4, 124 }
257 },
258 {
259 '4',
260 new byte[5] { 64, 64, 80, 124, 16 }
261 },
262 {
263 '5',
264 new byte[5] { 124, 64, 120, 4, 120 }
265 },
266 {
267 '6',
268 new byte[5] { 124, 64, 124, 68, 124 }
269 },
270 {
271 '7',
272 new byte[5] { 124, 4, 8, 16, 16 }
273 },
274 {
275 '8',
276 new byte[5] { 124, 68, 124, 68, 124 }
277 },
278 {
279 '9',
280 new byte[5] { 124, 68, 124, 4, 124 }
281 },
282 {
283 '-',
284 new byte[5] { 0, 0, 124, 0, 0 }
285 },
286 {
287 ' ',
288 new byte[5]
289 }
290 };
291
292 public static void DrawString(Point start, string text, DrawMode mode)
293 {
294 Point position = start;
295 foreach (char c in text)
296 {
297 if (c == '\n')
298 {
299 position.X = start.X;
300 position.Y += 6;
301 }
302 if (MicroFont.TryGetValue(c, out var value))
303 {
304 DrawChar(position, value, mode);
305 position.X += 6;
306 }
307 }
308 }
309
310 private static void DrawChar(Point position, byte[] charData, DrawMode mode)
311 {
312 if (mode.HasBackground)
313 {
314 for (int i = -1; i < charData.Length + 1; i++)
315 {
316 for (int j = -1; j < 6; j++)
317 {
318 Main.tile[position.X + j, position.Y + i].ResetToType(mode.BackgroundTile);
319 WorldGen.TileFrame(position.X + j, position.Y + i);
320 }
321 }
322 }
323 for (int k = 0; k < charData.Length; k++)
324 {
325 int num = charData[k] << 1;
326 for (int l = 0; l < 5; l++)
327 {
328 if ((num & 0x80) == 128)
329 {
330 Main.tile[position.X + l, position.Y + k].ResetToType(mode.ForegroundTile);
331 WorldGen.TileFrame(position.X + l, position.Y + k);
332 }
333 num <<= 1;
334 }
335 }
336 }
337
338 public static Point MeasureString(string text)
339 {
341 Point point = zero;
342 Point result = new Point(0, 5);
343 foreach (char c in text)
344 {
345 if (c == '\n')
346 {
347 point.X = zero.X;
348 point.Y += 6;
349 result.Y = point.Y + 5;
350 }
351 if (MicroFont.TryGetValue(c, out var _))
352 {
353 point.X += 6;
354 result.X = Math.Max(result.X, point.X - 1);
355 }
356 }
357 return result;
358 }
359
360 public static void HLineLabel(Point start, int width, string text, DrawMode mode, bool rightSideText = false)
361 {
362 Point point = MeasureString(text);
363 for (int i = start.X; i < start.X + width; i++)
364 {
365 Main.tile[i, start.Y].ResetToType(mode.ForegroundTile);
367 }
368 DrawString(new Point(rightSideText ? (start.X + width + 1) : (start.X - point.X - 1), start.Y - point.Y / 2), text, mode);
369 }
370
371 public static void VLineLabel(Point start, int height, string text, DrawMode mode, bool bottomText = false)
372 {
373 Point point = MeasureString(text);
374 for (int i = start.Y; i < start.Y + height; i++)
375 {
376 Main.tile[start.X, i].ResetToType(mode.ForegroundTile);
378 }
379 DrawString(new Point(start.X - point.X / 2, bottomText ? (start.Y + height + 1) : (start.Y - point.Y - 1)), text, mode);
380 }
381}
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static Tile[,] tile
Definition Main.cs:1675
static void DrawChar(Point position, byte[] charData, DrawMode mode)
Definition TileFont.cs:310
static void VLineLabel(Point start, int height, string text, DrawMode mode, bool bottomText=false)
Definition TileFont.cs:371
static Point MeasureString(string text)
Definition TileFont.cs:338
static readonly Dictionary< char, byte[]> MicroFont
Definition TileFont.cs:32
static void DrawString(Point start, string text, DrawMode mode)
Definition TileFont.cs:292
static void HLineLabel(Point start, int width, string text, DrawMode mode, bool rightSideText=false)
Definition TileFont.cs:360
static void TileFrame(int i, int j, bool resetFrame=false, bool noBreak=false)
DrawMode(ushort foregroundTile)
Definition TileFont.cs:17
DrawMode(ushort foregroundTile, ushort backgroundTile)
Definition TileFont.cs:24