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

namespace XMainClient
{
	internal class XRecycleItemDocument : XDocComponent
	{
		public override uint ID
		{
			get
			{
				return XRecycleItemDocument.uuID;
			}
		}

		public RecycleItemOperateView OperateView { get; set; }

		public RecycleItemBagView BagView { get; set; }

		public XSysDefine CurrentSys { get; set; }

		public Dictionary<ulong, ulong> SelectedItems
		{
			get
			{
				return this.m_SelectedItems;
			}
		}

		public bool IsSelectionFull
		{
			get
			{
				return (long)this.m_SelectedItems.Count >= (long)((ulong)XRecycleItemDocument.MAX_RECYCLE_COUNT);
			}
		}

		public new static readonly uint uuID = XSingleton<XCommon>.singleton.XHash("RecycleItemDocument");

		public static readonly uint MAX_RECYCLE_COUNT = 5u;

		private Dictionary<ulong, ulong> m_SelectedItems = new Dictionary<ulong, ulong>();

		private List<XItem> m_ItemList = new List<XItem>();

		protected override void EventSubscribe()
		{
			base.EventSubscribe();
			base.RegisterEvent(XEventDefine.XEvent_ItemChangeFinished, new XComponent.XEventHandler(this.OnItemChangeFinished));
		}

		protected bool OnItemChangeFinished(XEventArgs args)
		{
			bool flag = this.BagView != null && this.BagView.active;
			if (flag)
			{
				this.BagView.UpdateView();
			}
			return true;
		}

		public void RefreshUI()
		{
			bool flag = this.BagView != null && this.BagView.active;
			if (flag)
			{
				this.BagView.Refresh();
			}
			bool flag2 = this.OperateView != null && this.OperateView.active;
			if (flag2)
			{
				this.OperateView.Refresh();
			}
		}

		public List<XItem> GetItems()
		{
			this.m_ItemList.Clear();
			for (int i = 0; i < XBagDocument.BagDoc.ItemBag.Count; i++)
			{
				bool flag = XBagDocument.BagDoc.ItemBag[i].itemConf.IsCanRecycle == 1;
				if (flag)
				{
					this.m_ItemList.Add(XBagDocument.BagDoc.ItemBag[i]);
				}
			}
			return this.m_ItemList;
		}

		public void GetQuickSelectItems(int mask)
		{
			List<XItem> items = this.GetItems();
			this.ResetSelection(false);
			foreach (XItem xitem in items)
			{
				ItemList.RowData itemConf = XBagDocument.GetItemConf(xitem.itemID);
				int num = 1 << (int)itemConf.ItemQuality;
				bool flag = (num & mask) == 0;
				if (!flag)
				{
					bool flag2 = xitem.itemCount > 1;
					if (!flag2)
					{
						this._ToggleItemSelect(true, xitem.uid, 1UL, false);
						bool isSelectionFull = this.IsSelectionFull;
						if (isSelectionFull)
						{
							break;
						}
					}
				}
			}
			this.RefreshUI();
		}

		public void ResetSelection(bool bRefreshUI)
		{
			this.m_SelectedItems.Clear();
			if (bRefreshUI)
			{
				this.RefreshUI();
			}
		}

		public bool IsSelected(ulong uid, out int leftCount)
		{
			leftCount = 0;
			XItem itemByUID = XBagDocument.BagDoc.GetItemByUID(uid);
			bool flag = this.m_SelectedItems.ContainsKey(uid);
			bool result;
			if (flag)
			{
				bool flag2 = itemByUID != null;
				if (flag2)
				{
					leftCount = itemByUID.itemCount - (int)this.m_SelectedItems[uid];
					leftCount = ((leftCount < 0) ? 0 : leftCount);
				}
				result = true;
			}
			else
			{
				bool flag3 = itemByUID != null;
				if (flag3)
				{
					leftCount = itemByUID.itemCount;
				}
				result = false;
			}
			return result;
		}

		private bool IsSelectFull(ulong uid)
		{
			bool flag = this.m_SelectedItems.ContainsKey(uid);
			bool result;
			if (flag)
			{
				XItem itemByUID = XBagDocument.BagDoc.GetItemByUID(uid);
				bool flag2 = itemByUID != null;
				if (flag2)
				{
					result = (itemByUID.itemCount > 999);
				}
				else
				{
					this.m_SelectedItems.Remove(uid);
					result = false;
				}
			}
			else
			{
				result = this.IsSelectionFull;
			}
			return result;
		}

		public int GetSelectUidCount(ulong uid)
		{
			ulong num = 0UL;
			this.m_SelectedItems.TryGetValue(uid, out num);
			return (int)num;
		}

		public void ToggleItemSelect(ulong uid)
		{
			XItem itemByUID = XBagDocument.BagDoc.GetItemByUID(uid);
			bool flag = itemByUID != null;
			if (flag)
			{
				bool flag2 = itemByUID.itemCount == 1;
				if (flag2)
				{
					this._ToggleItemSelect(true, uid, 1UL, true);
				}
				else
				{
					bool flag3 = !this.IsSelectFull(uid);
					if (flag3)
					{
						DlgBase<SelectNumFrameDlg, SelectNumFrameBehaviour>.singleton.Show(uid);
					}
				}
			}
		}

		public void ToggleItemUnSelect(ulong uid)
		{
			bool flag = this.m_SelectedItems.ContainsKey(uid);
			if (flag)
			{
				this._ToggleItemSelect(false, uid, this.m_SelectedItems[uid], true);
			}
		}

		public void _ToggleItemSelect(bool select, ulong uid, ulong count, bool bRefreshUI)
		{
			bool flag = false;
			if (select)
			{
				bool isSelectionFull = this.IsSelectionFull;
				if (isSelectionFull)
				{
					bool flag2 = this.m_SelectedItems.ContainsKey(uid);
					if (flag2)
					{
						Dictionary<ulong, ulong> selectedItems = this.m_SelectedItems;
						selectedItems[uid] += count;
						this.m_SelectedItems[uid] = ((this.m_SelectedItems[uid] >= 999UL) ? 999UL : this.m_SelectedItems[uid]);
						flag = true;
					}
				}
				else
				{
					bool flag3 = this.m_SelectedItems.ContainsKey(uid);
					if (flag3)
					{
						Dictionary<ulong, ulong> selectedItems = this.m_SelectedItems;
						selectedItems[uid] += count;
						this.m_SelectedItems[uid] = ((this.m_SelectedItems[uid] >= 999UL) ? 999UL : this.m_SelectedItems[uid]);
					}
					else
					{
						this.m_SelectedItems.Add(uid, count);
					}
					flag = true;
				}
			}
			else
			{
				flag = this.m_SelectedItems.Remove(uid);
			}
			bool flag4 = flag && bRefreshUI;
			if (flag4)
			{
				bool flag5 = this.BagView != null && this.BagView.active;
				if (flag5)
				{
					this.BagView.Refresh();
				}
				bool flag6 = this.OperateView != null && this.OperateView.active;
				if (flag6)
				{
					bool flag7 = this.m_SelectedItems.ContainsKey(uid);
					if (flag7)
					{
						this.OperateView.ToggleItem(uid, this.m_SelectedItems[uid], select);
					}
					else
					{
						this.OperateView.ToggleItem(uid, 1UL, select);
					}
				}
			}
		}

		public void Recycle()
		{
			bool flag = this.m_SelectedItems.Count == 0;
			if (!flag)
			{
				RpcC2G_DecomposeEquipment rpcC2G_DecomposeEquipment = new RpcC2G_DecomposeEquipment();
				foreach (KeyValuePair<ulong, ulong> keyValuePair in this.m_SelectedItems)
				{
					rpcC2G_DecomposeEquipment.oArg.equipuniqueid.Add(keyValuePair.Key);
					rpcC2G_DecomposeEquipment.oArg.count.Add((uint)keyValuePair.Value);
				}
				XSingleton<XClientNetwork>.singleton.Send(rpcC2G_DecomposeEquipment);
				this.ResetSelection(false);
				bool flag2 = this.OperateView != null && this.OperateView.active;
				if (flag2)
				{
					this.OperateView.Refresh();
				}
			}
		}

		public void OnRecycle(DecomposeEquipmentRes oRes)
		{
			bool flag = oRes.ErrorCode > ErrorCode.ERR_SUCCESS;
			if (flag)
			{
				XSingleton<UiUtility>.singleton.ShowSystemTip(oRes.ErrorCode, "fece00");
			}
			else
			{
				bool flag2 = oRes.param.Count > 0 && oRes.param[0] > 1f;
				if (flag2)
				{
					bool flag3 = this.OperateView != null && this.OperateView.active;
					if (flag3)
					{
						this.OperateView.PlayCritical();
					}
				}
			}
		}

		protected override void OnReconnected(XReconnectedEventArgs arg)
		{
			bool flag = this.BagView != null && this.BagView.active;
			if (flag)
			{
				this.BagView.Refresh();
			}
			bool flag2 = this.OperateView != null && this.OperateView.active;
			if (flag2)
			{
				this.OperateView.Refresh();
			}
		}
	}
}