summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/UI/UICommon/UIManager.cs
blob: 0daba0f9137381a1c569670ad6fd21c5a7e6c0b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
using System;
using System.Collections.Generic;
using System.Text;
using UILib;
using UnityEngine;
using XUpdater;
using XUtliPoolLib;

namespace XMainClient.UI.UICommon
{
	internal class UIManager : XSingleton<UIManager>
	{
		public Transform UIRoot
		{
			get
			{
				return this.m_uiRoot;
			}
			set
			{
				this.m_uiRoot = value;
			}
		}

		private Dictionary<string, IXUIDlg> m_dicDlgs = new Dictionary<string, IXUIDlg>();

		private Dictionary<int, List<IXUIDlg>> m_dicUILayer = new Dictionary<int, List<IXUIDlg>>();

		private List<IXUIDlg> m_iterDlgs = new List<IXUIDlg>();

		private Transform m_uiRoot = null;

		private Dictionary<int, IXUIDlg> m_GroupDlg = new Dictionary<int, IXUIDlg>();

		private List<IXUIDlg> m_ShowedDlg = new List<IXUIDlg>();

		private int m_TutorialClashUICount = 0;

		private List<IXUIDlg> m_ToBeUnloadDlg = new List<IXUIDlg>();

		private XLFU<IXUIDlg> m_LFU = new XLFU<IXUIDlg>(5);

		private List<IXUIDlg> m_CachedExculsiveUI = new List<IXUIDlg>();

		private Stack<IXUIDlg> m_ShowUIStack = new Stack<IXUIDlg>();

		private List<IXUIDlg> m_StoreUIList = new List<IXUIDlg>();

		private List<IXUIDlg> m_AvatarStack = new List<IXUIDlg>();

		public int unloadUICount = 0;

		public void OnEnterScene()
		{
			this.m_LFU.Clear();
			this.m_ShowedDlg.Clear();
			this.m_TutorialClashUICount = 0;
			this.m_CachedExculsiveUI.Clear();
			this.m_ShowUIStack.Clear();
			this.m_ToBeUnloadDlg.Clear();
			this.m_StoreUIList.Clear();
			this.unloadUICount = 0;
		}

		public void OnLeaveScene(bool transfer)
		{
			for (int i = this.m_iterDlgs.Count - 1; i >= 0; i--)
			{
				bool flag = i < this.m_iterDlgs.Count && this.m_iterDlgs[i] != null;
				if (flag)
				{
					this.m_iterDlgs[i].UnLoad(transfer);
				}
			}
			this.m_AvatarStack.Clear();
			this.unloadUICount = 0;
		}

		public override bool Init()
		{
			RuntimePlatform platform = Application.platform;
			int @int;
			if ((int)platform != 8)
			{
				if ((int)platform != 11)
				{
					@int = XSingleton<XGlobalConfig>.singleton.GetInt("UIUnloadLFUSizeDefault");
				}
				else
				{
					@int = XSingleton<XGlobalConfig>.singleton.GetInt("UIUnloadLFUSizeAndroid");
				}
			}
			else
			{
				@int = XSingleton<XGlobalConfig>.singleton.GetInt("UIUnloadLFUSizeIPhone");
			}
			this.m_LFU = new XLFU<IXUIDlg>(@int);
			return true;
		}

		public override void Uninit()
		{
		}

		public void LoadUI(string strUIFile, LoadUIFinishedEventHandler eventHandler)
		{
			bool flag = eventHandler != null;
			if (flag)
			{
				eventHandler(strUIFile);
			}
		}

		public void Update(float fDeltaT)
		{
			int i = 0;
			while (i < this.m_iterDlgs.Count)
			{
				IXUIDlg ixuidlg = this.m_iterDlgs[i];
				bool flag = ixuidlg != null;
				if (flag)
				{
					bool flag2 = ixuidlg.uiBehaviourInterface == null || ixuidlg.uiBehaviourInterface.gameObject == null;
					if (flag2)
					{
						XSingleton<XDebug>.singleton.AddErrorLog("UI missing: ", ixuidlg.fileName, null, null, null, null);
					}
					else
					{
						bool activeInHierarchy = ixuidlg.uiBehaviourInterface.gameObject.activeInHierarchy;
						if (activeInHierarchy)
						{
							ixuidlg.OnUpdate();
						}
					}
				}
				IL_78:
				i++;
				continue;
				goto IL_78;
			}
		}

		public void PostUpdate(float fDeltaT)
		{
			for (int i = 0; i < this.m_iterDlgs.Count; i++)
			{
				bool flag = this.m_iterDlgs[i] != null;
				if (flag)
				{
					this.m_iterDlgs[i].OnPostUpdate();
				}
			}
			bool flag2 = this.m_ToBeUnloadDlg.Count > 0;
			if (flag2)
			{
				for (int j = 0; j < this.m_ToBeUnloadDlg.Count; j++)
				{
					this.m_ToBeUnloadDlg[j].UnLoad(false);
				}
				this.m_ToBeUnloadDlg.Clear();
			}
		}

		public bool IsUIShowed()
		{
			bool flag = this.m_ShowUIStack.Count > 0;
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				bool flag2 = DlgBase<ScreenShotShareView, ScreenShotShareBehaviour>.singleton.IsLoaded() && DlgBase<ScreenShotShareView, ScreenShotShareBehaviour>.singleton.IsVisible();
				if (flag2)
				{
					result = true;
				}
				else
				{
					bool flag3 = DlgBase<XOtherPlayerInfoView, XOtherPlayerInfoBehaviour>.singleton.IsVisible();
					if (flag3)
					{
						result = true;
					}
					else
					{
						bool flag4 = XSingleton<XUpdater.XUpdater>.singleton.XLuaEngine.luaUIManager.IsUIShowed();
						result = flag4;
					}
				}
			}
			return result;
		}

		public bool IsHideTutorial()
		{
			return this.m_TutorialClashUICount != 0;
		}

		public int GetUIStackCount()
		{
			return this.m_ShowUIStack.Count;
		}

		public int GetFullScreenUICount()
		{
			int num = 0;
			foreach (IXUIDlg ixuidlg in this.m_ShowUIStack)
			{
				bool fullscreenui = ixuidlg.fullscreenui;
				if (fullscreenui)
				{
					num++;
				}
			}
			return num;
		}

		public void RemoveDlg(IXUIDlg dlg)
		{
			List<IXUIDlg> list = null;
			bool flag = this.m_dicUILayer.TryGetValue(dlg.layer, out list);
			if (flag)
			{
				list.Remove(dlg);
			}
			bool flag2 = this.m_dicDlgs.ContainsKey(dlg.fileName);
			if (flag2)
			{
				this.m_dicDlgs.Remove(dlg.fileName);
				this.m_iterDlgs.Remove(dlg);
			}
			bool flag3 = this.m_GroupDlg.ContainsKey(dlg.group);
			if (flag3)
			{
				this.m_GroupDlg.Remove(dlg.group);
			}
			bool flag4 = this.m_ShowedDlg.Contains(dlg);
			if (flag4)
			{
				bool isHideTutorial = dlg.isHideTutorial;
				if (isHideTutorial)
				{
					this.ChangeTutorialClashUI(false);
				}
				this.m_ShowedDlg.Remove(dlg);
			}
			this.m_LFU.Remove(dlg);
			this.m_AvatarStack.Remove(dlg);
		}

		public bool AddDlg(IXUIDlg dlg)
		{
			bool flag = this.m_dicDlgs.ContainsKey(dlg.fileName);
			bool result;
			if (flag)
			{
				XSingleton<XDebug>.singleton.AddLog("true == m_dicDlgs.ContainsKey(dlg.fileName): ", dlg.fileName, null, null, null, null, XDebugColor.XDebug_None);
				result = false;
			}
			else
			{
				this.m_dicDlgs.Add(dlg.fileName, dlg);
				this.m_iterDlgs.Add(dlg);
				List<IXUIDlg> list = null;
				bool flag2 = this.m_dicUILayer.TryGetValue(dlg.layer, out list);
				if (flag2)
				{
					list.Add(dlg);
				}
				else
				{
					list = new List<IXUIDlg>();
					list.Add(dlg);
					this.m_dicUILayer.Add(dlg.layer, list);
				}
				result = true;
			}
			return result;
		}

		protected void CacheExclusiveUI()
		{
			this.m_CachedExculsiveUI.Clear();
			for (int i = 0; i < this.m_ShowedDlg.Count; i++)
			{
				this.m_CachedExculsiveUI.Add(this.m_ShowedDlg[i]);
			}
		}

		public void CloseAllUI()
		{
			this.ClearUIinStack();
			List<IXUIDlg> list = new List<IXUIDlg>();
			for (int i = 0; i < this.m_ShowedDlg.Count; i++)
			{
				bool flag = !this.m_ShowedDlg[i].isMainUI;
				if (flag)
				{
					list.Add(this.m_ShowedDlg[i]);
				}
			}
			for (int j = 0; j < list.Count; j++)
			{
				list[j].SetVisible(false, true);
			}
		}

		public void OnDlgShow(IXUIDlg dlg)
		{
			bool exclusive = dlg.exclusive;
			if (exclusive)
			{
				this.CloseAllUI();
				this.CacheExclusiveUI();
				for (int i = 0; i < this.m_CachedExculsiveUI.Count; i++)
				{
					this.m_CachedExculsiveUI[i].uiBehaviourInterface.uiDlgInterface.SetVisiblePure(false);
				}
				this.ChangeTutorialClashUI(true);
			}
			else
			{
				bool flag = !this.m_ShowedDlg.Contains(dlg);
				if (flag)
				{
					this.m_ShowedDlg.Add(dlg);
					bool isHideTutorial = dlg.isHideTutorial;
					if (isHideTutorial)
					{
						this.ChangeTutorialClashUI(true);
					}
				}
				bool flag2 = !dlg.needOnTop;
				if (flag2)
				{
					this.m_AvatarStack.Remove(dlg);
					this.m_AvatarStack.Add(dlg);
				}
				else
				{
					Vector3 localPosition = dlg.uiBehaviourInterface.gameObject.transform.localPosition;
					localPosition.z = 0f;
					dlg.uiBehaviourInterface.gameObject.transform.localPosition = localPosition;
				}
				float num = 0f;
				for (int j = this.m_AvatarStack.Count - 1; j >= 0; j--)
				{
					IXUIDlg ixuidlg = this.m_AvatarStack[j];
					Vector3 localPosition2 = ixuidlg.uiBehaviourInterface.gameObject.transform.localPosition;
					localPosition2.z = num;
					ixuidlg.uiBehaviourInterface.gameObject.transform.localPosition = localPosition2;
					num += 800f;
				}
			}
			bool pushstack = dlg.pushstack;
			if (pushstack)
			{
				IXUIDlg ixuidlg2 = this.m_LFU.Add(dlg);
				bool flag3 = ixuidlg2 != null;
				if (flag3)
				{
					this.m_ToBeUnloadDlg.Add(ixuidlg2);
					XSingleton<XDebug>.singleton.AddGreenLog("Auto Unload UI: ", ixuidlg2.fileName, " while opening ", dlg.fileName, null, null);
				}
				XSingleton<XVirtualTab>.singleton.Cancel();
			}
			bool hideMainMenu = dlg.hideMainMenu;
			if (hideMainMenu)
			{
				this.UIBlurEffect(true);
			}
			bool pushstack2 = dlg.pushstack;
			if (pushstack2)
			{
				XMainInterfaceDocument specificDocument = XDocuments.GetSpecificDocument<XMainInterfaceDocument>(XMainInterfaceDocument.uuID);
				bool flag4 = this.m_ShowUIStack.Count > 0;
				if (flag4)
				{
					IXUIDlg ixuidlg3 = this.m_ShowUIStack.Peek();
					ixuidlg3.LeaveStackTop();
					ixuidlg3.uiBehaviourInterface.uiDlgInterface.SetVisiblePure(false);
					Stack<IXUIDlg> stack = new Stack<IXUIDlg>();
					IXUIDlg ixuidlg4 = this.m_ShowUIStack.Pop();
					while (ixuidlg4 != dlg && this.m_ShowUIStack.Count > 0)
					{
						stack.Push(ixuidlg4);
						ixuidlg4 = this.m_ShowUIStack.Pop();
					}
					bool flag5 = ixuidlg4 != dlg;
					if (flag5)
					{
						this.m_ShowUIStack.Push(ixuidlg4);
					}
					while (stack.Count > 0)
					{
						this.m_ShowUIStack.Push(stack.Pop());
					}
				}
				this.m_ShowUIStack.Push(dlg);
				specificDocument.OnTopUIRefreshed(dlg);
			}
			DlgBase<XChatView, XChatBehaviour>.singleton.TryCloseChat(dlg);
		}

		public void UIBlurEffect(bool bOn)
		{
			bool flag = DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.IsLoaded();
			if (flag)
			{
				DlgBase<XMainInterface, XMainInterfaceBehaviour>.singleton.FakeShowSelf(!bOn);
			}
		}

		public void OnDlgHide(IXUIDlg dlg)
		{
			bool exclusive = dlg.exclusive;
			if (exclusive)
			{
				for (int i = 0; i < this.m_CachedExculsiveUI.Count; i++)
				{
					this.m_CachedExculsiveUI[i].uiBehaviourInterface.uiDlgInterface.SetVisiblePure(true);
				}
				this.ChangeTutorialClashUI(false);
			}
			else
			{
				this.m_ShowedDlg.Remove(dlg);
				bool isHideTutorial = dlg.isHideTutorial;
				if (isHideTutorial)
				{
					this.ChangeTutorialClashUI(false);
				}
				this.m_AvatarStack.Remove(dlg);
			}
			bool pushstack = dlg.pushstack;
			if (pushstack)
			{
				this.m_LFU.MarkCanPop(dlg, true);
			}
			bool hideMainMenu = dlg.hideMainMenu;
			if (hideMainMenu)
			{
				this.UIBlurEffect(false);
			}
			bool flag = dlg.pushstack && this.m_ShowUIStack.Count > 0;
			if (flag)
			{
				IXUIDlg ixuidlg = this.m_ShowUIStack.Peek();
				bool flag2 = ixuidlg != dlg;
				if (flag2)
				{
					XSingleton<XDebug>.singleton.AddLog("Not hide top of ui stack!:", dlg.fileName, null, null, null, null, XDebugColor.XDebug_None);
					Stack<IXUIDlg> stack = new Stack<IXUIDlg>();
					for (IXUIDlg ixuidlg2 = this.m_ShowUIStack.Pop(); ixuidlg2 != dlg; ixuidlg2 = this.m_ShowUIStack.Pop())
					{
						stack.Push(ixuidlg2);
						bool flag3 = this.m_ShowUIStack.Count == 0;
						if (flag3)
						{
							StringBuilder sharedStringBuilder = XSingleton<XCommon>.singleton.GetSharedStringBuilder();
							sharedStringBuilder.Length = 0;
							sharedStringBuilder.Append("Hide UI not in stack!!!! : ").Append(dlg.fileName);
							sharedStringBuilder.Append("; UIs in stack: ");
							foreach (IXUIDlg ixuidlg3 in stack)
							{
								sharedStringBuilder.Append(ixuidlg3.fileName).Append(" ");
							}
							XSingleton<XDebug>.singleton.AddErrorLog(sharedStringBuilder.ToString(), null, null, null, null, null);
							break;
						}
					}
					while (stack.Count > 0)
					{
						this.m_ShowUIStack.Push(stack.Pop());
					}
					bool flag4 = this.m_ShowUIStack.Count > 0;
					if (flag4)
					{
						IXUIDlg ixuidlg4 = this.m_ShowUIStack.Peek();
						bool hideMainMenu2 = ixuidlg4.hideMainMenu;
						if (hideMainMenu2)
						{
							this.UIBlurEffect(true);
						}
					}
				}
				else
				{
					this.m_ShowUIStack.Pop();
					XMainInterfaceDocument specificDocument = XDocuments.GetSpecificDocument<XMainInterfaceDocument>(XMainInterfaceDocument.uuID);
					bool flag5 = this.m_ShowUIStack.Count > 0;
					if (flag5)
					{
						IXUIDlg ixuidlg5 = this.m_ShowUIStack.Peek();
						ixuidlg5.uiBehaviourInterface.uiDlgInterface.SetVisiblePure(true);
						ixuidlg5.StackRefresh();
						specificDocument.OnTopUIRefreshed(ixuidlg5);
						bool hideMainMenu3 = ixuidlg5.hideMainMenu;
						if (hideMainMenu3)
						{
							this.UIBlurEffect(true);
						}
					}
					else
					{
						specificDocument.OnTopUIRefreshed(null);
					}
				}
			}
		}

		public List<IXUIDlg> GetShowedUI()
		{
			return this.m_ShowedDlg;
		}

		public void ClearUIinStack()
		{
			while (this.m_ShowUIStack.Count > 0)
			{
				IXUIDlg ixuidlg = this.m_ShowUIStack.Peek();
				bool flag = ixuidlg != null;
				if (flag)
				{
					ixuidlg.SetVisiblePure(true);
					ixuidlg.SetVisible(false, true);
				}
			}
			this.UIBlurEffect(false);
		}

		public void HideAllUIWithOutCall()
		{
			for (int i = 0; i < this.m_ShowedDlg.Count; i++)
			{
				bool flag = this.m_ShowedDlg[i] == DlgBase<XShowGetItemView, XShowGetItemBehaviour>.singleton || this.m_ShowedDlg[i] == DlgBase<XChatMaqueeView, XChatMaqueeBehaviour>.singleton || this.m_ShowedDlg[i] == DlgBase<XSystemTipView, XSystemTipBehaviour>.singleton;
				if (!flag)
				{
					bool flag2 = this.m_ShowedDlg[i].IsVisible();
					if (flag2)
					{
						this.m_StoreUIList.Add(this.m_ShowedDlg[i]);
						this.m_ShowedDlg[i].SetVisiblePure(false);
					}
				}
			}
		}

		public void RestoreAllUIWithOutCall()
		{
			for (int i = 0; i < this.m_StoreUIList.Count; i++)
			{
				bool flag = this.m_StoreUIList[i] != null;
				if (flag)
				{
					this.m_StoreUIList[i].SetVisiblePure(true);
				}
			}
			this.m_StoreUIList.Clear();
		}

		private void ChangeTutorialClashUI(bool isAdd)
		{
			if (isAdd)
			{
				this.m_TutorialClashUICount++;
				XSingleton<XDebug>.singleton.AddGreenLog("TutorialClashUICount++:" + this.m_TutorialClashUICount, null, null, null, null, null);
			}
			else
			{
				this.m_TutorialClashUICount--;
				XSingleton<XDebug>.singleton.AddGreenLog("TutorialClashUICount--:" + this.m_TutorialClashUICount, null, null, null, null, null);
				bool flag = this.m_TutorialClashUICount < 0;
				if (flag)
				{
					this.m_TutorialClashUICount = 0;
					XSingleton<XDebug>.singleton.AddErrorLog("TutorialClashUICount Error", null, null, null, null, null);
				}
			}
		}
	}
}