Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EmoteButton.cs
Go to the documentation of this file.
6using Terraria.UI;
7
9
10public class EmoteButton : UIElement
11{
13
15
16 private int _emoteIndex;
17
18 private bool _hovered;
19
20 private int _frameCounter;
21
22 public EmoteButton(int emoteIndex)
23 {
24 _texture = Main.Assets.Request<Texture2D>("Images/Extra_" + (short)48, (AssetRequestMode)1);
25 _textureBorder = Main.Assets.Request<Texture2D>("Images/UI/EmoteBubbleBorder", (AssetRequestMode)1);
26 _emoteIndex = emoteIndex;
27 Rectangle frame = GetFrame();
28 Width.Set(frame.Width, 0f);
29 Height.Set(frame.Height, 0f);
30 }
31
33 {
34 int num = ((_frameCounter >= 10) ? 1 : 0);
35 return _texture.Frame(8, EmoteBubble.EMOTE_SHEET_VERTICAL_FRAMES, _emoteIndex % 4 * 2 + num, _emoteIndex / 4 + 1);
36 }
37
38 private void UpdateFrame()
39 {
40 if (++_frameCounter >= 20)
41 {
42 _frameCounter = 0;
43 }
44 }
45
46 public override void Update(GameTime gameTime)
47 {
49 base.Update(gameTime);
50 }
51
52 protected override void DrawSelf(SpriteBatch spriteBatch)
53 {
54 CalculatedStyle dimensions = GetDimensions();
55 Vector2 vector = dimensions.Position() + new Vector2(dimensions.Width, dimensions.Height) / 2f;
56 Rectangle frame = GetFrame();
57 Rectangle value = frame;
58 value.X = _texture.Width() / 8;
59 value.Y = 0;
60 Vector2 origin = frame.Size() / 2f;
61 Color white = Color.White;
62 Color color = Color.Black;
63 if (_hovered)
64 {
65 color = Main.OurFavoriteColor;
66 }
67 spriteBatch.Draw(_texture.Value, vector, value, white, 0f, origin, 1f, SpriteEffects.None, 0f);
68 spriteBatch.Draw(_texture.Value, vector, frame, white, 0f, origin, 1f, SpriteEffects.None, 0f);
69 spriteBatch.Draw(_textureBorder.Value, vector - Vector2.One * 2f, null, color, 0f, origin, 1f, SpriteEffects.None, 0f);
70 if (_hovered)
71 {
72 string name = EmoteID.Search.GetName(_emoteIndex);
73 string cursorText = "/" + Language.GetTextValue("EmojiName." + name);
74 Main.instance.MouseText(cursorText, 0, 0);
75 }
76 }
77
78 public override void MouseOver(UIMouseEvent evt)
79 {
80 base.MouseOver(evt);
82 _hovered = true;
83 }
84
85 public override void MouseOut(UIMouseEvent evt)
86 {
87 base.MouseOut(evt);
88 _hovered = false;
89 }
90
91 public override void LeftClick(UIMouseEvent evt)
92 {
93 base.LeftClick(evt);
96 }
97}
void Draw(Texture2D texture, Vector2 position, Color color)
static void PlaySound(int type, Vector2 position, int style=1)
override void Update(GameTime gameTime)
override void LeftClick(UIMouseEvent evt)
override void MouseOut(UIMouseEvent evt)
override void DrawSelf(SpriteBatch spriteBatch)
override void MouseOver(UIMouseEvent evt)
static void MakeLocalPlayerEmote(int emoteId)
static readonly int EMOTE_SHEET_VERTICAL_FRAMES
static readonly IdDictionary Search
Definition EmoteID.cs:313
static string GetTextValue(string key)
Definition Language.cs:15
static Main instance
Definition Main.cs:283
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition Main.cs:902
static IAssetRepository Assets
Definition Main.cs:209
StyleDimension Height
Definition UIElement.cs:29
StyleDimension Width
Definition UIElement.cs:27
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void Set(float pixels, float precent)