Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
WidgetManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using SFB;
5using UnityEngine;
6using UnityEngine.UI;
7
8public class WidgetManager : EMono
9{
10 public class SaveData
11 {
12 public Dictionary<string, Widget.Config> dict;
13 }
14
15 public Dictionary<string, Widget.Meta> metaMap = new Dictionary<string, Widget.Meta>();
16
17 public string currentPath;
18
19 [NonSerialized]
20 public List<Widget> list = new List<Widget>();
21
22 private bool first;
23
25
26 public Dictionary<string, Widget.Config> configs => EMono.player.widgets.dict;
27
28 public void OnActivateZone()
29 {
30 if (!first)
31 {
32 return;
33 }
34 first = false;
35 foreach (Widget.Config value in configs.Values)
36 {
37 if (value.state == Widget.State.Active)
38 {
39 ActivateWidget(value);
40 }
41 }
42 bool flag = EMono.ui.layerFloat.GetLayer<LayerInventory>();
43 if (GetWidget("Equip") == null)
44 {
45 if (flag)
46 {
47 Activate("Equip");
48 }
49 }
50 else if (!flag)
51 {
52 DeactivateWidget("Equip");
53 }
54 }
55
56 public void OnGameInstantiated()
57 {
58 if (Application.isEditor && EMono.debug.resetPlayerConfig && !EMono.player.isEditor)
59 {
60 EMono.player.useSubWidgetTheme = false;
61 EMono.ui.widgets.Load(isSubTheme: false);
62 }
63 first = true;
65 {
66 if (EMono.player.subWidgets == null)
67 {
68 Load(isSubTheme: true);
69 }
70 }
71 else if (EMono.player.mainWidgets == null)
72 {
73 Load(isSubTheme: false);
74 if (Screen.width <= 1300 && !EMono.player.useSubWidgetTheme)
75 {
76 foreach (KeyValuePair<string, Widget.Config> item in EMono.player.mainWidgets.dict)
77 {
78 if (item.Key == "StatsBar")
79 {
80 item.Value.state = Widget.State.Inactive;
81 }
82 }
83 }
84 }
85 if (metaMap.Count == 0)
86 {
87 foreach (Widget.Meta meta in metas)
88 {
89 metaMap.Add(meta.id, meta);
90 }
91 }
92 foreach (Widget.Meta meta2 in metas)
93 {
94 if (!configs.ContainsKey(meta2.id))
95 {
96 Widget.Config config = new Widget.Config
97 {
98 meta = meta2,
99 valid = true,
100 id = meta2.id,
101 state = ((!meta2.enabled) ? Widget.State.Inactive : Widget.State.Active),
102 locked = meta2.locked
103 };
104 config.skin.SetID(0);
105 configs.Add(meta2.id, config);
106 }
107 else
108 {
109 Widget.Config config2 = configs[meta2.id];
110 config2.valid = true;
111 config2.meta = meta2;
112 }
113 }
114 foreach (Widget.Config item2 in configs.Values.ToList())
115 {
116 if (!item2.valid)
117 {
118 configs.Remove(item2.id);
119 }
120 }
121 }
122
123 public void OnKillGame()
124 {
125 KillWidgets();
126 }
127
128 public void OnChangeActionMode()
129 {
130 foreach (Widget item in list)
131 {
132 item.OnChangeActionMode();
133 }
134 }
135
136 public void UpdateConfigs()
137 {
138 foreach (Widget item in list)
139 {
140 item.UpdateConfig();
141 }
142 }
143
144 public void Activate(string id)
145 {
146 if (!GetWidget(id))
147 {
149 }
150 }
151
152 public Widget Toggle(string id)
153 {
154 Widget widget = GetWidget(id);
155 if ((bool)widget)
156 {
157 DeactivateWidget(widget);
158 return null;
159 }
160 return ActivateWidget(configs[id]);
161 }
162
164 {
165 Widget widget = GetWidget(c.id);
166 if ((bool)widget)
167 {
168 DeactivateWidget(widget);
169 return null;
170 }
171 return ActivateWidget(c);
172 }
173
174 public void ToggleLock(Widget.Config c)
175 {
176 c.locked = !c.locked;
177 RefreshWidget(c);
178 }
179
181 {
182 return ActivateWidget(c.id);
183 }
184
185 public Widget ActivateWidget(string id)
186 {
187 string text = "Widget" + id;
188 Widget widget = Util.Instantiate<Widget>("UI/Widget/" + text, this) ?? Util.Instantiate<Widget>("UI/Widget/" + text + "/" + text, this);
189 if (!widget)
190 {
191 Debug.LogError("Widget:" + id + " not found.");
192 return null;
193 }
194 list.Add(widget);
195 widget.gameObject.name = text;
196 widget.Activate();
197 RefreshWidget(widget);
198 if ((bool)LayerWidget.Instance)
199 {
200 widget.OnManagerActivate();
201 }
202 return widget;
203 }
204
206 {
208 }
209
210 public void RefreshWidget(Widget w)
211 {
212 if ((bool)w)
213 {
214 w.dragPanel.GetComponent<Graphic>().raycastTarget = !w.config.locked;
215 }
216 }
217
218 public Widget GetWidget(string id)
219 {
220 foreach (Widget item in list)
221 {
222 if (item.gameObject.name == "Widget" + id)
223 {
224 return item;
225 }
226 }
227 return null;
228 }
229
230 public void DeactivateWidget(string id)
231 {
233 }
234
236 {
237 if (!(w == null))
238 {
239 list.Remove(w);
240 w.Deactivate();
241 if ((bool)LayerWidget.Instance)
242 {
244 }
245 }
246 }
247
248 public void KillWidgets()
249 {
250 this.DestroyChildren(destroyInactive: true);
251 list.Clear();
252 first = true;
253 }
254
255 public void Show()
256 {
257 foreach (Widget item in list)
258 {
259 if (item.IsInRightMode())
260 {
261 item.gameObject.SetActive(value: true);
262 }
263 }
264 }
265
266 public void Hide()
267 {
268 foreach (Widget item in list)
269 {
271 {
272 item.gameObject.SetActive(value: false);
273 }
274 }
275 }
276
277 public void Reset(bool toggleTheme)
278 {
280 {
282 }
283 if ((bool)WidgetMainText.Instance)
284 {
285 (WidgetMainText.boxBk = WidgetMainText.Instance.box).transform.SetParent(base.transform.parent, worldPositionStays: false);
286 }
287 KillWidgets();
288 if (toggleTheme)
289 {
290 EMono.player.useSubWidgetTheme = !EMono.player.useSubWidgetTheme;
291 }
295 }
296
297 public void DialogSave(Action onSave = null)
298 {
300 {
301 string text = StandaloneFileBrowser.SaveFilePanel("Save Widget Theme", CorePath.WidgetSave, "new theme", "json");
302 if (!string.IsNullOrEmpty(text))
303 {
304 if (!EMono.debug.enable && (text.Contains("Default.json") || text.Contains("Modern.json") || text.Contains("Classic.json")))
305 {
306 Dialog.Ok("dialogInvalidTheme");
307 }
308 else
309 {
310 Save(text);
311 if (onSave != null)
312 {
313 onSave();
314 }
315 }
316 }
317 });
318 }
319
320 public void DialogLoad(Action onLoad = null)
321 {
323 {
324 string[] array = StandaloneFileBrowser.OpenFilePanel("Load Widget Theme", CorePath.WidgetSave, "json", multiselect: false);
325 if (array.Length != 0)
326 {
327 Load(EMono.player.useSubWidgetTheme, array[0]);
328 Reset(toggleTheme: false);
329 if (onLoad != null)
330 {
331 onLoad();
332 }
333 }
334 });
335 }
336
337 public void Save(string path = null)
338 {
339 if (path == null)
340 {
341 path = CorePath.WidgetSave + (EMono.player.useSubWidgetTheme ? EMono.core.config.other.idSubWidgetTheme : EMono.core.config.other.idMainWidgetTheme) + ".json";
342 }
343 UpdateConfigs();
344 IO.SaveFile(path, EMono.player.widgets);
345 }
346
347 public void Load(bool isSubTheme, string path = null)
348 {
349 if (path == null)
350 {
351 path = CorePath.WidgetSave + (isSubTheme ? EMono.core.config.other.idSubWidgetTheme : EMono.core.config.other.idMainWidgetTheme) + ".json";
352 }
353 SaveData saveData = IO.LoadFile<SaveData>(path);
354 if (isSubTheme)
355 {
356 EMono.player.subWidgets = saveData;
357 }
358 else
359 {
360 EMono.player.mainWidgets = saveData;
361 }
362 currentPath = path;
363 }
364}
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
void WaitForEndOfFrame(Action action)
Definition: BaseCore.cs:61
OtherSetting other
Definition: CoreConfig.cs:606
bool enable
Definition: CoreDebug.cs:285
bool resetPlayerConfig
Definition: CoreDebug.cs:119
static string WidgetSave
Definition: CorePath.cs:190
CoreConfig config
Definition: Core.cs:70
Definition: EMono.cs:4
static GameSetting setting
Definition: EMono.cs:31
static Core core
Definition: EMono.cs:5
static Player player
Definition: EMono.cs:11
static UI ui
Definition: EMono.cs:15
static CoreDebug debug
Definition: EMono.cs:45
List< Widget.Meta > widgetMetas
Definition: GameSetting.cs:26
UISetting ui
Definition: GameSetting.cs:307
void Refresh()
Definition: LayerWidget.cs:124
static LayerWidget Instance
Definition: LayerWidget.cs:5
bool isShowingLog
Definition: MsgBox.cs:55
bool useSubWidgetTheme
Definition: Player.cs:781
WidgetManager.SaveData widgets
Definition: Player.cs:1035
WidgetManager.SaveData subWidgets
Definition: Player.cs:832
WidgetManager.SaveData mainWidgets
Definition: Player.cs:829
bool isEditor
Definition: Player.cs:796
static string[] OpenFilePanel(string title, string directory, string extension, bool multiselect)
static string SaveFilePanel(string title, string directory, string defaultName, string extension)
void SetID(int _id)
Definition: SkinConfig.cs:133
static WidgetMainText Instance
Dictionary< string, Widget.Config > dict
void DialogLoad(Action onLoad=null)
List< Widget.Meta > metas
void ToggleLock(Widget.Config c)
Widget GetWidget(string id)
void UpdateConfigs()
Dictionary< string, Widget.Meta > metaMap
Widget Toggle(Widget.Config c)
Widget ActivateWidget(Widget.Config c)
void Load(bool isSubTheme, string path=null)
void Reset(bool toggleTheme)
void DialogSave(Action onSave=null)
void DeactivateWidget(Widget w)
void Save(string path=null)
void Activate(string id)
string currentPath
Dictionary< string, Widget.Config > configs
Widget ActivateWidget(string id)
List< Widget > list
void OnActivateZone()
Widget Toggle(string id)
void OnGameInstantiated()
void OnChangeActionMode()
void DeactivateWidget(string id)
void RefreshWidget(Widget w)
void KillWidgets()
void RefreshWidget(Widget.Config c)
SkinConfig skin
Definition: Widget.cs:61
bool locked
Definition: Widget.cs:55
string id
Definition: Widget.cs:47
Definition: Widget.cs:7
void Deactivate()
Definition: Widget.cs:307
void Activate()
Definition: Widget.cs:225
UIDragPanel dragPanel
Definition: Widget.cs:154
State
Definition: Widget.cs:141
virtual void OnManagerActivate()
Definition: Widget.cs:330
Config config
Definition: Widget.cs:180