summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/ChoiceUIFrameHelper.cs
blob: 220e26a176ef7bbb14b1e25e0e9ec7d284a88bc9 (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
using System.Collections.Generic;
using I2.Loc;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class ChoiceUIFrameHelper : MonoBehaviour
{
	public UIFrame frame;

	public HorizontalLayoutGroup choicesParent;

	public TFUIUpgradeChoice upgradeChoiceButtonPrefab;

	public TextMeshProUGUI choiceTitle;

	public TextMeshProUGUI choiceDescription;

	private List<TFUIUpgradeChoice> choices = new List<TFUIUpgradeChoice>();

	public void OnShow()
	{
		choices.Clear();
		foreach (Transform item in choicesParent.transform)
		{
			Object.Destroy(item.gameObject);
		}
		foreach (Choice availableChoice in ChoiceManager.instance.availableChoices)
		{
			AddChoiceTFUI(choicesParent, availableChoice);
		}
		RecomputeNavigation();
	}

	private void AddChoiceTFUI(HorizontalLayoutGroup parent, Choice _choice)
	{
		TFUIUpgradeChoice component = Object.Instantiate(upgradeChoiceButtonPrefab, parent.transform).GetComponent<TFUIUpgradeChoice>();
		component.SetData(_choice);
		choices.Add(component);
	}

	private void RecomputeNavigation()
	{
		for (int i = 0; i < choices.Count; i++)
		{
			TFUIUpgradeChoice tFUIUpgradeChoice = choices[i];
			if (i <= 0)
			{
				tFUIUpgradeChoice.leftNav = choices[choices.Count - 1];
			}
			else
			{
				tFUIUpgradeChoice.leftNav = choices[i - 1];
			}
			if (i >= choices.Count - 1)
			{
				tFUIUpgradeChoice.rightNav = choices[0];
			}
			else
			{
				tFUIUpgradeChoice.rightNav = choices[i + 1];
			}
		}
		frame.firstSelected = choices[0];
	}

	public void UpdateSelectedChoice()
	{
		TFUIUpgradeChoice tFUIUpgradeChoice = null;
		if (frame.CurrentFocus != null)
		{
			tFUIUpgradeChoice = frame.CurrentFocus as TFUIUpgradeChoice;
		}
		if (tFUIUpgradeChoice == null && frame.CurrentSelection != null)
		{
			tFUIUpgradeChoice = frame.CurrentSelection as TFUIUpgradeChoice;
		}
		if (tFUIUpgradeChoice != null)
		{
			if (!tFUIUpgradeChoice.Locked)
			{
				BuildSlot currentOriginBuildSlot = ChoiceManager.instance.currentOriginBuildSlot;
				choiceTitle.text = LocalizationManager.GetTranslation(currentOriginBuildSlot.GET_LOCIDENTIFIER_CHOICENAME(tFUIUpgradeChoice.Data));
				choiceDescription.text = LocalizationManager.GetTranslation(currentOriginBuildSlot.GET_LOCIDENTIFIER_CHOICEDESCRIPTION(tFUIUpgradeChoice.Data));
			}
			else
			{
				choiceTitle.text = LocalizationManager.GetTranslation("Menu/Locked");
				choiceDescription.text = LocalizationManager.GetTranslation("Menu/Locked Choice Description");
			}
		}
	}

	public void OnApply()
	{
		TFUIUpgradeChoice tFUIUpgradeChoice = frame.LastApplied as TFUIUpgradeChoice;
		if (!(tFUIUpgradeChoice == null) && !tFUIUpgradeChoice.Locked)
		{
			ChoiceManager.instance.choiceToReturn = tFUIUpgradeChoice.Data;
			UIFrameManager.instance.CloseActiveFrame();
		}
	}
}