< Summary

Class:OwnersTooltipView
Assembly:NFTPromptHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NFTPromptHUD/Scripts/OwnersTooltipView.cs
Covered lines:24
Uncovered lines:14
Coverable lines:38
Total lines:106
Line coverage:63.1% (24 of 38)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Show()0%2.032080%
Hide(...)0%2.262060%
KeepOnScreen()0%6200%
SetElements(...)0%330100%
IsActive()0%110100%
Awake()0%110100%
OnDestroy()0%110100%
ViewAllPressed()0%6200%
OnPointerEnter()0%6200%
OnPointerExit()0%6200%
HideRoutine()0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NFTPromptHUD/Scripts/OwnersTooltipView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using UnityEngine;
 5
 6internal interface IOwnersTooltipView
 7{
 8    event Action OnViewAllPressed;
 9    event Action OnFocusLost;
 10    void Show();
 11    void Hide(bool instant);
 12    void KeepOnScreen();
 13    void SetElements(List<IOwnerInfoElement> elements);
 14    bool IsActive();
 15}
 16
 17internal class OwnersTooltipView : MonoBehaviour, IOwnersTooltipView
 18{
 19    internal const int MAX_ELEMENTS = 5;
 20    private const int ADDRESS_MAX_CHARS = 11;
 21    private const float HIDE_DELAY = 0.3f;
 22    private const float ELEMENT_FONT_SIZE = 16;
 23    private const float ELEMENT_HORIZONTAL_SPACING = 10;
 24
 25    [SerializeField] internal Transform ownerElementsContainer;
 26    [SerializeField] internal Button_OnPointerDown viewAllButton;
 27    [SerializeField] private ShowHideAnimator showHideAnimator;
 28    [SerializeField] private UIHoverCallback hoverArea;
 29
 30    public event Action OnViewAllPressed;
 31    public event Action OnFocusLost;
 32    public event Action OnFocus;
 33
 34    private Coroutine hideRoutine;
 35
 36    void IOwnersTooltipView.Show()
 37    {
 138        if (hideRoutine != null)
 039            StopCoroutine(hideRoutine);
 40
 141        gameObject.SetActive(true);
 142        showHideAnimator.Show();
 143    }
 44
 45    void IOwnersTooltipView.Hide(bool instant)
 46    {
 247        if (instant)
 48        {
 249            gameObject.SetActive(false);
 250        }
 51        else
 52        {
 053            hideRoutine = StartCoroutine(HideRoutine());
 54        }
 055    }
 56
 57    void IOwnersTooltipView.KeepOnScreen()
 58    {
 059        if (hideRoutine != null)
 060            StopCoroutine(hideRoutine);
 61
 062        showHideAnimator.Show(true);
 063    }
 64
 65    void IOwnersTooltipView.SetElements(List<IOwnerInfoElement> elements)
 66    {
 2467        for (int i = 0; i < elements.Count && i < MAX_ELEMENTS; i++)
 68        {
 1069            elements[i].SetParent(ownerElementsContainer);
 1070            elements[i].SetAddressLength(ADDRESS_MAX_CHARS);
 1071            elements[i].SetColorIndex(i);
 1072            elements[i].SetConfig(ELEMENT_FONT_SIZE, ELEMENT_HORIZONTAL_SPACING);
 1073            elements[i].SetActive(true);
 74        }
 275        viewAllButton.gameObject.SetActive(elements.Count > MAX_ELEMENTS);
 276    }
 77
 378    bool IOwnersTooltipView.IsActive() { return gameObject.activeSelf; }
 79
 80    private void Awake()
 81    {
 782        viewAllButton.onPointerDown += ViewAllPressed;
 783        hoverArea.OnPointerEnter += OnPointerEnter;
 784        hoverArea.OnPointerExit += OnPointerExit;
 785    }
 86
 87    private void OnDestroy()
 88    {
 789        viewAllButton.onPointerDown -= ViewAllPressed;
 790        hoverArea.OnPointerEnter -= OnPointerEnter;
 791        hoverArea.OnPointerExit -= OnPointerExit;
 792    }
 93
 094    private void ViewAllPressed() { OnViewAllPressed?.Invoke(); }
 95
 096    private void OnPointerEnter() { OnFocus?.Invoke(); }
 97
 098    private void OnPointerExit() { OnFocusLost?.Invoke(); }
 99
 100    IEnumerator HideRoutine()
 101    {
 0102        yield return new WaitForSeconds(HIDE_DELAY);
 0103        showHideAnimator.Hide();
 0104        hideRoutine = null;
 0105    }
 106}