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

namespace XMainClient.UI
{
	internal class HomeSeedBagHandler : DlgHandlerBase
	{
		private HomePlantDocument m_doc
		{
			get
			{
				return HomePlantDocument.Doc;
			}
		}

		private bool m_bIsPlayingAction
		{
			get
			{
				return DlgBase<HomePlantDlg, HomePlantBehaviour>.singleton.IsPlayingAction;
			}
			set
			{
				DlgBase<HomePlantDlg, HomePlantBehaviour>.singleton.IsPlayingAction = value;
			}
		}

		protected override string FileName
		{
			get
			{
				return "Home/SeedBag";
			}
		}

		private IXUIWrapContent m_wrapContent;

		private GameObject m_hadSeedGo;

		private GameObject m_noSeddGo;

		private GameObject m_ItemGo;

		private GameObject m_tplGo;

		private GameObject m_noSeedTipsGo;

		private IXUILabel m_describeLab;

		private IXUILabel m_timeLab;

		private IXUILabel m_harvestLab;

		private IXUIButton m_plantBtn;

		private IXUIButton m_gotoShopBtn;

		private IXUILabel m_sprNameLab;

		private XBagWindow m_bagWindow;

		private XItemSelector _ItemSelector = new XItemSelector(0u);

		private uint m_token;

		private float m_plantActionTime = 2.5f;

		private float m_fCoolTime = 3f;

		private float m_fLastClickBtnTime = 0f;

		protected override void Init()
		{
			this.m_hadSeedGo = base.PanelObject.transform.Find("HadSeed").gameObject;
			this.m_noSeddGo = base.PanelObject.transform.Find("NoSeed").gameObject;
			this.m_noSeedTipsGo = this.m_noSeddGo.transform.Find("tip").gameObject;
			Transform transform = this.m_hadSeedGo.transform.Find("ItemView");
			this.m_ItemGo = transform.Find("Item").gameObject;
			this.m_describeLab = (transform.Find("Panel/Describe").GetComponent("XUILabel") as IXUILabel);
			this.m_timeLab = (transform.Find("time").GetComponent("XUILabel") as IXUILabel);
			this.m_harvestLab = (transform.Find("harvest").GetComponent("XUILabel") as IXUILabel);
			this.m_sprNameLab = (transform.Find("Name").GetComponent("XUILabel") as IXUILabel);
			transform = this.m_hadSeedGo.transform.Find("Items/Panel/WrapContent");
			this.m_wrapContent = (transform.GetComponent("XUIWrapContent") as IXUIWrapContent);
			this.m_wrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this.WrapContentItemUpdated));
			this.m_tplGo = this.m_hadSeedGo.transform.Find("Items").gameObject;
			this.m_plantBtn = (this.m_hadSeedGo.transform.Find("BtnPlant").GetComponent("XUIButton") as IXUIButton);
			this.m_gotoShopBtn = (this.m_noSeddGo.transform.Find("BtnShop").GetComponent("XUIButton") as IXUIButton);
			this.m_bagWindow = new XBagWindow(this.m_tplGo, null, null);
			this.m_bagWindow.Init();
			base.Init();
		}

		public override void RegisterEvent()
		{
			this.m_gotoShopBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickGoToShopBtn));
			base.RegisterEvent();
		}

		protected override void OnShow()
		{
			base.OnShow();
			this.m_bIsPlayingAction = false;
			this.FillContent();
		}

		protected override void OnHide()
		{
			this.m_bagWindow.OnHide();
			this._ItemSelector.Hide();
			this.m_bIsPlayingAction = false;
			base.OnHide();
		}

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

		public override void OnUnload()
		{
			this._ItemSelector.Unload();
			base.OnUnload();
		}

		public void RefreshUI()
		{
			this.FillContent();
		}

		private void FillContent()
		{
			this.m_doc.GetHadSeedList();
			bool flag = this.m_doc.HadSeedList == null || this.m_doc.HadSeedList.Count == 0;
			if (flag)
			{
				this.m_noSeddGo.SetActive(true);
				this.m_hadSeedGo.SetActive(false);
				this.m_gotoShopBtn.gameObject.SetActive(this.m_doc.HomeType != HomeTypeEnum.GuildHome);
				this.m_noSeedTipsGo.SetActive(this.m_doc.HomeType != HomeTypeEnum.GuildHome);
			}
			else
			{
				this.m_noSeddGo.SetActive(false);
				this.m_hadSeedGo.SetActive(true);
				this.m_bagWindow.ChangeData(new ItemUpdateHandler(this.WrapContentItemUpdated), new GetItemHandler(this.m_doc.GetHadSeedsList));
				this.m_bagWindow.OnShow();
			}
		}

		private void WrapContentItemUpdated(Transform t, int index)
		{
			bool flag = this.m_doc.HadSeedList == null;
			if (flag)
			{
				XSingleton<XDebug>.singleton.AddErrorLog("no data", null, null, null, null, null);
			}
			else
			{
				bool flag2 = index >= this.m_doc.HadSeedList.Count;
				if (flag2)
				{
					XSingleton<XItemDrawerMgr>.singleton.DrawItem(t.gameObject, null);
				}
				else
				{
					IXUISprite ixuisprite = t.Find("Icon").GetComponent("XUISprite") as IXUISprite;
					XItem xitem = this.m_doc.HadSeedList[index];
					XSingleton<XItemDrawerMgr>.singleton.DrawItem(t.gameObject, xitem);
					ixuisprite.ID = xitem.uid;
					ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnItemClicked));
					bool flag3 = index == 0;
					if (flag3)
					{
						this.OnItemClicked(ixuisprite);
					}
				}
			}
		}

		private void FillSeedInfo(XItem item)
		{
			ItemList.RowData itemConf = XBagDocument.GetItemConf(item.itemID);
			bool flag = itemConf != null;
			if (flag)
			{
				this.m_describeLab.SetText(XSingleton<UiUtility>.singleton.ReplaceReturn(itemConf.ItemDescription));
			}
			else
			{
				this.m_describeLab.SetText(string.Empty);
			}
			PlantSeed.RowData bySeedID = HomePlantDocument.PlantSeedTable.GetBySeedID((uint)item.itemID);
			bool flag2 = bySeedID != null;
			if (flag2)
			{
				this.m_sprNameLab.SetText(bySeedID.SeedName);
				this.m_timeLab.SetText(this.GetTimeString((ulong)bySeedID.PredictGrowUpTime));
				this.m_harvestLab.SetText(bySeedID.PlantID[1].ToString());
				XSingleton<XItemDrawerMgr>.singleton.normalItemDrawer.DrawItem(this.m_ItemGo, bySeedID.PlantID[0], 0, false);
				IXUISprite ixuisprite = this.m_ItemGo.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
				ixuisprite.ID = (ulong)((long)bySeedID.PlantID[0]);
				ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(XSingleton<UiUtility>.singleton.OnItemClick));
			}
			else
			{
				this.m_sprNameLab.SetText("");
				this.m_timeLab.SetText("");
				this.m_harvestLab.SetText("");
			}
			this.m_plantBtn.ID = (ulong)((long)item.itemID);
			this.m_plantBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnClickPlantBtn));
		}

		private string GetTimeString(ulong ti)
		{
			bool flag = ti < 60UL;
			string result;
			if (flag)
			{
				string text = string.Format("{0}{1}", ti, XStringDefineProxy.GetString("MINUTE_DUARATION"));
				result = text;
			}
			else
			{
				ulong num = ti / 60UL;
				ulong num2 = ti % 60UL;
				bool flag2 = num2 > 0UL;
				string text;
				if (flag2)
				{
					text = string.Format("{0}{1}{2}{3}", new object[]
					{
						num,
						XStringDefineProxy.GetString("HOUR_DUARATION"),
						num2,
						XStringDefineProxy.GetString("MINUTE_DUARATION")
					});
				}
				else
				{
					text = string.Format("{0}{1}", num, XStringDefineProxy.GetString("HOUR_DUARATION"));
				}
				result = text;
			}
			return result;
		}

		private bool OnClickPlantBtn(IXUIButton btn)
		{
			bool flag = this.SetButtonCool(this.m_fCoolTime);
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				Farmland farmland = this.m_doc.GetFarmland(this.m_doc.CurFarmlandId);
				bool flag2 = farmland == null || !farmland.IsFree;
				if (flag2)
				{
					result = true;
				}
				else
				{
					bool bIsPlayingAction = this.m_bIsPlayingAction;
					if (bIsPlayingAction)
					{
						result = true;
					}
					else
					{
						List<XItem> hadSeedsList = this.m_doc.GetHadSeedsList();
						bool flag3 = hadSeedsList == null || hadSeedsList.Count == 0;
						if (flag3)
						{
							XSingleton<UiUtility>.singleton.ShowSystemTip(XStringDefineProxy.GetString("ERR_GARDEN_NOSEED"), "fece00");
							result = true;
						}
						else
						{
							bool flag4 = XSingleton<XEntityMgr>.singleton.Player == null;
							if (flag4)
							{
								result = true;
							}
							else
							{
								bool flag5 = !XOutlookHelper.CanPlaySpecifiedAnimation(XSingleton<XEntityMgr>.singleton.Player);
								if (flag5)
								{
									result = true;
								}
								else
								{
									this.m_bIsPlayingAction = true;
									XSingleton<XEntityMgr>.singleton.Player.PlaySpecifiedAnimation(this.m_doc.GetHomePlantAction(ActionType.Plant));
									XSingleton<XTimerMgr>.singleton.KillTimer(this.m_token);
									this.m_token = XSingleton<XTimerMgr>.singleton.SetTimer(this.m_plantActionTime, new XTimerMgr.ElapsedEventHandler(this.QequestPlant), (uint)btn.ID);
									XSingleton<XFxMgr>.singleton.CreateAndPlay(HomePlantDocument.PlantEffectPath, XSingleton<XEntityMgr>.singleton.Player.EngineObject, Vector3.zero, Vector3.one, 1f, false, this.m_plantActionTime, true);
									XSingleton<XAudioMgr>.singleton.PlayUISound("Audio/UI/Farm_Planting", true, AudioChannel.Action);
									result = true;
								}
							}
						}
					}
				}
			}
			return result;
		}

		private bool SetButtonCool(float time)
		{
			float num = Time.realtimeSinceStartup - this.m_fLastClickBtnTime;
			bool flag = num < time;
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				this.m_fLastClickBtnTime = Time.realtimeSinceStartup;
				result = false;
			}
			return result;
		}

		public void QequestPlant(object o = null)
		{
			XSingleton<XEntityMgr>.singleton.Player.PlayStateBack();
			bool flag = o != null;
			if (flag)
			{
				this.m_doc.StartPlant(this.m_doc.CurFarmlandId, (uint)o, false);
			}
			this.m_bIsPlayingAction = false;
		}

		private bool OnClickGoToShopBtn(IXUIButton btn)
		{
			HomeTypeEnum homeType = this.m_doc.HomeType;
			bool flag = homeType == HomeTypeEnum.GuildHome;
			if (flag)
			{
				XGuildDocument specificDocument = XDocuments.GetSpecificDocument<XGuildDocument>(XGuildDocument.uuID);
				bool flag2 = !specificDocument.CheckInGuild();
				if (flag2)
				{
					return true;
				}
				bool flag3 = !specificDocument.CheckUnlockLevel(XSysDefine.XSys_GuildBoon_Shop);
				if (flag3)
				{
					return true;
				}
				DlgBase<HomePlantDlg, HomePlantBehaviour>.singleton.SetVisible(false, true);
				DlgBase<MallSystemDlg, MallSystemBehaviour>.singleton.ShowShopSystem(XSysDefine.XSys_Mall_Guild, 0UL);
			}
			else
			{
				DlgBase<HomePlantDlg, HomePlantBehaviour>.singleton.SetVisible(false, true);
				DlgBase<MallSystemDlg, MallSystemBehaviour>.singleton.ShowShopSystem(XSysDefine.XSys_Mall_Home, 0UL);
			}
			return true;
		}

		private void OnItemClicked(IXUISprite iSp)
		{
			XItem itemByUID = XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemByUID(iSp.ID);
			bool flag = itemByUID == null;
			if (!flag)
			{
				this.FillSeedInfo(itemByUID);
				this._ItemSelector.Select(iSp);
			}
		}
	}
}