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 grid = new List(); 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 list = new List(); List list2 = new List(); List list3 = new List(); 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(); 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]; } } } }