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

namespace XMainClient.UI
{
	internal class EnchantResultHandler : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "ItemNew/EnchantResultPanel";
			}
		}

		private XEnchantDocument _doc = null;

		private GameObject _equipItem;

		private IXUISprite _enchantIcon;

		private IXUIButton _accessBtn;

		private XItemRequiredCollector m_ItemRequiredCollector = new XItemRequiredCollector();

		private IXUILabel _costStone;

		private IXUILabel m_uiCostValue;

		private IXUISprite m_uiCostIcon;

		private IXUISprite m_Close;

		private IXUIScrollView _scrollView;

		private IXUIWrapContent _wrapContent;

		private XEnchantInfo _curEnchantInfo;

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

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

		protected override void OnShow()
		{
			base.OnShow();
			this._doc.ReqEnchant();
		}

		protected override void OnHide()
		{
			base.OnHide();
		}

		public override void OnUnload()
		{
			this._doc._EnchantResultHandler = null;
			this._doc = null;
			base.OnUnload();
		}

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

		public override void RefreshData()
		{
			base.RefreshData();
			XEquipItem xequipItem = XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemByUID(this._doc.SelectedEquipUID) as XEquipItem;
			bool flag = xequipItem == null;
			if (flag)
			{
				base.SetVisible(false);
			}
			else
			{
				this._curEnchantInfo = xequipItem.enchantInfo;
				this._RefreshCost();
				this._wrapContent.SetContentCount(this._curEnchantInfo.AttrList.Count, false);
				this._scrollView.ResetPosition();
			}
		}

		private void InitProperties()
		{
			IXUIButton ixuibutton = base.PanelObject.transform.Find("Bottom/BtnOK").GetComponent("XUIButton") as IXUIButton;
			ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.ContinueToEnchant));
			this.m_uiCostValue = (base.transform.Find("Bottom/Cost").GetComponent("XUILabel") as IXUILabel);
			this.m_uiCostIcon = (base.transform.Find("Bottom/Cost/Icon").GetComponent("XUISprite") as IXUISprite);
			this.m_Close = (base.transform.Find("Close").GetComponent("XUISprite") as IXUISprite);
			this.m_Close.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClose));
			this._equipItem = base.transform.Find("Top/EquipItem").gameObject;
			this._enchantIcon = (base.transform.Find("Bottom/CostStone/Icon").GetComponent("XUISprite") as IXUISprite);
			this._accessBtn = (base.transform.Find("Bottom/BtnGet").GetComponent("XUIButton") as IXUIButton);
			this._accessBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.ToAccesss));
			this._costStone = (base.transform.Find("Bottom/CostStone").GetComponent("XUILabel") as IXUILabel);
			this._wrapContent = (base.transform.Find("Detail/wrapcontent").GetComponent("XUIWrapContent") as IXUIWrapContent);
			this._wrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this.UpdateWrapContent));
			this._scrollView = (base.transform.Find("Detail").GetComponent("XUIScrollView") as IXUIScrollView);
		}

		private void UpdateWrapContent(Transform itemTransform, int index)
		{
			bool flag = index >= this._curEnchantInfo.AttrList.Count;
			if (!flag)
			{
				GameObject gameObject = itemTransform.Find("New").gameObject;
				IXUILabel ixuilabel = itemTransform.GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel2 = itemTransform.Find("Right").GetComponent("XUILabel") as IXUILabel;
				GameObject gameObject2 = itemTransform.Find("Jt/Up").gameObject;
				GameObject gameObject3 = itemTransform.Find("Jt/Down").gameObject;
				GameObject gameObject4 = itemTransform.Find("Jt/unchanged").gameObject;
				gameObject2.SetActive(false);
				gameObject3.SetActive(false);
				gameObject4.SetActive(false);
				gameObject.SetActive(false);
				XItemChangeAttr xitemChangeAttr = this._curEnchantInfo.AttrList[index];
				string text = XAttributeCommon.GetAttrStr((int)xitemChangeAttr.AttrID) + "+" + xitemChangeAttr.AttrValue;
				bool flag2 = xitemChangeAttr.AttrID == this._doc.LastEnchantAttr.AttrID;
				if (flag2)
				{
					int changedPreAttrValue = this.GetChangedPreAttrValue();
					gameObject.SetActive(changedPreAttrValue < 0);
					bool flag3 = changedPreAttrValue >= 0;
					if (flag3)
					{
						gameObject4.gameObject.SetActive((long)changedPreAttrValue == (long)((ulong)this._doc.LastEnchantAttr.AttrValue));
						gameObject2.SetActive((long)changedPreAttrValue < (long)((ulong)this._doc.LastEnchantAttr.AttrValue));
						gameObject3.SetActive((long)changedPreAttrValue > (long)((ulong)this._doc.LastEnchantAttr.AttrValue));
						bool flag4 = (long)changedPreAttrValue < (long)((ulong)this._doc.LastEnchantAttr.AttrValue);
						if (flag4)
						{
							text = string.Concat(new object[]
							{
								"[00ff00]",
								text,
								" ",
								(long)((ulong)this._doc.LastEnchantAttr.AttrValue - (ulong)((long)changedPreAttrValue)),
								"[-]"
							});
						}
						else
						{
							bool flag5 = (long)changedPreAttrValue > (long)((ulong)this._doc.LastEnchantAttr.AttrValue);
							if (flag5)
							{
								text = string.Concat(new object[]
								{
									text,
									" [ff0000]",
									(long)changedPreAttrValue - (long)((ulong)this._doc.LastEnchantAttr.AttrValue),
									"[-]"
								});
							}
						}
					}
				}
				string text2 = "";
				EnchantEquip.RowData enchantEquipData = this._doc.GetEnchantEquipData(this._doc.SelectedItemID);
				bool flag6 = enchantEquipData != null;
				if (flag6)
				{
					for (int i = 0; i < (int)enchantEquipData.Attribute.count; i++)
					{
						bool flag7 = enchantEquipData.Attribute[i, 0] == xitemChangeAttr.AttrID;
						if (flag7)
						{
							text2 = string.Concat(new object[]
							{
								" [",
								enchantEquipData.Attribute[i, 1],
								",",
								enchantEquipData.Attribute[i, 2],
								"]"
							});
							break;
						}
					}
				}
				ixuilabel.SetText(text);
				ixuilabel2.SetText(text2);
			}
		}

		private bool ToAccesss(IXUIButton button)
		{
			XSingleton<UiUtility>.singleton.ShowItemAccess(240, null);
			return true;
		}

		private bool ContinueToEnchant(IXUIButton button)
		{
			bool flag = !this.m_ItemRequiredCollector.bItemsEnough;
			bool result;
			if (flag)
			{
				for (int i = 0; i < this.m_ItemRequiredCollector.RequiredItems.Count; i++)
				{
					bool flag2 = !this.m_ItemRequiredCollector.RequiredItems[i].bEnough;
					if (flag2)
					{
						DlgBase<XPurchaseView, XPurchaseBehaviour>.singleton.ShowBorad(this.m_ItemRequiredCollector.RequiredItems[i].itemID);
						break;
					}
				}
				result = true;
			}
			else
			{
				XEquipItem xequipItem = XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemByUID(this._doc.SelectedEquipUID) as XEquipItem;
				bool flag3 = xequipItem == null;
				if (flag3)
				{
					result = true;
				}
				else
				{
					this._doc.ReqEnchant();
					result = true;
				}
			}
			return result;
		}

		private void OnClose(IXUISprite uiSprite)
		{
			base.SetVisible(false);
		}

		private void _RefreshCost()
		{
			ItemList.RowData itemConf = XBagDocument.GetItemConf(this._doc.SelectedItemID);
			bool flag = itemConf != null;
			if (flag)
			{
				this._enchantIcon.SetSprite(itemConf.ItemIcon1[0]);
			}
			XEquipItem xequipItem = XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemByUID(this._doc.SelectedEquipUID) as XEquipItem;
			bool flag2 = xequipItem != null;
			if (flag2)
			{
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(this._equipItem, xequipItem);
			}
			this.m_ItemRequiredCollector.Init();
			EnchantEquip.RowData enchantEquipData = this._doc.GetEnchantEquipData(this._doc.SelectedItemID);
			bool flag3 = enchantEquipData != null;
			if (flag3)
			{
				for (int i = 0; i < enchantEquipData.Cost.Count; i++)
				{
					XItemRequired requiredItem = this.m_ItemRequiredCollector.GetRequiredItem(enchantEquipData.Cost[i, 0], (ulong)enchantEquipData.Cost[i, 1], 1f);
					bool flag4 = requiredItem == null;
					if (!flag4)
					{
						this.m_uiCostValue.SetText(requiredItem.requiredCount.ToString());
						this.m_uiCostValue.SetColor(requiredItem.bEnough ? Color.white : Color.red);
						this.m_uiCostIcon.SetSprite(XBagDocument.GetItemSmallIcon(requiredItem.itemID, 0u));
					}
				}
			}
			XItemRequired requiredItem2 = this.m_ItemRequiredCollector.GetRequiredItem((uint)this._doc.SelectedItemID, (ulong)enchantEquipData.Num, 1f);
			ulong itemCount = XBagDocument.BagDoc.GetItemCount(this._doc.SelectedItemID);
			uint num = (enchantEquipData == null) ? 0u : enchantEquipData.Num;
			this._costStone.SetText(itemCount + "/" + num);
			this._costStone.SetColor((itemCount >= (ulong)num) ? Color.white : Color.red);
			this._costStone.gameObject.transform.Find("GetTip").gameObject.SetActive(itemCount < (ulong)num);
		}

		private void RefreshAfterAttri()
		{
		}

		private int GetChangedPreAttrValue()
		{
			XEnchantInfo preEnchantInfo = this._doc.GetPreEnchantInfo();
			XEnchantInfo curEnchantInfo = this._curEnchantInfo;
			int result = -1;
			uint attrID = this._doc.LastEnchantAttr.AttrID;
			for (int i = 0; i < preEnchantInfo.AttrList.Count; i++)
			{
				bool flag = preEnchantInfo.AttrList[i].AttrID == attrID;
				if (flag)
				{
					result = (int)preEnchantInfo.AttrList[i].AttrValue;
					break;
				}
			}
			return result;
		}
	}
}