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

namespace XMainClient
{
	internal class XSweepView : DlgBase<XSweepView, XSweepBehaviour>
	{
		public override string fileName
		{
			get
			{
				return "GameSystem/SweepDlg";
			}
		}

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

		private uint _sweepTime;

		private uint _setPosition;

		private XSweepDocument _doc = null;

		private GameObject _preSweepReward = null;

		private readonly int m_showNum = 6;

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

		public override void RegisterEvent()
		{
			base.uiBehaviour.m_Close.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnCloseClicked));
		}

		protected override void OnShow()
		{
			base.uiBehaviour.m_RewardPool.ReturnAll(false);
			base.uiBehaviour.m_DropPool.ReturnAll(false);
			this._preSweepReward = base.uiBehaviour.m_RewardPool._tpl;
			base.uiBehaviour.m_SweepTip.SetVisible(false);
			base.uiBehaviour.m_Exp.SetVisible(!this._doc.IsSeal);
			base.uiBehaviour.m_SealTip.gameObject.SetActive(this._doc.IsSeal);
		}

		protected bool OnCloseClicked(IXUIButton button)
		{
			bool flag = this._doc.Count > 0;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				XSingleton<XTimerMgr>.singleton.KillTimer(this._sweepTime);
				XSingleton<XTimerMgr>.singleton.KillTimer(this._setPosition);
				this.SetVisibleWithAnimation(false, null);
				result = true;
			}
			return result;
		}

		public void SetReward()
		{
			this.ShowReward(null);
			this.SetExpBar();
		}

		private void ShowReward(object o = null)
		{
			bool flag = !base.IsVisible();
			if (!flag)
			{
				GameObject gameObject = base.uiBehaviour.m_RewardPool.FetchGameObject(false);
				IXUILabel ixuilabel = gameObject.transform.Find("RewardLabel").GetComponent("XUILabel") as IXUILabel;
				ixuilabel.SetText(XStringDefineProxy.GetString("SWEEP_COUNT", new object[]
				{
					this._doc.GetCount() + 1
				}));
				base.uiBehaviour.m_dragBox.enabled = false;
				int num = 0;
				for (int i = 0; i < 10; i++)
				{
					ItemBrief item = this._doc.GetItem(this._doc.GetCount(), i);
					bool flag2 = item == null;
					if (flag2)
					{
						break;
					}
					GameObject gameObject2 = base.uiBehaviour.m_DropPool.FetchGameObject(false);
					gameObject2.transform.parent = gameObject.transform.Find("Parent");
					gameObject2.transform.localPosition = new Vector3((float)(i % this.m_showNum * base.uiBehaviour.m_DropPool.TplWidth), (float)(-(float)(i / this.m_showNum) * base.uiBehaviour.m_DropPool.TplHeight), 0f);
					XItemDrawerMgr.Param.bBinding = item.isbind;
					XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(gameObject2, (int)item.itemID, (int)item.itemCount, true);
					num++;
					IXUISprite ixuisprite = gameObject2.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
					ixuisprite.ID = (ulong)item.itemID;
					bool flag3 = !item.isbind;
					if (flag3)
					{
						ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(XSingleton<UiUtility>.singleton.OnItemClick));
					}
					else
					{
						ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(XSingleton<UiUtility>.singleton.OnBindItemClick));
					}
				}
				IXUISprite ixuisprite2 = gameObject.transform.Find("P").GetComponent("XUISprite") as IXUISprite;
				ixuisprite2.spriteHeight += (num - 1) / this.m_showNum * base.uiBehaviour.m_DropPool.TplHeight;
				gameObject.transform.localPosition = new Vector3(base.uiBehaviour.m_RewardPool.TplPos.x, this._preSweepReward.transform.localPosition.y + (float)(ixuisprite2.spriteHeight + 5), 0f);
				this._preSweepReward = gameObject;
				this._doc.Count = this._doc.Count - 1;
				bool flag4 = this._doc.Count > 0;
				if (flag4)
				{
					XSingleton<XTimerMgr>.singleton.KillTimer(this._sweepTime);
					this._sweepTime = XSingleton<XTimerMgr>.singleton.SetTimer(0.4f, new XTimerMgr.ElapsedEventHandler(this.ShowReward), null);
				}
				else
				{
					base.uiBehaviour.m_SweepTip.SetVisible(this._doc.ShowTip);
					base.uiBehaviour.m_SweepTip.gameObject.transform.localPosition = new Vector3(0f, this._preSweepReward.transform.localPosition.y + 125f);
					bool showTip = this._doc.ShowTip;
					if (showTip)
					{
						XSweepDocument xsweepDocument = XSingleton<XGame>.singleton.Doc.GetXComponent(XSweepDocument.uuID) as XSweepDocument;
						int slectDiffect = xsweepDocument.SlectDiffect;
						bool flag5 = slectDiffect == 1 && XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemCount(87) <= 0UL;
						if (flag5)
						{
							base.uiBehaviour.m_SweepTip.SetText(XStringDefineProxy.GetString("NOT_TICKET_FATIGUE", new object[]
							{
								this._doc.GetCount()
							}));
						}
						else
						{
							bool notHaveFatigue = this._doc.NotHaveFatigue;
							if (notHaveFatigue)
							{
								base.uiBehaviour.m_SweepTip.SetText(XStringDefineProxy.GetString("NOT_HAVE_FATIGUE", new object[]
								{
									this._doc.GetCount()
								}));
							}
							else
							{
								base.uiBehaviour.m_SweepTip.SetText(XStringDefineProxy.GetString("NOT_HAVE_COUNT", new object[]
								{
									this._doc.GetCount()
								}));
							}
						}
					}
					base.uiBehaviour.m_dragBox.enabled = true;
				}
				XSingleton<XTimerMgr>.singleton.KillTimer(this._setPosition);
				this._setPosition = XSingleton<XTimerMgr>.singleton.SetTimer(0.1f, new XTimerMgr.ElapsedEventHandler(this.SetPos), null);
			}
		}

		public void SetPos(object o = null)
		{
			bool flag = !base.IsVisible();
			if (!flag)
			{
				base.uiBehaviour.m_ScrollView.ResetPosition();
			}
		}

		public override void OnUpdate()
		{
			bool flag = this._doc.GainExp > 0f;
			if (flag)
			{
				this.SetExpBar();
			}
		}

		private void SetExpBar()
		{
			bool flag = XSingleton<XEntityMgr>.singleton.Player == null;
			if (!flag)
			{
				XPlayerAttributes xplayerAttributes = XSingleton<XEntityMgr>.singleton.Player.Attributes as XPlayerAttributes;
				this._doc.GainExp -= this._doc.ExpDelta;
				this._doc.CurExp += this._doc.ExpDelta;
				int num = (int)xplayerAttributes.GetLevelUpExp((int)(this._doc.ProcessLevel + 1u));
				num = ((num <= 0) ? 1 : num);
				while (this._doc.CurExp >= (float)num)
				{
					this._doc.CurExp -= (float)num;
					XSweepDocument doc = this._doc;
					uint processLevel = doc.ProcessLevel + 1u;
					doc.ProcessLevel = processLevel;
					num = (int)xplayerAttributes.GetLevelUpExp((int)(this._doc.ProcessLevel + 1u));
				}
				bool flag2 = num == 0;
				if (flag2)
				{
					base.uiBehaviour.m_ExpText.SetText("+0.00%");
					base.uiBehaviour.m_Exp.value = 1f;
				}
				else
				{
					float num2 = this._doc.CurExp / (float)num;
					base.uiBehaviour.m_ExpText.SetText(string.Format("+{0:F2}%", num2 * 100f));
					base.uiBehaviour.m_Exp.value = num2;
				}
			}
		}
	}
}