< Summary

Class:UsersAroundListHUDListElementView
Assembly:UsersAroundListHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/UsersAroundListHUD/UsersAroundListHUDListElementView.cs
Covered lines:37
Uncovered lines:42
Coverable lines:79
Total lines:187
Line coverage:46.8% (37 of 79)
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%12300%
OnDisable()0%6200%
OnDestroy()0%6200%
SetUserProfile(...)0%3.213071.43%
SetMuted(...)0%110100%
SetRecording(...)0%6200%
SetBlocked(...)0%110100%
OnPoolRelease()0%440100%
OnPoolGet()0%22090%
SetupFriends(...)0%3.333066.67%
SetAvatarSnapshotImage(...)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;
 4using DCL.Components;
 5using TMPro;
 6using UnityEngine;
 7using UnityEngine.UI;
 8using UnityEngine.EventSystems;
 9
 10internal class UsersAroundListHUDListElementView : MonoBehaviour, IPoolLifecycleHandler, IPointerEnterHandler, IPointerE
 11{
 112    private static readonly int talkingAnimation = Animator.StringToHash("Talking");
 13
 14    public event Action<string, bool> OnMuteUser;
 15    public event Action<Vector3, string> OnShowUserContexMenu;
 16
 17    [SerializeField] internal TextMeshProUGUI userName;
 18    [SerializeField] internal GameObject friendLabel;
 19    [SerializeField] internal RawImage avatarPreview;
 20    [SerializeField] internal GameObject blockedGO;
 21    [SerializeField] internal Button soundButton;
 22    [SerializeField] internal GameObject muteGO;
 23    [SerializeField] internal GameObject backgroundHover;
 24    [SerializeField] internal Button menuButton;
 25    [SerializeField] internal Transform contexMenuRefPosition;
 26    [SerializeField] internal Animator talkingAnimator;
 27
 28    private UserProfile profile;
 29    private bool isMuted = false;
 30    private bool isRecording = false;
 31
 32    private void Start()
 33    {
 034        soundButton.onClick.AddListener(OnSoundButtonPressed);
 035        menuButton.onClick.AddListener(() =>
 36        {
 037            if (profile)
 38            {
 039                OnShowUserContexMenu?.Invoke(contexMenuRefPosition.position, profile.userId);
 40            }
 041        });
 042    }
 43
 44    private void OnEnable()
 45    {
 046        if ( profile != null )
 047            profile.snapshotObserver.AddListener(SetAvatarSnapshotImage);
 48
 049        if ( talkingAnimator.isActiveAndEnabled )
 050            talkingAnimator.SetBool(talkingAnimation, isRecording);
 051    }
 52
 53    private void OnDisable()
 54    {
 055        if ( profile != null )
 056            profile.snapshotObserver.RemoveListener(SetAvatarSnapshotImage);
 057    }
 58
 59    private void OnDestroy()
 60    {
 061        if ( profile != null )
 062            profile.snapshotObserver.RemoveListener(SetAvatarSnapshotImage);
 063    }
 64
 65    public void SetUserProfile(UserProfile profile)
 66    {
 367        userName.text = profile.userName;
 68
 369        SetupFriends(profile.userId);
 70
 371        if (this.profile != null && isActiveAndEnabled)
 72        {
 073            this.profile.snapshotObserver.RemoveListener(SetAvatarSnapshotImage);
 074            profile.snapshotObserver.AddListener(SetAvatarSnapshotImage);
 75        }
 76
 377        this.profile = profile;
 378    }
 79
 80    public void SetMuted(bool isMuted)
 81    {
 382        this.isMuted = isMuted;
 383        muteGO.SetActive(isMuted);
 384    }
 85
 86    public void SetRecording(bool isRecording)
 87    {
 088        this.isRecording = isRecording;
 89
 090        if ( talkingAnimator.isActiveAndEnabled )
 091            talkingAnimator.SetBool(talkingAnimation, isRecording);
 092    }
 93
 694    public void SetBlocked(bool blocked) { blockedGO.SetActive(blocked); }
 95
 96    public void OnPoolRelease()
 97    {
 698        avatarPreview.texture = null;
 699        userName.text = string.Empty;
 6100        isMuted = false;
 6101        isRecording = false;
 102
 6103        if (profile != null)
 104        {
 2105            profile.snapshotObserver?.RemoveListener(SetAvatarSnapshotImage);
 2106            profile = null;
 107        }
 108
 6109        if (FriendsController.i != null)
 110        {
 6111            FriendsController.i.OnUpdateFriendship -= OnFriendActionUpdate;
 112        }
 113
 6114        gameObject.SetActive(false);
 6115    }
 116
 117    public void OnPoolGet()
 118    {
 3119        muteGO.SetActive(false);
 120
 3121        if (talkingAnimator.isActiveAndEnabled)
 0122            talkingAnimator.SetBool(talkingAnimation, false);
 123
 3124        avatarPreview.texture = null;
 3125        userName.text = string.Empty;
 3126        backgroundHover.SetActive(false);
 3127        menuButton.gameObject.SetActive(false);
 3128        blockedGO.SetActive(false);
 3129        gameObject.SetActive(true);
 3130    }
 131
 132    void SetupFriends(string userId)
 133    {
 3134        if (FriendsController.i == null)
 135        {
 0136            return;
 137        }
 138
 3139        if (FriendsController.i.friends.TryGetValue(userId, out FriendsController.UserStatus status))
 140        {
 0141            SetupFriendship(status.friendshipStatus);
 0142        }
 143        else
 144        {
 3145            SetupFriendship(FriendshipStatus.NONE);
 146        }
 147
 3148        FriendsController.i.OnUpdateFriendship -= OnFriendActionUpdate;
 3149        FriendsController.i.OnUpdateFriendship += OnFriendActionUpdate;
 3150    }
 151
 0152    void SetAvatarSnapshotImage(Texture2D texture) { avatarPreview.texture = texture; }
 153
 154    void OnSoundButtonPressed()
 155    {
 0156        if (profile == null)
 157        {
 0158            return;
 159        }
 160
 0161        OnMuteUser?.Invoke(profile.userId, !isMuted);
 0162    }
 163
 164    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
 165    {
 0166        backgroundHover.SetActive(true);
 0167        menuButton.gameObject.SetActive(true);
 0168    }
 169
 170    void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
 171    {
 0172        backgroundHover.SetActive(false);
 0173        menuButton.gameObject.SetActive(false);
 0174    }
 175
 176    void OnFriendActionUpdate(string userId, FriendshipAction action)
 177    {
 0178        if (profile.userId != userId)
 179        {
 0180            return;
 181        }
 182
 0183        friendLabel.SetActive(action == FriendshipAction.APPROVED);
 0184    }
 185
 6186    void SetupFriendship(FriendshipStatus friendshipStatus) { friendLabel.SetActive(friendshipStatus == FriendshipStatus
 187}