Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UIDynamicList.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using Mosframe;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class UIDynamicList : BaseList
8{
9 public class Row
10 {
11 public bool isHeader;
12
13 public List<object> objects = new List<object>();
14
15 public Action<UIItem> onSetHeader;
16 }
17
19
20 public Transform moldItem;
21
22 public Transform moldHeader;
23
24 public int columns = 1;
25
26 public bool autoSize = true;
27
28 public bool captureScreen = true;
29
30 public bool refreshHighlight = true;
31
32 public bool rebuildLayout = true;
33
34 public bool useGrid;
35
36 public bool useHighlight;
37
38 public List<Row> rows = new List<Row>();
39
40 public List<object> objects = new List<object>();
41
42 public object selectedObject;
43
44 public float minHeight;
45
46 [NonSerialized]
47 public bool first = true;
48
49 private bool autoSized;
50
51 public override int ItemCount => objects.Count;
52
53 public override int RowCount => rows.Count;
54
55 public Row NewRow()
56 {
57 Row row = new Row();
58 rows.Add(row);
59 return row;
60 }
61
62 public override void Clear()
63 {
64 rows.Clear();
65 objects.Clear();
66 }
67
68 public override void Add(object o)
69 {
70 if (o == null)
71 {
72 Debug.Log("Tried to add null object");
73 }
74 else
75 {
76 objects.Add(o);
77 }
78 }
79
80 private void _Add(object o)
81 {
82 if (autoSize && !autoSized)
83 {
84 autoSized = true;
85 this.RebuildLayoutTo<Layer>();
86 GridLayoutGroup component = dsv.itemPrototype.GetComponent<GridLayoutGroup>();
87 columns = (int)(this.Rect().rect.width / (component.spacing.x + component.cellSize.x));
88 if (columns < 1)
89 {
90 columns = 1;
91 }
92 }
93 if (rows.Count == 0)
94 {
95 NewRow();
96 }
97 Row row = rows.LastItem();
98 if (row.objects.Count >= columns)
99 {
100 row = NewRow();
101 }
102 row.objects.Add(o);
103 }
104
105 public void RemoveObj(object o)
106 {
107 }
108
109 public void AddHeader(Action<UIItem> onSetHeader)
110 {
111 Row row = NewRow();
112 row.isHeader = true;
113 row.onSetHeader = onSetHeader;
114 NewRow();
115 }
116
117 public void Refresh()
118 {
119 dsv.prevTotalItemCount = -1;
120 dsv.totalItemCount = rows.Count;
121 this.RebuildLayoutTo<Layer>();
122 if (!isBuilt)
123 {
124 dsv.Build();
125 isBuilt = true;
126 }
127 else
128 {
129 dsv.Update();
130 }
133 }
134
135 public int GetIndex(object o)
136 {
137 for (int i = 0; i < rows.Count; i++)
138 {
139 for (int j = 0; j < rows[i].objects.Count; j++)
140 {
141 if (rows[i].objects[j] == o)
142 {
143 return i;
144 }
145 }
146 }
147 return -1;
148 }
149
150 public void UpdateRow(DSVRow dsvRow, int index)
151 {
152 Row row = rows[index];
153 for (int i = 0; i < columns; i++)
154 {
155 if (dsvRow.items.Count <= i)
156 {
157 dsvRow.items.Add(new DSVRow.Item
158 {
159 comp = callbacks.GetComponent(Util.Instantiate(moldItem, dsvRow.transform).transform)
160 });
161 }
162 Component comp = dsvRow.items[i].comp;
163 bool flag = !row.isHeader && row.objects.Count > i;
164 comp.SetActive(flag);
165 dsvRow.items[i].obj = null;
166 if (!flag)
167 {
168 continue;
169 }
170 object obj = row.objects[i];
171 dsvRow.items[i].obj = obj;
172 callbacks.OnRedraw(obj, comp, columns * index + i);
173 UIButton uIButton = comp as UIButton;
174 if (!uIButton)
175 {
176 uIButton = (comp as UIItem)?.button1;
177 }
178 if ((bool)uIButton && callbacks.useOnClick)
179 {
180 uIButton.onClick.RemoveAllListeners();
181 uIButton.onClick.AddListener(delegate
182 {
183 callbacks.OnClick(obj, comp);
184 });
185 }
186 if (useHighlight)
187 {
188 uIButton.selected = obj == selectedObject;
189 if (uIButton.selected)
190 {
191 uIButton.DoHighlightTransition(instant: true);
192 }
193 else
194 {
195 uIButton.DoNormalTransition();
196 }
197 }
198 }
199 if (dsvRow.items.Count > columns)
200 {
201 for (int j = columns; j < dsvRow.items.Count; j++)
202 {
203 dsvRow.items[j].comp.SetActive(enable: false);
204 dsvRow.items[j].obj = null;
205 }
206 }
207 if ((bool)dsvRow.itemHeader)
208 {
209 if (row.isHeader)
210 {
211 dsvRow.itemHeader.SetActive(enable: true);
212 row.onSetHeader(dsvRow.itemHeader);
213 }
214 else
215 {
216 dsvRow.itemHeader.SetActive(enable: false);
217 }
218 }
219 if ((bool)dsvRow.bgGrid)
220 {
221 dsvRow.bgGrid.SetActive(useGrid);
222 }
223 if (useGrid)
224 {
225 dsvRow.bgGrid.Rect().sizeDelta = new Vector2((float)row.objects.Count * dsvRow.GetComponent<GridLayoutGroup>().cellSize.x, 0f);
226 dsvRow.bgGrid.uvRect = new Rect(0f, 0f, row.objects.Count, 1f);
227 }
228 }
229
230 public override void Redraw()
231 {
232 List();
233 }
234
235 public override void List()
236 {
237 List(sortMode);
238 }
239
240 public override void List(UIList.SortMode m)
241 {
242 if (!first && captureScreen)
243 {
245 }
246 first = false;
247 sortMode = m;
248 Clear();
249 callbacks.OnList(sortMode);
250 foreach (object @object in objects)
251 {
252 _Add(@object);
253 }
254 Layer root = base.transform.GetComponentInParent<Layer>();
255 root = root.parent?.GetComponent<Layer>() ?? root;
256 if (objects.Count != 0)
257 {
259 {
261 UIButton.TryShowTip(root.transform);
263 {
265 UIButton.TryShowTip(root.transform);
266 if (captureScreen)
267 {
269 {
271 });
272 }
273 });
274 }
275 }
276 else
277 {
279 }
280 Refresh();
281 }
282
283 public void OnResizeWindow()
284 {
285 if (autoSize)
286 {
287 this.RebuildLayoutTo<Layer>();
288 GridLayoutGroup component = dsv.itemPrototype.GetComponent<GridLayoutGroup>();
289 columns = (int)(this.Rect().rect.width / (component.spacing.x + component.cellSize.x));
290 if (columns < 1)
291 {
292 columns = 1;
293 }
294 List();
295 dsv.OnResize();
296 }
297 }
298
299 public void Select<T>(Func<T, bool> func, bool invoke = false)
300 {
301 foreach (DSVRow container in dsv.containers)
302 {
303 foreach (DSVRow.Item item in container.items)
304 {
305 UIButton uIButton = item.comp as UIButton;
306 if (!(uIButton == null) && uIButton.gameObject.activeInHierarchy)
307 {
308 T arg = (T)item.obj;
309 if (func(arg))
310 {
311 Select(item.obj, invoke);
312 return;
313 }
314 }
315 }
316 }
317 }
318
319 public bool Select(object o, bool invoke = false)
320 {
321 selectedObject = o;
322 return RefreshHighlight(invoke);
323 }
324
325 public bool RefreshHighlight(bool invoke = false)
326 {
327 bool result = false;
328 foreach (DSVRow container in dsv.containers)
329 {
330 foreach (DSVRow.Item item in container.items)
331 {
332 UIButton b = item.comp as UIButton;
333 if (b == null || !b.gameObject.activeInHierarchy)
334 {
335 continue;
336 }
337 b.selected = item.obj == selectedObject;
338 if (b.selected)
339 {
341 {
342 if (b != null)
343 {
345 b.DoHighlightTransition(instant: true);
346 }
347 });
348 result = true;
349 b.DoHighlightTransition(instant: true);
350 if (invoke)
351 {
352 callbacks.OnClick(item.obj, item.comp);
353 }
354 }
355 else
356 {
358 }
359 }
360 }
361 return result;
362 }
363
364 public void Scroll(int index = 0)
365 {
366 if (index <= 0)
367 {
368 dsv.contentAnchoredPosition = 0f;
369 }
370 else
371 {
372 dsv.scrollByItemIndex(index);
373 }
374 dsv.refresh();
375 }
376
377 public void Scroll(object o)
378 {
379 int index = objects.IndexOf(o);
380 Scroll(index);
381 }
382
383 public T GetComp<T>(object o) where T : Component
384 {
385 foreach (DSVRow container in dsv.containers)
386 {
387 foreach (DSVRow.Item item in container.items)
388 {
389 if (item.obj == o)
390 {
391 return item.comp as T;
392 }
393 }
394 }
395 return null;
396 }
397}
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
virtual void FreezeScreen(float duration=0.3f)
Definition: BaseCore.cs:80
void WaitForEndOfFrame(Action action)
Definition: BaseCore.cs:61
List< Action > actionsNextFrame
Definition: BaseCore.cs:31
virtual void UnfreezeScreen()
Definition: BaseCore.cs:84
static BaseCore Instance
Definition: BaseCore.cs:11
void RefreshNoItem()
Definition: BaseList.cs:69
bool isBuilt
Definition: BaseList.cs:36
UIList.ICallback callbacks
Definition: BaseList.cs:13
UIList.SortMode sortMode
Definition: BaseList.cs:33
void RefreshBGGrid()
Definition: BaseList.cs:89
Definition: DSVRow.cs:7
UIItem itemHeader
Definition: DSVRow.cs:17
RawImage bgGrid
Definition: DSVRow.cs:19
List< Item > items
Definition: DSVRow.cs:15
Definition: Layer.cs:9
Layer parent
Definition: Layer.cs:104
LinkedList< DSVRow > containers
void scrollByItemIndex(int itemIndex)
static TooltipManager Instance
void HideTooltips(bool immediate=false)
void DoHighlightTransition(bool instant=false)
Definition: UIButton.cs:526
static void TryHihlight()
Definition: UIButton.cs:768
bool selected
Definition: UIButton.cs:163
static void TryShowTip(Transform root=null, bool highlight=true, bool ignoreWhenRightClick=true)
Definition: UIButton.cs:778
void DoNormalTransition(bool instant=true)
Definition: UIButton.cs:531
List< object > objects
Action< UIItem > onSetHeader
override int RowCount
void RemoveObj(object o)
override void List()
List< Row > rows
override void List(UIList.SortMode m)
List< object > objects
int GetIndex(object o)
void Scroll(int index=0)
Transform moldItem
override void Redraw()
override void Add(object o)
void Scroll(object o)
void AddHeader(Action< UIItem > onSetHeader)
void UpdateRow(DSVRow dsvRow, int index)
bool Select(object o, bool invoke=false)
DynamicScrollView dsv
void Select< T >(Func< T, bool > func, bool invoke=false)
bool RefreshHighlight(bool invoke=false)
Transform moldHeader
void _Add(object o)
object selectedObject
void OnResizeWindow()
override void Clear()
override int ItemCount
bool refreshHighlight
T GetComp< T >(object o)
Definition: UIItem.cs:5
Definition: UIList.cs:9
SortMode
Definition: UIList.cs:27