summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XUtliPoolLib/XUpdater/XLoadingUI.cs
blob: b74f8e3940f8596e11bd6b22367f71b3fff949df (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
using System;
using UILib;
using UnityEngine;
using XUtliPoolLib;

namespace XUpdater
{
	internal class XLoadingUI : XSingleton<XLoadingUI>
	{
		private IXUISprite JY;

		private IXUISprite Black;

		private IXUITweenTool JYPlayTween;

		private IXUITweenTool BlackPlayTween;

		private IXUILabel StatusText;

		private IXUILabel VersionText;

		private IXUISprite ClickBox;

		public bool LoadingOK = false;

		private bool TweenOK = false;

		private Transform mTextureTransform;

		private Transform mDialogTransform;

		private IXUIButton mDialogSureBtn;

		private IXUIButton mDialogCancelBtn;

		private IXUILabel mDialogCapacityLabel;

		private IXUITexture mDownLoadTexture;

		private IXUIButton mDownLoadNewBtn;

		private Transform mDownLoadTransform;

		private XLoadingUI.OnSureCallBack mDialogCallBack;

		private XLoadingUI.OnSureCallBack mDialogCancelCallBack;

		private XLoadingUI.OnSureCallBack mDownCallBack;

		public delegate void OnSureCallBack();

		public override bool Init()
		{
			PlayerPrefs.SetString("Language", "Language");
			GameObject gameObject = GameObject.Find("UIRoot/StartLoadingDlg/Bg/Ailin");
			GameObject gameObject2 = GameObject.Find("UIRoot/StartLoadingDlg/Bg/JY");
			GameObject gameObject3 = GameObject.Find("UIRoot/StartLoadingDlg/Bg").transform.Find("Black").gameObject;
			this.StatusText = (GameObject.Find("UIRoot/StartLoadingDlg/Bg/LabelStatus").GetComponent("XUILabel") as IXUILabel);
			this.VersionText = (GameObject.Find("UIRoot/StartLoadingDlg/Bg/LabelVersion").GetComponent("XUILabel") as IXUILabel);
			this.JY = (gameObject2.GetComponent("XUISprite") as IXUISprite);
			this.Black = (gameObject3.GetComponent("XUISprite") as IXUISprite);
			this.JYPlayTween = (gameObject2.GetComponent("XUIPlayTween") as IXUITweenTool);
			this.BlackPlayTween = (gameObject3.GetComponent("XUIPlayTween") as IXUITweenTool);
			this.JYPlayTween.SetTargetGameObject(gameObject2);
			this.JYPlayTween.RegisterOnFinishEventHandler(new OnTweenFinishEventHandler(this.OnJYPlayTweenFinish));
			this.Black.SetVisible(true);
			this.BlackPlayTween.SetTargetGameObject(gameObject3);
			this.BlackPlayTween.RegisterOnFinishEventHandler(new OnTweenFinishEventHandler(this.OnBlackPlayTweenFinish));
			this.StatusText.SetVisible(false);
			this.VersionText.SetVisible(false);
			this.Black.SetVisible(false);
			this.JY.SetVisible(true);
			this.JYPlayTween.PlayTween(true, -1f);
			this.ClickBox = (GameObject.Find("UIRoot/StartLoadingDlg/Bg").GetComponent("XUISprite") as IXUISprite);
			this.ClickBox.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnBoxClick));
			this.mTextureTransform = GameObject.Find("UIRoot/StartLoadingDlg/Bg/Texture").transform;
			this.mDialogTransform = GameObject.Find("UIRoot/StartLoadingDlg/Bg/Dialog").transform;
			this.mDialogSureBtn = (this.mDialogTransform.Find("OK").GetComponent("XUIButton") as IXUIButton);
			this.mDialogCancelBtn = (this.mDialogTransform.Find("Cancel").GetComponent("XUIButton") as IXUIButton);
			this.mDialogCapacityLabel = (this.mDialogTransform.Find("CapacityValue").GetComponent("XUILabel") as IXUILabel);
			this.mDialogSureBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnDialogSureClick));
			this.mDialogCancelBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnDialogCancelClick));
			this.mTextureTransform.gameObject.SetActive(false);
			this.mDialogTransform.gameObject.SetActive(false);
			this.mDownLoadTransform = GameObject.Find("UIRoot/StartLoadingDlg/Bg/DownNew").transform;
			this.mDownLoadTexture = (this.mDownLoadTransform.Find("Pic").GetComponent("XUITexture") as IXUITexture);
			this.mDownLoadNewBtn = (this.mDownLoadTransform.Find("OK").GetComponent("XUIButton") as IXUIButton);
			this.mDownLoadTransform.gameObject.SetActive(false);
			this.mDownLoadNewBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnDownLoadCallback));
			return true;
		}

		public bool OnDialogSureClick(IXUIButton btn)
		{
			this.mDialogTransform.gameObject.SetActive(false);
			bool flag = this.mDialogCallBack != null;
			if (flag)
			{
				this.mDialogCallBack();
			}
			return true;
		}

		public bool OnDialogCancelClick(IXUIButton btn)
		{
			this.mDialogTransform.gameObject.SetActive(false);
			bool flag = this.mDialogCancelCallBack != null;
			if (flag)
			{
				this.mDialogCancelCallBack();
			}
			return true;
		}

		public bool OnDownLoadCallback(IXUIButton btn)
		{
			this.mDownLoadTransform.gameObject.SetActive(false);
			bool flag = this.mDownCallBack != null;
			if (flag)
			{
				this.mDownCallBack();
			}
			return true;
		}

		public void OnBoxClick(IXUISprite sp)
		{
			XSingleton<XUpdater>.singleton.OnRetry();
		}

		private void OnBlackPlayTweenFinish(IXUITweenTool iPlayTween)
		{
			XSingleton<XUpdater>.singleton.Phase = eUPdatePhase.xUP_Finish;
		}

		private void OnAilinPlayTweenFinish(IXUITweenTool iPlayTween)
		{
			this.TweenOK = true;
		}

		private void OnJYPlayTweenFinish(IXUITweenTool iPlayTween)
		{
			this.JY.SetVisible(false);
			this.mTextureTransform.gameObject.SetActive(true);
			this.TweenOK = true;
			XSingleton<XUpdater>.singleton.Begin();
		}

		private void LoadFinishClean()
		{
			this.JY = null;
			this.Black = null;
			this.JYPlayTween = null;
			this.BlackPlayTween = null;
			this.StatusText = null;
			this.VersionText = null;
			this.ClickBox = null;
			this.mDialogCallBack = null;
			this.mDialogCancelCallBack = null;
			this.mDialogCancelBtn = null;
			this.mDialogSureBtn = null;
			this.mDialogCapacityLabel = null;
			this.mDialogTransform = null;
			this.mDownLoadNewBtn = null;
			this.mDownLoadTransform = null;
		}

		public void SetDialog(ulong capacity, XLoadingUI.OnSureCallBack sureCallBack, XLoadingUI.OnSureCallBack cancelCallBack)
		{
			this.mDialogCallBack = sureCallBack;
			this.mDialogCancelCallBack = cancelCallBack;
			this.mDialogTransform.gameObject.SetActive(true);
			this.mDialogCapacityLabel.SetText(this.GetCapacityValue(capacity));
		}

		public void SetDownLoad(XLoadingUI.OnSureCallBack sureCallBack, Texture tex)
		{
			this.mDownCallBack = sureCallBack;
			this.mDownLoadTransform.gameObject.SetActive(true);
			bool flag = tex != null;
			if (flag)
			{
				this.mDownLoadTexture.SetRuntimeTex(tex, true);
			}
		}

		private string GetCapacityValue(ulong capacity)
		{
			bool flag = capacity < 1048576UL;
			string result;
			if (flag)
			{
				result = string.Format("{0}K", (capacity / 1024UL).ToString("F2"));
			}
			else
			{
				result = string.Format("{0}M", (capacity / 1024UL / 1024UL).ToString("F2"));
			}
			return result;
		}

		public void SetStatus(string text, byte r = 255, byte g = 255, byte b = 255)
		{
			bool flag = !this.StatusText.IsVisible();
			if (flag)
			{
				this.StatusText.SetVisible(true);
			}
			this.StatusText.SetColor(new Color32(r, g, b, byte.MaxValue));
			this.StatusText.SetText(text);
		}

		public void SetVersion(string text)
		{
			bool flag = !this.VersionText.IsVisible();
			if (flag)
			{
				this.VersionText.SetVisible(true);
			}
			this.VersionText.SetText(text);
		}

		public void OnUpdate()
		{
			bool flag = this.TweenOK && this.LoadingOK;
			if (flag)
			{
				this.TweenOK = (this.LoadingOK = false);
				XSingleton<XUpdater>.singleton.Phase = eUPdatePhase.xUP_Finish;
				this.LoadFinishClean();
			}
		}

		public override void Uninit()
		{
		}
	}
}