Elin Decompiled Documentation EA 23.200 Stable
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 Sort();
68 if (dirty)
69 {
70 layout.RebuildLayout();
71 if ((bool)layout2)
72 {
73 layout2.RebuildLayout(recursive: true);
74 }
75 dirty = false;
76 }
77 }
78
79 public void Sort()
80 {
81 IList<BaseNotification> list = this.list.Copy();
83 for (int i = 0; i < list.Count; i++)
84 {
85 list[i].item.transform.SetSiblingIndex(4 + i);
86 }
87 }
88
89 public virtual void OnRefresh()
90 {
91 }
92
93 public ItemNotice Add(BaseNotification n, Transform parent = null)
94 {
95 list.Add(n);
96 LayoutGroup layoutGroup = n.GetLayoutGroup() ?? layout;
97 ItemNotice itemNotice = Util.Instantiate(n.GetMold() ?? mold, parent ?? layoutGroup.transform);
98 itemNotice.button.onClick.AddListener(delegate
99 {
101 {
102 BaseCore.Instance.WaitForEndOfFrame(n.OnClick);
103 }
104 else
105 {
106 n.OnClick();
107 }
108 });
109 Sprite sprite = n.Sprite;
110 if (n.idSprite != -1)
111 {
112 sprite = sprites[n.idSprite];
113 }
114 if ((bool)sprite)
115 {
116 itemNotice.button.icon.sprite = sprite;
117 }
118 itemNotice.button.image.raycastTarget = n.Interactable;
119 itemNotice.button.tooltip.enable = n.onShowTooltip != null;
120 itemNotice.button.tooltip.onShowTooltip = n.onShowTooltip;
121 n.item = itemNotice;
122 n.Refresh();
123 n.OnInstantiate();
124 if (!activating)
125 {
126 layoutGroup.RebuildLayout(recursive: true);
127 Sort();
128 }
129 return itemNotice;
130 }
131
133 {
134 list.Remove(n);
135 if ((bool)n.item)
136 {
137 Object.DestroyImmediate(n.item.gameObject);
138 }
139 }
140
141 public override void OnFlip()
142 {
143 layout.childAlignment = (flip ? TextAnchor.MiddleRight : TextAnchor.MiddleLeft);
144 this.Rect().pivot = new Vector2(flip ? 1 : 0, this.Rect().pivot.y);
145 }
146
147 public override void OnSetContextMenu(UIContextMenu m)
148 {
149 m.AddChild("style").AddSlider("toggleButtonBG", (float a) => a.ToString() ?? "", base.config.skin.button, delegate(float a)
150 {
151 base.config.skin.button = (int)a;
152 ApplySkin();
153 }, 0f, base.config.skin.Skin.buttons.Count - 1, isInt: true);
155 }
156
157 public void RefreshLayout()
158 {
159 SkinAsset_Button button = GetComponent<SkinRoot>().Config.Button;
160 int y = button.size.y;
161 foreach (BaseNotification item in list)
162 {
163 RectTransform rectTransform = item.item.Rect();
164 rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, y);
165 }
166 layout.spacing = button.spacing.y;
167 }
168
169 public override void OnApplySkin()
170 {
172 }
173}
static AM_NoMap NoMap
Definition: ActionMode.cs:25
virtual ItemNotice GetMold()
virtual int idSprite
virtual Action< UITooltip > onShowTooltip
virtual int GetSortVal()
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:79
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