summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/XMainClient/RecruitStepCounter.cs
blob: 03faddad1202c8e09ecddd92fbedc6193682f4a9 (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
using System;
using UILib;

namespace XMainClient
{
	internal class RecruitStepCounter : DlgHandlerBase
	{
		public int Step
		{
			get
			{
				return this.limit_step;
			}
		}

		public int Cur
		{
			get
			{
				return this.limit_cur;
			}
		}

		private IXUIButton m_AddBtn;

		private IXUIButton m_MinusBtn;

		private IXUILabel m_timeLabel;

		private int limit_max = 0;

		private int limit_min = 0;

		private int limit_normal = 0;

		private int limit_cur = 0;

		private int limit_step = 0;

		private RecruitStepCounterUpdate m_counter;

		public int GetTime()
		{
			return this.limit_step * this.limit_cur;
		}

		protected override void Init()
		{
			base.Init();
			this.m_AddBtn = (base.transform.Find("Add").GetComponent("XUIButton") as IXUIButton);
			this.m_MinusBtn = (base.transform.Find("Minus").GetComponent("XUIButton") as IXUIButton);
			this.m_timeLabel = (base.transform.Find("buynum").GetComponent("XUILabel") as IXUILabel);
		}

		public override void RegisterEvent()
		{
			base.RegisterEvent();
			this.m_AddBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnAddClick));
			this.m_MinusBtn.RegisterClickEventHandler(new ButtonClickEventHandler(this.OnMinusBtn));
		}

		private bool OnAddClick(IXUIButton btn)
		{
			bool flag = this.limit_max == -1;
			if (flag)
			{
				this.limit_cur += this.limit_step;
			}
			else
			{
				bool flag2 = this.limit_cur < this.limit_max - this.limit_step;
				if (flag2)
				{
					this.limit_cur += this.limit_step;
				}
				else
				{
					this.limit_cur = this.limit_max - this.limit_step;
				}
			}
			this.Excute();
			return true;
		}

		private bool OnMinusBtn(IXUIButton btn)
		{
			bool flag = this.limit_min == -1;
			if (flag)
			{
				this.limit_cur -= this.limit_step;
			}
			else
			{
				bool flag2 = this.limit_cur - this.limit_step > this.limit_min;
				if (flag2)
				{
					this.limit_cur -= this.limit_step;
				}
				else
				{
					this.limit_cur = this.limit_min;
				}
			}
			this.Excute();
			return true;
		}

		public void Setup(int min, int max, int cur, int step = 1, RecruitStepCounterUpdate counter = null)
		{
			this.limit_max = max;
			this.limit_min = min;
			this.limit_normal = cur;
			this.limit_step = step;
			this.limit_cur = cur;
			this.m_counter = counter;
			this.Excute();
		}

		private void Excute()
		{
			bool flag = this.m_counter != null;
			if (flag)
			{
				this.m_counter(this.m_timeLabel);
			}
		}
	}
}