< Summary

Class:SceneCatalogController
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Scripts/Common/SceneCatalogController.cs
Covered lines:140
Uncovered lines:31
Coverable lines:171
Total lines:383
Line coverage:81.8% (140 of 171)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SceneCatalogController()0%110100%
Initialize(...)0%660100%
AdapterStartDrag(...)0%2.52050%
Dispose()0%660100%
GetCurrentSection()0%2100%
AssetsFiltered(...)0%2.062075%
FilterRemoved()0%2100%
AssetsPackFilter(...)0%6200%
CategoryFilter(...)0%6200%
FavoritesFilter(...)0%6200%
ToggleCatalogExpanse()0%110100%
QuickBarInput(...)0%110100%
ShowFavorites()0%220100%
GenerateFavorites()0%110100%
CatalogItemSelected(...)0%220100%
ResumeInput()0%220100%
StopInput()0%220100%
OnPointerEnter(...)0%6200%
OnPointerExit(...)0%6200%
HideCatalogClicked()0%220100%
OnCatalogItemPackSelected(...)0%110100%
SetCatalogAssetPackInListView(...)0%2.062075%
GenerateContentListForCatalogItemPack(...)0%330100%
GetAssetsListByCategory(...)0%330100%
SceneCatalogBack()0%3.013088.89%
IsCatalogOpen()0%110100%
IsCatalogExpanded()0%110100%
ShowCategories()0%3.333066.67%
ShowAssetsPacks()0%330100%
ShowCatalogContent()0%3.333066.67%
OpenCatalog()0%110100%
CloseCatalog()0%110100%
RefreshAssetPack()0%220100%
RefreshCatalog()0%220100%
ShowLastSelectedSection()0%6.984042.86%
SetActive(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuildModeHUD/Scripts/Common/SceneCatalogController.cs

#LineLine coverage
 1using DCL.Configuration;
 2using DCL.Helpers;
 3using System;
 4using System.Collections.Generic;
 5using UnityEngine;
 6using UnityEngine.EventSystems;
 7
 8public enum BuildModeCatalogSection
 9{
 10    CATEGORIES,
 11    ASSET_PACKS,
 12    FAVOURITES
 13}
 14
 15public interface ISceneCatalogController
 16{
 17    event Action OnHideCatalogClicked;
 18    event Action<CatalogItem> OnCatalogItemSelected;
 19    event Action OnResumeInput;
 20    event Action OnStopInput;
 21    event Action<PointerEventData, CatalogItemAdapter> OnPointerEnterInCatalogItemAdapter;
 22    event Action<PointerEventData, CatalogItemAdapter> OnPointerExitInCatalogItemAdapter;
 23    event Action<CatalogItem, CatalogItemAdapter> OnCatalogItemStartDrag;
 24    void Initialize(ISceneCatalogView view, IQuickBarController quickBarController);
 25    void Dispose();
 26    void AssetsPackFilter(bool isOn);
 27    void CategoryFilter(bool isOn);
 28    void FavoritesFilter(bool isOn);
 29    void ToggleCatalogExpanse();
 30    void QuickBarInput(int quickBarSlot);
 31    void ShowFavorites();
 32    void CatalogItemSelected(CatalogItem catalogItem);
 33    void OnCatalogItemPackSelected(CatalogItemPack catalogItemPack);
 34    void SceneCatalogBack();
 35    bool IsCatalogOpen();
 36    bool IsCatalogExpanded();
 37    void ShowCategories();
 38    void ShowAssetsPacks();
 39    void ShowCatalogContent();
 40    void OpenCatalog();
 41    void CloseCatalog();
 42    void RefreshAssetPack();
 43    void RefreshCatalog();
 44    void SetActive(bool isActive);
 45    BuildModeCatalogSection GetCurrentSection();
 46}
 47
 48public class SceneCatalogController : ISceneCatalogController
 49{
 50    internal const string FAVORITE_NAME = "Favorites";
 51
 52    public event Action OnHideCatalogClicked;
 53    public event Action<CatalogItem> OnCatalogItemSelected;
 54    public event Action OnResumeInput;
 55    public event Action OnStopInput;
 56    public event Action<PointerEventData, CatalogItemAdapter> OnPointerEnterInCatalogItemAdapter;
 57    public event Action<PointerEventData, CatalogItemAdapter> OnPointerExitInCatalogItemAdapter;
 58    public event Action<CatalogItem, CatalogItemAdapter> OnCatalogItemStartDrag;
 59
 60    internal ISceneCatalogView sceneCatalogView;
 61    internal IQuickBarController quickBarController;
 62    internal FavoritesController favoritesController;
 63    internal BIWSearchBarController biwSearchBarController;
 64    internal bool isShowingAssetPacks = false;
 5865    internal bool isFilterByAssetPacks = true;
 5866    internal BuildModeCatalogSection currentSection = BuildModeCatalogSection.ASSET_PACKS;
 67
 68    public void Initialize(ISceneCatalogView sceneCatalogView, IQuickBarController quickBarController)
 69    {
 5770        this.sceneCatalogView = sceneCatalogView;
 5771        this.quickBarController = quickBarController;
 5772        favoritesController = new FavoritesController(sceneCatalogView.catalogGroupList);
 5773        biwSearchBarController = new BIWSearchBarController();
 5774        biwSearchBarController.Initialize(sceneCatalogView);
 75
 5776        sceneCatalogView.OnHideCatalogClicked += HideCatalogClicked;
 77
 5778        if (sceneCatalogView.catalogAssetPackList != null)
 2779            sceneCatalogView.catalogAssetPackList.OnCatalogPackClick += OnCatalogItemPackSelected;
 80
 5781        if (sceneCatalogView.catalogGroupList != null)
 82        {
 2783            sceneCatalogView.catalogGroupList.OnCatalogItemClicked += CatalogItemSelected;
 2784            sceneCatalogView.catalogGroupList.OnCatalogItemStarDragging += AdapterStartDrag;
 2785            sceneCatalogView.catalogGroupList.OnPointerEnterInAdapter += OnPointerEnter;
 2786            sceneCatalogView.catalogGroupList.OnPointerExitInAdapter += OnPointerExit;
 87        }
 88
 5789        if (sceneCatalogView.category != null)
 2790            sceneCatalogView.category.onValueChanged.AddListener(CategoryFilter);
 91
 5792        if (sceneCatalogView.favorites != null)
 2793            sceneCatalogView.favorites.onValueChanged.AddListener(FavoritesFilter);
 94
 5795        if (sceneCatalogView.assetPack != null)
 2796            sceneCatalogView.assetPack.onValueChanged.AddListener(AssetsPackFilter);
 97
 5798        sceneCatalogView.OnSceneCatalogBack += SceneCatalogBack;
 5799        quickBarController.OnQuickBarShortcutSelected += QuickBarInput;
 57100        quickBarController.OnCatalogItemSelected += CatalogItemSelected;
 101
 57102        biwSearchBarController.OnFilterChange += AssetsFiltered;
 57103        biwSearchBarController.OnFilterRemove += FilterRemoved;
 57104    }
 105
 9106    private void AdapterStartDrag(CatalogItem item, CatalogItemAdapter adapter) { OnCatalogItemStartDrag?.Invoke(item, a
 107
 108    public void Dispose()
 109    {
 56110        sceneCatalogView.OnHideCatalogClicked -= HideCatalogClicked;
 111
 56112        if (sceneCatalogView.catalogAssetPackList != null)
 26113            sceneCatalogView.catalogAssetPackList.OnCatalogPackClick -= OnCatalogItemPackSelected;
 114
 56115        if (sceneCatalogView.catalogGroupList != null)
 116        {
 26117            sceneCatalogView.catalogGroupList.OnCatalogItemClicked -= CatalogItemSelected;
 26118            sceneCatalogView.catalogGroupList.OnCatalogItemStarDragging -= AdapterStartDrag;
 26119            sceneCatalogView.catalogGroupList.OnPointerEnterInAdapter -= OnPointerEnter;
 26120            sceneCatalogView.catalogGroupList.OnPointerExitInAdapter -= OnPointerExit;
 121        }
 122
 56123        if (sceneCatalogView.category != null)
 26124            sceneCatalogView.category.onValueChanged.RemoveListener(CategoryFilter);
 125
 56126        if (sceneCatalogView.favorites != null)
 26127            sceneCatalogView.favorites.onValueChanged.RemoveListener(FavoritesFilter);
 128
 56129        if (sceneCatalogView.assetPack != null)
 26130            sceneCatalogView.assetPack.onValueChanged.RemoveListener(AssetsPackFilter);
 131
 56132        sceneCatalogView.OnSceneCatalogBack -= SceneCatalogBack;
 133
 56134        quickBarController.OnQuickBarShortcutSelected -= QuickBarInput;
 56135        quickBarController.OnCatalogItemSelected -= CatalogItemSelected;
 136
 56137        biwSearchBarController.OnFilterChange -= AssetsFiltered;
 56138        biwSearchBarController.OnFilterRemove -= FilterRemoved;
 139
 56140        favoritesController.Dispose();
 56141        biwSearchBarController.Dispose();
 56142    }
 143
 0144    public BuildModeCatalogSection GetCurrentSection() { return currentSection; }
 145
 146    public void AssetsFiltered(List<Dictionary<string, List<CatalogItem>>> filterObjects)
 147    {
 2148        ShowCatalogContent();
 2149        if (sceneCatalogView.catalogGroupList != null)
 0150            sceneCatalogView.catalogGroupList.SetContent(filterObjects);
 2151    }
 152
 0153    public void FilterRemoved() { ShowLastSelectedSection(); }
 154
 155    public void AssetsPackFilter(bool isOn)
 156    {
 0157        if (!isOn)
 0158            return;
 159
 0160        isFilterByAssetPacks = true;
 0161        ShowAssetsPacks();
 0162    }
 163
 164    public void CategoryFilter(bool isOn)
 165    {
 0166        if (!isOn)
 0167            return;
 168
 0169        isFilterByAssetPacks = false;
 0170        ShowCategories();
 0171    }
 172
 173    public void FavoritesFilter(bool isOn)
 174    {
 0175        if (!isOn)
 0176            return;
 177
 0178        ShowFavorites();
 0179    }
 180
 2181    public void ToggleCatalogExpanse() { sceneCatalogView.ToggleCatalogExpanse(); }
 182
 6183    public void QuickBarInput(int quickBarSlot) { quickBarController.QuickBarObjectSelected(quickBarSlot); }
 184
 185    public void ShowFavorites()
 186    {
 1187        currentSection = BuildModeCatalogSection.FAVOURITES;
 1188        biwSearchBarController.ReleaseFilters();
 189
 1190        sceneCatalogView.SetCatalogTitle(FAVORITE_NAME);
 1191        ShowCatalogContent();
 192
 1193        var favorites  = GenerateFavorites();
 194
 1195        sceneCatalogView.catalogGroupList?.SetContent(favorites);
 1196        sceneCatalogView.ShowBackButton(false);
 1197    }
 198
 199    internal List<Dictionary<string, List<CatalogItem>>>  GenerateFavorites()
 200    {
 2201        List<Dictionary<string, List<CatalogItem>>> favorites = new List<Dictionary<string, List<CatalogItem>>>();
 2202        Dictionary<string, List<CatalogItem>> groupedCategoryItems = new Dictionary<string, List<CatalogItem>>();
 2203        groupedCategoryItems.Add(FAVORITE_NAME, favoritesController.GetFavorites());
 2204        favorites.Add(groupedCategoryItems);
 2205        return favorites;
 206    }
 207
 11208    public void CatalogItemSelected(CatalogItem catalogItem) { OnCatalogItemSelected?.Invoke(catalogItem); }
 209
 2210    public void ResumeInput() { OnResumeInput?.Invoke(); }
 211
 2212    public void StopInput() { OnStopInput?.Invoke(); }
 213
 0214    private void OnPointerEnter(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerEnterInCatalogItemAda
 215
 0216    private void OnPointerExit(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerExitInCatalogItemAdapt
 217
 2218    public void HideCatalogClicked() { OnHideCatalogClicked?.Invoke(); }
 219
 220    public void OnCatalogItemPackSelected(CatalogItemPack catalogItemPack)
 221    {
 1222        ShowCatalogContent();
 1223        SetCatalogAssetPackInListView(catalogItemPack);
 1224        sceneCatalogView.ShowBackButton(true);
 1225    }
 226
 227    internal void SetCatalogAssetPackInListView(CatalogItemPack catalogItemPack)
 228    {
 1229        sceneCatalogView.SetCatalogTitle(catalogItemPack.title);
 230
 1231        var contentList = GenerateContentListForCatalogItemPack(catalogItemPack);
 232
 1233        sceneCatalogView.catalogGroupList?.SetContent(contentList);
 0234    }
 235
 236    internal  List<Dictionary<string, List<CatalogItem>>> GenerateContentListForCatalogItemPack(CatalogItemPack catalogI
 237    {
 1238        Dictionary<string, List<CatalogItem>> groupedCatalogItem = new Dictionary<string, List<CatalogItem>>();
 239
 6240        foreach (CatalogItem sceneObject in catalogItemPack.assets)
 241        {
 2242            string titleToUse = sceneObject.categoryName;
 243
 2244            if (!groupedCatalogItem.ContainsKey(titleToUse))
 245            {
 1246                groupedCatalogItem.Add(titleToUse, GetAssetsListByCategory(titleToUse, catalogItemPack));
 247            }
 248        }
 249
 1250        List<Dictionary<string, List<CatalogItem>>> contentList = new List<Dictionary<string, List<CatalogItem>>>
 251        {
 252            groupedCatalogItem
 253        };
 254
 1255        return contentList;
 256    }
 257
 258    internal List<CatalogItem> GetAssetsListByCategory(string category, CatalogItemPack sceneAssetPack)
 259    {
 2260        List<CatalogItem> catalogItemList = new List<CatalogItem>();
 261
 14262        foreach (CatalogItem catalogItem in sceneAssetPack.assets)
 263        {
 5264            if (category == catalogItem.categoryName)
 4265                catalogItemList.Add(catalogItem);
 266        }
 267
 2268        return catalogItemList;
 269    }
 270
 271    public void SceneCatalogBack()
 272    {
 2273        if (isShowingAssetPacks)
 274        {
 1275            sceneCatalogView.CloseCatalog();
 1276        }
 277        else
 278        {
 1279            if (isFilterByAssetPacks)
 1280                ShowAssetsPacks();
 281            else
 0282                ShowCategories();
 283
 1284            sceneCatalogView.ShowBackButton(false);
 1285            biwSearchBarController.ReleaseFilters();
 286        }
 1287    }
 288
 1289    public bool IsCatalogOpen() { return sceneCatalogView.IsCatalogOpen(); }
 290
 1291    public bool IsCatalogExpanded() { return sceneCatalogView.IsCatalogExpanded(); }
 292
 293    public void ShowCategories()
 294    {
 1295        currentSection = BuildModeCatalogSection.CATEGORIES;
 1296        biwSearchBarController.ReleaseFilters();
 297
 1298        if (sceneCatalogView.catalogAssetPackList != null)
 299        {
 0300            sceneCatalogView.catalogAssetPackList.SetCategoryStyle();
 0301            sceneCatalogView.catalogAssetPackList.SetContent(BIWCatalogManager.GetCatalogItemPacksFilteredByCategories()
 0302            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(true);
 303        }
 304
 1305        isShowingAssetPacks = true;
 1306        sceneCatalogView.SetCatalogTitle(BIWSettings.CATALOG_ASSET_PACK_TITLE);
 307
 1308        if (sceneCatalogView.catalogGroupList != null)
 0309            sceneCatalogView.catalogGroupList.gameObject.SetActive(false);
 310
 1311        sceneCatalogView.ShowBackButton(false);
 1312    }
 313
 314    public void ShowAssetsPacks()
 315    {
 10316        currentSection = BuildModeCatalogSection.ASSET_PACKS;
 10317        biwSearchBarController.ReleaseFilters();
 318
 10319        if (sceneCatalogView.catalogAssetPackList != null)
 320        {
 7321            sceneCatalogView.catalogAssetPackList.SetAssetPackStyle();
 7322            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(true);
 323        }
 324
 10325        isShowingAssetPacks = true;
 10326        sceneCatalogView.SetCatalogTitle(BIWSettings.CATALOG_ASSET_PACK_TITLE);
 10327        RefreshCatalog();
 328
 10329        if (sceneCatalogView.catalogGroupList != null)
 7330            sceneCatalogView.catalogGroupList.gameObject.SetActive(false);
 331
 10332        sceneCatalogView.ShowBackButton(false);
 10333    }
 334
 335    public void ShowCatalogContent()
 336    {
 4337        isShowingAssetPacks = false;
 4338        if (sceneCatalogView.catalogAssetPackList != null)
 0339            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(false);
 340
 4341        if (sceneCatalogView.catalogGroupList != null)
 0342            sceneCatalogView.catalogGroupList.gameObject.SetActive(true);
 4343    }
 344
 345    public void OpenCatalog()
 346    {
 8347        ShowLastSelectedSection();
 8348        Utils.UnlockCursor();
 8349        sceneCatalogView.SetActive(true);
 8350    }
 351
 2352    public void CloseCatalog() { sceneCatalogView.CloseCatalog(); }
 353
 354    public void RefreshAssetPack()
 355    {
 7356        if (sceneCatalogView.catalogGroupList != null)
 7357            sceneCatalogView.catalogGroupList.RefreshDisplay();
 7358    }
 359
 360    public void RefreshCatalog()
 361    {
 25362        if (sceneCatalogView.catalogAssetPackList != null)
 22363            sceneCatalogView.catalogAssetPackList.SetContent(BIWCatalogManager.GetCatalogItemPackList());
 25364    }
 365
 366    private void ShowLastSelectedSection()
 367    {
 8368        switch (currentSection)
 369        {
 370            case BuildModeCatalogSection.CATEGORIES:
 0371                ShowCategories();
 0372                break;
 373            case BuildModeCatalogSection.ASSET_PACKS:
 8374                ShowAssetsPacks();
 8375                break;
 376            case BuildModeCatalogSection.FAVOURITES:
 0377                ShowFavorites();
 378                break;
 379        }
 0380    }
 381
 4382    public void SetActive(bool isActive) { sceneCatalogView.SetActive(isActive); }
 383}