using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SkillsGUI : MonoBehaviour { public Text statsText; public Text skillPointsText; public SkillWidget skillWidgetPrefab; public Transform skillWidgetsParent; public ScrollRect scrollRectWindow; public float scrollWidgetsOffset = 100f; private Vector2 scrollParentStartPos = Vector2.zero; [HideInInspector] public SkillsManager skillsManager; public List skillWidgetsList = new List(); private void Start() { } private void OnEnable() { Initialize(); } public void Initialize() { skillsManager = GlobalSettings.Instance.skillsManager; for (int i = 0; i < skillWidgetsList.Count; i++) { Object.Destroy(skillWidgetsList[i].gameObject); } skillWidgetsList.Clear(); scrollParentStartPos = scrollRectWindow.content.localPosition; List list = new List(skillsManager.skills); list.Sort((SkillsManager.Skill f1, SkillsManager.Skill f2) => f1.requiredLevel.CompareTo(f2.requiredLevel)); Canvas.ForceUpdateCanvases(); scrollRectWindow.verticalScrollbar.value = 1f; Canvas.ForceUpdateCanvases(); int num = 0; for (int num2 = 0; num2 < list.Count; num2++) { if (list[num2].isAvailable && (!list[num2].onlyBeta || GlobalSettings.Instance.isBeta) && (!list[num2].onlyCheats || GlobalSettings.Instance.turnOnCheats)) { SkillWidget skillWidget = Object.Instantiate(skillWidgetPrefab); skillWidget.transform.SetParent(skillWidgetsParent); RectTransform component = skillWidget.GetComponent(); component.localPosition = Vector3.zero + new Vector3(0f, (float)num * (0f - scrollWidgetsOffset), 0f); component.localRotation = Quaternion.identity; component.localScale = Vector3.one; skillWidget.skillsGUI = this; skillWidget.SetSkill(list[num2]); skillWidgetsList.Add(skillWidget); num++; } } scrollRectWindow.content.sizeDelta = new Vector2(scrollRectWindow.content.sizeDelta.x, scrollWidgetsOffset * (float)num + scrollWidgetsOffset * 0f); scrollRectWindow.content.localPosition = scrollParentStartPos; Refresh(); scrollRectWindow.verticalScrollbar.value = 1f; scrollRectWindow.verticalNormalizedPosition = 1f; Canvas.ForceUpdateCanvases(); scrollRectWindow.verticalScrollbar.value = 1f; scrollRectWindow.verticalNormalizedPosition = 1f; Canvas.ForceUpdateCanvases(); } public void Refresh() { if (!(skillsManager == null)) { skillPointsText.text = "Skill Points: " + skillsManager.skillPoints; for (int i = 0; i < skillWidgetsList.Count; i++) { skillWidgetsList[i].RefreshWidget(); } RefreshStats(); } } public void RefreshStats() { statsText.text = string.Empty; LevelsManager.FisheryStats globalFisheryStats = GlobalSettings.Instance.levelsManager.GetGlobalFisheryStats(); Text text = statsText; text.text = text.text + LevelStatsController.FormatHeaderGlobal(Utilities.GetTranslation("ENCYCLOPEDIA/TIME_SPENT")) + "\n"; Text text2 = statsText; text2.text = text2.text + LevelStatsController.FormatTime(globalFisheryStats.timeSpent) + "\n\n"; Text text3 = statsText; text3.text = text3.text + LevelStatsController.FormatHeaderGlobal(Utilities.GetTranslation("ENCYCLOPEDIA/CAUGHT")) + "\n"; Text text4 = statsText; string text5 = text4.text; text4.text = string.Concat(text5, globalFisheryStats.fishCaught, " (", UtilitiesUnits.GetWeightString(globalFisheryStats.weightSum), ")\n\n"); Text text6 = statsText; text6.text = text6.text + LevelStatsController.FormatHeaderGlobal(Utilities.GetTranslation("ENCYCLOPEDIA/FIGHTS")) + "\n"; if ((int)globalFisheryStats.bitesAmount > 0) { Text text7 = statsText; text5 = text7.text; text7.text = string.Concat(text5, globalFisheryStats.bitesAmount, " (", Mathf.RoundToInt((float)(int)globalFisheryStats.fishCaught / (float)(int)globalFisheryStats.bitesAmount * 100f), "% ", Utilities.GetTranslation("ENCYCLOPEDIA/WON"), ")\n\n"); } else { Text text8 = statsText; text8.text = text8.text + "0 (0% " + Utilities.GetTranslation("ENCYCLOPEDIA/WON") + ")\n\n"; } Text text9 = statsText; text9.text = text9.text + LevelStatsController.FormatHeaderGlobal(Utilities.GetTranslation("ENCYCLOPEDIA/BIGGEST_CAUGHT")) + "\n"; FishManager.FishDefinition biggestFishDefinition = GlobalSettings.Instance.fishManager.GetBiggestFishDefinition(); if (biggestFishDefinition != null) { Text text10 = statsText; text10.text = text10.text + Utilities.GetTranslation(biggestFishDefinition.fishPrefab.fishName) + "\n"; Text text11 = statsText; text11.text = text11.text + UtilitiesUnits.GetWeightString(biggestFishDefinition.weight) + "\n"; statsText.text += UtilitiesUnits.GetLengthString(biggestFishDefinition.length); } else { statsText.text += "-"; } } }