summaryrefslogtreecommitdiff
path: root/GameCode/LevelSelectManager.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-11-02 11:51:31 +0800
committerchai <215380520@qq.com>2023-11-02 11:51:31 +0800
commit7f493f682503f5186308de7b8f74b5b49233cfe4 (patch)
tree8a91e2056bc79788ee4735dce88b8d516ba12beb /GameCode/LevelSelectManager.cs
+init
Diffstat (limited to 'GameCode/LevelSelectManager.cs')
-rw-r--r--GameCode/LevelSelectManager.cs114
1 files changed, 114 insertions, 0 deletions
diff --git a/GameCode/LevelSelectManager.cs b/GameCode/LevelSelectManager.cs
new file mode 100644
index 0000000..5650ffd
--- /dev/null
+++ b/GameCode/LevelSelectManager.cs
@@ -0,0 +1,114 @@
+using TMPro;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class LevelSelectManager : MonoBehaviour
+{
+ public static LevelSelectManager instance;
+
+ private LevelInteractor[] levelInteractors;
+
+ public Vector3 spawnOnLevelOffsetPositon;
+
+ public PlayerMovement playerMovement;
+
+ public TMP_Text levelTitle;
+
+ public TMP_Text levelHighscore;
+
+ public TMP_Text beatenState;
+
+ public string notBeatenYet = "Not beaten yet.";
+
+ public string successfullyBeaten = "Successfully beaten.";
+
+ public string scorePrefix = "Your Best: ";
+
+ public GameObject tooltipObject;
+
+ public Image tooltipImage;
+
+ public TMP_Text tooltipTitle;
+
+ public TMP_Text tooltipDescription;
+
+ private Equippable showingTooltipFor;
+
+ public Canvas levelSelectedCanvas;
+
+ public Camera camMain;
+
+ private LevelInteractor openedLevel;
+
+ private int iFrames;
+
+ private bool fixedLoadout;
+
+ public Equippable ShowingTooltipFor => showingTooltipFor;
+
+ public bool PreLevelMenuIsOpen => openedLevel != null;
+
+ public void ShowTooltip(Equippable _eq)
+ {
+ showingTooltipFor = _eq;
+ tooltipObject.SetActive(_eq != null);
+ if (!(_eq == null))
+ {
+ tooltipImage.sprite = _eq.icon;
+ tooltipTitle.text = _eq.displayName;
+ tooltipDescription.text = _eq.description;
+ float num = camMain.pixelRect.height / levelSelectedCanvas.pixelRect.height;
+ tooltipObject.transform.position = Input.mousePosition * num;
+ }
+ }
+
+ private void Awake()
+ {
+ instance = this;
+ }
+
+ private void Start()
+ {
+ levelInteractors = GetComponentsInChildren<LevelInteractor>();
+ ShowTooltip(null);
+ }
+
+ private void MovePlayerToTheLevelYouCameFrom()
+ {
+ SceneTransitionManager sceneTransitionManager = SceneTransitionManager.instance;
+ if (!sceneTransitionManager || sceneTransitionManager.ComingFromGameplayScene == "")
+ {
+ return;
+ }
+ for (int i = 0; i < levelInteractors.Length; i++)
+ {
+ if (levelInteractors[i].sceneName == sceneTransitionManager.ComingFromGameplayScene)
+ {
+ playerMovement.TeleportTo(levelInteractors[i].transform.position + spawnOnLevelOffsetPositon);
+ break;
+ }
+ }
+ }
+
+ private void Update()
+ {
+ if (iFrames <= 1)
+ {
+ MovePlayerToTheLevelYouCameFrom();
+ }
+ iFrames++;
+ }
+
+ public void PlayButtonPressed()
+ {
+ if (PreLevelMenuIsOpen)
+ {
+ if (openedLevel.fixedLoadout.Count > 0)
+ {
+ PerkManager.instance.CurrentlyEquipped.Clear();
+ PerkManager.instance.CurrentlyEquipped.AddRange(openedLevel.fixedLoadout);
+ }
+ SceneTransitionManager.instance.TransitionFromLevelSelectToLevel(openedLevel.sceneName);
+ }
+ }
+}