summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/UI/PartnerMainHandler.cs
blob: c6af4a86a221d0c2d9840b68af3aa5cacad864da (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
using System;
using System.Collections.Generic;
using KKSG;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient.UI
{
	internal class PartnerMainHandler : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "Partner/PartnerFrame";
			}
		}

		private XPartnerDocument m_doc = XPartnerDocument.Doc;

		private IUIDummy[] m_Snapshots = new IUIDummy[XPartnerDocument.MaxAvata];

		private float m_fCoolTime = 0.5f;

		private float m_fLastClickBtnTime = 0f;

		private uint m_token;

		private GameObject m_emptyGo;

		private GameObject m_obtainedGo;

		private IXUIButton m_shopBtn;

		private IXUIButton m_gotoTeamBtn;

		private IXUIButton m_gotoBtn;

		private IXUILabel m_noPartnerTips;

		private IXUILabel m_ruleLab;

		private XUIPool m_emptyItemPool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		private Transform m_livenessTra;

		private IXUIButton m_livenessBtn;

		private IXUIButton m_breakupBtn;

		private IXUIButton m_cancleBreakUpBtn;

		private IXUILabel m_breakUpCutDownLab;

		private XUIPool m_itemPool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		private XTeamPartnerBonusHandler m_FriendBonusHandler = null;

		protected override void Init()
		{
			base.Init();
			this.m_doc.View = this;
			this.m_emptyGo = base.PanelObject.transform.Find("Bg/Empty").gameObject;
			this.m_obtainedGo = base.PanelObject.transform.Find("Bg/Obtained").gameObject;
			this.m_shopBtn = (base.PanelObject.transform.Find("Bg/BtnShop").GetComponent("XUIButton") as IXUIButton);
			Transform transform = this.m_emptyGo.transform.Find("PartnerPrior/Grid");
			this.m_emptyItemPool.SetupPool(transform.gameObject, transform.Find("Tpl").gameObject, 3u, false);
			this.m_gotoBtn = (this.m_emptyGo.transform.Find("ButtonR").GetComponent("XUIButton") as IXUIButton);
			this.m_gotoTeamBtn = (this.m_emptyGo.transform.Find("GoTeam").GetComponent("XUIButton") as IXUIButton);
			this.m_noPartnerTips = (this.m_emptyGo.transform.Find("T").GetComponent("XUILabel") as IXUILabel);
			this.m_ruleLab = (this.m_emptyGo.transform.Find("RuleLab").GetComponent("XUILabel") as IXUILabel);
			this.m_livenessTra = this.m_obtainedGo.transform.Find("Bar");
			this.m_livenessBtn = (this.m_obtainedGo.transform.Find("LivenessBtn").GetComponent("XUIButton") as IXUIButton);
			this.m_breakupBtn = (this.m_obtainedGo.transform.Find("BreakupBtn").GetComponent("XUIButton") as IXUIButton);
			this.m_cancleBreakUpBtn = (this.m_obtainedGo.transform.Find("CancleBreakupBtn").GetComponent("XUIButton") as IXUIButton);
			this.m_breakUpCutDownLab = (this.m_obtainedGo.transform.Find("BreakUpCutDownLab").GetComponent("XUILabel") as IXUILabel);
			transform = this.m_obtainedGo.transform.Find("ModleParent");
			this.m_itemPool.SetupPool(transform.gameObject, transform.Find("Tpl").gameObject, 4u, false);
			DlgHandlerBase.EnsureCreate<XTeamPartnerBonusHandler>(ref this.m_FriendBonusHandler, this.m_obtainedGo.transform.Find("FriendBonusFrame").gameObject, this, true);
			this.m_FriendBonusHandler.bConsiderTeam = false;
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_shopBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickShopBtn));
			this.m_gotoBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickGoToBtn));
			this.m_gotoTeamBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickGoToTeamBtn));
			this.m_livenessBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickLivenessBtn));
			this.m_breakupBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickbreakupBtn));
			this.m_cancleBreakUpBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickCancleBreakupBtn));
		}

		protected override void OnShow()
		{
			base.OnShow();
			base.Alloc3DAvatarPool("PartnerMainHandler", 1);
			this.FillContent();
		}

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

		public override void StackRefresh()
		{
			base.StackRefresh();
			base.Alloc3DAvatarPool("PartnerMainHandler", 1);
		}

		public override void OnUnload()
		{
			base.Return3DAvatarPool();
			this.m_doc.View = null;
			base.OnUnload();
		}

		private void FillContent()
		{
			this.m_emptyGo.SetActive(false);
			this.m_obtainedGo.SetActive(false);
			this.m_shopBtn.gameObject.SetActive(false);
			bool flag = this.m_doc.PartnerID == 0UL;
			if (flag)
			{
				this.FillNoPartner();
			}
			else
			{
				this.m_doc.ReqPartnerDetailInfo();
			}
		}

		public void RefreshUi()
		{
			this.m_emptyGo.SetActive(false);
			this.m_obtainedGo.SetActive(false);
			this.m_shopBtn.gameObject.SetActive(false);
			bool flag = this.m_doc.PartnerID == 0UL;
			if (flag)
			{
				this.FillNoPartner();
			}
			else
			{
				this.FillHadPartner();
			}
		}

		private void FillNoPartner()
		{
			this.m_emptyGo.SetActive(true);
			this.m_emptyItemPool.ReturnAll(false);
			for (int i = 0; i < XPartnerDocument.PartnerWelfareTab.Table.Length; i++)
			{
				PartnerWelfare.RowData rowData = XPartnerDocument.PartnerWelfareTab.Table[i];
				bool flag = rowData == null;
				if (!flag)
				{
					GameObject gameObject = this.m_emptyItemPool.FetchGameObject(false);
					gameObject.SetActive(true);
					gameObject.transform.localPosition = new Vector3(0f, (float)(-(float)i * this.m_emptyItemPool.TplHeight), 0f);
					IXUILabel ixuilabel = gameObject.transform.Find("Tip").GetComponent("XUILabel") as IXUILabel;
					ixuilabel.SetText(XSingleton<UiUtility>.singleton.ReplaceReturn(rowData.ContentTxt));
				}
			}
			this.m_ruleLab.SetText(XSingleton<UiUtility>.singleton.ReplaceReturn(XSingleton<XStringTable>.singleton.GetString("PartnerRule")));
			this.m_noPartnerTips.SetText(XSingleton<XStringTable>.singleton.GetString("NoPartnerTips"));
		}

		private void FillHadPartner()
		{
			this.m_obtainedGo.SetActive(true);
			this.m_shopBtn.gameObject.SetActive(true);
			this.RefreshUIRedPoint();
			Partner myParnerInfo = this.m_doc.GetMyParnerInfo();
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
			bool flag = myParnerInfo != null;
			if (flag)
			{
				bool is_apply_leave = myParnerInfo.Detail.is_apply_leave;
				if (is_apply_leave)
				{
					this.m_breakUpCutDownLab.gameObject.SetActive(true);
					this.m_breakUpCutDownLab.SetText(this.GetTimeString((ulong)myParnerInfo.Detail.left_leave_time, XSingleton<XStringTable>.singleton.GetString("BreakPartner")));
					this.m_breakupBtn.gameObject.SetActive(false);
					this.m_cancleBreakUpBtn.gameObject.SetActive(true);
					this.m_token = XSingleton<XTimerMgr>.singleton.SetTimer(5f, new XTimerMgr.ElapsedEventHandler(this.SetTime), myParnerInfo.Detail.left_leave_time);
				}
				else
				{
					this.m_breakUpCutDownLab.gameObject.SetActive(false);
					this.m_breakupBtn.gameObject.SetActive(true);
					this.m_cancleBreakUpBtn.gameObject.SetActive(false);
				}
			}
			IXUISlider ixuislider = this.m_livenessTra.Find("slider").GetComponent("XUISlider") as IXUISlider;
			IXUILabel ixuilabel = this.m_livenessTra.Find("slider/PLabel").GetComponent("XUILabel") as IXUILabel;
			float num = (this.m_doc.CurLevelMaxExp == 0f) ? 1u : this.m_doc.CurLevelMaxExp;
			ixuislider.Value = this.m_doc.Degree / num;
			ixuilabel.SetText(string.Format("{0}/{1}", this.m_doc.Degree, this.m_doc.CurLevelMaxExp));
			this.m_FriendBonusHandler.RefreshData();
			this.m_itemPool.ReturnAll(false);
			int num2 = 0;
			foreach (KeyValuePair<ulong, Partner> keyValuePair in this.m_doc.PartnerDic)
			{
				GameObject gameObject = this.m_itemPool.FetchGameObject(false);
				gameObject.SetActive(true);
				gameObject.transform.localPosition = new Vector3((float)(this.m_itemPool.TplWidth * num2), 0f, 0f);
				this.FillAvataItem(gameObject, keyValuePair.Value, num2);
				num2++;
			}
			base.Return3DAvatarPool();
			base.Alloc3DAvatarPool("PartnerMainHandler", 1);
			int i = this.m_doc.PartnerDic.Count;
			int num3 = this.m_Snapshots.Length;
			while (i < num3)
			{
				this.m_Snapshots[i] = null;
				i++;
			}
			this.RefreshAvataData();
		}

		private void FillAvataItem(GameObject go, Partner partner, int count)
		{
			bool flag = partner == null || go == null || partner.Detail == null;
			if (!flag)
			{
				IXUISprite ixuisprite = go.transform.Find("ProfIcon").GetComponent("XUISprite") as IXUISprite;
				ixuisprite.SetSprite(XSingleton<XProfessionSkillMgr>.singleton.GetProfIcon((int)((int)partner.Detail.profession % 10)));
				IXUILabel ixuilabel = go.transform.Find("Name").GetComponent("XUILabel") as IXUILabel;
				ixuilabel.SetText(partner.Detail.name);
				ixuilabel = (go.transform.Find("Level").GetComponent("XUILabel") as IXUILabel);
				ixuilabel.SetText(partner.Detail.level.ToString());
				ixuilabel = (go.transform.Find("Battlepoint").GetComponent("XUILabel") as IXUILabel);
				ixuilabel.SetText(partner.Detail.ppt.ToString());
				bool is_apply_leave = partner.Detail.is_apply_leave;
				if (is_apply_leave)
				{
					go.transform.Find("Breakup").gameObject.SetActive(true);
				}
				else
				{
					go.transform.Find("Breakup").gameObject.SetActive(false);
				}
				ixuisprite = (go.transform.Find("Bg/BgSmall").GetComponent("XUISprite") as IXUISprite);
				ixuisprite.ID = partner.MemberId;
				ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClickavata));
				this.m_Snapshots[count] = (go.transform.Find("Snapshot").GetComponent("UIDummy") as IUIDummy);
			}
		}

		private void RefreshAvataData()
		{
			int num = 0;
			foreach (KeyValuePair<ulong, Partner> keyValuePair in this.m_doc.PartnerDic)
			{
				bool flag = num >= XPartnerDocument.MaxAvata;
				if (flag)
				{
					break;
				}
				bool flag2 = this.m_Snapshots[num] != null;
				if (flag2)
				{
					XDummy xdummy = XSingleton<X3DAvatarMgr>.singleton.CreateCommonRoleDummy(this.m_dummPool, keyValuePair.Value.Detail.memberid, (uint)XFastEnumIntEqualityComparer<RoleType>.ToInt(keyValuePair.Value.Detail.profession), keyValuePair.Value.Detail.outlook, this.m_Snapshots[num], null);
					num++;
				}
			}
		}

		private string GetTimeString(ulong ti, string str)
		{
			bool flag = ti < 60UL;
			string result;
			if (flag)
			{
				string arg = string.Format("{0}{1}", ti, XStringDefineProxy.GetString("SECOND_DUARATION"));
				result = string.Format(str, arg);
			}
			else
			{
				ulong num = ti / 60UL;
				ulong num2 = ti % 60UL;
				bool flag2 = num < 60UL;
				string arg;
				if (flag2)
				{
					bool flag3 = num2 > 0UL;
					if (flag3)
					{
						arg = string.Format("{0}{1}{2}{3}", new object[]
						{
							num,
							XStringDefineProxy.GetString("MINUTE_DUARATION"),
							num2,
							XStringDefineProxy.GetString("SECOND_DUARATION")
						});
					}
					else
					{
						arg = string.Format("{0}{1}", num, XStringDefineProxy.GetString("MINUTE_DUARATION"));
					}
				}
				else
				{
					bool flag4 = num2 > 0UL;
					if (flag4)
					{
						num += 1UL;
					}
					ulong num3 = num / 60UL;
					num %= 60UL;
					bool flag5 = num > 0UL;
					if (flag5)
					{
						arg = string.Format("{0}{1}{2}{3}", new object[]
						{
							num3,
							XStringDefineProxy.GetString("HOUR_DUARATION"),
							num,
							XStringDefineProxy.GetString("MINUTE_DUARATION")
						});
					}
					else
					{
						arg = string.Format("{0}{1}", num3, XStringDefineProxy.GetString("HOUR_DUARATION"));
					}
				}
				result = string.Format(str, arg);
			}
			return result;
		}

		public void RefreshUIRedPoint()
		{
			this.m_shopBtn.gameObject.transform.Find("RedPoint").gameObject.SetActive(this.m_doc.IsHadShopRedPoint);
			this.m_livenessBtn.gameObject.transform.Find("RedPoint").gameObject.SetActive(this.m_doc.IsHadLivenessRedPoint);
		}

		public void SetTime(object o = null)
		{
			uint num = (uint)o;
			this.m_breakUpCutDownLab.SetText(this.GetTimeString((ulong)num, XSingleton<XStringTable>.singleton.GetString("BreakPartner")));
			bool flag = num == 0u;
			if (flag)
			{
				XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
			}
			num -= 1u;
			this.m_token = XSingleton<XTimerMgr>.singleton.SetTimer(1f, new XTimerMgr.ElapsedEventHandler(this.SetTime), num);
		}

		private bool OnClickShopBtn(IXUIButton btn)
		{
			bool flag = this.SetButtonCool(this.m_fCoolTime);
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				this.m_doc.IsHadShopRedPoint = false;
				DlgBase<MallSystemDlg, MallSystemBehaviour>.singleton.ShowShopSystem(XSysDefine.XSys_Mall_Partner, 0UL);
				result = true;
			}
			return result;
		}

		private bool OnClickGoToBtn(IXUIButton btn)
		{
			bool flag = this.SetButtonCool(this.m_fCoolTime);
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				XSingleton<UIManager>.singleton.CloseAllUI();
				uint num = 0u;
				XNpcInfo npcInfo = XSingleton<XEntityMgr>.singleton.NpcInfo;
				for (int i = 0; i < npcInfo.Table.Length; i++)
				{
					bool flag2 = npcInfo.Table[i].LinkSystem == 700;
					if (flag2)
					{
						num = npcInfo.Table[i].ID;
						break;
					}
				}
				bool flag3 = num == 0u;
				if (flag3)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("had not find partner npc", null, null, null, null, null);
					result = true;
				}
				else
				{
					XSingleton<XInput>.singleton.LastNpc = XSingleton<XEntityMgr>.singleton.GetNpc(num);
					result = true;
				}
			}
			return result;
		}

		private bool OnClickGoToTeamBtn(IXUIButton btn)
		{
			bool flag = this.SetButtonCool(this.m_fCoolTime);
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				XExpeditionDocument specificDocument = XDocuments.GetSpecificDocument<XExpeditionDocument>(XExpeditionDocument.uuID);
				List<ExpeditionTable.RowData> expeditionList = specificDocument.GetExpeditionList(TeamLevelType.TeamLevelPartner);
				bool flag2 = expeditionList != null && expeditionList.Count > 0;
				if (flag2)
				{
					XTeamDocument specificDocument2 = XDocuments.GetSpecificDocument<XTeamDocument>(XTeamDocument.uuID);
					specificDocument2.SetAndMatch(expeditionList[0].DNExpeditionID);
				}
				result = true;
			}
			return result;
		}

		private bool OnClickLivenessBtn(IXUIButton btn)
		{
			bool flag = this.SetButtonCool(this.m_fCoolTime);
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				DlgBase<PartnerLivenessDlg, PartnerLivenessBehaviour>.singleton.SetVisible(true, true);
				result = true;
			}
			return result;
		}

		private bool OnClickbreakupBtn(IXUIButton btn)
		{
			bool flag = this.SetButtonCool(this.m_fCoolTime);
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				Partner myParnerInfo = this.m_doc.GetMyParnerInfo();
				bool flag2 = myParnerInfo == null;
				if (flag2)
				{
					result = true;
				}
				else
				{
					bool is_apply_leave = myParnerInfo.Detail.is_apply_leave;
					if (is_apply_leave)
					{
						XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("IsLeavingPartner"), "fece00");
						result = true;
					}
					else
					{
						XSingleton<UiUtility>.singleton.ShowModalDialog(XStringDefineProxy.GetString("SureBreakUpPartner"), XStringDefineProxy.GetString("COMMON_OK"), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this.BreakUp));
						result = true;
					}
				}
			}
			return result;
		}

		private bool BreakUp(IXUIButton btn)
		{
			this.m_doc.ReqLeavePartner();
			XSingleton<UiUtility>.singleton.CloseModalDlg();
			return true;
		}

		private bool OnClickCancleBreakupBtn(IXUIButton btn)
		{
			bool flag = this.SetButtonCool(this.m_fCoolTime);
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				Partner myParnerInfo = this.m_doc.GetMyParnerInfo();
				bool flag2 = myParnerInfo == null;
				if (flag2)
				{
					result = true;
				}
				else
				{
					bool flag3 = !myParnerInfo.Detail.is_apply_leave;
					if (flag3)
					{
						result = true;
					}
					else
					{
						this.m_doc.ReqCancleLeavePartner();
						result = true;
					}
				}
			}
			return result;
		}

		private void OnClickavata(IXUISprite sp)
		{
			bool flag = sp == null;
			if (!flag)
			{
				ulong id = sp.ID;
				XCharacterCommonMenuDocument.ReqCharacterMenuInfo(id, false);
			}
		}

		private bool SetButtonCool(float time)
		{
			float num = Time.realtimeSinceStartup - this.m_fLastClickBtnTime;
			bool flag = num < time;
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				this.m_fLastClickBtnTime = Time.realtimeSinceStartup;
				result = false;
			}
			return result;
		}
	}
}