< Summary

Class:DCL.Builder.LeftMenuButtonToggleView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/LeftMenuButtonToggleView.cs
Covered lines:17
Uncovered lines:26
Coverable lines:43
Total lines:120
Line coverage:39.5% (17 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Setup()0%2.032080%
SetIsOnWithoutNotify(...)0%220100%
OnDestroy()0%110100%
OnPointerEnter(...)0%6200%
OnPointerExit(...)0%6200%
OnPointerClick(...)0%6200%
SetSelectColor()0%110100%
SetDefaultColor()0%110100%
OnReceiveToggleOn(...)0%12300%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/LeftMenuButtonToggleView.cs

#LineLine coverage
 1using System;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.EventSystems;
 5using UnityEngine.UI;
 6
 7namespace DCL.Builder
 8{
 9    internal class LeftMenuButtonToggleView : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHan
 10    {
 11        public static event Action<LeftMenuButtonToggleView> OnToggleOn;
 12
 13        [Header("Action")]
 14        [SerializeField] public SectionId openSection;
 15
 16        [Header("Settings")]
 17        [SerializeField] private Color colorBackgroundDefault;
 18        [SerializeField] private Color colorBackgroundSelected;
 19        [SerializeField] private Color colorTextDefault;
 20        [SerializeField] private Color colorTextSelected;
 21
 22        [Header("References")]
 23        [SerializeField] private Image imageBackground;
 24        [SerializeField] private TextMeshProUGUI text;
 25
 26        public bool isOn
 27        {
 28            set
 29            {
 030                if (isToggleOn == value)
 031                    return;
 32
 033                SetIsOnWithoutNotify(value);
 34
 035                if (value)
 36                {
 037                    OnToggleOn?.Invoke(this);
 38                }
 039            }
 040            get { return isToggleOn; }
 41        }
 42
 43        private bool isToggleOn = false;
 44        private bool isSetup = false;
 45
 46        public void Setup()
 47        {
 15348            if (isSetup)
 049                return;
 50
 15351            isSetup = true;
 15352            OnToggleOn += OnReceiveToggleOn;
 15353        }
 54
 55        public void SetIsOnWithoutNotify(bool value)
 56        {
 1857            isToggleOn = value;
 58
 1859            if (isToggleOn)
 60            {
 361                SetSelectColor();
 362            }
 63            else
 64            {
 1565                SetDefaultColor();
 66            }
 1567        }
 68
 1669        private void OnDestroy() { OnToggleOn -= OnReceiveToggleOn; }
 70
 71        void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
 72        {
 073            if (isOn)
 074                return;
 75
 076            SetSelectColor();
 077        }
 78
 79        void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
 80        {
 081            if (isOn)
 082                return;
 83
 084            SetDefaultColor();
 085        }
 86
 87        void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
 88        {
 089            AudioScriptableObjects.buttonClick.Play(true);
 90
 091            if (isOn)
 092                return;
 93
 094            isOn = true;
 095        }
 96
 97        private void SetSelectColor()
 98        {
 399            imageBackground.color = colorBackgroundSelected;
 3100            text.color = colorTextSelected;
 3101        }
 102
 103        private void SetDefaultColor()
 104        {
 15105            imageBackground.color = colorBackgroundDefault;
 15106            text.color = colorTextDefault;
 15107        }
 108
 109        private void OnReceiveToggleOn(LeftMenuButtonToggleView toggle)
 110        {
 0111            if (!isOn)
 0112                return;
 113
 0114            if (toggle != this)
 115            {
 0116                isOn = false;
 117            }
 0118        }
 119    }
 120}