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

namespace XMainClient.UI
{
	internal class FrozenSealHandler : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "OperatingActivity/CrushingSeal";
			}
		}

		protected XUIPool _frozenSealPool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		protected XUIPool _rewardPool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		protected Dictionary<ulong, Transform> _itemsDic = new Dictionary<ulong, Transform>();

		protected List<FrozenSealHandler.FrozenSealSortData> _sortList = new List<FrozenSealHandler.FrozenSealSortData>();

		protected uint curActid = 0u;

		protected IXUIScrollView _scrollview;

		protected IXUILabel _timeLabel;

		public class FrozenSealSortData
		{
			public ulong id = 0UL;

			public FrozenSealState state = FrozenSealState.None;
		}

		protected override void Init()
		{
			base.Init();
			this.curActid = XOperatingActivityDocument.Doc.CurSealActID;
			bool flag = this.curActid > 0u;
			if (flag)
			{
				this.InitUIPool();
				this.InitScrollView();
			}
		}

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

		protected override void OnShow()
		{
			base.OnShow();
			uint num = this.curActid;
			this.curActid = XOperatingActivityDocument.Doc.CurSealActID;
			bool flag = num > 0u && this.curActid != num;
			if (flag)
			{
				this.Clear();
				this.InitScrollView();
			}
			bool flag2 = this.curActid > 0u;
			if (flag2)
			{
				this.RefreshAllItem();
			}
		}

		protected bool OnFetch(IXUIButton btn)
		{
			RpcC2G_GetSpActivityReward rpcC2G_GetSpActivityReward = new RpcC2G_GetSpActivityReward();
			rpcC2G_GetSpActivityReward.oArg.actid = this.curActid;
			rpcC2G_GetSpActivityReward.oArg.taskid = (uint)btn.ID;
			XSingleton<XClientNetwork>.singleton.Send(rpcC2G_GetSpActivityReward);
			return true;
		}

		protected bool OnJump(IXUIButton btn)
		{
			uint num = (uint)btn.ID;
			List<SuperActivityTask.RowData> sealDatas = XOperatingActivityDocument.Doc.SealDatas;
			for (int i = 0; i < sealDatas.Count; i++)
			{
				bool flag = sealDatas[i].taskid == num;
				if (flag)
				{
					SuperActivityTask.RowData rowData = sealDatas[i];
					bool flag2 = rowData.arg != null && rowData.arg.Length != 0;
					if (flag2)
					{
						bool flag3 = rowData.arg[0] == 1;
						if (flag3)
						{
							DlgBase<DungeonSelect, DungeonSelectBehaviour>.singleton.SelectChapter(rowData.arg[1], (uint)rowData.arg[2]);
						}
						else
						{
							bool flag4 = rowData.arg[0] == 2;
							if (flag4)
							{
								DlgBase<TheExpView, TheExpBehaviour>.singleton.ShowView(rowData.arg[1]);
							}
						}
					}
					else
					{
						XSingleton<XGameSysMgr>.singleton.OpenSystem((int)rowData.jump);
					}
					return true;
				}
			}
			return false;
		}

		protected void InitItemInfo(Transform item, SuperActivityTask.RowData data)
		{
			IXUILabel ixuilabel = item.Find("Name").GetComponent("XUILabel") as IXUILabel;
			ixuilabel.SetText(data.title);
			Transform transform = item.Find("Fetch");
			IXUIButton ixuibutton = transform.GetComponent("XUIButton") as IXUIButton;
			ixuibutton.ID = (ulong)data.taskid;
			ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnFetch));
			Transform transform2 = item.Find("Go");
			IXUIButton ixuibutton2 = transform2.GetComponent("XUIButton") as IXUIButton;
			ixuibutton2.ID = (ulong)data.taskid;
			ixuibutton2.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnJump));
			IXUILabel ixuilabel2 = item.Find("Go/Tip").GetComponent("XUILabel") as IXUILabel;
			IXUILabel ixuilabel3 = item.Find("Go/LinkTo").GetComponent("XUILabel") as IXUILabel;
			transform.gameObject.SetActive(false);
			bool flag = data.jump > 0u;
			if (flag)
			{
				this._sortList.Add(new FrozenSealHandler.FrozenSealSortData
				{
					id = (ulong)data.taskid,
					state = FrozenSealState.LeaveFor
				});
				ixuilabel2.gameObject.SetActive(true);
				ixuilabel3.gameObject.SetActive(false);
			}
			else
			{
				this._sortList.Add(new FrozenSealHandler.FrozenSealSortData
				{
					id = (ulong)data.taskid,
					state = FrozenSealState.UnFinish
				});
				ixuibutton2.SetEnable(false, false);
				ixuilabel3.gameObject.SetActive(true);
				ixuilabel2.gameObject.SetActive(false);
			}
			item.Find("Fetched").gameObject.SetActive(false);
			Transform parent = item.Find("ItemReward");
			for (int i = 0; i < data.items.Count; i++)
			{
				GameObject gameObject = this._rewardPool.FetchGameObject(false);
				gameObject.transform.parent = parent;
				gameObject.transform.localPosition = new Vector3((float)(this._rewardPool.TplWidth * i), 0f, 0f);
				uint num = data.items[i, 0];
				XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(gameObject, (int)num, (int)data.items[i, 1], false);
				IXUISprite ixuisprite = gameObject.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
				ixuisprite.ID = (ulong)num;
				ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(XSingleton<UiUtility>.singleton.OnItemClick));
			}
		}

		protected void RefreshItemState(uint taskid, ActivityTaskState state)
		{
			Transform parent = null;
			bool flag = this._itemsDic.TryGetValue((ulong)taskid, out parent);
			if (flag)
			{
				Transform childByName = this.GetChildByName(parent, "Fetch");
				Transform childByName2 = this.GetChildByName(parent, "Go");
				Transform childByName3 = this.GetChildByName(parent, "Fetched");
				bool flag2 = state == ActivityTaskState.Uncomplete;
				if (!flag2)
				{
					bool flag3 = state == ActivityTaskState.Complete;
					if (flag3)
					{
						childByName2.gameObject.SetActive(false);
						childByName.gameObject.SetActive(true);
					}
					else
					{
						bool flag4 = state == ActivityTaskState.Fetched;
						if (flag4)
						{
							childByName.gameObject.SetActive(false);
							childByName2.gameObject.SetActive(false);
							childByName3.gameObject.SetActive(true);
						}
					}
				}
			}
		}

		protected void UpdateItemState(uint taskid, ActivityTaskState state)
		{
			for (int i = 0; i < this._sortList.Count; i++)
			{
				bool flag = this._sortList[i].id == (ulong)taskid;
				if (flag)
				{
					bool flag2 = state == ActivityTaskState.Complete;
					if (flag2)
					{
						this._sortList[i].state = FrozenSealState.CanFetch;
					}
					else
					{
						bool flag3 = state == ActivityTaskState.Fetched;
						if (flag3)
						{
							this._sortList[i].state = FrozenSealState.Fetched;
						}
					}
				}
			}
		}

		protected FrozenSealState GetFrozenSealStateById(ulong id)
		{
			return FrozenSealState.CanFetch;
		}

		protected Transform GetChildByName(Transform parent, string name)
		{
			foreach (object obj in parent)
			{
				Transform transform = (Transform)obj;
				bool flag = transform.name.Equals(name);
				if (flag)
				{
					return transform;
				}
			}
			XSingleton<XDebug>.singleton.AddErrorLog("wrong child name", null, null, null, null, null);
			return null;
		}

		protected void RefreshAllItem()
		{
			this.UpdateTime();
			this.RefreshAllStates();
			this.SortListItems();
			this._scrollview.SetPosition(0f);
		}

		public void UpdateTime()
		{
			int remainDays = XTempActivityDocument.Doc.GetRemainDays(this.curActid);
			bool flag = remainDays == 1;
			if (flag)
			{
				this._timeLabel.SetText(XStringDefineProxy.GetString("CarnivalLast"));
			}
			else
			{
				this._timeLabel.SetText(XStringDefineProxy.GetString("CarnivalEnd", new object[]
				{
					remainDays
				}));
			}
		}

		protected void UpdateStates()
		{
			for (int i = 0; i < XOperatingActivityDocument.Doc.SealDatas.Count; i++)
			{
				SuperActivityTask.RowData rowData = XOperatingActivityDocument.Doc.SealDatas[i];
				FrozenSealHandler.FrozenSealSortData frozenSealSortData = this._sortList[i];
				uint activityState = XTempActivityDocument.Doc.GetActivityState(this.curActid, rowData.taskid);
				bool flag = activityState == 1u;
				if (flag)
				{
					frozenSealSortData.state = FrozenSealState.CanFetch;
				}
				else
				{
					bool flag2 = activityState == 2u;
					if (flag2)
					{
						frozenSealSortData.state = FrozenSealState.Fetched;
					}
				}
			}
		}

		protected void RefreshAllStates()
		{
			List<SuperActivityTask.RowData> sealDatas = XOperatingActivityDocument.Doc.SealDatas;
			for (int i = 0; i < sealDatas.Count; i++)
			{
				uint activityState = XTempActivityDocument.Doc.GetActivityState(this.curActid, sealDatas[i].taskid);
				this.RefreshItemState(sealDatas[i].taskid, (ActivityTaskState)activityState);
				this.UpdateItemState(sealDatas[i].taskid, (ActivityTaskState)activityState);
			}
		}

		protected int SortItemList(FrozenSealHandler.FrozenSealSortData x1, FrozenSealHandler.FrozenSealSortData x2)
		{
			int num = (x1.state.CompareTo(x2.state) == 0) ? x1.id.CompareTo(x2.id) : x1.state.CompareTo(x2.state);
			return -num;
		}

		public void SortListItems()
		{
			this._sortList.Sort(new Comparison<FrozenSealHandler.FrozenSealSortData>(this.SortItemList));
			for (int i = 0; i < this._sortList.Count; i++)
			{
				this._itemsDic[this._sortList[i].id].name = i.ToString("D2");
				this._itemsDic[this._sortList[i].id].localPosition = new Vector3(this._frozenSealPool.TplPos.x, this._frozenSealPool.TplPos.y - (float)(this._frozenSealPool.TplHeight * i), 0f);
			}
		}

		public void InitScrollView()
		{
			this._scrollview = (base.transform.Find("Scrollview").GetComponent("XUIScrollView") as IXUIScrollView);
			this._timeLabel = (base.transform.Find("CountDown/Time").GetComponent("XUILabel") as IXUILabel);
			this._frozenSealPool.ReturnAll(false);
			this._rewardPool.ReturnAll(false);
			this._scrollview.SetPosition(0f);
			List<SuperActivityTask.RowData> sealDatas = XOperatingActivityDocument.Doc.SealDatas;
			for (int i = 0; i < sealDatas.Count; i++)
			{
				GameObject gameObject = this._frozenSealPool.FetchGameObject(false);
				this.InitItemInfo(gameObject.transform, sealDatas[i]);
				this._itemsDic.Add((ulong)sealDatas[i].taskid, gameObject.transform);
				gameObject.transform.localPosition = new Vector3(this._frozenSealPool.TplPos.x, this._frozenSealPool.TplPos.y - (float)(this._frozenSealPool.TplHeight * i), 0f);
			}
		}

		public void RefreshItemWithTaskidAndState(uint taskId, ActivityTaskState state)
		{
			this.UpdateItemState(taskId, state);
			this.RefreshItemState(taskId, state);
			this.SortListItems();
		}

		public void Clear()
		{
			this._itemsDic.Clear();
			this._sortList.Clear();
			this._rewardPool.ReturnAll(false);
			this._frozenSealPool.ReturnAll(false);
		}

		private void InitUIPool()
		{
			Transform transform = base.transform.Find("Scrollview/FirstPassFsItem");
			this._frozenSealPool.SetupPool(transform.parent.gameObject, transform.gameObject, 3u, false);
			Transform transform2 = base.transform.Find("Scrollview/ItemTpl");
			this._rewardPool.SetupPool(base.transform.gameObject, transform2.gameObject, 2u, false);
		}
	}
}