Elin Decompiled Documentation EA 23.102 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 text4 = (layer.name = text);
323 layer2.idLayer = text4;
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
358 {
359 l.option.screenlockType = Option.ScreenlockType.Default;
360 l.closeOthers = false;
361 AddLayer(l);
362 return l;
363 }
364
365 public T GetOrAddLayer<T>() where T : Layer
366 {
367 T val = GetLayer<T>();
368 if (!val)
369 {
370 val = AddLayer<T>();
371 }
372 return val;
373 }
374
375 public virtual void OnBeforeAddLayer()
376 {
377 }
378
379 public virtual void OnAfterAddLayer()
380 {
381 }
382
384 {
386 if (l.option.persist && l.isDestroyed)
387 {
388 l.isDestroyed = false;
389 l.gameObject.SetActive(value: true);
390 layers.Add(l);
391 if (!ignoreSounds)
392 {
393 SoundManager.current.Play(l.option.soundActivate);
394 }
395 return l;
396 }
397 l.gameObject.SetActive(value: true);
398 l.parent = this;
399 l.transform.SetParent(rectLayers, worldPositionStays: false);
400 l.Init();
401 if (l.option.hideOthers)
402 {
403 foreach (Layer layer in layers)
404 {
405 if (layer.option.hideOnUnfocus)
406 {
407 CanvasGroup canvasGroup = layer.gameObject.GetComponent<CanvasGroup>();
408 if (!canvasGroup)
409 {
410 canvasGroup = layer.gameObject.AddComponent<CanvasGroup>();
411 }
412 canvasGroup.alpha = 0f;
413 }
414 }
415 }
416 layers.Add(l);
418 l._rect.anchorMin = Vector2.zero;
419 l._rect.anchorMax = Vector2.one;
420 l._rect.anchoredPosition = Vector2.zero;
421 l._rect.sizeDelta = Vector2.zero;
422 l.OnAfterAddLayer();
423 return l;
424 }
425
426 public void ToggleLayer(string id)
427 {
428 Layer layer = GetLayer(id);
429 if ((bool)layer)
430 {
431 RemoveLayer(layer);
432 }
433 else
434 {
435 AddLayer(id);
436 }
437 }
438
439 public T ToggleLayer<T>(string id = null) where T : Layer
440 {
441 T layer = GetLayer<T>();
442 if ((bool)layer)
443 {
444 RemoveLayer(layer);
445 return null;
446 }
447 return AddLayer<T>(id);
448 }
449
450 public void WaitAndClose()
451 {
453 }
454
455 public void OnClickClose()
456 {
457 if (!BaseCore.BlockInput())
458 {
459 Close();
460 }
461 }
462
463 public virtual void Close()
464 {
465 if ((bool)animeOut)
466 {
467 animeOut.Play(rectLayers).OnComplete(_Close);
468 }
469 else
470 {
471 _Close();
472 }
473 }
474
475 protected virtual void _Close()
476 {
477 if ((bool)parent)
478 {
479 parent.RemoveLayer(this);
480 }
481 else
482 {
483 Kill();
484 }
485 skipInput = 2;
486 }
487
488 public void CloseLayers()
489 {
490 for (int num = layers.Count - 1; num >= 0; num--)
491 {
492 layers[num].Close();
493 }
494 }
495
496 public void RemoveLayers(bool removeImportant = false)
497 {
498 for (int num = layers.Count - 1; num >= 0; num--)
499 {
500 if (removeImportant || (!layers[num].option.important && !layers[num].option.persist))
501 {
502 RemoveLayer(layers[num]);
503 }
504 }
505 }
506
507 public bool RemoveLayer<T>()
508 {
509 for (int num = layers.Count - 1; num >= 0; num--)
510 {
511 if (layers[num] is T)
512 {
513 RemoveLayer(layers[num]);
514 return true;
515 }
516 }
517 return false;
518 }
519
520 public void RemoveLayer(Layer l)
521 {
522 _RemoveLayer(l);
523 }
524
525 private void _RemoveLayer(Layer l)
526 {
527 l.Kill();
528 layers.Remove(l);
529 if (layers.Count > 0)
530 {
531 Layer layer = layers.LastItem();
532 if (!layer.isDestroyed)
533 {
534 CanvasGroup component = layer.GetComponent<CanvasGroup>();
535 if (layer.option.hideOnUnfocus && (bool)component)
536 {
537 component.alpha = 1f;
538 }
539 }
540 }
542 }
543
544 protected virtual void Kill()
545 {
546 if (isDestroyed || base.gameObject == null)
547 {
548 return;
549 }
550 isDestroyed = true;
551 foreach (Layer layer in layers)
552 {
553 layer.Kill();
554 }
555 if (windows.Count > 0)
556 {
558 foreach (Window window in windows)
559 {
560 window.OnKill();
561 }
562 }
563 OnKill();
564 onKill.Invoke();
565 if (option.persist)
566 {
567 base.gameObject.SetActive(value: false);
568 }
569 else
570 {
571 UnityEngine.Object.DestroyImmediate(base.gameObject);
572 }
573 }
574
575 public virtual void OnKill()
576 {
577 }
578
579 public Layer SetOnKill(Action action)
580 {
581 onKill.AddListener(delegate
582 {
583 action();
584 });
585 return this;
586 }
587
588 public void DisableClose()
589 {
590 option.canClose = false;
591 foreach (Window window in windows)
592 {
593 window.buttonClose.SetActive(enable: false);
594 }
595 }
596
597 public void Delay(float duration = 0.05f)
598 {
599 foreach (Window window in windows)
600 {
601 window.setting.anime = null;
602 }
603 _rect.anchoredPosition = new Vector2(10000f, 10000f);
604 TweenUtil.Tween(0.1f, delegate
605 {
607 {
608 if ((bool)this && (bool)base.gameObject)
609 {
610 _rect.anchoredPosition = new Vector2(0f, 0f);
611 foreach (Window window2 in windows)
612 {
613 window2.ClampToScreen();
614 }
616 }
617 });
618 });
619 }
620
621 public Layer SetDelay(float d)
622 {
623 CanvasGroup cg = GetComponent<CanvasGroup>() ?? base.gameObject.AddComponent<CanvasGroup>();
624 cg.alpha = 0f;
625 TweenUtil.Tween(d, null, delegate
626 {
627 cg.alpha = 1f;
628 });
629 return this;
630 }
631
632 public Layer GetLayer(string id)
633 {
634 foreach (Layer layer in layers)
635 {
636 if (layer.idLayer == id)
637 {
638 return layer;
639 }
640 }
641 return null;
642 }
643
644 public T GetLayer<T>(bool fromTop = false) where T : Layer
645 {
646 if (fromTop)
647 {
648 for (int num = layers.Count - 1; num >= 0; num--)
649 {
650 Layer layer = layers[num];
651 if (layer is T)
652 {
653 return layer as T;
654 }
655 }
656 }
657 else
658 {
659 foreach (Layer layer2 in layers)
660 {
661 if (layer2 is T)
662 {
663 return layer2 as T;
664 }
665 }
666 }
667 return null;
668 }
669
671 {
672 if (layers.Count > 0)
673 {
674 return layers.LastItem().GetTopLayer();
675 }
676 return this;
677 }
678
679 public void SwitchContent(int idWindow, int i)
680 {
681 windows[idWindow].SwitchContent(i);
682 }
683
684 public virtual void OnSwitchContent(Window window)
685 {
686 }
687
688 public Layer SetTitles(string langList, string idHeaderRow = null)
689 {
690 windows[0].SetTitles(langList, idHeaderRow);
691 return this;
692 }
693
694 public bool IsBlockWidgetClick()
695 {
696 foreach (Layer layer in layers)
697 {
698 if (layer.blockWidgetClick)
699 {
700 return true;
701 }
702 }
703 return blockWidgetClick;
704 }
705
706 public bool IsHideHud()
707 {
708 foreach (Layer layer in layers)
709 {
710 if (layer.IsHideHud())
711 {
712 return true;
713 }
714 }
715 return option.hideHud;
716 }
717
719 {
720 foreach (Layer layer in layers)
721 {
722 if (!layer.IsAllowGeneralInput())
723 {
724 return false;
725 }
726 }
727 return option.allowGeneralInput;
728 }
729
730 public bool IsUseBlur()
731 {
732 if ((bool)blurStopInstance)
733 {
734 return false;
735 }
736 foreach (Layer layer in layers)
737 {
738 if (layer.IsUseBlur())
739 {
740 return true;
741 }
742 }
743 return option.blur;
744 }
745
746 public bool IsPointerOnLayer()
747 {
748 foreach (GameObject item in InputModuleEX.GetPointerEventData().hovered)
749 {
750 if (item.GetComponentInParent<Layer>() == this)
751 {
752 return true;
753 }
754 }
755 return false;
756 }
757}
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:349
static ButtonState rightMouse
Definition: EInput.cs:351
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:520
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:644
Layer SetTitles(string langList, string idHeaderRow=null)
Definition: Layer.cs:688
void _RemoveLayer(Layer l)
Definition: Layer.cs:525
void DisableClose()
Definition: Layer.cs:588
Layer parent
Definition: Layer.cs:104
bool IsHideHud()
Definition: Layer.cs:706
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:507
RectTransform _rect
Definition: Layer.cs:96
string langHint
Definition: Layer.cs:119
Layer SetDelay(float d)
Definition: Layer.cs:621
Option option
Definition: Layer.cs:84
bool closeOthers
Definition: Layer.cs:92
bool IsPointerOnLayer()
Definition: Layer.cs:746
Layer GetLayer(string id)
Definition: Layer.cs:632
T ToggleLayer< T >(string id=null)
Definition: Layer.cs:439
T GetOrAddLayer< T >()
Definition: Layer.cs:365
static string[] searchPath
Definition: Layer.cs:121
virtual void OnKill()
Definition: Layer.cs:575
virtual void Kill()
Definition: Layer.cs:544
virtual void OnSwitchContent(Window window)
Definition: Layer.cs:684
virtual void Awake()
Definition: Layer.cs:146
void OnClickClose()
Definition: Layer.cs:455
virtual void OnAfterAddLayer()
Definition: Layer.cs:379
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:475
static bool rightClicked
Definition: Layer.cs:76
virtual void OnCreate()
Definition: Layer.cs:328
void SwitchContent(int idWindow, int i)
Definition: Layer.cs:679
static int skipInput
Definition: Layer.cs:72
Button screenLock
Definition: Layer.cs:101
bool IsBlockWidgetClick()
Definition: Layer.cs:694
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:730
void CloseLayers()
Definition: Layer.cs:488
Layer AddLayer(Layer l)
Definition: Layer.cs:383
T AddLayerDontCloseOthers< T >()
Definition: Layer.cs:352
virtual void Init()
Definition: Layer.cs:163
void WaitAndClose()
Definition: Layer.cs:450
virtual bool OnBack()
Definition: Layer.cs:267
static bool closeOnRightClick
Definition: Layer.cs:74
virtual void OnBeforeAddLayer()
Definition: Layer.cs:375
Anime animeIn
Definition: Layer.cs:88
bool isDestroyed
Definition: Layer.cs:98
Layer AddLayerDontCloseOthers(Layer l)
Definition: Layer.cs:357
void ToggleLayer(string id)
Definition: Layer.cs:426
List< Window > windows
Definition: Layer.cs:116
bool IsAllowGeneralInput()
Definition: Layer.cs:718
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:670
virtual void Close()
Definition: Layer.cs:463
virtual RectTransform rectLayers
Definition: Layer.cs:127
void RemoveLayers(bool removeImportant=false)
Definition: Layer.cs:496
void Delay(float duration=0.05f)
Definition: Layer.cs:597
static Layer Create(string path)
Definition: Layer.cs:299
Layer SetOnKill(Action action)
Definition: Layer.cs:579
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