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

namespace XMainClient.UI
{
	internal class XSceneDamageRankHandler : DlgHandlerBase, IRankView
	{
		private XSceneDamageRankDocument doc;

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

		private List<GameObject> m_RankList = new List<GameObject>();

		private bool m_bShow = false;

		private uint m_AutoCloseTimerToken = 0u;

		private uint m_AutoReqDataTimerToken = 0u;

		private ulong[] cacheRoleids;

		private int[] cacheStates;

		protected override void Init()
		{
			base.Init();
			this.doc = XDocuments.GetSpecificDocument<XSceneDamageRankDocument>(XSceneDamageRankDocument.uuID);
			this.doc.RankHandler = this;
			Transform transform = base.PanelObject.transform.Find("RankTpl");
			this.m_RankPool.SetupPool(transform.parent.gameObject, transform.gameObject, 2u, false);
		}

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

		public override void OnUnload()
		{
			this.doc.RankHandler = null;
			this._ClearAutoClose();
			base.OnUnload();
		}

		protected override void OnShow()
		{
			base.OnShow();
			this.m_bShow = true;
			SceneTable.RowData sceneData = XSingleton<XSceneMgr>.singleton.GetSceneData(XSingleton<XScene>.singleton.SceneID);
			SceneType type = (SceneType)sceneData.type;
			if (type <= SceneType.SCENE_HEROBATTLE)
			{
				if (type == SceneType.SCENE_PVP)
				{
					XBattleCaptainPVPDocument specificDocument = XDocuments.GetSpecificDocument<XBattleCaptainPVPDocument>(XBattleCaptainPVPDocument.uuID);
					this.doc.OnGetRank(specificDocument.RankList);
					return;
				}
				if (type == SceneType.SCENE_HEROBATTLE)
				{
					XHeroBattleDocument specificDocument2 = XDocuments.GetSpecificDocument<XHeroBattleDocument>(XHeroBattleDocument.uuID);
					this.doc.OnGetRank(specificDocument2.RankList);
					return;
				}
			}
			else if (type - SceneType.SCENE_WEEKEND4V4_MONSTERFIGHT <= 4 || type == SceneType.SCENE_WEEKEND4V4_DUCK)
			{
				this.RefreshWeekendPartRank();
				return;
			}
			this._AutoReqData(null);
		}

		protected override void OnHide()
		{
			this.m_bShow = false;
			this._ClearAutoClose();
			this._ClearAutoReqData();
			base.OnHide();
		}

		public void RefreshPage()
		{
			List<XBaseRankInfo> rankList = this.doc.RankList;
			bool flag = rankList.Count > this.m_RankList.Count;
			if (flag)
			{
				for (int i = this.m_RankList.Count; i < rankList.Count; i++)
				{
					GameObject gameObject = this.m_RankPool.FetchGameObject(false);
					gameObject.transform.localPosition = new Vector3(this.m_RankPool.TplPos.x, this.m_RankPool.TplPos.y - (float)(this.m_RankPool.TplHeight * i), this.m_RankPool.TplPos.z);
					this.m_RankList.Add(gameObject);
					IXUILabel ixuilabel = gameObject.transform.Find("Rank").GetComponent("XUILabel") as IXUILabel;
					ixuilabel.SetText(string.Format("{0}.", i + 1));
					bool bSpectator = XSingleton<XScene>.singleton.bSpectator;
					if (bSpectator)
					{
						IXUICheckBox ixuicheckBox = gameObject.GetComponent("XUICheckBox") as IXUICheckBox;
						ixuicheckBox.ID = (ulong)((long)i);
						ixuicheckBox.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnSpectateChangeClick));
					}
				}
			}
			else
			{
				bool flag2 = rankList.Count < this.m_RankList.Count;
				if (flag2)
				{
					for (int j = this.m_RankList.Count - 1; j >= rankList.Count; j--)
					{
						this.m_RankPool.ReturnInstance(this.m_RankList[j], false);
					}
					this.m_RankList.RemoveRange(rankList.Count, this.m_RankList.Count - rankList.Count);
				}
			}
			for (int k = 0; k < rankList.Count; k++)
			{
				GameObject gameObject2 = this.m_RankList[k];
				bool bSpectator2 = XSingleton<XScene>.singleton.bSpectator;
				if (bSpectator2)
				{
					IXUICheckBox ixuicheckBox2 = gameObject2.GetComponent("XUICheckBox") as IXUICheckBox;
					bool flag3 = XSingleton<XEntityMgr>.singleton.Player != null && XSingleton<XEntityMgr>.singleton.Player.WatchTo != null && rankList[k].id == XSingleton<XEntityMgr>.singleton.Player.WatchTo.ID;
					if (flag3)
					{
						ixuicheckBox2.ForceSetFlag(true);
					}
					else
					{
						ixuicheckBox2.ForceSetFlag(false);
					}
				}
				IXUILabel ixuilabel2 = gameObject2.transform.Find("Name").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel3 = gameObject2.transform.Find("Value").GetComponent("XUILabel") as IXUILabel;
				ixuilabel2.SetText(rankList[k].name);
				XCaptainPVPRankInfo xcaptainPVPRankInfo = rankList[k] as XCaptainPVPRankInfo;
				bool flag4 = xcaptainPVPRankInfo != null;
				if (flag4)
				{
					ixuilabel3.SetText(rankList[k].GetValue());
				}
				else
				{
					ixuilabel3.SetText(XSingleton<UiUtility>.singleton.NumberFormat(rankList[k].value));
				}
			}
			this.HideVoice();
		}

		private void _AutoReqData(object o)
		{
			this.doc.ReqRank();
			bool bShow = this.m_bShow;
			if (bShow)
			{
				this.m_AutoReqDataTimerToken = XSingleton<XTimerMgr>.singleton.SetTimer(2f, new XTimerMgr.ElapsedEventHandler(this._AutoReqData), null);
			}
		}

		private void _ClearAutoClose()
		{
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_AutoCloseTimerToken);
		}

		private void _ClearAutoReqData()
		{
			this.m_AutoReqDataTimerToken = 0u;
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_AutoReqDataTimerToken);
		}

		private bool OnSpectateChangeClick(IXUICheckBox checkBox)
		{
			bool flag = !checkBox.bChecked;
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				ulong id = this.doc.RankList[(int)checkBox.ID].id;
				bool flag2 = XSingleton<XEntityMgr>.singleton.Player != null && XSingleton<XEntityMgr>.singleton.Player.WatchTo != null && id == XSingleton<XEntityMgr>.singleton.Player.WatchTo.ID;
				if (flag2)
				{
					result = true;
				}
				else
				{
					XEntity entityConsiderDeath = XSingleton<XEntityMgr>.singleton.GetEntityConsiderDeath(id);
					bool flag3 = entityConsiderDeath != null && entityConsiderDeath.IsRole;
					if (flag3)
					{
						XSingleton<XEntityMgr>.singleton.Player.WatchIt(entityConsiderDeath as XRole);
					}
					result = true;
				}
			}
			return result;
		}

		public void RefreshVoice(ulong[] roleids, int[] states)
		{
			bool flag = DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded();
			if (flag)
			{
				this.cacheRoleids = roleids;
				this.cacheStates = states;
				bool flag2 = roleids == null || states == null;
				if (!flag2)
				{
					for (int i = 0; i < roleids.Length; i++)
					{
						this.PlayRole(roleids[i], states[i]);
					}
				}
			}
		}

		public void PlayRole(ulong roleid, int state)
		{
			for (int i = 0; i < this.doc.RankList.Count; i++)
			{
				bool flag = this.doc.RankList[i].id == roleid && this.m_RankList.Count > i;
				if (flag)
				{
					Transform transform = this.m_RankList[i].transform.Find("voice");
					bool flag2 = transform != null;
					if (flag2)
					{
						transform.gameObject.SetActive(state == 1);
					}
					Transform transform2 = this.m_RankList[i].transform.Find("speak");
					bool flag3 = transform2 != null;
					if (flag3)
					{
						transform2.gameObject.SetActive(state == 2);
					}
				}
			}
		}

		public void HideVoice()
		{
			bool flag = DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded();
			if (flag)
			{
				for (int i = 0; i < this.m_RankList.Count; i++)
				{
					Transform transform = this.m_RankList[i].transform.Find("voice");
					Transform transform2 = this.m_RankList[i].transform.Find("speak");
					bool flag2 = transform.gameObject.activeSelf && transform2.gameObject.activeSelf;
					if (flag2)
					{
						transform.gameObject.SetActive(false);
						transform2.gameObject.SetActive(false);
					}
				}
				this.RefreshVoice(this.cacheRoleids, this.cacheStates);
			}
		}

		public void RefreshWeekendPartRank()
		{
			XWeekendPartyDocument specificDocument = XDocuments.GetSpecificDocument<XWeekendPartyDocument>(XWeekendPartyDocument.uuID);
			List<WeekendPartyBattleRoleInfo> selfWeekendPartyBattleList = specificDocument.SelfWeekendPartyBattleList;
			bool flag = selfWeekendPartyBattleList.Count > this.m_RankList.Count;
			if (flag)
			{
				for (int i = this.m_RankList.Count; i < selfWeekendPartyBattleList.Count; i++)
				{
					GameObject gameObject = this.m_RankPool.FetchGameObject(false);
					gameObject.transform.localPosition = new Vector3(this.m_RankPool.TplPos.x, this.m_RankPool.TplPos.y - (float)(this.m_RankPool.TplHeight * i), this.m_RankPool.TplPos.z);
					this.m_RankList.Add(gameObject);
				}
			}
			else
			{
				bool flag2 = selfWeekendPartyBattleList.Count < this.m_RankList.Count;
				if (flag2)
				{
					for (int j = this.m_RankList.Count - 1; j >= selfWeekendPartyBattleList.Count; j--)
					{
						this.m_RankPool.ReturnInstance(this.m_RankList[j], false);
					}
					this.m_RankList.RemoveRange(selfWeekendPartyBattleList.Count, this.m_RankList.Count - selfWeekendPartyBattleList.Count);
				}
			}
			for (int k = 0; k < selfWeekendPartyBattleList.Count; k++)
			{
				GameObject gameObject2 = this.m_RankList[k];
				IXUILabel ixuilabel = gameObject2.transform.Find("Rank").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel2 = gameObject2.transform.Find("Name").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel3 = gameObject2.transform.Find("Value").GetComponent("XUILabel") as IXUILabel;
				ixuilabel.SetText(string.Format("{0}.", selfWeekendPartyBattleList[k].Rank));
				ixuilabel2.SetText((selfWeekendPartyBattleList[k].roleName != null) ? selfWeekendPartyBattleList[k].roleName : "");
				string arg = (XSingleton<XScene>.singleton.SceneType == SceneType.SCENE_WEEKEND4V4_CRAZYBOMB || XSingleton<XScene>.singleton.SceneType == SceneType.SCENE_WEEKEND4V4_LIVECHALLENGE) ? XStringDefineProxy.GetString("WeekendPartyBattleRankTypeDeath") : XStringDefineProxy.GetString("WeekendPartyBattleRankTypeScore");
				uint num = (XSingleton<XScene>.singleton.SceneType == SceneType.SCENE_WEEKEND4V4_CRAZYBOMB || XSingleton<XScene>.singleton.SceneType == SceneType.SCENE_WEEKEND4V4_LIVECHALLENGE) ? selfWeekendPartyBattleList[k].beKilled : selfWeekendPartyBattleList[k].score;
				ixuilabel3.SetText(string.Format("{0}{1}", arg, num));
			}
			this.HideVoice();
		}
	}
}