< Summary

Class:TooltipController
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/TooltipController.cs
Covered lines:28
Uncovered lines:7
Coverable lines:35
Total lines:84
Line coverage:80% (28 of 35)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%110100%
Dispose()0%110100%
SetTooltipText(...)0%110100%
ShowTooltip(...)0%110100%
ShowTooltip(...)0%2.012085.71%
HideTooltip()0%2100%
ChangeAlpha()0%5.255078.57%
KillTooltipCoroutine()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/TooltipController.cs

#LineLine coverage
 1using System.Collections;
 2using UnityEngine;
 3using UnityEngine.EventSystems;
 4
 5public interface ITooltipController
 6{
 7    void Initialize(ITooltipView view);
 8    void Dispose();
 9    void SetTooltipText(string text);
 10    void ShowTooltip(BaseEventData data);
 11    void ShowTooltip(BaseEventData data, Vector3 offset);
 12    void HideTooltip();
 13}
 14
 15public class TooltipController : ITooltipController
 16{
 17    internal ITooltipView view;
 18    internal Coroutine changeAlphaCoroutine;
 19
 20    public void Initialize(ITooltipView view)
 21    {
 322        this.view = view;
 23
 324        view.OnHideTooltip += HideTooltip;
 325    }
 26
 27    public void Dispose()
 28    {
 329        KillTooltipCoroutine();
 30
 331        view.OnHideTooltip -= HideTooltip;
 332    }
 33
 234    public void SetTooltipText(string text) { view.SetText(text); }
 35
 236    public void ShowTooltip(BaseEventData data) { ShowTooltip(data, Vector3.zero); }
 37
 38    public void ShowTooltip(BaseEventData data, Vector3 offset)
 39    {
 240        if (!(data is PointerEventData dataConverted))
 041            return;
 42
 243        RectTransform selectedRT = dataConverted.pointerEnter.GetComponent<RectTransform>();
 244        view.SetTooltipPosition(offset + selectedRT.position);
 45
 246        KillTooltipCoroutine();
 47
 248        changeAlphaCoroutine = CoroutineStarter.Start(ChangeAlpha(0, 1));
 249    }
 50
 51    public void HideTooltip()
 52    {
 053        KillTooltipCoroutine();
 054        changeAlphaCoroutine = CoroutineStarter.Start(ChangeAlpha(1, 0));
 055    }
 56
 57    internal IEnumerator ChangeAlpha(float from, float to)
 58    {
 259        if (view.currentAlpha == to)
 060            yield break;
 61
 262        view.SetTooltipAlpha(from);
 63
 264        float currentAlpha = from;
 265        float destinationAlpha = to;
 66
 267        float fractionOfJourney = 0;
 268        float speed = view.alphaTranstionSpeed;
 269        while (fractionOfJourney < 1)
 70        {
 271            fractionOfJourney += Time.unscaledDeltaTime * speed;
 272            float lerpedAlpha = Mathf.Lerp(currentAlpha, destinationAlpha, fractionOfJourney);
 273            view.SetTooltipAlpha(lerpedAlpha);
 274            yield return null;
 75        }
 076        changeAlphaCoroutine = null;
 077    }
 78
 79    internal void KillTooltipCoroutine()
 80    {
 581        if (changeAlphaCoroutine != null)
 282            CoroutineStarter.Stop(changeAlphaCoroutine);
 583    }
 84}