summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/UI/CharacterEquipBagHandler.cs
blob: 08bde5aec07e7bd4d3c96e4f47f7542ac4ab98b3 (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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
using System;
using System.Collections.Generic;
using KKSG;
using UILib;
using UnityEngine;
using XMainClient.UI.UICommon;
using XUtliPoolLib;

namespace XMainClient.UI
{
	internal class CharacterEquipBagHandler : DlgHandlerBase
	{
		private XBagWindow bagWindow
		{
			get
			{
				return DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton.BagWindow;
			}
		}

		private XItemMorePowerfulTipMgr powerfullMgr
		{
			get
			{
				return DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton.RedPointMgr;
			}
		}

		private XItemMorePowerfulTipMgr newItemMgr
		{
			get
			{
				return DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton.NewItemMgr;
			}
		}

		protected override string FileName
		{
			get
			{
				return "ItemNew/EquipListPanel";
			}
		}

		private XCharacterEquipDocument _doc;

		private EnhanceMasterHandler m_EnhanceMasterHandler;

		private GameObject m_topGo;

		private IXUILabel m_masterHisMaxLevelLab;

		private IXUIButton m_mastetBtn;

		private IXUIButton m_BtnShowAttr;

		private IXUIButton m_BtnShowTitle;

		private GameObject m_TitleRedPoint;

		private IXUIButton m_Help;

		private IXUILabel m_bagNumLab;

		private List<int> m_RedPointEquipPosList = new List<int>();

		public IXUIButton m_expandBagBtn;

		protected override void Init()
		{
			base.Init();
			this._doc = (XSingleton<XGame>.singleton.Doc.GetXComponent(XCharacterEquipDocument.uuID) as XCharacterEquipDocument);
			this._doc.Handler = this;
			this.m_topGo = base.PanelObject.transform.Find("Top").gameObject;
			this.m_masterHisMaxLevelLab = (base.PanelObject.transform.Find("Top/Lab").GetComponent("XUILabel") as IXUILabel);
			this.m_mastetBtn = (base.PanelObject.transform.Find("Top/Btn").GetComponent("XUIButton") as IXUIButton);
			this.m_BtnShowAttr = (base.transform.Find("ShowAttr").GetComponent("XUIButton") as IXUIButton);
			this.m_BtnShowTitle = (base.transform.Find("ShowTitle").GetComponent("XUIButton") as IXUIButton);
			this.m_TitleRedPoint = base.transform.Find("ShowTitle/RedPoint").gameObject;
			this.m_Help = (base.transform.Find("Help").GetComponent("XUIButton") as IXUIButton);
			this.m_bagNumLab = (base.PanelObject.transform.Find("BagNum").GetComponent("XUILabel") as IXUILabel);
			this.m_expandBagBtn = (base.PanelObject.transform.Find("add").GetComponent("XUIButton") as IXUIButton);
			BagExpandItemListTable.RowData expandItemConfByType = XBagDocument.GetExpandItemConfByType((uint)XFastEnumIntEqualityComparer<BagType>.ToInt(BagType.EquipBag));
			this.m_expandBagBtn.gameObject.SetActive(expandItemConfByType != null);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_mastetBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnShowEnhanceMaster));
			this.m_BtnShowAttr.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnShowAttrClick));
			this.m_BtnShowTitle.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnShowTitleClick));
			this.m_Help.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnHelpClicked));
			this.m_expandBagBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnBagExpandClicked));
		}

		public bool OnHelpClicked(IXUIButton button)
		{
			DlgBase<XCommonHelpTipView, XCommonHelpTipBehaviour>.singleton.ShowHelp(XSysDefine.XSys_Item_Equip);
			return true;
		}

		public override void StackRefresh()
		{
			base.StackRefresh();
			this.RefreshBag();
			this._doc.NewItems.bCanClear = true;
		}

		protected override void OnShow()
		{
			base.OnShow();
			this.RefreshBag();
			this.ShowEnhanceMasterLevel();
			this._doc.NewItems.bCanClear = true;
			bool flag = this.m_EnhanceMasterHandler != null;
			if (flag)
			{
				this.m_EnhanceMasterHandler.SetVisible(false);
			}
			this.RefreshRedPoints();
			this.RefreshTitleRedPoint();
			this.SetBagNum();
		}

		public void RefreshRedPoints()
		{
			bool flag = DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton.IsVisible() && DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler != null;
			if (flag)
			{
				this.m_RedPointEquipPosList.Clear();
				XEnhanceDocument specificDocument = XDocuments.GetSpecificDocument<XEnhanceDocument>(XEnhanceDocument.uuID);
				bool flag2 = XSingleton<XGameSysMgr>.singleton.IsSystemOpened(XSysDefine.XSys_Item_Enhance);
				if (flag2)
				{
					for (int i = 0; i < specificDocument.MorePowerfulEquips.Count; i++)
					{
						this.m_RedPointEquipPosList.Add(specificDocument.MorePowerfulEquips[i]);
					}
				}
				XSmeltDocument doc = XSmeltDocument.Doc;
				doc.GetRedDotEquips();
				bool flag3 = XSingleton<XGameSysMgr>.singleton.IsSystemOpened(XSysDefine.XSys_Item_Smelting);
				if (flag3)
				{
					for (int j = 0; j < doc.MorePowerfulEquips.Count; j++)
					{
						bool flag4 = !this.m_RedPointEquipPosList.Contains(doc.MorePowerfulEquips[j]);
						if (flag4)
						{
							this.m_RedPointEquipPosList.Add(doc.MorePowerfulEquips[j]);
						}
					}
				}
				bool flag5 = XSingleton<XGameSysMgr>.singleton.IsSystemOpened(XSysDefine.XSys_Item_Enchant);
				if (flag5)
				{
					XEnchantDocument specificDocument2 = XDocuments.GetSpecificDocument<XEnchantDocument>(XEnchantDocument.uuID);
					for (int k = 0; k < XBagDocument.EquipMax; k++)
					{
						bool flag6 = specificDocument2.RedPointStates[k];
						if (flag6)
						{
							this.m_RedPointEquipPosList.Add(k);
						}
					}
				}
				DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.SetArrows(this.m_RedPointEquipPosList);
			}
		}

		public void RefreshTitleRedPoint()
		{
			this.m_BtnShowTitle.SetVisible(XSingleton<XGameSysMgr>.singleton.IsSystemOpened(XSysDefine.XSys_Title));
			XTitleDocument specificDocument = XDocuments.GetSpecificDocument<XTitleDocument>(XTitleDocument.uuID);
			this.m_TitleRedPoint.SetActive(specificDocument.bEnableTitleLevelUp);
		}

		protected override void OnHide()
		{
			this.powerfullMgr.ReturnAll();
			this.newItemMgr.ReturnAll();
			this.bagWindow.OnHide();
			this._doc.NewItems.TryClear();
			base.OnHide();
		}

		private void RefreshBag()
		{
			this.bagWindow.ChangeData(new ItemUpdateHandler(this.WrapContentItemUpdated), new GetItemHandler(this._doc.GetEquips));
			DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.RegisterItemClickEvents(null);
			this.bagWindow.OnShow();
			this.SetBagNum();
		}

		public override void OnUnload()
		{
			this._doc.Handler = null;
			DlgHandlerBase.EnsureUnload<EnhanceMasterHandler>(ref this.m_EnhanceMasterHandler);
			base.OnUnload();
		}

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

		public void Refresh()
		{
			this.bagWindow.RefreshWindow();
			this.SetBagNum();
		}

		public void ShowEnhanceMasterLevel()
		{
			bool flag = !XSingleton<XGameSysMgr>.singleton.IsSystemOpened(XSysDefine.XSys_Item_Enhance);
			if (flag)
			{
				this.m_topGo.SetActive(false);
			}
			else
			{
				this.m_topGo.SetActive(true);
				this.m_masterHisMaxLevelLab.SetText(string.Format(XStringDefineProxy.GetString("EnhanceMasterLevel"), XEnhanceDocument.Doc.HistoryMaxLevel));
			}
		}

		private void SetBagNum()
		{
			int count = this._doc.GetEquips().Count;
			XRechargeDocument specificDocument = XDocuments.GetSpecificDocument<XRechargeDocument>(XRechargeDocument.uuID);
			VIPTable.RowData byVIP = specificDocument.VIPReader.GetByVIP((int)specificDocument.VipLevel);
			bool flag = byVIP != null;
			if (flag)
			{
				uint num = byVIP.EquipMax;
				BagExpandData bagExpandData = XBagDocument.BagDoc.GetBagExpandData(BagType.EquipBag);
				bool flag2 = bagExpandData != null;
				if (flag2)
				{
					num += bagExpandData.ExpandNum;
				}
				bool flag3 = (long)count >= (long)((ulong)num);
				if (flag3)
				{
					this.m_bagNumLab.SetText(string.Format("[ff4366]{0}[-]/{1}", count, num));
				}
				else
				{
					this.m_bagNumLab.SetText(string.Format("{0}[-]/{1}", count, num));
				}
			}
		}

		private void WrapContentItemUpdated(Transform t, int index)
		{
			Transform transform = t.Find("Icon/SupplementBrought");
			bool flag = transform != null;
			if (flag)
			{
				transform.gameObject.SetActive(false);
			}
			IXUISprite ixuisprite = t.Find("Icon").GetComponent("XUISprite") as IXUISprite;
			bool flag2 = this.bagWindow.m_XItemList == null || index >= this.bagWindow.m_XItemList.Count || index < 0;
			if (flag2)
			{
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(t.gameObject, null);
				this.powerfullMgr.ReturnInstance(ixuisprite);
				this.newItemMgr.ReturnInstance(ixuisprite);
				t.gameObject.name = XSingleton<XCommon>.singleton.StringCombine("empty", index.ToString());
			}
			else
			{
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(t.gameObject, this.bagWindow.m_XItemList[index]);
				ixuisprite.ID = this.bagWindow.m_XItemList[index].uid;
				ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnItemClicked));
				t.gameObject.name = XSingleton<XCommon>.singleton.StringCombine("equip", this.bagWindow.m_XItemList[index].itemID.ToString());
				EquipCompare mix = this._doc.IsEquipMorePowerful(ixuisprite.ID);
				EquipCompare final = XCharacterEquipDocument.GetFinal(mix);
				bool flag3 = final == EquipCompare.EC_MORE_POWERFUL;
				if (flag3)
				{
					this.powerfullMgr.SetTip(ixuisprite);
				}
				else
				{
					this.powerfullMgr.ReturnInstance(ixuisprite);
				}
				bool flag4 = this._doc.NewItems.IsNew(ixuisprite.ID);
				if (flag4)
				{
					this.newItemMgr.SetTip(ixuisprite);
				}
				else
				{
					this.newItemMgr.ReturnInstance(ixuisprite);
				}
			}
		}

		public void LoadEquip(XItem item, int slot)
		{
			DlgBase<EquipTooltipDlg, EquipTooltipDlgBehaviour>.singleton.HideToolTip(true);
			bool flag = DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler != null && DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.IsVisible();
			if (flag)
			{
				DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.SetEquipSlot(slot, item);
			}
			this.Refresh();
		}

		public void UnloadEquip(int slot)
		{
			DlgBase<EquipTooltipDlg, EquipTooltipDlgBehaviour>.singleton.HideToolTip(true);
			bool flag = DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler != null && DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.IsVisible();
			if (flag)
			{
				DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.SetEquipSlot(slot, null);
			}
			this.Refresh();
		}

		public void AddItem(List<XItem> items)
		{
			this.bagWindow.UpdateBag();
			this.SetBagNum();
		}

		public void RemoveItem(List<ulong> uids)
		{
			this.bagWindow.UpdateBag();
			this.SetBagNum();
			foreach (ulong num in uids)
			{
				bool flag = num == DlgBase<EquipTooltipDlg, EquipTooltipDlgBehaviour>.singleton.MainItemUID;
				if (flag)
				{
					DlgBase<EquipTooltipDlg, EquipTooltipDlgBehaviour>.singleton.HideToolTip(false);
				}
			}
		}

		public void ItemNumChanged(XItem item)
		{
			this.bagWindow.UpdateItem(item);
			this.SetBagNum();
		}

		public void SwapItem(XItem item1, XItem item2, int slot)
		{
			DlgBase<EquipTooltipDlg, EquipTooltipDlgBehaviour>.singleton.HideToolTip(true);
			bool flag = DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler != null && DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.IsVisible();
			if (flag)
			{
				DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.SetEquipSlot(slot, item1);
			}
			this.bagWindow.ReplaceItem(item1, item2);
		}

		public void UpdateItem(XItem item)
		{
			this.bagWindow.UpdateItem(item);
			DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._equipHandler.UpdateEquipSlot(item);
			bool flag = item.uid == DlgBase<EquipTooltipDlg, EquipTooltipDlgBehaviour>.singleton.MainItemUID;
			if (flag)
			{
				DlgBase<EquipTooltipDlg, EquipTooltipDlgBehaviour>.singleton.HideToolTip(false);
			}
			bool flag2 = item.uid == DlgBase<ItemTooltipDlg, ItemTooltipDlgBehaviour>.singleton.MainItemUID;
			if (flag2)
			{
				DlgBase<ItemTooltipDlg, ItemTooltipDlgBehaviour>.singleton.HideToolTip(true);
			}
		}

		private void _OnItemClicked(IXUISprite iSp)
		{
			XItem itemByUID = XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemByUID(iSp.ID);
			bool flag = itemByUID == null;
			if (!flag)
			{
				bool flag2 = this._doc.NewItems.RemoveItem(iSp.ID, itemByUID.Type, false);
				if (flag2)
				{
					this._doc.GetEquips();
				}
				CharacterEquipHandler.OnItemClicked(iSp);
			}
		}

		private bool OnShowEnhanceMaster(IXUIButton btn)
		{
			DlgHandlerBase.EnsureCreate<EnhanceMasterHandler>(ref this.m_EnhanceMasterHandler, base.PanelObject.transform.parent.parent.Find("LeftPanel"), true, this);
			return true;
		}

		private bool OnShowAttrClick(IXUIButton btn)
		{
			DlgBase<ItemSystemDlg, TabDlgBehaviour>.singleton._CharacterAttrHandler.SetVisible(true);
			return true;
		}

		private bool OnShowTitleClick(IXUIButton btn)
		{
			DlgBase<TitleDlg, TitleDlgBehaviour>.singleton.SetVisibleWithAnimation(true, null);
			return true;
		}

		public bool OnBagExpandClicked(IXUIButton button)
		{
			XBagDocument.BagDoc.UseBagExpandTicket(BagType.EquipBag);
			return true;
		}
	}
}