summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/NightCall.cs
blob: 2db1c18e4d33883a0d465ef777c044b379899c6c (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
using MoreMountains.Feedbacks;
using MPUIKIT;
using Rewired;
using TMPro;
using UnityEngine;

public class NightCall : MonoBehaviour, DayNightCycle.IDaytimeSensitive
{
	public static NightCall instance;

	public float nightCallTime = 1f;

	public MPImage targetGraphic;

	public MPImage targetFill;

	public MPImage background;

	public TextMeshProUGUI nightCallCueText;

	public TextMeshProUGUI nightCallTimeText;

	public MMF_Player fullFeedback;

	public AnimationCurve textCueScaleCurve;

	public RectTransform scaleParent;

	public AudioSource nightCallAudio;

	private Player input;

	private bool active = true;

	private float currentFill;

	private PlayerInteraction player;

	private Color defaultBackgroundColor;

	private float nightCallTargetVolume;

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		input = ReInput.players.GetPlayer(0);
		DayNightCycle.Instance.RegisterDaytimeSensitiveObject(this);
		targetFill.transform.localScale = Vector3.zero;
		player = PlayerInteraction.instance;
		defaultBackgroundColor = background.color;
		nightCallTargetVolume = nightCallAudio.volume;
	}

	private void Update()
	{
		UpdateFill();
	}

	public void UpdateFill()
	{
		if (active)
		{
			if (SettingsManager.Instance.UseLargeInGameUI)
			{
				scaleParent.localScale = Vector3.one * 1.5f;
			}
			else
			{
				scaleParent.localScale = Vector3.one;
			}
			if (input.GetButtonDown("Call Night") && player.IsFreeToCallNight)
			{
				nightCallAudio.Stop();
				nightCallAudio.PlayOneShot(ThronefallAudioManager.Instance.audioContent.NightCallStart, 0.45f);
			}
			if (input.GetButton("Call Night") && player.IsFreeToCallNight)
			{
				currentFill += Time.deltaTime * (1f / nightCallTime);
			}
			else
			{
				currentFill -= Time.deltaTime * 2f * (1f / nightCallTime);
			}
			if (currentFill >= 1f)
			{
				nightCallAudio.PlayOneShot(ThronefallAudioManager.Instance.audioContent.NightCallComplete, 0.8f);
				DayNightCycle.Instance.SwitchToNight();
				fullFeedback.PlayFeedbacks();
				active = false;
			}
			if (currentFill > 0f)
			{
				nightCallCueText.gameObject.SetActive(value: true);
				nightCallTimeText.text = (nightCallTime * (1f - currentFill)).ToString("F1") + "s";
				nightCallCueText.transform.localScale = Vector3.one * textCueScaleCurve.Evaluate(Mathf.InverseLerp(0f, 0.15f, currentFill));
				nightCallAudio.volume = Mathf.Lerp(0f, nightCallTargetVolume, Mathf.InverseLerp(0f, 0.3f, currentFill));
			}
			else
			{
				nightCallCueText.gameObject.SetActive(value: false);
				nightCallCueText.transform.localScale = Vector3.one;
			}
			defaultBackgroundColor.a = Mathf.InverseLerp(0f, 0.4f, currentFill);
			background.color = defaultBackgroundColor;
			currentFill = Mathf.Clamp01(currentFill);
			targetGraphic.fillAmount = currentFill;
		}
		else if (currentFill > 0f)
		{
			currentFill -= Time.deltaTime * 2f;
			defaultBackgroundColor.a = Mathf.InverseLerp(0f, 0.4f, currentFill);
			background.color = defaultBackgroundColor;
		}
	}

	public void OnDawn_AfterSunrise()
	{
		targetFill.transform.localScale = Vector3.zero;
		targetGraphic.transform.localScale = Vector3.one;
		targetGraphic.fillAmount = 0f;
		nightCallCueText.gameObject.SetActive(value: false);
		nightCallCueText.transform.localScale = Vector3.one;
		defaultBackgroundColor.a = 0f;
		background.color = defaultBackgroundColor;
		currentFill = 0f;
		active = true;
	}

	public void OnDawn_BeforeSunrise()
	{
	}

	public void OnDusk()
	{
	}
}