< Summary

Class:DCL.SettingsPanelHUD.Sections.SettingsButtonEntry
Assembly:SettingsPanelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/SectionsModule/SettingsButtonEntry.cs
Covered lines:12
Uncovered lines:8
Coverable lines:20
Total lines:82
Line coverage:60% (12 of 20)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%110100%
ConfigureAction(...)0%110100%
MarkAsSelected(...)0%770100%
OnPointerEnter(...)0%6200%
OnPointerExit(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUD/Scripts/SectionsModule/SettingsButtonEntry.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3using UnityEngine.Events;
 4using UnityEngine.EventSystems;
 5using UnityEngine.UI;
 6
 7namespace DCL.SettingsPanelHUD.Sections
 8{
 9    /// <summary>
 10    /// MonoBehaviour that represents a template for a menu button.
 11    /// It will be instantiated on the left part of the main settings panel and will be associated to a specific SECTION
 12    /// </summary>
 13    public class SettingsButtonEntry : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
 14    {
 15        [SerializeField]
 16        private Image icon;
 17
 18        [SerializeField]
 19        private TextMeshProUGUI text;
 20
 21        [SerializeField]
 22        private Button button;
 23
 24        [SerializeField]
 25        private Image backgroundImage;
 26
 27        [SerializeField]
 28        private Color textColorOnSelect;
 29
 30        [SerializeField]
 31        private Color backgroundColorOnSelect;
 32
 33        private Color originalIconColor;
 34        private Color originalTextColor;
 35        private Color originalBackgroundColor;
 36        private bool isSelected;
 37
 38        public void Initialize(Sprite icon, string text)
 39        {
 340            this.icon.sprite = icon;
 341            this.text.text = text;
 42
 343            originalIconColor = this.icon.color;
 344            originalTextColor = this.text.color;
 345            originalBackgroundColor = backgroundImage.color;
 346        }
 47
 48        /// <summary>
 49        /// Adds an action to execute when the button is clicked.
 50        /// </summary>
 51        /// <param name="action">Action to execute.</param>
 652        public void ConfigureAction(UnityAction action) { button.onClick.AddListener(action); }
 53
 54        /// <summary>
 55        /// Mark this button as selected. It will change the visual aspect of the button.
 56        /// </summary>
 57        /// <param name="isSelected">True for select the button.</param>
 58        public void MarkAsSelected(bool isSelected)
 59        {
 660            icon.color = isSelected ? textColorOnSelect : originalIconColor;
 661            text.color = isSelected ? textColorOnSelect : originalTextColor;
 662            backgroundImage.color = isSelected ? backgroundColorOnSelect : originalBackgroundColor;
 663            this.isSelected = isSelected;
 664        }
 65
 66        public void OnPointerEnter(PointerEventData eventData)
 67        {
 068            if (isSelected)
 069                return;
 70
 071            backgroundImage.color = backgroundColorOnSelect;
 072        }
 73
 74        public void OnPointerExit(PointerEventData eventData)
 75        {
 076            if (isSelected)
 077                return;
 78
 079            backgroundImage.color = originalBackgroundColor;
 080        }
 81    }
 82}