Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ClassicPlayerResourcesDisplaySet.cs
Go to the documentation of this file.
5
7
9{
10 private int UIDisplay_ManaPerStar = 20;
11
12 private float UIDisplay_LifePerHeart = 20f;
13
14 private int UI_ScreenAnchorX;
15
16 public string NameKey { get; private set; }
17
18 public string ConfigKey { get; private set; }
19
20 public ClassicPlayerResourcesDisplaySet(string nameKey, string configKey)
21 {
22 NameKey = nameKey;
23 ConfigKey = configKey;
24 }
25
26 public void Draw()
27 {
28 UI_ScreenAnchorX = Main.screenWidth - 800;
29 DrawLife();
30 DrawMana();
31 }
32
33 private void DrawLife()
34 {
35 Player localPlayer = Main.LocalPlayer;
36 SpriteBatch spriteBatch = Main.spriteBatch;
39 if (localPlayer.ghost)
40 {
41 return;
42 }
43 int num = localPlayer.statLifeMax / 20;
44 int num2 = (localPlayer.statLifeMax - 400) / 5;
45 if (num2 < 0)
46 {
47 num2 = 0;
48 }
49 if (num2 > 0)
50 {
51 num = localPlayer.statLifeMax / (20 + num2 / 4);
52 UIDisplay_LifePerHeart = (float)localPlayer.statLifeMax / 20f;
53 }
54 int num3 = localPlayer.statLifeMax2 - localPlayer.statLifeMax;
55 UIDisplay_LifePerHeart += num3 / num;
56 int num4 = (int)((float)localPlayer.statLifeMax2 / UIDisplay_LifePerHeart);
57 if (num4 >= 10)
58 {
59 num4 = 10;
60 }
61 string text = Lang.inter[0].Value + " " + localPlayer.statLifeMax2 + "/" + localPlayer.statLifeMax2;
62 Vector2 vector = FontAssets.MouseText.Value.MeasureString(text);
63 if (!localPlayer.ghost)
64 {
65 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, Lang.inter[0].Value, new Vector2((float)(500 + 13 * num4) - vector.X * 0.5f + (float)UI_ScreenAnchorX, 6f), color, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
66 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, localPlayer.statLife + "/" + localPlayer.statLifeMax2, new Vector2((float)(500 + 13 * num4) + vector.X * 0.5f + (float)UI_ScreenAnchorX, 6f), color, 0f, new Vector2(FontAssets.MouseText.Value.MeasureString(localPlayer.statLife + "/" + localPlayer.statLifeMax2).X, 0f), 1f, SpriteEffects.None, 0f);
67 }
68 for (int i = 1; i < (int)((float)localPlayer.statLifeMax2 / UIDisplay_LifePerHeart) + 1; i++)
69 {
70 int num5 = 255;
71 float num6 = 1f;
72 bool flag = false;
73 if ((float)localPlayer.statLife >= (float)i * UIDisplay_LifePerHeart)
74 {
75 num5 = 255;
76 if ((float)localPlayer.statLife == (float)i * UIDisplay_LifePerHeart)
77 {
78 flag = true;
79 }
80 }
81 else
82 {
83 float num7 = ((float)localPlayer.statLife - (float)(i - 1) * UIDisplay_LifePerHeart) / UIDisplay_LifePerHeart;
84 num5 = (int)(30f + 225f * num7);
85 if (num5 < 30)
86 {
87 num5 = 30;
88 }
89 num6 = num7 / 4f + 0.75f;
90 if ((double)num6 < 0.75)
91 {
92 num6 = 0.75f;
93 }
94 if (num7 > 0f)
95 {
96 flag = true;
97 }
98 }
99 if (flag)
100 {
101 num6 += Main.cursorScale - 1f;
102 }
103 int num8 = 0;
104 int num9 = 0;
105 if (i > 10)
106 {
107 num8 -= 260;
108 num9 += 26;
109 }
110 int a = (int)((double)num5 * 0.9);
111 if (!localPlayer.ghost)
112 {
113 if (num2 > 0)
114 {
115 num2--;
116 spriteBatch.Draw(TextureAssets.Heart2.Value, new Vector2(500 + 26 * (i - 1) + num8 + UI_ScreenAnchorX + TextureAssets.Heart.Width() / 2, 32f + ((float)TextureAssets.Heart.Height() - (float)TextureAssets.Heart.Height() * num6) / 2f + (float)num9 + (float)(TextureAssets.Heart.Height() / 2)), new Rectangle(0, 0, TextureAssets.Heart.Width(), TextureAssets.Heart.Height()), new Color(num5, num5, num5, a), 0f, new Vector2(TextureAssets.Heart.Width() / 2, TextureAssets.Heart.Height() / 2), num6, SpriteEffects.None, 0f);
117 }
118 else
119 {
120 spriteBatch.Draw(TextureAssets.Heart.Value, new Vector2(500 + 26 * (i - 1) + num8 + UI_ScreenAnchorX + TextureAssets.Heart.Width() / 2, 32f + ((float)TextureAssets.Heart.Height() - (float)TextureAssets.Heart.Height() * num6) / 2f + (float)num9 + (float)(TextureAssets.Heart.Height() / 2)), new Rectangle(0, 0, TextureAssets.Heart.Width(), TextureAssets.Heart.Height()), new Color(num5, num5, num5, a), 0f, new Vector2(TextureAssets.Heart.Width() / 2, TextureAssets.Heart.Height() / 2), num6, SpriteEffects.None, 0f);
121 }
122 }
123 }
124 }
125
126 private void DrawMana()
127 {
128 Player localPlayer = Main.LocalPlayer;
129 SpriteBatch spriteBatch = Main.spriteBatch;
132 if (localPlayer.ghost || localPlayer.statManaMax2 <= 0)
133 {
134 return;
135 }
136 _ = localPlayer.statManaMax2 / 20;
137 Vector2 vector = FontAssets.MouseText.Value.MeasureString(Lang.inter[2].Value);
138 int num = 50;
139 if (vector.X >= 45f)
140 {
141 num = (int)vector.X + 5;
142 }
143 DynamicSpriteFontExtensionMethods.DrawString(spriteBatch, FontAssets.MouseText.Value, Lang.inter[2].Value, new Vector2(800 - num + UI_ScreenAnchorX, 6f), color, 0f, default(Vector2), 1f, SpriteEffects.None, 0f);
144 for (int i = 1; i < localPlayer.statManaMax2 / UIDisplay_ManaPerStar + 1; i++)
145 {
146 int num2 = 255;
147 bool flag = false;
148 float num3 = 1f;
149 if (localPlayer.statMana >= i * UIDisplay_ManaPerStar)
150 {
151 num2 = 255;
152 if (localPlayer.statMana == i * UIDisplay_ManaPerStar)
153 {
154 flag = true;
155 }
156 }
157 else
158 {
159 float num4 = (float)(localPlayer.statMana - (i - 1) * UIDisplay_ManaPerStar) / (float)UIDisplay_ManaPerStar;
160 num2 = (int)(30f + 225f * num4);
161 if (num2 < 30)
162 {
163 num2 = 30;
164 }
165 num3 = num4 / 4f + 0.75f;
166 if ((double)num3 < 0.75)
167 {
168 num3 = 0.75f;
169 }
170 if (num4 > 0f)
171 {
172 flag = true;
173 }
174 }
175 if (flag)
176 {
177 num3 += Main.cursorScale - 1f;
178 }
179 int a = (int)((double)num2 * 0.9);
180 spriteBatch.Draw(TextureAssets.Mana.Value, new Vector2(775 + UI_ScreenAnchorX, (float)(30 + TextureAssets.Mana.Height() / 2) + ((float)TextureAssets.Mana.Height() - (float)TextureAssets.Mana.Height() * num3) / 2f + (float)(28 * (i - 1))), new Rectangle(0, 0, TextureAssets.Mana.Width(), TextureAssets.Mana.Height()), new Color(num2, num2, num2, a), 0f, new Vector2(TextureAssets.Mana.Width() / 2, TextureAssets.Mana.Height() / 2), num3, SpriteEffects.None, 0f);
181 }
182 }
183
184 public void TryToHover()
185 {
186 Vector2 mouseScreen = Main.MouseScreen;
187 Player localPlayer = Main.LocalPlayer;
188 int num = 26 * localPlayer.statLifeMax2 / (int)UIDisplay_LifePerHeart;
189 int num2 = 0;
190 if (localPlayer.statLifeMax2 > 200)
191 {
192 num = 260;
193 num2 += 26;
194 }
195 if (mouseScreen.X > (float)(500 + UI_ScreenAnchorX) && mouseScreen.X < (float)(500 + num + UI_ScreenAnchorX) && mouseScreen.Y > 32f && mouseScreen.Y < (float)(32 + TextureAssets.Heart.Height() + num2))
196 {
198 }
199 num = 24;
200 num2 = 28 * localPlayer.statManaMax2 / UIDisplay_ManaPerStar;
201 if (mouseScreen.X > (float)(762 + UI_ScreenAnchorX) && mouseScreen.X < (float)(762 + num + UI_ScreenAnchorX) && mouseScreen.Y > 30f && mouseScreen.Y < (float)(30 + num2))
202 {
204 }
205 }
206}
void Draw(Texture2D texture, Vector2 position, Color color)
static void DrawString(this SpriteBatch spriteBatch, DynamicSpriteFont spriteFont, string text, Vector2 position, Color color)
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
static Asset< Texture2D > Heart2
static Asset< Texture2D > Mana
static Asset< Texture2D > Heart
static LocalizedText[] inter
Definition Lang.cs:28
static SpriteBatch spriteBatch
Definition Main.cs:974
static Vector2 MouseScreen
Definition Main.cs:2773
static byte mouseTextColor
Definition Main.cs:1751
static Player LocalPlayer
Definition Main.cs:2829