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

namespace XMainClient.UI
{
	internal class BattleStatisticsHandler : DlgHandlerBase
	{
		protected override string FileName
		{
			get
			{
				return "Battle/BattleStatistics";
			}
		}

		private XCombatStatisticsDocument doc;

		private IXUIScrollView m_ScrollView;

		private IXUIWrapContent m_WrapContent;

		private IXUILabel m_Total;

		private IXUISprite m_BtnHelp;

		private IXUISprite m_BtnReset;

		private GameObject m_HelpFrame;

		private IXUILabel m_LabelHelp;

		private float m_Timer = 0f;

		private static float REFRESH_INTERVAL = 1f;

		protected override void Init()
		{
			base.Init();
			this.doc = XDocuments.GetSpecificDocument<XCombatStatisticsDocument>(XCombatStatisticsDocument.uuID);
			this.doc.StatisticsHandler = this;
			this.m_ScrollView = (base.PanelObject.transform.Find("Bg/ScrollView").GetComponent("XUIScrollView") as IXUIScrollView);
			this.m_WrapContent = (this.m_ScrollView.gameObject.transform.Find("WrapContent").GetComponent("XUIWrapContent") as IXUIWrapContent);
			this.m_Total = (base.PanelObject.transform.Find("Bg/Total").GetComponent("XUILabel") as IXUILabel);
			this.m_HelpFrame = base.PanelObject.transform.Find("Bg/HelpsFrame").gameObject;
			this.m_LabelHelp = (this.m_HelpFrame.transform.Find("Helps").GetComponent("XUILabel") as IXUILabel);
			this.m_LabelHelp.SetText(XSingleton<UiUtility>.singleton.ReplaceReturn(XStringDefineProxy.GetString("BATTLE_STATISTICS_HELP")));
			this.m_BtnHelp = (base.PanelObject.transform.Find("Bg/BtnHelp").GetComponent("XUISprite") as IXUISprite);
			this.m_BtnReset = (base.PanelObject.transform.Find("Bg/BtnReset").GetComponent("XUISprite") as IXUISprite);
			this.m_HelpFrame.SetActive(false);
		}

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

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_WrapContent.RegisterItemUpdateEventHandler(new WrapItemUpdateEventHandler(this._WrapContentItemUpdated));
			this.m_BtnHelp.RegisterSpritePressEventHandler(new SpritePressEventHandler(this._OnHelpClicked));
			this.m_BtnReset.RegisterSpriteClickEventHandler(new SpriteClickEventHandler(this._OnResetClicked));
		}

		protected override void OnShow()
		{
			base.OnShow();
			this.RefreshData();
			bool flag = DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded() && DlgBase<BattleMain, BattleMainBehaviour>.singleton.TeamMonitor != null;
			if (flag)
			{
				DlgBase<BattleMain, BattleMainBehaviour>.singleton.TeamMonitor.TemporarilyHide(true);
			}
		}

		protected override void OnHide()
		{
			base.OnHide();
			bool flag = DlgBase<BattleMain, BattleMainBehaviour>.singleton.IsLoaded() && DlgBase<BattleMain, BattleMainBehaviour>.singleton.TeamMonitor != null;
			if (flag)
			{
				DlgBase<BattleMain, BattleMainBehaviour>.singleton.TeamMonitor.TemporarilyHide(false);
			}
		}

		public override void OnUpdate()
		{
			base.OnUpdate();
			float time = Time.time;
			bool flag = time - this.m_Timer > BattleStatisticsHandler.REFRESH_INTERVAL;
			if (flag)
			{
				this.m_Timer = time;
				this.doc.ReqStatistics();
			}
		}

		public override void RefreshData()
		{
			base.RefreshData();
			this.m_WrapContent.SetContentCount(this.doc.StatisticsList.Count, false);
			this.m_Total.SetText(XSingleton<UiUtility>.singleton.NumberFormat((ulong)this.doc.TotalDamage));
		}

		private void _WrapContentItemUpdated(Transform t, int index)
		{
			bool flag = index < 0 || index >= this.doc.StatisticsList.Count;
			if (!flag)
			{
				XCombatStatisticsInfo xcombatStatisticsInfo = this.doc.StatisticsList[index];
				bool flag2 = xcombatStatisticsInfo == null;
				if (!flag2)
				{
					IXUILabel ixuilabel = t.Find("Name").GetComponent("XUILabel") as IXUILabel;
					IXUILabel ixuilabel2 = t.Find("Count").GetComponent("XUILabel") as IXUILabel;
					IXUILabel ixuilabel3 = t.Find("Value").GetComponent("XUILabel") as IXUILabel;
					IXUILabel ixuilabel4 = t.Find("Percentage").GetComponent("XUILabel") as IXUILabel;
					ulong num = (ulong)xcombatStatisticsInfo.value;
					ixuilabel.SetText(xcombatStatisticsInfo.name);
					bool flag3 = xcombatStatisticsInfo.count > 999;
					if (flag3)
					{
						ixuilabel2.SetText("...");
					}
					else
					{
						bool flag4 = num != 0UL && xcombatStatisticsInfo.count == 0;
						if (flag4)
						{
							ixuilabel2.SetText("1");
						}
						else
						{
							ixuilabel2.SetText(xcombatStatisticsInfo.count.ToString());
						}
					}
					ixuilabel3.SetText(XSingleton<UiUtility>.singleton.NumberFormat(num));
					ixuilabel4.SetText(string.Format("{0}%", (int)(xcombatStatisticsInfo.percent * 100f)));
				}
			}
		}

		private bool _OnHelpClicked(IXUISprite iSp, bool isPressed)
		{
			this.m_HelpFrame.SetActive(isPressed);
			return true;
		}

		private void _OnResetClicked(IXUISprite iSp)
		{
			this.doc.ResetStatistics();
			this.doc.ReqStatistics();
		}
	}
}