Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
NPCPortraitInfoElement.cs
Go to the documentation of this file.
1
using
System
;
2
using
System.Collections.Generic
;
3
using
System.Linq
;
4
using
Microsoft.Xna.Framework
;
5
using
Microsoft.Xna.Framework.Graphics
;
6
using
ReLogic.Content
;
7
using
Terraria.GameContent.UI.Elements
;
8
using
Terraria.UI
;
9
10
namespace
Terraria.GameContent.Bestiary
;
11
12
public
class
NPCPortraitInfoElement
:
IBestiaryInfoElement
13
{
14
private
int
?
_filledStarsCount
;
15
16
public
NPCPortraitInfoElement
(
int
?
rarityStars
=
null
)
17
{
18
_filledStarsCount
=
rarityStars
;
19
}
20
21
public
UIElement
ProvideUIElement
(
BestiaryUICollectionInfo
info
)
22
{
23
UIElement
uIElement
=
new
UIElement
24
{
25
Width =
new
StyleDimension
(0f, 1f),
26
Height =
new
StyleDimension
(112f, 0f)
27
};
28
uIElement
.SetPadding(0f);
29
BestiaryEntry
bestiaryEntry
=
new
BestiaryEntry
();
30
Asset<Texture2D>
portraitBackgroundAsset
=
null
;
31
Color
portraitColor
=
Color
.
White
;
32
bestiaryEntry.Icon =
info
.OwnerEntry.Icon.CreateClone();
33
bestiaryEntry.UIInfoProvider =
info
.OwnerEntry.UIInfoProvider;
34
List<IBestiaryBackgroundOverlayAndColorProvider>
list
=
new
List<IBestiaryBackgroundOverlayAndColorProvider>
();
35
bool
flag = info.UnlockState >
BestiaryEntryUnlockState
.NotKnownAtAll_0;
36
if
(flag)
37
{
38
List<IBestiaryInfoElement>
list2
=
new
List<IBestiaryInfoElement>
();
39
IEnumerable<IBestiaryBackgroundImagePathAndColorProvider>
source
=
info
.OwnerEntry.Info.OfType<
IBestiaryBackgroundImagePathAndColorProvider
>();
40
IEnumerable<IPreferenceProviderElement>
preferences
=
info
.OwnerEntry.Info.OfType<
IPreferenceProviderElement
>();
41
IEnumerable<IBestiaryBackgroundImagePathAndColorProvider>
enumerable
=
source
.Where((
IBestiaryBackgroundImagePathAndColorProvider
provider
) =>
preferences
.Any((
IPreferenceProviderElement
preference
) =>
preference
.Matches(
provider
)));
42
bool
flag2
=
false
;
43
foreach
(
IBestiaryBackgroundImagePathAndColorProvider
item
in
enumerable
)
44
{
45
Asset<Texture2D>
backgroundImage
=
item
.GetBackgroundImage();
46
if
(
backgroundImage
!=
null
)
47
{
48
portraitBackgroundAsset
=
backgroundImage
;
49
flag2
=
true
;
50
Color
?
backgroundColor
=
item
.GetBackgroundColor();
51
if
(
backgroundColor
.HasValue)
52
{
53
portraitColor
=
backgroundColor
.Value;
54
}
55
break
;
56
}
57
}
58
foreach
(
IBestiaryInfoElement
item2
in
info
.OwnerEntry.Info)
59
{
60
if
(
item2
is
IBestiaryBackgroundImagePathAndColorProvider
bestiaryBackgroundImagePathAndColorProvider
)
61
{
62
Asset<Texture2D>
backgroundImage2
=
bestiaryBackgroundImagePathAndColorProvider
.GetBackgroundImage();
63
if
(
backgroundImage2
==
null
)
64
{
65
continue
;
66
}
67
if
(!
flag2
)
68
{
69
portraitBackgroundAsset
=
backgroundImage2
;
70
}
71
Color
?
backgroundColor2
=
bestiaryBackgroundImagePathAndColorProvider
.GetBackgroundColor();
72
if
(
backgroundColor2
.HasValue)
73
{
74
portraitColor
=
backgroundColor2
.Value;
75
}
76
}
77
if
(!
flag2
&&
item2
is
IBestiaryBackgroundOverlayAndColorProvider
bestiaryBackgroundOverlayAndColorProvider
&&
bestiaryBackgroundOverlayAndColorProvider
.GetBackgroundOverlayImage() !=
null
)
78
{
79
list2
.
Add
(
item2
);
80
}
81
}
82
list
.
AddRange
(
from
x
in
list2
.OrderBy(
GetSortingValueForElement
)
83
select x
as
IBestiaryBackgroundOverlayAndColorProvider
);
84
}
85
UIBestiaryNPCEntryPortrait
element =
new
UIBestiaryNPCEntryPortrait
(
bestiaryEntry
,
portraitBackgroundAsset
,
portraitColor
,
list
)
86
{
87
Left
=
new
StyleDimension
(4f, 0f),
88
HAlign = 0f
89
};
90
uIElement
.Append(element);
91
if
(flag &&
_filledStarsCount
.HasValue)
92
{
93
UIElement
element2
=
CreateStarsContainer
();
94
uIElement
.Append(
element2
);
95
}
96
return
uIElement
;
97
}
98
99
private
float
GetSortingValueForElement
(
IBestiaryInfoElement
element)
100
{
101
if
(element
is
IBestiaryBackgroundOverlayAndColorProvider
bestiaryBackgroundOverlayAndColorProvider
)
102
{
103
return
bestiaryBackgroundOverlayAndColorProvider
.DisplayPriority;
104
}
105
return
0f;
106
}
107
108
private
UIElement
CreateStarsContainer
()
109
{
110
int
num = 14;
111
int
num2
= 14;
112
int
num3
= -4;
113
int
num4
= num +
num3
;
114
int
num5
= 5;
115
int
num6
= 5;
116
int
value
=
_filledStarsCount
.Value;
117
float
num7
= 1f;
118
int
num8
=
num4
*
Math
.
Min
(
num6
,
num5
) -
num3
;
119
double
num9
= (double)
num4
*
Math
.
Ceiling
((
double
)
num5
/ (double)
num6
) - (double)
num3
;
120
UIElement
uIElement
=
new
UIPanel
(
Main
.
Assets
.Request<
Texture2D
>(
"Images/UI/Bestiary/Stat_Panel"
, (
AssetRequestMode
)1),
null
, 5, 21)
121
{
122
Width =
new
StyleDimension
((
float
)
num8
+
num7
* 2f, 0f),
123
Height =
new
StyleDimension
((
float
)
num9
+
num7
* 2f, 0f),
124
BackgroundColor = Color.Gray * 0f,
125
BorderColor =
Color
.
Transparent
,
126
Left
=
new
StyleDimension
(10f, 0f),
127
Top =
new
StyleDimension
(6f, 0f),
128
VAlign = 0f
129
};
130
uIElement
.SetPadding(0f);
131
for
(
int
num10
=
num5
- 1;
num10
>= 0;
num10
--)
132
{
133
string
text
=
"Images/UI/Bestiary/Icon_Rank_Light"
;
134
if
(
num10
>=
value
)
135
{
136
text
=
"Images/UI/Bestiary/Icon_Rank_Dim"
;
137
}
138
UIImage
element =
new
UIImage
(
Main
.
Assets
.Request<
Texture2D
>(
text
, (
AssetRequestMode
)1))
139
{
140
Left
=
new
StyleDimension
((
float
)(
num4
* (
num10
%
num6
)) - (
float
)
num8
* 0.5f + (
float
)num * 0.5f, 0f),
141
Top =
new
StyleDimension
((
float
)(
num4
* (
num10
/
num6
)) - (
float
)
num9
* 0.5f + (
float
)
num2
* 0.5f, 0f),
142
HAlign = 0.5f,
143
VAlign = 0.5f
144
};
145
uIElement
.Append(element);
146
}
147
return
uIElement
;
148
}
149
}
Microsoft.Xna.Framework.Graphics.Texture2D
Definition
Texture2D.cs:13
System.Collections.Generic.Dictionary.AddRange
void AddRange(IEnumerable< KeyValuePair< TKey, TValue > > collection)
Definition
Dictionary.cs:837
System.Collections.Generic.Dictionary.Add
void Add(TKey key, TValue value)
Definition
Dictionary.cs:873
System.Collections.Generic.Dictionary
Definition
Dictionary.cs:14
System.Math.Min
static byte Min(byte val1, byte val2)
Definition
Math.cs:912
System.Math.Ceiling
static double Ceiling(double a)
System.Math
Definition
Math.cs:13
Terraria.GameContent.Bestiary.BestiaryEntry
Definition
BestiaryEntry.cs:9
Terraria.GameContent.Bestiary.NPCPortraitInfoElement.CreateStarsContainer
UIElement CreateStarsContainer()
Definition
NPCPortraitInfoElement.cs:108
Terraria.GameContent.Bestiary.NPCPortraitInfoElement._filledStarsCount
int? _filledStarsCount
Definition
NPCPortraitInfoElement.cs:14
Terraria.GameContent.Bestiary.NPCPortraitInfoElement.ProvideUIElement
UIElement ProvideUIElement(BestiaryUICollectionInfo info)
Definition
NPCPortraitInfoElement.cs:21
Terraria.GameContent.Bestiary.NPCPortraitInfoElement.GetSortingValueForElement
float GetSortingValueForElement(IBestiaryInfoElement element)
Definition
NPCPortraitInfoElement.cs:99
Terraria.GameContent.Bestiary.NPCPortraitInfoElement.NPCPortraitInfoElement
NPCPortraitInfoElement(int? rarityStars=null)
Definition
NPCPortraitInfoElement.cs:16
Terraria.GameContent.Bestiary.NPCPortraitInfoElement
Definition
NPCPortraitInfoElement.cs:13
Terraria.GameContent.UI.Elements.UIBestiaryNPCEntryPortrait
Definition
UIBestiaryNPCEntryPortrait.cs:11
Terraria.GameContent.UI.Elements.UIImage
Definition
UIImage.cs:9
Terraria.GameContent.UI.Elements.UIPanel
Definition
UIPanel.cs:9
Terraria.Main.Assets
static IAssetRepository Assets
Definition
Main.cs:209
Terraria.Main
Definition
Main.cs:79
Terraria.UI.UIElement
Definition
UIElement.cs:12
Terraria.GameContent.Bestiary.IBestiaryBackgroundImagePathAndColorProvider
Definition
IBestiaryBackgroundImagePathAndColorProvider.cs:8
Terraria.GameContent.Bestiary.IBestiaryBackgroundOverlayAndColorProvider
Definition
IBestiaryBackgroundOverlayAndColorProvider.cs:8
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.TreeRotation.Left
@ Left
System.Collections.Generic
Definition
IHashKeyCollection.cs:1
System.Linq.ExceptionArgument.source
@ source
System.Linq.ExceptionArgument.enumerable
@ enumerable
System.Linq
Definition
ImmutableArrayExtensions.cs:4
System.ExceptionArgument.list
@ list
System.ExceptionArgument.text
@ text
System.ExceptionArgument.value
@ value
System.ExceptionArgument.item
@ item
System.ExceptionArgument.info
@ info
System
Definition
BlockingCollection.cs:8
Terraria.GameContent.Bestiary.BestiaryEntryUnlockState
BestiaryEntryUnlockState
Definition
BestiaryEntryUnlockState.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.Transparent
static Color Transparent
Definition
Color.cs:76
Microsoft.Xna.Framework.Color.White
static Color White
Definition
Color.cs:350
Microsoft.Xna.Framework.Color
Definition
Color.cs:12
Terraria.GameContent.Bestiary.BestiaryUICollectionInfo
Definition
BestiaryUICollectionInfo.cs:4
Terraria.UI.StyleDimension
Definition
StyleDimension.cs:4
source
Terraria.GameContent.Bestiary
NPCPortraitInfoElement.cs
Generated by
1.10.0