123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- 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<TaskUINew>().GetTaskId() == taskId)
- {
- taskChild.GetComponent<TaskUINew>().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);
- }
- }
|