Elin Decompiled Documentation EA 23.358.1 Nightly
Loading...
Searching...
No Matches
Layer.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using DG.Tweening;
4using UnityEngine;
5using UnityEngine.Events;
6using UnityEngine.UI;
7
8public class Layer : MonoBehaviour, IUISkin
9{
10 [Serializable]
11 public class Option
12 {
13 public enum ScreenlockType
14 {
15 Default,
16 None,
17 Dark,
19 }
20
21 public Playlist playlist;
22
23 public SoundData bgm;
24
25 public SoundData soundActivate;
26
27 public SoundData soundDeactivate;
28
29 public bool canClose = true;
30
31 public bool screenClickClose;
32
34
35 public bool passive;
36
37 public bool important;
38
39 public bool hideHud;
40
41 public bool allowGeneralInput = true;
42
44
45 public bool rebuildLayout;
46
47 public bool persist;
48
49 public bool blur;
50
51 public bool hideOnUnfocus;
52
53 public bool hideOthers = true;
54
55 public bool hideInspector = true;
56
57 public bool pauseGame = true;
58
59 public bool consumeInput = true;
60
61 public bool dontRefreshHint;
62
63 public bool dontShowHint;
64
65 public bool hideFloatUI;
66
67 public bool hideWidgets;
68
70 }
71
72 public static int skipInput;
73
74 public static bool closeOnRightClick;
75
76 public static bool rightClicked;
77
78 public static bool cancelKeyDown;
79
80 public static bool ignoreSounds;
81
82 public static Transform blurStopInstance;
83
84 public Option option;
85
86 public UnityEvent onKill;
87
88 public Anime animeIn;
89
91
92 public bool closeOthers;
93
94 public bool defaultActionMode = true;
95
96 protected RectTransform _rect;
97
98 protected bool isDestroyed;
99
100 [NonSerialized]
102
103 [NonSerialized]
104 public Layer parent;
105
106 [NonSerialized]
107 public string idLayer;
108
109 [NonSerialized]
110 public List<Layer> layers = new List<Layer>();
111
112 [NonSerialized]
113 public Vector2 lastParentPos;
114
115 [NonSerialized]
116 public List<Window> windows = new List<Window>();
117
118 [NonSerialized]
119 public string langHint;
120
121 public static string[] searchPath = new string[3] { "Layer", "Layer/Dialog", "Layer/LayerHome" };
122
123 public Layer TopLayer => layers.LastItem();
124
125 public string uid => base.name;
126
127 public virtual RectTransform rectLayers => _rect;
128
129 public virtual bool blockWidgetClick => true;
130
131 public virtual string GetTextHeader(Window window)
132 {
133 string text = (window.CurrentTab?.idLang ?? window.setting.textCaption).lang();
134 if (!HeaderIsListOf(window.idTab))
135 {
136 return text;
137 }
138 return "_listOf".lang(text);
139 }
140
141 public virtual bool HeaderIsListOf(int id)
142 {
143 return false;
144 }
145
146 protected virtual void Awake()
147 {
148 _rect = this.Rect();
149 foreach (Window componentsInDirectChild in this.GetComponentsInDirectChildren<Window>())
150 {
151 windows.Add(componentsInDirectChild);
152 }
153 for (int i = 0; i < windows.Count; i++)
154 {
155 windows[i].windowIndex = i;
156 }
157 if (windows.Count > 1 && windows[0].transform.position.x < windows[1].transform.position.x)
158 {
159 windows[0].transform.SetAsLastSibling();
160 }
161 }
162
163 public virtual void Init()
164 {
166 {
168 }
169 OnInit();
170 for (int i = 0; i < windows.Count; i++)
171 {
172 windows[i].Init(this);
173 }
174 ApplySkin();
175 OnAfterInit();
176 SoundManager.current.Play(option.soundActivate);
177 if ((bool)animeIn)
178 {
180 }
181 if ((bool)option.bgm)
182 {
183 SoundManager.current.PlayBGM(option.bgm);
184 }
185 if ((bool)option.playlist)
186 {
187 SoundManager.current.SwitchPlaylist(option.playlist);
188 }
190 {
191 this.RebuildLayout(recursive: true);
192 }
193 }
194
195 public virtual void OnInit()
196 {
197 }
198
199 public virtual void OnAfterInit()
200 {
201 }
202
203 public virtual void ApplySkin()
204 {
205 }
206
207 public void ShowScreenLock(string id)
208 {
209 if ((bool)screenLock)
210 {
211 UnityEngine.Object.DestroyImmediate(screenLock.gameObject);
212 }
213 screenLock = Util.Instantiate<Button>("UI/Screenlock" + id, rectLayers);
214 screenLock.transform.SetAsFirstSibling();
215 }
216
217 public void UpdateInput()
218 {
220 {
221 skipInput--;
222 }
223 else if (layers.Count > 0)
224 {
225 layers.LastItem().UpdateInput();
226 }
227 else if ((EInput.leftMouse.down || (EInput.rightMouse.down && option.screenClickCloseRight)) && (((bool)screenLock && InputModuleEX.IsPointerOver(screenLock)) || (!InputModuleEX.IsPointerOverRoot(this) && !InputModuleEX.GetComponentOf<RectTransform>())))
228 {
230 {
231 OnBack();
232 }
233 }
234 else if (rightClicked || cancelKeyDown)
235 {
236 if ((bool)UIDropdown.activeInstance)
237 {
239 }
240 else if (rightClicked)
241 {
242 OnRightClick();
243 }
244 else
245 {
246 OnBack();
247 }
248 }
249 else
250 {
252 }
253 }
254
255 public virtual void OnUpdateInput()
256 {
257 }
258
259 public virtual void OnRightClick()
260 {
262 {
263 OnBack();
264 }
265 }
266
267 public virtual bool OnBack()
268 {
269 if (layers.Count > 0)
270 {
271 return layers.LastItem().OnBack();
272 }
273 if (!parent)
274 {
275 return false;
276 }
277 if (option.canClose)
278 {
279 Close();
280 return true;
281 }
282 return false;
283 }
284
285 public virtual void OnChangeLayer()
286 {
287 }
288
289 public static T Create<T>() where T : Layer
290 {
291 return Create(typeof(T).Name) as T;
292 }
293
294 public static T Create<T>(string path) where T : Layer
295 {
296 return Create(path) as T;
297 }
298
299 public static Layer Create(string path)
300 {
301 Layer layer = null;
302 string text = path.Split('/').LastItem();
303 string[] array = searchPath;
304 foreach (string text2 in array)
305 {
306 layer = Resources.Load<Layer>("UI/" + text2 + "/" + path);
307 if (!layer)
308 {
309 layer = Resources.Load<Layer>("UI/" + text2 + "/" + path + "/" + text);
310 }
311 if ((bool)layer)
312 {
313 break;
314 }
315 }
316 if (!layer)
317 {
318 Debug.Log(path + " --- " + text);
319 }
320 layer = UnityEngine.Object.Instantiate(layer);
321 Layer layer2 = layer;
322 string text3 = (layer.name = text);
323 layer2.idLayer = text3;
324 layer.OnCreate();
325 return layer;
326 }
327
328 public virtual void OnCreate()
329 {
330 }
331
332 public void _AddLayer(string id)
333 {
334 ToggleLayer(id);
335 }
336
337 public Layer AddLayer(string id)
338 {
339 return AddLayer(Create(id));
340 }
341
342 public T AddLayer<T>() where T : Layer
343 {
344 return AddLayer(typeof(T).Name) as T;
345 }
346
347 public T AddLayer<T>(string id) where T : Layer
348 {
349 return AddLayer(id.IsEmpty(typeof(T).Name)) as T;
350 }
351
353 {
354 return AddLayerDontCloseOthers(Create<T>()) as T;
355 }
356
357 public T AddLayerDontCloseOthers<T>(string path) where T : Layer
358 {
359 return AddLayerDontCloseOthers(Create<T>(path)) as T;
360 }
361
363 {
364 l.option.screenlockType = Option.ScreenlockType.Default;
365 l.closeOthers = false;
366 AddLayer(l);
367 return l;
368 }
369
370 public T GetOrAddLayer<T>() where T : Layer
371 {
372 T val = GetLayer<T>();
373 if (!val)
374 {
375 val = AddLayer<T>();
376 }
377 return val;
378 }
379
380 public virtual void OnBeforeAddLayer()
381 {
382 }
383
384 public virtual void OnAfterAddLayer()
385 {
386 }
387
389 {
391 if (l.option.persist && l.isDestroyed)
392 {
393 l.isDestroyed = false;
394 l.gameObject.SetActive(value: true);
395 layers.Add(l);
396 if (!ignoreSounds)
397 {
398 SoundManager.current.Play(l.option.soundActivate);
399 }
400 return l;
401 }
402 l.gameObject.SetActive(value: true);
403 l.parent = this;
404 l.transform.SetParent(rectLayers, worldPositionStays: false);
405 l.Init();
406 if (l.option.hideOthers)
407 {
408 foreach (Layer layer in layers)
409 {
410 if (layer.option.hideOnUnfocus)
411 {
412 CanvasGroup canvasGroup = layer.gameObject.GetComponent<CanvasGroup>();
413 if (!canvasGroup)
414 {
415 canvasGroup = layer.gameObject.AddComponent<CanvasGroup>();
416 }
417 canvasGroup.alpha = 0f;
418 }
419 }
420 }
421 layers.Add(l);
423 l._rect.anchorMin = Vector2.zero;
424 l._rect.anchorMax = Vector2.one;
425 l._rect.anchoredPosition = Vector2.zero;
426 l._rect.sizeDelta = Vector2.zero;
427 l.OnAfterAddLayer();
428 return l;
429 }
430
431 public void ToggleLayer(string id)
432 {
433 Layer layer = GetLayer(id);
434 if ((bool)layer)
435 {
436 RemoveLayer(layer);
437 }
438 else
439 {
440 AddLayer(id);
441 }
442 }
443
444 public T ToggleLayer<T>(string id = null) where T : Layer
445 {
446 T layer = GetLayer<T>();
447 if ((bool)layer)
448 {
449 RemoveLayer(layer);
450 return null;
451 }
452 return AddLayer<T>(id);
453 }
454
455 public void WaitAndClose()
456 {
458 }
459
460 public void OnClickClose()
461 {
462 if (!BaseCore.BlockInput())
463 {
464 Close();
465 }
466 }
467
468 public virtual void Close()
469 {
470 if ((bool)animeOut)
471 {
472 animeOut.Play(rectLayers).OnComplete(_Close);
473 }
474 else
475 {
476 _Close();
477 }
478 }
479
480 protected virtual void _Close()
481 {
482 if ((bool)parent)
483 {
484 parent.RemoveLayer(this);
485 }
486 else
487 {
488 Kill();
489 }
490 skipInput = 2;
491 }
492
493 public void CloseLayers()
494 {
495 for (int num = layers.Count - 1; num >= 0; num--)
496 {
497 layers[num].Close();
498 }
499 }
500
501 public void RemoveLayers(bool removeImportant = false)
502 {
503 for (int num = layers.Count - 1; num >= 0; num--)
504 {
505 if (removeImportant || (!layers[num].option.important && !layers[num].option.persist))
506 {
507 RemoveLayer(layers[num]);
508 }
509 }
510 }
511
512 public bool RemoveLayer<T>()
513 {
514 for (int num = layers.Count - 1; num >= 0; num--)
515 {
516 if (layers[num] is T)
517 {
518 RemoveLayer(layers[num]);
519 return true;
520 }
521 }
522 return false;
523 }
524
525 public void RemoveLayer(Layer l)
526 {
527 _RemoveLayer(l);
528 }
529
530 private void _RemoveLayer(Layer l)
531 {
532 l.Kill();
533 layers.Remove(l);
534 if (layers.Count > 0)
535 {
536 Layer layer = layers.LastItem();
537 if (!layer.isDestroyed)
538 {
539 CanvasGroup component = layer.GetComponent<CanvasGroup>();
540 if (layer.option.hideOnUnfocus && (bool)component)
541 {
542 component.alpha = 1f;
543 }
544 }
545 }
547 }
548
549 protected virtual void Kill()
550 {
551 if (isDestroyed || base.gameObject == null)
552 {
553 return;
554 }
555 isDestroyed = true;
556 foreach (Layer layer in layers)
557 {
558 layer.Kill();
559 }
560 if (windows.Count > 0)
561 {
563 foreach (Window window in windows)
564 {
565 window.OnKill();
566 }
567 }
568 OnKill();
569 onKill.Invoke();
570 if (option.persist)
571 {
572 base.gameObject.SetActive(value: false);
573 }
574 else
575 {
576 UnityEngine.Object.DestroyImmediate(base.gameObject);
577 }
578 }
579
580 public virtual void OnKill()
581 {
582 }
583
584 public Layer SetOnKill(Action action)
585 {
586 onKill.AddListener(delegate
587 {
588 action();
589 });
590 return this;
591 }
592
593 public void DisableClose()
594 {
595 option.canClose = false;
596 foreach (Window window in windows)
597 {
598 window.buttonClose.SetActive(enable: false);
599 }
600 }
601
602 public void Delay(float duration = 0.05f)
603 {
604 foreach (Window window in windows)
605 {
606 window.setting.anime = null;
607 }
608 _rect.anchoredPosition = new Vector2(10000f, 10000f);
609 TweenUtil.Tween(0.1f, delegate
610 {
612 {
613 if ((bool)this && (bool)base.gameObject)
614 {
615 _rect.anchoredPosition = new Vector2(0f, 0f);
616 foreach (Window window2 in windows)
617 {
618 window2.ClampToScreen();
619 }
621 }
622 });
623 });
624 }
625
626 public Layer SetDelay(float d)
627 {
628 CanvasGroup cg = GetComponent<CanvasGroup>() ?? base.gameObject.AddComponent<CanvasGroup>();
629 cg.alpha = 0f;
630 TweenUtil.Tween(d, null, delegate
631 {
632 cg.alpha = 1f;
633 });
634 return this;
635 }
636
637 public Layer GetLayer(string id)
638 {
639 foreach (Layer layer in layers)
640 {
641 if (layer.idLayer == id)
642 {
643 return layer;
644 }
645 }
646 return null;
647 }
648
649 public T GetLayer<T>(bool fromTop = false) where T : Layer
650 {
651 if (fromTop)
652 {
653 for (int num = layers.Count - 1; num >= 0; num--)
654 {
655 Layer layer = layers[num];
656 if (layer is T)
657 {
658 return layer as T;
659 }
660 }
661 }
662 else
663 {
664 foreach (Layer layer2 in layers)
665 {
666 if (layer2 is T)
667 {
668 return layer2 as T;
669 }
670 }
671 }
672 return null;
673 }
674
676 {
677 if (layers.Count > 0)
678 {
679 return layers.LastItem().GetTopLayer();
680 }
681 return this;
682 }
683
684 public void SwitchContent(int idWindow, int i)
685 {
686 windows[idWindow].SwitchContent(i);
687 }
688
689 public virtual void OnSwitchContent(Window window)
690 {
691 }
692
693 public Layer SetTitles(string langList, string idHeaderRow = null)
694 {
695 windows[0].SetTitles(langList, idHeaderRow);
696 return this;
697 }
698
699 public bool IsBlockWidgetClick()
700 {
701 foreach (Layer layer in layers)
702 {
703 if (layer.blockWidgetClick)
704 {
705 return true;
706 }
707 }
708 return blockWidgetClick;
709 }
710
711 public bool IsHideHud()
712 {
713 foreach (Layer layer in layers)
714 {
715 if (layer.IsHideHud())
716 {
717 return true;
718 }
719 }
720 return option.hideHud;
721 }
722
724 {
725 foreach (Layer layer in layers)
726 {
727 if (!layer.IsAllowGeneralInput())
728 {
729 return false;
730 }
731 }
732 return option.allowGeneralInput;
733 }
734
735 public bool IsUseBlur()
736 {
737 if ((bool)blurStopInstance)
738 {
739 return false;
740 }
741 foreach (Layer layer in layers)
742 {
743 if (layer.IsUseBlur())
744 {
745 return true;
746 }
747 }
748 return option.blur;
749 }
750
751 public bool IsPointerOnLayer()
752 {
753 foreach (GameObject item in InputModuleEX.GetPointerEventData().hovered)
754 {
755 if (item.GetComponentInParent<Layer>() == this)
756 {
757 return true;
758 }
759 }
760 return false;
761 }
762}
Definition: Anime.cs:6
virtual Tween Play(Transform trans, UnityAction onComplete=null, float duration=-1f, float delay=0f)
Definition: Anime.cs:7
void WaitForEndOfFrame(Action action)
Definition: BaseCore.cs:61
static Func< bool > BlockInput
Definition: BaseCore.cs:15
static BaseCore Instance
Definition: BaseCore.cs:11
static void SetCursor(CursorInfo info=null, int _priority=0)
Definition: EInput.cs:8
static ButtonState leftMouse
Definition: EInput.cs:360
static ButtonState rightMouse
Definition: EInput.cs:362
static bool IsPointerOver(Component c)
static PointerEventData GetPointerEventData(int pointerId=-1)
static bool IsPointerOverRoot(Component c)
bool hideHud
Definition: Layer.cs:39
bool consumeInput
Definition: Layer.cs:59
bool hideFloatUI
Definition: Layer.cs:65
bool hideOnUnfocus
Definition: Layer.cs:51
bool dontRefreshHint
Definition: Layer.cs:61
bool blur
Definition: Layer.cs:49
bool allowInventoryInteraction
Definition: Layer.cs:43
SoundData bgm
Definition: Layer.cs:23
Playlist playlist
Definition: Layer.cs:21
bool hideOthers
Definition: Layer.cs:53
bool screenClickClose
Definition: Layer.cs:31
SoundData soundDeactivate
Definition: Layer.cs:27
bool pauseGame
Definition: Layer.cs:57
bool hideWidgets
Definition: Layer.cs:67
ScreenlockType
Definition: Layer.cs:14
bool screenClickCloseRight
Definition: Layer.cs:33
ScreenlockType screenlockType
Definition: Layer.cs:69
bool rebuildLayout
Definition: Layer.cs:45
SoundData soundActivate
Definition: Layer.cs:25
bool allowGeneralInput
Definition: Layer.cs:41
bool passive
Definition: Layer.cs:35
bool persist
Definition: Layer.cs:47
bool dontShowHint
Definition: Layer.cs:63
bool important
Definition: Layer.cs:37
bool canClose
Definition: Layer.cs:29
bool hideInspector
Definition: Layer.cs:55
Definition: Layer.cs:9
static bool ignoreSounds
Definition: Layer.cs:80
void RemoveLayer(Layer l)
Definition: Layer.cs:525
UnityEvent onKill
Definition: Layer.cs:86
static Transform blurStopInstance
Definition: Layer.cs:82
List< Layer > layers
Definition: Layer.cs:110
virtual bool blockWidgetClick
Definition: Layer.cs:129
T GetLayer< T >(bool fromTop=false)
Definition: Layer.cs:649
Layer SetTitles(string langList, string idHeaderRow=null)
Definition: Layer.cs:693
void _RemoveLayer(Layer l)
Definition: Layer.cs:530
void DisableClose()
Definition: Layer.cs:593
Layer parent
Definition: Layer.cs:104
bool IsHideHud()
Definition: Layer.cs:711
virtual void OnInit()
Definition: Layer.cs:195
virtual void OnAfterInit()
Definition: Layer.cs:199
string idLayer
Definition: Layer.cs:107
void _AddLayer(string id)
Definition: Layer.cs:332
bool RemoveLayer< T >()
Definition: Layer.cs:512
RectTransform _rect
Definition: Layer.cs:96
string langHint
Definition: Layer.cs:119
Layer SetDelay(float d)
Definition: Layer.cs:626
Option option
Definition: Layer.cs:84
bool closeOthers
Definition: Layer.cs:92
bool IsPointerOnLayer()
Definition: Layer.cs:751
Layer GetLayer(string id)
Definition: Layer.cs:637
T ToggleLayer< T >(string id=null)
Definition: Layer.cs:444
T GetOrAddLayer< T >()
Definition: Layer.cs:370
static string[] searchPath
Definition: Layer.cs:121
virtual void OnKill()
Definition: Layer.cs:580
virtual void Kill()
Definition: Layer.cs:549
virtual void OnSwitchContent(Window window)
Definition: Layer.cs:689
virtual void Awake()
Definition: Layer.cs:146
void OnClickClose()
Definition: Layer.cs:460
virtual void OnAfterAddLayer()
Definition: Layer.cs:384
void UpdateInput()
Definition: Layer.cs:217
virtual bool HeaderIsListOf(int id)
Definition: Layer.cs:141
T AddLayer< T >()
Definition: Layer.cs:342
void ShowScreenLock(string id)
Definition: Layer.cs:207
virtual void OnUpdateInput()
Definition: Layer.cs:255
Layer AddLayer(string id)
Definition: Layer.cs:337
virtual void ApplySkin()
Definition: Layer.cs:203
bool defaultActionMode
Definition: Layer.cs:94
virtual void OnChangeLayer()
Definition: Layer.cs:285
virtual void _Close()
Definition: Layer.cs:480
static bool rightClicked
Definition: Layer.cs:76
virtual void OnCreate()
Definition: Layer.cs:328
void SwitchContent(int idWindow, int i)
Definition: Layer.cs:684
static int skipInput
Definition: Layer.cs:72
Button screenLock
Definition: Layer.cs:101
bool IsBlockWidgetClick()
Definition: Layer.cs:699
Vector2 lastParentPos
Definition: Layer.cs:113
static T Create< T >()
Definition: Layer.cs:289
virtual void OnRightClick()
Definition: Layer.cs:259
bool IsUseBlur()
Definition: Layer.cs:735
void CloseLayers()
Definition: Layer.cs:493
Layer AddLayer(Layer l)
Definition: Layer.cs:388
T AddLayerDontCloseOthers< T >()
Definition: Layer.cs:352
virtual void Init()
Definition: Layer.cs:163
void WaitAndClose()
Definition: Layer.cs:455
virtual bool OnBack()
Definition: Layer.cs:267
static bool closeOnRightClick
Definition: Layer.cs:74
virtual void OnBeforeAddLayer()
Definition: Layer.cs:380
Anime animeIn
Definition: Layer.cs:88
bool isDestroyed
Definition: Layer.cs:98
Layer AddLayerDontCloseOthers(Layer l)
Definition: Layer.cs:362
void ToggleLayer(string id)
Definition: Layer.cs:431
List< Window > windows
Definition: Layer.cs:116
bool IsAllowGeneralInput()
Definition: Layer.cs:723
static bool cancelKeyDown
Definition: Layer.cs:78
Layer TopLayer
Definition: Layer.cs:123
virtual string GetTextHeader(Window window)
Definition: Layer.cs:131
Layer GetTopLayer()
Definition: Layer.cs:675
virtual void Close()
Definition: Layer.cs:468
virtual RectTransform rectLayers
Definition: Layer.cs:127
void RemoveLayers(bool removeImportant=false)
Definition: Layer.cs:501
void Delay(float duration=0.05f)
Definition: Layer.cs:602
static Layer Create(string path)
Definition: Layer.cs:299
Layer SetOnKill(Action action)
Definition: Layer.cs:584
Anime animeOut
Definition: Layer.cs:90
string uid
Definition: Layer.cs:125
static void TryShowTip(Transform root=null, bool highlight=true, bool ignoreWhenRightClick=true)
Definition: UIButton.cs:778
static UIContextMenuManager Instance
static UIDropdown activeInstance
Definition: UIDropdown.cs:12
string textCaption
Definition: Window.cs:53
Definition: Window.cs:13
void OnKill()
Definition: Window.cs:1116
Setting.Tab CurrentTab
Definition: Window.cs:787
Setting setting
Definition: Window.cs:606
int idTab
Definition: Window.cs:694
Button buttonClose
Definition: Window.cs:624