Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UINote.cs
Go to the documentation of this file.
1using System;
2using UnityEngine;
3using UnityEngine.UI;
4
5public class UINote : MonoBehaviour
6{
7 public RectTransform target;
8
10
12
13 public string idDefaultText;
14
15 [NonSerialized]
16 public LayoutGroup layout;
17
18 [NonSerialized]
19 public RectTransform cur;
20
21 public bool extraRebuild;
22
24
25 private void Awake()
26 {
27 if (!target)
28 {
29 target = this.Rect();
30 }
31 cur = target;
32 layout = GetComponent<LayoutGroup>();
33 }
34
35 public void Clear()
36 {
37 if (!layout)
38 {
39 layout = GetComponent<LayoutGroup>();
40 }
41 layout.DestroyChildren(destroyInactive: true);
43 if (skinType != 0)
44 {
45 SkinManager.tempSkin = SkinManager.CurrentSkin.GetSkin(skinType);
46 }
47 }
48
49 public void Build()
50 {
51 if (extraRebuild)
52 {
53 this.RebuildLayoutTo<Layer>();
54 }
55 this.RebuildLayout(recursive: true);
56 this.RebuildLayoutTo<Layer>();
57 this.RebuildLayoutTo<UIContent>();
58 this.RebuildLayoutTo<UIContent>();
59 SkinManager.tempSkin = oldTempSkin;
60 }
61
62 public void Space(int sizeY = 0, int sizeX = 1)
63 {
64 RectTransform rectTransform = Load<Transform>("UI/Element/Deco/Space").Rect();
65 rectTransform.sizeDelta = ((sizeY == 0) ? prof.sizeSpace : new Vector2(sizeX, sizeY));
66 if (sizeX != 1)
67 {
68 rectTransform.GetComponent<LayoutElement>().preferredWidth = sizeX;
69 }
70 }
71
72 public UINote AddNote(string id)
73 {
74 UINote componentInChildren = Load<Transform>("UI/Element/Note/" + id).gameObject.GetComponentInChildren<UINote>();
75 extraRebuild = true;
76 return componentInChildren;
77 }
78
79 public UIItem AddHeader(string text, Sprite sprite = null)
80 {
81 return AddHeader("HeaderNote", text, sprite);
82 }
83
84 public UIItem AddHeaderCard(string text, Sprite sprite = null)
85 {
86 return AddHeader("HeaderCard", text, sprite);
87 }
88
89 public UIItem AddHeaderTopic(string text, Sprite sprite = null)
90 {
91 return AddHeader("HeaderTopic", text, sprite);
92 }
93
94 public UIItem AddHeader(string id, string text, Sprite sprite = null)
95 {
96 UIItem uIItem = Load("UI/Element/Header/" + id);
97 uIItem.text1.text = text.lang();
98 if ((bool)uIItem.image1)
99 {
100 if ((bool)sprite)
101 {
102 uIItem.image1.sprite = sprite;
103 uIItem.image1.SetNativeSize();
104 }
105 else
106 {
107 uIItem.image1.SetActive(enable: false);
108 }
109 }
110 return uIItem;
111 }
112
113 public UIItem AddText(string text, FontColor color = FontColor.DontChange)
114 {
115 return AddText(null, text, color);
116 }
117
118 public UIItem AddText(string id, string text, FontColor color = FontColor.DontChange)
119 {
120 UIItem uIItem = Load("UI/Element/Text/" + id.IsEmpty(idDefaultText.IsEmpty("NoteText")));
121 if (color != 0)
122 {
123 uIItem.text1.SetText(text.lang(), color);
124 }
125 else
126 {
127 uIItem.text1.SetText(text.lang());
128 }
129 return uIItem;
130 }
131
132 public UIItem AddText(string id, string text, Color color)
133 {
134 UIItem uIItem = Load("UI/Element/Text/" + id.IsEmpty(idDefaultText.IsEmpty("NoteText")));
135 uIItem.text1.SetText(text.lang(), color);
136 return uIItem;
137 }
138
139 public UIItem AddItem(string id)
140 {
141 return Load("UI/Element/Item/" + id);
142 }
143
144 public UIItem AddTopic(string id, string text, string value = null)
145 {
146 UIItem uIItem = Load("UI/Element/Text/" + id);
147 uIItem.text1.SetText(text.lang());
148 uIItem.text2.SetText(value);
149 uIItem.text2.SetActive(!value.IsEmpty());
150 return uIItem;
151 }
152
153 public UIItem AddTopic(string text, string value = null)
154 {
155 return AddTopic("TopicDefault", text, value);
156 }
157
158 public void AddImage(Sprite sprite)
159 {
160 Image image = Load("UI/Element/Deco/ImageNote").image1;
161 image.sprite = sprite;
162 image.SetNativeSize();
163 image.transform.parent.Rect().sizeDelta = image.Rect().sizeDelta;
164 if (sprite == null)
165 {
166 image.transform.parent.SetActive(enable: false);
167 }
168 }
169
170 public void AddImage(string idFile)
171 {
172 Image image = Load("UI/Element/Deco/ImageNote").image1;
173 Sprite sprite2 = (image.sprite = Resources.Load<Sprite>("Media/Graphics/Image/" + idFile));
174 image.SetNativeSize();
175 image.transform.parent.Rect().sizeDelta = image.Rect().sizeDelta;
176 if (sprite2 == null)
177 {
178 image.transform.parent.SetActive(enable: false);
179 }
180 }
181
182 public UIButton AddButton(string text, Action onClick)
183 {
184 UIButton uIButton = Load<UIButton>("UI/Element/Button/ButtonNote");
185 uIButton.mainText.text = text;
186 uIButton.onClick.AddListener(delegate
187 {
188 onClick();
189 });
190 return uIButton;
191 }
192
193 public UIButton AddButtonLink(string text, string url)
194 {
195 UIButton button = Load<UIItem>("UI/Element/Item/ItemNoteLink").button1;
196 button.mainText.text = text;
197 button.onClick.AddListener(delegate
198 {
199 SE.Click();
200 Application.OpenURL(url);
201 });
202 return button;
203 }
204
205 public UIDropdown AddDropdown(string id = "DropdownDefault")
206 {
207 return Load<UIDropdown>("UI/Element/Other/" + id);
208 }
209
210 public UIButton AddToggle(string idLang = "", bool isOn = false, Action<bool> action = null)
211 {
212 UIButton uIButton = Load<UIButton>("UI/Element/Button/ButtonToggle");
213 uIButton.SetToggle(isOn, action);
214 uIButton.mainText.text = idLang.lang().ToTitleCase();
215 return uIButton;
216 }
217
218 public Transform AddPrefab(string path)
219 {
220 return Util.Instantiate(path, this);
221 }
222
223 public T AddExtra<T>(string path) where T : Component
224 {
225 return Util.Instantiate<T>("UI/Element/Note/Extra/" + path, this);
226 }
227
228 private UIItem Load(string path)
229 {
230 return Load<UIItem>(path);
231 }
232
233 private T Load<T>(string path) where T : Component
234 {
235 return Util.Instantiate<T>(path, layout);
236 }
237}
FontColor
Definition: FontColor.cs:2
SkinType
Definition: SkinType.cs:2
static SkinRootStatic CurrentSkin
Definition: SkinManager.cs:82
static SkinRootStatic tempSkin
Definition: SkinManager.cs:63
SkinRootStatic GetSkin(SkinType type)
void SetToggle(bool isOn, Action< bool > onToggle=null)
Definition: UIButton.cs:341
Definition: UIItem.cs:5
Image image1
Definition: UIItem.cs:14
UIText text2
Definition: UIItem.cs:8
UIText text1
Definition: UIItem.cs:6
Vector2 sizeSpace
Definition: UINoteProfile.cs:5
Definition: UINote.cs:6
LayoutGroup layout
Definition: UINote.cs:16
UIButton AddButtonLink(string text, string url)
Definition: UINote.cs:193
void AddImage(string idFile)
Definition: UINote.cs:170
UIItem AddHeaderCard(string text, Sprite sprite=null)
Definition: UINote.cs:84
UIItem AddHeaderTopic(string text, Sprite sprite=null)
Definition: UINote.cs:89
void Clear()
Definition: UINote.cs:35
RectTransform cur
Definition: UINote.cs:19
UINoteProfile prof
Definition: UINote.cs:9
UIDropdown AddDropdown(string id="DropdownDefault")
Definition: UINote.cs:205
UINote AddNote(string id)
Definition: UINote.cs:72
T Load< T >(string path)
Definition: UINote.cs:233
UIItem Load(string path)
Definition: UINote.cs:228
Transform AddPrefab(string path)
Definition: UINote.cs:218
void AddImage(Sprite sprite)
Definition: UINote.cs:158
string idDefaultText
Definition: UINote.cs:13
void Awake()
Definition: UINote.cs:25
UIItem AddHeader(string id, string text, Sprite sprite=null)
Definition: UINote.cs:94
bool extraRebuild
Definition: UINote.cs:21
T AddExtra< T >(string path)
Definition: UINote.cs:223
UIItem AddText(string id, string text, Color color)
Definition: UINote.cs:132
UIItem AddItem(string id)
Definition: UINote.cs:139
UIItem AddText(string id, string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:118
UIItem AddHeader(string text, Sprite sprite=null)
Definition: UINote.cs:79
UIItem AddTopic(string text, string value=null)
Definition: UINote.cs:153
SkinRootStatic oldTempSkin
Definition: UINote.cs:23
SkinType skinType
Definition: UINote.cs:11
UIButton AddButton(string text, Action onClick)
Definition: UINote.cs:182
UIItem AddTopic(string id, string text, string value=null)
Definition: UINote.cs:144
UIButton AddToggle(string idLang="", bool isOn=false, Action< bool > action=null)
Definition: UINote.cs:210
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
void Space(int sizeY=0, int sizeX=1)
Definition: UINote.cs:62
RectTransform target
Definition: UINote.cs:7
void Build()
Definition: UINote.cs:49
void SetText(string s)
Definition: UIText.cs:159