summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/PlayerVoteArea.cs
blob: d23a2a01e49a854253f7672e49819d71d0005d62 (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
using System;
using System.Collections;
using Hazel;
using UnityEngine;

public class PlayerVoteArea : MonoBehaviour
{
	public MeetingHud Parent { get; set; }

	public sbyte TargetPlayerId;

	public const byte DeadBit = 128;

	public const byte VotedBit = 64;

	public const byte ReportedBit = 32;

	public const byte VoteMask = 15;

	public GameObject Buttons;

	public SpriteRenderer PlayerIcon;

	public SpriteRenderer Flag;

	public SpriteRenderer Megaphone;

	public SpriteRenderer Overlay;

	public TextRenderer NameText;

	public bool isDead;

	public bool didVote;

	public bool didReport;

	public sbyte votedFor;

	public bool voteComplete;

	public bool resultsShowing;

	public void SetDead(bool isMe, bool didReport, bool isDead)
	{
		this.isDead = isDead;
		this.didReport = didReport;
		this.Megaphone.enabled = didReport;
		this.Overlay.gameObject.SetActive(false);
		this.Overlay.transform.GetChild(0).gameObject.SetActive(isDead);
	}

	public void SetDisabled()
	{
		if (this.isDead)
		{
			return;
		}
		if (this.Overlay)
		{
			this.Overlay.gameObject.SetActive(true);
			this.Overlay.transform.GetChild(0).gameObject.SetActive(false);
			return;
		}
		base.GetComponent<SpriteRenderer>().enabled = false;
	}

	public void SetEnabled()
	{
		if (this.isDead)
		{
			return;
		}
		if (this.Overlay)
		{
			this.Overlay.gameObject.SetActive(false);
			return;
		}
		base.GetComponent<SpriteRenderer>().enabled = true;
	}

	public IEnumerator CoAnimateOverlay()
	{
		this.Overlay.gameObject.SetActive(this.isDead);
		if (this.isDead)
		{
			Transform xMark = this.Overlay.transform.GetChild(0);
			this.Overlay.color = Palette.ClearWhite;
			xMark.localScale = Vector3.zero;
			float fadeDuration = 0.5f;
			for (float t = 0f; t < fadeDuration; t += Time.deltaTime)
			{
				this.Overlay.color = Color.Lerp(Palette.ClearWhite, Color.white, t / fadeDuration);
				yield return null;
			}
			this.Overlay.color = Color.white;
			float scaleDuration = 0.15f;
			for (float t = 0f; t < scaleDuration; t += Time.deltaTime)
			{
				float num = Mathf.Lerp(3f, 1f, t / scaleDuration);
				xMark.transform.localScale = new Vector3(num, num, num);
				yield return null;
			}
			xMark.transform.localScale = Vector3.one;
			xMark = null;
		}
		else if (this.didReport)
		{
			float scaleDuration = 1f;
			for (float fadeDuration = 0f; fadeDuration < scaleDuration; fadeDuration += Time.deltaTime)
			{
				float num2 = fadeDuration / scaleDuration;
				float num3 = PlayerVoteArea.TriangleWave(num2 * 3f) * 2f - 1f;
				this.Megaphone.transform.localEulerAngles = new Vector3(0f, 0f, num3 * 30f);
				num3 = Mathf.Lerp(0.7f, 1.2f, PlayerVoteArea.TriangleWave(num2 * 2f));
				this.Megaphone.transform.localScale = new Vector3(num3, num3, num3);
				yield return null;
			}
			this.Megaphone.transform.localEulerAngles = Vector3.zero;
			this.Megaphone.transform.localScale = Vector3.one;
		}
		yield break;
	}

	private static float TriangleWave(float t)
	{
		t -= (float)((int)t);
		if (t < 0.5f)
		{
			return t * 2f;
		}
		return 1f - (t - 0.5f) * 2f;
	}

	internal void SetVote(sbyte suspectIdx)
	{
		this.didVote = true;
		this.votedFor = suspectIdx;
		this.Flag.enabled = true;
	}

	public void UnsetVote()
	{
		this.Flag.enabled = false;
		this.votedFor = 0;
		this.didVote = false;
	}

	public void ClearButtons()
	{
		this.Buttons.SetActive(false);
	}

	public void ClearForResults()
	{
		this.resultsShowing = true;
		this.Flag.enabled = false;
	}

	public void VoteForMe()
	{
		if (!this.voteComplete)
		{
			this.Parent.Confirm(this.TargetPlayerId);
		}
	}

	public void Select()
	{
		if (PlayerControl.LocalPlayer.Data.IsDead)
		{
			return;
		}
		if (this.isDead)
		{
			return;
		}
		if (!this.voteComplete && this.Parent.Select((int)this.TargetPlayerId))
		{
			this.Buttons.SetActive(true);
		}
	}

	public void Cancel()
	{
		this.Buttons.SetActive(false);
	}

	public void Serialize(MessageWriter writer)
	{
		byte state = this.GetState();
		writer.Write(state);
	}

	public void Deserialize(MessageReader reader)
	{
		byte b = reader.ReadByte();
		this.votedFor = (sbyte)((b & 15) - 1);
		this.isDead = ((b & 128) > 0);
		this.didVote = ((b & 64) > 0);
		this.didReport = ((b & 32) > 0);
		this.Flag.enabled = (this.didVote && !this.resultsShowing);
		this.Overlay.gameObject.SetActive(this.isDead);
		this.Megaphone.enabled = this.didReport;
	}

	public byte GetState()
	{
		return (byte)((int)(this.votedFor + 1 & 15) | (this.isDead ? 128 : 0) | (this.didVote ? 64 : 0) | (this.didReport ? 32 : 0));
	}
}