< Summary

Class:DCL.EmotesWheel.EmotesWheelView
Assembly:EmotesWheelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmotesWheelHUD/EmotesWheelView.cs
Covered lines:32
Uncovered lines:13
Coverable lines:45
Total lines:137
Line coverage:71.1% (32 of 45)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Create()0%110100%
Awake()0%220100%
SetVisiblity(...)0%3.033085.71%
SetEmotes(...)0%7.736063.64%
OnSlotHover(...)0%2100%
Close()0%6200%
OnDestroy()0%220100%
CleanUp()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmotesWheelHUD/EmotesWheelView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using TMPro;
 5using UnityEngine;
 6
 7namespace DCL.EmotesWheel
 8{
 9    public class EmotesWheelView : MonoBehaviour
 10    {
 11        public class EmoteSlotData
 12        {
 13            public WearableItem emoteItem;
 14            public Sprite thumbnailSprite;
 15        }
 16
 17        [Serializable]
 18        internal class RarityColor
 19        {
 20            public string rarity;
 21            public Color markColor;
 22        }
 23
 24        private const string PATH = "EmotesWheelHUD";
 25
 26
 27        public event Action<string> onEmoteClicked;
 28        public event Action OnClose;
 29        public event Action OnCustomizeClicked;
 30
 31        [SerializeField] internal Sprite nonAssignedEmoteSprite;
 32        [SerializeField] internal EmoteWheelSlot[] emoteButtons;
 33        [SerializeField] internal Button_OnPointerDown[] closeButtons;
 34        [SerializeField] internal ButtonComponentView openCustomizeButton;
 35        [SerializeField] internal TMP_Text selectedEmoteName;
 36        [SerializeField] internal List<RarityColor> rarityColors;
 37        [SerializeField] internal GameObject customizeTitle;
 38
 39        private HUDCanvasCameraModeController hudCanvasCameraModeController;
 40
 341        public static EmotesWheelView Create() { return Instantiate(Resources.Load<GameObject>(PATH)).GetComponent<Emote
 42
 43        private void Awake()
 44        {
 1845            for (int i = 0; i < closeButtons.Length; i++)
 46            {
 647                closeButtons[i].onPointerDown += Close;
 48            }
 49
 350            openCustomizeButton.onClick.AddListener(() =>
 51            {
 052                OnCustomizeClicked?.Invoke();
 053            });
 54
 355            selectedEmoteName.text = string.Empty;
 356            hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera
 357        }
 58
 59        public void SetVisiblity(bool visible)
 60        {
 561            if (visible == gameObject.activeSelf)
 062                return;
 63
 564            gameObject.SetActive(visible);
 565            if (visible)
 66            {
 167                AudioScriptableObjects.dialogOpen.Play(true);
 68            }
 69            else
 70            {
 471                AudioScriptableObjects.dialogClose.Play(true);
 72            }
 473        }
 74
 75        public List<EmoteWheelSlot> SetEmotes(List<EmoteSlotData> emotes)
 76        {
 6677            for (int i = 0; i < emotes.Count; i++)
 78            {
 3079                EmoteSlotData equippedEmote = emotes[i];
 80
 3081                if (i < emoteButtons.Length)
 82                {
 3083                    emoteButtons[i].button.onClick.RemoveAllListeners();
 3084                    emoteButtons[i].onSlotHover -= OnSlotHover;
 3085                    emoteButtons[i].onSlotHover += OnSlotHover;
 86
 3087                    if (equippedEmote != null)
 88                    {
 089                        emoteButtons[i].button.onClick.AddListener(() => onEmoteClicked?.Invoke(equippedEmote.emoteItem.
 90
 091                        if (equippedEmote.thumbnailSprite != null)
 092                            emoteButtons[i].SetImage(equippedEmote.thumbnailSprite);
 93                        else
 094                            emoteButtons[i].SetImage(equippedEmote.emoteItem.ComposeThumbnailUrl());
 95
 096                        emoteButtons[i].SetId(equippedEmote.emoteItem.id);
 097                        emoteButtons[i].SetName(equippedEmote.emoteItem.GetName());
 98
 099                        RarityColor rarityColor = rarityColors.FirstOrDefault(x => x.rarity == equippedEmote.emoteItem.r
 0100                        emoteButtons[i].SetRarity(
 101                            rarityColor != null,
 102                            rarityColor != null ? rarityColor.markColor : Color.white);
 103                    }
 104                    else
 105                    {
 30106                        emoteButtons[i].SetImage(nonAssignedEmoteSprite);
 30107                        emoteButtons[i].SetId(string.Empty);
 30108                        emoteButtons[i].SetName(string.Empty);
 30109                        emoteButtons[i].SetRarity(false, Color.white);
 110                    }
 111                }
 112            }
 113
 3114            return emoteButtons.ToList();
 115        }
 116
 0117        private void OnSlotHover(string emoteName) { selectedEmoteName.text = emoteName; }
 118
 0119        private void Close() { OnClose?.Invoke(); }
 120
 121        public void OnDestroy()
 122        {
 3123            CleanUp();
 3124            hudCanvasCameraModeController?.Dispose();
 3125        }
 126
 127        public void CleanUp()
 128        {
 36129            for (int i = 0; i < closeButtons.Length; i++)
 130            {
 12131                closeButtons[i].onPointerDown -= Close;
 132            }
 133
 6134            openCustomizeButton.onClick.RemoveAllListeners();
 6135        }
 136    }
 137}