Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIColoredSlider.cs
Go to the documentation of this file.
1using System;
7using Terraria.UI;
8
10
12{
13 private Color _color;
14
16
17 private Func<float> _getStatusTextAct;
18
19 private Action<float> _slideKeyboardAction;
20
21 private Func<float, Color> _blipFunc;
22
23 private Action _slideGamepadAction;
24
25 private const bool BOTHER_WITH_TEXT = false;
26
28
29 private bool _alreadyHovered;
30
31 private bool _soundedUsage;
32
33 public UIColoredSlider(LocalizedText textKey, Func<float> getStatus, Action<float> setStatusKeyboard, Action setStatusGamepad, Func<float, Color> blipColorFunction, Color color)
34 {
35 _color = color;
36 _textKey = textKey;
37 _getStatusTextAct = ((getStatus != null) ? getStatus : ((Func<float>)(() => 0f)));
38 _slideKeyboardAction = ((setStatusKeyboard != null) ? setStatusKeyboard : ((Action<float>)delegate
39 {
40 }));
41 _blipFunc = ((blipColorFunction != null) ? blipColorFunction : ((Func<float, Color>)((float s) => Color.Lerp(Color.Black, Color.White, s))));
42 _slideGamepadAction = setStatusGamepad;
44 }
45
46 protected override void DrawSelf(SpriteBatch spriteBatch)
47 {
48 UISliderBase.CurrentAimedSlider = null;
49 if (!Main.mouseLeft)
50 {
51 UISliderBase.CurrentLockedSlider = null;
52 }
53 int usageLevel = GetUsageLevel();
54 float num = 8f;
55 base.DrawSelf(spriteBatch);
56 CalculatedStyle dimensions = GetDimensions();
57 float num2 = dimensions.Width + 1f;
58 Vector2 vector = new Vector2(dimensions.X, dimensions.Y);
59 bool flag = false;
60 bool flag2 = base.IsMouseHovering;
61 if (usageLevel == 2)
62 {
63 flag2 = false;
64 }
65 if (usageLevel == 1)
66 {
67 flag2 = true;
68 }
69 Vector2 vector2 = vector + new Vector2(0f, 2f);
70 Color value = (flag ? Color.Gold : (flag2 ? Color.White : Color.Silver));
71 value = Color.Lerp(value, Color.White, flag2 ? 0.5f : 0f);
72 Vector2 vector3 = new Vector2(0.8f);
73 vector2.X += 8f;
74 vector2.Y += num;
75 vector2.X -= 17f;
76 TextureAssets.ColorBar.Frame();
77 vector2 = new Vector2(dimensions.X + dimensions.Width - 10f, dimensions.Y + 10f + num);
78 bool wasInBar;
79 float obj = DrawValueBar(spriteBatch, vector2, 1f, _getStatusTextAct(), usageLevel, out wasInBar, _blipFunc);
80 if (UISliderBase.CurrentLockedSlider == this || wasInBar)
81 {
82 UISliderBase.CurrentAimedSlider = this;
84 {
86 if (!_soundedUsage)
87 {
89 }
90 _soundedUsage = true;
91 }
92 else
93 {
94 _soundedUsage = false;
95 }
96 }
98 {
99 UISliderBase.CurrentLockedSlider = UISliderBase.CurrentAimedSlider;
100 }
102 {
104 }
105 }
106
107 private float DrawValueBar(SpriteBatch sb, Vector2 drawPosition, float drawScale, float sliderPosition, int lockMode, out bool wasInBar, Func<float, Color> blipColorFunc)
108 {
110 Vector2 vector = new Vector2(value.Width, value.Height) * drawScale;
111 drawPosition.X -= (int)vector.X;
112 Rectangle rectangle = new Rectangle((int)drawPosition.X, (int)drawPosition.Y - (int)vector.Y / 2, (int)vector.X, (int)vector.Y);
113 Rectangle destinationRectangle = rectangle;
114 sb.Draw(value, rectangle, Color.White);
115 float num = (float)rectangle.X + 5f * drawScale;
116 float num2 = (float)rectangle.Y + 4f * drawScale;
117 for (float num3 = 0f; num3 < 167f; num3 += 1f)
118 {
119 float arg = num3 / 167f;
120 Color color = blipColorFunc(arg);
121 sb.Draw(TextureAssets.ColorBlip.Value, new Vector2(num + num3 * drawScale, num2), null, color, 0f, Vector2.Zero, drawScale, SpriteEffects.None, 0f);
122 }
123 rectangle.X = (int)num - 2;
124 rectangle.Y = (int)num2;
125 rectangle.Width -= 4;
126 rectangle.Height -= 8;
127 bool flag = (_isReallyMouseOvered = rectangle.Contains(new Point(Main.mouseX, Main.mouseY)));
129 {
130 flag = false;
131 }
132 if (lockMode == 2)
133 {
134 flag = false;
135 }
136 if (flag || lockMode == 1)
137 {
138 sb.Draw(TextureAssets.ColorHighlight.Value, destinationRectangle, Main.OurFavoriteColor);
139 if (!_alreadyHovered)
140 {
142 }
143 _alreadyHovered = true;
144 }
145 else
146 {
147 _alreadyHovered = false;
148 }
149 wasInBar = false;
151 {
152 sb.Draw(TextureAssets.ColorSlider.Value, new Vector2(num + 167f * drawScale * sliderPosition, num2 + 4f * drawScale), null, Color.White, 0f, new Vector2(0.5f * (float)TextureAssets.ColorSlider.Value.Width, 0.5f * (float)TextureAssets.ColorSlider.Value.Height), drawScale, SpriteEffects.None, 0f);
153 if (Main.mouseX >= rectangle.X && Main.mouseX <= rectangle.X + rectangle.Width)
154 {
155 wasInBar = flag;
156 return (float)(Main.mouseX - rectangle.X) / (float)rectangle.Width;
157 }
158 }
159 if (rectangle.X >= Main.mouseX)
160 {
161 return 0f;
162 }
163 return 1f;
164 }
165}
void Draw(Texture2D texture, Vector2 position, Color color)
static void PlaySound(int type, Vector2 position, int style=1)
static Asset< Texture2D > ColorHighlight
static Asset< Texture2D > ColorSlider
static Asset< Texture2D > ColorBlip
static Asset< Texture2D > ColorBar
float DrawValueBar(SpriteBatch sb, Vector2 drawPosition, float drawScale, float sliderPosition, int lockMode, out bool wasInBar, Func< float, Color > blipColorFunc)
override void DrawSelf(SpriteBatch spriteBatch)
UIColoredSlider(LocalizedText textKey, Func< float > getStatus, Action< float > setStatusKeyboard, Action setStatusGamepad, Func< float, Color > blipColorFunction, Color color)
static TriggersPack Triggers
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition Main.cs:902
static int mouseY
Definition Main.cs:606
static int mouseX
Definition Main.cs:604
static bool mouseLeft
Definition Main.cs:614
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
bool Contains(int x, int y)
Definition Rectangle.cs:92