PanelGameplayQuest.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using DataTools;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using SimpleFirebaseUnity;
  7. using System;
  8. public class PanelGameplayQuest : MonoBehaviour
  9. {
  10. public static PanelGameplayQuest intance;
  11. [SerializeField]
  12. private TaskUINew taskItem;
  13. [SerializeField]
  14. private Text uiTittle;
  15. [SerializeField]
  16. private RectTransform tasksHolder;
  17. [SerializeField]
  18. private RectTransform panelBg;
  19. [SerializeField]
  20. private float minHeightOfPanel;
  21. [Header("ANIMATIONS")]
  22. [SerializeField]
  23. private Animator windowAnimation;
  24. [Header("DATA")]
  25. [SerializeField]
  26. protected DataUser dataUser;
  27. private bool windowIsHide = true;
  28. private void Awake()
  29. {
  30. intance = this;
  31. }
  32. private void Start()
  33. {
  34. GameGlobal.Instance.OnQuestChanged += OnQuestChange;
  35. GameGlobal.Instance.OnTaskCompleted += TaskCompleted;
  36. AnimateWindow();
  37. }
  38. public void AnimateWindow()
  39. {
  40. if (windowIsHide)
  41. {
  42. windowIsHide = false;
  43. windowAnimation.Play("QuestIndicatorShow");
  44. }
  45. else
  46. {
  47. windowIsHide = true;
  48. windowAnimation.Play("QuestIndicatorHide");
  49. }
  50. }
  51. private void ScalePanel()
  52. {
  53. float newHeight = minHeightOfPanel;
  54. if (tasksHolder.rect.height > minHeightOfPanel)
  55. {
  56. newHeight = tasksHolder.rect.height + 15f;
  57. }
  58. else
  59. {
  60. newHeight = minHeightOfPanel;
  61. }
  62. panelBg.sizeDelta = new Vector2(panelBg.sizeDelta.x, newHeight);
  63. }
  64. private void Update()
  65. {
  66. ScalePanel();
  67. }
  68. private void TaskCompleted(string taskId)
  69. {
  70. foreach (Transform taskChild in tasksHolder)
  71. {
  72. if (taskChild.GetComponent<TaskUINew>().GetTaskId() == taskId)
  73. {
  74. taskChild.GetComponent<TaskUINew>().SetCheckActive();
  75. }
  76. }
  77. }
  78. public void AddNewTask(string description, float duration, System.DateTime questStartTime, string id)
  79. {
  80. TaskUINew taskItemInstance;
  81. taskItemInstance = Instantiate(taskItem) as TaskUINew;
  82. taskItemInstance.transform.parent = tasksHolder;
  83. taskItemInstance.transform.localScale = Vector3.one;
  84. taskItemInstance.transform.localPosition = Vector3.zero;
  85. taskItemInstance.SetDescriptionText(description);
  86. taskItemInstance.SetTaskId(id);
  87. taskItemInstance.durationInHours = duration;
  88. taskItemInstance.questStartTime = questStartTime;
  89. }
  90. private void AddNewTaskInHolder(DataTools.Quest currentQuest)
  91. {
  92. int index = 0;
  93. foreach (DataTools.Task task in currentQuest.Tasks)
  94. {
  95. if (index >= GameGlobal.Instance.GetQuestIndex())
  96. {
  97. DateTime tastDateTime = FirebaseDatabase.TimeStampToDateTime(dataUser.UserData.TimeData.QuestStartTime);
  98. AddNewTask(task.Description, task.Duration, tastDateTime, task.Action.PropertyId);
  99. }
  100. index++;
  101. }
  102. }
  103. private void OnQuestChange(DataTools.Quest currentQuest)
  104. {
  105. AddNewTaskInHolder(currentQuest);
  106. }
  107. }