< Summary

Class:SceneCatalogController
Assembly:BuildModeHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/BuildModeHUD/Scripts/Common/SceneCatalogController.cs
Covered lines:125
Uncovered lines:46
Coverable lines:171
Total lines:376
Line coverage:73% (125 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%7.736063.64%
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%3.143075%
ShowCatalogContent()0%3.333066.67%
OpenCatalog()0%110100%
CloseCatalog()0%110100%
RefreshAssetPack()0%6200%
RefreshCatalog()0%2.152066.67%
ShowLastSelectedSection()0%6.984042.86%
SetActive(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/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 interface ISceneCatalogController
 9{
 10    event Action OnHideCatalogClicked;
 11    event Action<CatalogItem> OnCatalogItemSelected;
 12    event Action OnResumeInput;
 13    event Action OnStopInput;
 14    event Action<PointerEventData, CatalogItemAdapter> OnPointerEnterInCatalogItemAdapter;
 15    event Action<PointerEventData, CatalogItemAdapter> OnPointerExitInCatalogItemAdapter;
 16    event Action<CatalogItem, CatalogItemAdapter> OnCatalogItemStartDrag;
 17    void Initialize(ISceneCatalogView view, IQuickBarController quickBarController);
 18    void Dispose();
 19    void AssetsPackFilter(bool isOn);
 20    void CategoryFilter(bool isOn);
 21    void FavoritesFilter(bool isOn);
 22    void ToggleCatalogExpanse();
 23    void QuickBarInput(int quickBarSlot);
 24    void ShowFavorites();
 25    void CatalogItemSelected(CatalogItem catalogItem);
 26    void OnCatalogItemPackSelected(CatalogItemPack catalogItemPack);
 27    void SceneCatalogBack();
 28    bool IsCatalogOpen();
 29    bool IsCatalogExpanded();
 30    void ShowCategories();
 31    void ShowAssetsPacks();
 32    void ShowCatalogContent();
 33    void OpenCatalog();
 34    void CloseCatalog();
 35    void RefreshAssetPack();
 36    void RefreshCatalog();
 37    void SetActive(bool isActive);
 38    BuildModeCatalogSection GetCurrentSection();
 39}
 40
 41public class SceneCatalogController : ISceneCatalogController
 42{
 43    internal const string FAVORITE_NAME = "Favorites";
 44
 45    public event Action OnHideCatalogClicked;
 46    public event Action<CatalogItem> OnCatalogItemSelected;
 47    public event Action OnResumeInput;
 48    public event Action OnStopInput;
 49    public event Action<PointerEventData, CatalogItemAdapter> OnPointerEnterInCatalogItemAdapter;
 50    public event Action<PointerEventData, CatalogItemAdapter> OnPointerExitInCatalogItemAdapter;
 51    public event Action<CatalogItem, CatalogItemAdapter> OnCatalogItemStartDrag;
 52
 53    internal ISceneCatalogView sceneCatalogView;
 54    internal IQuickBarController quickBarController;
 55    internal FavoritesController favoritesController;
 56    internal BIWSearchBarController biwSearchBarController;
 57    internal bool isShowingAssetPacks = false;
 3258    internal bool isFilterByAssetPacks = true;
 3259    internal BuildModeCatalogSection currentSection = BuildModeCatalogSection.ASSET_PACKS;
 60
 61    public void Initialize(ISceneCatalogView sceneCatalogView, IQuickBarController quickBarController)
 62    {
 3163        this.sceneCatalogView = sceneCatalogView;
 3164        this.quickBarController = quickBarController;
 3165        favoritesController = new FavoritesController(sceneCatalogView.catalogGroupList);
 3166        biwSearchBarController = new BIWSearchBarController();
 3167        biwSearchBarController.Initialize(sceneCatalogView);
 68
 3169        sceneCatalogView.OnHideCatalogClicked += HideCatalogClicked;
 70
 3171        if (sceneCatalogView.catalogAssetPackList != null)
 172            sceneCatalogView.catalogAssetPackList.OnCatalogPackClick += OnCatalogItemPackSelected;
 73
 3174        if (sceneCatalogView.catalogGroupList != null)
 75        {
 176            sceneCatalogView.catalogGroupList.OnCatalogItemClicked += CatalogItemSelected;
 177            sceneCatalogView.catalogGroupList.OnCatalogItemStarDragging += AdapterStartDrag;
 178            sceneCatalogView.catalogGroupList.OnPointerEnterInAdapter += OnPointerEnter;
 179            sceneCatalogView.catalogGroupList.OnPointerExitInAdapter += OnPointerExit;
 80        }
 81
 3182        if (sceneCatalogView.category != null)
 183            sceneCatalogView.category.onValueChanged.AddListener(CategoryFilter);
 84
 3185        if (sceneCatalogView.favorites != null)
 186            sceneCatalogView.favorites.onValueChanged.AddListener(FavoritesFilter);
 87
 3188        if (sceneCatalogView.assetPack != null)
 189            sceneCatalogView.assetPack.onValueChanged.AddListener(AssetsPackFilter);
 90
 3191        sceneCatalogView.OnSceneCatalogBack += SceneCatalogBack;
 3192        quickBarController.OnQuickBarShortcutSelected += QuickBarInput;
 3193        quickBarController.OnCatalogItemSelected += CatalogItemSelected;
 94
 3195        biwSearchBarController.OnFilterChange += AssetsFiltered;
 3196        biwSearchBarController.OnFilterRemove += FilterRemoved;
 3197    }
 98
 999    private void AdapterStartDrag(CatalogItem item, CatalogItemAdapter adapter) { OnCatalogItemStartDrag?.Invoke(item, a
 100
 101    public void Dispose()
 102    {
 30103        sceneCatalogView.OnHideCatalogClicked -= HideCatalogClicked;
 104
 30105        if (sceneCatalogView.catalogAssetPackList != null)
 0106            sceneCatalogView.catalogAssetPackList.OnCatalogPackClick -= OnCatalogItemPackSelected;
 107
 30108        if (sceneCatalogView.catalogGroupList != null)
 109        {
 0110            sceneCatalogView.catalogGroupList.OnCatalogItemClicked -= CatalogItemSelected;
 0111            sceneCatalogView.catalogGroupList.OnCatalogItemStarDragging -= AdapterStartDrag;
 0112            sceneCatalogView.catalogGroupList.OnPointerEnterInAdapter -= OnPointerEnter;
 0113            sceneCatalogView.catalogGroupList.OnPointerExitInAdapter -= OnPointerExit;
 114        }
 115
 30116        if (sceneCatalogView.category != null)
 0117            sceneCatalogView.category.onValueChanged.RemoveListener(CategoryFilter);
 118
 30119        if (sceneCatalogView.favorites != null)
 0120            sceneCatalogView.favorites.onValueChanged.RemoveListener(FavoritesFilter);
 121
 30122        if (sceneCatalogView.assetPack != null)
 0123            sceneCatalogView.assetPack.onValueChanged.RemoveListener(AssetsPackFilter);
 124
 30125        sceneCatalogView.OnSceneCatalogBack -= SceneCatalogBack;
 126
 30127        quickBarController.OnQuickBarShortcutSelected -= QuickBarInput;
 30128        quickBarController.OnCatalogItemSelected -= CatalogItemSelected;
 129
 30130        biwSearchBarController.OnFilterChange -= AssetsFiltered;
 30131        biwSearchBarController.OnFilterRemove -= FilterRemoved;
 132
 30133        favoritesController.Dispose();
 30134        biwSearchBarController.Dispose();
 30135    }
 136
 0137    public BuildModeCatalogSection GetCurrentSection() { return currentSection; }
 138
 139    public void AssetsFiltered(List<Dictionary<string, List<CatalogItem>>> filterObjects)
 140    {
 2141        ShowCatalogContent();
 2142        if (sceneCatalogView.catalogGroupList != null)
 0143            sceneCatalogView.catalogGroupList.SetContent(filterObjects);
 2144    }
 145
 0146    public void FilterRemoved() { ShowLastSelectedSection(); }
 147
 148    public void AssetsPackFilter(bool isOn)
 149    {
 0150        if (!isOn)
 0151            return;
 152
 0153        isFilterByAssetPacks = true;
 0154        ShowAssetsPacks();
 0155    }
 156
 157    public void CategoryFilter(bool isOn)
 158    {
 0159        if (!isOn)
 0160            return;
 161
 0162        isFilterByAssetPacks = false;
 0163        ShowCategories();
 0164    }
 165
 166    public void FavoritesFilter(bool isOn)
 167    {
 0168        if (!isOn)
 0169            return;
 170
 0171        ShowFavorites();
 0172    }
 173
 2174    public void ToggleCatalogExpanse() { sceneCatalogView.ToggleCatalogExpanse(); }
 175
 6176    public void QuickBarInput(int quickBarSlot) { quickBarController.QuickBarObjectSelected(quickBarSlot); }
 177
 178    public void ShowFavorites()
 179    {
 1180        currentSection = BuildModeCatalogSection.FAVOURITES;
 1181        biwSearchBarController.ReleaseFilters();
 182
 1183        sceneCatalogView.SetCatalogTitle(FAVORITE_NAME);
 1184        ShowCatalogContent();
 185
 1186        var favorites  = GenerateFavorites();
 187
 1188        sceneCatalogView.catalogGroupList?.SetContent(favorites);
 1189        sceneCatalogView.ShowBackButton(false);
 1190    }
 191
 192    internal List<Dictionary<string, List<CatalogItem>>>  GenerateFavorites()
 193    {
 2194        List<Dictionary<string, List<CatalogItem>>> favorites = new List<Dictionary<string, List<CatalogItem>>>();
 2195        Dictionary<string, List<CatalogItem>> groupedCategoryItems = new Dictionary<string, List<CatalogItem>>();
 2196        groupedCategoryItems.Add(FAVORITE_NAME, favoritesController.GetFavorites());
 2197        favorites.Add(groupedCategoryItems);
 2198        return favorites;
 199    }
 200
 11201    public void CatalogItemSelected(CatalogItem catalogItem) { OnCatalogItemSelected?.Invoke(catalogItem); }
 202
 2203    public void ResumeInput() { OnResumeInput?.Invoke(); }
 204
 2205    public void StopInput() { OnStopInput?.Invoke(); }
 206
 0207    private void OnPointerEnter(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerEnterInCatalogItemAda
 208
 0209    private void OnPointerExit(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerExitInCatalogItemAdapt
 210
 2211    public void HideCatalogClicked() { OnHideCatalogClicked?.Invoke(); }
 212
 213    public void OnCatalogItemPackSelected(CatalogItemPack catalogItemPack)
 214    {
 1215        ShowCatalogContent();
 1216        SetCatalogAssetPackInListView(catalogItemPack);
 1217        sceneCatalogView.ShowBackButton(true);
 1218    }
 219
 220    internal void SetCatalogAssetPackInListView(CatalogItemPack catalogItemPack)
 221    {
 1222        sceneCatalogView.SetCatalogTitle(catalogItemPack.title);
 223
 1224        var contentList = GenerateContentListForCatalogItemPack(catalogItemPack);
 225
 1226        sceneCatalogView.catalogGroupList?.SetContent(contentList);
 0227    }
 228
 229    internal  List<Dictionary<string, List<CatalogItem>>> GenerateContentListForCatalogItemPack(CatalogItemPack catalogI
 230    {
 1231        Dictionary<string, List<CatalogItem>> groupedCatalogItem = new Dictionary<string, List<CatalogItem>>();
 232
 6233        foreach (CatalogItem sceneObject in catalogItemPack.assets)
 234        {
 2235            string titleToUse = sceneObject.categoryName;
 236
 2237            if (!groupedCatalogItem.ContainsKey(titleToUse))
 238            {
 1239                groupedCatalogItem.Add(titleToUse, GetAssetsListByCategory(titleToUse, catalogItemPack));
 240            }
 241        }
 242
 1243        List<Dictionary<string, List<CatalogItem>>> contentList = new List<Dictionary<string, List<CatalogItem>>>
 244        {
 245            groupedCatalogItem
 246        };
 247
 1248        return contentList;
 249    }
 250
 251    internal List<CatalogItem> GetAssetsListByCategory(string category, CatalogItemPack sceneAssetPack)
 252    {
 2253        List<CatalogItem> catalogItemList = new List<CatalogItem>();
 254
 14255        foreach (CatalogItem catalogItem in sceneAssetPack.assets)
 256        {
 5257            if (category == catalogItem.categoryName)
 4258                catalogItemList.Add(catalogItem);
 259        }
 260
 2261        return catalogItemList;
 262    }
 263
 264    public void SceneCatalogBack()
 265    {
 2266        if (isShowingAssetPacks)
 267        {
 1268            sceneCatalogView.CloseCatalog();
 1269        }
 270        else
 271        {
 1272            if (isFilterByAssetPacks)
 1273                ShowAssetsPacks();
 274            else
 0275                ShowCategories();
 276
 1277            sceneCatalogView.ShowBackButton(false);
 1278            biwSearchBarController.ReleaseFilters();
 279        }
 1280    }
 281
 1282    public bool IsCatalogOpen() { return sceneCatalogView.IsCatalogOpen(); }
 283
 1284    public bool IsCatalogExpanded() { return sceneCatalogView.IsCatalogExpanded(); }
 285
 286    public void ShowCategories()
 287    {
 1288        currentSection = BuildModeCatalogSection.CATEGORIES;
 1289        biwSearchBarController.ReleaseFilters();
 290
 1291        if (sceneCatalogView.catalogAssetPackList != null)
 292        {
 0293            sceneCatalogView.catalogAssetPackList.SetCategoryStyle();
 0294            sceneCatalogView.catalogAssetPackList.SetContent(BIWCatalogManager.GetCatalogItemPacksFilteredByCategories()
 0295            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(true);
 296        }
 297
 1298        isShowingAssetPacks = true;
 1299        sceneCatalogView.SetCatalogTitle(BIWSettings.CATALOG_ASSET_PACK_TITLE);
 300
 1301        if (sceneCatalogView.catalogGroupList != null)
 0302            sceneCatalogView.catalogGroupList.gameObject.SetActive(false);
 303
 1304        sceneCatalogView.ShowBackButton(false);
 1305    }
 306
 307    public void ShowAssetsPacks()
 308    {
 3309        currentSection = BuildModeCatalogSection.ASSET_PACKS;
 3310        biwSearchBarController.ReleaseFilters();
 311
 3312        if (sceneCatalogView.catalogAssetPackList != null)
 313        {
 0314            sceneCatalogView.catalogAssetPackList.SetAssetPackStyle();
 0315            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(true);
 316        }
 317
 3318        isShowingAssetPacks = true;
 3319        sceneCatalogView.SetCatalogTitle(BIWSettings.CATALOG_ASSET_PACK_TITLE);
 3320        RefreshCatalog();
 321
 3322        if (sceneCatalogView.catalogGroupList != null)
 0323            sceneCatalogView.catalogGroupList.gameObject.SetActive(false);
 324
 3325        sceneCatalogView.ShowBackButton(false);
 3326    }
 327
 328    public void ShowCatalogContent()
 329    {
 4330        isShowingAssetPacks = false;
 4331        if (sceneCatalogView.catalogAssetPackList != null)
 0332            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(false);
 333
 4334        if (sceneCatalogView.catalogGroupList != null)
 0335            sceneCatalogView.catalogGroupList.gameObject.SetActive(true);
 4336    }
 337
 338    public void OpenCatalog()
 339    {
 1340        ShowLastSelectedSection();
 1341        Utils.UnlockCursor();
 1342        sceneCatalogView.SetActive(true);
 1343    }
 344
 2345    public void CloseCatalog() { sceneCatalogView.CloseCatalog(); }
 346
 347    public void RefreshAssetPack()
 348    {
 0349        if (sceneCatalogView.catalogGroupList != null)
 0350            sceneCatalogView.catalogGroupList.RefreshDisplay();
 0351    }
 352
 353    public void RefreshCatalog()
 354    {
 3355        if (sceneCatalogView.catalogAssetPackList != null)
 0356            sceneCatalogView.catalogAssetPackList.SetContent(BIWCatalogManager.GetCatalogItemPackList());
 3357    }
 358
 359    private void ShowLastSelectedSection()
 360    {
 1361        switch (currentSection)
 362        {
 363            case BuildModeCatalogSection.CATEGORIES:
 0364                ShowCategories();
 0365                break;
 366            case BuildModeCatalogSection.ASSET_PACKS:
 1367                ShowAssetsPacks();
 1368                break;
 369            case BuildModeCatalogSection.FAVOURITES:
 0370                ShowFavorites();
 371                break;
 372        }
 0373    }
 374
 4375    public void SetActive(bool isActive) { sceneCatalogView.SetActive(isActive); }
 376}