Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UISelectableGroup.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.Events;
5using UnityEngine.UI;
6
7public class UISelectableGroup : MonoBehaviour, IUISkin
8{
9 public enum ColorType
10 {
11 General = 0,
12 Tab = 5,
13 DontChange = 99
14 }
15
17
18 public LayoutGroup layoutButtons;
19
21
22 public bool colorWhenSelected;
23
24 public bool checkbox;
25
26 public bool loopNavigation;
27
28 public bool autoInitialize = true;
29
30 public bool selectOnClick = true;
31
32 public bool useIcon;
33
34 public bool useTransition = true;
35
36 public bool fixRefreshButtons;
37
38 public bool colorWhenDisabled;
39
41
43
45
47
49
51
52 [NonSerialized]
54
55 [NonSerialized]
56 public List<UIButton> list = new List<UIButton>();
57
58 public UnityAction<int> onClick;
59
60 private bool refreshButtons;
61
63 {
64 get
65 {
66 if (!(rootSkin != null))
67 {
69 }
70 return rootSkin;
71 }
72 }
73
74 private void Awake()
75 {
76 SetColors();
77 if (!layoutButtons)
78 {
79 layoutButtons = GetComponent<LayoutGroup>();
80 }
82 {
84 }
86 {
87 refreshButtons = true;
88 }
89 }
90
91 public void ApplySkin()
92 {
93 SetColors();
95 }
96
97 private void OnDisable()
98 {
100 {
101 refreshButtons = true;
102 }
103 }
104
105 public UIButton AddButton(UIButton mold, string text)
106 {
107 UIButton uIButton = Util.Instantiate(mold, layoutButtons);
108 uIButton.mainText.text = text;
109 return uIButton;
110 }
111
112 public void RemoveButton(UIButton button)
113 {
114 list.Remove(button);
115 }
116
117 public void SetButton(UIButton button)
118 {
119 list.Add(button);
120 SetGroup(list.Count - 1);
121 if (checkbox)
122 {
123 button.selected = false;
124 button.DoNormalTransition();
125 }
126 }
127
128 public void SetGroup(int id)
129 {
130 UIButton uIButton = list[id];
131 uIButton.group = this;
132 if (onClick != null)
133 {
134 uIButton.onClick.RemoveAllListeners();
135 uIButton.onClick.AddListener(delegate
136 {
137 onClick(id);
138 });
139 }
140 if (selectOnClick)
141 {
142 uIButton.onClick.RemoveListener(uIButton.Toggle);
143 uIButton.onClick.AddListener(uIButton.Toggle);
144 }
145 }
146
147 public virtual void Init(int index = 0, UnityAction<int> action = null, bool directChildren = false)
148 {
149 list.Clear();
150 if (action != null)
151 {
152 onClick = action;
153 }
154 UIButton[] array = (directChildren ? base.transform.GetComponentsInDirectChildren<UIButton>().ToArray() : base.transform.GetComponentsInChildren<UIButton>(includeInactive: true));
155 foreach (UIButton uIButton in array)
156 {
157 if (!uIButton.tag.Contains("IgnoreSelectable") && uIButton.gameObject.activeSelf)
158 {
159 SetButton(uIButton);
160 }
161 }
162 if (checkbox)
163 {
164 selected = null;
166 }
167 else
168 {
169 Select(index);
170 }
171 }
172
173 public void SetLoop()
174 {
175 if (loopNavigation)
176 {
177 for (int i = 0; i < list.Count; i++)
178 {
179 Navigation navigation = list[i].navigation;
180 navigation.mode = Navigation.Mode.Explicit;
181 navigation.selectOnLeft = ((i == 0) ? list[list.Count - 1] : list[i - 1]);
182 navigation.selectOnRight = ((i + 1 == list.Count) ? list[0] : list[i + 1]);
183 list[i].navigation = navigation;
184 }
185 }
186 }
187
188 public void Select(UIButton button, bool check = true)
189 {
190 if (checkbox)
191 {
192 selected = null;
193 button.SetCheck(check);
194 }
195 else if (!(selected == button))
196 {
197 selected = button;
199 }
200 }
201
202 public void Select(int id)
203 {
204 Select((id == -1 || id >= list.Count) ? null : list[id]);
205 }
206
207 public void Select(string id)
208 {
209 foreach (UIButton item in list)
210 {
211 if (item.name == id)
212 {
213 Select(item);
214 }
215 }
216 }
217
218 public void Select(Func<UIButton, bool> func)
219 {
220 foreach (UIButton item in list)
221 {
222 if (func(item))
223 {
224 Select(item);
225 break;
226 }
227 }
228 }
229
230 public void RefreshButtons()
231 {
232 foreach (UIButton item in list)
233 {
234 if (!item || item.gameObject == null)
235 {
236 continue;
237 }
238 if (colorWhenDisabled && !item.interactable)
239 {
240 item.image.color = colorDisabled;
241 continue;
242 }
243 if (checkbox)
244 {
245 if (useIcon)
246 {
247 item.icon.color = colorDefault;
248 }
249 else
250 {
251 item.image.color = colorDefault;
252 }
253 if (useTransition)
254 {
255 item.selected = false;
256 item.DoNormalTransition();
257 }
258 break;
259 }
261 {
262 item.SetCheck(check: false);
263 if (useIcon)
264 {
265 item.icon.color = colorNoSelection;
266 }
267 else
268 {
269 item.image.color = colorNoSelection;
270 }
271 }
272 else if ((bool)selected && item == selected)
273 {
274 item.SetCheck(check: true);
275 if (useIcon)
276 {
277 item.icon.color = colorSelected;
278 }
279 else
280 {
281 item.image.color = colorSelected;
282 }
283 if (useTransition)
284 {
285 item.selected = true;
286 item.DoNormalTransition();
287 }
288 }
289 else
290 {
291 item.SetCheck(check: false);
292 if (useIcon)
293 {
294 item.icon.color = colorDefault;
295 }
296 else
297 {
298 item.image.color = colorDefault;
299 }
300 if (useTransition)
301 {
302 item.selected = false;
303 item.DoNormalTransition();
304 }
305 }
306 }
307 }
308
309 public void ForceDefaultColor(bool useNoSelection = false)
310 {
311 selected = null;
312 foreach (UIButton item in list)
313 {
314 item.SetCheck(check: false);
315 if (useNoSelection)
316 {
317 if (useIcon)
318 {
319 item.icon.color = colorNoSelection;
320 }
321 else
322 {
323 item.image.color = colorNoSelection;
324 }
325 }
326 else if (useIcon)
327 {
328 item.icon.color = colorDefault;
329 }
330 else
331 {
332 item.image.color = colorDefault;
333 }
334 }
335 }
336
337 public void ToggleInteractable(bool enable)
338 {
339 foreach (UIButton item in list)
340 {
341 item.interactable = enable;
342 }
343 }
344
345 public void SetColors()
346 {
347 if (colorType != ColorType.DontChange)
348 {
350 if (colorType == ColorType.Tab)
351 {
352 colors = colorsEx.tab;
353 }
354 else
355 {
356 colors = colorsEx.general;
357 }
358 colorDefault = colors.colorDefault;
359 colorSelected = colors.colorSelected;
360 colorNoSelection = colors.colorNoSelection;
361 }
362 }
363
364 private void LateUpdate()
365 {
366 if (refreshButtons)
367 {
368 refreshButtons = false;
370 }
371 }
372}
SkinRootStatic currentSkin
Definition: SkinManager.cs:53
static SkinManager Instance
Definition: SkinManager.cs:78
override SkinColorProfileEx ColorsEx
void SetCheck(bool check)
Definition: UIButton.cs:332
void Toggle()
Definition: UIButton.cs:322
void DoNormalTransition(bool instant=true)
Definition: UIButton.cs:531
void Select(UIButton button, bool check=true)
LayoutGroup layoutButtons
void RemoveButton(UIButton button)
SkinRootStatic Skin
List< UIButton > list
SkinColorProfileEx.GroupColors colors
UIButton AddButton(UIButton mold, string text)
void Select(string id)
void SetButton(UIButton button)
UnityAction< int > onClick
void Select(Func< UIButton, bool > func)
virtual void Init(int index=0, UnityAction< int > action=null, bool directChildren=false)
void ToggleInteractable(bool enable)
SkinRootStatic rootSkin
void ForceDefaultColor(bool useNoSelection=false)