summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/UI/ArtifactFuseHandler.cs
blob: 07c34e9f4dce6136b4ff15274fe1a83ac55cdb2d (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
using System;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient.UI
{
	internal class ArtifactFuseHandler : DlgHandlerBase
	{
		private string SucEffectPath
		{
			get
			{
				bool flag = string.IsNullOrEmpty(this.m_sucEffectPath);
				if (flag)
				{
					this.m_sucEffectPath = XSingleton<XGlobalConfig>.singleton.GetValue("FuseSucEffectPath");
				}
				return this.m_sucEffectPath;
			}
		}

		private string FailEffectPath
		{
			get
			{
				bool flag = string.IsNullOrEmpty(this.m_failEffectPath);
				if (flag)
				{
					this.m_failEffectPath = XSingleton<XGlobalConfig>.singleton.GetValue("FuseFailEffectPath");
				}
				return this.m_failEffectPath;
			}
		}

		private string EffectPath
		{
			get
			{
				bool flag = string.IsNullOrEmpty(this.m_effectPath);
				if (flag)
				{
					this.m_effectPath = XSingleton<XGlobalConfig>.singleton.GetValue("FuseEffectPath");
				}
				return this.m_effectPath;
			}
		}

		protected override string FileName
		{
			get
			{
				return "ItemNew/ArtifactFuseHandler";
			}
		}

		private ArtifactFuseDocument m_doc;

		private bool m_bMatIsEnough = false;

		private int m_needItemId = 0;

		private GameObject m_itemGo1;

		private GameObject m_itemGo2;

		private GameObject m_itemGo3;

		private Transform m_effectTra;

		private IXUISprite m_boxSpr1;

		private IXUISprite m_boxSpr2;

		private IXUICheckBox m_checkBox;

		private IXUIButton m_fuseBtn;

		private IXUILabel m_rateLab;

		private XFx m_fx;

		private XFx m_sucFx;

		private XFx m_failFx;

		private uint m_token = 0u;

		private float m_lastTime = 1f;

		private bool m_bIsPlayingEffect = false;

		private string m_sucEffectPath = string.Empty;

		private string m_failEffectPath = string.Empty;

		private string m_effectPath = string.Empty;

		protected override void Init()
		{
			base.Init();
			this.m_doc = ArtifactFuseDocument.Doc;
			this.m_doc.Handler = this;
			Transform transform = base.PanelObject.transform.Find("Bg1");
			this.m_rateLab = (transform.Find("ossd").GetComponent("XUILabel") as IXUILabel);
			this.m_itemGo1 = transform.Find("item1").gameObject;
			this.m_itemGo2 = transform.Find("item2").gameObject;
			this.m_itemGo3 = transform.Find("item3").gameObject;
			this.m_boxSpr1 = (transform.Find("BgBox1").GetComponent("XUISprite") as IXUISprite);
			this.m_boxSpr2 = (transform.Find("BgBox2").GetComponent("XUISprite") as IXUISprite);
			this.m_checkBox = (transform.Find("BtnUse").GetComponent("XUICheckBox") as IXUICheckBox);
			this.m_fuseBtn = (transform.Find("Get").GetComponent("XUIButton") as IXUIButton);
			this.m_effectTra = transform.Find("Effect");
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_boxSpr1.ID = 1UL;
			this.m_boxSpr1.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClickBox));
			this.m_boxSpr2.ID = 2UL;
			this.m_boxSpr2.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClickBox));
			this.m_checkBox.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnClickToggle));
			this.m_fuseBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickFuseBtn));
		}

		protected override void OnShow()
		{
			base.OnShow();
			this.FillContent();
		}

		protected override void OnHide()
		{
			base.OnHide();
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
			this.StopEffect();
		}

		public override void StackRefresh()
		{
			base.StackRefresh();
		}

		public override void OnUnload()
		{
			base.OnUnload();
			this.m_doc.Handler = null;
			bool flag = this.m_fx != null;
			if (flag)
			{
				XSingleton<XFxMgr>.singleton.DestroyFx(this.m_fx, true);
				this.m_fx = null;
			}
			bool flag2 = this.m_sucFx != null;
			if (flag2)
			{
				XSingleton<XFxMgr>.singleton.DestroyFx(this.m_sucFx, true);
				this.m_sucFx = null;
			}
			bool flag3 = this.m_failFx != null;
			if (flag3)
			{
				XSingleton<XFxMgr>.singleton.DestroyFx(this.m_failFx, true);
				this.m_failFx = null;
			}
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
		}

		public void RefreshUi(FuseEffectType type)
		{
			this.FillContent();
			bool flag = type > FuseEffectType.None;
			if (flag)
			{
				this.PlayEffect(type);
			}
		}

		private void FillContent()
		{
			bool flag = this.m_doc.FuseUid == 0UL;
			if (flag)
			{
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(this.m_itemGo1, null);
			}
			else
			{
				XItem itemByUID = XBagDocument.BagDoc.GetItemByUID(this.m_doc.FuseUid);
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(this.m_itemGo1, itemByUID);
				IXUISprite ixuisprite = this.m_itemGo1.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
				ixuisprite.ID = this.m_doc.FuseUid;
				ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClickTips));
			}
			bool flag2 = this.m_doc.FusedUid == 0UL;
			if (flag2)
			{
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(this.m_itemGo2, null);
			}
			else
			{
				XItem itemByUID2 = XBagDocument.BagDoc.GetItemByUID(this.m_doc.FusedUid);
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(this.m_itemGo2, itemByUID2);
				IXUISprite ixuisprite2 = this.m_itemGo2.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
				ixuisprite2.ID = this.m_doc.FusedUid;
				ixuisprite2.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClickTips));
			}
			bool flag3 = this.m_doc.FusedUid != 0UL && this.m_doc.FuseUid > 0UL;
			if (flag3)
			{
				bool flag4 = this.m_fx == null;
				if (flag4)
				{
					this.m_fx = XSingleton<XFxMgr>.singleton.CreateFx(this.EffectPath, null, true);
				}
				else
				{
					this.m_fx.SetActive(true);
				}
				this.m_fx.Play(this.m_effectTra, Vector3.zero, Vector3.one, 1f, true, false);
			}
			else
			{
				bool flag5 = this.m_fx != null;
				if (flag5)
				{
					this.m_fx.SetActive(false);
				}
			}
			this.m_checkBox.ForceSetFlag(this.m_doc.UseFuseStone);
			this.FillNeedItem();
		}

		private void FillNeedItem()
		{
			IXUILabel ixuilabel = this.m_itemGo3.transform.Find("Num").GetComponent("XUILabel") as IXUILabel;
			bool flag = this.m_doc.FuseUid == 0UL;
			int num;
			if (flag)
			{
				num = this.m_doc.FuseStoneItemId;
				XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(this.m_itemGo3, num, 2, false);
				ulong itemCount = XBagDocument.BagDoc.GetItemCount(num);
				ixuilabel.SetText(string.Format("{0}/?", itemCount));
				this.m_rateLab.SetText(string.Format(XSingleton<XStringTable>.singleton.GetString("FuseRateSucRate"), "?"));
				this.m_bMatIsEnough = false;
			}
			else
			{
				XItem itemByUID = XBagDocument.BagDoc.GetItemByUID(this.m_doc.FuseUid);
				bool flag2 = itemByUID == null;
				if (flag2)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("m_doc.FuseUid = {0} not find" + this.m_doc.FuseUid.ToString(), null, null, null, null, null);
					return;
				}
				ArtifactListTable.RowData artifactListRowData = ArtifactDocument.GetArtifactListRowData((uint)itemByUID.itemID);
				bool flag3 = artifactListRowData == null;
				if (flag3)
				{
					XSingleton<XDebug>.singleton.AddErrorLog(string.Format("artifactlist not find this itemId = {0}", itemByUID.itemID), null, null, null, null, null);
					return;
				}
				num = (int)artifactListRowData.FuseMaterials[0, 0];
				XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(this.m_itemGo3, num, 2, false);
				ulong itemCount2 = XBagDocument.BagDoc.GetItemCount(num);
				this.m_bMatIsEnough = (itemCount2 >= (ulong)artifactListRowData.FuseMaterials[0, 1]);
				bool bMatIsEnough = this.m_bMatIsEnough;
				if (bMatIsEnough)
				{
					ixuilabel.SetText(string.Format("[00ff00]{0}/{1}[-]", itemCount2, artifactListRowData.FuseMaterials[0, 1]));
				}
				else
				{
					ixuilabel.SetText(string.Format("[ff0000]{0}/{1}[-]", itemCount2, artifactListRowData.FuseMaterials[0, 1]));
				}
				bool useFuseStone = this.m_doc.UseFuseStone;
				if (useFuseStone)
				{
					this.m_rateLab.SetText(string.Format(XSingleton<XStringTable>.singleton.GetString("FuseRateSucRate"), artifactListRowData.FuseSucRateUseStone));
				}
				else
				{
					this.m_bMatIsEnough = true;
					this.m_rateLab.SetText(string.Format(XSingleton<XStringTable>.singleton.GetString("FuseRateSucRate"), artifactListRowData.FuseSucRate[0]));
				}
			}
			this.m_needItemId = num;
			IXUISprite ixuisprite = this.m_itemGo3.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
			ixuisprite.ID = (ulong)((long)num);
			ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClickTips));
			ixuisprite = (this.m_itemGo3.transform.Find("Icon/Icon").GetComponent("XUISprite") as IXUISprite);
			ixuisprite.SetGrey(this.m_doc.FuseUid > 0UL);
			ixuisprite = (this.m_itemGo3.transform.Find("Quality").GetComponent("XUISprite") as IXUISprite);
			ixuisprite.SetGrey(this.m_doc.FuseUid > 0UL);
		}

		private void PlayEffect(FuseEffectType type)
		{
			bool flag = type == FuseEffectType.Sucess;
			if (flag)
			{
				bool flag2 = this.m_sucFx == null;
				if (flag2)
				{
					this.m_sucFx = XSingleton<XFxMgr>.singleton.CreateFx(this.SucEffectPath, null, true);
				}
				else
				{
					this.m_sucFx.SetActive(true);
				}
				this.m_sucFx.Play(base.PanelObject.transform, Vector3.zero, Vector3.one, 1f, true, false);
				this.m_bIsPlayingEffect = true;
			}
			else
			{
				bool flag3 = type == FuseEffectType.Fail;
				if (flag3)
				{
					bool flag4 = this.m_failFx == null;
					if (flag4)
					{
						this.m_failFx = XSingleton<XFxMgr>.singleton.CreateFx(this.FailEffectPath, null, true);
					}
					else
					{
						this.m_failFx.SetActive(true);
					}
					this.m_failFx.Play(base.PanelObject.transform, Vector3.zero, Vector3.one, 1f, true, false);
					this.m_bIsPlayingEffect = true;
				}
			}
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
			this.m_token = XSingleton<XTimerMgr>.singleton.SetTimer(this.m_lastTime, new XTimerMgr.ElapsedEventHandler(this.OnEffectEnd), null);
		}

		private void OnEffectEnd(object o = null)
		{
			bool flag = this.m_sucFx != null;
			if (flag)
			{
				this.m_sucFx.SetActive(false);
			}
			bool flag2 = this.m_failFx != null;
			if (flag2)
			{
				this.m_failFx.SetActive(false);
			}
			this.m_bIsPlayingEffect = false;
		}

		private void StopEffect()
		{
			bool flag = this.m_sucFx != null;
			if (flag)
			{
				this.m_sucFx.SetActive(false);
			}
			bool flag2 = this.m_failFx != null;
			if (flag2)
			{
				this.m_failFx.SetActive(false);
			}
			bool flag3 = this.m_fx != null;
			if (flag3)
			{
				this.m_fx.SetActive(false);
			}
		}

		private bool OnClickFuseBtn(IXUIButton btn)
		{
			bool bIsPlayingEffect = this.m_bIsPlayingEffect;
			bool result;
			if (bIsPlayingEffect)
			{
				result = false;
			}
			else
			{
				bool flag = this.m_doc.FuseUid == 0UL;
				if (flag)
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FuseTips1"), "fece00");
					result = false;
				}
				else
				{
					bool flag2 = this.m_doc.FusedUid == 0UL;
					if (flag2)
					{
						XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FuseTips2"), "fece00");
						result = false;
					}
					else
					{
						bool flag3 = !this.m_bMatIsEnough;
						if (flag3)
						{
							DlgBase<ArtifactDeityStoveDlg, TabDlgBehaviour>.singleton.SetVisible(false, true);
							XSingleton<UiUtility>.singleton.ShowItemAccess(this.m_needItemId, null);
							result = false;
						}
						else
						{
							XOptionsDocument specificDocument = XDocuments.GetSpecificDocument<XOptionsDocument>(XOptionsDocument.uuID);
							bool flag4 = specificDocument.GetValue(XOptionsDefine.OD_NO_FUSE_CONFIRM) == 1;
							if (flag4)
							{
								this.m_doc.ReqFuse();
							}
							else
							{
								bool useFuseStone = this.m_doc.UseFuseStone;
								string @string;
								if (useFuseStone)
								{
									@string = XStringDefineProxy.GetString("FuseEnsureTips2");
								}
								else
								{
									@string = XStringDefineProxy.GetString("FuseEnsureTips1");
								}
								XSingleton<UiUtility>.singleton.ShowModalDialog(@string, XStringDefineProxy.GetString(XStringDefine.COMMON_OK), XStringDefineProxy.GetString(XStringDefine.COMMON_CANCEL), new ButtonClickEventHandler(this.DoOK), new ButtonClickEventHandler(this.DoCancel), false, XTempTipDefine.OD_FUSE_CONFIRM, 50);
							}
							result = true;
						}
					}
				}
			}
			return result;
		}

		private bool DoOK(IXUIButton btn)
		{
			bool flag = DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.IsVisible();
			if (flag)
			{
				XOptionsDocument specificDocument = XDocuments.GetSpecificDocument<XOptionsDocument>(XOptionsDocument.uuID);
				specificDocument.SetValue(XOptionsDefine.OD_NO_FUSE_CONFIRM, DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.GetTempTip(XTempTipDefine.OD_FUSE_CONFIRM) ? 1 : 0, false);
			}
			XSingleton<UiUtility>.singleton.CloseModalDlg();
			this.m_doc.ReqFuse();
			return true;
		}

		private bool DoCancel(IXUIButton btn)
		{
			XOptionsDocument specificDocument = XDocuments.GetSpecificDocument<XOptionsDocument>(XOptionsDocument.uuID);
			specificDocument.SetValue(XOptionsDefine.OD_NO_FUSE_CONFIRM, DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.GetTempTip(XTempTipDefine.OD_FUSE_CONFIRM) ? 1 : 0, false);
			XSingleton<UiUtility>.singleton.CloseModalDlg();
			return true;
		}

		private void OnClickBox(IXUISprite spr)
		{
			bool flag = spr.ID == 1UL;
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FuseTips1"), "fece00");
			}
			else
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("FuseTips2"), "fece00");
			}
		}

		private void OnClickTips(IXUISprite spr)
		{
			bool flag = spr.ID == 0UL;
			if (!flag)
			{
				XItem xitem = XBagDocument.BagDoc.GetItemByUID(spr.ID);
				bool flag2 = xitem == null;
				if (flag2)
				{
					xitem = XBagDocument.MakeXItem((int)spr.ID, false);
				}
				bool flag3 = xitem == null;
				if (!flag3)
				{
					bool flag4 = xitem.Type == ItemType.ARTIFACT;
					if (flag4)
					{
						XSingleton<TooltipParam>.singleton.bShowTakeOutBtn = true;
					}
					XSingleton<UiUtility>.singleton.ShowTooltipDialog(xitem, null, spr, true, 0u);
				}
			}
		}

		private bool OnClickToggle(IXUICheckBox box)
		{
			bool flag = box.bChecked != this.m_doc.UseFuseStone;
			if (flag)
			{
				this.m_doc.UseFuseStone = box.bChecked;
				this.FillNeedItem();
			}
			return true;
		}
	}
}