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

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

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

		public List<MailItem> mails = new List<MailItem>();

		private int currPage = 0;

		private int pagesCnt = 1;

		public ulong select_mail = 0UL;

		public const int PERCNT = 7;

		public string valit;

		protected override void OnReconnected(XReconnectedEventArgs arg)
		{
			bool flag = DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton.IsVisible();
			if (flag)
			{
				this.ReqMailInfo();
			}
		}

		public override void OnAttachToHost(XObject host)
		{
			base.OnAttachToHost(host);
			this.mails.Clear();
		}

		public void ReqMailInfo()
		{
			RpcC2M_FetchMail rpcC2M_FetchMail = new RpcC2M_FetchMail();
			rpcC2M_FetchMail.oArg.page = (uint)this.currPage;
			rpcC2M_FetchMail.oArg.count = 7u;
			XSingleton<XClientNetwork>.singleton.Send(rpcC2M_FetchMail);
		}

		public void ResMailInfo(FetchMailRes res)
		{
			this.currPage = (int)res.page;
			this.pagesCnt = (int)res.pagecount;
			this.mails.Clear();
			for (int i = 0; i < res.mails.Count; i++)
			{
				SMail smail = res.mails[i];
				MailItem mailItem = new MailItem();
				mailItem.id = smail.uid;
				mailItem.isRead = smail.isread;
				mailItem.state = (MailState)smail.state;
				mailItem.type = (MailType)smail.type;
				mailItem.isTemp = smail.istemplate;
				mailItem.title = this.FormatStringLength(smail.title, 28);
				mailItem.date = this.UnixDate(smail.timestamp);
				mailItem.content = smail.content;
				bool flag = mailItem.items == null;
				if (flag)
				{
					mailItem.items = new List<ItemBrief>();
				}
				bool flag2 = mailItem.xitems == null;
				if (flag2)
				{
					mailItem.xitems = new List<Item>();
				}
				mailItem.items.Clear();
				for (int j = 0; j < smail.items.Count; j++)
				{
					mailItem.items.Add(smail.items[j]);
				}
				for (int k = 0; k < smail.xitems.Count; k++)
				{
					mailItem.xitems.Add(smail.xitems[k]);
				}
				mailItem.valit = smail.timeleft;
				this.mails.Add(mailItem);
			}
			bool flag3 = DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._systemFrameView != null && DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._systemFrameView.IsVisible();
			if (flag3)
			{
				DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._systemFrameView.Refresh();
			}
		}

		public void ReqMailOP(MailOP type, ulong uid)
		{
			this.ReqMailOP(type, new List<ulong>
			{
				uid
			});
		}

		public void ReqMailOP(MailOP type, List<ulong> uid)
		{
			RpcC2M_MailOp rpcC2M_MailOp = new RpcC2M_MailOp();
			rpcC2M_MailOp.oArg.uid.Clear();
			foreach (ulong num in uid)
			{
				MailItem mailItem = this.Find(num);
				rpcC2M_MailOp.oArg.uid.Add(num);
			}
			rpcC2M_MailOp.oArg.optype = (uint)type;
			XSingleton<XClientNetwork>.singleton.Send(rpcC2M_MailOp);
		}

		private MailItem Find(ulong id)
		{
			for (int i = 0; i < this.mails.Count; i++)
			{
				bool flag = this.mails[i].id == id;
				if (flag)
				{
					return this.mails[i];
				}
			}
			return null;
		}

		public void ResMailOP(MailOpArg req, MailOpRes res)
		{
			bool flag = DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton.IsVisible();
			if (flag)
			{
				bool flag2 = req.optype == 0u;
				if (flag2)
				{
					ulong id = req.uid[0];
					MailItem mailItem = this.Find(id);
					bool flag3 = mailItem != null;
					if (flag3)
					{
						mailItem.isRead = true;
						bool flag4 = DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._systemFrameView.IsVisible();
						if (flag4)
						{
							DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._systemFrameView.RefreshItems();
						}
					}
				}
				else
				{
					bool flag5 = req.optype == 2u;
					if (flag5)
					{
						ulong id2 = req.uid[0];
						MailItem mailItem2 = this.Find(id2);
						bool flag6 = mailItem2 != null;
						if (flag6)
						{
							mailItem2.state = MailState.CLAIMED;
							bool flag7 = DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._contMailView.IsVisible();
							if (flag7)
							{
								DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._contMailView.Refresh();
							}
							bool flag8 = DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._systemFrameView.IsVisible();
							if (flag8)
							{
								DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._systemFrameView.RefreshItems();
							}
						}
					}
					else
					{
						this.ReqMailInfo();
					}
				}
			}
		}

		private DateTime UnixDate(uint sp)
		{
			DateTime minValue = DateTime.MinValue;
			return TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(sp);
		}

		private void Sort()
		{
			this.mails.Sort(new Comparison<MailItem>(this.SortMethod));
		}

		private int SortMethod(ulong _x, ulong _y)
		{
			MailItem x = this.Find(_x);
			MailItem y = this.Find(_y);
			return this.SortMethod(x, y);
		}

		private int SortMethod(MailItem x, MailItem y)
		{
			bool flag = x == null || y == null;
			int result;
			if (flag)
			{
				result = 0;
			}
			else
			{
				TimeSpan timeSpan = x.date - y.date;
				bool flag2 = timeSpan.TotalSeconds < 0.0;
				if (flag2)
				{
					result = -1;
				}
				else
				{
					bool flag3 = timeSpan.TotalSeconds == 0.0;
					if (flag3)
					{
						result = 0;
					}
					else
					{
						result = 1;
					}
				}
			}
			return result;
		}

		public void SetSelect(ulong id)
		{
			this.select_mail = id;
		}

		public void RefreshContentNil()
		{
			this.select_mail = 0UL;
			DlgBase<MailSystemDlg, TabDlgBehaviour>.singleton._contMailView.Refresh();
		}

		public bool CtlPage(bool add)
		{
			bool flag = !add;
			bool result;
			if (flag)
			{
				bool flag2 = this.currPage > 0;
				if (flag2)
				{
					this.currPage--;
					this.ReqMailInfo();
					result = true;
				}
				else
				{
					result = false;
				}
			}
			else
			{
				bool flag3 = this.currPage < this.pagesCnt - 1;
				if (flag3)
				{
					this.currPage++;
					this.ReqMailInfo();
					result = true;
				}
				else
				{
					result = false;
				}
			}
			return result;
		}

		public string GetPageFormat()
		{
			return string.Format("{0}/{1}", this.currPage + 1, Math.Max(1, this.pagesCnt));
		}

		public bool ShowMailContent()
		{
			return this.select_mail != 0UL && this.Find(this.select_mail) != null;
		}

		public MailItem GetMailItem()
		{
			return this.Find(this.select_mail);
		}

		public MailItem GetMailItem(ulong id)
		{
			return this.Find(id);
		}

		public string FormatStringLength(string str, int displayLength)
		{
			string result = string.Empty;
			int byteCount = Encoding.Default.GetByteCount(str);
			bool flag = byteCount > displayLength;
			if (flag)
			{
				displayLength -= 3;
				int num = 0;
				int num2 = 0;
				byte[] bytes = Encoding.Unicode.GetBytes(str);
				while (num2 < bytes.GetLength(0) && num < displayLength)
				{
					bool flag2 = num2 % 2 == 0;
					if (flag2)
					{
						num++;
					}
					else
					{
						bool flag3 = bytes[num2] > 0;
						if (flag3)
						{
							num++;
						}
					}
					num2++;
				}
				bool flag4 = num2 % 2 == 1;
				if (flag4)
				{
					bool flag5 = bytes[num2] > 0;
					if (flag5)
					{
						num2--;
					}
					else
					{
						num2++;
					}
				}
				result = Encoding.Unicode.GetString(bytes, 0, num2) + "...";
			}
			else
			{
				result = str;
			}
			return result;
		}
	}
}