diff options
Diffstat (limited to 'Client/Assembly-CSharp/PlayerVoteArea.cs')
-rw-r--r-- | Client/Assembly-CSharp/PlayerVoteArea.cs | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/PlayerVoteArea.cs b/Client/Assembly-CSharp/PlayerVoteArea.cs new file mode 100644 index 0000000..d23a2a0 --- /dev/null +++ b/Client/Assembly-CSharp/PlayerVoteArea.cs @@ -0,0 +1,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)); + } +} |