194 lines
4.8 KiB
C#
194 lines
4.8 KiB
C#
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using GameKit.Dependencies.Utilities;
|
|
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; }
|
|
public OffScreenIndicatorManager OffScreenManager;
|
|
public ManageableAudio MatchMusic;
|
|
|
|
|
|
/// <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)
|
|
{
|
|
IHUDOwner s = p.spawnedCharacter.GetComponent<IHUDOwner>();
|
|
// var BoostUI = HUD.boostCapacities[p.playerNumber - 1].GetComponent<BoostCapacityUI>();
|
|
// BoostUI.SetPlayerName(p);
|
|
// BoostUI.gameObject.SetActive(true);
|
|
// s.BoostUpdated += BoostUI.UpdateFill;
|
|
|
|
GameObject lm = Instantiate(HUD.LifeMeter);
|
|
Vector3 pos = lm.transform.localPosition;
|
|
Vector3 angles = lm.transform.localEulerAngles;
|
|
Vector3 scale = lm.transform.localScale;
|
|
lm.transform.SetParent(p.spawnedCharacter.transform);
|
|
lm.transform.localPosition = pos;
|
|
lm.transform.localEulerAngles = angles;
|
|
lm.transform.localScale = scale;
|
|
var LifeMeter = lm.GetComponent<SegmentIndicator>();
|
|
s.LifeUpdated += LifeMeter.SetFill;
|
|
|
|
GameObject bm = Instantiate(HUD.BoostMeter);
|
|
pos = bm.transform.localPosition;
|
|
angles = bm.transform.localEulerAngles;
|
|
scale = bm.transform.localScale;
|
|
bm.transform.SetParent(p.spawnedCharacter.transform);
|
|
bm.transform.localPosition = pos;
|
|
bm.transform.localEulerAngles = angles;
|
|
bm.transform.localScale = scale;
|
|
var BoostMeter = bm.GetComponent<SegmentIndicator>();
|
|
s.BoostUpdated += BoostMeter.SetFill;
|
|
|
|
OffScreenManager.AddTarget(p.spawnedCharacter, p.character.ShipHullColor);
|
|
}
|
|
// TODO: This belongs somewhere?
|
|
MatchMusic = AudioManager.G.GetGlobalSoundRandom("match_music", true);
|
|
MatchMusic.PlayAudio(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();
|
|
}
|
|
}
|
|
} |