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