summaryrefslogtreecommitdiff
path: root/Thronefall_1_0/GameCode/SettingsUIHelper.cs
blob: 1156f533cfba28e30f489862f79e601f32e2a93c (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
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SettingsUIHelper : MonoBehaviour
{
	[Serializable]
	public class SettingsTab
	{
		public TFUITextButton parentElement;

		public VerticalLayoutGroup childContainer;

		public void ComputeNavigationForSettingsTab()
		{
			List<ThronefallUIElement> list = new List<ThronefallUIElement>();
			foreach (Transform item in childContainer.transform)
			{
				list.Add(item.GetComponent<ThronefallUIElement>());
			}
			parentElement.botNav = list[0];
			parentElement.topNav = list[list.Count - 1];
			for (int i = 0; i < list.Count; i++)
			{
				ThronefallUIElement thronefallUIElement = list[i];
				if (i == 0)
				{
					thronefallUIElement.topNav = parentElement;
				}
				else
				{
					thronefallUIElement.topNav = list[i - 1];
				}
				if (i == list.Count - 1)
				{
					thronefallUIElement.botNav = parentElement;
				}
				else
				{
					thronefallUIElement.botNav = list[i + 1];
				}
			}
		}
	}

	public UIFrame targetFrame;

	public SettingsTab videoTab;

	public SettingsTab audioTab;

	public SettingsTab gameplayTab;

	public SettingsTab controlsTab;

	public GameObject dimBG;

	private SettingsTab currentSelectedTab;

	private Dictionary<ThronefallUIElement, SettingsTab> allTabs = new Dictionary<ThronefallUIElement, SettingsTab>();

	private void Awake()
	{
		allTabs.Add(videoTab.parentElement, videoTab);
		allTabs.Add(audioTab.parentElement, audioTab);
		allTabs.Add(gameplayTab.parentElement, gameplayTab);
		allTabs.Add(controlsTab.parentElement, controlsTab);
		videoTab.childContainer.gameObject.SetActive(value: false);
		audioTab.childContainer.gameObject.SetActive(value: false);
		gameplayTab.childContainer.gameObject.SetActive(value: false);
		controlsTab.childContainer.gameObject.SetActive(value: false);
		RecomputeAllNavigation();
	}

	private void RecomputeAllNavigation()
	{
		videoTab.ComputeNavigationForSettingsTab();
		audioTab.ComputeNavigationForSettingsTab();
		gameplayTab.ComputeNavigationForSettingsTab();
		controlsTab.ComputeNavigationForSettingsTab();
	}

	public void OnShow()
	{
		if (SceneTransitionManager.instance.CurrentSceneState == SceneTransitionManager.SceneState.MainMenu)
		{
			dimBG.SetActive(value: false);
		}
		else
		{
			dimBG.SetActive(value: true);
		}
	}

	public void OnSelect()
	{
		SettingsTab value = null;
		if (allTabs.TryGetValue(targetFrame.CurrentSelection, out value))
		{
			if (currentSelectedTab != null)
			{
				currentSelectedTab.childContainer.gameObject.SetActive(value: false);
				currentSelectedTab.parentElement.applyOverrideStyle = false;
			}
			currentSelectedTab = value;
			currentSelectedTab.childContainer.gameObject.SetActive(value: true);
		}
		else if (currentSelectedTab != null)
		{
			currentSelectedTab.parentElement.applyOverrideStyle = true;
		}
	}
}