Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
LayerList.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5public class LayerList : ELayer
6{
7 public class CustomItem
8 {
9 public string lang;
10
11 public Action<int> action;
12
13 public int id;
14 }
15
16 public UIList list;
17
19
21
23
24 public Transform moldItemGeneral;
25
26 public Transform moldItemDetail;
27
28 public bool useItem;
29
30 public bool autoX;
31
32 public bool autoY;
33
34 public bool noSound;
35
37
38 public Vector2 sizeMin;
39
40 public Vector2 sizeMax;
41
42 public Vector2 paddings;
43
44 private bool initialized;
45
46 public List<CustomItem> customItems = new List<CustomItem>();
47
48 protected override void Awake()
49 {
50 base.Awake();
51 if ((bool)buttonReroll)
52 {
53 buttonReroll.SetActive(enable: false);
54 }
55 }
56
57 public override void OnInit()
58 {
59 if ((bool)highlightTarget)
60 {
62 }
64 }
65
66 public override void OnUpdateInput()
67 {
68 foreach (UIList.ButtonPair button in list.buttons)
69 {
70 ItemGeneral itemGeneral = button.component as ItemGeneral;
71 UIButton uIButton = (itemGeneral ? itemGeneral.button1 : (button.component as UIButton));
72 if ((bool)uIButton && uIButton.interactable && !EInput.waitReleaseAnyKey && (bool)uIButton.keyText && !uIButton.keyText.text.IsEmpty() && uIButton.keyText.text == Input.inputString)
73 {
74 SE.ClickOk();
75 uIButton.onClick.Invoke();
76 return;
77 }
78 }
79 base.OnUpdateInput();
80 }
81
82 public LayerList SetMold(int index)
83 {
84 switch (index)
85 {
86 case 0:
87 list.moldItem = moldItemGeneral;
88 break;
89 case 1:
90 list.moldItem = moldItemDetail;
91 break;
92 }
93 return this;
94 }
95
96 public LayerList SetSize(float w = 450f, float h = -1f)
97 {
98 Vector2 sizeDelta = windows[0].Rect().sizeDelta;
99 windows[0].Rect().sizeDelta = new Vector2((w == -1f) ? sizeDelta.x : w, (h == -1f) ? sizeDelta.y : h);
100 if (w != -1f)
101 {
102 autoX = false;
103 }
104 if (h != -1f)
105 {
106 autoY = false;
107 }
108 return this;
109 }
110
111 public LayerList SetPivot(float x, float y = -1f)
112 {
113 windows[0].Rect().pivot = new Vector2(x, y);
114 return this;
115 }
116
117 public void RefreshSize()
118 {
119 RectTransform rectTransform = windows[0].Rect();
120 float x = rectTransform.sizeDelta.x;
121 float y = rectTransform.sizeDelta.y;
122 this.RebuildLayout(recursive: true);
123 Vector2 sizeDelta = scroll.content.Rect().sizeDelta;
124 if (autoX)
125 {
126 x = Mathf.Clamp(sizeDelta.x, sizeMin.x, sizeMax.x) + paddings.x;
127 }
128 if (autoY)
129 {
130 y = Mathf.Clamp(sizeDelta.y, sizeMin.y, sizeMax.y) + paddings.y;
131 }
132 rectTransform.sizeDelta = new Vector2(x, y);
133 }
134
135 public LayerList SetList<TValue>(ICollection<TValue> items, Func<TValue, string> getString, Action<int, string> onSelect, bool autoClose = true)
136 {
137 List<string> strs = new List<string>();
138 foreach (TValue item in items)
139 {
140 strs.Add(getString(item));
141 }
142 SetStringList(() => strs, onSelect, autoClose);
143 return this;
144 }
145
146 public LayerList SetStringList(Func<ICollection<string>> getList, Action<int, string> onSelect, bool autoClose = true)
147 {
148 list.callbacks = new UIList.Callback<string, ItemGeneral>
149 {
150 onClick = delegate(string a, ItemGeneral b)
151 {
152 onSelect(list.items.IndexOf(a), a);
153 if (autoClose)
154 {
155 Close();
156 }
157 },
158 onInstantiate = delegate(string a, ItemGeneral item)
159 {
160 item.button1.mainText.text = a;
161 item.DisableIcon();
162 item.Build();
163 if (noSound)
164 {
165 item.button1.soundClick = null;
166 }
167 },
168 onList = delegate
169 {
170 foreach (string item in getList())
171 {
172 list.Add(item);
173 }
174 }
175 };
176 list.List();
177 RefreshSize();
178 return this;
179 }
180
181 public LayerList SetList2<TValue>(ICollection<TValue> _list, Func<TValue, string> getText, Action<TValue, ItemGeneral> onClick, Action<TValue, ItemGeneral> onInstantiate, bool autoClose = true)
182 {
183 list.callbacks = new UIList.Callback<TValue, ItemGeneral>
184 {
185 onClick = delegate(TValue a, ItemGeneral b)
186 {
187 onClick(a, b);
188 if (autoClose)
189 {
190 Close();
191 }
192 },
193 onInstantiate = delegate(TValue a, ItemGeneral item)
194 {
195 item.button1.mainText.text = getText(a);
196 item.DisableIcon();
197 item.Build();
198 if (noSound)
199 {
200 item.button1.soundClick = null;
201 }
202 if (onInstantiate != null)
203 {
204 onInstantiate(a, item);
205 }
206 },
207 onList = delegate
208 {
209 foreach (TValue item in _list)
210 {
211 list.Add(item);
212 }
213 }
214 };
215 list.List();
216 RefreshSize();
217 UIButton.TryShowTip(base.transform);
218 return this;
219 }
220
221 public LayerList SetListCheck<TValue>(ICollection<TValue> _list, Func<TValue, string> getText, Action<TValue, ItemGeneral> onClick, Action<List<UIList.ButtonPair>> onValidate)
222 {
223 list.moldItem = moldItemCheck.transform;
224 list.callbacks = new UIList.Callback<TValue, ItemGeneral>
225 {
226 onClick = delegate
227 {
228 },
229 onInstantiate = delegate(TValue a, ItemGeneral item)
230 {
231 item.button1.mainText.text = getText(a);
232 item.DisableIcon();
233 item.Build();
234 item.button1.SetOnClick(delegate
235 {
236 onClick(a, item);
237 Validate();
238 });
239 },
240 onList = delegate
241 {
242 foreach (TValue item in _list)
243 {
244 list.Add(item);
245 }
246 }
247 };
248 list.List();
249 Validate();
250 RefreshSize();
251 UIButton.TryShowTip(base.transform);
252 return this;
253 void Validate()
254 {
255 onValidate(list.buttons);
256 }
257 }
258
260 {
261 buttonReroll.SetActive(enable: true);
262 buttonReroll.onClick.RemoveAllListeners();
263 buttonReroll.onClick.AddListener(delegate
264 {
265 list.List();
266 });
267 list.RebuildLayout(recursive: true);
268 RefreshSize();
269 return this;
270 }
271
272 public LayerList ManualList(Action<UIList, LayerList> onInit)
273 {
274 buttonReroll.SetActive(enable: false);
275 list.moldItem = moldItemGeneral;
276 onInit(list, this);
277 list.List();
278 RefreshSize();
279 return this;
280 }
281
282 public LayerList SetHeader(string lang)
283 {
284 windows[0].SetCaption(lang.lang());
285 return this;
286 }
287
289 {
290 noSound = true;
291 return this;
292 }
293
294 public void SetHighlightTarget(UIButton _target)
295 {
296 highlightTarget = _target;
298 }
299
300 private void Update()
301 {
302 if ((bool)highlightTarget)
303 {
305 }
306 }
307
308 private void LateUpdate()
309 {
310 if ((bool)highlightTarget)
311 {
313 }
314 }
315
316 public override void OnKill()
317 {
318 if ((bool)highlightTarget)
319 {
321 {
322 if ((bool)highlightTarget)
323 {
325 {
326 highlightTarget.DoNormalTransition();
327 }
328 else
329 {
330 highlightTarget.DoHighlightTransition();
331 }
332 }
333 });
334 }
335 TooltipManager.Instance.HideTooltips(immediate: true);
336 TooltipManager.Instance.disableHide = null;
338 }
339
340 public void Add(string lang, Action<int> action)
341 {
342 if (!initialized)
343 {
344 initialized = true;
345 }
346 customItems.Add(new CustomItem
347 {
348 lang = lang,
349 action = action,
350 id = customItems.Count
351 });
352 }
353
354 public void Show(bool autoClose = true)
355 {
356 list.callbacks = new UIList.Callback<CustomItem, ItemGeneral>
357 {
358 onClick = delegate(CustomItem a, ItemGeneral b)
359 {
360 a.action(a.id);
361 if (autoClose)
362 {
363 Close();
364 }
365 },
366 onInstantiate = delegate(CustomItem a, ItemGeneral item)
367 {
368 item.button1.mainText.text = a.lang.lang();
369 item.DisableIcon();
370 item.Build();
371 },
372 onList = delegate
373 {
374 foreach (CustomItem customItem in customItems)
375 {
376 list.Add(customItem);
377 }
378 }
379 };
380 buttonReroll.SetActive(enable: false);
381 list.List();
382 RefreshSize();
383 if (!autoClose)
384 {
385 windows[0].AddBottomButton("back", Close, setFirst: true);
386 }
387 }
388}
void WaitForEndOfFrame(Action action)
Definition: BaseCore.cs:61
Definition: EInput.cs:8
static void WaitReleaseKey()
Definition: EInput.cs:650
Definition: ELayer.cs:4
static Core core
Definition: ELayer.cs:7
static bool IsPointerOver(Component c)
Action< int > action
Definition: LayerList.cs:11
List< CustomItem > customItems
Definition: LayerList.cs:46
LayerList SetList2< TValue >(ICollection< TValue > _list, Func< TValue, string > getText, Action< TValue, ItemGeneral > onClick, Action< TValue, ItemGeneral > onInstantiate, bool autoClose=true)
Definition: LayerList.cs:181
LayerList SetSize(float w=450f, float h=-1f)
Definition: LayerList.cs:96
bool initialized
Definition: LayerList.cs:44
LayerList ManualList(Action< UIList, LayerList > onInit)
Definition: LayerList.cs:272
UIButton buttonReroll
Definition: LayerList.cs:18
UIList list
Definition: LayerList.cs:16
UIItem moldItemCheck
Definition: LayerList.cs:22
void LateUpdate()
Definition: LayerList.cs:308
Transform moldItemDetail
Definition: LayerList.cs:26
UIScrollView scroll
Definition: LayerList.cs:36
LayerList SetList< TValue >(ICollection< TValue > items, Func< TValue, string > getString, Action< int, string > onSelect, bool autoClose=true)
Definition: LayerList.cs:135
bool useItem
Definition: LayerList.cs:28
UIButton highlightTarget
Definition: LayerList.cs:20
void Show(bool autoClose=true)
Definition: LayerList.cs:354
LayerList SetHeader(string lang)
Definition: LayerList.cs:282
LayerList SetMold(int index)
Definition: LayerList.cs:82
override void OnInit()
Definition: LayerList.cs:57
void Update()
Definition: LayerList.cs:300
override void OnUpdateInput()
Definition: LayerList.cs:66
Vector2 sizeMax
Definition: LayerList.cs:40
void RefreshSize()
Definition: LayerList.cs:117
LayerList SetPivot(float x, float y=-1f)
Definition: LayerList.cs:111
LayerList EnableReroll()
Definition: LayerList.cs:259
void SetHighlightTarget(UIButton _target)
Definition: LayerList.cs:294
bool autoY
Definition: LayerList.cs:32
Vector2 paddings
Definition: LayerList.cs:42
void Add(string lang, Action< int > action)
Definition: LayerList.cs:340
LayerList SetListCheck< TValue >(ICollection< TValue > _list, Func< TValue, string > getText, Action< TValue, ItemGeneral > onClick, Action< List< UIList.ButtonPair > > onValidate)
Definition: LayerList.cs:221
Transform moldItemGeneral
Definition: LayerList.cs:24
bool autoX
Definition: LayerList.cs:30
override void OnKill()
Definition: LayerList.cs:316
bool noSound
Definition: LayerList.cs:34
LayerList SetStringList(Func< ICollection< string > > getList, Action< int, string > onSelect, bool autoClose=true)
Definition: LayerList.cs:146
LayerList SetNoSound()
Definition: LayerList.cs:288
Vector2 sizeMin
Definition: LayerList.cs:38
override void Awake()
Definition: LayerList.cs:48
List< Window > windows
Definition: Layer.cs:116
virtual void Close()
Definition: Layer.cs:463
static TooltipManager Instance
void HideTooltips(bool immediate=false)
void DoHighlightTransition(bool instant=false)
Definition: UIButton.cs:526
UIText keyText
Definition: UIButton.cs:108
static void TryShowTip(Transform root=null, bool highlight=true, bool ignoreWhenRightClick=true)
Definition: UIButton.cs:778
Definition: UIItem.cs:5
Definition: UIList.cs:9
List< ButtonPair > buttons
Definition: UIList.cs:244
List< object > items
Definition: UIList.cs:241
override void Add(object item)
Definition: UIList.cs:302
override void List()
Definition: UIList.cs:717