< Summary

Class:SceneCardViewContextMenu
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/SceneCardViewContextMenu.cs
Covered lines:41
Uncovered lines:30
Coverable lines:71
Total lines:163
Line coverage:57.7% (41 of 71)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Update()0%2100%
Show(...)0%220100%
Show(...)0%110100%
Hide()0%110100%
Build(...)0%110100%
GetDeployedSceneConfig(...)0%3.213071.43%
GetProjectSceneConfig(...)0%330100%
HideIfClickedOutside()0%12300%

File(s)

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

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5internal class SceneCardViewContextMenu : MonoBehaviour
 6{
 7    [Header("Containers")]
 8    [SerializeField] internal GameObject headerContainer;
 9    [SerializeField] internal GameObject headerSeparator;
 10
 11    [Header("Buttons")]
 12    [SerializeField] internal Button settingsButton;
 13    [SerializeField] internal Button duplicateAsProjectButton;
 14    [SerializeField] internal Button duplicateButton;
 15    [SerializeField] internal Button downloadButton;
 16    [SerializeField] internal Button shareButton;
 17    [SerializeField] internal Button unpublishButton;
 18    [SerializeField] internal Button deleteButton;
 19    [SerializeField] internal Button quitContributorButton;
 20
 21    public event Action<string> OnSettingsPressed;
 22    public event Action<string> OnDuplicatePressed;
 23    public event Action<string> OnDownloadPressed;
 24    public event Action<string> OnSharePressed;
 25    public event Action<string> OnUnpublishPressed;
 26    public event Action<string> OnDeletePressed;
 27    public event Action<string> OnQuitContributorPressed;
 28
 29    [System.Flags]
 30    public enum ConfigFlags
 31    {
 32        Settings = 1,
 33        DuplicateAsProject = 2,
 34        Duplicate = 4,
 35        Download = 8,
 36        Share = 16,
 37        Unpublish = 32,
 38        Delete = 64,
 39        QuitContributor = 128
 40    }
 41
 42    private const ConfigFlags headerFlags = ConfigFlags.Settings;
 43
 44    private string sceneId;
 45    private RectTransform rectTransform;
 46
 47    private void Awake()
 48    {
 349        rectTransform = GetComponent<RectTransform>();
 50
 351        settingsButton.onClick.AddListener(() =>
 52        {
 053            OnSettingsPressed?.Invoke(sceneId);
 054            Hide();
 055        });
 356        duplicateAsProjectButton.onClick.AddListener(() =>
 57        {
 058            OnDuplicatePressed?.Invoke(sceneId);
 059            Hide();
 060        });
 361        duplicateButton.onClick.AddListener(() =>
 62        {
 063            OnDuplicatePressed?.Invoke(sceneId);
 064            Hide();
 065        });
 366        downloadButton.onClick.AddListener(() =>
 67        {
 068            OnDownloadPressed?.Invoke(sceneId);
 069            Hide();
 070        });
 371        shareButton.onClick.AddListener(() =>
 72        {
 073            OnSharePressed?.Invoke(sceneId);
 074            Hide();
 075        });
 376        unpublishButton.onClick.AddListener(() =>
 77        {
 078            OnUnpublishPressed?.Invoke(sceneId);
 079            Hide();
 080        });
 381        deleteButton.onClick.AddListener(() =>
 82        {
 083            OnDeletePressed?.Invoke(sceneId);
 084            Hide();
 085        });
 386        quitContributorButton.onClick.AddListener(() =>
 87        {
 088            OnQuitContributorPressed?.Invoke(sceneId);
 089            Hide();
 090        });
 391    }
 92
 093    private void Update() { HideIfClickedOutside(); }
 94
 95    public void Show(string sceneId, bool isSceneDeployed, bool isOwnerOrOperator, bool isContributor)
 96    {
 397        ConfigFlags config = isSceneDeployed ? GetDeployedSceneConfig(isOwnerOrOperator, isContributor) : GetProjectScen
 98
 399        Show(sceneId, config);
 3100    }
 101
 102    public void Show(string sceneId, ConfigFlags configFlags)
 103    {
 3104        this.sceneId = sceneId;
 3105        Build(configFlags);
 3106        gameObject.SetActive(true);
 3107    }
 108
 36109    public void Hide() { gameObject.SetActive(false); }
 110
 111    private void Build(ConfigFlags flags)
 112    {
 3113        headerContainer.SetActive((flags & headerFlags) != 0);
 3114        headerSeparator.SetActive((flags & headerFlags) != 0);
 3115        settingsButton.gameObject.SetActive((flags & ConfigFlags.Settings) != 0);
 3116        duplicateAsProjectButton.gameObject.SetActive((flags & ConfigFlags.DuplicateAsProject) != 0);
 3117        duplicateButton.gameObject.SetActive((flags & ConfigFlags.Duplicate) != 0);
 3118        downloadButton.gameObject.SetActive((flags & ConfigFlags.Download) != 0);
 3119        shareButton.gameObject.SetActive((flags & ConfigFlags.Share) != 0);
 3120        unpublishButton.gameObject.SetActive((flags & ConfigFlags.Unpublish) != 0);
 3121        deleteButton.gameObject.SetActive((flags & ConfigFlags.Delete) != 0);
 3122        quitContributorButton.gameObject.SetActive((flags & ConfigFlags.QuitContributor) != 0);
 3123    }
 124
 125    private ConfigFlags GetDeployedSceneConfig(bool isOwnerOrOperator, bool isContributor)
 126    {
 1127        ConfigFlags config = 0;
 1128        if (isOwnerOrOperator)
 129        {
 1130            config |= ConfigFlags.Unpublish;
 1131        }
 0132        else if (isContributor)
 133        {
 0134            config |= ConfigFlags.QuitContributor;
 135        }
 136
 1137        return config;
 138    }
 139
 140    private ConfigFlags GetProjectSceneConfig(bool isOwnerOrOperator, bool isContributor)
 141    {
 2142        ConfigFlags config = ConfigFlags.Duplicate | ConfigFlags.Download | ConfigFlags.Share;
 2143        if (isOwnerOrOperator)
 144        {
 1145            config |= ConfigFlags.Settings | ConfigFlags.Delete;
 1146        }
 1147        else if (isContributor)
 148        {
 1149            config |= ConfigFlags.QuitContributor;
 150        }
 151
 2152        return config;
 153    }
 154
 155    private void HideIfClickedOutside()
 156    {
 0157        if (Input.GetMouseButtonDown(0) &&
 158            !RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition))
 159        {
 0160            Hide();
 161        }
 0162    }
 163}