PanelQuestBehaviour.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. using UnityEngine;
  2. public class PanelQuestBehaviour : MonoBehaviour
  3. {
  4. private static PanelQuestBehaviour instance;
  5. public static PanelQuestBehaviour Instance
  6. {
  7. get
  8. {
  9. return instance;
  10. }
  11. }
  12. private void Start()
  13. {
  14. instance = this;
  15. AttachEvents();
  16. EnableSideQuests(false);
  17. }
  18. [Header("Main quest container")]
  19. [SerializeField]
  20. private QuestContainerBehaviour mainQuest;
  21. [Header("Side quest container")]
  22. [SerializeField]
  23. private QuestContainerBehaviour sideQuest;
  24. [Header("Container`s RectTransform")]
  25. [SerializeField]
  26. private RectTransform container;
  27. public void SetMainQuest(DataTools.Quest quest)
  28. {
  29. if (mainQuest.IsAnyToShow)
  30. {
  31. mainQuest.RemoveQuest();
  32. }
  33. mainQuest.SetQuest(quest);
  34. SetMainTask(0);
  35. }
  36. public void DisableTimerOnMain(int taskIndex=-1)
  37. {
  38. mainQuest.DisableTimerOnTask(taskIndex);
  39. }
  40. public void SetMainTask(int taskIndex)
  41. {
  42. mainQuest.SetTaskActive(taskIndex);
  43. if(mainQuest.IsAnyToShow)
  44. {
  45. mainQuest.UpdateTasksForLinearQuestsIncludingHiddenFlag(taskIndex);
  46. if (mainQuest.NumOfVisibleTasks == 0)
  47. {
  48. mainQuest.ShowNearestNonhiddenTask(GameGlobal.Instance.GetQuestIndex());
  49. }
  50. }
  51. UpdateLayout();
  52. }
  53. public void RemoveMainQuest()
  54. {
  55. mainQuest.Hide();
  56. mainQuest.RemoveQuest();
  57. }
  58. public void RemoveSideQuest()
  59. {
  60. sideQuest.Hide();
  61. sideQuest.RemoveQuest();
  62. }
  63. public void SetMainTask(string taskId)
  64. {
  65. mainQuest.SetTaskActive(taskId);
  66. if(mainQuest.IsAnyToShow)
  67. {
  68. mainQuest.UpdateTasksForLinearQuestsIncludingHiddenFlag(mainQuest.LastActive);
  69. if (mainQuest.NumOfVisibleTasks == 0)
  70. {
  71. mainQuest.ShowNearestNonhiddenTask(GameGlobal.Instance.GetQuestIndex());
  72. }
  73. }
  74. UpdateLayout();
  75. }
  76. public void CompleteMainTask(int taskIndex)
  77. {
  78. mainQuest.SetTaskComplete(taskIndex);
  79. }
  80. public void CompleteMainTask(string taskId)
  81. {
  82. mainQuest.SetTaskComplete(taskId);
  83. }
  84. public void SetSideQuest(DataTools.Quest quest)
  85. {
  86. sideQuest.SetQuest(quest);
  87. if (sideQuest.IsAnyToShow)
  88. {
  89. EnableSideQuests(true);
  90. }
  91. }
  92. public void SetSideTask(int taskIndex)
  93. {
  94. sideQuest.SetTaskActive(taskIndex);
  95. }
  96. public void CompleteSideTask(int taskIndex)
  97. {
  98. sideQuest.SetTaskComplete(taskIndex);
  99. if (!sideQuest.IsAnyToShow)
  100. {
  101. EnableSideQuests(false);
  102. }
  103. }
  104. public void EnableSideQuests(bool enable=false)
  105. {
  106. sideQuest.gameObject.SetActive(enable);
  107. }
  108. public void ShowMainQuest()
  109. {
  110. mainQuest.Show();
  111. UpdateLayout();
  112. }
  113. public void HideMainQuest()
  114. {
  115. mainQuest.Hide();
  116. HideSideQuest();
  117. }
  118. public void ShowSideQuest()
  119. {
  120. sideQuest.Show();
  121. UpdateLayout();
  122. }
  123. public void HideSideQuest()
  124. {
  125. sideQuest.Hide();
  126. }
  127. public void SetSimpleTask(string task, string title="")
  128. {
  129. if(mainQuest.IsQuestComplete)
  130. {
  131. mainQuest.RemoveQuest();
  132. mainQuest.SetFakeTask(task, title);
  133. }
  134. }
  135. private void AttachEvents()
  136. {
  137. GameGlobal.Instance.OnTaskCompleted += CompleteMainTask;
  138. GameGlobal.Instance.OnQuestChanged += SetMainQuest;
  139. }
  140. public void UpdateState()
  141. {
  142. }
  143. private void UpdateLayout()
  144. {
  145. UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(container);
  146. }
  147. }