| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Threading; |
| | 5 | | using Cysharp.Threading.Tasks; |
| | 6 | | using TMPro; |
| | 7 | | using UnityEngine; |
| | 8 | | using UnityEngine.UI; |
| | 9 | |
|
| | 10 | | public class HighlightsSubSectionComponentView : BaseComponentView, IHighlightsSubSectionComponentView |
| | 11 | | { |
| | 12 | | private const string TRENDING_PLACE_CARDS_POOL_NAME = "Highlights_TrendingPlaceCardsPool"; |
| | 13 | | private const int TRENDING_PLACE_CARDS_POOL_PREWARM = 10; |
| | 14 | | private const string TRENDING_EVENT_CARDS_POOL_NAME = "Highlights_TrendingEventCardsPool"; |
| | 15 | | private const int TRENDING_EVENT_CARDS_POOL_PREWARM = 10; |
| | 16 | | private const string FEATURED_PLACE_CARDS_POOL_NAME = "Highlights_FeaturedPlaceCardsPool"; |
| | 17 | | private const int FEATURED_PLACE_CARDS_POOL_PREWARM = 9; |
| | 18 | | private const string LIVE_EVENT_CARDS_POOL_NAME = "Highlights_LiveEventCardsPool"; |
| | 19 | | private const int LIVE_EVENT_CARDS_POOL_PREWARM = 3; |
| | 20 | |
|
| 67 | 21 | | private readonly Queue<Func<UniTask>> cardsVisualUpdateBuffer = new Queue<Func<UniTask>>(); |
| 67 | 22 | | private readonly Queue<Func<UniTask>> poolsPrewarmAsyncsBuffer = new Queue<Func<UniTask>>(); |
| 67 | 23 | | private readonly CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); |
| | 24 | |
|
| | 25 | | [Header("Assets References")] |
| | 26 | | [SerializeField] internal PlaceCardComponentView placeCardLongPrefab; |
| | 27 | | [SerializeField] internal EventCardComponentView eventCardLongPrefab; |
| | 28 | | [SerializeField] internal PlaceCardComponentView placeCardPrefab; |
| | 29 | | [SerializeField] internal PlaceCardComponentView placeCardModalPrefab; |
| | 30 | | [SerializeField] internal EventCardComponentView eventCardPrefab; |
| | 31 | | [SerializeField] internal EventCardComponentView eventCardModalPrefab; |
| | 32 | |
|
| | 33 | | [Header("Prefab References")] |
| | 34 | | [SerializeField] internal ScrollRect scrollView; |
| | 35 | | [SerializeField] internal CarouselComponentView trendingPlacesAndEvents; |
| | 36 | | [SerializeField] internal GameObject trendingPlacesAndEventsLoading; |
| | 37 | | [SerializeField] internal GridContainerComponentView featuredPlaces; |
| | 38 | | [SerializeField] internal GameObject featuredPlacesLoading; |
| | 39 | | [SerializeField] internal TMP_Text featuredPlacesNoDataText; |
| | 40 | | [SerializeField] internal GridContainerComponentView liveEvents; |
| | 41 | | [SerializeField] internal GameObject liveEventsLoading; |
| | 42 | | [SerializeField] internal TMP_Text liveEventsNoDataText; |
| | 43 | | [SerializeField] internal ButtonComponentView viewAllEventsButton; |
| | 44 | | [SerializeField] internal Color[] friendColors = null; |
| | 45 | |
|
| | 46 | | [SerializeField] private Canvas canvas; |
| | 47 | |
|
| | 48 | | internal PlaceCardComponentView placeModal; |
| | 49 | | internal EventCardComponentView eventModal; |
| | 50 | | internal Pool trendingPlaceCardsPool; |
| | 51 | | internal Pool trendingEventCardsPool; |
| | 52 | | internal Pool featuredPlaceCardsPool; |
| | 53 | | internal Pool liveEventCardsPool; |
| | 54 | |
|
| | 55 | | private bool isUpdatingCardsVisual; |
| | 56 | |
|
| 0 | 57 | | public Color[] currentFriendColors => friendColors; |
| | 58 | |
|
| | 59 | | public event Action OnReady; |
| | 60 | | public event Action<PlaceCardComponentModel> OnPlaceInfoClicked; |
| | 61 | | public event Action<EventCardComponentModel> OnEventInfoClicked; |
| | 62 | | public event Action<HotScenesController.HotSceneInfo> OnPlaceJumpInClicked; |
| | 63 | | public event Action<EventFromAPIModel> OnEventJumpInClicked; |
| | 64 | | public event Action<string> OnEventSubscribeEventClicked; |
| | 65 | | public event Action<string> OnEventUnsubscribeEventClicked; |
| | 66 | | public event Action OnViewAllEventsClicked; |
| | 67 | | public event Action<FriendsHandler> OnFriendHandlerAdded; |
| | 68 | | public event Action OnHighlightsSubSectionEnable; |
| | 69 | |
|
| | 70 | | public override void Start() |
| | 71 | | { |
| 61 | 72 | | placeModal = ExplorePlacesUtils.ConfigurePlaceCardModal(placeCardModalPrefab); |
| 61 | 73 | | eventModal = ExploreEventsUtils.ConfigureEventCardModal(eventCardModalPrefab); |
| | 74 | |
|
| 61 | 75 | | trendingPlacesAndEvents.RemoveItems(); |
| 61 | 76 | | featuredPlaces.RemoveItems(); |
| 61 | 77 | | liveEvents.RemoveItems(); |
| | 78 | |
|
| 61 | 79 | | viewAllEventsButton.onClick.AddListener(() => OnViewAllEventsClicked?.Invoke()); |
| | 80 | |
|
| 61 | 81 | | OnReady?.Invoke(); |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | public override void OnEnable() |
| | 85 | | { |
| 120 | 86 | | OnHighlightsSubSectionEnable?.Invoke(); |
| 0 | 87 | | } |
| | 88 | |
|
| | 89 | | public override void Dispose() |
| | 90 | | { |
| 139 | 91 | | base.Dispose(); |
| | 92 | |
|
| 139 | 93 | | cancellationTokenSource.Cancel(); |
| | 94 | |
|
| 139 | 95 | | trendingPlacesAndEvents.Dispose(); |
| 139 | 96 | | featuredPlaces.Dispose(); |
| 139 | 97 | | liveEvents.Dispose(); |
| | 98 | |
|
| 139 | 99 | | if (placeModal != null) |
| | 100 | | { |
| 88 | 101 | | placeModal.Dispose(); |
| 88 | 102 | | Destroy(placeModal.gameObject); |
| | 103 | | } |
| | 104 | |
|
| 139 | 105 | | if (eventModal != null) |
| | 106 | | { |
| 88 | 107 | | eventModal.Dispose(); |
| 88 | 108 | | Destroy(eventModal.gameObject); |
| | 109 | | } |
| | 110 | |
|
| 139 | 111 | | viewAllEventsButton.onClick.RemoveAllListeners(); |
| 139 | 112 | | } |
| | 113 | |
|
| | 114 | | public void SetActive(bool isActive) |
| | 115 | | { |
| 108 | 116 | | canvas.enabled = isActive; |
| | 117 | |
|
| 108 | 118 | | if (isActive) |
| 56 | 119 | | OnEnable(); |
| | 120 | | else |
| 52 | 121 | | OnDisable(); |
| 52 | 122 | | } |
| | 123 | |
|
| | 124 | | public void ConfigurePools() |
| | 125 | | { |
| 19 | 126 | | ExplorePlacesUtils.ConfigurePlaceCardsPool(out trendingPlaceCardsPool, TRENDING_PLACE_CARDS_POOL_NAME, placeCard |
| 19 | 127 | | ExploreEventsUtils.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCard |
| 19 | 128 | | ExplorePlacesUtils.ConfigurePlaceCardsPool(out featuredPlaceCardsPool, FEATURED_PLACE_CARDS_POOL_NAME, placeCard |
| 19 | 129 | | ExploreEventsUtils.ConfigureEventCardsPool(out liveEventCardsPool, LIVE_EVENT_CARDS_POOL_NAME, eventCardPrefab, |
| 19 | 130 | | } |
| | 131 | |
|
| | 132 | | public override void RefreshControl() |
| | 133 | | { |
| 0 | 134 | | trendingPlacesAndEvents.RefreshControl(); |
| 0 | 135 | | featuredPlaces.RefreshControl(); |
| 0 | 136 | | liveEvents.RefreshControl(); |
| 0 | 137 | | } |
| | 138 | |
|
| | 139 | | public void SetTrendingPlacesAndEventsAsLoading(bool isVisible) |
| | 140 | | { |
| 3 | 141 | | SetTrendingPlacesAndEventsActive(!isVisible); |
| 3 | 142 | | trendingPlacesAndEventsLoading.SetActive(isVisible); |
| 3 | 143 | | } |
| | 144 | |
|
| | 145 | | internal void SetTrendingPlacesAndEventsActive(bool isActive) => |
| 5 | 146 | | trendingPlacesAndEvents.gameObject.SetActive(isActive); |
| | 147 | |
|
| | 148 | | public void SetFeaturedPlacesAsLoading(bool isVisible) |
| | 149 | | { |
| 6 | 150 | | featuredPlaces.gameObject.SetActive(!isVisible); |
| 6 | 151 | | featuredPlacesLoading.SetActive(isVisible); |
| | 152 | |
|
| 6 | 153 | | if (isVisible) |
| 1 | 154 | | featuredPlacesNoDataText.gameObject.SetActive(false); |
| 6 | 155 | | } |
| | 156 | |
|
| | 157 | | public void SetLiveAsLoading(bool isVisible) |
| | 158 | | { |
| 6 | 159 | | liveEvents.gameObject.SetActive(!isVisible); |
| 6 | 160 | | liveEventsLoading.SetActive(isVisible); |
| 6 | 161 | | viewAllEventsButton.gameObject.SetActive(!isVisible); |
| | 162 | |
|
| 6 | 163 | | if (isVisible) |
| 1 | 164 | | liveEventsNoDataText.gameObject.SetActive(false); |
| 6 | 165 | | } |
| | 166 | |
|
| | 167 | | public void ShowPlaceModal(PlaceCardComponentModel placeInfo) |
| | 168 | | { |
| 1 | 169 | | placeModal.Show(); |
| 1 | 170 | | ExplorePlacesUtils.ConfigurePlaceCard(placeModal, placeInfo, OnPlaceInfoClicked, OnPlaceJumpInClicked); |
| 1 | 171 | | } |
| | 172 | |
|
| | 173 | | public void HidePlaceModal() |
| | 174 | | { |
| 1 | 175 | | if (placeModal != null) |
| 1 | 176 | | placeModal.Hide(); |
| 1 | 177 | | } |
| | 178 | |
|
| | 179 | | public void ShowEventModal(EventCardComponentModel eventInfo) |
| | 180 | | { |
| 1 | 181 | | eventModal.Show(); |
| 1 | 182 | | ExploreEventsUtils.ConfigureEventCard(eventModal, eventInfo, OnEventInfoClicked, OnEventJumpInClicked, OnEventSu |
| 1 | 183 | | } |
| | 184 | |
|
| | 185 | | public void HideEventModal() |
| | 186 | | { |
| 1 | 187 | | if (eventModal != null) |
| 1 | 188 | | eventModal.Hide(); |
| 1 | 189 | | } |
| | 190 | |
|
| | 191 | | public void RestartScrollViewPosition() => |
| 0 | 192 | | scrollView.verticalNormalizedPosition = 1; |
| | 193 | |
|
| | 194 | | public void SetFeaturedPlaces(List<PlaceCardComponentModel> places) |
| | 195 | | { |
| 4 | 196 | | SetFeaturedPlacesAsLoading(false); |
| 4 | 197 | | featuredPlacesNoDataText.gameObject.SetActive(places.Count == 0); |
| | 198 | |
|
| 4 | 199 | | featuredPlaceCardsPool.ReleaseAll(); |
| | 200 | |
|
| 4 | 201 | | featuredPlaces.ExtractItems(); |
| 4 | 202 | | featuredPlaces.RemoveItems(); |
| | 203 | |
|
| 8 | 204 | | cardsVisualUpdateBuffer.Enqueue(() => SetPlacesAsync(places, cancellationTokenSource.Token)); |
| 4 | 205 | | UpdateCardsVisual(); |
| 4 | 206 | | } |
| | 207 | |
|
| | 208 | | private async UniTask SetPlacesAsync(List<PlaceCardComponentModel> places, CancellationToken cancellationToken) |
| | 209 | | { |
| 29 | 210 | | foreach (PlaceCardComponentModel place in places) |
| | 211 | | { |
| 12 | 212 | | featuredPlaces.AddItem( |
| | 213 | | ExplorePlacesUtils.InstantiateConfiguredPlaceCard(place, featuredPlaceCardsPool, |
| | 214 | | OnFriendHandlerAdded, OnPlaceInfoClicked, OnPlaceJumpInClicked)); |
| | 215 | |
|
| 36 | 216 | | await UniTask.NextFrame(cancellationToken); |
| | 217 | | } |
| | 218 | |
|
| 1 | 219 | | featuredPlaces.SetItemSizeForModel(); |
| 2 | 220 | | poolsPrewarmAsyncsBuffer.Enqueue(() => featuredPlaceCardsPool.PrewarmAsync(places.Count, cancellationToken)); |
| 1 | 221 | | } |
| | 222 | |
|
| | 223 | | public void SetLiveEvents(List<EventCardComponentModel> events) |
| | 224 | | { |
| 4 | 225 | | SetLiveAsLoading(false); |
| 4 | 226 | | liveEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| | 227 | |
|
| 4 | 228 | | liveEventCardsPool.ReleaseAll(); |
| | 229 | |
|
| 4 | 230 | | liveEvents.ExtractItems(); |
| 4 | 231 | | liveEvents.RemoveItems(); |
| | 232 | |
|
| 8 | 233 | | cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, liveEvents, liveEventCardsPool, cancellationTokenSo |
| 4 | 234 | | UpdateCardsVisual(); |
| 4 | 235 | | } |
| | 236 | |
|
| | 237 | | private async UniTask SetEventsAsync(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Po |
| | 238 | | { |
| 29 | 239 | | foreach (EventCardComponentModel eventInfo in events) |
| | 240 | | { |
| 12 | 241 | | eventsGrid.AddItem( |
| | 242 | | ExploreEventsUtils.InstantiateConfiguredEventCard(eventInfo, pool, |
| | 243 | | OnEventInfoClicked, OnEventJumpInClicked, OnEventSubscribeEventClicked, OnEventUnsubscribeEventClick |
| | 244 | |
|
| 36 | 245 | | await UniTask.NextFrame(cancellationToken); |
| | 246 | | } |
| | 247 | |
|
| 1 | 248 | | eventsGrid.SetItemSizeForModel(); |
| | 249 | |
|
| 2 | 250 | | poolsPrewarmAsyncsBuffer.Enqueue(() => pool.PrewarmAsync(events.Count, cancellationToken)); |
| 1 | 251 | | } |
| | 252 | |
|
| | 253 | | public void SetTrendingPlacesAndEvents(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events) |
| | 254 | | { |
| 1 | 255 | | SetTrendingPlacesAndEventsAsLoading(false); |
| | 256 | |
|
| 1 | 257 | | trendingPlaceCardsPool.ReleaseAll(); |
| 1 | 258 | | trendingEventCardsPool.ReleaseAll(); |
| | 259 | |
|
| 1 | 260 | | trendingPlacesAndEvents.ExtractItems(); |
| 1 | 261 | | trendingPlacesAndEvents.RemoveItems(); |
| | 262 | |
|
| 2 | 263 | | cardsVisualUpdateBuffer.Enqueue(() => SetTrendingsAsync(places, events, cancellationTokenSource.Token)); |
| 1 | 264 | | UpdateCardsVisual(); |
| 1 | 265 | | } |
| | 266 | |
|
| | 267 | | private async UniTask SetTrendingsAsync(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events, |
| | 268 | | { |
| 1 | 269 | | int eventId = 0; |
| 1 | 270 | | int placeId = 0; |
| | 271 | |
|
| 8 | 272 | | for (int i = 0 ; i < HighlightsSubSectionComponentController.DEFAULT_NUMBER_OF_TRENDING_PLACES; i++) |
| | 273 | | { |
| 4 | 274 | | if (i % 2 == 0 && eventId < events.Count) |
| | 275 | | { |
| 2 | 276 | | trendingPlacesAndEvents.AddItem(ExploreEventsUtils.InstantiateConfiguredEventCard(events[eventId], trend |
| | 277 | | OnEventInfoClicked, OnEventJumpInClicked, OnEventSubscribeEventClicked, OnEventUnsubscribeEventClick |
| 2 | 278 | | eventId++; |
| 2 | 279 | | } |
| 2 | 280 | | else if (placeId < places.Count) |
| | 281 | | { |
| 2 | 282 | | trendingPlacesAndEvents.AddItem(ExplorePlacesUtils.InstantiateConfiguredPlaceCard(places[placeId], trend |
| | 283 | | OnFriendHandlerAdded, OnPlaceInfoClicked, OnPlaceJumpInClicked)); |
| 2 | 284 | | placeId++; |
| | 285 | | } |
| | 286 | |
|
| 12 | 287 | | await UniTask.NextFrame(cancellationToken); |
| | 288 | | } |
| | 289 | |
|
| 0 | 290 | | trendingPlacesAndEvents.SetManualControlsActive(); |
| 0 | 291 | | trendingPlacesAndEvents.GenerateDotsSelector(); |
| | 292 | |
|
| 0 | 293 | | poolsPrewarmAsyncsBuffer.Enqueue(() => trendingPlaceCardsPool.PrewarmAsync(HighlightsSubSectionComponentControll |
| 0 | 294 | | } |
| | 295 | |
|
| | 296 | | private void UpdateCardsVisual() |
| | 297 | | { |
| 9 | 298 | | if (!isUpdatingCardsVisual) |
| 9 | 299 | | UpdateCardsVisualProcess().Forget(); |
| | 300 | |
|
| | 301 | | async UniTask UpdateCardsVisualProcess() |
| | 302 | | { |
| 9 | 303 | | isUpdatingCardsVisual = true; |
| | 304 | |
|
| 11 | 305 | | while (cardsVisualUpdateBuffer.Count > 0) |
| 23 | 306 | | await cardsVisualUpdateBuffer.Dequeue().Invoke(); |
| | 307 | |
|
| 4 | 308 | | while (poolsPrewarmAsyncsBuffer.Count > 0) |
| 2 | 309 | | await poolsPrewarmAsyncsBuffer.Dequeue().Invoke(); |
| | 310 | |
|
| 2 | 311 | | isUpdatingCardsVisual = false; |
| 2 | 312 | | } |
| 9 | 313 | | } |
| | 314 | | } |