| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public interface IEventCardComponentView |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Event that will be triggered when the jumpIn button is clicked. |
| | 11 | | /// </summary> |
| | 12 | | Button.ButtonClickedEvent onJumpInClick { get; } |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// Event that will be triggered when the info button is clicked. |
| | 16 | | /// </summary> |
| | 17 | | Button.ButtonClickedEvent onInfoClick { get; } |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Event that will be triggered when the subscribe event button is clicked. |
| | 21 | | /// </summary> |
| | 22 | | Button.ButtonClickedEvent onSubscribeClick { get; } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Event that will be triggered when the unsubscribe event button is clicked. |
| | 26 | | /// </summary> |
| | 27 | | Button.ButtonClickedEvent onUnsubscribeClick { get; } |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Set the event picture directly from a sprite. |
| | 31 | | /// </summary> |
| | 32 | | /// <param name="sprite">Event picture (sprite).</param> |
| | 33 | | void SetEventPicture(Sprite sprite); |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// Set the event picture from a 2D texture. |
| | 37 | | /// </summary> |
| | 38 | | /// <param name="texture">Event picture (url).</param> |
| | 39 | | void SetEventPicture(Texture2D texture); |
| | 40 | |
|
| | 41 | | /// <summary> |
| | 42 | | /// Set the event picture from an uri. |
| | 43 | | /// </summary> |
| | 44 | | /// <param name="uri"></param> |
| | 45 | | void SetEventPicture(string uri); |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Set the event card as live mode. |
| | 49 | | /// </summary> |
| | 50 | | /// <param name="isLive">True to set the event as live.</param> |
| | 51 | | void SetEventAsLive(bool isLive); |
| | 52 | |
|
| | 53 | | /// <summary> |
| | 54 | | /// Set the live tag text. |
| | 55 | | /// </summary> |
| | 56 | | /// <param name="newText">New text.</param> |
| | 57 | | void SetLiveTagText(string newText); |
| | 58 | |
|
| | 59 | | /// <summary> |
| | 60 | | /// Set the event date. |
| | 61 | | /// </summary> |
| | 62 | | /// <param name="newDate">The new date showed in the event card.</param> |
| | 63 | | void SetEventDate(string newDate); |
| | 64 | |
|
| | 65 | | /// <summary> |
| | 66 | | /// Set the event name in the card. |
| | 67 | | /// </summary> |
| | 68 | | /// <param name="newText">New event name.</param> |
| | 69 | | void SetEventName(string newText); |
| | 70 | |
|
| | 71 | | /// <summary> |
| | 72 | | /// Set the event description in the card. |
| | 73 | | /// </summary> |
| | 74 | | /// <param name="newText">New event description.</param> |
| | 75 | | void SetEventDescription(string newText); |
| | 76 | |
|
| | 77 | | /// <summary> |
| | 78 | | /// Set the event started time in the card. |
| | 79 | | /// </summary> |
| | 80 | | /// <param name="newText">New event started time.</param> |
| | 81 | | void SetEventStartedIn(string newText); |
| | 82 | |
|
| | 83 | | /// <summary> |
| | 84 | | /// Set the event dates range in the card. |
| | 85 | | /// </summary> |
| | 86 | | /// <param name="newText">New event date range.</param> |
| | 87 | | void SetEventStartsInFromTo(string newText); |
| | 88 | |
|
| | 89 | | /// <summary> |
| | 90 | | /// Set the event organizer in the card. |
| | 91 | | /// </summary> |
| | 92 | | /// <param name="newText">New event organizer.</param> |
| | 93 | | void SetEventOrganizer(string newText); |
| | 94 | |
|
| | 95 | | /// <summary> |
| | 96 | | /// Set the event place in the card. |
| | 97 | | /// </summary> |
| | 98 | | /// <param name="newText">New event place.</param> |
| | 99 | | void SetEventPlace(string newText); |
| | 100 | |
|
| | 101 | | /// <summary> |
| | 102 | | /// Set the the number of users subscribed to the event. |
| | 103 | | /// </summary> |
| | 104 | | /// <param name="newNumberOfUsers">Number of users subscribed.</param> |
| | 105 | | void SetSubscribersUsers(int newNumberOfUsers); |
| | 106 | |
|
| | 107 | | /// <summary> |
| | 108 | | /// Set the event coords. |
| | 109 | | /// </summary> |
| | 110 | | /// <param name="newCoords">Event coords.</param> |
| | 111 | | void SetCoords(Vector2Int newCoords); |
| | 112 | |
|
| | 113 | | /// <summary> |
| | 114 | | /// Active or deactive the loading indicator. |
| | 115 | | /// </summary> |
| | 116 | | /// <param name="isVisible">True for showing the loading indicator and hiding the card info.</param> |
| | 117 | | void SetLoadingIndicatorVisible(bool isVisible); |
| | 118 | | } |
| | 119 | |
|
| | 120 | | public class EventCardComponentView : BaseComponentView, IEventCardComponentView, IComponentModelConfig<EventCardCompone |
| | 121 | | { |
| | 122 | | internal const string USERS_CONFIRMED_MESSAGE = "{0} confirmed"; |
| | 123 | | internal const string NOBODY_CONFIRMED_MESSAGE = "Nobody confirmed yet"; |
| | 124 | |
|
| | 125 | | [Header("Prefab References")] |
| | 126 | | [SerializeField] internal ImageComponentView eventImage; |
| | 127 | | [SerializeField] internal TagComponentView liveTag; |
| | 128 | | [SerializeField] internal TMP_Text eventDateText; |
| | 129 | | [SerializeField] internal TMP_Text eventNameText; |
| | 130 | | [SerializeField] internal TMP_Text eventDescText; |
| | 131 | | [SerializeField] internal TMP_Text eventStartedInTitleForLive; |
| | 132 | | [SerializeField] internal TMP_Text eventStartedInTitleForNotLive; |
| | 133 | | [SerializeField] internal TMP_Text eventStartedInText; |
| | 134 | | [SerializeField] internal TMP_Text eventStartsInFromToText; |
| | 135 | | [SerializeField] internal TMP_Text eventOrganizerText; |
| | 136 | | [SerializeField] internal TMP_Text eventPlaceText; |
| | 137 | | [SerializeField] internal TMP_Text subscribedUsersTitleForLive; |
| | 138 | | [SerializeField] internal TMP_Text subscribedUsersTitleForNotLive; |
| | 139 | | [SerializeField] internal TMP_Text subscribedUsersText; |
| | 140 | | [SerializeField] internal Button modalBackgroundButton; |
| | 141 | | [SerializeField] internal ButtonComponentView closeCardButton; |
| | 142 | | [SerializeField] internal InputAction_Trigger closeAction; |
| | 143 | | [SerializeField] internal ButtonComponentView infoButton; |
| | 144 | | [SerializeField] internal ButtonComponentView jumpinButton; |
| | 145 | | [SerializeField] internal ButtonComponentView jumpinButtonForNotLive; |
| | 146 | | [SerializeField] internal ButtonComponentView subscribeEventButton; |
| | 147 | | [SerializeField] internal ButtonComponentView unsubscribeEventButton; |
| | 148 | | [SerializeField] internal GameObject imageContainer; |
| | 149 | | [SerializeField] internal GameObject eventInfoContainer; |
| | 150 | | [SerializeField] internal GameObject loadingSpinner; |
| | 151 | | [SerializeField] internal VerticalLayoutGroup contentVerticalLayout; |
| | 152 | | [SerializeField] internal VerticalLayoutGroup infoVerticalLayout; |
| | 153 | | [SerializeField] internal HorizontalLayoutGroup timeAndPlayersHorizontalLayout; |
| | 154 | | [SerializeField] internal EventCardAnimator cardAnimator; |
| | 155 | |
|
| | 156 | | [Header("Configuration")] |
| | 157 | | [SerializeField] internal Sprite defaultPicture; |
| | 158 | | [SerializeField] internal bool isEventCardModal = false; |
| | 159 | | [SerializeField] internal EventCardComponentModel model; |
| | 160 | |
|
| 0 | 161 | | public Button.ButtonClickedEvent onJumpInClick => jumpinButton?.onClick; |
| 0 | 162 | | public Button.ButtonClickedEvent onJumpInForNotLiveClick => jumpinButtonForNotLive?.onClick; |
| 0 | 163 | | public Button.ButtonClickedEvent onInfoClick => infoButton?.onClick; |
| 0 | 164 | | public Button.ButtonClickedEvent onSubscribeClick => subscribeEventButton?.onClick; |
| 0 | 165 | | public Button.ButtonClickedEvent onUnsubscribeClick => unsubscribeEventButton?.onClick; |
| | 166 | |
|
| | 167 | | public override void Start() |
| | 168 | | { |
| 65 | 169 | | if (closeCardButton != null) |
| 34 | 170 | | closeCardButton.onClick.AddListener(CloseModal); |
| | 171 | |
|
| 65 | 172 | | if (closeAction != null) |
| 34 | 173 | | closeAction.OnTriggered += OnCloseActionTriggered; |
| | 174 | |
|
| 65 | 175 | | if (modalBackgroundButton != null) |
| 34 | 176 | | modalBackgroundButton.onClick.AddListener(CloseModal); |
| 65 | 177 | | } |
| | 178 | |
|
| | 179 | | public void Configure(EventCardComponentModel newModel) |
| | 180 | | { |
| 28 | 181 | | model = newModel; |
| 28 | 182 | | RefreshControl(); |
| 28 | 183 | | } |
| | 184 | |
|
| | 185 | | public override void RefreshControl() |
| | 186 | | { |
| 28 | 187 | | if (model == null) |
| 0 | 188 | | return; |
| | 189 | |
|
| 28 | 190 | | if (model.eventPictureSprite != null) |
| 28 | 191 | | SetEventPicture(model.eventPictureSprite); |
| 0 | 192 | | else if (model.eventPictureTexture != null) |
| 0 | 193 | | SetEventPicture(model.eventPictureTexture); |
| 0 | 194 | | else if (!string.IsNullOrEmpty(model.eventPictureUri)) |
| 0 | 195 | | SetEventPicture(model.eventPictureUri); |
| | 196 | | else |
| 0 | 197 | | SetEventPicture(sprite: null); |
| | 198 | |
|
| 28 | 199 | | SetEventAsLive(model.isLive); |
| 28 | 200 | | SetLiveTagText(model.liveTagText); |
| 28 | 201 | | SetEventDate(model.eventDateText); |
| 28 | 202 | | SetEventName(model.eventName); |
| 28 | 203 | | SetEventDescription(model.eventDescription); |
| 28 | 204 | | SetEventStartedIn(model.eventStartedIn); |
| 28 | 205 | | SetEventStartsInFromTo(model.eventStartsInFromTo); |
| 28 | 206 | | SetEventOrganizer(model.eventOrganizer); |
| 28 | 207 | | SetEventPlace(model.eventPlace); |
| 28 | 208 | | SetSubscribersUsers(model.subscribedUsers); |
| 28 | 209 | | SetCoords(model.coords); |
| | 210 | |
|
| 28 | 211 | | RebuildCardLayouts(); |
| 28 | 212 | | } |
| | 213 | |
|
| | 214 | | public override void OnFocus() |
| | 215 | | { |
| 29 | 216 | | base.OnFocus(); |
| | 217 | |
|
| 29 | 218 | | cardAnimator?.Focus(); |
| 29 | 219 | | } |
| | 220 | |
|
| | 221 | | public override void OnLoseFocus() |
| | 222 | | { |
| 442 | 223 | | base.OnLoseFocus(); |
| | 224 | |
|
| 442 | 225 | | cardAnimator?.Idle(); |
| 388 | 226 | | } |
| | 227 | |
|
| | 228 | | public override void Show(bool instant = false) |
| | 229 | | { |
| 4 | 230 | | base.Show(instant); |
| | 231 | |
|
| 4 | 232 | | DataStore.i.exploreV2.isSomeModalOpen.Set(true); |
| 4 | 233 | | } |
| | 234 | |
|
| | 235 | | public override void Hide(bool instant = false) |
| | 236 | | { |
| 123 | 237 | | base.Hide(instant); |
| | 238 | |
|
| 123 | 239 | | DataStore.i.exploreV2.isSomeModalOpen.Set(false); |
| 123 | 240 | | } |
| | 241 | |
|
| | 242 | | public override void Dispose() |
| | 243 | | { |
| 599 | 244 | | base.Dispose(); |
| | 245 | |
|
| 599 | 246 | | if (eventImage != null) |
| 599 | 247 | | eventImage.Dispose(); |
| | 248 | |
|
| 599 | 249 | | if (closeCardButton != null) |
| 263 | 250 | | closeCardButton.onClick.RemoveAllListeners(); |
| | 251 | |
|
| 599 | 252 | | if (closeAction != null) |
| 263 | 253 | | closeAction.OnTriggered -= OnCloseActionTriggered; |
| | 254 | |
|
| 599 | 255 | | if (modalBackgroundButton != null) |
| 263 | 256 | | modalBackgroundButton.onClick.RemoveAllListeners(); |
| 599 | 257 | | } |
| | 258 | |
|
| | 259 | | public void SetEventPicture(Sprite sprite) |
| | 260 | | { |
| 29 | 261 | | if (sprite == null && defaultPicture != null) |
| 0 | 262 | | sprite = defaultPicture; |
| | 263 | |
|
| 29 | 264 | | model.eventPictureSprite = sprite; |
| | 265 | |
|
| 29 | 266 | | if (eventImage == null) |
| 0 | 267 | | return; |
| | 268 | |
|
| 29 | 269 | | eventImage.SetImage(sprite); |
| 29 | 270 | | } |
| | 271 | |
|
| | 272 | | public void SetEventPicture(Texture2D texture) |
| | 273 | | { |
| 1 | 274 | | if (texture == null && defaultPicture != null) |
| | 275 | | { |
| 0 | 276 | | SetEventPicture(defaultPicture); |
| 0 | 277 | | return; |
| | 278 | | } |
| | 279 | |
|
| 1 | 280 | | model.eventPictureTexture = texture; |
| | 281 | |
|
| 1 | 282 | | if (!Application.isPlaying) |
| 0 | 283 | | return; |
| | 284 | |
|
| 1 | 285 | | if (eventImage == null) |
| 0 | 286 | | return; |
| | 287 | |
|
| 1 | 288 | | eventImage.SetImage(texture); |
| 1 | 289 | | } |
| | 290 | |
|
| | 291 | | public void SetEventPicture(string uri) |
| | 292 | | { |
| 1 | 293 | | if (string.IsNullOrEmpty(uri) && defaultPicture != null) |
| | 294 | | { |
| 0 | 295 | | SetEventPicture(defaultPicture); |
| 0 | 296 | | return; |
| | 297 | | } |
| | 298 | |
|
| 1 | 299 | | model.eventPictureUri = uri; |
| | 300 | |
|
| 1 | 301 | | if (!Application.isPlaying) |
| 0 | 302 | | return; |
| | 303 | |
|
| 1 | 304 | | if (eventImage == null) |
| 0 | 305 | | return; |
| | 306 | |
|
| 1 | 307 | | eventImage.SetImage(uri); |
| 1 | 308 | | } |
| | 309 | |
|
| | 310 | | public void SetEventAsLive(bool isLive) |
| | 311 | | { |
| 36 | 312 | | model.isLive = isLive; |
| | 313 | |
|
| 36 | 314 | | if (liveTag != null) |
| 36 | 315 | | liveTag.gameObject.SetActive(isLive); |
| | 316 | |
|
| 36 | 317 | | if (eventDateText != null) |
| 36 | 318 | | eventDateText.gameObject.SetActive(!isLive); |
| | 319 | |
|
| 36 | 320 | | if (jumpinButton != null) |
| 36 | 321 | | jumpinButton.gameObject.SetActive(isEventCardModal || isLive); |
| | 322 | |
|
| 36 | 323 | | if (jumpinButtonForNotLive) |
| 33 | 324 | | jumpinButtonForNotLive.gameObject.SetActive(!isEventCardModal && !isLive); |
| | 325 | |
|
| 36 | 326 | | if (subscribeEventButton != null) |
| 36 | 327 | | subscribeEventButton.gameObject.SetActive(!isLive && !model.isSubscribed); |
| | 328 | |
|
| 36 | 329 | | if (unsubscribeEventButton != null) |
| 36 | 330 | | unsubscribeEventButton.gameObject.SetActive(!isLive && model.isSubscribed); |
| | 331 | |
|
| 36 | 332 | | if (eventStartedInTitleForLive) |
| 33 | 333 | | eventStartedInTitleForLive.gameObject.SetActive(isLive); |
| | 334 | |
|
| 36 | 335 | | if (eventStartedInTitleForNotLive) |
| 33 | 336 | | eventStartedInTitleForNotLive.gameObject.SetActive(!isLive); |
| | 337 | |
|
| 36 | 338 | | if (subscribedUsersTitleForLive != null) |
| 33 | 339 | | subscribedUsersTitleForLive.gameObject.SetActive(isLive); |
| | 340 | |
|
| 36 | 341 | | if (subscribedUsersTitleForNotLive != null) |
| 33 | 342 | | subscribedUsersTitleForNotLive.gameObject.SetActive(!isLive); |
| 36 | 343 | | } |
| | 344 | |
|
| | 345 | | public void SetLiveTagText(string newText) |
| | 346 | | { |
| 29 | 347 | | model.liveTagText = newText; |
| | 348 | |
|
| 29 | 349 | | if (liveTag == null) |
| 0 | 350 | | return; |
| | 351 | |
|
| 29 | 352 | | liveTag.SetText(newText); |
| 29 | 353 | | } |
| | 354 | |
|
| | 355 | | public void SetEventDate(string newDate) |
| | 356 | | { |
| 29 | 357 | | model.eventDateText = newDate; |
| | 358 | |
|
| 29 | 359 | | if (eventDateText == null) |
| 0 | 360 | | return; |
| | 361 | |
|
| 29 | 362 | | eventDateText.text = newDate; |
| 29 | 363 | | } |
| | 364 | |
|
| | 365 | | public void SetEventName(string newText) |
| | 366 | | { |
| 29 | 367 | | model.eventName = newText; |
| | 368 | |
|
| 29 | 369 | | if (eventNameText == null) |
| 0 | 370 | | return; |
| | 371 | |
|
| 29 | 372 | | eventNameText.text = newText; |
| 29 | 373 | | } |
| | 374 | |
|
| | 375 | | public void SetEventDescription(string newText) |
| | 376 | | { |
| 29 | 377 | | model.eventDescription = newText; |
| | 378 | |
|
| 29 | 379 | | if (eventDescText == null) |
| 21 | 380 | | return; |
| | 381 | |
|
| 8 | 382 | | eventDescText.text = newText; |
| 8 | 383 | | } |
| | 384 | |
|
| | 385 | | public void SetEventStartedIn(string newText) |
| | 386 | | { |
| 29 | 387 | | model.eventStartedIn = newText; |
| | 388 | |
|
| 29 | 389 | | if (eventStartedInText == null) |
| 3 | 390 | | return; |
| | 391 | |
|
| 26 | 392 | | eventStartedInText.text = newText; |
| 26 | 393 | | } |
| | 394 | |
|
| | 395 | | public void SetEventStartsInFromTo(string newText) |
| | 396 | | { |
| 29 | 397 | | model.eventStartsInFromTo = newText; |
| | 398 | |
|
| 29 | 399 | | if (eventStartsInFromToText == null) |
| 25 | 400 | | return; |
| | 401 | |
|
| 4 | 402 | | eventStartsInFromToText.text = newText; |
| 4 | 403 | | } |
| | 404 | |
|
| | 405 | | public void SetEventOrganizer(string newText) |
| | 406 | | { |
| 29 | 407 | | model.eventOrganizer = newText; |
| | 408 | |
|
| 29 | 409 | | if (eventOrganizerText == null) |
| 25 | 410 | | return; |
| | 411 | |
|
| 4 | 412 | | eventOrganizerText.text = newText; |
| 4 | 413 | | } |
| | 414 | |
|
| | 415 | | public void SetEventPlace(string newText) |
| | 416 | | { |
| 29 | 417 | | model.eventPlace = newText; |
| | 418 | |
|
| 29 | 419 | | if (eventPlaceText == null) |
| 25 | 420 | | return; |
| | 421 | |
|
| 4 | 422 | | eventPlaceText.text = newText; |
| 4 | 423 | | } |
| | 424 | |
|
| | 425 | | public void SetSubscribersUsers(int newNumberOfUsers) |
| | 426 | | { |
| 32 | 427 | | model.subscribedUsers = newNumberOfUsers; |
| | 428 | |
|
| 32 | 429 | | if (subscribedUsersText == null) |
| 0 | 430 | | return; |
| | 431 | |
|
| 32 | 432 | | if (!isEventCardModal) |
| | 433 | | { |
| 27 | 434 | | subscribedUsersText.text = newNumberOfUsers.ToString(); |
| 27 | 435 | | } |
| | 436 | | else |
| | 437 | | { |
| 5 | 438 | | if (newNumberOfUsers > 0) |
| 4 | 439 | | subscribedUsersText.text = string.Format(USERS_CONFIRMED_MESSAGE, newNumberOfUsers); |
| | 440 | | else |
| 1 | 441 | | subscribedUsersText.text = NOBODY_CONFIRMED_MESSAGE; |
| | 442 | | } |
| 1 | 443 | | } |
| | 444 | |
|
| | 445 | | public void SetCoords(Vector2Int newCoords) |
| | 446 | | { |
| 29 | 447 | | model.coords = newCoords; |
| | 448 | |
|
| 29 | 449 | | if (jumpinButton == null || !isEventCardModal) |
| 25 | 450 | | return; |
| | 451 | |
|
| 4 | 452 | | jumpinButton.SetText($"{newCoords.x},{newCoords.y}"); |
| 4 | 453 | | } |
| | 454 | |
|
| | 455 | | public void SetLoadingIndicatorVisible(bool isVisible) |
| | 456 | | { |
| 2 | 457 | | imageContainer.SetActive(!isVisible); |
| 2 | 458 | | eventInfoContainer.SetActive(!isVisible); |
| 2 | 459 | | loadingSpinner.SetActive(isVisible); |
| 2 | 460 | | } |
| | 461 | |
|
| | 462 | | internal void RebuildCardLayouts() |
| | 463 | | { |
| 28 | 464 | | if (contentVerticalLayout != null) |
| 3 | 465 | | Utils.ForceRebuildLayoutImmediate(contentVerticalLayout.transform as RectTransform); |
| | 466 | |
|
| 28 | 467 | | if (infoVerticalLayout != null) |
| 3 | 468 | | Utils.ForceRebuildLayoutImmediate(infoVerticalLayout.transform as RectTransform); |
| | 469 | |
|
| 28 | 470 | | if (timeAndPlayersHorizontalLayout != null) |
| 25 | 471 | | Utils.ForceRebuildLayoutImmediate(timeAndPlayersHorizontalLayout.transform as RectTransform); |
| 28 | 472 | | } |
| | 473 | |
|
| 4 | 474 | | internal void CloseModal() { Hide(); } |
| | 475 | |
|
| 2 | 476 | | internal void OnCloseActionTriggered(DCLAction_Trigger action) { CloseModal(); } |
| | 477 | | } |