Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
EmoteButton.cs
Go to the documentation of this file.
1
using
Microsoft.Xna.Framework
;
2
using
Microsoft.Xna.Framework.Graphics
;
3
using
ReLogic.Content
;
4
using
Terraria.Audio
;
5
using
Terraria.Localization
;
6
using
Terraria.UI
;
7
8
namespace
Terraria.GameContent.UI.Elements
;
9
10
public
class
EmoteButton
:
UIElement
11
{
12
private
Asset<Texture2D>
_texture
;
13
14
private
Asset<Texture2D>
_textureBorder
;
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
32
private
Rectangle
GetFrame
()
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
{
48
UpdateFrame
();
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);
81
SoundEngine
.
PlaySound
(12);
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);
94
EmoteBubble
.
MakeLocalPlayerEmote
(
_emoteIndex
);
95
IngameFancyUI
.
Close
();
96
}
97
}
Microsoft.Xna.Framework.Graphics.SpriteBatch.Draw
void Draw(Texture2D texture, Vector2 position, Color color)
Definition
SpriteBatch.cs:397
Microsoft.Xna.Framework.Graphics.SpriteBatch
Definition
SpriteBatch.cs:8
Microsoft.Xna.Framework.Graphics.Texture2D
Definition
Texture2D.cs:13
ReLogic.Content.Asset.Value
T Value
Definition
Asset.cs:26
ReLogic.Content.Asset
Definition
Asset.cs:8
Terraria.Audio.SoundEngine.PlaySound
static void PlaySound(int type, Vector2 position, int style=1)
Definition
SoundEngine.cs:71
Terraria.Audio.SoundEngine
Definition
SoundEngine.cs:10
Terraria.GameContent.UI.Elements.EmoteButton._frameCounter
int _frameCounter
Definition
EmoteButton.cs:20
Terraria.GameContent.UI.Elements.EmoteButton._textureBorder
Asset< Texture2D > _textureBorder
Definition
EmoteButton.cs:14
Terraria.GameContent.UI.Elements.EmoteButton.Update
override void Update(GameTime gameTime)
Definition
EmoteButton.cs:46
Terraria.GameContent.UI.Elements.EmoteButton._emoteIndex
int _emoteIndex
Definition
EmoteButton.cs:16
Terraria.GameContent.UI.Elements.EmoteButton._hovered
bool _hovered
Definition
EmoteButton.cs:18
Terraria.GameContent.UI.Elements.EmoteButton.LeftClick
override void LeftClick(UIMouseEvent evt)
Definition
EmoteButton.cs:91
Terraria.GameContent.UI.Elements.EmoteButton.MouseOut
override void MouseOut(UIMouseEvent evt)
Definition
EmoteButton.cs:85
Terraria.GameContent.UI.Elements.EmoteButton.DrawSelf
override void DrawSelf(SpriteBatch spriteBatch)
Definition
EmoteButton.cs:52
Terraria.GameContent.UI.Elements.EmoteButton.GetFrame
Rectangle GetFrame()
Definition
EmoteButton.cs:32
Terraria.GameContent.UI.Elements.EmoteButton.EmoteButton
EmoteButton(int emoteIndex)
Definition
EmoteButton.cs:22
Terraria.GameContent.UI.Elements.EmoteButton._texture
Asset< Texture2D > _texture
Definition
EmoteButton.cs:12
Terraria.GameContent.UI.Elements.EmoteButton.MouseOver
override void MouseOver(UIMouseEvent evt)
Definition
EmoteButton.cs:78
Terraria.GameContent.UI.Elements.EmoteButton.UpdateFrame
void UpdateFrame()
Definition
EmoteButton.cs:38
Terraria.GameContent.UI.Elements.EmoteButton
Definition
EmoteButton.cs:11
Terraria.GameContent.UI.EmoteBubble.MakeLocalPlayerEmote
static void MakeLocalPlayerEmote(int emoteId)
Definition
EmoteBubble.cs:267
Terraria.GameContent.UI.EmoteBubble.EMOTE_SHEET_VERTICAL_FRAMES
static readonly int EMOTE_SHEET_VERTICAL_FRAMES
Definition
EmoteBubble.cs:42
Terraria.GameContent.UI.EmoteBubble
Definition
EmoteBubble.cs:11
Terraria.GameContent.UI.EmoteID.Search
static readonly IdDictionary Search
Definition
EmoteID.cs:313
Terraria.GameContent.UI.EmoteID
Definition
EmoteID.cs:6
Terraria.Localization.Language.GetTextValue
static string GetTextValue(string key)
Definition
Language.cs:15
Terraria.Localization.Language
Definition
Language.cs:7
Terraria.Main.instance
static Main instance
Definition
Main.cs:283
Terraria.Main.OurFavoriteColor
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition
Main.cs:902
Terraria.Main.Assets
static IAssetRepository Assets
Definition
Main.cs:209
Terraria.Main
Definition
Main.cs:79
Terraria.UI.IngameFancyUI.Close
static void Close()
Definition
IngameFancyUI.cs:151
Terraria.UI.IngameFancyUI
Definition
IngameFancyUI.cs:13
Terraria.UI.UIElement.Height
StyleDimension Height
Definition
UIElement.cs:29
Terraria.UI.UIElement.Width
StyleDimension Width
Definition
UIElement.cs:27
Terraria.UI.UIElement.GetDimensions
CalculatedStyle GetDimensions()
Definition
UIElement.cs:382
Terraria.UI.UIElement
Definition
UIElement.cs:12
Terraria.UI.UIMouseEvent
Definition
UIMouseEvent.cs:6
short
Microsoft.Xna.Framework.Graphics.SurfaceFormat.Vector2
@ Vector2
Microsoft.Xna.Framework.Graphics.SpriteEffects
SpriteEffects
Definition
SpriteEffects.cs:7
Microsoft.Xna.Framework.Graphics
Definition
AlphaTestEffect.cs:1
Microsoft.Xna.Framework
Definition
AlphaTestEffect.cs:1
ReLogic.Content.AssetRequestMode
AssetRequestMode
Definition
AssetRequestMode.cs:4
ReLogic.Content
Definition
IAssetReader.cs:5
Terraria.Audio
Definition
ActiveSound.cs:4
Terraria.GameContent.UI.Elements
Definition
AWorldListItem.cs:8
Terraria.Localization
Definition
GameCulture.cs:5
Terraria.UI
Definition
ChatLine.cs:3
Microsoft.Xna.Framework.Color.Black
static Color Black
Definition
Color.cs:92
Microsoft.Xna.Framework.Color.White
static Color White
Definition
Color.cs:350
Microsoft.Xna.Framework.Color
Definition
Color.cs:12
Microsoft.Xna.Framework.Rectangle.Height
int Height
Definition
Rectangle.cs:23
Microsoft.Xna.Framework.Rectangle.Width
int Width
Definition
Rectangle.cs:20
Microsoft.Xna.Framework.Rectangle
Definition
Rectangle.cs:12
Microsoft.Xna.Framework.Vector2.One
static Vector2 One
Definition
Vector2.cs:29
Microsoft.Xna.Framework.Vector2
Definition
Vector2.cs:12
Terraria.UI.CalculatedStyle.Position
Vector2 Position()
Definition
CalculatedStyle.cs:28
Terraria.UI.CalculatedStyle.Height
float Height
Definition
CalculatedStyle.cs:13
Terraria.UI.CalculatedStyle.Width
float Width
Definition
CalculatedStyle.cs:11
Terraria.UI.CalculatedStyle
Definition
CalculatedStyle.cs:6
Terraria.UI.StyleDimension.Set
void Set(float pixels, float precent)
Definition
StyleDimension.cs:19
source
Terraria.GameContent.UI.Elements
EmoteButton.cs
Generated by
1.10.0