summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/TFUIAudioHelper.cs
blob: 39c293ef4621cce76942bb99dd6bd6a95c495ec3 (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
using UnityEngine;

[RequireComponent(typeof(ThronefallUIElement))]
public class TFUIAudioHelper : MonoBehaviour
{
	public bool playOnColdSelect;

	public ThronefallAudioManager.AudioOneShot onSelect = ThronefallAudioManager.AudioOneShot.ButtonSelect;

	public ThronefallAudioManager.AudioOneShot onApply = ThronefallAudioManager.AudioOneShot.ButtonApply;

	private ThronefallUIElement tfui;

	private bool selected
	{
		get
		{
			if (tfui.CurrentState == ThronefallUIElement.SelectionState.Selected || tfui.CurrentState == ThronefallUIElement.SelectionState.FocussedAndSelected)
			{
				if (tfui.PreviousState != ThronefallUIElement.SelectionState.FocussedAndSelected)
				{
					return tfui.PreviousState != ThronefallUIElement.SelectionState.Selected;
				}
				return false;
			}
			return false;
		}
	}

	private void Start()
	{
		tfui = GetComponent<ThronefallUIElement>();
		tfui.onApply.AddListener(PlayApply);
		tfui.onSelectionStateChange.AddListener(PlaySelect);
		if (selected && playOnColdSelect)
		{
			PlaySelect();
		}
	}

	private void PlayApply()
	{
		ThronefallAudioManager.Oneshot(onApply);
	}

	private void PlaySelect()
	{
		if (selected)
		{
			ThronefallAudioManager.Oneshot(onSelect);
		}
	}
}