Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIDifficultyButton.cs
Go to the documentation of this file.
6using Terraria.UI;
7
9
11{
12 private readonly Player _player;
13
15
17
19
20 private readonly byte _difficulty;
21
22 private readonly Color _color;
23
24 private bool _hovered;
25
26 private bool _soundedHover;
27
28 public UIDifficultyButton(Player player, LocalizedText title, LocalizedText description, byte difficulty, Color color)
29 {
30 _player = player;
31 _difficulty = difficulty;
34 _BasePanelTexture = Main.Assets.Request<Texture2D>("Images/UI/CharCreation/PanelGrayscale", (AssetRequestMode)1);
35 _selectedBorderTexture = Main.Assets.Request<Texture2D>("Images/UI/CharCreation/CategoryPanelHighlight", (AssetRequestMode)1);
36 _hoveredBorderTexture = Main.Assets.Request<Texture2D>("Images/UI/CharCreation/CategoryPanelBorder", (AssetRequestMode)1);
37 _color = color;
38 UIText element = new UIText(title, 0.9f)
39 {
40 HAlign = 0.5f,
41 VAlign = 0f,
44 };
45 Append(element);
46 }
47
48 protected override void DrawSelf(SpriteBatch spriteBatch)
49 {
50 if (_hovered)
51 {
52 if (!_soundedHover)
53 {
55 }
56 _soundedHover = true;
57 }
58 else
59 {
60 _soundedHover = false;
61 }
62 CalculatedStyle dimensions = GetDimensions();
63 int num = 7;
64 if (dimensions.Height < 30f)
65 {
66 num = 5;
67 }
68 int num2 = 10;
69 int num3 = 10;
70 bool num4 = _difficulty == _player.difficulty;
71 Utils.DrawSplicedPanel(spriteBatch, _BasePanelTexture.Value, (int)dimensions.X, (int)dimensions.Y, (int)dimensions.Width, (int)dimensions.Height, num2, num2, num3, num3, Color.Lerp(Color.Black, _color, 0.8f) * 0.5f);
72 if (num4)
73 {
74 Utils.DrawSplicedPanel(spriteBatch, _BasePanelTexture.Value, (int)dimensions.X + num, (int)dimensions.Y + num - 2, (int)dimensions.Width - num * 2, (int)dimensions.Height - num * 2, num2, num2, num3, num3, Color.Lerp(_color, Color.White, 0.7f) * 0.5f);
75 }
76 if (_hovered)
77 {
78 Utils.DrawSplicedPanel(spriteBatch, _hoveredBorderTexture.Value, (int)dimensions.X, (int)dimensions.Y, (int)dimensions.Width, (int)dimensions.Height, num2, num2, num3, num3, Color.White);
79 }
80 }
81
82 public override void LeftMouseDown(UIMouseEvent evt)
83 {
84 _player.difficulty = _difficulty;
86 base.LeftMouseDown(evt);
87 }
88
89 public override void MouseOver(UIMouseEvent evt)
90 {
91 base.MouseOver(evt);
92 _hovered = true;
93 }
94
95 public override void MouseOut(UIMouseEvent evt)
96 {
97 base.MouseOut(evt);
98 _hovered = false;
99 }
100}
static void PlaySound(int type, Vector2 position, int style=1)
override void DrawSelf(SpriteBatch spriteBatch)
UIDifficultyButton(Player player, LocalizedText title, LocalizedText description, byte difficulty, Color color)
static IAssetRepository Assets
Definition Main.cs:209
StyleDimension Height
Definition UIElement.cs:29
void Append(UIElement element)
Definition UIElement.cs:166
StyleDimension Width
Definition UIElement.cs:27
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
StyleDimension Top
Definition UIElement.cs:23
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 Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491
static StyleDimension FromPixels(float pixels)
static StyleDimension FromPixelsAndPercent(float pixels, float percent)