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

namespace XMainClient
{
	internal class XPKInvitationView : DlgBase<XPKInvitationView, XPKInvitationBehaviour>
	{
		public override string fileName
		{
			get
			{
				return "GameSystem/pkdlg";
			}
		}

		public override bool autoload
		{
			get
			{
				return true;
			}
		}

		private XPKInvitationDocument _Doc;

		private uint _CDToken = 0u;

		private List<IXUILabel> m_TimeLabelList = new List<IXUILabel>();

		private List<ulong> m_TimeInvID = new List<ulong>();

		private Dictionary<ulong, uint> m_TimeDic = new Dictionary<ulong, uint>();

		protected override void Init()
		{
			base.Init();
			this._Doc = XDocuments.GetSpecificDocument<XPKInvitationDocument>(XPKInvitationDocument.uuID);
		}

		protected override void OnHide()
		{
			base.OnHide();
			XSingleton<XTimerMgr>.singleton.KillTimer(this._CDToken);
			bool flag = false;
			for (int i = 0; i < this._Doc.AllInvitation.Count; i++)
			{
				bool flag2 = this._Doc.AllInvitation[i].ctime > 0u;
				if (flag2)
				{
					flag = true;
					break;
				}
			}
			bool flag3 = !flag;
			if (flag3)
			{
				this._Doc.InvitationCount = 0u;
			}
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			base.uiBehaviour.m_Close.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnCloseBtnClicked));
			base.uiBehaviour.m_WrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this.OnWrapContentUpdate));
			base.uiBehaviour.m_IgnoreAll.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnIgnoreAllClicked));
			base.uiBehaviour.m_Help.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnHelpBtnClicked));
		}

		protected override void OnShow()
		{
			base.OnShow();
			base.uiBehaviour.m_WrapContent.SetVisible(false);
			this.m_TimeLabelList.Clear();
			this.m_TimeInvID.Clear();
			this.m_TimeDic.Clear();
			this._Doc.ReqAllPKInvitation();
		}

		public void StartTimer()
		{
			bool flag = !base.IsVisible();
			if (!flag)
			{
				for (int i = 0; i < this._Doc.AllInvitation.Count; i++)
				{
					this.m_TimeDic[this._Doc.AllInvitation[i].invID] = this._Doc.AllInvitation[i].ctime;
				}
				XSingleton<XTimerMgr>.singleton.KillTimer(this._CDToken);
				this._CDToken = XSingleton<XTimerMgr>.singleton.SetTimer(1f, new XTimerMgr.ElapsedEventHandler(this.LeftTimeUpdate), null);
			}
		}

		private void LeftTimeUpdate(object o)
		{
			for (int i = 0; i < this._Doc.AllInvitation.Count; i++)
			{
				bool flag = this._Doc.AllInvitation[i].ctime > 0u;
				if (flag)
				{
					InvFightRoleBrief invFightRoleBrief = this._Doc.AllInvitation[i];
					uint ctime = invFightRoleBrief.ctime;
					invFightRoleBrief.ctime = ctime - 1u;
				}
				this.m_TimeDic[this._Doc.AllInvitation[i].invID] = this._Doc.AllInvitation[i].ctime;
				int num = this.m_TimeInvID.IndexOf(this._Doc.AllInvitation[i].invID);
				bool flag2 = num >= 0 && num < this.m_TimeLabelList.Count;
				if (flag2)
				{
					IXUILabel ixuilabel = this.m_TimeLabelList[num];
					bool flag3 = ixuilabel.IsVisible();
					if (flag3)
					{
						bool flag4 = this._Doc.AllInvitation[i].ctime > 0u;
						if (flag4)
						{
							ixuilabel.SetText(string.Format("{0}{1}", this._Doc.AllInvitation[i].ctime, XSingleton<XStringTable>.singleton.GetString("SECOND_DUARATION")));
						}
						else
						{
							ixuilabel.SetText(XSingleton<XStringTable>.singleton.GetString("PK_TIME_END"));
						}
					}
				}
			}
			XSingleton<XTimerMgr>.singleton.KillTimer(this._CDToken);
			this._CDToken = XSingleton<XTimerMgr>.singleton.SetTimer(1f, new XTimerMgr.ElapsedEventHandler(this.LeftTimeUpdate), null);
		}

		public void RefreshList()
		{
			bool flag = !base.IsVisible();
			if (!flag)
			{
				base.uiBehaviour.m_WrapContent.SetVisible(true);
				base.uiBehaviour.m_WrapContent.SetContentCount(this._Doc.AllInvitation.Count, false);
			}
		}

		private void OnWrapContentUpdate(Transform t, int index)
		{
			List<InvFightRoleBrief> allInvitation = this._Doc.AllInvitation;
			bool flag = index >= allInvitation.Count;
			if (!flag)
			{
				this.SetInvitationInfo(t, allInvitation[index]);
			}
		}

		private void SetInvitationInfo(Transform t, InvFightRoleBrief info)
		{
			bool flag = info == null;
			if (!flag)
			{
				IXUISprite ixuisprite = t.Find("head").GetComponent("XUISprite") as IXUISprite;
				IXUILabelSymbol ixuilabelSymbol = t.Find("Name").GetComponent("XUILabelSymbol") as IXUILabelSymbol;
				IXUILabel ixuilabel = t.Find("Level").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel2 = t.Find("Position").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel3 = t.Find("time").GetComponent("XUILabel") as IXUILabel;
				IXUIButton ixuibutton = t.Find("yesBtn").GetComponent("XUIButton") as IXUIButton;
				IXUIButton ixuibutton2 = t.Find("noBtn").GetComponent("XUIButton") as IXUIButton;
				GameObject gameObject = t.Find("qqLaunch").gameObject;
				GameObject gameObject2 = t.Find("wxLaunch").gameObject;
				ixuisprite.SetSprite(XSingleton<XProfessionSkillMgr>.singleton.GetProfHeadIcon2((int)info.profession));
				ixuilabelSymbol.InputText = XTitleDocument.GetTitleWithFormat(info.title, info.name);
				ixuilabel.SetText(info.level.ToString());
				ixuilabel2.SetText(XSingleton<XProfessionSkillMgr>.singleton.GetProfName((int)info.profession));
				gameObject.SetActive(XSingleton<XLoginDocument>.singleton.Channel == XAuthorizationChannel.XAuthorization_QQ && info.isplatfriend);
				gameObject2.SetActive(XSingleton<XLoginDocument>.singleton.Channel == XAuthorizationChannel.XAuthorization_WeChat && info.isplatfriend);
				ixuibutton.ID = info.invID;
				ixuibutton2.ID = info.invID;
				ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnAcceptBtnClicked));
				ixuibutton2.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnRejectBtnClicked));
				int num = this.m_TimeLabelList.IndexOf(ixuilabel3);
				bool flag2 = num >= 0 && num < this.m_TimeInvID.Count;
				if (flag2)
				{
					this.m_TimeInvID[num] = info.invID;
				}
				else
				{
					this.m_TimeLabelList.Add(ixuilabel3);
					this.m_TimeInvID.Add(info.invID);
				}
				uint num2;
				bool flag3 = this.m_TimeDic.TryGetValue(info.invID, out num2);
				if (flag3)
				{
					bool flag4 = num2 > 0u;
					if (flag4)
					{
						ixuilabel3.SetText(string.Format("{0}{1}", num2, XSingleton<XStringTable>.singleton.GetString("SECOND_DUARATION")));
					}
					else
					{
						ixuilabel3.SetText(XSingleton<XStringTable>.singleton.GetString("PK_TIME_END"));
					}
				}
			}
		}

		private bool OnAcceptBtnClicked(IXUIButton btn)
		{
			uint num;
			bool flag = this.m_TimeDic.TryGetValue(btn.ID, out num);
			if (flag)
			{
				bool flag2 = num > 0u;
				if (flag2)
				{
					this._Doc.AcceptInvitation(btn.ID);
				}
				else
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XSingleton<XStringTable>.singleton.GetString("PK_TIME_END_TIP"), "fece00");
				}
			}
			return true;
		}

		private bool OnRejectBtnClicked(IXUIButton btn)
		{
			this._Doc.RejectInvitation(btn.ID);
			return true;
		}

		private bool OnIgnoreAllClicked(IXUIButton btn)
		{
			this._Doc.IgnoreAllInvitation();
			return true;
		}

		private bool OnHelpBtnClicked(IXUIButton btn)
		{
			DlgBase<XCommonHelpTipView, XCommonHelpTipBehaviour>.singleton.ShowHelp(XSysDefine.XSys_PK);
			return true;
		}

		private bool OnCloseBtnClicked(IXUIButton btn)
		{
			this.SetVisibleWithAnimation(false, null);
			return true;
		}
	}
}