Elin Modding Docs Doc
Loading...
Searching...
No Matches
WidgetManager.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using SFB;
5using UnityEngine;
6using UnityEngine.UI;
7
8// Token: 0x0200061F RID: 1567
9public class WidgetManager : EMono
10{
11 // Token: 0x17000C8E RID: 3214
12 // (get) Token: 0x06002BBB RID: 11195 RVA: 0x000F5CED File Offset: 0x000F3EED
13 public List<Widget.Meta> metas
14 {
15 get
16 {
17 return EMono.setting.ui.widgetMetas;
18 }
19 }
20
21 // Token: 0x17000C8F RID: 3215
22 // (get) Token: 0x06002BBC RID: 11196 RVA: 0x000F5CFE File Offset: 0x000F3EFE
23 public Dictionary<string, Widget.Config> configs
24 {
25 get
26 {
27 return EMono.player.widgets.dict;
28 }
29 }
30
31 // Token: 0x06002BBD RID: 11197 RVA: 0x000F5D10 File Offset: 0x000F3F10
32 public void OnActivateZone()
33 {
34 if (!this.first)
35 {
36 return;
37 }
38 this.first = false;
39 foreach (Widget.Config config in this.configs.Values)
40 {
41 if (config.state == Widget.State.Active)
42 {
43 this.ActivateWidget(config);
44 }
45 }
46 bool flag = EMono.ui.layerFloat.GetLayer<LayerInventory>(false);
47 if (this.GetWidget("Equip") == null)
48 {
49 if (flag)
50 {
51 this.Activate("Equip");
52 return;
53 }
54 }
55 else if (!flag)
56 {
57 this.DeactivateWidget("Equip");
58 }
59 }
60
61 // Token: 0x06002BBE RID: 11198 RVA: 0x000F5DC8 File Offset: 0x000F3FC8
62 public void OnGameInstantiated()
63 {
64 if (Application.isEditor && EMono.debug.resetPlayerConfig && !EMono.player.isEditor)
65 {
66 EMono.player.useSubWidgetTheme = false;
67 EMono.ui.widgets.Load(false, null);
68 }
69 this.first = true;
70 if (EMono.player.useSubWidgetTheme)
71 {
72 if (EMono.player.subWidgets == null)
73 {
74 this.Load(true, null);
75 }
76 }
77 else if (EMono.player.mainWidgets == null)
78 {
79 this.Load(false, null);
80 if (Screen.width <= 1300 && !EMono.player.useSubWidgetTheme)
81 {
82 foreach (KeyValuePair<string, Widget.Config> keyValuePair in EMono.player.mainWidgets.dict)
83 {
84 if (keyValuePair.Key == "StatsBar")
85 {
86 keyValuePair.Value.state = Widget.State.Inactive;
87 }
88 }
89 }
90 }
91 if (this.metaMap.Count == 0)
92 {
93 foreach (Widget.Meta meta in this.metas)
94 {
95 this.metaMap.Add(meta.id, meta);
96 }
97 }
98 foreach (Widget.Meta meta2 in this.metas)
99 {
100 if (!this.configs.ContainsKey(meta2.id))
101 {
102 Widget.Config config = new Widget.Config
103 {
104 meta = meta2,
105 valid = true,
106 id = meta2.id,
107 state = (meta2.enabled ? Widget.State.Active : Widget.State.Inactive),
108 locked = meta2.locked
109 };
110 config.skin.SetID(0);
111 this.configs.Add(meta2.id, config);
112 }
113 else
114 {
115 Widget.Config config2 = this.configs[meta2.id];
116 config2.valid = true;
117 config2.meta = meta2;
118 }
119 }
120 foreach (Widget.Config config3 in this.configs.Values.ToList<Widget.Config>())
121 {
122 if (!config3.valid)
123 {
124 this.configs.Remove(config3.id);
125 }
126 }
127 }
128
129 // Token: 0x06002BBF RID: 11199 RVA: 0x000F606C File Offset: 0x000F426C
130 public void OnKillGame()
131 {
132 this.KillWidgets();
133 }
134
135 // Token: 0x06002BC0 RID: 11200 RVA: 0x000F6074 File Offset: 0x000F4274
136 public void OnChangeActionMode()
137 {
138 foreach (Widget widget in this.list)
139 {
140 widget.OnChangeActionMode();
141 }
142 }
143
144 // Token: 0x06002BC1 RID: 11201 RVA: 0x000F60C4 File Offset: 0x000F42C4
145 public void UpdateConfigs()
146 {
147 foreach (Widget widget in this.list)
148 {
149 widget.UpdateConfig();
150 }
151 }
152
153 // Token: 0x06002BC2 RID: 11202 RVA: 0x000F6114 File Offset: 0x000F4314
154 public void Activate(string id)
155 {
156 if (!this.GetWidget(id))
157 {
158 this.ActivateWidget(this.configs[id]);
159 }
160 }
161
162 // Token: 0x06002BC3 RID: 11203 RVA: 0x000F6138 File Offset: 0x000F4338
163 public Widget Toggle(string id)
164 {
165 Widget widget = this.GetWidget(id);
166 if (widget)
167 {
168 this.DeactivateWidget(widget);
169 return null;
170 }
171 return this.ActivateWidget(this.configs[id]);
172 }
173
174 // Token: 0x06002BC4 RID: 11204 RVA: 0x000F6170 File Offset: 0x000F4370
175 public Widget Toggle(Widget.Config c)
176 {
177 Widget widget = this.GetWidget(c.id);
178 if (widget)
179 {
180 this.DeactivateWidget(widget);
181 return null;
182 }
183 return this.ActivateWidget(c);
184 }
185
186 // Token: 0x06002BC5 RID: 11205 RVA: 0x000F61A2 File Offset: 0x000F43A2
187 public void ToggleLock(Widget.Config c)
188 {
189 c.locked = !c.locked;
190 this.RefreshWidget(c);
191 }
192
193 // Token: 0x06002BC6 RID: 11206 RVA: 0x000F61BA File Offset: 0x000F43BA
194 public Widget ActivateWidget(Widget.Config c)
195 {
196 return this.ActivateWidget(c.id);
197 }
198
199 // Token: 0x06002BC7 RID: 11207 RVA: 0x000F61C8 File Offset: 0x000F43C8
200 public Widget ActivateWidget(string id)
201 {
202 string text = "Widget" + id;
203 Widget widget = Util.Instantiate<Widget>("UI/Widget/" + text, this) ?? Util.Instantiate<Widget>("UI/Widget/" + text + "/" + text, this);
204 if (!widget)
205 {
206 Debug.LogError("Widget:" + id + " not found.");
207 return null;
208 }
209 this.list.Add(widget);
210 widget.gameObject.name = text;
211 widget.Activate();
212 this.RefreshWidget(widget);
213 if (LayerWidget.Instance)
214 {
215 widget.OnManagerActivate();
216 }
217 if (widget.AlwaysBottom)
218 {
219 Type setSiblingAfter = widget.SetSiblingAfter;
220 bool flag = false;
221 if (setSiblingAfter != null)
222 {
223 foreach (Widget widget2 in this.list)
224 {
225 if (widget2.GetType() == setSiblingAfter)
226 {
227 widget.transform.SetSiblingIndex(widget2.transform.GetSiblingIndex() + 1);
228 flag = true;
229 break;
230 }
231 }
232 }
233 if (!flag)
234 {
235 widget.transform.SetAsFirstSibling();
236 }
237 }
238 return widget;
239 }
240
241 // Token: 0x06002BC8 RID: 11208 RVA: 0x000F62FC File Offset: 0x000F44FC
242 public void RefreshWidget(Widget.Config c)
243 {
244 this.RefreshWidget(this.GetWidget(c.id));
245 }
246
247 // Token: 0x06002BC9 RID: 11209 RVA: 0x000F6310 File Offset: 0x000F4510
248 public void RefreshWidget(Widget w)
249 {
250 if (!w)
251 {
252 return;
253 }
254 w.dragPanel.GetComponent<Graphic>().raycastTarget = !w.config.locked;
255 }
256
257 // Token: 0x06002BCA RID: 11210 RVA: 0x000F633C File Offset: 0x000F453C
258 public Widget GetWidget(string id)
259 {
260 foreach (Widget widget in this.list)
261 {
262 if (widget.gameObject.name == "Widget" + id)
263 {
264 return widget;
265 }
266 }
267 return null;
268 }
269
270 // Token: 0x06002BCB RID: 11211 RVA: 0x000F63AC File Offset: 0x000F45AC
271 public void DeactivateWidget(string id)
272 {
273 this.DeactivateWidget(this.GetWidget(id));
274 }
275
276 // Token: 0x06002BCC RID: 11212 RVA: 0x000F63BB File Offset: 0x000F45BB
277 public void DeactivateWidget(Widget w)
278 {
279 if (w == null)
280 {
281 return;
282 }
283 this.list.Remove(w);
284 w.Deactivate();
285 if (LayerWidget.Instance)
286 {
287 LayerWidget.Instance.Refresh();
288 }
289 }
290
291 // Token: 0x06002BCD RID: 11213 RVA: 0x000F63F0 File Offset: 0x000F45F0
292 public void KillWidgets()
293 {
294 this.DestroyChildren(true, true);
295 this.list.Clear();
296 this.first = true;
297 }
298
299 // Token: 0x06002BCE RID: 11214 RVA: 0x000F640C File Offset: 0x000F460C
300 public void Show()
301 {
302 foreach (Widget widget in this.list)
303 {
304 if (widget.IsInRightMode())
305 {
306 widget.gameObject.SetActive(true);
307 }
308 }
309 }
310
311 // Token: 0x06002BCF RID: 11215 RVA: 0x000F646C File Offset: 0x000F466C
312 public void Hide()
313 {
314 foreach (Widget widget in this.list)
315 {
316 if (widget is WidgetCurrentTool || widget is WidgetQuestTracker || widget is WidgetTracker || widget is WidgetMemo || widget is WidgetEquip)
317 {
318 widget.gameObject.SetActive(false);
319 }
320 }
321 }
322
323 // Token: 0x06002BD0 RID: 11216 RVA: 0x000F64EC File Offset: 0x000F46EC
324 public void Reset(bool toggleTheme)
325 {
326 if (WidgetMainText.Instance.box.isShowingLog)
327 {
328 WidgetMainText.Instance._ToggleLog();
329 }
330 if (WidgetMainText.Instance)
331 {
332 (WidgetMainText.boxBk = WidgetMainText.Instance.box).transform.SetParent(base.transform.parent, false);
333 }
334 this.KillWidgets();
335 if (toggleTheme)
336 {
337 EMono.player.useSubWidgetTheme = !EMono.player.useSubWidgetTheme;
338 }
339 this.OnGameInstantiated();
340 this.OnActivateZone();
341 this.OnChangeActionMode();
342 }
343
344 // Token: 0x06002BD1 RID: 11217 RVA: 0x000F6578 File Offset: 0x000F4778
345 public void DialogSave(Action onSave = null)
346 {
347 EMono.core.WaitForEndOfFrame(delegate
348 {
349 string text = StandaloneFileBrowser.SaveFilePanel("Save Widget Theme", CorePath.WidgetSave, "new theme", "json");
350 if (!string.IsNullOrEmpty(text))
351 {
352 if (!EMono.debug.enable && (text.Contains("Default.json") || text.Contains("Modern.json") || text.Contains("Classic.json")))
353 {
354 Dialog.Ok("dialogInvalidTheme");
355 return;
356 }
357 this.Save(text);
358 if (onSave != null)
359 {
360 onSave();
361 }
362 }
363 });
364 }
365
366 // Token: 0x06002BD2 RID: 11218 RVA: 0x000F65B0 File Offset: 0x000F47B0
367 public void DialogLoad(Action onLoad = null)
368 {
369 EMono.core.WaitForEndOfFrame(delegate
370 {
371 string[] array = StandaloneFileBrowser.OpenFilePanel("Load Widget Theme", CorePath.WidgetSave, "json", false);
372 if (array.Length != 0)
373 {
374 this.Load(EMono.player.useSubWidgetTheme, array[0]);
375 this.Reset(false);
376 if (onLoad != null)
377 {
378 onLoad();
379 }
380 }
381 });
382 }
383
384 // Token: 0x06002BD3 RID: 11219 RVA: 0x000F65E8 File Offset: 0x000F47E8
385 public void Save(string path = null)
386 {
387 if (path == null)
388 {
389 path = CorePath.WidgetSave + (EMono.player.useSubWidgetTheme ? EMono.core.config.other.idSubWidgetTheme : EMono.core.config.other.idMainWidgetTheme) + ".json";
390 }
391 this.UpdateConfigs();
392 IO.SaveFile(path, EMono.player.widgets, false, null);
393 }
394
395 // Token: 0x06002BD4 RID: 11220 RVA: 0x000F6658 File Offset: 0x000F4858
396 public void Load(bool isSubTheme, string path = null)
397 {
398 if (path == null)
399 {
400 path = CorePath.WidgetSave + (isSubTheme ? EMono.core.config.other.idSubWidgetTheme : EMono.core.config.other.idMainWidgetTheme) + ".json";
401 }
402 WidgetManager.SaveData saveData = IO.LoadFile<WidgetManager.SaveData>(path, false, null);
403 if (isSubTheme)
404 {
405 EMono.player.subWidgets = saveData;
406 }
407 else
408 {
409 EMono.player.mainWidgets = saveData;
410 }
411 this.currentPath = path;
412 }
413
414 // Token: 0x04001864 RID: 6244
415 public Dictionary<string, Widget.Meta> metaMap = new Dictionary<string, Widget.Meta>();
416
417 // Token: 0x04001865 RID: 6245
418 public string currentPath;
419
420 // Token: 0x04001866 RID: 6246
421 [NonSerialized]
422 public List<Widget> list = new List<Widget>();
423
424 // Token: 0x04001867 RID: 6247
425 private bool first;
426
427 // Token: 0x02000B90 RID: 2960
428 public class SaveData
429 {
430 // Token: 0x04002E6B RID: 11883
431 public Dictionary<string, Widget.Config> dict;
432 }
433}
Definition EMono.cs:6