Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GlyphTagHandler.cs
Go to the documentation of this file.
4using Microsoft.Xna.Framework.Input;
7
9
11{
12 private class GlyphSnippet : TextSnippet
13 {
14 private int _glyphIndex;
15
16 public GlyphSnippet(int index)
17 {
18 _glyphIndex = index;
20 }
21
22 public override bool UniqueDraw(bool justCheckingString, out Vector2 size, SpriteBatch spriteBatch, Vector2 position = default(Vector2), Color color = default(Color), float scale = 1f)
23 {
24 if (!justCheckingString && color != Color.Black)
25 {
26 int num = _glyphIndex;
28 if (glyphIndex == 25)
29 {
30 num = ((Main.GlobalTimeWrappedHourly % 0.6f < 0.3f) ? 17 : 18);
31 }
32 Texture2D value = TextureAssets.TextGlyph[0].Value;
33 spriteBatch.Draw(value, position, value.Frame(25, 1, num, num / 25), color, 0f, Vector2.Zero, GlyphsScale, SpriteEffects.None, 0f);
34 }
35 size = new Vector2(26f) * GlyphsScale;
36 return true;
37 }
38
39 public override float GetStringLength(DynamicSpriteFont font)
40 {
41 return 26f * GlyphsScale;
42 }
43 }
44
45 private const int GlyphsPerLine = 25;
46
47 private const int MaxGlyphs = 26;
48
49 public static float GlyphsScale = 1f;
50
52 {
53 {
54 Buttons.A.ToString(),
55 0
56 },
57 {
58 Buttons.B.ToString(),
59 1
60 },
61 {
62 Buttons.Back.ToString(),
63 4
64 },
65 {
66 Buttons.DPadDown.ToString(),
67 15
68 },
69 {
70 Buttons.DPadLeft.ToString(),
71 14
72 },
73 {
74 Buttons.DPadRight.ToString(),
75 13
76 },
77 {
78 Buttons.DPadUp.ToString(),
79 16
80 },
81 {
82 Buttons.LeftShoulder.ToString(),
83 6
84 },
85 {
86 Buttons.LeftStick.ToString(),
87 10
88 },
89 {
90 Buttons.LeftThumbstickDown.ToString(),
91 20
92 },
93 {
94 Buttons.LeftThumbstickLeft.ToString(),
95 17
96 },
97 {
98 Buttons.LeftThumbstickRight.ToString(),
99 18
100 },
101 {
102 Buttons.LeftThumbstickUp.ToString(),
103 19
104 },
105 {
106 Buttons.LeftTrigger.ToString(),
107 8
108 },
109 {
110 Buttons.RightShoulder.ToString(),
111 7
112 },
113 {
114 Buttons.RightStick.ToString(),
115 11
116 },
117 {
118 Buttons.RightThumbstickDown.ToString(),
119 24
120 },
121 {
122 Buttons.RightThumbstickLeft.ToString(),
123 21
124 },
125 {
126 Buttons.RightThumbstickRight.ToString(),
127 22
128 },
129 {
130 Buttons.RightThumbstickUp.ToString(),
131 23
132 },
133 {
134 Buttons.RightTrigger.ToString(),
135 9
136 },
137 {
138 Buttons.Start.ToString(),
139 5
140 },
141 {
142 Buttons.X.ToString(),
143 2
144 },
145 {
146 Buttons.Y.ToString(),
147 3
148 },
149 { "LR", 25 }
150 };
151
152 TextSnippet ITagHandler.Parse(string text, Color baseColor, string options)
153 {
154 if (!int.TryParse(text, out var result) || result >= 26)
155 {
156 return new TextSnippet(text);
157 }
158 return new GlyphSnippet(result)
159 {
160 DeleteWhole = true,
161 Text = "[g:" + result + "]"
162 };
163 }
164
165 public static string GenerateTag(int index)
166 {
167 string text = "[g";
168 return text + ":" + index + "]";
169 }
170
171 public static string GenerateTag(string keyname)
172 {
173 if (GlyphIndexes.TryGetValue(keyname, out var value))
174 {
175 return GenerateTag(value);
176 }
177 return keyname;
178 }
179}
void Draw(Texture2D texture, Vector2 position, Color color)
static Asset< Texture2D >[] TextGlyph
override float GetStringLength(DynamicSpriteFont font)
override bool UniqueDraw(bool justCheckingString, out Vector2 size, SpriteBatch spriteBatch, Vector2 position=default(Vector2), Color color=default(Color), float scale=1f)
static Dictionary< string, int > GlyphIndexes
static string GenerateTag(string keyname)
TextSnippet Parse(string text, Color baseColor=default(Color), string options=null)