| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using TMPro; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.UI; |
| | 7 | |
|
| | 8 | | public interface IHighlightsSubSectionComponentView |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// It will be triggered when all the UI components have been fully initialized. |
| | 12 | | /// </summary> |
| | 13 | | event Action OnReady; |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// It will be triggered when the place info button is clicked. |
| | 17 | | /// </summary> |
| | 18 | | event Action<PlaceCardComponentModel> OnPlaceInfoClicked; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// It will be triggered when the event info button is clicked. |
| | 22 | | /// </summary> |
| | 23 | | event Action<EventCardComponentModel> OnEventInfoClicked; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// It will be triggered when the place JumpIn button is clicked. |
| | 27 | | /// </summary> |
| | 28 | | event Action<HotScenesController.HotSceneInfo> OnPlaceJumpInClicked; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// It will be triggered when the event JumpIn button is clicked. |
| | 32 | | /// </summary> |
| | 33 | | event Action<EventFromAPIModel> OnEventJumpInClicked; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// It will be triggered when the subscribe event button is clicked. |
| | 37 | | /// </summary> |
| | 38 | | event Action<string> OnEventSubscribeEventClicked; |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// It will be triggered when the unsubscribe event button is clicked. |
| | 42 | | /// </summary> |
| | 43 | | event Action<string> OnEventUnsubscribeEventClicked; |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// It will be triggered when the view all events button is clicked. |
| | 47 | | /// </summary> |
| | 48 | | event Action OnViewAllEventsClicked; |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// It will be triggered when a new friend handler is added by a place card. |
| | 52 | | /// </summary> |
| | 53 | | event Action<FriendsHandler> OnFriendHandlerAdded; |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// It will be triggered each time the view is enabled. |
| | 57 | | /// </summary> |
| | 58 | | event Action OnHighlightsSubSectionEnable; |
| | 59 | |
|
| | 60 | | /// <summary> |
| | 61 | | /// Colors used for the background of the friends heads. |
| | 62 | | /// </summary> |
| | 63 | | Color[] currentFriendColors { get; } |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// Set the trending places/events component with a list of places and events. |
| | 67 | | /// </summary> |
| | 68 | | /// <param name="places">List of places (model) to be loaded.</param> |
| | 69 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 70 | | void SetTrendingPlacesAndEvents(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events); |
| | 71 | |
|
| | 72 | | /// <summary> |
| | 73 | | /// Set the trending places and events component in loading mode. |
| | 74 | | /// </summary> |
| | 75 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 76 | | void SetTrendingPlacesAndEventsAsLoading(bool isVisible); |
| | 77 | |
|
| | 78 | | /// <summary> |
| | 79 | | /// Activates/deactivates the trending places and events component. |
| | 80 | | /// </summary> |
| | 81 | | /// <param name="isActive">True for activating.</param> |
| | 82 | | void SetTrendingPlacesAndEventsActive(bool isActive); |
| | 83 | |
|
| | 84 | | /// <summary> |
| | 85 | | /// Set the featured places component with a list of places. |
| | 86 | | /// </summary> |
| | 87 | | /// <param name="places">List of places (model) to be loaded.</param> |
| | 88 | | void SetFeaturedPlaces(List<PlaceCardComponentModel> places); |
| | 89 | |
|
| | 90 | | /// <summary> |
| | 91 | | /// Set the featured places component in loading mode. |
| | 92 | | /// </summary> |
| | 93 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 94 | | void SetFeaturedPlacesAsLoading(bool isVisible); |
| | 95 | |
|
| | 96 | | /// <summary> |
| | 97 | | /// Set the live events component with a list of places. |
| | 98 | | /// </summary> |
| | 99 | | /// <param name="events">List of events (model) to be loaded.</param> |
| | 100 | | void SetLiveEvents(List<EventCardComponentModel> events); |
| | 101 | |
|
| | 102 | | /// <summary> |
| | 103 | | /// Set the live events component in loading mode. |
| | 104 | | /// </summary> |
| | 105 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 106 | | void SetLiveAsLoading(bool isVisible); |
| | 107 | |
|
| | 108 | | /// <summary> |
| | 109 | | /// Shows the Place Card modal with the provided information. |
| | 110 | | /// </summary> |
| | 111 | | /// <param name="placeInfo">Place (model) to be loaded in the card.</param> |
| | 112 | | void ShowPlaceModal(PlaceCardComponentModel placeInfo); |
| | 113 | |
|
| | 114 | | /// <summary> |
| | 115 | | /// Hides the Place Card modal. |
| | 116 | | /// </summary> |
| | 117 | | void HidePlaceModal(); |
| | 118 | |
|
| | 119 | | /// <summary> |
| | 120 | | /// Shows the Event Card modal with the provided information. |
| | 121 | | /// </summary> |
| | 122 | | /// <param name="eventInfo">Event (model) to be loaded in the card.</param> |
| | 123 | | void ShowEventModal(EventCardComponentModel eventInfo); |
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Hides the Event Card modal. |
| | 127 | | /// </summary> |
| | 128 | | void HideEventModal(); |
| | 129 | |
|
| | 130 | | /// <summary> |
| | 131 | | /// Set the current scroll view position to 1. |
| | 132 | | /// </summary> |
| | 133 | | void RestartScrollViewPosition(); |
| | 134 | |
|
| | 135 | | /// <summary> |
| | 136 | | /// Configure the needed pools for the places and events instantiation. |
| | 137 | | /// </summary> |
| | 138 | | void ConfigurePools(); |
| | 139 | | } |
| | 140 | |
|
| | 141 | | public class HighlightsSubSectionComponentView : BaseComponentView, IHighlightsSubSectionComponentView |
| | 142 | | { |
| | 143 | | internal const string TRENDING_PLACE_CARDS_POOL_NAME = "Highlights_TrendingPlaceCardsPool"; |
| | 144 | | internal const int TRENDING_PLACE_CARDS_POOL_PREWARM = 10; |
| | 145 | | internal const string TRENDING_EVENT_CARDS_POOL_NAME = "Highlights_TrendingEventCardsPool"; |
| | 146 | | internal const int TRENDING_EVENT_CARDS_POOL_PREWARM = 10; |
| | 147 | | internal const string FEATURED_PLACE_CARDS_POOL_NAME = "Highlights_FeaturedPlaceCardsPool"; |
| | 148 | | internal const int FEATURED_PLACE_CARDS_POOL_PREWARM = 9; |
| | 149 | | internal const string LIVE_EVENT_CARDS_POOL_NAME = "Highlights_LiveEventCardsPool"; |
| | 150 | | internal const int LIVE_EVENT_CARDS_POOL_PREWARM = 3; |
| | 151 | |
|
| | 152 | | [Header("Assets References")] |
| | 153 | | [SerializeField] internal PlaceCardComponentView placeCardLongPrefab; |
| | 154 | | [SerializeField] internal EventCardComponentView eventCardLongPrefab; |
| | 155 | | [SerializeField] internal PlaceCardComponentView placeCardPrefab; |
| | 156 | | [SerializeField] internal PlaceCardComponentView placeCardModalPrefab; |
| | 157 | | [SerializeField] internal EventCardComponentView eventCardPrefab; |
| | 158 | | [SerializeField] internal EventCardComponentView eventCardModalPrefab; |
| | 159 | |
|
| | 160 | | [Header("Prefab References")] |
| | 161 | | [SerializeField] internal ScrollRect scrollView; |
| | 162 | | [SerializeField] internal CarouselComponentView trendingPlacesAndEvents; |
| | 163 | | [SerializeField] internal GameObject trendingPlacesAndEventsLoading; |
| | 164 | | [SerializeField] internal GridContainerComponentView featuredPlaces; |
| | 165 | | [SerializeField] internal GameObject featuredPlacesLoading; |
| | 166 | | [SerializeField] internal TMP_Text featuredPlacesNoDataText; |
| | 167 | | [SerializeField] internal GridContainerComponentView liveEvents; |
| | 168 | | [SerializeField] internal GameObject liveEventsLoading; |
| | 169 | | [SerializeField] internal TMP_Text liveEventsNoDataText; |
| | 170 | | [SerializeField] internal ButtonComponentView viewAllEventsButton; |
| | 171 | | [SerializeField] internal Color[] friendColors = null; |
| | 172 | |
|
| | 173 | | public event Action OnReady; |
| | 174 | | public event Action<PlaceCardComponentModel> OnPlaceInfoClicked; |
| | 175 | | public event Action<EventCardComponentModel> OnEventInfoClicked; |
| | 176 | | public event Action<HotScenesController.HotSceneInfo> OnPlaceJumpInClicked; |
| | 177 | | public event Action<EventFromAPIModel> OnEventJumpInClicked; |
| | 178 | | public event Action<string> OnEventSubscribeEventClicked; |
| | 179 | | public event Action<string> OnEventUnsubscribeEventClicked; |
| | 180 | | public event Action OnViewAllEventsClicked; |
| | 181 | | public event Action<FriendsHandler> OnFriendHandlerAdded; |
| | 182 | | public event Action OnHighlightsSubSectionEnable; |
| | 183 | |
|
| | 184 | | internal PlaceCardComponentView placeModal; |
| | 185 | | internal EventCardComponentView eventModal; |
| | 186 | | internal Pool trendingPlaceCardsPool; |
| | 187 | | internal Pool trendingEventCardsPool; |
| | 188 | | internal Pool featuredPlaceCardsPool; |
| | 189 | | internal Pool liveEventCardsPool; |
| | 190 | |
|
| 0 | 191 | | public Color[] currentFriendColors => friendColors; |
| | 192 | |
|
| 29 | 193 | | public override void OnEnable() { OnHighlightsSubSectionEnable?.Invoke(); } |
| | 194 | |
|
| | 195 | | public void ConfigurePools() |
| | 196 | | { |
| 13 | 197 | | ExplorePlacesUtils.ConfigurePlaceCardsPool(out trendingPlaceCardsPool, TRENDING_PLACE_CARDS_POOL_NAME, placeCard |
| 13 | 198 | | ExploreEventsUtils.ConfigureEventCardsPool(out trendingEventCardsPool, TRENDING_EVENT_CARDS_POOL_NAME, eventCard |
| 13 | 199 | | ExplorePlacesUtils.ConfigurePlaceCardsPool(out featuredPlaceCardsPool, FEATURED_PLACE_CARDS_POOL_NAME, placeCard |
| 13 | 200 | | ExploreEventsUtils.ConfigureEventCardsPool(out liveEventCardsPool, LIVE_EVENT_CARDS_POOL_NAME, eventCardPrefab, |
| 13 | 201 | | } |
| | 202 | |
|
| | 203 | | public override void Start() |
| | 204 | | { |
| 13 | 205 | | placeModal = ExplorePlacesUtils.ConfigurePlaceCardModal(placeCardModalPrefab); |
| 13 | 206 | | eventModal = ExploreEventsUtils.ConfigureEventCardModal(eventCardModalPrefab); |
| | 207 | |
|
| 13 | 208 | | trendingPlacesAndEvents.RemoveItems(); |
| 13 | 209 | | featuredPlaces.RemoveItems(); |
| 13 | 210 | | liveEvents.RemoveItems(); |
| | 211 | |
|
| 13 | 212 | | viewAllEventsButton.onClick.AddListener(() => OnViewAllEventsClicked?.Invoke()); |
| | 213 | |
|
| 13 | 214 | | OnReady?.Invoke(); |
| 0 | 215 | | } |
| | 216 | |
|
| | 217 | | public override void RefreshControl() |
| | 218 | | { |
| 0 | 219 | | trendingPlacesAndEvents.RefreshControl(); |
| 0 | 220 | | featuredPlaces.RefreshControl(); |
| 0 | 221 | | liveEvents.RefreshControl(); |
| 0 | 222 | | } |
| | 223 | |
|
| | 224 | | public override void Dispose() |
| | 225 | | { |
| 61 | 226 | | base.Dispose(); |
| | 227 | |
|
| 61 | 228 | | trendingPlacesAndEvents.Dispose(); |
| 61 | 229 | | featuredPlaces.Dispose(); |
| 61 | 230 | | liveEvents.Dispose(); |
| | 231 | |
|
| 61 | 232 | | if (placeModal != null) |
| | 233 | | { |
| 17 | 234 | | placeModal.Dispose(); |
| 17 | 235 | | Destroy(placeModal.gameObject); |
| | 236 | | } |
| | 237 | |
|
| 61 | 238 | | if (eventModal != null) |
| | 239 | | { |
| 17 | 240 | | eventModal.Dispose(); |
| 17 | 241 | | Destroy(eventModal.gameObject); |
| | 242 | | } |
| | 243 | |
|
| 61 | 244 | | viewAllEventsButton.onClick.RemoveAllListeners(); |
| 61 | 245 | | } |
| | 246 | |
|
| | 247 | | public void SetTrendingPlacesAndEvents(List<PlaceCardComponentModel> places, List<EventCardComponentModel> events) |
| | 248 | | { |
| 1 | 249 | | List<BaseComponentView> placesAndEventsToSet = new List<BaseComponentView>(); |
| | 250 | |
|
| 1 | 251 | | trendingPlacesAndEvents.ExtractItems(); |
| 1 | 252 | | trendingPlaceCardsPool.ReleaseAll(); |
| 1 | 253 | | trendingEventCardsPool.ReleaseAll(); |
| | 254 | |
|
| 1 | 255 | | List<BaseComponentView> placeComponentsToAdd = ExplorePlacesUtils.InstantiateAndConfigurePlaceCards( |
| | 256 | | places, |
| | 257 | | trendingPlaceCardsPool, |
| | 258 | | OnFriendHandlerAdded, |
| | 259 | | OnPlaceInfoClicked, |
| | 260 | | OnPlaceJumpInClicked); |
| | 261 | |
|
| 1 | 262 | | List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards( |
| | 263 | | events, |
| | 264 | | trendingEventCardsPool, |
| | 265 | | OnEventInfoClicked, |
| | 266 | | OnEventJumpInClicked, |
| | 267 | | OnEventSubscribeEventClicked, |
| | 268 | | OnEventUnsubscribeEventClicked); |
| | 269 | |
|
| | 270 | |
|
| 22 | 271 | | for (int i = 0; i < HighlightsSubSectionComponentController.DEFAULT_NUMBER_OF_TRENDING_PLACES; i++) |
| | 272 | | { |
| 10 | 273 | | if (eventComponentsToAdd.Count - 1 >= i) |
| 2 | 274 | | placesAndEventsToSet.Add(eventComponentsToAdd[i]); |
| | 275 | |
|
| 10 | 276 | | if (placeComponentsToAdd.Count - 1 >= i) |
| 2 | 277 | | placesAndEventsToSet.Add(placeComponentsToAdd[i]); |
| | 278 | | } |
| | 279 | |
|
| 1 | 280 | | trendingPlacesAndEvents.SetItems(placesAndEventsToSet); |
| 1 | 281 | | SetTrendingPlacesAndEventsActive(placesAndEventsToSet.Count > 0); |
| 1 | 282 | | } |
| | 283 | |
|
| | 284 | | public void SetTrendingPlacesAndEventsAsLoading(bool isVisible) |
| | 285 | | { |
| 2 | 286 | | SetTrendingPlacesAndEventsActive(!isVisible); |
| 2 | 287 | | trendingPlacesAndEventsLoading.SetActive(isVisible); |
| 2 | 288 | | } |
| | 289 | |
|
| 10 | 290 | | public void SetTrendingPlacesAndEventsActive(bool isActive) { trendingPlacesAndEvents.gameObject.SetActive(isActive) |
| | 291 | |
|
| | 292 | | public void SetFeaturedPlaces(List<PlaceCardComponentModel> places) |
| | 293 | | { |
| 1 | 294 | | featuredPlaces.ExtractItems(); |
| 1 | 295 | | featuredPlaceCardsPool.ReleaseAll(); |
| | 296 | |
|
| 1 | 297 | | List<BaseComponentView> placeComponentsToAdd = ExplorePlacesUtils.InstantiateAndConfigurePlaceCards( |
| | 298 | | places, |
| | 299 | | featuredPlaceCardsPool, |
| | 300 | | OnFriendHandlerAdded, |
| | 301 | | OnPlaceInfoClicked, |
| | 302 | | OnPlaceJumpInClicked); |
| | 303 | |
|
| 1 | 304 | | featuredPlaces.SetItems(placeComponentsToAdd); |
| 1 | 305 | | featuredPlacesNoDataText.gameObject.SetActive(places.Count == 0); |
| 1 | 306 | | } |
| | 307 | |
|
| | 308 | | public void SetFeaturedPlacesAsLoading(bool isVisible) |
| | 309 | | { |
| 2 | 310 | | featuredPlaces.gameObject.SetActive(!isVisible); |
| 2 | 311 | | featuredPlacesLoading.SetActive(isVisible); |
| | 312 | |
|
| 2 | 313 | | if (isVisible) |
| 1 | 314 | | featuredPlacesNoDataText.gameObject.SetActive(false); |
| 2 | 315 | | } |
| | 316 | |
|
| | 317 | | public void SetLiveEvents(List<EventCardComponentModel> events) |
| | 318 | | { |
| 1 | 319 | | liveEvents.ExtractItems(); |
| 1 | 320 | | liveEventCardsPool.ReleaseAll(); |
| | 321 | |
|
| 1 | 322 | | List<BaseComponentView> eventComponentsToAdd = ExploreEventsUtils.InstantiateAndConfigureEventCards( |
| | 323 | | events, |
| | 324 | | liveEventCardsPool, |
| | 325 | | OnEventInfoClicked, |
| | 326 | | OnEventJumpInClicked, |
| | 327 | | OnEventSubscribeEventClicked, |
| | 328 | | OnEventUnsubscribeEventClicked); |
| | 329 | |
|
| 1 | 330 | | liveEvents.SetItems(eventComponentsToAdd); |
| 1 | 331 | | liveEventsNoDataText.gameObject.SetActive(events.Count == 0); |
| 1 | 332 | | } |
| | 333 | |
|
| | 334 | | public void SetLiveAsLoading(bool isVisible) |
| | 335 | | { |
| 2 | 336 | | liveEvents.gameObject.SetActive(!isVisible); |
| 2 | 337 | | liveEventsLoading.SetActive(isVisible); |
| 2 | 338 | | viewAllEventsButton.gameObject.SetActive(!isVisible); |
| | 339 | |
|
| 2 | 340 | | if (isVisible) |
| 1 | 341 | | liveEventsNoDataText.gameObject.SetActive(false); |
| 2 | 342 | | } |
| | 343 | |
|
| | 344 | | public void ShowPlaceModal(PlaceCardComponentModel placeInfo) |
| | 345 | | { |
| 1 | 346 | | placeModal.Show(); |
| 1 | 347 | | ExplorePlacesUtils.ConfigurePlaceCard(placeModal, placeInfo, OnPlaceInfoClicked, OnPlaceJumpInClicked); |
| 1 | 348 | | } |
| | 349 | |
|
| 2 | 350 | | public void HidePlaceModal() { placeModal.Hide(); } |
| | 351 | |
|
| | 352 | | public void ShowEventModal(EventCardComponentModel eventInfo) |
| | 353 | | { |
| 1 | 354 | | eventModal.Show(); |
| 1 | 355 | | ExploreEventsUtils.ConfigureEventCard(eventModal, eventInfo, OnEventInfoClicked, OnEventJumpInClicked, OnEventSu |
| 1 | 356 | | } |
| | 357 | |
|
| 2 | 358 | | public void HideEventModal() { eventModal.Hide(); } |
| | 359 | |
|
| 0 | 360 | | public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; } |
| | 361 | | } |