162 lines
3.5 KiB
C#
162 lines
3.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using log4net;
|
|
using UnityEngine;
|
|
|
|
namespace Managers
|
|
{
|
|
/// <summary>
|
|
/// Manages dynamic UI elements which can be triggered from everywhere.
|
|
/// </summary>
|
|
public class UIManager : MonoBehaviour
|
|
{
|
|
private static ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
|
[SerializeField] public bool IsUIActiveScene { get; set; }
|
|
public HUD hUD { get; private set; }
|
|
public Announcments Announcments { get; private set; }
|
|
public PauseMenu PauseMenu { get; private set; }
|
|
public MatchEndMenu MatchEndMenu { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Globally accessible member to use manager with.
|
|
/// </summary>
|
|
public static UIManager G { get; private set; }
|
|
|
|
void Awake()
|
|
{
|
|
G = this;
|
|
Log.Info("Awake");
|
|
}
|
|
|
|
public bool StartManagingMatchUI()
|
|
{
|
|
if (!StartManagingHUD() || !StartManagingAnnouncements()
|
|
|| !StartManagingPauseMenu() || !StartManagingMatchEndMenu())
|
|
{
|
|
Log.Error("Problems when starting in game match UI.");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool StartManagingHUD()
|
|
{
|
|
if (hUD == null)
|
|
{
|
|
GameObject go = GameObject.Find("HUD");
|
|
if (go == null)
|
|
{
|
|
Log.Error("Could not find HUD GameObject in loaded scenes!");
|
|
return false;
|
|
}
|
|
hUD = go.GetComponent<HUD>();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool StartManagingPauseMenu()
|
|
{
|
|
if (PauseMenu == null)
|
|
{
|
|
GameObject go = GameObject.Find("Paused Menu");
|
|
if (go == null)
|
|
{
|
|
Log.Error("Could not find Pause Menu GameObject in loaded scenes!");
|
|
return false;
|
|
}
|
|
PauseMenu = go.GetComponent<PauseMenu>();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool StartManagingMatchEndMenu()
|
|
{
|
|
if (MatchEndMenu == null)
|
|
{
|
|
GameObject go = GameObject.Find("Match End Menu");
|
|
if (go == null)
|
|
{
|
|
Log.Error("Could not find Match End Menu GameObject in loaded scenes!");
|
|
return false;
|
|
}
|
|
MatchEndMenu = go.GetComponent<MatchEndMenu>();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool StartManagingAnnouncements()
|
|
{
|
|
if (Announcments == null)
|
|
{
|
|
GameObject go = GameObject.Find("Announcer UI");
|
|
if (go == null)
|
|
{
|
|
Log.Error("Could not find Pause Menu GameObject in loaded scenes!");
|
|
return false;
|
|
}
|
|
Announcments = go.GetComponent<Announcments>();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public void AssignHUDElementsToPlayers(List<Player> players)
|
|
{
|
|
foreach (Player p in players)
|
|
{
|
|
Ship s = p.spawnedCharacter.GetComponent<Ship>();
|
|
s.boostUI = hUD.boostCapacities[p.playerNumber - 1].GetComponent<BoostCapacityUI>();
|
|
s.boostUI.SetPlayerName(p);
|
|
hUD.boostCapacities[p.playerNumber - 1].gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
public void StartInputPrompt(Dictionary<int, Player> unassignedPlayers)
|
|
{
|
|
foreach (int playerNumber in unassignedPlayers.Keys)
|
|
{
|
|
hUD.StartJoinPrompt(unassignedPlayers[playerNumber]);
|
|
}
|
|
}
|
|
|
|
public void ShowMatchStartPrompt()
|
|
{
|
|
Announcments.AnnounceText("Press Start/Enter \n to start the match!");
|
|
}
|
|
public void HideAnnouncement()
|
|
{
|
|
Announcments.StopAnnouncement();
|
|
}
|
|
|
|
public void ShowPauseMenu(Transform transform)
|
|
{
|
|
hUD?.Hide();
|
|
PauseMenu?.Show(transform);
|
|
}
|
|
|
|
public void HidePauseMenu()
|
|
{
|
|
PauseMenu?.Hide();
|
|
hUD?.Show();
|
|
}
|
|
public void ShowMatchEndMenu(Transform transform)
|
|
{
|
|
hUD?.Hide();
|
|
MatchEndMenu?.Show(transform);
|
|
}
|
|
|
|
public void HideMatchEndMenu()
|
|
{
|
|
MatchEndMenu?.Hide();
|
|
hUD?.Show();
|
|
}
|
|
public void ShowHUD()
|
|
{
|
|
hUD?.Show();
|
|
}
|
|
|
|
public void HideHUD()
|
|
{
|
|
hUD?.Hide();
|
|
}
|
|
}
|
|
} |