Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIBestiaryInfoLine.cs
Go to the documentation of this file.
3using Terraria.UI;
4
6
8{
9 private T _text;
10
11 private float _textScale = 1f;
12
14
16
17 public int OrderInUIList { get; set; }
18
19 public float TextScale
20 {
21 get
22 {
23 return _textScale;
24 }
25 set
26 {
27 _textScale = value;
28 }
29 }
30
32
33 public string Text
34 {
35 get
36 {
37 if (_text != null)
38 {
39 return _text.ToString();
40 }
41 return "";
42 }
43 }
44
46 {
47 get
48 {
49 return _color;
50 }
51 set
52 {
53 _color = value;
54 }
55 }
56
57 public UIBestiaryInfoLine(T text, float textScale = 1f)
58 {
59 SetText(text, textScale);
60 }
61
62 public override void Recalculate()
63 {
65 base.Recalculate();
66 }
67
68 public void SetText(T text)
69 {
70 SetText(text, _textScale);
71 }
72
73 public virtual void SetText(T text, float textScale)
74 {
75 Vector2 textSize = new Vector2(FontAssets.MouseText.Value.MeasureString(text.ToString()).X, 16f) * textScale;
76 _text = text;
77 _textScale = textScale;
78 _textSize = textSize;
79 MinWidth.Set(textSize.X + PaddingLeft + PaddingRight, 0f);
80 MinHeight.Set(textSize.Y + PaddingTop + PaddingBottom, 0f);
81 }
82
83 protected override void DrawSelf(SpriteBatch spriteBatch)
84 {
85 CalculatedStyle innerDimensions = GetInnerDimensions();
86 Vector2 pos = innerDimensions.Position();
87 pos.Y -= 2f * _textScale;
88 pos.X += (innerDimensions.Width - _textSize.X) * 0.5f;
89 Utils.DrawBorderString(spriteBatch, Text, pos, _color, _textScale);
90 }
91
92 public override int CompareTo(object obj)
93 {
94 if (obj is IManuallyOrderedUIElement manuallyOrderedUIElement)
95 {
96 return OrderInUIList.CompareTo(manuallyOrderedUIElement.OrderInUIList);
97 }
98 return base.CompareTo(obj);
99 }
100}
static Asset< DynamicSpriteFont > MouseText
Definition FontAssets.cs:10
virtual void SetText(T text, float textScale)
override void DrawSelf(SpriteBatch spriteBatch)
StyleDimension MinWidth
Definition UIElement.cs:35
CalculatedStyle GetInnerDimensions()
Definition UIElement.cs:377
StyleDimension MinHeight
Definition UIElement.cs:37
static Vector2 DrawBorderString(SpriteBatch sb, string text, Vector2 pos, Color color, float scale=1f, float anchorx=0f, float anchory=0f, int maxCharactersDisplayed=-1)
Definition Utils.cs:1891
void Set(float pixels, float precent)