< Summary

Class:ChatHeadButton
Assembly:TaskbarHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/ChatHeadButton.cs
Covered lines:15
Uncovered lines:8
Coverable lines:23
Total lines:56
Line coverage:65.2% (15 of 23)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ChatHeadButton()0%110100%
Initialize(...)0%3.053081.82%
Profile_OnFaceSnapshotReadyEvent(...)0%12300%
OnDestroy()0%220100%
OnPointerEnter(...)0%2100%
OnPointerExit(...)0%2100%
SetOnlineStatus(...)0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TaskbarHUD/ChatHeadButton.cs

#LineLine coverage
 1using UnityEngine;
 2using UnityEngine.EventSystems;
 3using UnityEngine.UI;
 4
 5public class ChatHeadButton : TaskbarButton, IPointerEnterHandler, IPointerExitHandler
 6{
 7    [SerializeField] internal ShowHideAnimator labelContainer;
 8    [SerializeField] internal TMPro.TextMeshProUGUI label;
 9    [SerializeField] internal RawImage portrait;
 10    [SerializeField] internal UnreadNotificationBadge unreadNotificationBadge;
 11    [SerializeField] internal Image onlineStatusIndicator;
 212    [SerializeField] internal Color onlineColor = Color.green;
 213    [SerializeField] internal Color offlineColor = Color.gray;
 14
 15    internal ulong lastTimestamp;
 16    internal UserProfile profile;
 17
 18    public void Initialize(UserProfile profile)
 19    {
 120        base.Initialize();
 121        this.profile = profile;
 122        unreadNotificationBadge.Initialize(ChatController.i, profile.userId);
 23
 124        if (profile.userName.Length > 10)
 125            label.text = profile.userName.Substring(0, 10) + "...";
 26        else
 027            label.text = profile.userName;
 28
 129        if (profile.faceSnapshot != null)
 030            portrait.texture = profile.faceSnapshot;
 31        else
 132            profile.OnFaceSnapshotReadyEvent += Profile_OnFaceSnapshotReadyEvent;
 33
 134        SetOnlineStatus(false);
 135    }
 36
 37    private void Profile_OnFaceSnapshotReadyEvent(Texture2D portraitTexture)
 38    {
 039        profile.OnFaceSnapshotReadyEvent -= Profile_OnFaceSnapshotReadyEvent;
 40
 041        if (portraitTexture != null && this.portrait.texture != portraitTexture)
 042            this.portrait.texture = portraitTexture;
 043    }
 44
 45    private void OnDestroy()
 46    {
 147        if (profile != null)
 148            profile.OnFaceSnapshotReadyEvent -= Profile_OnFaceSnapshotReadyEvent;
 149    }
 50
 051    public void OnPointerEnter(PointerEventData eventData) { labelContainer.Show(); }
 52
 053    public void OnPointerExit(PointerEventData eventData) { labelContainer.Hide(); }
 54
 255    public void SetOnlineStatus(bool isOnline) { onlineStatusIndicator.color = isOnline ? onlineColor : offlineColor; }
 56}