Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
BigProgressBarHelper.cs
Go to the documentation of this file.
5
7
9{
10 private const string _bossBarTexturePath = "Images/UI/UI_BossBar";
11
12 public static void DrawBareBonesBar(SpriteBatch spriteBatch, float lifePercent)
13 {
14 Rectangle rectangle = Utils.CenteredRectangle(Main.ScreenSize.ToVector2() * new Vector2(0.5f, 1f) + new Vector2(0f, -50f), new Vector2(400f, 20f));
15 Rectangle destinationRectangle = rectangle;
16 destinationRectangle.Inflate(2, 2);
18 Rectangle value2 = new Rectangle(0, 0, 1, 1);
19 Rectangle destinationRectangle2 = rectangle;
20 destinationRectangle2.Width = (int)((float)destinationRectangle2.Width * lifePercent);
21 spriteBatch.Draw(value, destinationRectangle, value2, Color.White * 0.6f);
22 spriteBatch.Draw(value, rectangle, value2, Color.Black * 0.6f);
23 spriteBatch.Draw(value, destinationRectangle2, value2, Color.LimeGreen * 0.5f);
24 }
25
26 public static void DrawFancyBar(SpriteBatch spriteBatch, float lifeAmount, float lifeMax, Texture2D barIconTexture, Rectangle barIconFrame)
27 {
28 Texture2D value = Main.Assets.Request<Texture2D>("Images/UI/UI_BossBar", (AssetRequestMode)1).Value;
29 Point p = new Point(456, 22);
30 Point p2 = new Point(32, 24);
31 int verticalFrames = 6;
32 Rectangle value2 = value.Frame(1, verticalFrames, 0, 3);
33 Color color = Color.White * 0.2f;
34 float num = lifeAmount / lifeMax;
35 int num2 = (int)((float)p.X * num);
36 num2 -= num2 % 2;
37 Rectangle value3 = value.Frame(1, verticalFrames, 0, 2);
38 value3.X += p2.X;
39 value3.Y += p2.Y;
40 value3.Width = 2;
41 value3.Height = p.Y;
42 Rectangle value4 = value.Frame(1, verticalFrames, 0, 1);
43 value4.X += p2.X;
44 value4.Y += p2.Y;
45 value4.Width = 2;
46 value4.Height = p.Y;
47 Rectangle rectangle = Utils.CenteredRectangle(Main.ScreenSize.ToVector2() * new Vector2(0.5f, 1f) + new Vector2(0f, -50f), p.ToVector2());
48 Vector2 vector = rectangle.TopLeft() - p2.ToVector2();
49 spriteBatch.Draw(value, vector, value2, color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
50 spriteBatch.Draw(value, rectangle.TopLeft(), value3, Color.White, 0f, Vector2.Zero, new Vector2(num2 / value3.Width, 1f), SpriteEffects.None, 0f);
51 spriteBatch.Draw(value, rectangle.TopLeft() + new Vector2(num2 - 2, 0f), value4, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
52 Rectangle value5 = value.Frame(1, verticalFrames);
53 spriteBatch.Draw(value, vector, value5, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
54 Vector2 vector2 = new Vector2(4f, 20f) + new Vector2(26f, 28f) / 2f;
55 spriteBatch.Draw(barIconTexture, vector + vector2, barIconFrame, Color.White, 0f, barIconFrame.Size() / 2f, 1f, SpriteEffects.None, 0f);
57 {
58 DrawHealthText(spriteBatch, rectangle, lifeAmount, lifeMax);
59 }
60 }
61
62 private static void DrawHealthText(SpriteBatch spriteBatch, Rectangle area, float current, float max)
63 {
65 Vector2 vector = area.Center.ToVector2();
66 vector.Y += 1f;
67 string text = "/";
68 Vector2 vector2 = value.MeasureString(text);
69 Utils.DrawBorderStringFourWay(spriteBatch, value, text, vector.X, vector.Y, Color.White, Color.Black, vector2 * 0.5f);
70 text = ((int)current).ToString();
71 vector2 = value.MeasureString(text);
72 Utils.DrawBorderStringFourWay(spriteBatch, value, text, vector.X - 5f, vector.Y, Color.White, Color.Black, vector2 * new Vector2(1f, 0.5f));
73 text = ((int)max).ToString();
74 vector2 = value.MeasureString(text);
75 Utils.DrawBorderStringFourWay(spriteBatch, value, text, vector.X + 5f, vector.Y, Color.White, Color.Black, vector2 * new Vector2(0f, 0.5f));
76 }
77
78 public static void DrawFancyBar(SpriteBatch spriteBatch, float lifeAmount, float lifeMax, Texture2D barIconTexture, Rectangle barIconFrame, float shieldCurrent, float shieldMax)
79 {
80 Texture2D value = Main.Assets.Request<Texture2D>("Images/UI/UI_BossBar", (AssetRequestMode)1).Value;
81 Point p = new Point(456, 22);
82 Point p2 = new Point(32, 24);
83 int verticalFrames = 6;
84 Rectangle value2 = value.Frame(1, verticalFrames, 0, 3);
85 Color color = Color.White * 0.2f;
86 float num = lifeAmount / lifeMax;
87 int num2 = (int)((float)p.X * num);
88 num2 -= num2 % 2;
89 Rectangle value3 = value.Frame(1, verticalFrames, 0, 2);
90 value3.X += p2.X;
91 value3.Y += p2.Y;
92 value3.Width = 2;
93 value3.Height = p.Y;
94 Rectangle value4 = value.Frame(1, verticalFrames, 0, 1);
95 value4.X += p2.X;
96 value4.Y += p2.Y;
97 value4.Width = 2;
98 value4.Height = p.Y;
99 float num3 = shieldCurrent / shieldMax;
100 int num4 = (int)((float)p.X * num3);
101 num4 -= num4 % 2;
102 Rectangle value5 = value.Frame(1, verticalFrames, 0, 5);
103 value5.X += p2.X;
104 value5.Y += p2.Y;
105 value5.Width = 2;
106 value5.Height = p.Y;
107 Rectangle value6 = value.Frame(1, verticalFrames, 0, 4);
108 value6.X += p2.X;
109 value6.Y += p2.Y;
110 value6.Width = 2;
111 value6.Height = p.Y;
112 Rectangle rectangle = Utils.CenteredRectangle(Main.ScreenSize.ToVector2() * new Vector2(0.5f, 1f) + new Vector2(0f, -50f), p.ToVector2());
113 Vector2 vector = rectangle.TopLeft() - p2.ToVector2();
114 spriteBatch.Draw(value, vector, value2, color, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
115 spriteBatch.Draw(value, rectangle.TopLeft(), value3, Color.White, 0f, Vector2.Zero, new Vector2(num2 / value3.Width, 1f), SpriteEffects.None, 0f);
116 spriteBatch.Draw(value, rectangle.TopLeft() + new Vector2(num2 - 2, 0f), value4, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
117 spriteBatch.Draw(value, rectangle.TopLeft(), value5, Color.White, 0f, Vector2.Zero, new Vector2(num4 / value5.Width, 1f), SpriteEffects.None, 0f);
118 spriteBatch.Draw(value, rectangle.TopLeft() + new Vector2(num4 - 2, 0f), value6, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
119 Rectangle value7 = value.Frame(1, verticalFrames);
120 spriteBatch.Draw(value, vector, value7, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f);
121 Vector2 vector2 = new Vector2(4f, 20f) + barIconFrame.Size() / 2f;
122 spriteBatch.Draw(barIconTexture, vector + vector2, barIconFrame, Color.White, 0f, barIconFrame.Size() / 2f, 1f, SpriteEffects.None, 0f);
124 {
125 if (shieldCurrent > 0f)
126 {
127 DrawHealthText(spriteBatch, rectangle, shieldCurrent, shieldMax);
128 }
129 else
130 {
131 DrawHealthText(spriteBatch, rectangle, lifeAmount, lifeMax);
132 }
133 }
134 }
135}
void Draw(Texture2D texture, Vector2 position, Color color)
static Asset< DynamicSpriteFont > ItemStack
Definition FontAssets.cs:8
static Asset< Texture2D > MagicPixel
static void DrawFancyBar(SpriteBatch spriteBatch, float lifeAmount, float lifeMax, Texture2D barIconTexture, Rectangle barIconFrame)
static void DrawHealthText(SpriteBatch spriteBatch, Rectangle area, float current, float max)
static void DrawBareBonesBar(SpriteBatch spriteBatch, float lifePercent)
static void DrawFancyBar(SpriteBatch spriteBatch, float lifeAmount, float lifeMax, Texture2D barIconTexture, Rectangle barIconFrame, float shieldCurrent, float shieldMax)
static Microsoft.Xna.Framework.Point ScreenSize
Definition Main.cs:2925
static IAssetRepository Assets
Definition Main.cs:209
static void DrawBorderStringFourWay(SpriteBatch sb, DynamicSpriteFont font, string text, float x, float y, Color textColor, Color borderColor, Vector2 origin, float scale=1f)
Definition Utils.cs:1857
static Rectangle CenteredRectangle(Vector2 center, Vector2 size)
Definition Utils.cs:604
void Inflate(int horizontalAmount, int verticalAmount)
Definition Rectangle.cs:84