| | 1 | | using DCL; |
| | 2 | | using MainScripts.DCL.Controllers.HotScenes; |
| | 3 | | using MainScripts.DCL.Helpers.Utils; |
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.UI; |
| | 9 | | using Utils = DCL.Helpers.Utils; |
| | 10 | |
|
| | 11 | | public class SearchSubSectionComponentView : BaseComponentView, ISearchSubSectionComponentView |
| | 12 | | { |
| | 13 | | private const int MAX_POOL_COUNT = 6; |
| | 14 | | internal const string WORLDS_SUBSECTION_FF = "worlds_subsection"; |
| | 15 | |
|
| 0 | 16 | | public int CurrentTilesPerRow { get; } |
| 0 | 17 | | public int CurrentGoingTilesPerRow { get; } |
| | 18 | |
|
| | 19 | | [SerializeField] private GameObject minimalSearchSection; |
| | 20 | | [SerializeField] private GameObject fullSearchSection; |
| | 21 | | [SerializeField] private GameObject normalHeader; |
| | 22 | | [SerializeField] private GameObject searchHeader; |
| | 23 | | [SerializeField] private GameObject favoritesHeader; |
| | 24 | | [SerializeField] private Button backButton; |
| | 25 | | [SerializeField] private TMP_Text searchTerm; |
| | 26 | |
|
| | 27 | | [SerializeField] private Canvas canvas; |
| | 28 | | [SerializeField] private GameObject worldsSection; |
| | 29 | | [SerializeField] private Transform eventsParent; |
| | 30 | | [SerializeField] private Transform placesParent; |
| | 31 | | [SerializeField] private Transform worldsParent; |
| | 32 | | [SerializeField] private RectTransform fullEventsParent; |
| | 33 | | [SerializeField] private RectTransform fullPlacesParent; |
| | 34 | | [SerializeField] private RectTransform fullWorldsParent; |
| | 35 | | [SerializeField] private RectTransform gridContainer; |
| | 36 | | [SerializeField] private EventCardComponentView eventPrefab; |
| | 37 | | [SerializeField] private PlaceCardComponentView placePrefab; |
| | 38 | | [SerializeField] private GameObject loadingEvents; |
| | 39 | | [SerializeField] private GameObject loadingPlaces; |
| | 40 | | [SerializeField] private GameObject loadingWorlds; |
| | 41 | | [SerializeField] private GameObject loadingAll; |
| | 42 | | [SerializeField] private Button showAllPlaces; |
| | 43 | | [SerializeField] private Button showAllWorlds; |
| | 44 | | [SerializeField] private Button showAllEvents; |
| | 45 | | [SerializeField] private Button showMore; |
| | 46 | |
|
| | 47 | | [SerializeField] internal GameObject noEvents; |
| | 48 | | [SerializeField] internal GameObject noPlaces; |
| | 49 | | [SerializeField] internal GameObject noWorlds; |
| | 50 | | [SerializeField] internal GameObject noResults; |
| | 51 | | [SerializeField] private TMP_Text noEventsText; |
| | 52 | | [SerializeField] private TMP_Text noPlacesText; |
| | 53 | | [SerializeField] private TMP_Text noWorldsText; |
| | 54 | | [SerializeField] private TMP_Text noResultsText; |
| | 55 | | [SerializeField] internal EventCardComponentView eventCardModalPrefab; |
| | 56 | | [SerializeField] internal PlaceCardComponentView placeCardModalPrefab; |
| | 57 | | [SerializeField] internal PlaceCardComponentView worldCardModalPrefab; |
| | 58 | |
|
| | 59 | | internal EventCardComponentView eventModal; |
| | 60 | | internal PlaceCardComponentView placeModal; |
| | 61 | | internal PlaceCardComponentView worldModal; |
| | 62 | | public event Action<int> OnRequestAllEvents; |
| | 63 | | public event Action<int> OnRequestAllPlaces; |
| | 64 | | public event Action<int> OnRequestAllWorlds; |
| | 65 | | public event Action OnBackFromSearch; |
| | 66 | | public event Action<EventCardComponentModel, int> OnEventInfoClicked; |
| | 67 | | public event Action<PlaceCardComponentModel, int> OnPlaceInfoClicked; |
| | 68 | | public event Action<PlaceCardComponentModel, int> OnWorldInfoClicked; |
| | 69 | | public event Action<EventFromAPIModel> OnEventJumpInClicked; |
| | 70 | | public event Action<IHotScenesController.PlaceInfo> OnPlaceJumpInClicked; |
| | 71 | | public event Action<IHotScenesController.PlaceInfo> OnWorldJumpInClicked; |
| | 72 | | public event Action<string, bool?> OnVoteChanged; |
| | 73 | | public event Action<string, bool> OnPlaceFavoriteChanged; |
| | 74 | | public event Action<string, bool> OnSubscribeEventClicked; |
| | 75 | | public event Action<string, bool> OnUnsubscribeEventClicked; |
| | 76 | |
|
| | 77 | | private UnityObjectPool<EventCardComponentView> eventsPool; |
| 50 | 78 | | internal List<EventCardComponentView> pooledEvents = new List<EventCardComponentView>(); |
| | 79 | | private UnityObjectPool<EventCardComponentView> fullEventsPool; |
| 50 | 80 | | internal List<EventCardComponentView> pooledFullEvents = new List<EventCardComponentView>(); |
| | 81 | | private UnityObjectPool<PlaceCardComponentView> placesPool; |
| 50 | 82 | | internal List<PlaceCardComponentView> pooledPlaces = new List<PlaceCardComponentView>(); |
| | 83 | | private UnityObjectPool<PlaceCardComponentView> fullPlacesPool; |
| 50 | 84 | | internal List<PlaceCardComponentView> pooledFullPlaces = new List<PlaceCardComponentView>(); |
| | 85 | | private UnityObjectPool<PlaceCardComponentView> worldsPool; |
| 50 | 86 | | internal List<PlaceCardComponentView> pooledWorlds = new List<PlaceCardComponentView>(); |
| | 87 | | private UnityObjectPool<PlaceCardComponentView> fullWorldsPool; |
| 50 | 88 | | internal List<PlaceCardComponentView> pooledFullWorlds = new List<PlaceCardComponentView>(); |
| | 89 | | private int currentPage = 0; |
| | 90 | |
|
| | 91 | | public override void Awake() |
| | 92 | | { |
| 47 | 93 | | InitializePools(); |
| 47 | 94 | | InitialiseButtonEvents(); |
| | 95 | |
|
| 47 | 96 | | noEvents.SetActive(false); |
| 47 | 97 | | noPlaces.SetActive(false); |
| 47 | 98 | | eventModal = PlacesAndEventsCardsFactory.GetEventCardTemplateHiddenLazy(eventCardModalPrefab); |
| 47 | 99 | | placeModal = PlacesAndEventsCardsFactory.GetPlaceCardTemplateHiddenLazy(placeCardModalPrefab); |
| 47 | 100 | | worldModal = PlacesAndEventsCardsFactory.GetWorldCardTemplateHiddenLazy(worldCardModalPrefab); |
| 47 | 101 | | } |
| | 102 | |
|
| | 103 | | private void InitialiseButtonEvents() |
| | 104 | | { |
| 47 | 105 | | if (showAllEvents != null) |
| | 106 | | { |
| 47 | 107 | | showAllEvents.onClick.RemoveAllListeners(); |
| 47 | 108 | | showAllEvents.onClick.AddListener(RequestAllEvents); |
| | 109 | | } |
| | 110 | |
|
| 47 | 111 | | if (showAllPlaces != null) |
| | 112 | | { |
| 47 | 113 | | showAllPlaces.onClick.RemoveAllListeners(); |
| 47 | 114 | | showAllPlaces.onClick.AddListener(RequestAllPlaces); |
| | 115 | | } |
| | 116 | |
|
| 47 | 117 | | if (showAllWorlds != null) |
| | 118 | | { |
| 47 | 119 | | showAllWorlds.onClick.RemoveAllListeners(); |
| 47 | 120 | | showAllWorlds.onClick.AddListener(RequestAllWorlds); |
| | 121 | | } |
| | 122 | |
|
| 47 | 123 | | if (showMore != null) |
| | 124 | | { |
| 47 | 125 | | showMore.onClick.RemoveAllListeners(); |
| 47 | 126 | | showMore.onClick.AddListener(RequestAdditionalPage); |
| | 127 | | } |
| | 128 | |
|
| 47 | 129 | | if (backButton != null) |
| | 130 | | { |
| 37 | 131 | | backButton.onClick.RemoveAllListeners(); |
| 37 | 132 | | backButton.onClick.AddListener(OnBackButtonPressed); |
| | 133 | | } |
| 47 | 134 | | } |
| | 135 | |
|
| | 136 | | private void RequestAdditionalPage() |
| | 137 | | { |
| 0 | 138 | | currentPage++; |
| | 139 | |
|
| 0 | 140 | | if(fullEventsParent.gameObject.activeSelf) |
| 0 | 141 | | OnRequestAllEvents?.Invoke(currentPage); |
| 0 | 142 | | else if(fullPlacesParent.gameObject.activeSelf) |
| 0 | 143 | | OnRequestAllPlaces?.Invoke(currentPage); |
| 0 | 144 | | else if(fullWorldsParent.gameObject.activeSelf) |
| 0 | 145 | | OnRequestAllWorlds?.Invoke(currentPage); |
| 0 | 146 | | } |
| | 147 | |
|
| | 148 | | private void OnBackButtonPressed() |
| | 149 | | { |
| 0 | 150 | | if (minimalSearchSection.activeSelf || noResults.activeSelf) |
| | 151 | | { |
| 0 | 152 | | OnBackFromSearch?.Invoke(); |
| | 153 | | } |
| | 154 | | else |
| | 155 | | { |
| 0 | 156 | | minimalSearchSection.SetActive(true); |
| 0 | 157 | | fullSearchSection.SetActive(false); |
| | 158 | | } |
| 0 | 159 | | } |
| | 160 | |
|
| | 161 | | private void RequestAllEvents() |
| | 162 | | { |
| 0 | 163 | | currentPage = 0; |
| 0 | 164 | | minimalSearchSection.SetActive(false); |
| 0 | 165 | | fullSearchSection.SetActive(true); |
| 0 | 166 | | fullEventsParent.gameObject.SetActive(true); |
| 0 | 167 | | fullPlacesParent.gameObject.SetActive(false); |
| 0 | 168 | | fullWorldsParent.gameObject.SetActive(false); |
| 0 | 169 | | loadingAll.SetActive(true); |
| 0 | 170 | | ClearFullEventsPool(); |
| 0 | 171 | | OnRequestAllEvents?.Invoke(currentPage); |
| 0 | 172 | | } |
| | 173 | |
|
| | 174 | | private void RequestAllPlaces() |
| | 175 | | { |
| 0 | 176 | | currentPage = 0; |
| 0 | 177 | | minimalSearchSection.SetActive(false); |
| 0 | 178 | | fullSearchSection.SetActive(true); |
| 0 | 179 | | fullEventsParent.gameObject.SetActive(false); |
| 0 | 180 | | fullPlacesParent.gameObject.SetActive(true); |
| 0 | 181 | | fullWorldsParent.gameObject.SetActive(false); |
| 0 | 182 | | loadingAll.SetActive(true); |
| 0 | 183 | | ClearFullPlacesPool(); |
| 0 | 184 | | OnRequestAllPlaces?.Invoke(currentPage); |
| 0 | 185 | | } |
| | 186 | |
|
| | 187 | | private void RequestAllWorlds() |
| | 188 | | { |
| 0 | 189 | | currentPage = 0; |
| 0 | 190 | | minimalSearchSection.SetActive(false); |
| 0 | 191 | | fullSearchSection.SetActive(true); |
| 0 | 192 | | fullEventsParent.gameObject.SetActive(false); |
| 0 | 193 | | fullPlacesParent.gameObject.SetActive(false); |
| 0 | 194 | | fullWorldsParent.gameObject.SetActive(true); |
| 0 | 195 | | loadingAll.SetActive(true); |
| 0 | 196 | | ClearFullWorldsPool(); |
| 0 | 197 | | OnRequestAllWorlds?.Invoke(currentPage); |
| 0 | 198 | | } |
| | 199 | |
|
| | 200 | | public void ShowEvents(List<EventCardComponentModel> events, string searchText) |
| | 201 | | { |
| 3 | 202 | | ClearEventsPool(); |
| 10 | 203 | | foreach (EventCardComponentModel eventCardComponentModel in events) |
| | 204 | | { |
| 2 | 205 | | EventCardComponentView eventCardComponentView = eventsPool.Get(); |
| 2 | 206 | | eventCardComponentView.model = eventCardComponentModel; |
| 2 | 207 | | eventCardComponentView.RefreshControl(); |
| 2 | 208 | | pooledEvents.Add(eventCardComponentView); |
| 2 | 209 | | ConfigureEventCardActions(eventCardComponentView, eventCardComponentModel); |
| | 210 | | } |
| 3 | 211 | | eventsParent.gameObject.SetActive(true); |
| 3 | 212 | | loadingEvents.gameObject.SetActive(false); |
| | 213 | |
|
| 3 | 214 | | showAllEvents.gameObject.SetActive(events.Count == 6); |
| 3 | 215 | | if (events.Count == 0) |
| | 216 | | { |
| 2 | 217 | | noEvents.SetActive(true); |
| 2 | 218 | | noEventsText.text = $"No events found for '{searchText}'"; |
| | 219 | | } |
| | 220 | | else |
| | 221 | | { |
| 1 | 222 | | noEvents.SetActive(false); |
| | 223 | | } |
| 3 | 224 | | CheckAndSetNoResults(searchText); |
| 3 | 225 | | } |
| | 226 | |
|
| | 227 | | public void ShowPlaces(List<PlaceCardComponentModel> places, string searchText) |
| | 228 | | { |
| 3 | 229 | | ClearPlacesPool(); |
| 10 | 230 | | foreach (PlaceCardComponentModel placeCardComponentModel in places) |
| | 231 | | { |
| 2 | 232 | | PlaceCardComponentView placeCardComponentView = placesPool.Get(); |
| 2 | 233 | | placeCardComponentView.model = placeCardComponentModel; |
| 2 | 234 | | placeCardComponentView.RefreshControl(); |
| 2 | 235 | | pooledPlaces.Add(placeCardComponentView); |
| 2 | 236 | | ConfigurePlaceCardActions(placeCardComponentView, placeCardComponentModel); |
| | 237 | | } |
| 3 | 238 | | placesParent.gameObject.SetActive(true); |
| 3 | 239 | | loadingPlaces.gameObject.SetActive(false); |
| | 240 | |
|
| 3 | 241 | | showAllPlaces.gameObject.SetActive(places.Count == 6); |
| 3 | 242 | | if (places.Count == 0) |
| | 243 | | { |
| 2 | 244 | | noPlaces.SetActive(true); |
| 2 | 245 | | noPlacesText.text = $"No places found for '{searchText}'"; |
| | 246 | | } |
| | 247 | | else |
| | 248 | | { |
| 1 | 249 | | noPlaces.SetActive(false); |
| | 250 | | } |
| 3 | 251 | | CheckAndSetNoResults(searchText); |
| 3 | 252 | | } |
| | 253 | |
|
| | 254 | | public void ShowWorlds(List<PlaceCardComponentModel> worlds, string searchText) |
| | 255 | | { |
| 3 | 256 | | ClearWorldsPool(); |
| 10 | 257 | | foreach (PlaceCardComponentModel placeCardComponentModel in worlds) |
| | 258 | | { |
| 2 | 259 | | PlaceCardComponentView placeCardComponentView = worldsPool.Get(); |
| 2 | 260 | | placeCardComponentView.model = placeCardComponentModel; |
| 2 | 261 | | placeCardComponentView.RefreshControl(); |
| 2 | 262 | | pooledWorlds.Add(placeCardComponentView); |
| 2 | 263 | | ConfigureWorldCardActions(placeCardComponentView, placeCardComponentModel); |
| | 264 | | } |
| 3 | 265 | | worldsParent.gameObject.SetActive(true); |
| 3 | 266 | | loadingWorlds.gameObject.SetActive(false); |
| | 267 | |
|
| 3 | 268 | | showAllWorlds.gameObject.SetActive(worlds.Count == 6); |
| 3 | 269 | | if (worlds.Count == 0) |
| | 270 | | { |
| 2 | 271 | | noWorlds.SetActive(true); |
| 2 | 272 | | noWorldsText.text = $"No wordls found for '{searchText}'"; |
| | 273 | | } |
| | 274 | | else |
| | 275 | | { |
| 1 | 276 | | noWorlds.SetActive(false); |
| | 277 | | } |
| 3 | 278 | | CheckAndSetNoResults(searchText); |
| 3 | 279 | | } |
| | 280 | |
|
| | 281 | | private void CheckAndSetNoResults(string searchText) |
| | 282 | | { |
| 9 | 283 | | if (noPlaces.activeSelf && noEvents.activeSelf && noWorlds.activeSelf) |
| | 284 | | { |
| 1 | 285 | | noResults.SetActive(true); |
| 1 | 286 | | minimalSearchSection.SetActive(false); |
| 1 | 287 | | noResultsText.text = $"No results found for '{searchText}'"; |
| | 288 | | } |
| | 289 | | else |
| | 290 | | { |
| 8 | 291 | | noResults.SetActive(false); |
| 8 | 292 | | if(minimalSearchSection.activeSelf == false) |
| 0 | 293 | | minimalSearchSection.SetActive(true); |
| | 294 | | } |
| 9 | 295 | | Utils.ForceRebuildLayoutImmediate(gridContainer); |
| 9 | 296 | | } |
| | 297 | |
|
| | 298 | | private void ConfigureEventCardActions(EventCardComponentView view, EventCardComponentModel model) |
| | 299 | | { |
| 4 | 300 | | view.onInfoClick.RemoveAllListeners(); |
| 4 | 301 | | view.onBackgroundClick.RemoveAllListeners(); |
| 4 | 302 | | view.onSubscribeClick.RemoveAllListeners(); |
| 4 | 303 | | view.onUnsubscribeClick.RemoveAllListeners(); |
| 4 | 304 | | view.onJumpInClick.RemoveAllListeners(); |
| 4 | 305 | | view.onSecondaryJumpInClick?.RemoveAllListeners(); |
| 4 | 306 | | view.onInfoClick.AddListener(() => OnEventInfoClicked?.Invoke(model, view.transform.GetSiblingIndex())); |
| 4 | 307 | | view.onBackgroundClick.AddListener(() => OnEventInfoClicked?.Invoke(model, view.transform.GetSiblingIndex())); |
| 4 | 308 | | view.onSubscribeClick.AddListener(() => OnSubscribeEventClicked?.Invoke(model.eventId, !string.IsNullOrEmpty(mod |
| 4 | 309 | | view.onUnsubscribeClick.AddListener(() => OnUnsubscribeEventClicked?.Invoke(model.eventId, !string.IsNullOrEmpty |
| 4 | 310 | | view.onJumpInClick.AddListener(() => OnEventJumpInClicked?.Invoke(model.eventFromAPIInfo)); |
| 4 | 311 | | view.onSecondaryJumpInClick?.AddListener(() => OnEventJumpInClicked?.Invoke(model.eventFromAPIInfo)); |
| 0 | 312 | | } |
| | 313 | |
|
| | 314 | | private void ConfigurePlaceCardActions(PlaceCardComponentView view, PlaceCardComponentModel model) |
| | 315 | | { |
| 4 | 316 | | view.onInfoClick.RemoveAllListeners(); |
| 4 | 317 | | view.onBackgroundClick.RemoveAllListeners(); |
| 4 | 318 | | view.onJumpInClick.RemoveAllListeners(); |
| 4 | 319 | | view.OnFavoriteChanged -= ViewOnOnFavoriteChanged; |
| 4 | 320 | | view.OnVoteChanged -= ViewOnVoteChanged; |
| 4 | 321 | | view.onInfoClick.AddListener(()=>OnPlaceInfoClicked?.Invoke(model, view.transform.GetSiblingIndex())); |
| 4 | 322 | | view.onBackgroundClick.AddListener(()=>OnPlaceInfoClicked?.Invoke(model, view.transform.GetSiblingIndex())); |
| 4 | 323 | | view.onJumpInClick.AddListener(()=>OnPlaceJumpInClicked?.Invoke(model.placeInfo)); |
| 4 | 324 | | view.OnFavoriteChanged += ViewOnOnFavoriteChanged; |
| 4 | 325 | | view.OnVoteChanged += ViewOnVoteChanged; |
| 4 | 326 | | } |
| | 327 | |
|
| | 328 | | private void ConfigureWorldCardActions(PlaceCardComponentView view, PlaceCardComponentModel model) |
| | 329 | | { |
| 4 | 330 | | view.onInfoClick.RemoveAllListeners(); |
| 4 | 331 | | view.onBackgroundClick.RemoveAllListeners(); |
| 4 | 332 | | view.onJumpInClick.RemoveAllListeners(); |
| 4 | 333 | | view.OnFavoriteChanged -= ViewOnOnFavoriteChanged; |
| 4 | 334 | | view.OnVoteChanged -= ViewOnVoteChanged; |
| 4 | 335 | | view.onInfoClick.AddListener(()=>OnWorldInfoClicked?.Invoke(model, view.transform.GetSiblingIndex())); |
| 4 | 336 | | view.onBackgroundClick.AddListener(()=>OnWorldInfoClicked?.Invoke(model, view.transform.GetSiblingIndex())); |
| 4 | 337 | | view.onJumpInClick.AddListener(()=>OnWorldJumpInClicked?.Invoke(model.placeInfo)); |
| 4 | 338 | | view.OnFavoriteChanged += ViewOnOnFavoriteChanged; |
| 4 | 339 | | view.OnVoteChanged += ViewOnVoteChanged; |
| 4 | 340 | | } |
| | 341 | |
|
| | 342 | | public void HideWorldModal() |
| | 343 | | { |
| 0 | 344 | | if (worldModal != null) |
| 0 | 345 | | worldModal.Hide(); |
| 0 | 346 | | } |
| | 347 | |
|
| | 348 | | private void ViewOnVoteChanged(string arg1, bool? arg2) |
| | 349 | | { |
| 0 | 350 | | OnVoteChanged?.Invoke(arg1, arg2); |
| 0 | 351 | | } |
| | 352 | |
|
| | 353 | | private void ViewOnOnFavoriteChanged(string placeId, bool isFavorite) |
| | 354 | | { |
| 0 | 355 | | OnPlaceFavoriteChanged?.Invoke(placeId, isFavorite); |
| 0 | 356 | | } |
| | 357 | |
|
| | 358 | | public void ShowEventModal(EventCardComponentModel eventInfo) |
| | 359 | | { |
| 0 | 360 | | eventModal.Show(); |
| 0 | 361 | | EventsCardsConfigurator.Configure(eventModal, eventInfo, null, OnEventJumpInClicked, OnSubscribeEventClicked, On |
| 0 | 362 | | } |
| | 363 | |
|
| | 364 | | public void ShowPlaceModal(PlaceCardComponentModel placeModel) |
| | 365 | | { |
| 0 | 366 | | placeModal.Show(); |
| 0 | 367 | | PlacesCardsConfigurator.Configure(placeModal, placeModel, null, OnPlaceJumpInClicked, OnVoteChanged, OnPlaceFavo |
| 0 | 368 | | } |
| | 369 | |
|
| | 370 | | public void ShowWorldModal(PlaceCardComponentModel placeModel) |
| | 371 | | { |
| 0 | 372 | | worldModal.Show(); |
| 0 | 373 | | PlacesCardsConfigurator.Configure(worldModal, placeModel, null, OnWorldJumpInClicked, OnVoteChanged, OnPlaceFavo |
| 0 | 374 | | } |
| | 375 | |
|
| | 376 | | public void ShowAllEvents(List<EventCardComponentModel> events, bool showMoreButton) |
| | 377 | | { |
| 1 | 378 | | showMore.gameObject.SetActive(showMoreButton); |
| 6 | 379 | | foreach (EventCardComponentModel eventCardComponentModel in events) |
| | 380 | | { |
| 2 | 381 | | EventCardComponentView eventCardComponentView = fullEventsPool.Get(); |
| 2 | 382 | | eventCardComponentView.model = eventCardComponentModel; |
| 2 | 383 | | eventCardComponentView.RefreshControl(); |
| 2 | 384 | | eventCardComponentView.transform.SetAsLastSibling(); |
| 2 | 385 | | pooledFullEvents.Add(eventCardComponentView); |
| 2 | 386 | | ConfigureEventCardActions(eventCardComponentView, eventCardComponentModel); |
| | 387 | | } |
| 1 | 388 | | loadingAll.SetActive(false); |
| 1 | 389 | | Utils.ForceRebuildLayoutImmediate(fullEventsParent); |
| 1 | 390 | | } |
| | 391 | |
|
| | 392 | | public void ShowAllPlaces(List<PlaceCardComponentModel> places, bool showMoreButton) |
| | 393 | | { |
| 1 | 394 | | showMore.gameObject.SetActive(showMoreButton); |
| 6 | 395 | | foreach (PlaceCardComponentModel placeCardComponentModel in places) |
| | 396 | | { |
| 2 | 397 | | PlaceCardComponentView placeCardComponentView = fullPlacesPool.Get(); |
| 2 | 398 | | placeCardComponentView.model = placeCardComponentModel; |
| 2 | 399 | | placeCardComponentView.RefreshControl(); |
| 2 | 400 | | placeCardComponentView.OnLoseFocus(); |
| 2 | 401 | | placeCardComponentView.transform.SetAsLastSibling(); |
| 2 | 402 | | pooledFullPlaces.Add(placeCardComponentView); |
| 2 | 403 | | ConfigurePlaceCardActions(placeCardComponentView, placeCardComponentModel); |
| | 404 | | } |
| 1 | 405 | | loadingAll.SetActive(false); |
| 1 | 406 | | Utils.ForceRebuildLayoutImmediate(fullPlacesParent); |
| 1 | 407 | | } |
| | 408 | |
|
| | 409 | | public void ShowAllWorlds(List<PlaceCardComponentModel> worlds, bool showMoreButton) |
| | 410 | | { |
| 1 | 411 | | showMore.gameObject.SetActive(showMoreButton); |
| 6 | 412 | | foreach (PlaceCardComponentModel placeCardComponentModel in worlds) |
| | 413 | | { |
| 2 | 414 | | PlaceCardComponentView placeCardComponentView = fullWorldsPool.Get(); |
| 2 | 415 | | placeCardComponentView.model = placeCardComponentModel; |
| 2 | 416 | | placeCardComponentView.RefreshControl(); |
| 2 | 417 | | placeCardComponentView.OnLoseFocus(); |
| 2 | 418 | | placeCardComponentView.transform.SetAsLastSibling(); |
| 2 | 419 | | pooledFullWorlds.Add(placeCardComponentView); |
| 2 | 420 | | ConfigureWorldCardActions(placeCardComponentView, placeCardComponentModel); |
| | 421 | | } |
| 1 | 422 | | loadingAll.SetActive(false); |
| 1 | 423 | | Utils.ForceRebuildLayoutImmediate(fullWorldsParent); |
| 1 | 424 | | } |
| | 425 | |
|
| | 426 | | private void InitializePools() |
| | 427 | | { |
| 47 | 428 | | eventsPool = new UnityObjectPool<EventCardComponentView>(eventPrefab, eventsParent); |
| 47 | 429 | | eventsPool.Prewarm(MAX_POOL_COUNT); |
| 47 | 430 | | placesPool = new UnityObjectPool<PlaceCardComponentView>(placePrefab, placesParent); |
| 47 | 431 | | placesPool.Prewarm(MAX_POOL_COUNT); |
| 47 | 432 | | worldsPool = new UnityObjectPool<PlaceCardComponentView>(placePrefab, worldsParent); |
| 47 | 433 | | worldsPool.Prewarm(MAX_POOL_COUNT); |
| 47 | 434 | | fullEventsPool = new UnityObjectPool<EventCardComponentView>(eventPrefab, fullEventsParent); |
| 47 | 435 | | fullEventsPool.Prewarm(MAX_POOL_COUNT); |
| 47 | 436 | | fullPlacesPool = new UnityObjectPool<PlaceCardComponentView>(placePrefab, fullPlacesParent); |
| 47 | 437 | | fullPlacesPool.Prewarm(MAX_POOL_COUNT); |
| 47 | 438 | | fullWorldsPool = new UnityObjectPool<PlaceCardComponentView>(placePrefab, fullWorldsParent); |
| 47 | 439 | | fullWorldsPool.Prewarm(MAX_POOL_COUNT); |
| 47 | 440 | | } |
| | 441 | |
|
| | 442 | | public void RestartScrollViewPosition() |
| | 443 | | { |
| 0 | 444 | | } |
| | 445 | |
|
| | 446 | | private void CloseFullList() |
| | 447 | | { |
| 0 | 448 | | minimalSearchSection.SetActive(true); |
| 0 | 449 | | fullSearchSection.SetActive(false); |
| 0 | 450 | | } |
| | 451 | |
|
| | 452 | | public void SetAllAsLoading() |
| | 453 | | { |
| 0 | 454 | | CloseFullList(); |
| 0 | 455 | | eventsParent.gameObject.SetActive(false); |
| 0 | 456 | | placesParent.gameObject.SetActive(false); |
| 0 | 457 | | worldsParent.gameObject.SetActive(false); |
| 0 | 458 | | loadingEvents.SetActive(true); |
| 0 | 459 | | loadingPlaces.SetActive(true); |
| 0 | 460 | | loadingWorlds.SetActive(true); |
| 0 | 461 | | } |
| | 462 | |
|
| | 463 | | public void SetHeaderEnabled(string searchText) |
| | 464 | | { |
| 37 | 465 | | normalHeader.SetActive(string.IsNullOrEmpty(searchText)); |
| 37 | 466 | | searchHeader.SetActive(!string.IsNullOrEmpty(searchText)); |
| 37 | 467 | | favoritesHeader.SetActive(false); |
| 37 | 468 | | searchTerm.text = $"\"{searchText}\""; |
| 37 | 469 | | } |
| | 470 | |
|
| | 471 | | public void SetActive(bool isActive) |
| | 472 | | { |
| 127 | 473 | | if (canvas.enabled == isActive) |
| 91 | 474 | | return; |
| 36 | 475 | | canvas.enabled = isActive; |
| | 476 | |
|
| 36 | 477 | | if (isActive) |
| 0 | 478 | | OnEnable(); |
| | 479 | | else |
| | 480 | | { |
| 36 | 481 | | OnDisable(); |
| | 482 | | } |
| 36 | 483 | | } |
| | 484 | |
|
| | 485 | | public override void OnEnable() |
| | 486 | | { |
| 47 | 487 | | base.OnEnable(); |
| | 488 | |
|
| | 489 | | //Temporary until the full feature is released |
| 47 | 490 | | worldsSection.SetActive(DataStore.i.featureFlags.flags.Get().IsFeatureEnabled(WORLDS_SUBSECTION_FF)); |
| 47 | 491 | | } |
| | 492 | |
|
| | 493 | | public override void RefreshControl() |
| | 494 | | { |
| 0 | 495 | | } |
| | 496 | |
|
| | 497 | | public override void Dispose() |
| | 498 | | { |
| 102 | 499 | | ClearEventsPool(); |
| 102 | 500 | | ClearFullEventsPool(); |
| 102 | 501 | | ClearPlacesPool(); |
| 102 | 502 | | ClearFullPlacesPool(); |
| 102 | 503 | | ClearWorldsPool(); |
| 102 | 504 | | ClearFullWorldsPool(); |
| 102 | 505 | | } |
| | 506 | |
|
| | 507 | | private void ClearEventsPool() |
| | 508 | | { |
| 214 | 509 | | foreach (var pooledEvent in pooledEvents) |
| 2 | 510 | | eventsPool.Release(pooledEvent); |
| 105 | 511 | | pooledEvents.Clear(); |
| 105 | 512 | | } |
| | 513 | |
|
| | 514 | | private void ClearFullEventsPool() |
| | 515 | | { |
| 208 | 516 | | foreach (var pooledEvent in pooledFullEvents) |
| 2 | 517 | | fullEventsPool.Release(pooledEvent); |
| 102 | 518 | | pooledFullEvents.Clear(); |
| 102 | 519 | | } |
| | 520 | |
|
| | 521 | | private void ClearPlacesPool() |
| | 522 | | { |
| 214 | 523 | | foreach (var pooledEvent in pooledPlaces) |
| 2 | 524 | | placesPool.Release(pooledEvent); |
| 105 | 525 | | pooledPlaces.Clear(); |
| 105 | 526 | | } |
| | 527 | |
|
| | 528 | | private void ClearFullPlacesPool(){ |
| 208 | 529 | | foreach (var pooledEvent in pooledFullPlaces) |
| 2 | 530 | | fullPlacesPool.Release(pooledEvent); |
| 102 | 531 | | pooledFullPlaces.Clear(); |
| 102 | 532 | | } |
| | 533 | |
|
| | 534 | | private void ClearWorldsPool() |
| | 535 | | { |
| 214 | 536 | | foreach (var pooledWorld in pooledWorlds) |
| 2 | 537 | | worldsPool.Release(pooledWorld); |
| 105 | 538 | | pooledWorlds.Clear(); |
| 105 | 539 | | } |
| | 540 | |
|
| | 541 | | private void ClearFullWorldsPool(){ |
| 208 | 542 | | foreach (var pooledWorld in pooledFullWorlds) |
| 2 | 543 | | fullWorldsPool.Release(pooledWorld); |
| 102 | 544 | | pooledFullWorlds.Clear(); |
| 102 | 545 | | } |
| | 546 | | } |