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

public abstract class Minigame : MonoBehaviour
{
	public global::Console Console { get; set; }

	protected int ConsoleId
	{
		get
		{
			if (!this.Console)
			{
				return 0;
			}
			return this.Console.ConsoleId;
		}
	}

	public static Minigame Instance;

	public const float Depth = -50f;

	public TransitionType TransType;

	protected PlayerTask MyTask;

	protected NormalPlayerTask MyNormTask;

	protected Minigame.CloseState amClosing;

	public AudioClip OpenSound;

	public AudioClip CloseSound;

	protected enum CloseState
	{
		None,
		Waiting,
		Closing
	}

	public virtual void Begin(PlayerTask task)
	{
		Minigame.Instance = this;
		this.MyTask = task;
		this.MyNormTask = (task as NormalPlayerTask);
		if (PlayerControl.LocalPlayer)
		{
			if (MapBehaviour.Instance)
			{
				MapBehaviour.Instance.Close();
			}
			PlayerControl.LocalPlayer.NetTransform.Halt();
		}
		base.StartCoroutine(this.CoAnimateOpen());
	}

	protected IEnumerator CoStartClose(float duration = 0.75f)
	{
		if (this.amClosing != Minigame.CloseState.None)
		{
			yield break;
		}
		this.amClosing = Minigame.CloseState.Waiting;
		yield return Effects.Wait(duration);
		this.Close();
		yield break;
	}

	[Obsolete("Don't use, I just don't want to reselect the close button event handlers", true)]
	public void Close(bool allowMovement)
	{
		this.Close();
	}

	public virtual void Close()
	{
		if (this.amClosing != Minigame.CloseState.Closing)
		{
			if (this.CloseSound && Constants.ShouldPlaySfx())
			{
				SoundManager.Instance.PlaySound(this.CloseSound, false, 1f);
			}
			this.amClosing = Minigame.CloseState.Closing;
			base.StartCoroutine(this.CoDestroySelf());
			return;
		}
		UnityEngine.Object.Destroy(base.gameObject);
	}

	protected virtual IEnumerator CoAnimateOpen()
	{
		if (this.OpenSound && Constants.ShouldPlaySfx())
		{
			SoundManager.Instance.PlaySound(this.OpenSound, false, 1f);
		}
		TransitionType transType = this.TransType;
		if (transType != TransitionType.SlideBottom)
		{
			if (transType == TransitionType.Alpha)
			{
				SpriteRenderer[] rends = base.GetComponentsInChildren<SpriteRenderer>();
				for (float timer = 0f; timer < 0.25f; timer += Time.deltaTime)
				{
					float t = timer / 0.25f;
					for (int i = 0; i < rends.Length; i++)
					{
						rends[i].color = Color.Lerp(Palette.ClearWhite, Color.white, t);
					}
					yield return null;
				}
				for (int j = 0; j < rends.Length; j++)
				{
					rends[j].color = Color.white;
				}
				rends = null;
			}
		}
		else
		{
			for (float timer = 0f; timer < 0.25f; timer += Time.deltaTime)
			{
				float t2 = timer / 0.25f;
				base.transform.localPosition = new Vector3(0f, Mathf.SmoothStep(-8f, 0f, t2), -50f);
				yield return null;
			}
			base.transform.localPosition = new Vector3(0f, 0f, -50f);
		}
		yield break;
	}

	protected virtual IEnumerator CoDestroySelf()
	{
		TransitionType transType = this.TransType;
		if (transType != TransitionType.SlideBottom)
		{
			if (transType == TransitionType.Alpha)
			{
				SpriteRenderer[] rends = base.GetComponentsInChildren<SpriteRenderer>();
				for (float timer = 0f; timer < 0.25f; timer += Time.deltaTime)
				{
					float t = timer / 0.25f;
					for (int i = 0; i < rends.Length; i++)
					{
						rends[i].color = Color.Lerp(Color.white, Palette.ClearWhite, t);
					}
					yield return null;
				}
				rends = null;
			}
		}
		else
		{
			for (float timer = 0f; timer < 0.25f; timer += Time.deltaTime)
			{
				float t2 = timer / 0.25f;
				base.transform.localPosition = new Vector3(0f, Mathf.SmoothStep(0f, -8f, t2), -50f);
				yield return null;
			}
		}
		UnityEngine.Object.Destroy(base.gameObject);
		yield break;
	}
}