Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIList.cs
Go to the documentation of this file.
1using System;
6using Terraria.UI;
7
9
10public class UIList : UIElement, IEnumerable<UIElement>, IEnumerable
11{
13
14 private class UIInnerList : UIElement
15 {
16 public override bool ContainsPoint(Vector2 point)
17 {
18 return true;
19 }
20
21 protected override void DrawChildren(SpriteBatch spriteBatch)
22 {
23 Vector2 position = base.Parent.GetDimensions().Position();
24 Vector2 dimensions = new Vector2(base.Parent.GetDimensions().Width, base.Parent.GetDimensions().Height);
25 foreach (UIElement element in Elements)
26 {
29 if (Collision.CheckAABBvAABBCollision(position, dimensions, position2, dimensions2))
30 {
31 element.Draw(spriteBatch);
32 }
33 }
34 }
35
36 public override Rectangle GetViewCullingArea()
37 {
38 return base.Parent.GetDimensions().ToRectangle();
39 }
40 }
41
43
45
47
48 private float _innerListHeight;
49
50 public float ListPadding = 5f;
51
53
54 public int Count => _items.Count;
55
56 public UIList()
57 {
58 _innerList.OverflowHidden = false;
59 _innerList.Width.Set(0f, 1f);
60 _innerList.Height.Set(0f, 1f);
61 OverflowHidden = true;
63 }
64
65 public float GetTotalHeight()
66 {
67 return _innerListHeight;
68 }
69
71 {
72 for (int i = 0; i < _items.Count; i++)
73 {
74 if (searchMethod(_items[i]))
75 {
76 _scrollbar.ViewPosition = _items[i].Top.Pixels;
77 break;
78 }
79 }
80 }
81
82 public virtual void Add(UIElement item)
83 {
88 }
89
90 public virtual bool Remove(UIElement item)
91 {
94 return _items.Remove(item);
95 }
96
97 public virtual void Clear()
98 {
100 _items.Clear();
101 }
102
103 public override void Recalculate()
104 {
105 base.Recalculate();
107 }
108
109 public override void ScrollWheel(UIScrollWheelEvent evt)
110 {
111 base.ScrollWheel(evt);
112 if (_scrollbar != null)
113 {
114 _scrollbar.ViewPosition -= evt.ScrollWheelValue;
115 }
116 }
117
118 public override void RecalculateChildren()
119 {
120 base.RecalculateChildren();
121 float num = 0f;
122 for (int i = 0; i < _items.Count; i++)
123 {
124 float num2 = ((_items.Count == 1) ? 0f : ListPadding);
125 _items[i].Top.Set(num, 0f);
126 _items[i].Recalculate();
127 num += _items[i].GetOuterDimensions().Height + num2;
128 }
129 _innerListHeight = num;
130 }
131
132 private void UpdateScrollbar()
133 {
134 if (_scrollbar != null)
135 {
136 float height = GetInnerDimensions().Height;
138 }
139 }
140
146
147 public void UpdateOrder()
148 {
149 if (ManualSortMethod != null)
150 {
152 }
153 else
154 {
156 }
158 }
159
161 {
162 return item1.CompareTo(item2);
163 }
164
166 {
168 if (GetSnapPoint(out var point))
169 {
170 list.Add(point);
171 }
172 foreach (UIElement item in _items)
173 {
174 list.AddRange(item.GetSnapPoints());
175 }
176 return list;
177 }
178
179 protected override void DrawSelf(SpriteBatch spriteBatch)
180 {
181 if (_scrollbar != null)
182 {
184 }
185 Recalculate();
186 }
187
192
197}
static bool CheckAABBvAABBCollision(Vector2 position1, Vector2 dimensions1, Vector2 position2, Vector2 dimensions2)
Definition Collision.cs:157
override bool ContainsPoint(Vector2 point)
Definition UIList.cs:16
override void DrawChildren(SpriteBatch spriteBatch)
Definition UIList.cs:21
override void ScrollWheel(UIScrollWheelEvent evt)
Definition UIList.cs:109
override void DrawSelf(SpriteBatch spriteBatch)
Definition UIList.cs:179
delegate bool ElementSearchMethod(UIElement element)
virtual void Add(UIElement item)
Definition UIList.cs:82
IEnumerator< UIElement > GetEnumerator()
Definition UIList.cs:188
Action< List< UIElement > > ManualSortMethod
Definition UIList.cs:52
override List< SnapPoint > GetSnapPoints()
Definition UIList.cs:165
int SortMethod(UIElement item1, UIElement item2)
Definition UIList.cs:160
void SetScrollbar(UIScrollbar scrollbar)
Definition UIList.cs:141
virtual bool Remove(UIElement item)
Definition UIList.cs:90
void Goto(ElementSearchMethod searchMethod)
Definition UIList.cs:70
void SetView(float viewSize, float maxViewSize)
StyleDimension Height
Definition UIElement.cs:29
virtual void Draw(SpriteBatch spriteBatch)
Definition UIElement.cs:197
void Append(UIElement element)
Definition UIElement.cs:166
CalculatedStyle GetInnerDimensions()
Definition UIElement.cs:377
StyleDimension Width
Definition UIElement.cs:27
bool GetSnapPoint(out SnapPoint point)
Definition UIElement.cs:135
virtual void Recalculate()
Definition UIElement.cs:281
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void RemoveChild(UIElement child)
Definition UIElement.cs:182
StyleDimension Top
Definition UIElement.cs:23
new IEnumerator< T > GetEnumerator()
void Set(float pixels, float precent)