| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.Huds.QuestsTracker; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Huds.QuestsTracker |
| | 7 | | { |
| | 8 | | public class QuestsNotificationsController : MonoBehaviour |
| | 9 | | { |
| 1 | 10 | | internal static float NOTIFICATIONS_SEPARATION { get; set; } = 0.5f; |
| 1 | 11 | | public static float DEFAULT_NOTIFICATION_DURATION { get; set; } = 2.5f; |
| | 12 | |
|
| 16 | 13 | | internal readonly Queue<IQuestNotification> notificationsQueue = new Queue<IQuestNotification>(); |
| | 14 | |
|
| | 15 | | [SerializeField] private GameObject questCompletedPrefab; |
| | 16 | | [SerializeField] private GameObject rewardObtainedPrefab; |
| | 17 | | private bool isDestroyed = false; |
| | 18 | |
|
| | 19 | | internal static QuestsNotificationsController Create() |
| | 20 | | { |
| 0 | 21 | | QuestsNotificationsController view = Instantiate(Resources.Load<GameObject>("QuestsNotificationsHUD")).GetCo |
| | 22 | | #if UNITY_EDITOR |
| 0 | 23 | | view.gameObject.name = "_QuestsNotificationsHUDView"; |
| | 24 | | #endif |
| 0 | 25 | | return view; |
| | 26 | | } |
| | 27 | |
|
| 28 | 28 | | private void Awake() { StartCoroutine(ProcessSectionsNotificationQueue()); } |
| | 29 | |
|
| | 30 | | public void ShowQuestCompleted(QuestModel quest) |
| | 31 | | { |
| 3 | 32 | | var questNotification = Instantiate(questCompletedPrefab, transform).GetComponent<QuestNotification_QuestCom |
| 3 | 33 | | questNotification.Populate(quest); |
| 3 | 34 | | questNotification.gameObject.SetActive(false); |
| 3 | 35 | | notificationsQueue.Enqueue(questNotification); |
| 3 | 36 | | } |
| | 37 | |
|
| | 38 | | public void ShowRewardObtained(QuestReward reward) |
| | 39 | | { |
| 0 | 40 | | var questNotification = Instantiate(rewardObtainedPrefab, transform).GetComponent<QuestNotification_RewardOb |
| 0 | 41 | | questNotification.Populate(reward); |
| 0 | 42 | | questNotification.gameObject.SetActive(false); |
| 0 | 43 | | notificationsQueue.Enqueue(questNotification); |
| 0 | 44 | | } |
| | 45 | |
|
| 0 | 46 | | public void SetVisibility(bool visible) { gameObject.SetActive(visible); } |
| | 47 | | public void Dispose() |
| | 48 | | { |
| 0 | 49 | | if (!isDestroyed) |
| 0 | 50 | | Destroy(gameObject); |
| 0 | 51 | | } |
| | 52 | |
|
| 28 | 53 | | private void OnDestroy() { isDestroyed = true; } |
| | 54 | |
|
| | 55 | | private IEnumerator ProcessSectionsNotificationQueue() |
| | 56 | | { |
| 16 | 57 | | while (true) |
| | 58 | | { |
| 30 | 59 | | if (notificationsQueue.Count > 0) |
| | 60 | | { |
| 2 | 61 | | IQuestNotification notification = notificationsQueue.Dequeue(); |
| 2 | 62 | | notification.Show(); |
| 2 | 63 | | yield return notification.Waiter(); |
| 2 | 64 | | notification.Dispose(); |
| 2 | 65 | | } |
| | 66 | |
|
| 30 | 67 | | yield return WaitForSecondsCache.Get(NOTIFICATIONS_SEPARATION); |
| | 68 | | } |
| | 69 | | } |
| | 70 | | } |
| | 71 | | } |