< 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:107
Uncovered lines:64
Coverable lines:171
Total lines:375
Line coverage:62.5% (107 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%
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%2100%
CatalogItemSelected(...)0%220100%
ResumeInput()0%220100%
StopInput()0%220100%
OnPointerEnter(...)0%6200%
OnPointerExit(...)0%6200%
HideCatalogClicked()0%220100%
OnCatalogItemPackSelected(...)0%2100%
SetCatalogAssetPackInListView(...)0%12300%
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%
GetLastCatalogItemDragged()0%6200%
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.EventSystems;
 6
 7public enum BuildModeCatalogSection
 8{
 9    CATEGORIES,
 10    ASSET_PACKS,
 11    FAVOURITES
 12}
 13
 14public interface ISceneCatalogController
 15{
 16    event Action OnHideCatalogClicked;
 17    event Action<CatalogItem> OnCatalogItemSelected;
 18    event Action OnResumeInput;
 19    event Action OnStopInput;
 20    event Action<PointerEventData, CatalogItemAdapter> OnPointerEnterInCatalogItemAdapter;
 21    event Action<PointerEventData, CatalogItemAdapter> OnPointerExitInCatalogItemAdapter;
 22    void Initialize(ISceneCatalogView view, IQuickBarController quickBarController);
 23    void Dispose();
 24    void AssetsPackFilter(bool isOn);
 25    void CategoryFilter(bool isOn);
 26    void FavoritesFilter(bool isOn);
 27    void ToggleCatalogExpanse();
 28    void QuickBarInput(int quickBarSlot);
 29    void ShowFavorites();
 30    void CatalogItemSelected(CatalogItem catalogItem);
 31    void OnCatalogItemPackSelected(CatalogItemPack catalogItemPack);
 32    void SceneCatalogBack();
 33    bool IsCatalogOpen();
 34    bool IsCatalogExpanded();
 35    void ShowCategories();
 36    void ShowAssetsPacks();
 37    void ShowCatalogContent();
 38    void OpenCatalog();
 39    void CloseCatalog();
 40    void RefreshAssetPack();
 41    void RefreshCatalog();
 42    CatalogItemAdapter GetLastCatalogItemDragged();
 43    void SetActive(bool isActive);
 44    BuildModeCatalogSection GetCurrentSection();
 45}
 46
 47public class SceneCatalogController : ISceneCatalogController
 48{
 49    internal const string FAVORITE_NAME = "Favorites";
 50
 51    public event Action OnHideCatalogClicked;
 52    public event Action<CatalogItem> OnCatalogItemSelected;
 53    public event Action OnResumeInput;
 54    public event Action OnStopInput;
 55    public event Action<PointerEventData, CatalogItemAdapter> OnPointerEnterInCatalogItemAdapter;
 56    public event Action<PointerEventData, CatalogItemAdapter> OnPointerExitInCatalogItemAdapter;
 57
 58    internal ISceneCatalogView sceneCatalogView;
 59    internal IQuickBarController quickBarController;
 60    internal FavoritesController favoritesController;
 61    internal BIWSearchBarController biwSearchBarController;
 62    internal bool isShowingAssetPacks = false;
 3163    internal bool isFilterByAssetPacks = true;
 3164    internal BuildModeCatalogSection currentSection = BuildModeCatalogSection.ASSET_PACKS;
 65
 66    public void Initialize(ISceneCatalogView sceneCatalogView, IQuickBarController quickBarController)
 67    {
 3068        this.sceneCatalogView = sceneCatalogView;
 3069        this.quickBarController = quickBarController;
 3070        favoritesController = new FavoritesController(sceneCatalogView.catalogGroupList);
 3071        biwSearchBarController = new BIWSearchBarController();
 3072        biwSearchBarController.Initialize(sceneCatalogView);
 73
 3074        sceneCatalogView.OnHideCatalogClicked += HideCatalogClicked;
 75
 3076        if (sceneCatalogView.catalogAssetPackList != null)
 277            sceneCatalogView.catalogAssetPackList.OnCatalogPackClick += OnCatalogItemPackSelected;
 78
 3079        if (sceneCatalogView.catalogGroupList != null)
 80        {
 281            sceneCatalogView.catalogGroupList.OnCatalogItemClicked += CatalogItemSelected;
 282            sceneCatalogView.catalogGroupList.OnResumeInput += ResumeInput;
 283            sceneCatalogView.catalogGroupList.OnStopInput += StopInput;
 284            sceneCatalogView.catalogGroupList.OnPointerEnterInAdapter += OnPointerEnter;
 285            sceneCatalogView.catalogGroupList.OnPointerExitInAdapter += OnPointerExit;
 86        }
 87
 3088        if (sceneCatalogView.category != null)
 289            sceneCatalogView.category.onValueChanged.AddListener(CategoryFilter);
 90
 3091        if (sceneCatalogView.favorites != null)
 292            sceneCatalogView.favorites.onValueChanged.AddListener(FavoritesFilter);
 93
 3094        if (sceneCatalogView.assetPack != null)
 295            sceneCatalogView.assetPack.onValueChanged.AddListener(AssetsPackFilter);
 96
 3097        sceneCatalogView.OnSceneCatalogBack += SceneCatalogBack;
 3098        quickBarController.OnQuickBarShortcutSelected += QuickBarInput;
 3099        quickBarController.OnCatalogItemSelected += CatalogItemSelected;
 100
 30101        biwSearchBarController.OnFilterChange += AssetsFiltered;
 30102        biwSearchBarController.OnFilterRemove += FilterRemoved;
 30103    }
 104
 105    public void Dispose()
 106    {
 29107        sceneCatalogView.OnHideCatalogClicked -= HideCatalogClicked;
 108
 29109        if (sceneCatalogView.catalogAssetPackList != null)
 1110            sceneCatalogView.catalogAssetPackList.OnCatalogPackClick -= OnCatalogItemPackSelected;
 111
 29112        if (sceneCatalogView.catalogGroupList != null)
 113        {
 1114            sceneCatalogView.catalogGroupList.OnCatalogItemClicked -= CatalogItemSelected;
 1115            sceneCatalogView.catalogGroupList.OnResumeInput -= ResumeInput;
 1116            sceneCatalogView.catalogGroupList.OnStopInput -= StopInput;
 1117            sceneCatalogView.catalogGroupList.OnPointerEnterInAdapter -= OnPointerEnter;
 1118            sceneCatalogView.catalogGroupList.OnPointerExitInAdapter -= OnPointerExit;
 119        }
 120
 29121        if (sceneCatalogView.category != null)
 1122            sceneCatalogView.category.onValueChanged.RemoveListener(CategoryFilter);
 123
 29124        if (sceneCatalogView.favorites != null)
 1125            sceneCatalogView.favorites.onValueChanged.RemoveListener(FavoritesFilter);
 126
 29127        if (sceneCatalogView.assetPack != null)
 1128            sceneCatalogView.assetPack.onValueChanged.RemoveListener(AssetsPackFilter);
 129
 29130        sceneCatalogView.OnSceneCatalogBack -= SceneCatalogBack;
 131
 29132        quickBarController.OnQuickBarShortcutSelected -= QuickBarInput;
 29133        quickBarController.OnCatalogItemSelected -= CatalogItemSelected;
 134
 29135        biwSearchBarController.OnFilterChange -= AssetsFiltered;
 29136        biwSearchBarController.OnFilterRemove -= FilterRemoved;
 137
 29138        favoritesController.Dispose();
 29139        biwSearchBarController.Dispose();
 29140    }
 141
 0142    public BuildModeCatalogSection GetCurrentSection() { return currentSection; }
 143
 144    public void AssetsFiltered(List<Dictionary<string, List<CatalogItem>>> filterObjects)
 145    {
 2146        ShowCatalogContent();
 2147        if (sceneCatalogView.catalogGroupList != null)
 0148            sceneCatalogView.catalogGroupList.SetContent(filterObjects);
 2149    }
 150
 0151    public void FilterRemoved() { ShowLastSelectedSection(); }
 152
 153    public void AssetsPackFilter(bool isOn)
 154    {
 0155        if (!isOn)
 0156            return;
 157
 0158        isFilterByAssetPacks = true;
 0159        ShowAssetsPacks();
 0160    }
 161
 162    public void CategoryFilter(bool isOn)
 163    {
 0164        if (!isOn)
 0165            return;
 166
 0167        isFilterByAssetPacks = false;
 0168        ShowCategories();
 0169    }
 170
 171    public void FavoritesFilter(bool isOn)
 172    {
 0173        if (!isOn)
 0174            return;
 175
 0176        ShowFavorites();
 0177    }
 178
 2179    public void ToggleCatalogExpanse() { sceneCatalogView.ToggleCatalogExpanse(); }
 180
 6181    public void QuickBarInput(int quickBarSlot) { quickBarController.QuickBarObjectSelected(quickBarSlot); }
 182
 183    public void ShowFavorites()
 184    {
 0185        currentSection = BuildModeCatalogSection.FAVOURITES;
 0186        biwSearchBarController.ReleaseFilters();
 187
 0188        sceneCatalogView.SetCatalogTitle(FAVORITE_NAME);
 0189        ShowCatalogContent();
 190
 0191        List<Dictionary<string, List<CatalogItem>>> favorites = new List<Dictionary<string, List<CatalogItem>>>();
 0192        Dictionary<string, List<CatalogItem>> groupedCategoryItems = new Dictionary<string, List<CatalogItem>>();
 0193        groupedCategoryItems.Add(FAVORITE_NAME, favoritesController.GetFavorites());
 0194        favorites.Add(groupedCategoryItems);
 195
 0196        sceneCatalogView.catalogGroupList.SetContent(favorites);
 0197        sceneCatalogView.ShowBackButton(false);
 0198    }
 199
 11200    public void CatalogItemSelected(CatalogItem catalogItem) { OnCatalogItemSelected?.Invoke(catalogItem); }
 201
 2202    public void ResumeInput() { OnResumeInput?.Invoke(); }
 203
 20204    public void StopInput() { OnStopInput?.Invoke(); }
 205
 0206    private void OnPointerEnter(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerEnterInCatalogItemAda
 207
 0208    private void OnPointerExit(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerExitInCatalogItemAdapt
 209
 2210    public void HideCatalogClicked() { OnHideCatalogClicked?.Invoke(); }
 211
 212    public void OnCatalogItemPackSelected(CatalogItemPack catalogItemPack)
 213    {
 0214        ShowCatalogContent();
 0215        SetCatalogAssetPackInListView(catalogItemPack);
 0216        sceneCatalogView.ShowBackButton(true);
 0217    }
 218
 219    internal void SetCatalogAssetPackInListView(CatalogItemPack catalogItemPack)
 220    {
 0221        sceneCatalogView.SetCatalogTitle(catalogItemPack.title);
 0222        Dictionary<string, List<CatalogItem>> groupedCatalogItem = new Dictionary<string, List<CatalogItem>>();
 223
 0224        foreach (CatalogItem sceneObject in catalogItemPack.assets)
 225        {
 0226            string titleToUse = sceneObject.categoryName;
 227
 0228            if (!groupedCatalogItem.ContainsKey(titleToUse))
 229            {
 0230                groupedCatalogItem.Add(titleToUse, GetAssetsListByCategory(titleToUse, catalogItemPack));
 231            }
 232        }
 233
 0234        List<Dictionary<string, List<CatalogItem>>> contentList = new List<Dictionary<string, List<CatalogItem>>>
 235        {
 236            groupedCatalogItem
 237        };
 238
 0239        sceneCatalogView.catalogGroupList.SetContent(contentList);
 0240    }
 241
 242    internal List<CatalogItem> GetAssetsListByCategory(string category, CatalogItemPack sceneAssetPack)
 243    {
 1244        List<CatalogItem> catalogItemList = new List<CatalogItem>();
 245
 8246        foreach (CatalogItem catalogItem in sceneAssetPack.assets)
 247        {
 3248            if (category == catalogItem.categoryName)
 2249                catalogItemList.Add(catalogItem);
 250        }
 251
 1252        return catalogItemList;
 253    }
 254
 255    public void SceneCatalogBack()
 256    {
 2257        if (isShowingAssetPacks)
 258        {
 1259            sceneCatalogView.CloseCatalog();
 1260        }
 261        else
 262        {
 1263            if (isFilterByAssetPacks)
 1264                ShowAssetsPacks();
 265            else
 0266                ShowCategories();
 267
 1268            sceneCatalogView.ShowBackButton(false);
 1269            biwSearchBarController.ReleaseFilters();
 270        }
 1271    }
 272
 1273    public bool IsCatalogOpen() { return sceneCatalogView.IsCatalogOpen(); }
 274
 1275    public bool IsCatalogExpanded() { return sceneCatalogView.IsCatalogExpanded(); }
 276
 277    public void ShowCategories()
 278    {
 1279        currentSection = BuildModeCatalogSection.CATEGORIES;
 1280        biwSearchBarController.ReleaseFilters();
 281
 1282        if (sceneCatalogView.catalogAssetPackList != null)
 283        {
 0284            sceneCatalogView.catalogAssetPackList.SetCategoryStyle();
 0285            sceneCatalogView.catalogAssetPackList.SetContent(BIWCatalogManager.GetCatalogItemPacksFilteredByCategories()
 0286            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(true);
 287        }
 288
 1289        isShowingAssetPacks = true;
 1290        sceneCatalogView.SetCatalogTitle(BuilderInWorldSettings.CATALOG_ASSET_PACK_TITLE);
 291
 1292        if (sceneCatalogView.catalogGroupList != null)
 0293            sceneCatalogView.catalogGroupList.gameObject.SetActive(false);
 294
 1295        sceneCatalogView.ShowBackButton(false);
 1296    }
 297
 298    public void ShowAssetsPacks()
 299    {
 3300        currentSection = BuildModeCatalogSection.ASSET_PACKS;
 3301        biwSearchBarController.ReleaseFilters();
 302
 3303        if (sceneCatalogView.catalogAssetPackList != null)
 304        {
 0305            sceneCatalogView.catalogAssetPackList.SetAssetPackStyle();
 0306            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(true);
 307        }
 308
 3309        isShowingAssetPacks = true;
 3310        sceneCatalogView.SetCatalogTitle(BuilderInWorldSettings.CATALOG_ASSET_PACK_TITLE);
 3311        RefreshCatalog();
 312
 3313        if (sceneCatalogView.catalogGroupList != null)
 0314            sceneCatalogView.catalogGroupList.gameObject.SetActive(false);
 315
 3316        sceneCatalogView.ShowBackButton(false);
 3317    }
 318
 319    public void ShowCatalogContent()
 320    {
 2321        isShowingAssetPacks = false;
 2322        if (sceneCatalogView.catalogAssetPackList != null)
 0323            sceneCatalogView.catalogAssetPackList.gameObject.SetActive(false);
 324
 2325        if (sceneCatalogView.catalogGroupList != null)
 0326            sceneCatalogView.catalogGroupList.gameObject.SetActive(true);
 2327    }
 328
 329    public void OpenCatalog()
 330    {
 1331        ShowLastSelectedSection();
 1332        Utils.UnlockCursor();
 1333        sceneCatalogView.SetActive(true);
 1334    }
 335
 2336    public void CloseCatalog() { sceneCatalogView.CloseCatalog(); }
 337
 338    public void RefreshAssetPack()
 339    {
 0340        if (sceneCatalogView.catalogGroupList != null)
 0341            sceneCatalogView.catalogGroupList.RefreshDisplay();
 0342    }
 343
 344    public void RefreshCatalog()
 345    {
 3346        if (sceneCatalogView.catalogAssetPackList != null)
 0347            sceneCatalogView.catalogAssetPackList.SetContent(BIWCatalogManager.GetCatalogItemPackList());
 3348    }
 349
 350    public CatalogItemAdapter GetLastCatalogItemDragged()
 351    {
 0352        if (sceneCatalogView.catalogGroupList == null)
 0353            return null;
 354
 0355        return sceneCatalogView.catalogGroupList.GetLastCatalogItemDragged();
 356    }
 357
 358    private void ShowLastSelectedSection()
 359    {
 1360        switch (currentSection)
 361        {
 362            case BuildModeCatalogSection.CATEGORIES:
 0363                ShowCategories();
 0364                break;
 365            case BuildModeCatalogSection.ASSET_PACKS:
 1366                ShowAssetsPacks();
 1367                break;
 368            case BuildModeCatalogSection.FAVOURITES:
 0369                ShowFavorites();
 370                break;
 371        }
 0372    }
 373
 4374    public void SetActive(bool isActive) { sceneCatalogView.SetActive(isActive); }
 375}