Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIClothStyleButton.cs
Go to the documentation of this file.
5using Terraria.UI;
6
8
10{
11 private readonly Player _player;
12
13 public readonly int ClothStyleId;
14
16
18
20
21 private readonly UICharacter _char;
22
23 private bool _hovered;
24
25 private bool _soundedHover;
26
27 private int _realSkinVariant;
28
29 public UIClothStyleButton(Player player, int clothStyleId)
30 {
31 _player = player;
32 ClothStyleId = clothStyleId;
35 _BasePanelTexture = Main.Assets.Request<Texture2D>("Images/UI/CharCreation/CategoryPanel", (AssetRequestMode)1);
36 _selectedBorderTexture = Main.Assets.Request<Texture2D>("Images/UI/CharCreation/CategoryPanelHighlight", (AssetRequestMode)1);
37 _hoveredBorderTexture = Main.Assets.Request<Texture2D>("Images/UI/CharCreation/CategoryPanelBorder", (AssetRequestMode)1);
38 _char = new UICharacter(_player, animated: false, hasBackPanel: false)
39 {
40 HAlign = 0.5f,
41 VAlign = 0.5f
42 };
44 }
45
46 public override void Draw(SpriteBatch spriteBatch)
47 {
49 _player.skinVariant = ClothStyleId;
50 base.Draw(spriteBatch);
51 _player.skinVariant = _realSkinVariant;
52 }
53
54 protected override void DrawSelf(SpriteBatch spriteBatch)
55 {
56 if (_hovered)
57 {
58 if (!_soundedHover)
59 {
61 }
62 _soundedHover = true;
63 }
64 else
65 {
66 _soundedHover = false;
67 }
68 CalculatedStyle dimensions = GetDimensions();
69 Utils.DrawSplicedPanel(spriteBatch, _BasePanelTexture.Value, (int)dimensions.X, (int)dimensions.Y, (int)dimensions.Width, (int)dimensions.Height, 10, 10, 10, 10, Color.White * 0.5f);
71 {
72 Utils.DrawSplicedPanel(spriteBatch, _selectedBorderTexture.Value, (int)dimensions.X + 3, (int)dimensions.Y + 3, (int)dimensions.Width - 6, (int)dimensions.Height - 6, 10, 10, 10, 10, Color.White);
73 }
74 if (_hovered)
75 {
76 Utils.DrawSplicedPanel(spriteBatch, _hoveredBorderTexture.Value, (int)dimensions.X, (int)dimensions.Y, (int)dimensions.Width, (int)dimensions.Height, 10, 10, 10, 10, Color.White);
77 }
78 }
79
80 public override void LeftMouseDown(UIMouseEvent evt)
81 {
82 _player.skinVariant = ClothStyleId;
84 base.LeftMouseDown(evt);
85 }
86
87 public override void MouseOver(UIMouseEvent evt)
88 {
89 base.MouseOver(evt);
90 _hovered = true;
91 _char.SetAnimated(animated: true);
92 }
93
94 public override void MouseOut(UIMouseEvent evt)
95 {
96 base.MouseOut(evt);
97 _hovered = false;
98 _char.SetAnimated(animated: false);
99 }
100}
static void PlaySound(int type, Vector2 position, int style=1)
override void DrawSelf(SpriteBatch spriteBatch)
override void Draw(SpriteBatch spriteBatch)
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
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 StyleDimension FromPixels(float pixels)