< Summary

Class:PublicChatChannelComponentView
Assembly:WorldChatWindowHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/PublicChatChannelComponentView.cs
Covered lines:42
Uncovered lines:12
Coverable lines:54
Total lines:134
Line coverage:77.7% (42 of 54)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
add_OnFocused(...)0%110100%
remove_OnFocused(...)0%110100%
Create()0%110100%
Awake()0%110100%
RefreshControl()0%110100%
Hide()0%110100%
Show()0%110100%
Configure(...)0%110100%
ActivatePreview()0%6.64045.45%
ActivatePreviewInstantly()0%3.023087.5%
DeactivatePreview()0%6.64045.45%
OnPointerDown(...)0%220100%
SetAlpha()0%660100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/WorldChatWindowHUD/PublicChatChannelComponentView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.EventSystems;
 6using UnityEngine.UI;
 7
 8public class PublicChatChannelComponentView : BaseComponentView, IChannelChatWindowView, IComponentModelConfig<PublicCha
 9{
 10    [SerializeField] internal Button closeButton;
 11    [SerializeField] internal Button backButton;
 12    [SerializeField] internal TMP_Text nameLabel;
 13    [SerializeField] internal TMP_Text descriptionLabel;
 14    [SerializeField] internal ChatHUDView chatView;
 15    [SerializeField] internal PublicChatChannelModel model;
 16    [SerializeField] internal CanvasGroup[] previewCanvasGroup;
 17    [SerializeField] internal Vector2 previewModeSize;
 18
 19    private Coroutine alphaRoutine;
 20    private Vector2 originalSize;
 21
 22    public event Action OnClose;
 23    public event Action OnBack;
 24    public event Action<bool> OnFocused
 25    {
 326        add => onFocused += value;
 127        remove => onFocused -= value;
 28    }
 29    public event Action OnClickOverWindow;
 30
 031    public bool IsActive => gameObject.activeInHierarchy;
 132    public IChatHUDComponentView ChatHUD => chatView;
 033    public RectTransform Transform => (RectTransform) transform;
 034    public bool IsFocused => isFocused;
 35
 36    public static PublicChatChannelComponentView Create()
 37    {
 1238        return Instantiate(Resources.Load<PublicChatChannelComponentView>("SocialBarV1/GeneralChatChannelHUD"));
 39    }
 40
 41    public override void Awake()
 42    {
 1243        base.Awake();
 1244        originalSize = ((RectTransform) transform).sizeDelta;
 1345        backButton.onClick.AddListener(() => OnBack?.Invoke());
 1346        closeButton.onClick.AddListener(() => OnClose?.Invoke());
 1247    }
 48
 49    public override void RefreshControl()
 50    {
 151        nameLabel.text = $"#{model.name}";
 152        descriptionLabel.text = model.description;
 153    }
 54
 155    public void Hide() => gameObject.SetActive(false);
 56
 257    public void Show() => gameObject.SetActive(true);
 58
 59    public void Configure(PublicChatChannelModel model)
 60    {
 161        this.model = model;
 162        RefreshControl();
 163    }
 64
 65    public void ActivatePreview()
 66    {
 67        const float alphaTarget = 0f;
 68
 169        if (!gameObject.activeInHierarchy)
 70        {
 071            foreach (var group in previewCanvasGroup)
 072                group.alpha = alphaTarget;
 73
 074            return;
 75        }
 76
 177        if (alphaRoutine != null)
 078            StopCoroutine(alphaRoutine);
 79
 180        alphaRoutine = StartCoroutine(SetAlpha(alphaTarget, 0.5f));
 181        ((RectTransform) transform).sizeDelta = previewModeSize;
 182    }
 83
 84    public void ActivatePreviewInstantly()
 85    {
 286        if (alphaRoutine != null)
 087            StopCoroutine(alphaRoutine);
 88
 89        const float alphaTarget = 0f;
 3290        foreach (var group in previewCanvasGroup)
 1491            group.alpha = alphaTarget;
 92
 293        ((RectTransform) transform).sizeDelta = previewModeSize;
 294    }
 95
 96    public void DeactivatePreview()
 97    {
 98        const float alphaTarget = 1f;
 99
 1100        if (!gameObject.activeInHierarchy)
 101        {
 0102            foreach (var group in previewCanvasGroup)
 0103                group.alpha = alphaTarget;
 104
 0105            return;
 106        }
 107
 1108        if (alphaRoutine != null)
 0109            StopCoroutine(alphaRoutine);
 110
 1111        alphaRoutine = StartCoroutine(SetAlpha(alphaTarget, 0.5f));
 1112        ((RectTransform) transform).sizeDelta = originalSize;
 1113    }
 114
 1115    public void OnPointerDown(PointerEventData eventData) => OnClickOverWindow?.Invoke();
 116
 117    private IEnumerator SetAlpha(float target, float duration)
 118    {
 2119        var t = 0f;
 120
 225121        while (t < duration)
 122        {
 223123            t += Time.deltaTime;
 124
 3568125            foreach (var group in previewCanvasGroup)
 1561126                group.alpha = Mathf.Lerp(group.alpha, target, t / duration);
 127
 223128            yield return null;
 129        }
 130
 32131        foreach (var group in previewCanvasGroup)
 14132            group.alpha = target;
 2133    }
 134}