< Summary

Class:DCL.Quests.QuestStartedPopupComponentView
Assembly:Quests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Quests/QuestOfferHUD/QuestStartedPopupComponentView.cs
Covered lines:26
Uncovered lines:3
Coverable lines:29
Total lines:80
Line coverage:89.6% (26 of 29)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:8
Method coverage:87.5% (7 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
RefreshControl()0%2100%
SetQuestName(...)0%110100%
SetVisible(...)0%440100%
Show()0%110100%
Hide()0%110100%
WaitAndHide()0%3.583060%
Dispose()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Quests/QuestOfferHUD/QuestStartedPopupComponentView.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using System;
 3using TMPro;
 4using UIComponents.Scripts.Components;
 5using UnityEngine;
 6using UnityEngine.UI;
 7using DG.Tweening;
 8using System.Threading;
 9
 10namespace DCL.Quests
 11{
 12    public class QuestStartedPopupComponentView : BaseComponentView<QuestStartedPopupComponentModel>, IQuestStartedPopup
 13    {
 14        private const float FADE_DURATION = 0.167f;
 15        private const float SHOW_HUD_TIME = 10f;
 16
 17        [SerializeField] internal TMP_Text questNameText;
 18        [SerializeField] internal Button openQuestLogButton;
 19        [SerializeField] internal CanvasGroup container;
 20
 21        public event Action OnOpenQuestLog;
 22        internal bool visible = false;
 23        private CancellationTokenSource cts;
 24
 25        public override void Awake()
 26        {
 327            openQuestLogButton.onClick.RemoveAllListeners();
 328            openQuestLogButton.onClick.AddListener(()=>
 29            {
 130                SetVisible(false);
 131                OnOpenQuestLog?.Invoke();
 132            });
 333            container.alpha = 0;
 334        }
 35
 36        public override void RefreshControl() =>
 037            SetQuestName(model.questName);
 38
 39        public void SetQuestName(string questName)
 40        {
 141            model.questName = questName;
 142            questNameText.text = questName;
 143        }
 44
 45        public void SetVisible(bool setVisible)
 46        {
 347            visible = setVisible;
 48
 349            if (setVisible)
 50            {
 151                Show();
 152                cts?.Cancel();
 153                cts?.Dispose();
 154                cts = new CancellationTokenSource();
 155                WaitAndHide(cts).Forget();
 56            }
 57            else
 258                Hide();
 259        }
 60
 61        private void Show() =>
 162            container.DOFade(1, FADE_DURATION).SetEase(Ease.InOutQuad);
 63
 64        private void Hide() =>
 265            container.DOFade(0, FADE_DURATION).SetEase(Ease.InOutQuad);
 66
 67        private async UniTaskVoid WaitAndHide(CancellationTokenSource ct)
 68        {
 369            await UniTask.Delay(TimeSpan.FromSeconds(SHOW_HUD_TIME), cancellationToken: cts.Token);
 070            Hide();
 071        }
 72
 73        public override void Dispose()
 74        {
 675            cts?.Cancel();
 676            cts?.Dispose();
 677            cts = null;
 678        }
 79    }
 80}