Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIVerticalSlider.cs
Go to the documentation of this file.
1using System;
6
8
10{
11 public float FillPercent;
12
14
16
17 private Func<float> _getSliderValue;
18
19 private Action<float> _slideKeyboardAction;
20
21 private Func<float, Color> _blipFunc;
22
23 private Action _slideGamepadAction;
24
26
27 private bool _soundedUsage;
28
29 private bool _alreadyHovered;
30
31 public UIVerticalSlider(Func<float> getStatus, Action<float> setStatusKeyboard, Action setStatusGamepad, Color color)
32 {
33 _getSliderValue = ((getStatus != null) ? getStatus : ((Func<float>)(() => 0f)));
34 _slideKeyboardAction = ((setStatusKeyboard != null) ? setStatusKeyboard : ((Action<float>)delegate
35 {
36 }));
37 _slideGamepadAction = setStatusGamepad;
39 }
40
41 protected override void DrawSelf(SpriteBatch spriteBatch)
42 {
43 UISliderBase.CurrentAimedSlider = null;
44 if (!Main.mouseLeft)
45 {
46 UISliderBase.CurrentLockedSlider = null;
47 }
50 float sliderValueThatWasSet = FillPercent;
51 bool flag = false;
52 if (DrawValueBarDynamicWidth(spriteBatch, out sliderValueThatWasSet))
53 {
54 flag = true;
55 }
56 if (UISliderBase.CurrentLockedSlider == this || flag)
57 {
58 UISliderBase.CurrentAimedSlider = this;
60 {
61 _slideKeyboardAction(sliderValueThatWasSet);
62 if (!_soundedUsage)
63 {
65 }
66 _soundedUsage = true;
67 }
68 else
69 {
70 _soundedUsage = false;
71 }
72 }
74 {
75 UISliderBase.CurrentLockedSlider = UISliderBase.CurrentAimedSlider;
76 }
78 {
80 }
81 }
82
83 private bool DrawValueBarDynamicWidth(SpriteBatch spriteBatch, out float sliderValueThatWasSet)
84 {
85 sliderValueThatWasSet = 0f;
87 Rectangle rectangle = GetDimensions().ToRectangle();
88 Rectangle rectangle2 = new Rectangle(5, 4, 4, 4);
89 Utils.DrawSplicedPanel(spriteBatch, value, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, rectangle2.X, rectangle2.Width, rectangle2.Y, rectangle2.Height, Color.White);
90 Rectangle rectangle3 = rectangle;
91 rectangle3.X += rectangle2.Left;
92 rectangle3.Width -= rectangle2.Right;
93 rectangle3.Y += rectangle2.Top;
94 rectangle3.Height -= rectangle2.Bottom;
95 Texture2D value2 = TextureAssets.MagicPixel.Value;
96 Rectangle value3 = new Rectangle(0, 0, 1, 1);
97 spriteBatch.Draw(value2, rectangle3, value3, EmptyColor);
98 Rectangle destinationRectangle = rectangle3;
99 destinationRectangle.Height = (int)((float)destinationRectangle.Height * FillPercent);
100 destinationRectangle.Y += rectangle3.Height - destinationRectangle.Height;
101 spriteBatch.Draw(value2, destinationRectangle, value3, FilledColor);
102 Vector2 center = new Vector2(destinationRectangle.Center.X + 1, destinationRectangle.Top);
103 Vector2 size = new Vector2(destinationRectangle.Width + 16, 4f);
104 Rectangle rectangle4 = Utils.CenteredRectangle(center, size);
105 Rectangle destinationRectangle2 = rectangle4;
106 destinationRectangle2.Inflate(2, 2);
107 spriteBatch.Draw(value2, destinationRectangle2, value3, Color.Black);
108 spriteBatch.Draw(value2, rectangle4, value3, Color.White);
109 Rectangle rectangle5 = rectangle3;
110 rectangle5.Inflate(4, 0);
111 bool flag = (_isReallyMouseOvered = rectangle5.Contains(Main.MouseScreen.ToPoint()));
113 {
114 flag = false;
115 }
116 int usageLevel = GetUsageLevel();
117 if (usageLevel == 2)
118 {
119 flag = false;
120 }
121 if (usageLevel == 1)
122 {
123 flag = true;
124 }
125 if (flag || usageLevel == 1)
126 {
127 if (!_alreadyHovered)
128 {
130 }
131 _alreadyHovered = true;
132 }
133 else
134 {
135 _alreadyHovered = false;
136 }
137 if (flag)
138 {
139 sliderValueThatWasSet = Utils.GetLerpValue(rectangle3.Bottom, rectangle3.Top, Main.mouseY, clamped: true);
140 return true;
141 }
142 return false;
143 }
144}
void Draw(Texture2D texture, Vector2 position, Color color)
static void PlaySound(int type, Vector2 position, int style=1)
static Asset< Texture2D > MagicPixel
static Asset< Texture2D > ColorBar
override void DrawSelf(SpriteBatch spriteBatch)
UIVerticalSlider(Func< float > getStatus, Action< float > setStatusKeyboard, Action setStatusGamepad, Color color)
bool DrawValueBarDynamicWidth(SpriteBatch spriteBatch, out float sliderValueThatWasSet)
static TriggersPack Triggers
static Vector2 MouseScreen
Definition Main.cs:2773
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition Main.cs:902
static int mouseY
Definition Main.cs:606
static bool mouseLeft
Definition Main.cs:614
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
static void DrawSplicedPanel(SpriteBatch sb, Texture2D texture, int x, int y, int w, int h, int leftEnd, int rightEnd, int topEnd, int bottomEnd, Color c)
Definition Utils.cs:1964
static float GetLerpValue(float from, float to, float t, bool clamped=false)
Definition Utils.cs:203
static Rectangle CenteredRectangle(Vector2 center, Vector2 size)
Definition Utils.cs:604
void Inflate(int horizontalAmount, int verticalAmount)
Definition Rectangle.cs:84
bool Contains(int x, int y)
Definition Rectangle.cs:92