| | 1 | | using DCL; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Threading; |
| | 5 | | using Cysharp.Threading.Tasks; |
| | 6 | | using DCL.Tasks; |
| | 7 | | using UIComponents.Scripts.Components.RangeSlider; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.EventSystems; |
| | 10 | | using UnityEngine.UI; |
| | 11 | |
|
| | 12 | | public class EventsSubSectionComponentView : BaseComponentView, IEventsSubSectionComponentView |
| | 13 | | { |
| | 14 | | internal const string FEATURED_EVENT_CARDS_POOL_NAME = "Events_FeaturedEventCardsPool"; |
| | 15 | | private const int FEATURED_EVENT_CARDS_POOL_PREWARM = 10; |
| | 16 | | private const string EVENT_CARDS_POOL_NAME = "Events_EventCardsPool"; |
| | 17 | | private const int EVENT_CARDS_POOL_PREWARM = 9; |
| | 18 | | private const string ALL_FILTER_ID = "all"; |
| | 19 | | private const string ALL_FILTER_TEXT = "All"; |
| | 20 | | private const string ONE_TIME_EVENT_FREQUENCY_FILTER_ID = "one_time_event"; |
| | 21 | | private const string ONE_TIME_EVENT_FREQUENCY_FILTER_TEXT = "One time event"; |
| | 22 | | private const string RECURRING_EVENT_FREQUENCY_FILTER_ID = "recurring_event"; |
| | 23 | | private const string RECURRING_EVENT_FREQUENCY_FILTER_TEXT = "Recurring event"; |
| | 24 | | private const float TIME_MIN_VALUE = 0; |
| | 25 | | private const float TIME_MAX_VALUE = 48; |
| | 26 | |
|
| 54 | 27 | | private readonly Queue<Func<UniTask>> cardsVisualUpdateBuffer = new (); |
| 54 | 28 | | private readonly Queue<Func<UniTask>> poolsPrewarmAsyncsBuffer = new (); |
| | 29 | | private CancellationTokenSource cancellationTokenSource; |
| | 30 | | private CancellationTokenSource featuredEventsCancellationTokenSource; |
| | 31 | |
|
| | 32 | | [Header("Assets References")] |
| | 33 | | [SerializeField] internal EventCardComponentView eventCardPrefab; |
| | 34 | | [SerializeField] internal EventCardComponentView eventCardLongPrefab; |
| | 35 | | [SerializeField] internal EventCardComponentView eventCardModalPrefab; |
| | 36 | |
|
| | 37 | | [Header("Prefab References")] |
| | 38 | | [SerializeField] internal ScrollRect scrollView; |
| | 39 | | [SerializeField] internal CarouselComponentView featuredEvents; |
| | 40 | | [SerializeField] internal GameObject featuredEventsLoading; |
| | 41 | | [SerializeField] internal GridContainerComponentView eventsGrid; |
| | 42 | | [SerializeField] internal GameObject eventsLoading; |
| | 43 | | [SerializeField] internal GameObject eventsNoDataContainer; |
| | 44 | | [SerializeField] internal GameObject showMoreEventsButtonContainer; |
| | 45 | | [SerializeField] internal ButtonComponentView showMoreEventsButton; |
| | 46 | | [SerializeField] internal GameObject guestGoingToPanel; |
| | 47 | | [SerializeField] internal ButtonComponentView connectWalletGuest; |
| | 48 | |
|
| | 49 | | [SerializeField] internal Button featuredButton; |
| | 50 | | [SerializeField] internal GameObject featuredDeselected; |
| | 51 | | [SerializeField] internal Image featuredDeselectedImage; |
| | 52 | | [SerializeField] internal GameObject featuredSelected; |
| | 53 | | [SerializeField] internal Image featuredSelectedImage; |
| | 54 | | [SerializeField] internal Button trendingButton; |
| | 55 | | [SerializeField] internal GameObject trendingDeselected; |
| | 56 | | [SerializeField] internal Image trendingDeselectedImage; |
| | 57 | | [SerializeField] internal GameObject trendingSelected; |
| | 58 | | [SerializeField] internal Image trendingSelectedImage; |
| | 59 | | [SerializeField] internal Button wantToGoButton; |
| | 60 | | [SerializeField] internal GameObject wantToGoDeselected; |
| | 61 | | [SerializeField] internal Image wantToGoDeselectedImage; |
| | 62 | | [SerializeField] internal GameObject wantToGoSelected; |
| | 63 | | [SerializeField] internal Image wantToGoSelectedImage; |
| | 64 | | [SerializeField] internal DropdownComponentView frequencyDropdown; |
| | 65 | | [SerializeField] internal DropdownComponentView categoriesDropdown; |
| | 66 | | [SerializeField] internal DropdownWithRangeSliderComponentView timeDropdown; |
| | 67 | |
|
| | 68 | | [SerializeField] private Canvas canvas; |
| | 69 | |
|
| | 70 | | internal Pool featuredEventCardsPool; |
| | 71 | | internal Pool eventCardsPool; |
| | 72 | |
|
| | 73 | | internal EventCardComponentView eventModal; |
| | 74 | |
|
| | 75 | | private Canvas eventsCanvas; |
| | 76 | |
|
| | 77 | | private bool isUpdatingCardsVisual; |
| | 78 | | private bool isGuest; |
| | 79 | |
|
| 0 | 80 | | public int currentEventsPerRow => eventsGrid.currentItemsPerRow; |
| | 81 | |
|
| 0 | 82 | | public void SetAllAsLoading() => SetAllEventGroupsAsLoading(); |
| | 83 | |
|
| 0 | 84 | | public int CurrentTilesPerRow => currentEventsPerRow; |
| | 85 | |
|
| 55 | 86 | | public EventsType SelectedEventType { get; private set; } |
| 54 | 87 | | public string SelectedFrequency { get; private set; } |
| 54 | 88 | | public string SelectedCategory { get; private set; } |
| 54 | 89 | | public float SelectedLowTime { get; private set; } |
| 54 | 90 | | public float SelectedHighTime { get; private set; } |
| | 91 | |
|
| | 92 | | public event Action OnReady; |
| | 93 | | public event Action<EventCardComponentModel> OnInfoClicked; |
| | 94 | | public event Action<EventFromAPIModel> OnJumpInClicked; |
| | 95 | | public event Action<string, bool> OnSubscribeEventClicked; |
| | 96 | | public event Action<string, bool> OnUnsubscribeEventClicked; |
| | 97 | | public event Action OnShowMoreEventsClicked; |
| | 98 | | public event Action OnConnectWallet; |
| | 99 | | public event Action OnEventsSubSectionEnable; |
| | 100 | | public event Action OnEventTypeFiltersChanged; |
| | 101 | | public event Action OnEventFrequencyFilterChanged; |
| | 102 | | public event Action OnEventCategoryFilterChanged; |
| | 103 | | public event Action OnEventTimeFilterChanged; |
| | 104 | |
|
| | 105 | | public override void Awake() |
| | 106 | | { |
| 51 | 107 | | base.Awake(); |
| 51 | 108 | | cancellationTokenSource = cancellationTokenSource.SafeRestart(); |
| 51 | 109 | | featuredEventsCancellationTokenSource = featuredEventsCancellationTokenSource.SafeRestart(); |
| 51 | 110 | | eventsCanvas = eventsGrid.GetComponent<Canvas>(); |
| 51 | 111 | | guestGoingToPanel.SetActive(false); |
| 51 | 112 | | } |
| | 113 | |
|
| | 114 | | public void Start() |
| | 115 | | { |
| 45 | 116 | | LoadFrequencyDropdown(); |
| | 117 | |
|
| 45 | 118 | | eventModal = PlacesAndEventsCardsFactory.GetEventCardTemplateHiddenLazy(eventCardModalPrefab); |
| | 119 | |
|
| 45 | 120 | | featuredEvents.RemoveItems(); |
| 45 | 121 | | eventsGrid.RemoveItems(); |
| | 122 | |
|
| 45 | 123 | | showMoreEventsButton.onClick.RemoveAllListeners(); |
| 45 | 124 | | showMoreEventsButton.onClick.AddListener(() => OnShowMoreEventsClicked?.Invoke()); |
| 45 | 125 | | connectWalletGuest.onClick.RemoveAllListeners(); |
| 45 | 126 | | connectWalletGuest.onClick.AddListener(() => OnConnectWallet?.Invoke()); |
| | 127 | |
|
| 45 | 128 | | featuredButton.onClick.RemoveAllListeners(); |
| 45 | 129 | | featuredButton.onClick.AddListener(ClickedOnFeatured); |
| 45 | 130 | | trendingButton.onClick.RemoveAllListeners(); |
| 45 | 131 | | trendingButton.onClick.AddListener(ClickedOnTrending); |
| 45 | 132 | | wantToGoButton.onClick.RemoveAllListeners(); |
| 45 | 133 | | wantToGoButton.onClick.AddListener(ClickedOnWantToGo); |
| 45 | 134 | | frequencyDropdown.OnOptionSelectionChanged += OnFrequencyFilterChanged; |
| 45 | 135 | | categoriesDropdown.OnOptionSelectionChanged += OnCategoryFilterChanged; |
| 45 | 136 | | timeDropdown.OnValueChanged.AddListener(OnTimeFilterChanged); |
| | 137 | |
|
| 45 | 138 | | OnReady?.Invoke(); |
| 0 | 139 | | } |
| | 140 | |
|
| | 141 | | public override void OnEnable() |
| | 142 | | { |
| 54 | 143 | | SelectedEventType = EventsType.Upcoming; |
| 54 | 144 | | SetFeaturedStatus(false); |
| 54 | 145 | | SetTrendingStatus(false); |
| 54 | 146 | | SetWantToGoStatus(false); |
| 54 | 147 | | SetFrequencyDropdownValue(ALL_FILTER_ID, ALL_FILTER_TEXT, false); |
| 54 | 148 | | SetCategoryDropdownValue(ALL_FILTER_ID, ALL_FILTER_TEXT, false); |
| 54 | 149 | | SelectedLowTime = TIME_MIN_VALUE; |
| 54 | 150 | | SelectedHighTime = TIME_MAX_VALUE; |
| 54 | 151 | | timeDropdown.SetWholeNumbers(true); |
| 54 | 152 | | timeDropdown.SetValues(TIME_MIN_VALUE, TIME_MAX_VALUE); |
| 54 | 153 | | timeDropdown.SetTitle($"{ConvertToTimeString(TIME_MIN_VALUE)} - {ConvertToTimeString(TIME_MAX_VALUE)} (UTC)"); |
| | 154 | |
|
| 54 | 155 | | OnEventsSubSectionEnable?.Invoke(); |
| 0 | 156 | | } |
| | 157 | |
|
| | 158 | | public void SetIsGuestUser(bool isGuestUser) |
| | 159 | | { |
| 0 | 160 | | isGuest = isGuestUser; |
| 0 | 161 | | } |
| | 162 | |
|
| | 163 | | public void SetCategories(List<ToggleComponentModel> categories) |
| | 164 | | { |
| 0 | 165 | | if (categories.Count == 0) |
| 0 | 166 | | return; |
| | 167 | |
|
| 0 | 168 | | categoriesDropdown.SetOptions(categories); |
| 0 | 169 | | SetCategoryDropdownValue(categories[0].id, categories[0].text, false); |
| 0 | 170 | | } |
| | 171 | |
|
| | 172 | | public override void Dispose() |
| | 173 | | { |
| 110 | 174 | | base.Dispose(); |
| 110 | 175 | | cancellationTokenSource.SafeCancelAndDispose(); |
| 110 | 176 | | featuredEventsCancellationTokenSource.SafeCancelAndDispose(); |
| | 177 | |
|
| 110 | 178 | | showMoreEventsButton.onClick.RemoveAllListeners(); |
| | 179 | |
|
| 110 | 180 | | frequencyDropdown.OnOptionSelectionChanged -= OnFrequencyFilterChanged; |
| 110 | 181 | | categoriesDropdown.OnOptionSelectionChanged -= OnCategoryFilterChanged; |
| 110 | 182 | | timeDropdown.OnValueChanged.RemoveAllListeners(); |
| | 183 | |
|
| 110 | 184 | | featuredEvents.Dispose(); |
| 110 | 185 | | eventsGrid.Dispose(); |
| | 186 | |
|
| 110 | 187 | | if (eventModal != null) |
| | 188 | | { |
| 74 | 189 | | eventModal.Dispose(); |
| 74 | 190 | | Destroy(eventModal.gameObject); |
| | 191 | | } |
| 110 | 192 | | } |
| | 193 | |
|
| | 194 | | public void SetActive(bool isActive) |
| | 195 | | { |
| 81 | 196 | | canvas.enabled = isActive; |
| | 197 | |
|
| 81 | 198 | | if (isActive) |
| 3 | 199 | | OnEnable(); |
| | 200 | | else |
| 78 | 201 | | OnDisable(); |
| 78 | 202 | | } |
| | 203 | |
|
| | 204 | | public void ConfigurePools() |
| | 205 | | { |
| 14 | 206 | | featuredEventCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(FEATURED_EVENT_CARDS_POOL_NAME, eventCardL |
| 14 | 207 | | eventCardsPool = PlacesAndEventsCardsFactory.GetCardsPoolLazy(EVENT_CARDS_POOL_NAME, eventCardPrefab, EVENT_CARD |
| 14 | 208 | | } |
| | 209 | |
|
| | 210 | | public override void RefreshControl() |
| | 211 | | { |
| 0 | 212 | | featuredEvents.RefreshControl(); |
| 0 | 213 | | eventsGrid.RefreshControl(); |
| 0 | 214 | | } |
| | 215 | |
|
| | 216 | | public void SetAllEventGroupsAsLoading() |
| | 217 | | { |
| 0 | 218 | | SetFeaturedEventsGroupAsLoading(); |
| 0 | 219 | | SetEventsGroupAsLoading(isVisible: true, eventsCanvas, eventsLoading); |
| 0 | 220 | | eventsNoDataContainer.SetActive(false); |
| 0 | 221 | | } |
| | 222 | |
|
| | 223 | | internal void SetFeaturedEventsGroupAsLoading() |
| | 224 | | { |
| 1 | 225 | | featuredEvents.gameObject.SetActive(false); |
| 1 | 226 | | featuredEventsLoading.SetActive(true); |
| 1 | 227 | | } |
| | 228 | |
|
| | 229 | | public void SetEventsGroupAsLoading(bool isVisible, Canvas gridCanvas, GameObject loadingBar) |
| | 230 | | { |
| 3 | 231 | | gridCanvas.enabled = !isVisible; |
| 3 | 232 | | loadingBar.SetActive(isVisible); |
| 3 | 233 | | } |
| | 234 | |
|
| | 235 | | public void SetShowMoreEventsButtonActive(bool isActive) => |
| 2 | 236 | | showMoreEventsButtonContainer.gameObject.SetActive(isActive); |
| | 237 | |
|
| | 238 | | public void ShowEventModal(EventCardComponentModel eventInfo) |
| | 239 | | { |
| 1 | 240 | | eventModal.Show(); |
| 1 | 241 | | EventsCardsConfigurator.Configure(eventModal, eventInfo, OnInfoClicked, OnJumpInClicked, OnSubscribeEventClicked |
| 1 | 242 | | } |
| | 243 | |
|
| | 244 | | public void HideEventModal() |
| | 245 | | { |
| 1 | 246 | | if (eventModal != null) |
| 1 | 247 | | eventModal.Hide(); |
| 1 | 248 | | } |
| | 249 | |
|
| | 250 | | public void RestartScrollViewPosition() => |
| 0 | 251 | | scrollView.verticalNormalizedPosition = 1; |
| | 252 | |
|
| | 253 | | public void SetEvents(List<EventCardComponentModel> events) => |
| 1 | 254 | | SetEvents(events, eventsGrid, eventsCanvas, eventCardsPool, eventsLoading); |
| | 255 | |
|
| | 256 | | private void SetEvents(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Canvas gridCanva |
| | 257 | | { |
| 1 | 258 | | SetEventsGroupAsLoading(false, gridCanvas, loadingBar); |
| 1 | 259 | | eventsNoDataContainer.gameObject.SetActive(events.Count == 0); |
| 1 | 260 | | eventsNoDataContainer.gameObject.SetActive(events.Count == 0 && !(SelectedEventType == EventsType.WantToGo && is |
| 1 | 261 | | guestGoingToPanel.SetActive(SelectedEventType == EventsType.WantToGo && isGuest); |
| | 262 | |
|
| 1 | 263 | | eventCardsPool.ReleaseAll(); |
| | 264 | |
|
| 1 | 265 | | eventsGrid.ExtractItems(); |
| 1 | 266 | | eventsGrid.RemoveItems(); |
| | 267 | |
|
| 1 | 268 | | cancellationTokenSource = cancellationTokenSource.SafeRestart(); |
| 1 | 269 | | cardsVisualUpdateBuffer.Clear(); |
| 1 | 270 | | isUpdatingCardsVisual = false; |
| 2 | 271 | | cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, eventsGrid, eventCardsPool, cancellationTokenSource |
| 1 | 272 | | UpdateCardsVisual(); |
| 1 | 273 | | } |
| | 274 | |
|
| | 275 | | public void AddEvents(List<EventCardComponentModel> events) |
| | 276 | | { |
| 2 | 277 | | cardsVisualUpdateBuffer.Enqueue(() => SetEventsAsync(events, eventsGrid, eventCardsPool, cancellationTokenSource |
| 1 | 278 | | UpdateCardsVisual(); |
| 1 | 279 | | } |
| | 280 | |
|
| | 281 | | private async UniTask SetEventsAsync(List<EventCardComponentModel> events, GridContainerComponentView eventsGrid, Po |
| | 282 | | { |
| 10 | 283 | | foreach (EventCardComponentModel eventInfo in events) |
| | 284 | | { |
| 4 | 285 | | eventsGrid.AddItem( |
| | 286 | | PlacesAndEventsCardsFactory.CreateConfiguredEventCard(pool, eventInfo, OnInfoClicked, OnJumpInClicked, O |
| | 287 | |
|
| 12 | 288 | | await UniTask.NextFrame(cancellationToken); |
| | 289 | | } |
| | 290 | |
|
| 0 | 291 | | eventsGrid.SetItemSizeForModel(); |
| 0 | 292 | | poolsPrewarmAsyncsBuffer.Enqueue(() => pool.PrewarmAsync(events.Count, cancellationToken)); |
| 0 | 293 | | } |
| | 294 | |
|
| | 295 | | public void SetFeaturedEvents(List<EventCardComponentModel> events) |
| | 296 | | { |
| 1 | 297 | | featuredEventsLoading.SetActive(false); |
| 1 | 298 | | featuredEvents.gameObject.SetActive(events.Count > 0); |
| | 299 | |
|
| 1 | 300 | | featuredEventCardsPool.ReleaseAll(); |
| | 301 | |
|
| 1 | 302 | | featuredEvents.ExtractItems(); |
| | 303 | |
|
| 1 | 304 | | featuredEventsCancellationTokenSource = featuredEventsCancellationTokenSource.SafeRestart(); |
| 1 | 305 | | SetFeaturedEventsAsync(events, featuredEventsCancellationTokenSource.Token).Forget(); |
| 1 | 306 | | } |
| | 307 | |
|
| | 308 | | private async UniTask SetFeaturedEventsAsync(List<EventCardComponentModel> events, CancellationToken cancellationTok |
| | 309 | | { |
| 5 | 310 | | foreach (EventCardComponentModel eventInfo in events) |
| | 311 | | { |
| 2 | 312 | | featuredEvents.AddItem( |
| | 313 | | PlacesAndEventsCardsFactory.CreateConfiguredEventCard(featuredEventCardsPool, eventInfo, OnInfoClicked, |
| | 314 | |
|
| 6 | 315 | | await UniTask.NextFrame(cancellationToken); |
| | 316 | | } |
| | 317 | |
|
| 0 | 318 | | featuredEvents.SetManualControlsActive(); |
| 0 | 319 | | featuredEvents.GenerateDotsSelector(); |
| 0 | 320 | | } |
| | 321 | |
|
| | 322 | | private void UpdateCardsVisual() |
| | 323 | | { |
| 2 | 324 | | if (!isUpdatingCardsVisual) |
| 2 | 325 | | ShowCardsProcess().Forget(); |
| | 326 | |
|
| | 327 | | async UniTask ShowCardsProcess() |
| | 328 | | { |
| 2 | 329 | | isUpdatingCardsVisual = true; |
| | 330 | |
|
| 2 | 331 | | while (cardsVisualUpdateBuffer.Count > 0) |
| 6 | 332 | | await cardsVisualUpdateBuffer.Dequeue().Invoke(); |
| | 333 | |
|
| 0 | 334 | | while (poolsPrewarmAsyncsBuffer.Count > 0) |
| 0 | 335 | | await poolsPrewarmAsyncsBuffer.Dequeue().Invoke(); |
| | 336 | |
|
| 0 | 337 | | isUpdatingCardsVisual = false; |
| 0 | 338 | | } |
| 2 | 339 | | } |
| | 340 | |
|
| | 341 | | private void LoadFrequencyDropdown() |
| | 342 | | { |
| 45 | 343 | | List<ToggleComponentModel> valuesToAdd = new List<ToggleComponentModel> |
| | 344 | | { |
| | 345 | | new () { id = ALL_FILTER_ID, text = ALL_FILTER_TEXT, isOn = true, isTextActive = true, changeTextColorOnSele |
| | 346 | | new () { id = ONE_TIME_EVENT_FREQUENCY_FILTER_ID, text = ONE_TIME_EVENT_FREQUENCY_FILTER_TEXT, isOn = false, |
| | 347 | | new () { id = RECURRING_EVENT_FREQUENCY_FILTER_ID, text = RECURRING_EVENT_FREQUENCY_FILTER_TEXT, isOn = fals |
| | 348 | | }; |
| | 349 | |
|
| 45 | 350 | | frequencyDropdown.SetTitle(valuesToAdd[0].text); |
| 45 | 351 | | frequencyDropdown.SetOptions(valuesToAdd); |
| 45 | 352 | | } |
| | 353 | |
|
| | 354 | | private void SetFeaturedStatus(bool isSelected) |
| | 355 | | { |
| 54 | 356 | | featuredButton.targetGraphic = isSelected ? featuredSelectedImage : featuredDeselectedImage; |
| 54 | 357 | | featuredDeselected.SetActive(!isSelected); |
| 54 | 358 | | featuredSelected.SetActive(isSelected); |
| 54 | 359 | | } |
| | 360 | |
|
| | 361 | | private void SetTrendingStatus(bool isSelected) |
| | 362 | | { |
| 54 | 363 | | trendingButton.targetGraphic = isSelected ? trendingSelectedImage : trendingDeselectedImage; |
| 54 | 364 | | trendingDeselected.SetActive(!isSelected); |
| 54 | 365 | | trendingSelected.SetActive(isSelected); |
| 54 | 366 | | } |
| | 367 | |
|
| | 368 | | private void SetWantToGoStatus(bool isSelected) |
| | 369 | | { |
| 54 | 370 | | wantToGoButton.targetGraphic = isSelected ? wantToGoSelectedImage : wantToGoDeselectedImage; |
| 54 | 371 | | wantToGoDeselected.SetActive(!isSelected); |
| 54 | 372 | | wantToGoSelected.SetActive(isSelected); |
| 54 | 373 | | } |
| | 374 | |
|
| | 375 | | private void ClickedOnFeatured() |
| | 376 | | { |
| 0 | 377 | | DeselectButtons(); |
| | 378 | |
|
| 0 | 379 | | if (SelectedEventType == EventsType.Featured) |
| | 380 | | { |
| 0 | 381 | | SelectedEventType = EventsType.Upcoming; |
| 0 | 382 | | SetFeaturedStatus(false); |
| | 383 | | } |
| | 384 | | else |
| | 385 | | { |
| 0 | 386 | | SelectedEventType = EventsType.Featured; |
| 0 | 387 | | SetFeaturedStatus(true); |
| 0 | 388 | | SetTrendingStatus(false); |
| 0 | 389 | | SetWantToGoStatus(false); |
| | 390 | | } |
| | 391 | |
|
| 0 | 392 | | OnEventTypeFiltersChanged?.Invoke(); |
| 0 | 393 | | } |
| | 394 | |
|
| | 395 | | private void ClickedOnTrending() |
| | 396 | | { |
| 0 | 397 | | DeselectButtons(); |
| | 398 | |
|
| 0 | 399 | | if (SelectedEventType == EventsType.Trending) |
| | 400 | | { |
| 0 | 401 | | SelectedEventType = EventsType.Upcoming; |
| 0 | 402 | | SetTrendingStatus(false); |
| | 403 | | } |
| | 404 | | else |
| | 405 | | { |
| 0 | 406 | | SelectedEventType = EventsType.Trending; |
| 0 | 407 | | SetTrendingStatus(true); |
| 0 | 408 | | SetFeaturedStatus(false); |
| 0 | 409 | | SetWantToGoStatus(false); |
| | 410 | | } |
| | 411 | |
|
| 0 | 412 | | OnEventTypeFiltersChanged?.Invoke(); |
| 0 | 413 | | } |
| | 414 | |
|
| | 415 | | private void ClickedOnWantToGo() |
| | 416 | | { |
| 0 | 417 | | DeselectButtons(); |
| | 418 | |
|
| 0 | 419 | | if (SelectedEventType == EventsType.WantToGo) |
| | 420 | | { |
| 0 | 421 | | SelectedEventType = EventsType.Upcoming; |
| 0 | 422 | | SetWantToGoStatus(false); |
| | 423 | | } |
| | 424 | | else |
| | 425 | | { |
| 0 | 426 | | SelectedEventType = EventsType.WantToGo; |
| 0 | 427 | | SetWantToGoStatus(true); |
| 0 | 428 | | SetFeaturedStatus(false); |
| 0 | 429 | | SetTrendingStatus(false); |
| | 430 | | } |
| | 431 | |
|
| 0 | 432 | | OnEventTypeFiltersChanged?.Invoke(); |
| 0 | 433 | | } |
| | 434 | |
|
| | 435 | | private void OnFrequencyFilterChanged(bool isOn, string optionId, string optionName) |
| | 436 | | { |
| 0 | 437 | | if (!isOn) |
| 0 | 438 | | return; |
| | 439 | |
|
| 0 | 440 | | SetFrequencyDropdownValue(optionId, optionName, false); |
| 0 | 441 | | OnEventFrequencyFilterChanged?.Invoke(); |
| 0 | 442 | | } |
| | 443 | |
|
| | 444 | | private void OnCategoryFilterChanged(bool isOn, string optionId, string optionName) |
| | 445 | | { |
| 0 | 446 | | if (!isOn) |
| 0 | 447 | | return; |
| | 448 | |
|
| 0 | 449 | | SetCategoryDropdownValue(optionId, optionName, false); |
| 0 | 450 | | OnEventCategoryFilterChanged?.Invoke(); |
| 0 | 451 | | } |
| | 452 | |
|
| | 453 | | private void OnTimeFilterChanged(float lowValue, float highValue) |
| | 454 | | { |
| 0 | 455 | | SelectedLowTime = lowValue; |
| 0 | 456 | | SelectedHighTime = highValue; |
| 0 | 457 | | timeDropdown.SetTitle($"{ConvertToTimeString(lowValue)} - {ConvertToTimeString(highValue)} (UTC)"); |
| 0 | 458 | | OnEventTimeFilterChanged?.Invoke(); |
| 0 | 459 | | } |
| | 460 | |
|
| | 461 | | private static string ConvertToTimeString(float hours) |
| | 462 | | { |
| 108 | 463 | | var wholeHours = (int)(hours / 2); |
| 108 | 464 | | int minutes = (int)(hours % 2) * 30; |
| 108 | 465 | | return $"{wholeHours:D2}:{minutes:D2}"; |
| | 466 | | } |
| | 467 | |
|
| | 468 | | private void SetFrequencyDropdownValue(string id, string title, bool notify) |
| | 469 | | { |
| 54 | 470 | | SelectedFrequency = id; |
| 54 | 471 | | frequencyDropdown.SetTitle(title); |
| 54 | 472 | | frequencyDropdown.SelectOption(id, notify); |
| 54 | 473 | | } |
| | 474 | |
|
| | 475 | | private void SetCategoryDropdownValue(string id, string title, bool notify) |
| | 476 | | { |
| 54 | 477 | | SelectedCategory = id; |
| 54 | 478 | | categoriesDropdown.SetTitle(title); |
| 54 | 479 | | categoriesDropdown.SelectOption(id, notify); |
| 54 | 480 | | } |
| | 481 | |
|
| | 482 | | private static void DeselectButtons() |
| | 483 | | { |
| 0 | 484 | | if (EventSystem.current == null) |
| 0 | 485 | | return; |
| | 486 | |
|
| 0 | 487 | | EventSystem.current.SetSelectedGameObject(null); |
| 0 | 488 | | } |
| | 489 | | } |