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

namespace XMainClient.UI
{
	internal class XNpcAttrHandler : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "GameSystem/NPCBlessing/NpcAttrHandler";
			}
		}

		private XNPCFavorDocument m_doc;

		private IXUIList m_BasicUIList;

		private XUIPool m_BasicAttrPool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		private IXUIList m_OtherUIList;

		private XUIPool m_OtherAttrPool = new XUIPool(XSingleton<XGameUI>.singleton.m_uiTool);

		protected override void Init()
		{
			base.Init();
			this.m_doc = XDocuments.GetSpecificDocument<XNPCFavorDocument>(XNPCFavorDocument.uuID);
			this.m_BasicUIList = (base.transform.Find("AttrGrid").GetComponent("XUIList") as IXUIList);
			Transform transform = this.m_BasicUIList.gameObject.transform.Find("Tpl");
			this.m_BasicAttrPool.SetupPool(this.m_BasicUIList.gameObject, transform.gameObject, 10u, false);
			transform.gameObject.SetActive(false);
			this.m_OtherUIList = (base.transform.Find("NoBasicAttrGrid").GetComponent("XUIList") as IXUIList);
			Transform transform2 = this.m_OtherUIList.gameObject.transform.Find("Tpl");
			this.m_OtherAttrPool.SetupPool(this.m_OtherUIList.gameObject, transform2.gameObject, 5u, false);
			transform2.gameObject.SetActive(false);
		}

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

		public override void RefreshData()
		{
			this.RefreshAttr();
		}

		private void RefreshAttr()
		{
			this.m_BasicAttrPool.FakeReturnAll();
			this.m_OtherAttrPool.FakeReturnAll();
			Dictionary<uint, uint> dictSumAttr = this.m_doc.DictSumAttr;
			foreach (KeyValuePair<uint, uint> keyValuePair in dictSumAttr)
			{
				uint key = keyValuePair.Key;
				//Dictionary<uint, uint>.Enumerator enumerator;
				//keyValuePair = enumerator.Current;
				uint value = keyValuePair.Value;
				bool flag = XAttributeCommon.IsBasicRange((int)key);
				GameObject gameObject;
				if (flag)
				{
					gameObject = this.m_BasicAttrPool.FetchGameObject(false);
					gameObject.transform.parent = this.m_BasicUIList.gameObject.transform;
				}
				else
				{
					gameObject = this.m_OtherAttrPool.FetchGameObject(false);
					gameObject.transform.parent = this.m_OtherUIList.gameObject.transform;
				}
				gameObject.transform.localScale = Vector3.one;
				this.DrawAttr(gameObject.transform, key, value);
			}
			this.m_BasicAttrPool.ActualReturnAll(false);
			this.m_OtherAttrPool.ActualReturnAll(false);
			this.m_BasicUIList.Refresh();
			this.m_OtherUIList.Refresh();
		}

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

		private void DrawAttr(Transform item, uint attrId, uint attrValue)
		{
			IXUILabel ixuilabel = item.Find("Name").GetComponent("XUILabel") as IXUILabel;
			IXUILabel ixuilabel2 = item.Find("Value").GetComponent("XUILabel") as IXUILabel;
			ixuilabel.SetText(XAttributeCommon.GetAttrStr((int)attrId));
			ixuilabel2.SetText(XAttributeCommon.GetAttrValueStr(attrId, attrValue, true));
		}
	}
}