< Summary

Class:SceneCatalogView
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/SceneCatalogView.cs
Covered lines:39
Uncovered lines:17
Coverable lines:56
Total lines:172
Line coverage:69.6% (39 of 56)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Create()0%110100%
Awake()0%110100%
OnDestroy()0%110100%
OnEnable()0%110100%
OnDisable()0%110100%
ToggleCatalogExpanse()0%6200%
OnHideCatalogClick()0%220100%
ShowBackButton(...)0%110100%
Back()0%220100%
SetCatalogTitle(...)0%110100%
IsCatalogOpen()0%110100%
IsCatalogExpanded()0%2100%
CloseCatalog()0%220100%
CloseCatalogAfterOneFrame()0%330100%
SetActive(...)0%330100%
OpenCatalogWhenIsAlreadyClosed()0%330100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/SceneCatalogView.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using TMPro;
 4using UnityEngine;
 5using UnityEngine.UI;
 6
 7public interface ISceneCatalogView
 8{
 9    CatalogAssetPackListView catalogAssetPackList { get; }
 10    CatalogGroupListView catalogGroupList { get; }
 11    Toggle category { get; }
 12    Toggle favorites { get; }
 13    Toggle assetPack { get; }
 14    IBIWSearchBarView searchBarView { get; }
 15
 16    event Action OnHideCatalogClicked;
 17    event Action OnSceneCatalogBack;
 18
 19    void Back();
 20    void CloseCatalog();
 21    bool IsCatalogOpen();
 22    bool IsCatalogExpanded();
 23    void OnHideCatalogClick();
 24    void SetCatalogTitle(string text);
 25    void ToggleCatalogExpanse();
 26    void SetActive(bool isActive);
 27    void ShowBackButton(bool isActive);
 28}
 29
 30public class SceneCatalogView : MonoBehaviour, ISceneCatalogView
 31{
 232    public CatalogAssetPackListView catalogAssetPackList => catalogAssetPackListView;
 633    public CatalogGroupListView catalogGroupList => catalogGroupListView;
 234    public Toggle category => categoryToggle;
 235    public Toggle favorites => favoritesToggle;
 236    public Toggle assetPack => assetPackToggle;
 137    public IBIWSearchBarView searchBarView  => biwSearchBarView;
 38
 39    public event Action OnHideCatalogClicked;
 40    public event Action OnSceneCatalogBack;
 41
 42    [Header("Prefab References")]
 43    [SerializeField] internal TextMeshProUGUI catalogTitleTxt;
 44
 45    [SerializeField] internal CatalogAssetPackListView catalogAssetPackListView;
 46    [SerializeField] internal CatalogGroupListView catalogGroupListView;
 47    [SerializeField] internal TMP_InputField searchInputField;
 48    [SerializeField] internal Toggle categoryToggle;
 49    [SerializeField] internal Toggle favoritesToggle;
 50    [SerializeField] internal Toggle assetPackToggle;
 51    [SerializeField] internal Button hideCatalogBtn;
 52    [SerializeField] internal Button backgBtn;
 53    [SerializeField] internal Button toggleCatalogBtn;
 54    [SerializeField] internal BIWSearchBarView biwSearchBarView;
 55
 56    [Header("Catalog RectTransforms")]
 57    [SerializeField] internal RectTransform panelRT;
 58
 59    [SerializeField] internal RectTransform headerRT;
 60    [SerializeField] internal RectTransform searchBarRT;
 61    [SerializeField] internal RectTransform assetPackRT;
 62    [SerializeField] internal RectTransform categoryRT;
 63
 64    [Header("MinSize Catalog RectTransforms")]
 65    [SerializeField] internal RectTransform panelMinSizeRT;
 66
 67    [SerializeField] internal RectTransform headerMinSizeRT;
 68    [SerializeField] internal RectTransform searchBarMinSizeRT;
 69    [SerializeField] internal RectTransform assetPackMinSizeRT;
 70
 71    [Header("MaxSize Catalog RectTransforms")]
 72    [SerializeField] internal RectTransform panelMaxSizeRT;
 73
 74    [SerializeField] internal RectTransform headerMaxSizeRT;
 75    [SerializeField] internal RectTransform searchBarMaxSizeRT;
 76    [SerializeField] internal RectTransform assetPackMaxSizeRT;
 77
 78    internal bool isCatalogExpanded = false;
 79    internal bool isClosing = false;
 80
 81    private const string VIEW_PATH = "Common/SceneCatalogView";
 82
 83    internal static SceneCatalogView Create()
 84    {
 1585        var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<SceneCatalogView>();
 1586        view.gameObject.name = "_SceneCatalogView";
 87
 1588        return view;
 89    }
 90
 91    private void Awake()
 92    {
 1593        hideCatalogBtn.onClick.AddListener(OnHideCatalogClick);
 1594        backgBtn.onClick.AddListener(Back);
 1595        toggleCatalogBtn.onClick.AddListener(ToggleCatalogExpanse);
 1596    }
 97
 98    private void OnDestroy()
 99    {
 15100        hideCatalogBtn.onClick.RemoveListener(OnHideCatalogClick);
 15101        backgBtn.onClick.RemoveListener(Back);
 15102        toggleCatalogBtn.onClick.RemoveListener(ToggleCatalogExpanse);
 15103    }
 104
 34105    private void OnEnable() { AudioScriptableObjects.dialogOpen.Play(); }
 106
 34107    private void OnDisable() { AudioScriptableObjects.dialogClose.Play(); }
 108
 109    public void ToggleCatalogExpanse()
 110    {
 0111        if (isCatalogExpanded)
 112        {
 0113            BIWUtils.CopyRectTransform(panelRT, panelMinSizeRT);
 0114            BIWUtils.CopyRectTransform(headerRT, headerMinSizeRT);
 0115            BIWUtils.CopyRectTransform(searchBarRT, searchBarMinSizeRT);
 0116            BIWUtils.CopyRectTransform(assetPackRT, assetPackMinSizeRT);
 0117            BIWUtils.CopyRectTransform(categoryRT, assetPackMinSizeRT);
 0118            AudioScriptableObjects.dialogClose.Play();
 0119        }
 120        else
 121        {
 0122            BIWUtils.CopyRectTransform(panelRT, panelMaxSizeRT);
 0123            BIWUtils.CopyRectTransform(headerRT, headerMaxSizeRT);
 0124            BIWUtils.CopyRectTransform(searchBarRT, searchBarMaxSizeRT);
 0125            BIWUtils.CopyRectTransform(assetPackRT, assetPackMaxSizeRT);
 0126            BIWUtils.CopyRectTransform(categoryRT, assetPackMaxSizeRT);
 0127            AudioScriptableObjects.dialogOpen.Play();
 128        }
 129
 0130        isCatalogExpanded = !isCatalogExpanded;
 0131    }
 132
 2133    public void OnHideCatalogClick() { OnHideCatalogClicked?.Invoke(); }
 134
 4135    public void ShowBackButton(bool isActive) { backgBtn.gameObject.SetActive(isActive); }
 136
 2137    public void Back() { OnSceneCatalogBack?.Invoke(); }
 138
 2139    public void SetCatalogTitle(string text) { catalogTitleTxt.text = text; }
 140
 2141    public bool IsCatalogOpen() { return gameObject.activeSelf; }
 142
 0143    public bool IsCatalogExpanded() { return isCatalogExpanded; }
 144
 145    public void CloseCatalog()
 146    {
 1147        if (gameObject.activeSelf)
 1148            CoroutineStarter.Start(CloseCatalogAfterOneFrame());
 1149    }
 150
 151    internal IEnumerator CloseCatalogAfterOneFrame()
 152    {
 1153        isClosing = true;
 1154        yield return null;
 1155        gameObject.SetActive(false);
 1156        isClosing = false;
 1157    }
 158
 159    public void SetActive(bool isActive)
 160    {
 4161        if (isActive && isClosing)
 1162            CoroutineStarter.Start(OpenCatalogWhenIsAlreadyClosed());
 163        else
 3164            gameObject.SetActive(isActive);
 3165    }
 166
 167    internal IEnumerator OpenCatalogWhenIsAlreadyClosed()
 168    {
 3169        yield return new WaitUntil(() => !isClosing);
 1170        gameObject.SetActive(true);
 1171    }
 172}