| | 1 | | using System.Linq; |
| | 2 | | using TMPro; |
| | 3 | | using UnityEngine; |
| | 4 | |
|
| | 5 | | namespace DCL.Huds.QuestsPanel |
| | 6 | | { |
| | 7 | | public class QuestsPanelSection : MonoBehaviour |
| | 8 | | { |
| | 9 | | [SerializeField] internal TextMeshProUGUI sectionName; |
| | 10 | | [SerializeField] internal RectTransform titleContainer; |
| | 11 | | [SerializeField] internal RectTransform tasksContainer; |
| | 12 | | [SerializeField] internal QuestsPanelTaskFactory factory; |
| | 13 | |
|
| | 14 | | public void Populate(QuestModel quest, QuestSection section) |
| | 15 | | { |
| 7 | 16 | | CleanUpTasksList(); |
| 7 | 17 | | titleContainer.gameObject.SetActive(!string.IsNullOrEmpty(section.name)); |
| 7 | 18 | | sectionName.text = section.name; |
| 21 | 19 | | var orderedTasks = section.tasks.OrderBy(x => x.progress >= 1).ThenBy(x => x.completionTime).ToArray(); |
| 28 | 20 | | foreach (QuestTask task in orderedTasks) |
| | 21 | | { |
| 7 | 22 | | CreateTask(quest, task); |
| | 23 | | } |
| 7 | 24 | | } |
| | 25 | |
|
| | 26 | | internal void CreateTask(QuestModel quest, QuestTask task) |
| | 27 | | { |
| 7 | 28 | | if (task.status == QuestsLiterals.Status.BLOCKED) |
| 0 | 29 | | return; |
| | 30 | |
|
| 7 | 31 | | GameObject prefab = factory.GetPrefab(task.type); |
| 7 | 32 | | if (prefab == null) |
| | 33 | | { |
| 0 | 34 | | Debug.LogError($"Type: {task.type} was not found in QuestTaskFactory"); |
| 0 | 35 | | return; |
| | 36 | | } |
| | 37 | |
|
| 7 | 38 | | var taskUIEntry = Instantiate(prefab, tasksContainer).GetComponent<IQuestsPanelTask>(); |
| 7 | 39 | | taskUIEntry.Populate(quest, task); |
| 7 | 40 | | } |
| | 41 | |
|
| | 42 | | internal void CleanUpTasksList() |
| | 43 | | { |
| 14 | 44 | | for (int i = tasksContainer.childCount - 1; i >= 0; i--) |
| 0 | 45 | | Destroy(tasksContainer.GetChild(i).gameObject); |
| 7 | 46 | | } |
| | 47 | | } |
| | 48 | | } |