summaryrefslogtreecommitdiff
path: root/Thronefall_v1.0/Decompile/PauseUILoadoutHelper.cs
blob: c51180cbee313a5aa5102c8bf42768b054885e78 (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
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PauseUILoadoutHelper : MonoBehaviour
{
	public ThronefallUIElement topmostButton;

	public ThronefallUIElement botmostButton;

	public GridLayoutGroup loadoutGroup;

	public TFUIEquippable equippableButtonPrefab;

	private List<TFUIEquippable> grid = new List<TFUIEquippable>();

	private const int maxRows = 4;

	public void Refresh()
	{
		if (SceneTransitionManager.instance.CurrentSceneState != SceneTransitionManager.SceneState.InGame)
		{
			return;
		}
		grid.Clear();
		foreach (Transform item in loadoutGroup.transform)
		{
			Object.Destroy(item.gameObject);
		}
		List<Equippable> list = new List<Equippable>();
		List<Equippable> list2 = new List<Equippable>();
		List<Equippable> list3 = new List<Equippable>();
		foreach (Equippable item2 in PerkManager.instance.CurrentlyEquipped)
		{
			if (item2 is EquippableWeapon)
			{
				list.Add(item2);
			}
			else if (item2 is EquippablePerk)
			{
				list2.Add(item2);
			}
			else if (item2 is EquippableMutation)
			{
				list3.Add(item2);
			}
		}
		foreach (Equippable item3 in list)
		{
			AddTFUIEquippable(loadoutGroup, item3);
		}
		foreach (Equippable item4 in list2)
		{
			AddTFUIEquippable(loadoutGroup, item4);
		}
		foreach (Equippable item5 in list3)
		{
			AddTFUIEquippable(loadoutGroup, item5);
		}
		AssignNavigationTargets();
	}

	private void AddTFUIEquippable(GridLayoutGroup parent, Equippable e)
	{
		TFUIEquippable component = Object.Instantiate(equippableButtonPrefab, parent.transform).GetComponent<TFUIEquippable>();
		component.SetDataSimple(e);
		grid.Add(component);
	}

	private void AssignNavigationTargets()
	{
		int num = grid.Count / 4;
		int num2 = grid.Count % 4;
		if (num2 > 0)
		{
			num++;
		}
		else
		{
			num2 = 4;
		}
		int num3 = 0;
		int num4 = 0;
		for (int i = 0; i < grid.Count; i++)
		{
			ThronefallUIElement thronefallUIElement = grid[i];
			if (num3 == 0)
			{
				thronefallUIElement.topNav = botmostButton;
			}
			else
			{
				thronefallUIElement.topNav = grid[i - 1];
			}
			if (num3 == 3 || (num == 1 && i == grid.Count - 1))
			{
				thronefallUIElement.botNav = topmostButton;
			}
			else if (num > 1 && i == grid.Count - 1)
			{
				thronefallUIElement.botNav = grid[4 * num4 - 1];
			}
			else
			{
				thronefallUIElement.botNav = grid[i + 1];
			}
			if (num > 1)
			{
				if (num4 == 0)
				{
					if (num3 <= num2 - 1)
					{
						thronefallUIElement.leftNav = grid[grid.Count - (num2 - num3)];
					}
					else if (i + 4 <= grid.Count - 1)
					{
						thronefallUIElement.leftNav = grid[i + 4];
					}
				}
				else
				{
					thronefallUIElement.leftNav = grid[i - 4];
				}
				if (num4 == num - 1)
				{
					thronefallUIElement.rightNav = grid[i - 4 * (num - 1)];
				}
				else
				{
					int num5 = i + 4;
					if (num5 <= grid.Count - 1)
					{
						thronefallUIElement.rightNav = grid[num5];
					}
					else
					{
						thronefallUIElement.rightNav = grid[i - 4 * num4];
					}
				}
			}
			num3++;
			if (num3 > 3)
			{
				num3 = 0;
				num4++;
			}
		}
		if (grid.Count > 0)
		{
			botmostButton.botNav = grid[0];
			if (num2 != 4 && num > 1)
			{
				topmostButton.topNav = grid[4 * (num - 1) - 1];
			}
			else
			{
				topmostButton.topNav = grid[grid.Count - 1];
			}
		}
	}
}