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

namespace XMainClient.UI
{
	internal class XSpriteAvatarHandler : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "GameSystem/SpriteSystem/SpriteAvatarHandler";
			}
		}

		private XSpriteSystemDocument _doc;

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

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

		private IXUILabel m_Name;

		private IXUILabel m_Power;

		private IXUILabel m_Level;

		private IXUISprite m_LevelFrame;

		private IUIDummy m_Snapshot;

		private IXUISprite m_Avatar;

		private IXUISprite m_Quality;

		private GameObject m_StarGrid;

		private XDummy m_Dummy;

		private SpriteInfo m_SpriteData = null;

		private XAttributes m_Attributes = null;

		private SpriteTable.RowData m_SpriteInfo = null;

		protected override void Init()
		{
			base.Init();
			this._doc = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			Transform transform = base.PanelObject.transform.Find("Message/StarGrid/StarTpl");
			this.m_StarPool.SetupPool(transform.parent.gameObject, transform.gameObject, 4u, false);
			transform = base.PanelObject.transform.Find("Message/StarGrid/MoonTpl");
			this.m_MoonPool.SetupPool(transform.parent.gameObject, transform.gameObject, 4u, false);
			this.m_StarGrid = base.PanelObject.transform.Find("Message/StarGrid").gameObject;
			this.m_Name = (base.PanelObject.transform.Find("Message/Name").GetComponent("XUILabel") as IXUILabel);
			this.m_LevelFrame = (base.PanelObject.transform.Find("Message/Level").GetComponent("XUISprite") as IXUISprite);
			this.m_Level = (base.PanelObject.transform.Find("Message/Level/Num").GetComponent("XUILabel") as IXUILabel);
			this.m_Power = (base.PanelObject.transform.Find("Message/Power").GetComponent("XUILabel") as IXUILabel);
			this.m_Quality = (base.PanelObject.transform.Find("Message/Quality").GetComponent("XUISprite") as IXUISprite);
			this.m_Avatar = (base.PanelObject.transform.Find("AvatarBtn").GetComponent("XUISprite") as IXUISprite);
			this.m_Snapshot = (base.PanelObject.transform.Find("Snapshot").GetComponent("UIDummy") as IUIDummy);
		}

		protected override void OnShow()
		{
			base.OnShow();
			base.Alloc3DAvatarPool("XSpriteAvatarHandler", 1);
		}

		protected override void OnHide()
		{
			base.OnHide();
			bool flag = this.m_Dummy != null;
			if (flag)
			{
				XSingleton<X3DAvatarMgr>.singleton.DestroyDummy(this.m_dummPool, this.m_Dummy);
				this.m_Dummy = null;
			}
		}

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

		public override void OnUnload()
		{
			base.Return3DAvatarPool();
			this.m_Dummy = null;
			base.OnUnload();
		}

		public void HideAvatar()
		{
			bool flag = this.m_Dummy != null;
			if (flag)
			{
				XSingleton<X3DAvatarMgr>.singleton.DestroyDummy(this.m_dummPool, this.m_Dummy);
				this.m_Dummy = null;
			}
			this.m_Name.SetText("");
			this.m_Level.gameObject.transform.parent.gameObject.SetActive(false);
			this.m_Quality.SetVisible(false);
			this.m_Power.SetText("");
			this.m_StarPool.ReturnAll(false);
			this.m_MoonPool.ReturnAll(false);
		}

		public void SetSpriteInfoByIndex(int index, int avatarIndex = 0, bool needClickEvent = false, bool showLevel = true)
		{
			bool flag = index >= this._doc.SpriteList.Count;
			if (!flag)
			{
				this.SetSpriteInfo(this._doc.SpriteList[index], XSingleton<XAttributeMgr>.singleton.XPlayerData, avatarIndex, needClickEvent, showLevel);
			}
		}

		public void SetSpriteInfo(SpriteInfo spriteData, XAttributes attributes, int avatarIndex = 6, bool needClickEvent = false, bool showLevel = true)
		{
			if (needClickEvent)
			{
				this.m_Avatar.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClickAvatar));
			}
			else
			{
				this.m_Avatar.RegisterSpriteClickEventHandler(null);
			}
			bool flag = spriteData == null;
			if (!flag)
			{
				this.m_SpriteInfo = this._doc._SpriteTable.GetBySpriteID(spriteData.SpriteID);
				this.m_SpriteData = spriteData;
				this.m_Attributes = attributes;
				SpriteTable.RowData bySpriteID = this._doc._SpriteTable.GetBySpriteID(spriteData.SpriteID);
				this.m_StarGrid.SetActive(true);
				this.m_StarPool.ReturnAll(false);
				this.m_MoonPool.ReturnAll(false);
				uint num = spriteData.EvolutionLevel / XSpriteSystemDocument.MOONWORTH;
				uint num2 = spriteData.EvolutionLevel % XSpriteSystemDocument.MOONWORTH;
				float num3 = (num + num2 - 1f) / 2f;
				int num4 = 0;
				while ((long)num4 < (long)((ulong)(num + num2)))
				{
					bool flag2 = (long)num4 < (long)((ulong)num);
					if (flag2)
					{
						GameObject gameObject = this.m_MoonPool.FetchGameObject(false);
						Vector3 tplPos = this.m_MoonPool.TplPos;
						gameObject.transform.localPosition = new Vector3(tplPos.x + ((float)num4 - num3) * (float)this.m_MoonPool.TplWidth, tplPos.y);
					}
					else
					{
						GameObject gameObject2 = this.m_StarPool.FetchGameObject(false);
						Vector3 tplPos2 = this.m_StarPool.TplPos;
						gameObject2.transform.localPosition = new Vector3(tplPos2.x + ((float)num4 - num3) * (float)this.m_StarPool.TplWidth, tplPos2.y);
					}
					num4++;
				}
				this.m_Name.SetText(string.Format("[{0}]{1}", this._doc.NAMECOLOR[(int)bySpriteID.SpriteQuality], bySpriteID.SpriteName));
				this.m_Quality.SetVisible(true);
				this.m_Quality.spriteName = string.Format("icondjdj_{0}", bySpriteID.SpriteQuality);
				XSpriteSystemDocument specificDocument = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
				if (showLevel)
				{
					this.m_Level.gameObject.transform.parent.gameObject.SetActive(true);
					this.m_Level.SetText(string.Format("Lv. {0}", spriteData.Level));
				}
				else
				{
					this.m_Level.gameObject.transform.parent.gameObject.SetActive(false);
				}
				this.m_Power.SetText(string.Format(XStringDefineProxy.GetString("BOSSRUSH_POWER"), spriteData.PowerPoint));
				this.m_LevelFrame.UpdateAnchors();
				this.m_Dummy = XSingleton<X3DAvatarMgr>.singleton.CreateCommonEntityDummy(this.m_dummPool, bySpriteID.SpriteModelID, this.m_Snapshot, this.m_Dummy, 1f);
				this.ResetSpriteAnim();
				bool flag3 = this.m_SpriteInfo != null;
				if (flag3)
				{
					this.ChangeMatColor(this.m_Dummy.EngineObject, this.m_SpriteInfo.PresentID);
				}
			}
		}

		public void SetSpriteInfo(uint spriteID, bool showLevel = true, uint power = 0u)
		{
			this.m_SpriteData = null;
			this.m_Attributes = null;
			this.m_SpriteInfo = this._doc._SpriteTable.GetBySpriteID(spriteID);
			this.m_Name.SetText(string.Format("[{0}]{1}", this._doc.NAMECOLOR[(int)this.m_SpriteInfo.SpriteQuality], this.m_SpriteInfo.SpriteName));
			this.m_Quality.SetVisible(true);
			this.m_Quality.spriteName = string.Format("icondjdj_{0}", this.m_SpriteInfo.SpriteQuality);
			this.m_Level.gameObject.transform.parent.gameObject.SetActive(showLevel);
			if (showLevel)
			{
				this.m_Level.SetText("Lv.1");
			}
			this.m_Power.SetText(string.Format(XStringDefineProxy.GetString("BOSSRUSH_POWER"), (power == 0u) ? this.GetSpriteOneLevelPower(this.m_SpriteInfo) : power));
			this.m_StarGrid.SetActive(false);
			this.m_Dummy = XSingleton<X3DAvatarMgr>.singleton.CreateCommonEntityDummy(this.m_dummPool, this.m_SpriteInfo.SpriteModelID, this.m_Snapshot, this.m_Dummy, 1f);
			this.ResetSpriteAnim();
			bool flag = this.m_SpriteInfo != null;
			if (flag)
			{
				this.ChangeMatColor(this.m_Dummy.EngineObject, this.m_SpriteInfo.PresentID);
			}
		}

		private void ChangeMatColor(XGameObject xobject, uint presentID)
		{
			XSpriteSystemDocument specificDocument = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			SpriteTable.RowData byPresentID = specificDocument._SpriteTable.GetByPresentID(presentID);
			bool flag = byPresentID != null;
			if (flag)
			{
				xobject.CallCommand(XAffiliate._changeSpriteMatColorCb, byPresentID, -1, false);
			}
		}

		public XEntityPresentation.RowData GetSpritePresent()
		{
			bool flag = this.m_Dummy == null;
			XEntityPresentation.RowData result;
			if (flag)
			{
				result = null;
			}
			else
			{
				bool flag2 = this.m_Dummy.Present == null;
				if (flag2)
				{
					result = null;
				}
				else
				{
					result = this.m_Dummy.Present.PresentLib;
				}
			}
			return result;
		}

		public void ResetSpriteAnim()
		{
			bool flag = this.m_Dummy == null;
			if (!flag)
			{
				this.m_Dummy.ResetAnimation();
			}
		}

		public float SetSpriteAnim(string clipname)
		{
			bool flag = this.m_Dummy == null;
			float result;
			if (flag)
			{
				result = -1f;
			}
			else
			{
				result = this.m_Dummy.SetAnimationGetLength(clipname);
			}
			return result;
		}

		private uint GetSpriteOneLevelPower(SpriteTable.RowData spriteInfo)
		{
			List<uint> list = new List<uint>();
			List<double> list2 = new List<double>();
			List<double> list3 = new List<double>();
			XSpriteSystemDocument specificDocument = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			XSpriteAttributeHandler.GetLevelOneSpriteAttr(spriteInfo, out list, out list2, out list3);
			double num = 0.0;
			for (int i = 0; i < list3.Count; i++)
			{
				num += XSingleton<XPowerPointCalculator>.singleton.GetPPT(list[i], list3[i] / 100.0, null, 0);
			}
			for (int j = 0; j < list2.Count; j++)
			{
				num += XSingleton<XPowerPointCalculator>.singleton.GetPPT(list[j], (uint)list2[j], null, 0);
			}
			return (uint)num;
		}

		private void OnClickAvatar(IXUISprite btn)
		{
			bool flag = this.m_SpriteData != null;
			if (flag)
			{
				DlgBase<XSpriteDetailView, XSpriteDetailBehaviour>.singleton.ShowDetail(this.m_SpriteData, this.m_Attributes);
			}
			else
			{
				bool flag2 = this.m_SpriteInfo != null;
				if (flag2)
				{
					DlgBase<XSpriteDetailView, XSpriteDetailBehaviour>.singleton.ShowDetail(this.m_SpriteInfo.SpriteID);
				}
			}
		}
	}
}