Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
BaseWidgetNotice.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3using UnityEngine.UI;
4
5public class BaseWidgetNotice : Widget
6{
7 public Sprite[] sprites;
8
9 public List<BaseNotification> list = new List<BaseNotification>();
10
11 public VerticalLayoutGroup layout;
12
13 public VerticalLayoutGroup layout2;
14
16
17 private bool activating = true;
18
19 protected bool dirty;
20
21 public sealed override void OnActivate()
22 {
23 if (!mold)
24 {
25 mold = layout.CreateMold<ItemNotice>();
26 }
29 layout.RebuildLayout(recursive: true);
30 if ((bool)layout2)
31 {
32 layout2.RebuildLayout(recursive: true);
33 }
34 activating = false;
36 }
37
38 public virtual void _OnActivate()
39 {
40 }
41
42 private void OnEnable()
43 {
44 InvokeRepeating("_RefreshAll", 0.1f, 0.2f);
45 }
46
47 private void OnDisable()
48 {
49 CancelInvoke();
50 }
51
52 public void _RefreshAll()
53 {
54 OnRefresh();
55 foreach (BaseNotification i in list)
56 {
57 i.Refresh();
58 i.item.SetActive(i.Visible, delegate(bool enabled)
59 {
60 if (enabled)
61 {
62 i.item.button.RebuildLayout(recursive: true);
63 }
64 dirty = true;
65 });
66 }
67 if (dirty)
68 {
69 layout.RebuildLayout();
70 if ((bool)layout2)
71 {
72 layout2.RebuildLayout(recursive: true);
73 }
74 dirty = false;
75 }
76 }
77
78 public virtual void OnRefresh()
79 {
80 }
81
82 public ItemNotice Add(BaseNotification n, Transform parent = null)
83 {
84 list.Add(n);
85 LayoutGroup layoutGroup = n.GetLayoutGroup() ?? layout;
86 ItemNotice itemNotice = Util.Instantiate(n.GetMold() ?? mold, parent ?? layoutGroup.transform);
87 itemNotice.button.onClick.AddListener(delegate
88 {
90 {
91 BaseCore.Instance.WaitForEndOfFrame(n.OnClick);
92 }
93 else
94 {
95 n.OnClick();
96 }
97 });
98 Sprite sprite = n.Sprite;
99 if (n.idSprite != -1)
100 {
101 sprite = sprites[n.idSprite];
102 }
103 if ((bool)sprite)
104 {
105 itemNotice.button.icon.sprite = sprite;
106 }
107 itemNotice.button.image.raycastTarget = n.Interactable;
108 itemNotice.button.tooltip.enable = n.onShowTooltip != null;
109 itemNotice.button.tooltip.onShowTooltip = n.onShowTooltip;
110 n.item = itemNotice;
111 n.Refresh();
112 n.OnInstantiate();
113 if (!activating)
114 {
115 layoutGroup.RebuildLayout(recursive: true);
116 }
117 return itemNotice;
118 }
119
121 {
122 list.Remove(n);
123 if ((bool)n.item)
124 {
125 Object.DestroyImmediate(n.item.gameObject);
126 }
127 }
128
129 public override void OnFlip()
130 {
131 layout.childAlignment = (flip ? TextAnchor.MiddleRight : TextAnchor.MiddleLeft);
132 this.Rect().pivot = new Vector2(flip ? 1 : 0, this.Rect().pivot.y);
133 }
134
135 public override void OnSetContextMenu(UIContextMenu m)
136 {
137 m.AddChild("style").AddSlider("toggleButtonBG", (float a) => a.ToString() ?? "", base.config.skin.button, delegate(float a)
138 {
139 base.config.skin.button = (int)a;
140 ApplySkin();
141 }, 0f, base.config.skin.Skin.buttons.Count - 1, isInt: true);
143 }
144
145 public void RefreshLayout()
146 {
147 SkinAsset_Button button = GetComponent<SkinRoot>().Config.Button;
148 int y = button.size.y;
149 foreach (BaseNotification item in list)
150 {
151 RectTransform rectTransform = item.item.Rect();
152 rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, y);
153 }
154 layout.spacing = button.spacing.y;
155 }
156
157 public override void OnApplySkin()
158 {
160 }
161}
static AM_NoMap NoMap
Definition: ActionMode.cs:25
virtual ItemNotice GetMold()
virtual int idSprite
virtual Action< UITooltip > onShowTooltip
virtual void OnInstantiate()
virtual LayoutGroup GetLayoutGroup()
virtual bool Interactable
virtual bool Visible
virtual Sprite Sprite
override void OnApplySkin()
VerticalLayoutGroup layout2
virtual void OnRefresh()
override void OnSetContextMenu(UIContextMenu m)
sealed override void OnActivate()
VerticalLayoutGroup layout
override void OnFlip()
ItemNotice Add(BaseNotification n, Transform parent=null)
virtual void _OnActivate()
void Remove(BaseNotification n)
List< BaseNotification > list
Definition: EMono.cs:4
static Scene scene
Definition: EMono.cs:27
UIButton button
Definition: ItemNotice.cs:11
ActionMode actionMode
Definition: Scene.cs:77
UIContextMenuItem AddSlider(string text, Func< float, string > textFunc, float value, Action< float > action, float min=0f, float max=1f, bool isInt=false, bool hideOther=true, bool useInput=false)
UIContextMenu AddChild(string idLang, TextAnchor anchor)
Definition: Widget.cs:7
virtual void ApplySkin()
Definition: Widget.cs:556
void SetBaseContextMenu(UIContextMenu m)
Definition: Widget.cs:608
bool flip
Definition: Widget.cs:164