< Summary

Class:UsersAroundListHUDListElementView
Assembly:UsersAroundListHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/UsersAroundListHUD/UsersAroundListHUDListElementView.cs
Covered lines:38
Uncovered lines:31
Coverable lines:69
Total lines:168
Line coverage:55% (38 of 69)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UsersAroundListHUDListElementView()0%110100%
Start()0%2100%
OnEnable()0%2100%
SetUserProfile(...)0%2.062075%
SetMuted(...)0%110100%
SetRecording(...)0%2100%
SetBlocked(...)0%110100%
OnPoolRelease()0%330100%
OnPoolGet()0%22090%
SetupFriends(...)0%3.333066.67%
SetAvatarPreviewImage(...)0%2100%
OnSoundButtonPressed()0%12300%
OnPointerEnter(...)0%2100%
OnPointerExit(...)0%2100%
OnFriendActionUpdate(...)0%6200%
SetupFriendship(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/UsersAroundListHUD/UsersAroundListHUDListElementView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using DCL.Components;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7using UnityEngine.EventSystems;
 8
 9internal class UsersAroundListHUDListElementView : MonoBehaviour, IPoolLifecycleHandler, IPointerEnterHandler, IPointerE
 10{
 111    private static readonly int talkingAnimation = Animator.StringToHash("Talking");
 12
 13    public event Action<string, bool> OnMuteUser;
 14    public event Action<Vector3, string> OnShowUserContexMenu;
 15
 16    [SerializeField] internal TextMeshProUGUI userName;
 17    [SerializeField] internal GameObject friendLabel;
 18    [SerializeField] internal RawImage avatarPreview;
 19    [SerializeField] internal GameObject blockedGO;
 20    [SerializeField] internal Button soundButton;
 21    [SerializeField] internal GameObject muteGO;
 22    [SerializeField] internal GameObject backgroundHover;
 23    [SerializeField] internal Button menuButton;
 24    [SerializeField] internal Transform contexMenuRefPosition;
 25    [SerializeField] internal Animator talkingAnimator;
 26
 27    private UserProfile profile;
 28    private bool isMuted = false;
 29    private bool isRecording = false;
 30
 31    private void Start()
 32    {
 033        soundButton.onClick.AddListener(OnSoundButtonPressed);
 034        menuButton.onClick.AddListener(() =>
 35        {
 036            if (profile)
 37            {
 038                OnShowUserContexMenu?.Invoke(contexMenuRefPosition.position, profile.userId);
 39            }
 040        });
 041    }
 42
 043    private void OnEnable() { talkingAnimator.SetBool(talkingAnimation, isRecording); }
 44
 45    public void SetUserProfile(UserProfile profile)
 46    {
 347        this.profile = profile;
 48
 349        userName.text = profile.userName;
 50
 351        if (profile.faceSnapshot)
 52        {
 053            SetAvatarPreviewImage(profile.faceSnapshot);
 054        }
 55        else
 56        {
 357            profile.OnFaceSnapshotReadyEvent += SetAvatarPreviewImage;
 58        }
 59
 360        SetupFriends(profile.userId);
 361    }
 62
 63    public void SetMuted(bool isMuted)
 64    {
 365        this.isMuted = isMuted;
 366        muteGO.SetActive(isMuted);
 367    }
 68
 69    public void SetRecording(bool isRecording)
 70    {
 071        this.isRecording = isRecording;
 072        talkingAnimator.SetBool(talkingAnimation, isRecording);
 073    }
 74
 675    public void SetBlocked(bool blocked) { blockedGO.SetActive(blocked); }
 76
 77    public void OnPoolRelease()
 78    {
 679        avatarPreview.texture = null;
 680        userName.text = string.Empty;
 681        isMuted = false;
 682        isRecording = false;
 83
 684        if (profile)
 85        {
 286            profile.OnFaceSnapshotReadyEvent -= SetAvatarPreviewImage;
 287            profile = null;
 88        }
 89
 690        if (FriendsController.i != null)
 91        {
 692            FriendsController.i.OnUpdateFriendship -= OnFriendActionUpdate;
 93        }
 94
 695        gameObject.SetActive(false);
 696    }
 97
 98    public void OnPoolGet()
 99    {
 3100        muteGO.SetActive(false);
 101
 3102        if (talkingAnimator.isActiveAndEnabled)
 0103            talkingAnimator.SetBool(talkingAnimation, false);
 104
 3105        avatarPreview.texture = null;
 3106        userName.text = string.Empty;
 3107        backgroundHover.SetActive(false);
 3108        menuButton.gameObject.SetActive(false);
 3109        blockedGO.SetActive(false);
 3110        gameObject.SetActive(true);
 3111    }
 112
 113    void SetupFriends(string userId)
 114    {
 3115        if (FriendsController.i == null)
 116        {
 0117            return;
 118        }
 119
 3120        if (FriendsController.i.friends.TryGetValue(userId, out FriendsController.UserStatus status))
 121        {
 0122            SetupFriendship(status.friendshipStatus);
 0123        }
 124        else
 125        {
 3126            SetupFriendship(FriendshipStatus.NONE);
 127        }
 128
 3129        FriendsController.i.OnUpdateFriendship -= OnFriendActionUpdate;
 3130        FriendsController.i.OnUpdateFriendship += OnFriendActionUpdate;
 3131    }
 132
 0133    void SetAvatarPreviewImage(Texture texture) { avatarPreview.texture = texture; }
 134
 135    void OnSoundButtonPressed()
 136    {
 0137        if (profile == null)
 138        {
 0139            return;
 140        }
 141
 0142        OnMuteUser?.Invoke(profile.userId, !isMuted);
 0143    }
 144
 145    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
 146    {
 0147        backgroundHover.SetActive(true);
 0148        menuButton.gameObject.SetActive(true);
 0149    }
 150
 151    void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
 152    {
 0153        backgroundHover.SetActive(false);
 0154        menuButton.gameObject.SetActive(false);
 0155    }
 156
 157    void OnFriendActionUpdate(string userId, FriendshipAction action)
 158    {
 0159        if (profile.userId != userId)
 160        {
 0161            return;
 162        }
 163
 0164        friendLabel.SetActive(action == FriendshipAction.APPROVED);
 0165    }
 166
 6167    void SetupFriendship(FriendshipStatus friendshipStatus) { friendLabel.SetActive(friendshipStatus == FriendshipStatus
 168}