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

namespace XMainClient.UI
{
	internal class DragonGuildLivenessDlg : DlgBase<DragonGuildLivenessDlg, DragonGuildLivenessBehaviour>
	{
		public override string fileName
		{
			get
			{
				return "DungeonTroop/DungeonTroopLiveness";
			}
		}

		public override int layer
		{
			get
			{
				return 1;
			}
		}

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

		public override bool fullscreenui
		{
			get
			{
				return false;
			}
		}

		private static readonly uint m_expIncreaseSpeed = 800u;

		private XDragonGuildDocument m_doc = XDragonGuildDocument.Doc;

		private List<DragonGuildLivenessTable.RowData> m_dragonguildLivenessRow;

		private int m_CurSelectIndex = 0;

		private float m_CoolTime = 0.5f;

		private float m_LastClickTime = 0f;

		protected override void Init()
		{
			XDragonGuildDocument.DragonGuildLivenessData.View = this;
			GameObject tpl = base.uiBehaviour.m_loopScrool.GetTpl();
			bool flag = tpl != null && tpl.GetComponent<DragonGuildLivenessRecordItem>() == null;
			if (flag)
			{
				tpl.AddComponent<DragonGuildLivenessRecordItem>();
			}
			base.uiBehaviour.m_Progress.IncreaseSpeed = DragonGuildLivenessDlg.m_expIncreaseSpeed;
			this.m_dragonguildLivenessRow = null;
			XDragonGuildDocument.DragonGuildLivenessData.GetDragonGuildLivenessRowsByLevel(this.m_doc.BaseData.level, out this.m_dragonguildLivenessRow);
			for (int i = 0; i < this.m_dragonguildLivenessRow.Count; i++)
			{
				GameObject chest = base.uiBehaviour.m_ChestPool.FetchGameObject(false);
				XChest chest2 = new XChest(chest, this.m_dragonguildLivenessRow[i].boxPic);
				base.uiBehaviour.m_Progress.AddChest(chest2);
			}
			this.ChangeChestProgressState(true);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			base.uiBehaviour.m_closedSpr.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClosed));
			this.m_dragonguildLivenessRow = null;
			XDragonGuildDocument.DragonGuildLivenessData.GetDragonGuildLivenessRowsByLevel(this.m_doc.BaseData.level, out this.m_dragonguildLivenessRow);
			for (int i = 0; i < this.m_dragonguildLivenessRow.Count; i++)
			{
				base.uiBehaviour.m_Progress.ChestList[i].m_Chest.ID = (ulong)((long)i);
				base.uiBehaviour.m_Progress.ChestList[i].m_Chest.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnChestClicked));
			}
		}

		protected override void OnShow()
		{
			XDragonGuildDocument.DragonGuildLivenessData.ReqDragonGuildLivenessInfo();
			bool flag = DlgBase<MallSystemDlg, MallSystemBehaviour>.singleton.IsVisible();
			if (flag)
			{
				DlgBase<MallSystemDlg, MallSystemBehaviour>.singleton.SetRelatedDlg(this);
			}
		}

		protected override void OnHide()
		{
			base.OnHide();
			bool flag = DlgBase<MallSystemDlg, MallSystemBehaviour>.singleton.IsVisible();
			if (flag)
			{
				DlgBase<MallSystemDlg, MallSystemBehaviour>.singleton.SetRelatedDlg(null);
			}
		}

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

		protected override void OnUnload()
		{
			base.OnUnload();
			base.uiBehaviour.m_Progress.Unload();
		}

		public override void OnUpdate()
		{
			base.OnUpdate();
			base.uiBehaviour.m_Progress.Update(Time.deltaTime);
		}

		public void FillContent()
		{
			this.RefreshBox();
			List<LoopItemData> list = new List<LoopItemData>();
			string empty = string.Empty;
			for (int i = 0; i < XDragonGuildDocument.DragonGuildLivenessData.RecordList.Count; i++)
			{
				DragonGuildLivenessRecord dragonGuildLivenessRecord = XDragonGuildDocument.DragonGuildLivenessData.RecordList[i];
				dragonGuildLivenessRecord.LoopID = XSingleton<XCommon>.singleton.XHash(XDragonGuildDocument.DragonGuildLivenessData.RecordList[i].ToString() + i);
				list.Add(dragonGuildLivenessRecord);
			}
			base.uiBehaviour.m_loopScrool.Init(list, new DelegateHandler(this.RefreshRecordItem), null, 0, true);
		}

		public void RefreshBox()
		{
			this.ChangeChestProgressState(false);
			this.SetCurrentExpAmi();
			this.ShowReward(XDragonGuildDocument.DragonGuildLivenessData.FindNeedShowReward());
		}

		private void RefreshRecordItem(ILoopItemObject item, LoopItemData data)
		{
			DragonGuildLivenessRecord dragonGuildLivenessRecord = data as DragonGuildLivenessRecord;
			bool flag = dragonGuildLivenessRecord != null;
			if (flag)
			{
				GameObject obj = item.GetObj();
				bool flag2 = obj != null;
				if (flag2)
				{
					DragonGuildLivenessRecordItem component = obj.GetComponent<DragonGuildLivenessRecordItem>();
					bool flag3 = component != null;
					if (flag3)
					{
						component.Refresh(dragonGuildLivenessRecord);
					}
				}
			}
			else
			{
				XSingleton<XDebug>.singleton.AddErrorLog("GuildMiniReportItem info is null", null, null, null, null, null);
			}
		}

		public void SetCurrentExpAmi()
		{
			base.uiBehaviour.m_Progress.TargetExp = XDragonGuildDocument.DragonGuildLivenessData.CurExp;
			base.uiBehaviour.m_TotalExpTween.SetNumberWithTween((ulong)XDragonGuildDocument.DragonGuildLivenessData.CurExp, "", false, true);
		}

		public void ChangeChestProgressState(bool init = false)
		{
			for (int i = 0; i < this.m_dragonguildLivenessRow.Count; i++)
			{
				XChest xchest = base.uiBehaviour.m_Progress.ChestList[i];
				if (init)
				{
					xchest.SetExp(this.m_dragonguildLivenessRow[i].liveness);
				}
				xchest.Opened = XDragonGuildDocument.DragonGuildLivenessData.IsChestOpened(i + 1);
			}
			if (init)
			{
				base.uiBehaviour.m_Progress.SetExp(0u, XDragonGuildDocument.DragonGuildLivenessData.MaxExp);
			}
		}

		public void ResetBoxRedDot(int index)
		{
			bool flag = index < 0 || index >= base.uiBehaviour.m_Progress.ChestList.Count;
			if (!flag)
			{
				base.uiBehaviour.m_Progress.ChestList[index].Open();
			}
		}

		private void OnChestClicked(IXUISprite iSp)
		{
			bool flag = this.SetButtonCool(this.m_CoolTime);
			if (!flag)
			{
				int index = (int)iSp.ID;
				this.ShowReward(index);
				bool flag2 = base.uiBehaviour.m_Progress.IsExpEnough(index);
				if (flag2)
				{
					DragonGuildLivenessTable.RowData rowData = this.m_dragonguildLivenessRow[index];
					bool flag3 = rowData != null;
					if (flag3)
					{
						XDragonGuildDocument.DragonGuildLivenessData.ReqTakeDragonGuildChest(rowData.index);
					}
				}
			}
		}

		public void ShowReward(int index)
		{
			this.m_CurSelectIndex = index;
			base.uiBehaviour.m_RewardItemPool.ReturnAll(false);
			DragonGuildLivenessTable.RowData rowData = this.m_dragonguildLivenessRow[this.m_CurSelectIndex];
			for (int i = 0; i < rowData.viewabledrop.Count; i++)
			{
				GameObject gameObject = base.uiBehaviour.m_RewardItemPool.FetchGameObject(false);
				bool flag = rowData.viewabledrop[i, 0] == 4u;
				if (flag)
				{
					XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(gameObject, (int)rowData.viewabledrop[i, 0], 0, false);
				}
				else
				{
					XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(gameObject, (int)rowData.viewabledrop[i, 0], (int)rowData.viewabledrop[i, 1], true);
				}
				XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.OpenClickShowTooltipEvent(gameObject, (int)rowData.viewabledrop[i, 0]);
				Vector3 tplPos = base.uiBehaviour.m_RewardItemPool.TplPos;
				gameObject.transform.localPosition = new Vector3(tplPos.x + (float)base.uiBehaviour.m_RewardItemPool.TplWidth * ((float)(-(float)rowData.viewabledrop.Count) / 2f + 0.5f + (float)i), tplPos.y, tplPos.z);
			}
			base.uiBehaviour.m_chestTips.SetText(rowData.liveness.ToString());
		}

		private void OnClosed(IXUISprite spr)
		{
			this.SetVisible(false, true);
		}

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