123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- using UnityEngine;
- public class PanelQuestBehaviour : MonoBehaviour
- {
- private static PanelQuestBehaviour instance;
- public static PanelQuestBehaviour Instance
- {
- get
- {
- return instance;
- }
- }
- private void Start()
- {
- instance = this;
- AttachEvents();
- EnableSideQuests(false);
- }
- [Header("Main quest container")]
- [SerializeField]
- private QuestContainerBehaviour mainQuest;
- [Header("Side quest container")]
- [SerializeField]
- private QuestContainerBehaviour sideQuest;
- [Header("Container`s RectTransform")]
- [SerializeField]
- private RectTransform container;
- public void SetMainQuest(DataTools.Quest quest)
- {
- if (mainQuest.IsAnyToShow)
- {
- mainQuest.RemoveQuest();
- }
- mainQuest.SetQuest(quest);
- SetMainTask(0);
- }
- public void DisableTimerOnMain(int taskIndex=-1)
- {
- mainQuest.DisableTimerOnTask(taskIndex);
- }
- public void SetMainTask(int taskIndex)
- {
- mainQuest.SetTaskActive(taskIndex);
- if(mainQuest.IsAnyToShow)
- {
- mainQuest.UpdateTasksForLinearQuestsIncludingHiddenFlag(taskIndex);
- if (mainQuest.NumOfVisibleTasks == 0)
- {
- mainQuest.ShowNearestNonhiddenTask(GameGlobal.Instance.GetQuestIndex());
- }
- }
- UpdateLayout();
- }
- public void RemoveMainQuest()
- {
- mainQuest.Hide();
- mainQuest.RemoveQuest();
- }
- public void RemoveSideQuest()
- {
- sideQuest.Hide();
- sideQuest.RemoveQuest();
- }
- public void SetMainTask(string taskId)
- {
- mainQuest.SetTaskActive(taskId);
- if(mainQuest.IsAnyToShow)
- {
- mainQuest.UpdateTasksForLinearQuestsIncludingHiddenFlag(mainQuest.LastActive);
- if (mainQuest.NumOfVisibleTasks == 0)
- {
- mainQuest.ShowNearestNonhiddenTask(GameGlobal.Instance.GetQuestIndex());
- }
- }
- UpdateLayout();
- }
- public void CompleteMainTask(int taskIndex)
- {
- mainQuest.SetTaskComplete(taskIndex);
- }
- public void CompleteMainTask(string taskId)
- {
- mainQuest.SetTaskComplete(taskId);
- }
- public void SetSideQuest(DataTools.Quest quest)
- {
- sideQuest.SetQuest(quest);
- if (sideQuest.IsAnyToShow)
- {
- EnableSideQuests(true);
- }
- }
- public void SetSideTask(int taskIndex)
- {
- sideQuest.SetTaskActive(taskIndex);
- }
- public void CompleteSideTask(int taskIndex)
- {
- sideQuest.SetTaskComplete(taskIndex);
- if (!sideQuest.IsAnyToShow)
- {
- EnableSideQuests(false);
- }
- }
- public void EnableSideQuests(bool enable=false)
- {
- sideQuest.gameObject.SetActive(enable);
- }
- public void ShowMainQuest()
- {
- mainQuest.Show();
- UpdateLayout();
- }
- public void HideMainQuest()
- {
- mainQuest.Hide();
- HideSideQuest();
- }
- public void ShowSideQuest()
- {
- sideQuest.Show();
- UpdateLayout();
- }
- public void HideSideQuest()
- {
- sideQuest.Hide();
- }
- public void SetSimpleTask(string task, string title="")
- {
- if(mainQuest.IsQuestComplete)
- {
- mainQuest.RemoveQuest();
- mainQuest.SetFakeTask(task, title);
- }
- }
- private void AttachEvents()
- {
- GameGlobal.Instance.OnTaskCompleted += CompleteMainTask;
- GameGlobal.Instance.OnQuestChanged += SetMainQuest;
- }
- public void UpdateState()
- {
-
- }
- private void UpdateLayout()
- {
- UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(container);
- }
- }
|