| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using TMPro; |
| | 4 | | using UIComponents.Scripts.Components; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | namespace DCL.Quests |
| | 9 | | { |
| | 10 | | public class QuestTrackerComponentView : BaseComponentView<QuestTrackerComponentModel>, IQuestTrackerComponentView |
| | 11 | | { |
| | 12 | | [SerializeField] internal TMP_Text questTitleText; |
| | 13 | | [SerializeField] internal Transform stepsContainer; |
| | 14 | | [SerializeField] internal QuestStepComponentView stepPrefab; |
| | 15 | | [SerializeField] internal Button jumpInButton; |
| | 16 | |
|
| | 17 | | public event Action<Vector2Int> OnJumpIn; |
| 6 | 18 | | internal List<GameObject> currentQuestSteps = new(); |
| | 19 | |
|
| | 20 | | public override void Awake() |
| | 21 | | { |
| 5 | 22 | | jumpInButton.onClick.RemoveAllListeners(); |
| 6 | 23 | | jumpInButton.onClick.AddListener(() => OnJumpIn?.Invoke(model.coordinates)); |
| 5 | 24 | | SetVisible(false); |
| 5 | 25 | | SetSupportsJumpIn(false); |
| 5 | 26 | | } |
| | 27 | |
|
| | 28 | | public override void RefreshControl() |
| | 29 | | { |
| 0 | 30 | | if (model == null) |
| 0 | 31 | | return; |
| | 32 | |
|
| 0 | 33 | | SetQuestTitle(model.questTitle); |
| 0 | 34 | | SetQuestCoordinates(model.coordinates); |
| 0 | 35 | | SetQuestSteps(model.questSteps); |
| 0 | 36 | | SetSupportsJumpIn(model.supportsJumpIn); |
| 0 | 37 | | } |
| | 38 | |
|
| | 39 | | public void SetQuestTitle(string questTitle) |
| | 40 | | { |
| 1 | 41 | | model.questTitle = questTitle; |
| 1 | 42 | | questTitleText.text = questTitle; |
| 1 | 43 | | } |
| | 44 | |
|
| | 45 | | public void SetQuestCoordinates(Vector2Int coordinates) => |
| 1 | 46 | | model.coordinates = coordinates; |
| | 47 | |
|
| | 48 | | public void SetQuestSteps(List<QuestStepComponentModel> questSteps) |
| | 49 | | { |
| 2 | 50 | | foreach (var step in currentQuestSteps) |
| 0 | 51 | | Destroy(step); |
| | 52 | |
|
| 6 | 53 | | foreach (var step in questSteps) |
| | 54 | | { |
| 2 | 55 | | QuestStepComponentView questStep = Instantiate(stepPrefab, stepsContainer); |
| 2 | 56 | | questStep.SetModel(step); |
| 2 | 57 | | questStep.OnJumpIn += OnJumpIn; |
| 2 | 58 | | currentQuestSteps.Add(questStep.gameObject); |
| | 59 | | } |
| 1 | 60 | | } |
| | 61 | |
|
| | 62 | | public void SetSupportsJumpIn(bool supportsJumpIn) |
| | 63 | | { |
| 7 | 64 | | model.supportsJumpIn = supportsJumpIn; |
| 7 | 65 | | jumpInButton.gameObject.SetActive(supportsJumpIn); |
| 7 | 66 | | } |
| | 67 | |
|
| | 68 | | public void SetVisible(bool isVisible) => |
| 5 | 69 | | gameObject.SetActive(isVisible); |
| | 70 | | } |
| | 71 | |
|
| | 72 | | } |