Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIBestiaryEntryButton.cs
Go to the documentation of this file.
1
using
System.Collections.Generic
;
2
using
System.Linq
;
3
using
Microsoft.Xna.Framework
;
4
using
Microsoft.Xna.Framework.Graphics
;
5
using
ReLogic.Content
;
6
using
Terraria.Audio
;
7
using
Terraria.GameContent.Bestiary
;
8
using
Terraria.UI
;
9
10
namespace
Terraria.GameContent.UI.Elements
;
11
12
public
class
UIBestiaryEntryButton
:
UIElement
13
{
14
private
UIImage
_bordersGlow
;
15
16
private
UIImage
_bordersOverlay
;
17
18
private
UIImage
_borders
;
19
20
private
UIBestiaryEntryIcon
_icon
;
21
22
public
BestiaryEntry
Entry
{
get
;
private
set
; }
23
24
public
UIBestiaryEntryButton
(
BestiaryEntry
entry
,
bool
isAPrettyPortrait
)
25
{
26
Entry
=
entry
;
27
Height
.
Set
(72f, 0f);
28
Width
.
Set
(72f, 0f);
29
SetPadding
(0f);
30
UIElement
uIElement
=
new
UIElement
31
{
32
Width
=
new
StyleDimension
(-4f, 1f),
33
Height
=
new
StyleDimension
(-4f, 1f),
34
IgnoresMouseInteraction
=
true
,
35
OverflowHidden
=
true
,
36
HAlign
= 0.5f,
37
VAlign
= 0.5f
38
};
39
uIElement
.SetPadding(0f);
40
uIElement
.Append(
new
UIImage
(
Main
.
Assets
.Request<
Texture2D
>(
"Images/UI/Bestiary/Slot_Back"
, (
AssetRequestMode
)1))
41
{
42
VAlign = 0.5f,
43
HAlign = 0.5f
44
});
45
if
(
isAPrettyPortrait
)
46
{
47
Asset<Texture2D>
val =
TryGettingBackgroundImageProvider
(
entry
);
48
if
(val !=
null
)
49
{
50
uIElement
.Append(
new
UIImage
(val)
51
{
52
HAlign
= 0.5f,
53
VAlign
= 0.5f
54
});
55
}
56
}
57
UIBestiaryEntryIcon
uIBestiaryEntryIcon
=
new
UIBestiaryEntryIcon
(
entry
,
isAPrettyPortrait
);
58
uIElement
.Append(
uIBestiaryEntryIcon
);
59
Append
(
uIElement
);
60
_icon
=
uIBestiaryEntryIcon
;
61
int
? num =
TryGettingDisplayIndex
(
entry
);
62
if
(num.HasValue)
63
{
64
UIText
element =
new
UIText
(num.Value.ToString(), 0.9f)
65
{
66
Top
=
new
StyleDimension
(10f, 0f),
67
Left
=
new
StyleDimension
(10f, 0f),
68
IgnoresMouseInteraction
=
true
69
};
70
Append
(element);
71
}
72
_bordersGlow
=
new
UIImage
(
Main
.
Assets
.Request<
Texture2D
>(
"Images/UI/Bestiary/Slot_Selection"
, (
AssetRequestMode
)1))
73
{
74
VAlign
= 0.5f,
75
HAlign
= 0.5f,
76
IgnoresMouseInteraction
=
true
77
};
78
_bordersOverlay
=
new
UIImage
(
Main
.
Assets
.Request<
Texture2D
>(
"Images/UI/Bestiary/Slot_Overlay"
, (
AssetRequestMode
)1))
79
{
80
VAlign
= 0.5f,
81
HAlign
= 0.5f,
82
IgnoresMouseInteraction
=
true
,
83
Color
= Color.White * 0.6f
84
};
85
Append
(
_bordersOverlay
);
86
UIImage
uIImage
=
new
UIImage
(
Main
.
Assets
.Request<
Texture2D
>(
"Images/UI/Bestiary/Slot_Front"
, (
AssetRequestMode
)1))
87
{
88
VAlign
= 0.5f,
89
HAlign
= 0.5f,
90
IgnoresMouseInteraction
=
true
91
};
92
Append
(
uIImage
);
93
_borders
=
uIImage
;
94
if
(
isAPrettyPortrait
)
95
{
96
RemoveChild
(
_bordersOverlay
);
97
}
98
if
(!
isAPrettyPortrait
)
99
{
100
base.OnMouseOver +=
MouseOver
;
101
base.OnMouseOut +=
MouseOut
;
102
}
103
}
104
105
private
Asset<Texture2D>
TryGettingBackgroundImageProvider
(
BestiaryEntry
entry
)
106
{
107
IEnumerable<IBestiaryBackgroundImagePathAndColorProvider>
enumerable
=
from
x
in
entry.Info
108
where
x
is
IBestiaryBackgroundImagePathAndColorProvider
109
select x
as
IBestiaryBackgroundImagePathAndColorProvider
;
110
IEnumerable<IPreferenceProviderElement>
preferences
=
entry
.Info.OfType<
IPreferenceProviderElement
>();
111
IEnumerable<IBestiaryBackgroundImagePathAndColorProvider>
enumerable2
=
enumerable
.Where((
IBestiaryBackgroundImagePathAndColorProvider
provider
) =>
preferences
.Any((
IPreferenceProviderElement
preference
) =>
preference
.Matches(
provider
)));
112
Asset<Texture2D>
val =
null
;
113
foreach
(
IBestiaryBackgroundImagePathAndColorProvider
item
in
enumerable2
)
114
{
115
val = item.GetBackgroundImage();
116
if
(val !=
null
)
117
{
118
return
val;
119
}
120
}
121
foreach
(
IBestiaryBackgroundImagePathAndColorProvider
item2
in
enumerable
)
122
{
123
val =
item2
.GetBackgroundImage();
124
if
(val !=
null
)
125
{
126
return
val;
127
}
128
}
129
return
null
;
130
}
131
132
private
int
?
TryGettingDisplayIndex
(
BestiaryEntry
entry
)
133
{
134
int
? result =
null
;
135
IBestiaryInfoElement
bestiaryInfoElement
=
entry
.Info.FirstOrDefault((
IBestiaryInfoElement
x) => x
is
IBestiaryEntryDisplayIndex
);
136
if
(
bestiaryInfoElement
!=
null
)
137
{
138
result = (
bestiaryInfoElement
as
IBestiaryEntryDisplayIndex
).BestiaryDisplayIndex;
139
}
140
return
result;
141
}
142
143
protected
override
void
DrawSelf
(
SpriteBatch
spriteBatch)
144
{
145
if
(
base
.IsMouseHovering)
146
{
147
Main
.
instance
.MouseText(
_icon
.
GetHoverText
(), 0, 0);
148
}
149
}
150
151
private
void
MouseOver
(
UIMouseEvent
evt
,
UIElement
listeningElement
)
152
{
153
SoundEngine
.
PlaySound
(12);
154
RemoveChild
(
_borders
);
155
RemoveChild
(
_bordersGlow
);
156
RemoveChild
(
_bordersOverlay
);
157
Append
(
_borders
);
158
Append
(
_bordersGlow
);
159
_icon.ForceHover =
true
;
160
}
161
162
private
void
MouseOut
(
UIMouseEvent
evt
,
UIElement
listeningElement
)
163
{
164
RemoveChild
(
_borders
);
165
RemoveChild
(
_bordersGlow
);
166
RemoveChild
(
_bordersOverlay
);
167
Append
(
_bordersOverlay
);
168
Append
(
_borders
);
169
_icon.ForceHover =
false
;
170
}
171
}
Microsoft.Xna.Framework.Graphics.SpriteBatch
Definition
SpriteBatch.cs:8
Microsoft.Xna.Framework.Graphics.Texture2D
Definition
Texture2D.cs:13
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
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.Bestiary.BestiaryEntry
Definition
BestiaryEntry.cs:9
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton._icon
UIBestiaryEntryIcon _icon
Definition
UIBestiaryEntryButton.cs:20
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton.MouseOut
void MouseOut(UIMouseEvent evt, UIElement listeningElement)
Definition
UIBestiaryEntryButton.cs:162
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton.Entry
BestiaryEntry Entry
Definition
UIBestiaryEntryButton.cs:22
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton.TryGettingDisplayIndex
int? TryGettingDisplayIndex(BestiaryEntry entry)
Definition
UIBestiaryEntryButton.cs:132
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton._bordersOverlay
UIImage _bordersOverlay
Definition
UIBestiaryEntryButton.cs:16
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton.TryGettingBackgroundImageProvider
Asset< Texture2D > TryGettingBackgroundImageProvider(BestiaryEntry entry)
Definition
UIBestiaryEntryButton.cs:105
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton.UIBestiaryEntryButton
UIBestiaryEntryButton(BestiaryEntry entry, bool isAPrettyPortrait)
Definition
UIBestiaryEntryButton.cs:24
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton.DrawSelf
override void DrawSelf(SpriteBatch spriteBatch)
Definition
UIBestiaryEntryButton.cs:143
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton._borders
UIImage _borders
Definition
UIBestiaryEntryButton.cs:18
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton._bordersGlow
UIImage _bordersGlow
Definition
UIBestiaryEntryButton.cs:14
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton.MouseOver
void MouseOver(UIMouseEvent evt, UIElement listeningElement)
Definition
UIBestiaryEntryButton.cs:151
Terraria.GameContent.UI.Elements.UIBestiaryEntryButton
Definition
UIBestiaryEntryButton.cs:13
Terraria.GameContent.UI.Elements.UIBestiaryEntryIcon.GetHoverText
string GetHoverText()
Definition
UIBestiaryEntryIcon.cs:69
Terraria.GameContent.UI.Elements.UIBestiaryEntryIcon
Definition
UIBestiaryEntryIcon.cs:10
Terraria.GameContent.UI.Elements.UIImage
Definition
UIImage.cs:9
Terraria.GameContent.UI.Elements.UIText
Definition
UIText.cs:12
Terraria.Main.instance
static Main instance
Definition
Main.cs:283
Terraria.Main.Assets
static IAssetRepository Assets
Definition
Main.cs:209
Terraria.Main
Definition
Main.cs:79
Terraria.UI.UIElement.IgnoresMouseInteraction
bool IgnoresMouseInteraction
Definition
UIElement.cs:41
Terraria.UI.UIElement.Height
StyleDimension Height
Definition
UIElement.cs:29
Terraria.UI.UIElement.HAlign
float HAlign
Definition
UIElement.cs:63
Terraria.UI.UIElement.Append
void Append(UIElement element)
Definition
UIElement.cs:166
Terraria.UI.UIElement.OverflowHidden
bool OverflowHidden
Definition
UIElement.cs:43
Terraria.UI.UIElement.Left
StyleDimension Left
Definition
UIElement.cs:25
Terraria.UI.UIElement.Width
StyleDimension Width
Definition
UIElement.cs:27
Terraria.UI.UIElement.VAlign
float VAlign
Definition
UIElement.cs:65
Terraria.UI.UIElement.RemoveChild
void RemoveChild(UIElement child)
Definition
UIElement.cs:182
Terraria.UI.UIElement.SetPadding
void SetPadding(float pixels)
Definition
UIElement.cs:361
Terraria.UI.UIElement.Top
StyleDimension Top
Definition
UIElement.cs:23
Terraria.UI.UIElement
Definition
UIElement.cs:12
Terraria.UI.UIMouseEvent
Definition
UIMouseEvent.cs:6
Terraria.GameContent.Bestiary.IBestiaryBackgroundImagePathAndColorProvider
Definition
IBestiaryBackgroundImagePathAndColorProvider.cs:8
Terraria.GameContent.Bestiary.IBestiaryEntryDisplayIndex
Definition
IBestiaryEntryDisplayIndex.cs:4
Terraria.GameContent.Bestiary.IBestiaryInfoElement
Definition
IBestiaryInfoElement.cs:6
Terraria.GameContent.Bestiary.IPreferenceProviderElement
Definition
IPreferenceProviderElement.cs:4
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
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Linq.ExceptionArgument.enumerable
@ enumerable
System.Linq
Definition
ImmutableArrayExtensions.cs:4
Terraria.Audio
Definition
ActiveSound.cs:4
Terraria.GameContent.Bestiary
Definition
BestiaryDatabase.cs:5
Terraria.GameContent.UI.Elements
Definition
AWorldListItem.cs:8
Terraria.UI
Definition
ChatLine.cs:3
Microsoft.Xna.Framework.Color
Definition
Color.cs:12
Terraria.UI.StyleDimension.Set
void Set(float pixels, float precent)
Definition
StyleDimension.cs:19
Terraria.UI.StyleDimension
Definition
StyleDimension.cs:4
source
Terraria.GameContent.UI.Elements
UIBestiaryEntryButton.cs
Generated by
1.10.0