using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// Controls the display of achievements on the screen
///
public class AchievenmentStack : MonoBehaviour
{
public RectTransform[] StackPanels;
public List BackLog = new List();
public GameObject AchievementTemplate;
private AchievementManager AM;
private void Start()
{
AM = AchievementManager.instance;
}
///
/// Add an achievement to screen if it fits, otherwise, add to the backlog list
///
/// Index of achievement to add
public void ScheduleAchievementDisplay (int Index)
{
var Spawned = Instantiate(AchievementTemplate).GetComponent();
Spawned.AS = this;
Spawned.Set(AM.AchievementList[Index], AM.States[Index]);
//If there is room on the screen
if (GetCurrentStack().childCount < AM.NumberOnScreen)
{
Spawned.transform.SetParent(GetCurrentStack(), false);
Spawned.StartDeathTimer();
}
else
{
Spawned.gameObject.SetActive(false);
BackLog.Add(Spawned);
}
}
///
/// Find the box where achievements should be spawned
///
public Transform GetCurrentStack () => StackPanels[(int)AM.StackLocation].transform;
///
/// Add one achievement from the backlog to the screen
///
public void CheckBackLog ()
{
if(BackLog.Count > 0)
{
BackLog[0].transform.SetParent(GetCurrentStack(), false);
BackLog[0].gameObject.SetActive(true);
BackLog[0].StartDeathTimer();
BackLog.RemoveAt(0);
}
}
}