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

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

		private XEnchantDocument _doc = null;

		private IXUIWrapContent _wrapContent;

		private IXUIScrollView _scrollView;

		private uint _curSelectedAttribute;

		private XEnchantInfo _curEnchantInfo;

		private GameObject _uiEquipItem;

		private GameObject _emptyTag;

		protected override void Init()
		{
			base.Init();
			this.InitProperties();
		}

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

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

		protected override void OnHide()
		{
			base.OnHide();
		}

		public override void OnUnload()
		{
			this._doc._EnchantActiveHandler = null;
			base.OnUnload();
		}

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

		public override void RefreshData()
		{
			base.RefreshData();
			XEquipItem xequipItem = XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemByUID(this._doc.SelectedEquipUID) as XEquipItem;
			bool flag = xequipItem == null;
			if (!flag)
			{
				this._curSelectedAttribute = xequipItem.enchantInfo.ChooseAttr;
				this._curEnchantInfo = xequipItem.enchantInfo;
				this._wrapContent.SetContentCount(this._curEnchantInfo.AttrList.Count, false);
				this._scrollView.ResetPosition();
				this._emptyTag.SetActive(this._curEnchantInfo.AttrList.Count == 0);
				XSingleton<XItemDrawerMgr>.singleton.DrawItem(this._uiEquipItem, xequipItem);
			}
		}

		private void SetChooseAttrItem()
		{
			List<GameObject> list = new List<GameObject>();
			this._wrapContent.GetActiveList(list);
			for (int i = 0; i < list.Count; i++)
			{
				IXUICheckBox ixuicheckBox = list[i].GetComponent("XUICheckBox") as IXUICheckBox;
				bool flag = ixuicheckBox.ID == (ulong)this._curEnchantInfo.ChooseAttr;
				if (flag)
				{
					ixuicheckBox.bChecked = true;
					break;
				}
			}
		}

		private void InitProperties()
		{
			this._doc = XDocuments.GetSpecificDocument<XEnchantDocument>(XEnchantDocument.uuID);
			this._doc._EnchantActiveHandler = this;
			this._scrollView = (base.transform.Find("BagPanel").GetComponent("XUIScrollView") as IXUIScrollView);
			this._wrapContent = (base.transform.Find("BagPanel/WrapContent").GetComponent("XUIWrapContent") as IXUIWrapContent);
			this._wrapContent.RegisterItemInitEventHandler(new WrapItemInitEventHandler(this.WrapContentInit));
			this._wrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this.WrapContentUpdate));
			IXUIButton ixuibutton = base.transform.Find("BtnOk").GetComponent("XUIButton") as IXUIButton;
			ixuibutton.RegisterClickEventHandler(new ButtonClickEventHandler(this.ConfirmActiveAttribute));
			this._uiEquipItem = base.transform.Find("Top/EquipItem").gameObject;
			IXUISprite ixuisprite = this._uiEquipItem.transform.Find("Icon").GetComponent("XUISprite") as IXUISprite;
			ixuisprite.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnEquipIconClicked));
			IXUISprite ixuisprite2 = base.transform.Find("Close").GetComponent("XUISprite") as IXUISprite;
			ixuisprite2.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this.OnClose));
			this._emptyTag = base.transform.Find("Empty").gameObject;
		}

		private void OnClose(IXUISprite uiSprite)
		{
			base.SetVisible(false);
		}

		private bool ConfirmActiveAttribute(IXUIButton button)
		{
			bool flag = this._curSelectedAttribute == 0u || this._curSelectedAttribute == this._curEnchantInfo.ChooseAttr;
			bool result;
			if (flag)
			{
				result = true;
			}
			else
			{
				this._doc.SendEnchantActiveAttribute(this._curSelectedAttribute);
				result = true;
			}
			return result;
		}

		private void _OnEquipIconClicked(IXUISprite iSp)
		{
			XSingleton<UiUtility>.singleton.ShowTooltipDialog(XSingleton<XGame>.singleton.Doc.XBagDoc.GetItemByUID(this._doc.SelectedEquipUID), null, iSp, false, 0u);
		}

		private void WrapContentUpdate(Transform itemTransform, int index)
		{
			bool flag = index >= this._curEnchantInfo.AttrList.Count;
			if (!flag)
			{
				XItemChangeAttr xitemChangeAttr = this._curEnchantInfo.AttrList[index];
				uint attrID = xitemChangeAttr.AttrID;
				uint attrValue = xitemChangeAttr.AttrValue;
				IXUICheckBox ixuicheckBox = itemTransform.GetComponent("XUICheckBox") as IXUICheckBox;
				ixuicheckBox.ID = (ulong)attrID;
				IXUILabel ixuilabel = itemTransform.Find("Attr").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel2 = itemTransform.Find("Attr/Value").GetComponent("XUILabel") as IXUILabel;
				IXUILabel ixuilabel3 = itemTransform.Find("PPT").GetComponent("XUILabel") as IXUILabel;
				ixuilabel.SetText(XAttributeCommon.GetAttrStr((int)attrID));
				ixuilabel2.SetText("+" + attrValue);
				bool flag2 = this._curSelectedAttribute == attrID;
				if (flag2)
				{
					ixuicheckBox.bChecked = true;
				}
				else
				{
					ixuicheckBox.ForceSetFlag(false);
				}
				double ppt = XSingleton<XPowerPointCalculator>.singleton.GetPPT(attrID, attrValue, null, -1);
				ixuilabel3.SetText(((int)ppt).ToString());
			}
		}

		private void WrapContentInit(Transform itemTransform, int index)
		{
			IXUICheckBox ixuicheckBox = itemTransform.GetComponent("XUICheckBox") as IXUICheckBox;
			ixuicheckBox.RegisterOnCheckEventHandler(new CheckBoxOnCheckEventHandler(this.OnSelectAttributeItem));
		}

		private bool OnSelectAttributeItem(IXUICheckBox iXUICheckBox)
		{
			bool flag = !iXUICheckBox.bChecked;
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				this._curSelectedAttribute = (uint)iXUICheckBox.ID;
				result = true;
			}
			return result;
		}
	}
}