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

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

		private XJadeDocument _doc = null;

		public GameObject m_ComposeMenu;

		public IXUIButton m_BtnComposeOne;

		public IXUILabel m_ComposeMenuTitle;

		public IXUILabel m_ComposeCost;

		public uint BtnComposeID;

		public IXUIButton m_BtnCompose;

		public IXUICheckBox m_ComposeMax;

		public IXUICheckBox m_ComposeOne;

		public GameObject m_IconComposeSource;

		public GameObject m_IconComposeTarget;

		private int _sourceID;

		private int _sourceCount;

		private int _requiredCount;

		private int _targetID;

		private int _sourceBindCount;

		private int _useCount;

		protected override void Init()
		{
			base.Init();
			this._doc = XDocuments.GetSpecificDocument<XJadeDocument>(XJadeDocument.uuID);
			this.m_ComposeMenu = base.PanelObject.transform.Find("ComposeMenu").gameObject;
			this.m_IconComposeSource = this.m_ComposeMenu.transform.Find("SourceJade/JadeTpl").gameObject;
			this.m_IconComposeTarget = this.m_ComposeMenu.transform.Find("TargetJade/JadeTpl").gameObject;
			this.m_ComposeCost = (this.m_ComposeMenu.transform.Find("Cost").GetComponent("XUILabel") as IXUILabel);
			this.m_BtnComposeOne = (this.m_ComposeMenu.transform.Find("BtnComposeOne").GetComponent("XUIButton") as IXUIButton);
			this.m_BtnCompose = (this.m_ComposeMenu.transform.Find("BtnCompose").GetComponent("XUIButton") as IXUIButton);
			this.m_ComposeMax = (this.m_ComposeMenu.transform.Find("ComposeMax").GetComponent("XUICheckBox") as IXUICheckBox);
			this.m_ComposeOne = (this.m_ComposeMenu.transform.Find("ComposeOne").GetComponent("XUICheckBox") as IXUICheckBox);
			this.m_ComposeMenuTitle = (this.m_ComposeMenu.transform.Find("Title").GetComponent("XUILabel") as IXUILabel);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_BtnComposeOne.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnComposeJadeEquipClicked));
			this.m_BtnCompose.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnOnComposeJadeBagClicked));
			this.m_ComposeMax.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnComposeMaxCheckBoxClicked));
			this.m_ComposeOne.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnComposeOneCheckBoxClicked));
			IXUIButton ixuibutton = this.m_ComposeMenu.transform.Find("Close").GetComponent("XUIButton") as IXUIButton;
			ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnComposeCloseClicked));
		}

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

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

		private void _OnCloseClicked(IXUISprite iSp)
		{
			base.SetVisible(false);
		}

		public void ToggleComposeMenu(bool open, int type = 0, int sourceID = 0, int sourceCount = 0, int requiredCount = 0, int targetID = 0, int sourceBindCount = -1)
		{
			base.SetVisible(open);
			if (open)
			{
				this._sourceID = sourceID;
				this._sourceCount = sourceCount;
				this._requiredCount = requiredCount;
				this._targetID = targetID;
				this._sourceBindCount = sourceBindCount;
				bool flag = type == -1;
				if (flag)
				{
					this.m_ComposeMax.gameObject.SetActive(true);
					this.m_ComposeOne.gameObject.SetActive(true);
					this.m_BtnCompose.gameObject.SetActive(true);
					this.m_BtnComposeOne.gameObject.SetActive(false);
					this.DrawComposeItem(true);
					this.m_ComposeMax.bChecked = true;
					this.m_BtnCompose.ID = 1UL;
				}
				else
				{
					bool flag2 = type >= 0;
					if (flag2)
					{
						this.m_ComposeMax.gameObject.SetActive(false);
						this.m_ComposeOne.gameObject.SetActive(false);
						this.m_BtnCompose.gameObject.SetActive(false);
						this.m_BtnComposeOne.gameObject.SetActive(true);
						this.DrawComposeItem(false);
						this.m_BtnComposeOne.ID = (ulong)((long)type);
					}
				}
			}
		}

		protected bool OnComposeCloseClicked(IXUIButton btn)
		{
			this.ToggleComposeMenu(false, 0, 0, 0, 0, 0, -1);
			return true;
		}

		protected bool OnComposeJadeEquipClicked(IXUIButton btn)
		{
			this.ToggleComposeMenu(false, 0, 0, 0, 0, 0, -1);
			return true;
		}

		private bool _Compose(IXUIButton btn)
		{
			bool flag = this.BtnComposeID == 1u;
			if (flag)
			{
				this.ToggleComposeMenu(false, 0, 0, 0, 0, 0, -1);
			}
			XSingleton<UiUtility>.singleton.CloseModalDlg();
			return true;
		}

		private bool _NoCompose(IXUIButton btn)
		{
			return true;
		}

		protected bool OnOnComposeJadeBagClicked(IXUIButton btn)
		{
			this.BtnComposeID = (uint)btn.ID;
			bool flag = false;
			bool flag2 = false;
			XJadeDocument specificDocument = XDocuments.GetSpecificDocument<XJadeDocument>(XJadeDocument.uuID);
			JadeTable.RowData byJadeID = specificDocument.jadeTable.GetByJadeID((uint)this._sourceID);
			bool flag3 = XSingleton<XAttributeMgr>.singleton.XPlayerData == null;
			bool result;
			if (flag3)
			{
				result = false;
			}
			else
			{
				uint level = XSingleton<XAttributeMgr>.singleton.XPlayerData.Level;
				int num = specificDocument.JadeLevelToMosaicLevel(byJadeID.JadeLevel + 1u);
				bool flag4 = (long)num > (long)((ulong)level) && !DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.GetTempTip(XTempTipDefine.OD_JADE_UPGRADE_NO_EQUIP);
				if (flag4)
				{
					flag2 = true;
				}
				bool flag5 = this._sourceBindCount < this._useCount && this._sourceBindCount < this._sourceCount && this._useCount <= this._sourceCount && !DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.GetTempTip(XTempTipDefine.OD_JADE_UPGRADE_NO_BIND);
				if (flag5)
				{
					flag = true;
				}
				bool flag6 = flag2 && !flag;
				if (flag6)
				{
					XSingleton<UiUtility>.singleton.ShowModalDialog(string.Format(XStringDefineProxy.GetString("JADE_COMPOSE_TIP_EQUIP"), num), XStringDefineProxy.GetString("COMMON_OK"), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this._Compose), null, false, XTempTipDefine.OD_JADE_UPGRADE_NO_EQUIP, 50);
					result = false;
				}
				else
				{
					bool flag7 = !flag2 && flag;
					if (flag7)
					{
						XSingleton<UiUtility>.singleton.ShowModalDialog(string.Format(XStringDefineProxy.GetString("JADE_COMPOSE_TIP_BIND"), new object[0]), XStringDefineProxy.GetString("COMMON_OK"), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this._Compose), null, false, XTempTipDefine.OD_JADE_UPGRADE_NO_BIND, 50);
						result = false;
					}
					else
					{
						bool flag8 = flag2 && flag;
						if (flag8)
						{
							XSingleton<UiUtility>.singleton.ShowModalDialog(string.Format(XStringDefineProxy.GetString("JADE_COMPOSE_TIP_BIND_EQUIP"), num), XStringDefineProxy.GetString("COMMON_OK"), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this._Compose));
							result = false;
						}
						else
						{
							bool flag9 = this.BtnComposeID == 1u;
							if (flag9)
							{
								this.ToggleComposeMenu(false, 0, 0, 0, 0, 0, -1);
							}
							result = true;
						}
					}
				}
			}
			return result;
		}

		protected bool OnComposeAllClicked(IXUIButton btn)
		{
			XSingleton<UiUtility>.singleton.ShowModalDialog(XStringDefineProxy.GetString("JADE_DIALOG_COMPOSE_ALL"), XStringDefineProxy.GetString("COMMON_OK"), XStringDefineProxy.GetString("COMMON_CANCEL"), new ButtonClickEventHandler(this._DoComposeAll));
			return true;
		}

		private bool _DoComposeAll(IXUIButton btn)
		{
			DlgBase<ModalDlg, ModalDlgBehaviour>.singleton.SetVisible(false, true);
			return true;
		}

		private bool OnComposeOneCheckBoxClicked(IXUICheckBox box)
		{
			bool flag = !box.bChecked;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.m_BtnCompose.ID = 0UL;
				this.DrawComposeItem(false);
				result = true;
			}
			return result;
		}

		private bool OnComposeMaxCheckBoxClicked(IXUICheckBox box)
		{
			bool flag = !box.bChecked;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this.m_BtnCompose.ID = 1UL;
				this.DrawComposeItem(true);
				result = true;
			}
			return result;
		}

		private bool DrawComposeItem(bool isAll)
		{
			int num2;
			int num3;
			if (isAll)
			{
				bool flag = this._requiredCount == 0;
				if (flag)
				{
					XSingleton<XDebug>.singleton.AddErrorLog("Jade RequiredCount Is 0", null, null, null, null, null);
				}
				int num = this._sourceCount / this._requiredCount;
				bool flag2 = num == 0;
				if (flag2)
				{
					num = 1;
				}
				num2 = num * this._requiredCount;
				num3 = num;
				this._useCount = num2;
			}
			else
			{
				num2 = this._requiredCount;
				num3 = 1;
				this._useCount = num2;
			}
			JadeTable.RowData byJadeID = this._doc.jadeTable.GetByJadeID((uint)this._sourceID);
			bool flag3 = (ulong)byJadeID.JadeLevel < (ulong)((long)this._doc.JadeLevelUpCost.Length);
			if (flag3)
			{
				int num4 = this._doc.JadeLevelUpCost[(int)byJadeID.JadeLevel] * num3;
				this.m_ComposeCost.SetText(num4.ToString());
			}
			else
			{
				this.m_ComposeCost.SetText("");
				XSingleton<XDebug>.singleton.AddErrorLog("Jade Level Up Cost No Find!\nJade Level:" + byJadeID.JadeLevel + 1, null, null, null, null, null);
			}
			XSingleton<XItemDrawerMgr>.singleton.jadeItemDrawer.DrawItem(this.m_IconComposeSource, this._sourceID, num2, true, this._sourceCount);
			XSingleton<XItemDrawerMgr>.singleton.jadeItemDrawer.DrawItem(this.m_IconComposeTarget, this._targetID, num3, true);
			XJadeItem jade = XBagDocument.MakeXItem(this._sourceID, false) as XJadeItem;
			XJadeItem jade2 = XBagDocument.MakeXItem(this._targetID, false) as XJadeItem;
			JadeEquipHandler.DrawAttr(this.m_IconComposeSource.gameObject.transform.parent.gameObject, jade);
			JadeEquipHandler.DrawAttr(this.m_IconComposeTarget.gameObject.transform.parent.gameObject, jade2);
			return true;
		}

		public void RefreshComposeItem()
		{
			bool activeSelf = this.m_ComposeMenu.activeSelf;
			if (activeSelf)
			{
				this._sourceCount = (int)XBagDocument.BagDoc.GetItemCount(this._sourceID);
				this._sourceBindCount = (int)XBagDocument.BagDoc.GetItemCount(this._sourceID, true);
				this.DrawComposeItem(false);
			}
		}
	}
}