using System.Collections; using System.Collections.Generic; using DataTools; using UnityEngine; using UnityEngine.UI; using SimpleFirebaseUnity; using System; public class PanelGameplayQuest : MonoBehaviour { public static PanelGameplayQuest intance; [SerializeField] private TaskUINew taskItem; [SerializeField] private Text uiTittle; [SerializeField] private RectTransform tasksHolder; [SerializeField] private RectTransform panelBg; [SerializeField] private float minHeightOfPanel; [Header("ANIMATIONS")] [SerializeField] private Animator windowAnimation; [Header("DATA")] [SerializeField] protected DataUser dataUser; private bool windowIsHide = true; private void Awake() { intance = this; } private void Start() { GameGlobal.Instance.OnQuestChanged += OnQuestChange; GameGlobal.Instance.OnTaskCompleted += TaskCompleted; AnimateWindow(); } public void AnimateWindow() { if (windowIsHide) { windowIsHide = false; windowAnimation.Play("QuestIndicatorShow"); } else { windowIsHide = true; windowAnimation.Play("QuestIndicatorHide"); } } private void ScalePanel() { float newHeight = minHeightOfPanel; if (tasksHolder.rect.height > minHeightOfPanel) { newHeight = tasksHolder.rect.height + 15f; } else { newHeight = minHeightOfPanel; } panelBg.sizeDelta = new Vector2(panelBg.sizeDelta.x, newHeight); } private void Update() { ScalePanel(); } private void TaskCompleted(string taskId) { foreach (Transform taskChild in tasksHolder) { if (taskChild.GetComponent().GetTaskId() == taskId) { taskChild.GetComponent().SetCheckActive(); } } } public void AddNewTask(string description, float duration, System.DateTime questStartTime, string id) { TaskUINew taskItemInstance; taskItemInstance = Instantiate(taskItem) as TaskUINew; taskItemInstance.transform.parent = tasksHolder; taskItemInstance.transform.localScale = Vector3.one; taskItemInstance.transform.localPosition = Vector3.zero; taskItemInstance.SetDescriptionText(description); taskItemInstance.SetTaskId(id); taskItemInstance.durationInHours = duration; taskItemInstance.questStartTime = questStartTime; } private void AddNewTaskInHolder(DataTools.Quest currentQuest) { int index = 0; foreach (DataTools.Task task in currentQuest.Tasks) { if (index >= GameGlobal.Instance.GetQuestIndex()) { DateTime tastDateTime = FirebaseDatabase.TimeStampToDateTime(dataUser.UserData.TimeData.QuestStartTime); AddNewTask(task.Description, task.Duration, tastDateTime, task.Action.PropertyId); } index++; } } private void OnQuestChange(DataTools.Quest currentQuest) { AddNewTaskInHolder(currentQuest); } }