| | 1 | | using DCL.Configuration; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.EventSystems; |
| | 7 | |
|
| | 8 | | public 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 | |
|
| | 41 | | public 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; |
| 32 | 58 | | internal bool isFilterByAssetPacks = true; |
| 32 | 59 | | internal BuildModeCatalogSection currentSection = BuildModeCatalogSection.ASSET_PACKS; |
| | 60 | |
|
| | 61 | | public void Initialize(ISceneCatalogView sceneCatalogView, IQuickBarController quickBarController) |
| | 62 | | { |
| 31 | 63 | | this.sceneCatalogView = sceneCatalogView; |
| 31 | 64 | | this.quickBarController = quickBarController; |
| 31 | 65 | | favoritesController = new FavoritesController(sceneCatalogView.catalogGroupList); |
| 31 | 66 | | biwSearchBarController = new BIWSearchBarController(); |
| 31 | 67 | | biwSearchBarController.Initialize(sceneCatalogView); |
| | 68 | |
|
| 31 | 69 | | sceneCatalogView.OnHideCatalogClicked += HideCatalogClicked; |
| | 70 | |
|
| 31 | 71 | | if (sceneCatalogView.catalogAssetPackList != null) |
| 1 | 72 | | sceneCatalogView.catalogAssetPackList.OnCatalogPackClick += OnCatalogItemPackSelected; |
| | 73 | |
|
| 31 | 74 | | if (sceneCatalogView.catalogGroupList != null) |
| | 75 | | { |
| 1 | 76 | | sceneCatalogView.catalogGroupList.OnCatalogItemClicked += CatalogItemSelected; |
| 1 | 77 | | sceneCatalogView.catalogGroupList.OnCatalogItemStarDragging += AdapterStartDrag; |
| 1 | 78 | | sceneCatalogView.catalogGroupList.OnPointerEnterInAdapter += OnPointerEnter; |
| 1 | 79 | | sceneCatalogView.catalogGroupList.OnPointerExitInAdapter += OnPointerExit; |
| | 80 | | } |
| | 81 | |
|
| 31 | 82 | | if (sceneCatalogView.category != null) |
| 1 | 83 | | sceneCatalogView.category.onValueChanged.AddListener(CategoryFilter); |
| | 84 | |
|
| 31 | 85 | | if (sceneCatalogView.favorites != null) |
| 1 | 86 | | sceneCatalogView.favorites.onValueChanged.AddListener(FavoritesFilter); |
| | 87 | |
|
| 31 | 88 | | if (sceneCatalogView.assetPack != null) |
| 1 | 89 | | sceneCatalogView.assetPack.onValueChanged.AddListener(AssetsPackFilter); |
| | 90 | |
|
| 31 | 91 | | sceneCatalogView.OnSceneCatalogBack += SceneCatalogBack; |
| 31 | 92 | | quickBarController.OnQuickBarShortcutSelected += QuickBarInput; |
| 31 | 93 | | quickBarController.OnCatalogItemSelected += CatalogItemSelected; |
| | 94 | |
|
| 31 | 95 | | biwSearchBarController.OnFilterChange += AssetsFiltered; |
| 31 | 96 | | biwSearchBarController.OnFilterRemove += FilterRemoved; |
| 31 | 97 | | } |
| | 98 | |
|
| 9 | 99 | | private void AdapterStartDrag(CatalogItem item, CatalogItemAdapter adapter) { OnCatalogItemStartDrag?.Invoke(item, a |
| | 100 | |
|
| | 101 | | public void Dispose() |
| | 102 | | { |
| 30 | 103 | | sceneCatalogView.OnHideCatalogClicked -= HideCatalogClicked; |
| | 104 | |
|
| 30 | 105 | | if (sceneCatalogView.catalogAssetPackList != null) |
| 0 | 106 | | sceneCatalogView.catalogAssetPackList.OnCatalogPackClick -= OnCatalogItemPackSelected; |
| | 107 | |
|
| 30 | 108 | | if (sceneCatalogView.catalogGroupList != null) |
| | 109 | | { |
| 0 | 110 | | sceneCatalogView.catalogGroupList.OnCatalogItemClicked -= CatalogItemSelected; |
| 0 | 111 | | sceneCatalogView.catalogGroupList.OnCatalogItemStarDragging -= AdapterStartDrag; |
| 0 | 112 | | sceneCatalogView.catalogGroupList.OnPointerEnterInAdapter -= OnPointerEnter; |
| 0 | 113 | | sceneCatalogView.catalogGroupList.OnPointerExitInAdapter -= OnPointerExit; |
| | 114 | | } |
| | 115 | |
|
| 30 | 116 | | if (sceneCatalogView.category != null) |
| 0 | 117 | | sceneCatalogView.category.onValueChanged.RemoveListener(CategoryFilter); |
| | 118 | |
|
| 30 | 119 | | if (sceneCatalogView.favorites != null) |
| 0 | 120 | | sceneCatalogView.favorites.onValueChanged.RemoveListener(FavoritesFilter); |
| | 121 | |
|
| 30 | 122 | | if (sceneCatalogView.assetPack != null) |
| 0 | 123 | | sceneCatalogView.assetPack.onValueChanged.RemoveListener(AssetsPackFilter); |
| | 124 | |
|
| 30 | 125 | | sceneCatalogView.OnSceneCatalogBack -= SceneCatalogBack; |
| | 126 | |
|
| 30 | 127 | | quickBarController.OnQuickBarShortcutSelected -= QuickBarInput; |
| 30 | 128 | | quickBarController.OnCatalogItemSelected -= CatalogItemSelected; |
| | 129 | |
|
| 30 | 130 | | biwSearchBarController.OnFilterChange -= AssetsFiltered; |
| 30 | 131 | | biwSearchBarController.OnFilterRemove -= FilterRemoved; |
| | 132 | |
|
| 30 | 133 | | favoritesController.Dispose(); |
| 30 | 134 | | biwSearchBarController.Dispose(); |
| 30 | 135 | | } |
| | 136 | |
|
| 0 | 137 | | public BuildModeCatalogSection GetCurrentSection() { return currentSection; } |
| | 138 | |
|
| | 139 | | public void AssetsFiltered(List<Dictionary<string, List<CatalogItem>>> filterObjects) |
| | 140 | | { |
| 2 | 141 | | ShowCatalogContent(); |
| 2 | 142 | | if (sceneCatalogView.catalogGroupList != null) |
| 0 | 143 | | sceneCatalogView.catalogGroupList.SetContent(filterObjects); |
| 2 | 144 | | } |
| | 145 | |
|
| 0 | 146 | | public void FilterRemoved() { ShowLastSelectedSection(); } |
| | 147 | |
|
| | 148 | | public void AssetsPackFilter(bool isOn) |
| | 149 | | { |
| 0 | 150 | | if (!isOn) |
| 0 | 151 | | return; |
| | 152 | |
|
| 0 | 153 | | isFilterByAssetPacks = true; |
| 0 | 154 | | ShowAssetsPacks(); |
| 0 | 155 | | } |
| | 156 | |
|
| | 157 | | public void CategoryFilter(bool isOn) |
| | 158 | | { |
| 0 | 159 | | if (!isOn) |
| 0 | 160 | | return; |
| | 161 | |
|
| 0 | 162 | | isFilterByAssetPacks = false; |
| 0 | 163 | | ShowCategories(); |
| 0 | 164 | | } |
| | 165 | |
|
| | 166 | | public void FavoritesFilter(bool isOn) |
| | 167 | | { |
| 0 | 168 | | if (!isOn) |
| 0 | 169 | | return; |
| | 170 | |
|
| 0 | 171 | | ShowFavorites(); |
| 0 | 172 | | } |
| | 173 | |
|
| 2 | 174 | | public void ToggleCatalogExpanse() { sceneCatalogView.ToggleCatalogExpanse(); } |
| | 175 | |
|
| 6 | 176 | | public void QuickBarInput(int quickBarSlot) { quickBarController.QuickBarObjectSelected(quickBarSlot); } |
| | 177 | |
|
| | 178 | | public void ShowFavorites() |
| | 179 | | { |
| 1 | 180 | | currentSection = BuildModeCatalogSection.FAVOURITES; |
| 1 | 181 | | biwSearchBarController.ReleaseFilters(); |
| | 182 | |
|
| 1 | 183 | | sceneCatalogView.SetCatalogTitle(FAVORITE_NAME); |
| 1 | 184 | | ShowCatalogContent(); |
| | 185 | |
|
| 1 | 186 | | var favorites = GenerateFavorites(); |
| | 187 | |
|
| 1 | 188 | | sceneCatalogView.catalogGroupList?.SetContent(favorites); |
| 1 | 189 | | sceneCatalogView.ShowBackButton(false); |
| 1 | 190 | | } |
| | 191 | |
|
| | 192 | | internal List<Dictionary<string, List<CatalogItem>>> GenerateFavorites() |
| | 193 | | { |
| 2 | 194 | | List<Dictionary<string, List<CatalogItem>>> favorites = new List<Dictionary<string, List<CatalogItem>>>(); |
| 2 | 195 | | Dictionary<string, List<CatalogItem>> groupedCategoryItems = new Dictionary<string, List<CatalogItem>>(); |
| 2 | 196 | | groupedCategoryItems.Add(FAVORITE_NAME, favoritesController.GetFavorites()); |
| 2 | 197 | | favorites.Add(groupedCategoryItems); |
| 2 | 198 | | return favorites; |
| | 199 | | } |
| | 200 | |
|
| 11 | 201 | | public void CatalogItemSelected(CatalogItem catalogItem) { OnCatalogItemSelected?.Invoke(catalogItem); } |
| | 202 | |
|
| 2 | 203 | | public void ResumeInput() { OnResumeInput?.Invoke(); } |
| | 204 | |
|
| 2 | 205 | | public void StopInput() { OnStopInput?.Invoke(); } |
| | 206 | |
|
| 0 | 207 | | private void OnPointerEnter(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerEnterInCatalogItemAda |
| | 208 | |
|
| 0 | 209 | | private void OnPointerExit(PointerEventData eventData, CatalogItemAdapter adapter) { OnPointerExitInCatalogItemAdapt |
| | 210 | |
|
| 2 | 211 | | public void HideCatalogClicked() { OnHideCatalogClicked?.Invoke(); } |
| | 212 | |
|
| | 213 | | public void OnCatalogItemPackSelected(CatalogItemPack catalogItemPack) |
| | 214 | | { |
| 1 | 215 | | ShowCatalogContent(); |
| 1 | 216 | | SetCatalogAssetPackInListView(catalogItemPack); |
| 1 | 217 | | sceneCatalogView.ShowBackButton(true); |
| 1 | 218 | | } |
| | 219 | |
|
| | 220 | | internal void SetCatalogAssetPackInListView(CatalogItemPack catalogItemPack) |
| | 221 | | { |
| 1 | 222 | | sceneCatalogView.SetCatalogTitle(catalogItemPack.title); |
| | 223 | |
|
| 1 | 224 | | var contentList = GenerateContentListForCatalogItemPack(catalogItemPack); |
| | 225 | |
|
| 1 | 226 | | sceneCatalogView.catalogGroupList?.SetContent(contentList); |
| 0 | 227 | | } |
| | 228 | |
|
| | 229 | | internal List<Dictionary<string, List<CatalogItem>>> GenerateContentListForCatalogItemPack(CatalogItemPack catalogI |
| | 230 | | { |
| 1 | 231 | | Dictionary<string, List<CatalogItem>> groupedCatalogItem = new Dictionary<string, List<CatalogItem>>(); |
| | 232 | |
|
| 6 | 233 | | foreach (CatalogItem sceneObject in catalogItemPack.assets) |
| | 234 | | { |
| 2 | 235 | | string titleToUse = sceneObject.categoryName; |
| | 236 | |
|
| 2 | 237 | | if (!groupedCatalogItem.ContainsKey(titleToUse)) |
| | 238 | | { |
| 1 | 239 | | groupedCatalogItem.Add(titleToUse, GetAssetsListByCategory(titleToUse, catalogItemPack)); |
| | 240 | | } |
| | 241 | | } |
| | 242 | |
|
| 1 | 243 | | List<Dictionary<string, List<CatalogItem>>> contentList = new List<Dictionary<string, List<CatalogItem>>> |
| | 244 | | { |
| | 245 | | groupedCatalogItem |
| | 246 | | }; |
| | 247 | |
|
| 1 | 248 | | return contentList; |
| | 249 | | } |
| | 250 | |
|
| | 251 | | internal List<CatalogItem> GetAssetsListByCategory(string category, CatalogItemPack sceneAssetPack) |
| | 252 | | { |
| 2 | 253 | | List<CatalogItem> catalogItemList = new List<CatalogItem>(); |
| | 254 | |
|
| 14 | 255 | | foreach (CatalogItem catalogItem in sceneAssetPack.assets) |
| | 256 | | { |
| 5 | 257 | | if (category == catalogItem.categoryName) |
| 4 | 258 | | catalogItemList.Add(catalogItem); |
| | 259 | | } |
| | 260 | |
|
| 2 | 261 | | return catalogItemList; |
| | 262 | | } |
| | 263 | |
|
| | 264 | | public void SceneCatalogBack() |
| | 265 | | { |
| 2 | 266 | | if (isShowingAssetPacks) |
| | 267 | | { |
| 1 | 268 | | sceneCatalogView.CloseCatalog(); |
| 1 | 269 | | } |
| | 270 | | else |
| | 271 | | { |
| 1 | 272 | | if (isFilterByAssetPacks) |
| 1 | 273 | | ShowAssetsPacks(); |
| | 274 | | else |
| 0 | 275 | | ShowCategories(); |
| | 276 | |
|
| 1 | 277 | | sceneCatalogView.ShowBackButton(false); |
| 1 | 278 | | biwSearchBarController.ReleaseFilters(); |
| | 279 | | } |
| 1 | 280 | | } |
| | 281 | |
|
| 1 | 282 | | public bool IsCatalogOpen() { return sceneCatalogView.IsCatalogOpen(); } |
| | 283 | |
|
| 1 | 284 | | public bool IsCatalogExpanded() { return sceneCatalogView.IsCatalogExpanded(); } |
| | 285 | |
|
| | 286 | | public void ShowCategories() |
| | 287 | | { |
| 1 | 288 | | currentSection = BuildModeCatalogSection.CATEGORIES; |
| 1 | 289 | | biwSearchBarController.ReleaseFilters(); |
| | 290 | |
|
| 1 | 291 | | if (sceneCatalogView.catalogAssetPackList != null) |
| | 292 | | { |
| 0 | 293 | | sceneCatalogView.catalogAssetPackList.SetCategoryStyle(); |
| 0 | 294 | | sceneCatalogView.catalogAssetPackList.SetContent(BIWCatalogManager.GetCatalogItemPacksFilteredByCategories() |
| 0 | 295 | | sceneCatalogView.catalogAssetPackList.gameObject.SetActive(true); |
| | 296 | | } |
| | 297 | |
|
| 1 | 298 | | isShowingAssetPacks = true; |
| 1 | 299 | | sceneCatalogView.SetCatalogTitle(BIWSettings.CATALOG_ASSET_PACK_TITLE); |
| | 300 | |
|
| 1 | 301 | | if (sceneCatalogView.catalogGroupList != null) |
| 0 | 302 | | sceneCatalogView.catalogGroupList.gameObject.SetActive(false); |
| | 303 | |
|
| 1 | 304 | | sceneCatalogView.ShowBackButton(false); |
| 1 | 305 | | } |
| | 306 | |
|
| | 307 | | public void ShowAssetsPacks() |
| | 308 | | { |
| 3 | 309 | | currentSection = BuildModeCatalogSection.ASSET_PACKS; |
| 3 | 310 | | biwSearchBarController.ReleaseFilters(); |
| | 311 | |
|
| 3 | 312 | | if (sceneCatalogView.catalogAssetPackList != null) |
| | 313 | | { |
| 0 | 314 | | sceneCatalogView.catalogAssetPackList.SetAssetPackStyle(); |
| 0 | 315 | | sceneCatalogView.catalogAssetPackList.gameObject.SetActive(true); |
| | 316 | | } |
| | 317 | |
|
| 3 | 318 | | isShowingAssetPacks = true; |
| 3 | 319 | | sceneCatalogView.SetCatalogTitle(BIWSettings.CATALOG_ASSET_PACK_TITLE); |
| 3 | 320 | | RefreshCatalog(); |
| | 321 | |
|
| 3 | 322 | | if (sceneCatalogView.catalogGroupList != null) |
| 0 | 323 | | sceneCatalogView.catalogGroupList.gameObject.SetActive(false); |
| | 324 | |
|
| 3 | 325 | | sceneCatalogView.ShowBackButton(false); |
| 3 | 326 | | } |
| | 327 | |
|
| | 328 | | public void ShowCatalogContent() |
| | 329 | | { |
| 4 | 330 | | isShowingAssetPacks = false; |
| 4 | 331 | | if (sceneCatalogView.catalogAssetPackList != null) |
| 0 | 332 | | sceneCatalogView.catalogAssetPackList.gameObject.SetActive(false); |
| | 333 | |
|
| 4 | 334 | | if (sceneCatalogView.catalogGroupList != null) |
| 0 | 335 | | sceneCatalogView.catalogGroupList.gameObject.SetActive(true); |
| 4 | 336 | | } |
| | 337 | |
|
| | 338 | | public void OpenCatalog() |
| | 339 | | { |
| 1 | 340 | | ShowLastSelectedSection(); |
| 1 | 341 | | Utils.UnlockCursor(); |
| 1 | 342 | | sceneCatalogView.SetActive(true); |
| 1 | 343 | | } |
| | 344 | |
|
| 2 | 345 | | public void CloseCatalog() { sceneCatalogView.CloseCatalog(); } |
| | 346 | |
|
| | 347 | | public void RefreshAssetPack() |
| | 348 | | { |
| 0 | 349 | | if (sceneCatalogView.catalogGroupList != null) |
| 0 | 350 | | sceneCatalogView.catalogGroupList.RefreshDisplay(); |
| 0 | 351 | | } |
| | 352 | |
|
| | 353 | | public void RefreshCatalog() |
| | 354 | | { |
| 3 | 355 | | if (sceneCatalogView.catalogAssetPackList != null) |
| 0 | 356 | | sceneCatalogView.catalogAssetPackList.SetContent(BIWCatalogManager.GetCatalogItemPackList()); |
| 3 | 357 | | } |
| | 358 | |
|
| | 359 | | private void ShowLastSelectedSection() |
| | 360 | | { |
| 1 | 361 | | switch (currentSection) |
| | 362 | | { |
| | 363 | | case BuildModeCatalogSection.CATEGORIES: |
| 0 | 364 | | ShowCategories(); |
| 0 | 365 | | break; |
| | 366 | | case BuildModeCatalogSection.ASSET_PACKS: |
| 1 | 367 | | ShowAssetsPacks(); |
| 1 | 368 | | break; |
| | 369 | | case BuildModeCatalogSection.FAVOURITES: |
| 0 | 370 | | ShowFavorites(); |
| | 371 | | break; |
| | 372 | | } |
| 0 | 373 | | } |
| | 374 | |
|
| 4 | 375 | | public void SetActive(bool isActive) { sceneCatalogView.SetActive(isActive); } |
| | 376 | | } |