summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/UI/XWheelOfFortuneHandler.cs
blob: e780dafa11a8eef64d3aca3234085a7c444cded8 (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 UILib;
using UnityEngine;
using XUtliPoolLib;

namespace XMainClient.UI
{
	internal class XWheelOfFortuneHandler : DlgHandlerBase
	{
		private static int START_DEGREE = 90;

		private int DIRECTION = -1;

		private int CIRCLE_DEGREE = 360;

		private int FIRST_STAGE_DEGREE = 10;

		private int SECOND_STAGE_DEGREE = 3;

		private float RESULT_STAY_TIME = 1.5f;

		private XCharacterItemDocument _doc;

		private GameObject m_Arrow;

		private IXCurve m_SpeedCurve;

		private IXUIButton m_BtnStart;

		private IXUIButton m_BtnClose;

		private IXUITweenTool m_ShowTween;

		private float m_StartSpeed;

		private int[] m_IndexMap = new int[XLotteryBoxItem.POOL_SIZE];

		private GameObject[] m_ItemList = new GameObject[XLotteryBoxItem.POOL_SIZE];

		private int[] m_DegreeList = new int[XLotteryBoxItem.POOL_SIZE];

		private XItem[] m_DataList = new XItem[XLotteryBoxItem.POOL_SIZE];

		private int m_TargetIndex;

		private int m_TargetDegree;

		private XWheelState m_State;

		private float m_CurrentDegree;

		private float m_CurrentSpeed;

		private float m_StartDecSpeedDegree;

		private float m_DecSpeedDegreeLength;

		private uint m_ResultStayTimerToken = 0u;

		private ulong m_ItemUID;

		private XItemSelector m_ItemSelector = new XItemSelector(0u);

		private XFx m_Fx = null;

		protected override void Init()
		{
			base.Init();
			this.DIRECTION = XSingleton<XGlobalConfig>.singleton.GetInt("WheelOfFortuneDirection");
			this.CIRCLE_DEGREE = 360 * this.DIRECTION;
			this.FIRST_STAGE_DEGREE = (int)(float.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("WheelOfFortuneFirstStageDegree")) * (float)this.CIRCLE_DEGREE);
			this.SECOND_STAGE_DEGREE = (int)(float.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("WheelOfFortuneSecondStageDegree")) * (float)this.CIRCLE_DEGREE);
			this.RESULT_STAY_TIME = float.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("WheelOfFortuneResultStayTime"));
			this._doc = (XSingleton<XGame>.singleton.Doc.GetXComponent(XCharacterItemDocument.uuID) as XCharacterItemDocument);
			GameObject gameObject = base.PanelObject.transform.Find("Bg/ItemTpl").gameObject;
			GameObject gameObject2 = gameObject.transform.Find("Effect").gameObject;
			this.m_ItemSelector.LoadFromUI(gameObject2, base.PanelObject.transform);
			XUIPool xuipool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);
			xuipool.SetupPool(gameObject.transform.parent.gameObject, gameObject, (uint)XLotteryBoxItem.POOL_SIZE, false);
			for (int i = 0; i < XLotteryBoxItem.POOL_SIZE; i++)
			{
				GameObject gameObject3 = xuipool.FetchGameObject(false);
				Transform transform = base.PanelObject.transform.Find("Bg/Pos/Pos" + i);
				gameObject3.transform.parent = transform;
				gameObject3.transform.localPosition = Vector3.zero;
				this.m_ItemList[i] = gameObject3;
				IXUISprite ixuisprite = gameObject3.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
				ixuisprite.ID = (ulong)((long)i);
				ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnItemClicked));
				int num = (int)(Mathf.Atan2(transform.localPosition.y, transform.localPosition.x) * 57.29578f);
				bool flag = this.DIRECTION * num < 0;
				if (flag)
				{
					num += this.CIRCLE_DEGREE;
				}
				this.m_DegreeList[i] = num;
				this.m_IndexMap[i] = i;
				this.m_DataList[i] = new XNormalItem();
			}
			this.m_Arrow = base.PanelObject.transform.Find("Bg/Arrow").gameObject;
			this.m_SpeedCurve = (this.m_Arrow.GetComponent("XCurve") as IXCurve);
			this.m_StartSpeed = this.m_SpeedCurve.Evaluate(0f) * (float)this.DIRECTION;
			this.m_BtnStart = (base.PanelObject.transform.Find("Bg/BtnStart").GetComponent("XUIButton") as IXUIButton);
			this.m_BtnClose = (base.PanelObject.transform.Find("Close").GetComponent("XUIButton") as IXUIButton);
			this.m_ShowTween = (base.PanelObject.GetComponent("XUIPlayTween") as IXUITweenTool);
			this.m_Fx = XSingleton<XFxMgr>.singleton.CreateUIFx("Effects/FX_Particle/UIfx/UI_WheelOfFortune_fx", base.PanelObject.transform.Find("Bg/Bg/Bg"), false);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_BtnStart.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnStartClicked));
			this.m_BtnClose.RegisterClickEventHandler(new ButtonClickEventHandler(this._OnCloseClicked));
		}

		protected override void OnShow()
		{
			base.OnShow();
			this.m_State = XWheelState.WS_IDLE;
			this.ToggleOperation(false, false);
			this.m_ShowTween.PlayTween(true, -1f);
			this.m_ItemSelector.Hide();
			this.m_ResultStayTimerToken = 0u;
		}

		protected override void OnHide()
		{
			this._doc.ToggleBlock(false);
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_ResultStayTimerToken);
			base.OnHide();
		}

		public override void OnUnload()
		{
			this._doc.ToggleBlock(false);
			XSingleton<XTimerMgr>.singleton.KillTimer(this.m_ResultStayTimerToken);
			this.m_ItemSelector.Unload();
			bool flag = this.m_Fx != null;
			if (flag)
			{
				XSingleton<XFxMgr>.singleton.DestroyFx(this.m_Fx, true);
			}
			this.m_Fx = null;
			base.OnUnload();
		}

		public override void OnUpdate()
		{
			base.OnUpdate();
			bool flag = this.m_State == XWheelState.WS_IDLE || this.m_State == XWheelState.WS_DONE;
			if (!flag)
			{
				bool flag2 = this.m_State == XWheelState.WS_DOING_FIRST_STAGE;
				if (flag2)
				{
					this.m_CurrentSpeed = this.m_StartSpeed;
				}
				else
				{
					this.m_CurrentSpeed = this.m_SpeedCurve.Evaluate((this.m_CurrentDegree - this.m_StartDecSpeedDegree) / this.m_DecSpeedDegreeLength) * (float)this.DIRECTION;
				}
				this.m_CurrentDegree += this.m_CurrentSpeed * Time.deltaTime;
				bool flag3 = this.m_State == XWheelState.WS_DOING_FIRST_STAGE && this.m_CurrentDegree * (float)this.DIRECTION > this.m_StartDecSpeedDegree * (float)this.DIRECTION;
				if (flag3)
				{
					this.m_State = XWheelState.WS_DOING_SECOND_STAGE;
				}
				bool flag4 = this.m_CurrentDegree * (float)this.DIRECTION >= (float)(this.m_TargetDegree * this.DIRECTION);
				if (flag4)
				{
					this.m_CurrentDegree = (float)this.m_TargetDegree;
					this.m_State = XWheelState.WS_DONE;
					this._FinishDoing();
				}
				this.m_Arrow.transform.localRotation = Quaternion.AngleAxis(this.m_CurrentDegree, Vector3.forward);
			}
		}

		private void _FinishDoing()
		{
			this._doc.ToggleBlock(false);
			ItemList.RowData itemConf = XBagDocument.GetItemConf(this.m_DataList[this.m_TargetIndex].itemID);
			GameObject gameObject = this.m_ItemList[this.m_TargetIndex].transform.Find("Icon").gameObject;
			bool flag = itemConf != null;
			if (flag)
			{
				IXUISprite ixuisprite = this.m_ItemSelector.Effects.transform.Find("Anim").GetComponent("XUISprite") as IXUISprite;
				ixuisprite.SetColor(XSingleton<UiUtility>.singleton.GetItemQualityColor((int)itemConf.ItemQuality));
				this.m_ItemSelector.Select(gameObject);
			}
			this.m_ResultStayTimerToken = XSingleton<XTimerMgr>.singleton.SetTimer(this.RESULT_STAY_TIME, new XTimerMgr.ElapsedEventHandler(this._FinishStay), null);
		}

		private void _FinishStay(object o)
		{
			this.m_ResultStayTimerToken = 0u;
			base.SetVisible(false);
		}

		private void _RandomPosition()
		{
			for (int i = 0; i < XLotteryBoxItem.POOL_SIZE; i++)
			{
				int num = XSingleton<XCommon>.singleton.RandomInt(i, XLotteryBoxItem.POOL_SIZE);
				int num2 = this.m_IndexMap[num];
				this.m_IndexMap[num] = this.m_IndexMap[i];
				this.m_IndexMap[i] = num2;
			}
		}

		public void OpenWheel(XLotteryBoxItem item)
		{
			base.SetVisible(true);
			this._RandomPosition();
			for (int i = 0; i < XLotteryBoxItem.POOL_SIZE; i++)
			{
				int num = this.m_IndexMap[i];
				this.m_DataList[num].itemID = item.itemList[i].itemID;
				this.m_DataList[num].itemCount = item.itemList[i].itemCount;
				XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(this.m_ItemList[num], this.m_DataList[num].itemID, this.m_DataList[num].itemCount, false);
			}
			this.m_ItemUID = item.uid;
		}

		public void ShowResult(int targetIndex)
		{
			this.ToggleOperation(true, true);
			this.m_TargetIndex = this.m_IndexMap[targetIndex];
			this.m_TargetDegree = XWheelOfFortuneHandler.START_DEGREE + this.FIRST_STAGE_DEGREE + this.SECOND_STAGE_DEGREE;
			this.m_StartDecSpeedDegree = (float)(XWheelOfFortuneHandler.START_DEGREE + this.FIRST_STAGE_DEGREE);
			this.m_DecSpeedDegreeLength = (float)this.SECOND_STAGE_DEGREE;
			int num = this.m_TargetDegree % this.CIRCLE_DEGREE;
			int num2 = this.m_DegreeList[this.m_TargetIndex];
			bool flag = (num2 - num) * this.DIRECTION < 0;
			if (flag)
			{
				num2 += this.CIRCLE_DEGREE;
			}
			int num3 = num2 - num;
			this.m_DecSpeedDegreeLength += (float)num3;
			this.m_TargetDegree += num3;
			this.m_State = XWheelState.WS_DOING_FIRST_STAGE;
			this.m_CurrentDegree = (float)XWheelOfFortuneHandler.START_DEGREE;
		}

		public void ToggleOperation(bool bBlockClose, bool bBlockStart)
		{
			this.m_BtnClose.SetVisible(!bBlockClose);
			this.m_BtnStart.SetVisible(!bBlockStart);
		}

		private void _OnItemClicked(IXUISprite icon)
		{
			int num = (int)icon.ID;
			XSingleton<UiUtility>.singleton.ShowTooltipDialog(this.m_DataList[num].itemID, icon, 0u);
		}

		private bool _OnCloseClicked(IXUIButton btn)
		{
			base.SetVisible(false);
			return true;
		}

		private bool _OnStartClicked(IXUIButton btn)
		{
			this._doc.UseItem(this.m_ItemUID);
			return true;
		}
	}
}