Files
AppleHillsProduction/Assets/Scripts/UI/PlayerHudManager.cs

155 lines
4.1 KiB
C#
Raw Normal View History

2025-11-07 16:47:10 +01:00
using Bootstrap;
using Cinematics;
using UnityEngine;
using Core;
using System;
using UnityEngine.UI;
using UnityEngine.Playables;
2025-11-07 17:08:02 +01:00
using Core.Lifecycle;
using JetBrains.Annotations;
2025-11-07 16:47:10 +01:00
2025-11-07 17:08:02 +01:00
public class PlayerHudManager : ManagedBehaviour
2025-11-07 16:47:10 +01:00
{
public enum UIMode { Overworld, Puzzle, Minigame, HideAll };
public UIMode currentUIMode;
2025-11-07 16:47:10 +01:00
private AppSwitcher _appSwitcher;
public GameObject landscapeObject;
public GameObject portraitObject;
public GameObject cinematicsParentObject;
public GameObject CinematicBackground;
public GameObject appSwitcher;
public GameObject eagleEye;
2025-11-07 16:47:10 +01:00
[HideInInspector] public Image cinematicSprites;
[HideInInspector] public Image cinematicBackgroundSprites;
[HideInInspector] public GameObject currentCinematicPlayer;
[HideInInspector] public PlayableDirector playableDirector;
private static PlayerHudManager _instance;
public static PlayerHudManager Instance => _instance;
2025-11-07 17:08:02 +01:00
private new void Awake()
2025-11-07 16:47:10 +01:00
{
base.Awake();
2025-11-07 16:47:10 +01:00
if (Instance != null)
{
Destroy(this);
return;
}
_instance = this;
InitializeReferences();
}
protected override void OnManagedAwake()
{
if (SceneManagerService.Instance != null)
{
SceneManagerService.Instance.SceneLoadCompleted += NewSceneLoaded;
}
if (SceneManagerService.Instance.CurrentGameplayScene == "AppleHillsOverworld")
{
NewSceneLoaded("AppleHillsOverworld");
}
if (SceneManagerService.Instance.CurrentGameplayScene == "StartingScene")
{
// TODO: Hide all UI until cinematics have played
NewSceneLoaded("AppleHillsOverworld");
}
2025-11-07 16:47:10 +01:00
}
private void InitializeReferences()
{
currentCinematicPlayer = landscapeObject;
playableDirector = cinematicsParentObject.GetComponent<PlayableDirector>();
2025-11-07 16:47:10 +01:00
cinematicSprites = currentCinematicPlayer.GetComponent<Image>();
cinematicBackgroundSprites = CinematicBackground.GetComponent<Image>();
}
private void UpateCinematicReferences(GameObject newCinematicPlayer)
2025-11-07 16:47:10 +01:00
{
currentCinematicPlayer = newCinematicPlayer;
cinematicSprites = currentCinematicPlayer.GetComponent<Image>();
2025-11-07 16:47:10 +01:00
}
2025-11-07 16:47:10 +01:00
public void SetPortraitMode(bool portraitModeEnable)
{
if (portraitModeEnable)
{
UpateCinematicReferences(portraitObject);
2025-11-07 16:47:10 +01:00
}
else
{
UpateCinematicReferences(landscapeObject);
2025-11-07 16:47:10 +01:00
}
}
public void NewSceneLoaded(string sceneName)
{
switch (sceneName)
{
case "AppleHillsOverworld":
UpdateUIMode(UIMode.Overworld);
break;
case "Quarry":
UpdateUIMode(UIMode.Puzzle);
break;
case "DivingForPictures":
UpdateUIMode(UIMode.Minigame);
break;
}
}
public void UpdateUIMode(UIMode mode)
{
switch (mode)
{
case UIMode.Overworld:
// Update currentUIMode var
currentUIMode = UIMode.Overworld;
// Show app switcher
appSwitcher.SetActive(true);
// Hide eagle eye
eagleEye.SetActive(false);
break;
case UIMode.Puzzle:
// Update currentUIMode var
currentUIMode = UIMode.Puzzle;
// Hide app switcher
appSwitcher.SetActive(false);
// show eagle eye
eagleEye.SetActive(true);
break;
case UIMode.Minigame:
// Update currentUIMode var
currentUIMode = UIMode.Minigame;
// Hide app switcher
appSwitcher.SetActive(false);
// Hide birds eye
eagleEye.SetActive(false);
break;
}
}
public void ToggleAppSwitcher(bool boo)
{
appSwitcher.SetActive(boo);
}
2025-11-07 16:47:10 +01:00
}