Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
UIGenProgressBar.cs
Go to the documentation of this file.
4using Terraria.UI;
5
7
9{
11
13
15
17
19
21
23
24 private int _smallBarWidth = 508;
25
26 private int _longBarWidth = 570;
27
29 {
30 if (Main.netMode != 2)
31 {
32 _texOuterCorrupt = Main.Assets.Request<Texture2D>("Images/UI/WorldGen/Outer_Corrupt", (AssetRequestMode)1);
33 _texOuterCrimson = Main.Assets.Request<Texture2D>("Images/UI/WorldGen/Outer_Crimson", (AssetRequestMode)1);
34 _texOuterLower = Main.Assets.Request<Texture2D>("Images/UI/WorldGen/Outer_Lower", (AssetRequestMode)1);
35 }
37 }
38
39 public override void Recalculate()
40 {
41 Width.Precent = 0f;
42 Height.Precent = 0f;
43 Width.Pixels = 612f;
44 Height.Pixels = 70f;
45 base.Recalculate();
46 }
47
48 public void SetProgress(float overallProgress, float currentProgress)
49 {
50 _targetCurrentProgress = currentProgress;
51 _targetOverallProgress = overallProgress;
52 }
53
54 protected override void DrawSelf(SpriteBatch spriteBatch)
55 {
57 {
58 bool flag = WorldGen.crimson;
59 if (WorldGen.drunkWorldGen && Main.rand.Next(2) == 0)
60 {
61 flag = !flag;
62 }
65 CalculatedStyle dimensions = GetDimensions();
66 int completedWidth = (int)(_visualOverallProgress * (float)_longBarWidth);
67 int completedWidth2 = (int)(_visualCurrentProgress * (float)_smallBarWidth);
68 Vector2 vector = new Vector2(dimensions.X, dimensions.Y);
69 Color color = default(Color);
70 color.PackedValue = (flag ? 4286836223u : 4283888223u);
71 DrawFilling2(spriteBatch, vector + new Vector2(20f, 40f), 16, completedWidth, _longBarWidth, color, Color.Lerp(color, Color.Black, 0.5f), new Color(48, 48, 48));
72 color.PackedValue = 4290947159u;
73 DrawFilling2(spriteBatch, vector + new Vector2(50f, 60f), 8, completedWidth2, _smallBarWidth, color, Color.Lerp(color, Color.Black, 0.5f), new Color(33, 33, 33));
75 r.X -= 8;
76 spriteBatch.Draw(flag ? _texOuterCrimson.Value : _texOuterCorrupt.Value, r.TopLeft(), Color.White);
77 spriteBatch.Draw(_texOuterLower.Value, r.TopLeft() + new Vector2(44f, 60f), Color.White);
78 }
79 }
80
81 private void DrawFilling(SpriteBatch spritebatch, Texture2D tex, Texture2D texShadow, Vector2 topLeft, int completedWidth, int totalWidth, Color separator, Color empty)
82 {
83 if (completedWidth % 2 != 0)
84 {
85 completedWidth--;
86 }
87 Vector2 position = topLeft + completedWidth * Vector2.UnitX;
88 int num = completedWidth;
89 Rectangle value = tex.Frame();
90 while (num > 0)
91 {
92 if (value.Width > num)
93 {
94 value.X += value.Width - num;
95 value.Width = num;
96 }
97 spritebatch.Draw(tex, position, value, Color.White, 0f, new Vector2(value.Width, 0f), 1f, SpriteEffects.None, 0f);
98 position.X -= value.Width;
99 num -= value.Width;
100 }
101 if (texShadow != null)
102 {
103 spritebatch.Draw(texShadow, topLeft, new Rectangle(0, 0, completedWidth, texShadow.Height), Color.White);
104 }
105 spritebatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((int)topLeft.X + completedWidth, (int)topLeft.Y, totalWidth - completedWidth, tex.Height), new Rectangle(0, 0, 1, 1), empty);
106 spritebatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((int)topLeft.X + completedWidth - 2, (int)topLeft.Y, 2, tex.Height), new Rectangle(0, 0, 1, 1), separator);
107 }
108
109 private void DrawFilling2(SpriteBatch spritebatch, Vector2 topLeft, int height, int completedWidth, int totalWidth, Color filled, Color separator, Color empty)
110 {
111 if (completedWidth % 2 != 0)
112 {
113 completedWidth--;
114 }
115 spritebatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((int)topLeft.X, (int)topLeft.Y, completedWidth, height), new Rectangle(0, 0, 1, 1), filled);
116 spritebatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((int)topLeft.X + completedWidth, (int)topLeft.Y, totalWidth - completedWidth, height), new Rectangle(0, 0, 1, 1), empty);
117 spritebatch.Draw(TextureAssets.MagicPixel.Value, new Rectangle((int)topLeft.X + completedWidth - 2, (int)topLeft.Y, 2, height), new Rectangle(0, 0, 1, 1), separator);
118 }
119}
void Draw(Texture2D texture, Vector2 position, Color color)
static Asset< Texture2D > MagicPixel
void DrawFilling2(SpriteBatch spritebatch, Vector2 topLeft, int height, int completedWidth, int totalWidth, Color filled, Color separator, Color empty)
void SetProgress(float overallProgress, float currentProgress)
void DrawFilling(SpriteBatch spritebatch, Texture2D tex, Texture2D texShadow, Vector2 topLeft, int completedWidth, int totalWidth, Color separator, Color empty)
override void DrawSelf(SpriteBatch spriteBatch)
static int netMode
Definition Main.cs:2095
static UnifiedRandom rand
Definition Main.cs:1387
static IAssetRepository Assets
Definition Main.cs:209
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
static bool crimson
Definition WorldGen.cs:932
static bool drunkWorldGen
Definition WorldGen.cs:1154
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491