< Summary

Class:PlayerInfoCardHUDView
Assembly:PlayerInfoCardHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PlayerInfoCardHUD/PlayerInfoCardHUDView.cs
Covered lines:87
Uncovered lines:17
Coverable lines:104
Total lines:269
Line coverage:83.6% (87 of 104)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerInfoCardHUDView()0%110100%
CreateView()0%110100%
Initialize(...)0%6.026091.18%
SetCardActive(...)0%3.073080%
UpdateTabs()0%220100%
SetFaceSnapshot(...)0%2100%
SetName(...)0%110100%
SetDescription(...)0%110100%
HideFriendshipInteraction()0%2100%
UpdateFriendshipInteraction(...)0%770100%
SetIsBlocked(...)0%110100%
SetVisibility(...)0%4.683042.86%
ClearCollectibles()0%220100%
SetWearables(...)0%440100%
OnPointerDown()0%2100%
OnDestroy()0%2.152066.67%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PlayerInfoCardHUD/PlayerInfoCardHUDView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL;
 5using DCL.Helpers;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.Assertions;
 9using UnityEngine.Events;
 10using UnityEngine.UI;
 11
 12public class PlayerInfoCardHUDView : MonoBehaviour
 13{
 14    private const string PREFAB_PATH = "PlayerInfoCardHUD";
 15
 16    public enum Tabs
 17    {
 18        Passport,
 19        Trade,
 20        Block
 21    }
 22
 23    [Serializable]
 24    internal class TabsMapping
 25    {
 26        public GameObject container;
 27        public Toggle toggle;
 28        public Tabs tab;
 29    }
 30
 31    [SerializeField] internal GenericFactory collectiblesFactory;
 32    [SerializeField] internal Canvas cardCanvas;
 33    [SerializeField] internal TabsMapping[] tabsMapping;
 34    [SerializeField] internal Button hideCardButton;
 35
 36    [Space] [SerializeField] internal RawImage avatarPicture;
 37    [SerializeField] internal Image blockedAvatarOverlay;
 38    [SerializeField] internal TextMeshProUGUI name;
 39
 40    [Header("Friends")] [SerializeField] internal GameObject friendStatusContainer;
 41    [SerializeField] internal Button requestSentButton;
 42    [SerializeField] internal Button addFriendButton;
 43    [SerializeField] internal GameObject alreadyFriendsContainer;
 44    [SerializeField] internal GameObject requestReceivedContainer;
 45    [SerializeField] internal Button acceptRequestButton;
 46    [SerializeField] internal Button rejectRequestButton;
 47
 48    [Header("Passport")] [SerializeField] internal TextMeshProUGUI description;
 49
 50    [Header("Trade")] [SerializeField] private RectTransform wearablesContainer;
 51    [SerializeField] private GameObject emptyCollectiblesImage;
 52
 53    [Header("Block")] [SerializeField] internal Button reportPlayerButton;
 54    [SerializeField] internal Button blockPlayerButton;
 55    [SerializeField] internal Button unblockPlayerButton;
 56
 2757    internal readonly List<PlayerInfoCollectibleItem> playerInfoCollectibles = new List<PlayerInfoCollectibleItem>(10);
 458    private UnityAction<bool> toggleChangedDelegate => (x) => UpdateTabs();
 59
 60    private MouseCatcher mouseCatcher;
 61
 62    public static PlayerInfoCardHUDView CreateView()
 63    {
 2664        return Instantiate(Resources.Load<GameObject>(PREFAB_PATH)).GetComponent<PlayerInfoCardHUDView>();
 65    }
 66
 67    public void Initialize(UnityAction cardClosedCallback,
 68        UnityAction reportPlayerCallback,
 69        UnityAction blockPlayerCallback,
 70        UnityAction unblockPlayerCallback,
 71        UnityAction addFriendCallback,
 72        UnityAction cancelInvitation,
 73        UnityAction acceptFriendRequest,
 74        UnityAction rejectFriendRequest)
 75    {
 2776        hideCardButton.onClick.RemoveAllListeners();
 2777        hideCardButton.onClick.AddListener(cardClosedCallback);
 78
 2779        reportPlayerButton.onClick.RemoveAllListeners();
 2780        reportPlayerButton.onClick.AddListener(reportPlayerCallback);
 81
 2782        blockPlayerButton.onClick.RemoveAllListeners();
 2783        blockPlayerButton.onClick.AddListener(blockPlayerCallback);
 84
 2785        unblockPlayerButton.onClick.RemoveAllListeners();
 2786        unblockPlayerButton.onClick.AddListener(unblockPlayerCallback);
 87
 2788        addFriendButton.onClick.RemoveAllListeners();
 2789        addFriendButton.onClick.AddListener(addFriendCallback);
 90
 2791        requestSentButton.onClick.RemoveAllListeners();
 2792        requestSentButton.onClick.AddListener(cancelInvitation);
 93
 2794        acceptRequestButton.onClick.RemoveAllListeners();
 2795        acceptRequestButton.onClick.AddListener(acceptFriendRequest);
 96
 2797        rejectRequestButton.onClick.RemoveAllListeners();
 2798        rejectRequestButton.onClick.AddListener(rejectFriendRequest);
 99
 216100        for (int index = 0; index < tabsMapping.Length; index++)
 101        {
 81102            var tab = tabsMapping[index];
 81103            tab.toggle.onValueChanged.RemoveListener(toggleChangedDelegate);
 81104            tab.toggle.onValueChanged.AddListener(toggleChangedDelegate);
 105        }
 106
 54107        for (int index = 0; index < tabsMapping.Length; index++)
 108        {
 27109            if (tabsMapping[index].tab == Tabs.Passport)
 110            {
 27111                tabsMapping[index].toggle.isOn = true;
 27112                break;
 113            }
 114        }
 115
 27116        if (SceneReferences.i != null)
 117        {
 27118            var mouseCatcher = DCL.SceneReferences.i.mouseCatcher;
 119
 27120            if (mouseCatcher != null)
 121            {
 0122                this.mouseCatcher = mouseCatcher;
 0123                mouseCatcher.OnMouseDown += OnPointerDown;
 124            }
 125        }
 27126    }
 127
 128    public void SetCardActive(bool active)
 129    {
 21130        if (active && mouseCatcher != null)
 131        {
 0132            mouseCatcher.UnlockCursor();
 133        }
 134
 21135        cardCanvas.enabled = active;
 21136        CommonScriptableObjects.playerInfoCardVisibleState.Set(active);
 21137    }
 138
 139    private void UpdateTabs()
 140    {
 32141        for (int index = 0; index < tabsMapping.Length; index++)
 142        {
 12143            tabsMapping[index].container.SetActive(tabsMapping[index].toggle.isOn);
 144        }
 4145    }
 146
 147    public void SetFaceSnapshot(Texture2D texture)
 148    {
 0149        avatarPicture.texture = texture;
 0150    }
 151
 32152    public void SetName(string name) => this.name.text = name;
 153
 32154    public void SetDescription(string description) => this.description.text = description;
 155
 156    public void HideFriendshipInteraction()
 157    {
 0158        requestReceivedContainer.SetActive(false);
 0159        addFriendButton.gameObject.SetActive(false);
 0160        alreadyFriendsContainer.SetActive(false);
 0161        requestSentButton.gameObject.SetActive(false);
 0162    }
 163
 164    public void UpdateFriendshipInteraction(bool canUseFriendButton,
 165        FriendsController.UserStatus status)
 166    {
 32167        if (status == null)
 168        {
 27169            requestReceivedContainer.SetActive(false);
 27170            addFriendButton.gameObject.SetActive(false);
 27171            alreadyFriendsContainer.SetActive(false);
 27172            requestSentButton.gameObject.SetActive(false);
 27173            return;
 174        }
 175
 5176        friendStatusContainer.SetActive(canUseFriendButton);
 177
 5178        if (!canUseFriendButton)
 179        {
 1180            addFriendButton.gameObject.SetActive(false);
 1181            alreadyFriendsContainer.SetActive(false);
 1182            requestSentButton.gameObject.SetActive(false);
 1183            return;
 184        }
 185
 4186        addFriendButton.gameObject.SetActive(false);
 4187        alreadyFriendsContainer.SetActive(false);
 4188        requestReceivedContainer.SetActive(false);
 4189        requestSentButton.gameObject.SetActive(false);
 190
 4191        switch (status.friendshipStatus)
 192        {
 193            case FriendshipStatus.NOT_FRIEND:
 1194                addFriendButton.gameObject.SetActive(true);
 1195                break;
 196            case FriendshipStatus.FRIEND:
 1197                alreadyFriendsContainer.SetActive(true);
 1198                break;
 199            case FriendshipStatus.REQUESTED_FROM:
 1200                requestReceivedContainer.SetActive(true);
 1201                break;
 202            case FriendshipStatus.REQUESTED_TO:
 1203                requestSentButton.gameObject.SetActive(true);
 204                break;
 205        }
 1206    }
 207
 208    public void SetIsBlocked(bool isBlocked)
 209    {
 32210        unblockPlayerButton.gameObject.SetActive(isBlocked);
 32211        blockedAvatarOverlay.gameObject.SetActive(isBlocked);
 32212    }
 213
 214    public void SetVisibility(bool visible)
 215    {
 1216        if (gameObject.activeSelf != visible)
 217        {
 0218            if (visible)
 219            {
 0220                AudioScriptableObjects.dialogOpen.Play(true);
 0221            }
 222            else
 223            {
 0224                AudioScriptableObjects.dialogClose.Play(true);
 225            }
 226        }
 227
 1228        gameObject.SetActive(visible);
 1229    }
 230
 231    public void ClearCollectibles()
 232    {
 194233        for (var i = playerInfoCollectibles.Count - 1; i >= 0; i--)
 234        {
 65235            var playerInfoCollectible = playerInfoCollectibles[i];
 65236            playerInfoCollectibles.RemoveAt(i);
 65237            Destroy(playerInfoCollectible.gameObject);
 238        }
 32239    }
 240
 241    public void SetWearables(IEnumerable<WearableItem> wearables)
 242    {
 31243        var emptyWearables = true;
 244
 362245        foreach (var wearable in wearables)
 246        {
 150247            emptyWearables = false;
 150248            var playerInfoCollectible =
 249                collectiblesFactory.Instantiate<PlayerInfoCollectibleItem>(wearable.rarity,
 250                    wearablesContainer.transform);
 150251            if (playerInfoCollectible == null) continue;
 150252            playerInfoCollectibles.Add(playerInfoCollectible);
 150253            playerInfoCollectible.Initialize(wearable);
 254        }
 255
 31256        emptyCollectiblesImage.SetActive(emptyWearables);
 31257    }
 258
 259    private void OnPointerDown()
 260    {
 0261        hideCardButton.onClick.Invoke();
 0262    }
 263
 264    private void OnDestroy()
 265    {
 26266        if (mouseCatcher != null)
 0267            mouseCatcher.OnMouseDown -= OnPointerDown;
 26268    }
 269}