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

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

		private XSpriteSystemDocument _doc;

		public SpriteSelectHandler _SpriteSelectHandler;

		public XUIPool m_SpritePool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		public IXUIScrollView m_ScrollView;

		public IXUISprite m_ResolveBtn;

		public GameObject m_ResolveTips;

		public IXUILabel m_JustTips;

		private HashSet<ulong> _resolveHash = new HashSet<ulong>();

		public List<SpriteInfo> SelectList = new List<SpriteInfo>();

		private uint _resolveMaxNum;

		protected override void Init()
		{
			base.Init();
			this._doc = XDocuments.GetSpecificDocument<XSpriteSystemDocument>(XSpriteSystemDocument.uuID);
			this._resolveMaxNum = uint.Parse(XSingleton<XGlobalConfig>.singleton.GetValue("SpriteResolveMaxNum"));
			Transform transform = base.PanelObject.transform.Find("ScrollView/Tpl");
			this.m_ScrollView = (base.PanelObject.transform.Find("ScrollView").GetComponent("XUIScrollView") as IXUIScrollView);
			this.m_SpritePool.SetupPool(transform.parent.gameObject, transform.gameObject, 12u, false);
			this.m_ResolveBtn = (base.PanelObject.transform.Find("ResolveBtn").GetComponent("XUISprite") as IXUISprite);
			this.m_ResolveTips = base.PanelObject.transform.Find("ResolveTips").gameObject;
			this.m_JustTips = (base.PanelObject.transform.Find("info").GetComponent("XUILabel") as IXUILabel);
			this.m_JustTips.SetText(XSingleton<UiUtility>.singleton.ReplaceReturn(XStringDefineProxy.GetString("SpriteResolveTips")));
			DlgHandlerBase.EnsureCreate<SpriteSelectHandler>(ref this._SpriteSelectHandler, base.PanelObject.transform.Find("SelectHandlerParent"), false, this);
		}

		protected override void OnShow()
		{
			base.OnShow();
			this._SpriteSelectHandler.SetVisible(true);
			this.CheckSelectList();
		}

		protected override void OnHide()
		{
			base.OnHide();
			this._SpriteSelectHandler.SetVisible(false);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_ResolveBtn.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnResolveBtnClick));
		}

		public override void OnUnload()
		{
			DlgHandlerBase.EnsureUnload<SpriteSelectHandler>(ref this._SpriteSelectHandler);
			base.OnUnload();
		}

		public void CheckSelectList()
		{
			this.SelectList.Clear();
			for (int i = 0; i < this._doc.ResolveList.Count; i++)
			{
				bool flag = this._resolveHash.Contains(this._doc.ResolveList[i].uid);
				if (flag)
				{
					bool flag2 = this._doc.isSpriteFight(this._doc.ResolveList[i].uid);
					if (flag2)
					{
						this._resolveHash.Remove(this._doc.ResolveList[i].uid);
					}
					else
					{
						this.SelectList.Add(this._doc.ResolveList[i]);
					}
				}
			}
			for (int j = 0; j < this._doc.FightingList.Count; j++)
			{
				bool flag3 = this._resolveHash.Contains(this._doc.FightingList[j]);
				if (flag3)
				{
					this._resolveHash.Remove(this._doc.FightingList[j]);
				}
			}
			this.SetSpriteList(true);
		}

		public void SetSpriteList(bool resetScrollPos = true)
		{
			bool flag = !base.IsVisible();
			if (!flag)
			{
				this.m_ResolveBtn.SetGrey(this.SelectList.Count != 0);
				this.m_ResolveTips.SetActive(this.SelectList.Count == 0);
				this.m_SpritePool.ReturnAll(false);
				Vector3 tplPos = this.m_SpritePool.TplPos;
				for (int i = 0; i < this.SelectList.Count; i++)
				{
					GameObject gameObject = this.m_SpritePool.FetchGameObject(false);
					gameObject.transform.localPosition = new Vector3(tplPos.x + (float)(i % 3 * this.m_SpritePool.TplWidth), tplPos.y - (float)(i / 3 * this.m_SpritePool.TplHeight));
					SpriteTable.RowData bySpriteID = this._doc._SpriteTable.GetBySpriteID(this.SelectList[i].SpriteID);
					Transform ts = gameObject.transform.Find("Star");
					this.SetStar(ts, this.SelectList[i].EvolutionLevel);
					IXUILabel ixuilabel = gameObject.transform.Find("Name").GetComponent("XUILabel") as IXUILabel;
					ixuilabel.SetText(string.Format("[{0}]{1}", this._doc.NAMECOLOR[(int)bySpriteID.SpriteQuality], bySpriteID.SpriteName));
					IXUILabel ixuilabel2 = gameObject.transform.Find("PPT").GetComponent("XUILabel") as IXUILabel;
					ixuilabel2.SetText(string.Format(XStringDefineProxy.GetString("BOSSRUSH_POWER"), this.SelectList[i].PowerPoint));
					IXUILabel ixuilabel3 = gameObject.transform.Find("Level").GetComponent("XUILabel") as IXUILabel;
					ixuilabel3.SetText(string.Format("Lv.{0}", this.SelectList[i].Level));
					IXUISprite ixuisprite = gameObject.transform.Find("Frame").GetComponent("XUISprite") as IXUISprite;
					ixuisprite.spriteName = string.Format("kuang_dj_{0}", bySpriteID.SpriteQuality);
					IXUISprite ixuisprite2 = gameObject.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
					ixuisprite2.spriteName = bySpriteID.SpriteIcon;
					IXUISprite ixuisprite3 = gameObject.transform.GetComponent("XUISprite") as IXUISprite;
					ixuisprite3.ID = (ulong)((long)i);
					ixuisprite3.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnSpriteScorllViewListClick));
				}
				if (resetScrollPos)
				{
					this.m_ScrollView.SetPosition(0f);
				}
			}
		}

		private void SetStar(Transform ts, uint num)
		{
			uint num2 = num / XSpriteSystemDocument.MOONWORTH;
			uint num3 = num % XSpriteSystemDocument.MOONWORTH;
			for (int i = 0; i < 7; i++)
			{
				IXUISprite ixuisprite = ts.Find(string.Format("star{0}", i)).GetComponent("XUISprite") as IXUISprite;
				bool flag = (long)i < (long)((ulong)(num2 + num3));
				if (flag)
				{
					ixuisprite.SetVisible(true);
					ixuisprite.spriteName = (((long)i < (long)((ulong)num2)) ? "l_stars_02" : "l_stars_01");
				}
				else
				{
					ixuisprite.SetVisible(false);
				}
			}
		}

		public bool ScrollViewHasSprite(ulong id)
		{
			return this._resolveHash.Contains(id);
		}

		public void OnSpriteListClick(IXUISprite iSp)
		{
			bool flag = (int)iSp.ID >= this._doc.ResolveList.Count;
			if (!flag)
			{
				SpriteInfo spriteInfo = this._doc.ResolveList[(int)iSp.ID];
				bool flag2 = this._resolveHash.Contains(spriteInfo.uid);
				if (flag2)
				{
					this.SelectList.Remove(spriteInfo);
					this._resolveHash.Remove(spriteInfo.uid);
					iSp.gameObject.transform.Find("Select").gameObject.SetActive(false);
					this.SetSpriteList(false);
				}
				else
				{
					bool flag3 = this.SelectList.Count >= this._doc.SpriteList.Count - 1;
					if (flag3)
					{
						XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("SpriteResolveAllTips"), "fece00");
					}
					else
					{
						bool flag4 = (long)this.SelectList.Count >= (long)((ulong)this._resolveMaxNum);
						if (flag4)
						{
							XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("SpriteResolveMaxTips"), "fece00");
						}
						else
						{
							this.SelectList.Add(spriteInfo);
							this._resolveHash.Add(spriteInfo.uid);
							iSp.gameObject.transform.Find("Select").gameObject.SetActive(true);
							this.SetSpriteList(false);
						}
					}
				}
			}
		}

		public void OnSpriteScorllViewListClick(IXUISprite iSp)
		{
			this._resolveHash.Remove(this.SelectList[(int)iSp.ID].uid);
			this.SelectList.RemoveAt((int)iSp.ID);
			this.SetSpriteList(false);
			this._SpriteSelectHandler.SetSpriteList(this._doc.ResolveList, false);
		}

		public void OnResolveBtnClick(IXUISprite iSp)
		{
			bool flag = this.SelectList.Count == 0;
			if (!flag)
			{
				bool flag2 = this.SelectList.Count == this._doc.SpriteList.Count;
				if (flag2)
				{
					XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("SpriteResolveAllTips"), "fece00");
				}
				else
				{
					bool flag3 = this.CheckWhetherNeedToTips();
					if (flag3)
					{
						string label = XSingleton<UiUtility>.singleton.ReplaceReturn(XStringDefineProxy.GetString("SpriteResolveSureTips"));
						string @string = XStringDefineProxy.GetString("COMMON_OK");
						string string2 = XStringDefineProxy.GetString("COMMON_CANCEL");
						XSingleton<UiUtility>.singleton.ShowModalDialog(label, @string, string2, new ButtonClickEventHandler(this.OnResolveSure));
					}
					else
					{
						this.SendResolveList();
					}
				}
			}
		}

		private bool CheckWhetherNeedToTips()
		{
			int i = 0;
			while (i < this.SelectList.Count)
			{
				bool flag = this.SelectList[i].Level > 1u;
				bool result;
				if (flag)
				{
					result = true;
				}
				else
				{
					SpriteTable.RowData bySpriteID = this._doc._SpriteTable.GetBySpriteID(this.SelectList[i].SpriteID);
					bool flag2 = bySpriteID.SpriteQuality > 2u;
					if (!flag2)
					{
						i++;
						continue;
					}
					result = true;
				}
				return result;
			}
			return false;
		}

		private bool OnResolveSure(IXUIButton btn)
		{
			this.SendResolveList();
			DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetVisible(false, true);
			return true;
		}

		private void SendResolveList()
		{
			XSingleton<XDebug>.singleton.AddLog("Resolve", null, null, null, null, null, XDebugColor.XDebug_None);
			this._doc.QueryResolveSprite(this.SelectList);
		}

		public void Clean()
		{
			this.SelectList.Clear();
			this._resolveHash.Clear();
			this.SetSpriteList(true);
			this._SpriteSelectHandler.SetSpriteList(this._doc.ResolveList, true);
		}
	}
}