| | 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 | |
|
| 1 | 125 | | internal static readonly int ON_FOCUS_CARD_COMPONENT_BOOL = Animator.StringToHash("OnFocus"); |
| | 126 | |
|
| | 127 | | [Header("Prefab References")] |
| | 128 | | [SerializeField] internal ImageComponentView eventImage; |
| | 129 | | [SerializeField] internal TagComponentView liveTag; |
| | 130 | | [SerializeField] internal TMP_Text eventDateText; |
| | 131 | | [SerializeField] internal TMP_Text eventNameText; |
| | 132 | | [SerializeField] internal TMP_Text eventDescText; |
| | 133 | | [SerializeField] internal TMP_Text eventStartedInTitleForLive; |
| | 134 | | [SerializeField] internal TMP_Text eventStartedInTitleForNotLive; |
| | 135 | | [SerializeField] internal TMP_Text eventStartedInText; |
| | 136 | | [SerializeField] internal TMP_Text eventStartsInFromToText; |
| | 137 | | [SerializeField] internal TMP_Text eventOrganizerText; |
| | 138 | | [SerializeField] internal TMP_Text eventPlaceText; |
| | 139 | | [SerializeField] internal TMP_Text subscribedUsersTitleForLive; |
| | 140 | | [SerializeField] internal TMP_Text subscribedUsersTitleForNotLive; |
| | 141 | | [SerializeField] internal TMP_Text subscribedUsersText; |
| | 142 | | [SerializeField] internal Button modalBackgroundButton; |
| | 143 | | [SerializeField] internal ButtonComponentView closeCardButton; |
| | 144 | | [SerializeField] internal InputAction_Trigger closeAction; |
| | 145 | | [SerializeField] internal ButtonComponentView infoButton; |
| | 146 | | [SerializeField] internal ButtonComponentView jumpinButton; |
| | 147 | | [SerializeField] internal ButtonComponentView jumpinButtonForNotLive; |
| | 148 | | [SerializeField] internal ButtonComponentView subscribeEventButton; |
| | 149 | | [SerializeField] internal ButtonComponentView unsubscribeEventButton; |
| | 150 | | [SerializeField] internal GameObject imageContainer; |
| | 151 | | [SerializeField] internal GameObject eventInfoContainer; |
| | 152 | | [SerializeField] internal GameObject loadingSpinner; |
| | 153 | | [SerializeField] internal Animator cardAnimator; |
| | 154 | | [SerializeField] internal VerticalLayoutGroup contentVerticalLayout; |
| | 155 | | [SerializeField] internal VerticalLayoutGroup infoVerticalLayout; |
| | 156 | | [SerializeField] internal HorizontalLayoutGroup timeAndPlayersHorizontalLayout; |
| | 157 | |
|
| | 158 | | [Header("Configuration")] |
| | 159 | | [SerializeField] internal Sprite defaultPicture; |
| | 160 | | [SerializeField] internal bool isEventCardModal = false; |
| | 161 | | [SerializeField] internal EventCardComponentModel model; |
| | 162 | |
|
| 0 | 163 | | public Button.ButtonClickedEvent onJumpInClick => jumpinButton?.onClick; |
| 0 | 164 | | public Button.ButtonClickedEvent onJumpInForNotLiveClick => jumpinButtonForNotLive?.onClick; |
| 0 | 165 | | public Button.ButtonClickedEvent onInfoClick => infoButton?.onClick; |
| 0 | 166 | | public Button.ButtonClickedEvent onSubscribeClick => subscribeEventButton?.onClick; |
| 0 | 167 | | public Button.ButtonClickedEvent onUnsubscribeClick => unsubscribeEventButton?.onClick; |
| | 168 | |
|
| | 169 | | public override void Start() |
| | 170 | | { |
| 60 | 171 | | if (closeCardButton != null) |
| 29 | 172 | | closeCardButton.onClick.AddListener(CloseModal); |
| | 173 | |
|
| 60 | 174 | | if (closeAction != null) |
| 29 | 175 | | closeAction.OnTriggered += OnCloseActionTriggered; |
| | 176 | |
|
| 60 | 177 | | if (modalBackgroundButton != null) |
| 29 | 178 | | modalBackgroundButton.onClick.AddListener(CloseModal); |
| 60 | 179 | | } |
| | 180 | |
|
| | 181 | | public void Configure(EventCardComponentModel newModel) |
| | 182 | | { |
| 18 | 183 | | model = newModel; |
| 18 | 184 | | RefreshControl(); |
| 18 | 185 | | } |
| | 186 | |
|
| | 187 | | public override void RefreshControl() |
| | 188 | | { |
| 18 | 189 | | if (model == null) |
| 0 | 190 | | return; |
| | 191 | |
|
| 18 | 192 | | if (model.eventPictureSprite != null) |
| 18 | 193 | | SetEventPicture(model.eventPictureSprite); |
| 0 | 194 | | else if (model.eventPictureTexture != null) |
| 0 | 195 | | SetEventPicture(model.eventPictureTexture); |
| 0 | 196 | | else if (!string.IsNullOrEmpty(model.eventPictureUri)) |
| 0 | 197 | | SetEventPicture(model.eventPictureUri); |
| | 198 | | else |
| 0 | 199 | | SetEventPicture(sprite: null); |
| | 200 | |
|
| 18 | 201 | | SetEventAsLive(model.isLive); |
| 18 | 202 | | SetLiveTagText(model.liveTagText); |
| 18 | 203 | | SetEventDate(model.eventDateText); |
| 18 | 204 | | SetEventName(model.eventName); |
| 18 | 205 | | SetEventDescription(model.eventDescription); |
| 18 | 206 | | SetEventStartedIn(model.eventStartedIn); |
| 18 | 207 | | SetEventStartsInFromTo(model.eventStartsInFromTo); |
| 18 | 208 | | SetEventOrganizer(model.eventOrganizer); |
| 18 | 209 | | SetEventPlace(model.eventPlace); |
| 18 | 210 | | SetSubscribersUsers(model.subscribedUsers); |
| 18 | 211 | | SetCoords(model.coords); |
| | 212 | |
|
| 18 | 213 | | RebuildCardLayouts(); |
| 18 | 214 | | } |
| | 215 | |
|
| | 216 | | public override void OnFocus() |
| | 217 | | { |
| 29 | 218 | | base.OnFocus(); |
| | 219 | |
|
| 29 | 220 | | if (cardAnimator != null) |
| 29 | 221 | | cardAnimator.SetBool(ON_FOCUS_CARD_COMPONENT_BOOL, true); |
| 29 | 222 | | } |
| | 223 | |
|
| | 224 | | public override void OnLoseFocus() |
| | 225 | | { |
| 238 | 226 | | base.OnLoseFocus(); |
| | 227 | |
|
| 238 | 228 | | if (cardAnimator != null) |
| 193 | 229 | | cardAnimator.SetBool(ON_FOCUS_CARD_COMPONENT_BOOL, false); |
| 238 | 230 | | } |
| | 231 | |
|
| | 232 | | public override void Show(bool instant = false) |
| | 233 | | { |
| 4 | 234 | | base.Show(instant); |
| | 235 | |
|
| 4 | 236 | | DataStore.i.exploreV2.isSomeModalOpen.Set(true); |
| 4 | 237 | | } |
| | 238 | |
|
| | 239 | | public override void Hide(bool instant = false) |
| | 240 | | { |
| 40 | 241 | | base.Hide(instant); |
| | 242 | |
|
| 40 | 243 | | DataStore.i.exploreV2.isSomeModalOpen.Set(false); |
| 40 | 244 | | } |
| | 245 | |
|
| | 246 | | public override void Dispose() |
| | 247 | | { |
| 298 | 248 | | base.Dispose(); |
| | 249 | |
|
| 298 | 250 | | if (eventImage != null) |
| 298 | 251 | | eventImage.Dispose(); |
| | 252 | |
|
| 298 | 253 | | if (closeCardButton != null) |
| 125 | 254 | | closeCardButton.onClick.RemoveAllListeners(); |
| | 255 | |
|
| 298 | 256 | | if (closeAction != null) |
| 125 | 257 | | closeAction.OnTriggered -= OnCloseActionTriggered; |
| | 258 | |
|
| 298 | 259 | | if (modalBackgroundButton != null) |
| 125 | 260 | | modalBackgroundButton.onClick.RemoveAllListeners(); |
| 298 | 261 | | } |
| | 262 | |
|
| | 263 | | public void SetEventPicture(Sprite sprite) |
| | 264 | | { |
| 19 | 265 | | if (sprite == null && defaultPicture != null) |
| 0 | 266 | | sprite = defaultPicture; |
| | 267 | |
|
| 19 | 268 | | model.eventPictureSprite = sprite; |
| | 269 | |
|
| 19 | 270 | | if (eventImage == null) |
| 0 | 271 | | return; |
| | 272 | |
|
| 19 | 273 | | eventImage.SetImage(sprite); |
| 19 | 274 | | } |
| | 275 | |
|
| | 276 | | public void SetEventPicture(Texture2D texture) |
| | 277 | | { |
| 1 | 278 | | if (texture == null && defaultPicture != null) |
| | 279 | | { |
| 0 | 280 | | SetEventPicture(defaultPicture); |
| 0 | 281 | | return; |
| | 282 | | } |
| | 283 | |
|
| 1 | 284 | | model.eventPictureTexture = texture; |
| | 285 | |
|
| 1 | 286 | | if (!Application.isPlaying) |
| 0 | 287 | | return; |
| | 288 | |
|
| 1 | 289 | | if (eventImage == null) |
| 0 | 290 | | return; |
| | 291 | |
|
| 1 | 292 | | eventImage.SetImage(texture); |
| 1 | 293 | | } |
| | 294 | |
|
| | 295 | | public void SetEventPicture(string uri) |
| | 296 | | { |
| 1 | 297 | | if (string.IsNullOrEmpty(uri) && defaultPicture != null) |
| | 298 | | { |
| 0 | 299 | | SetEventPicture(defaultPicture); |
| 0 | 300 | | return; |
| | 301 | | } |
| | 302 | |
|
| 1 | 303 | | model.eventPictureUri = uri; |
| | 304 | |
|
| 1 | 305 | | if (!Application.isPlaying) |
| 0 | 306 | | return; |
| | 307 | |
|
| 1 | 308 | | if (eventImage == null) |
| 0 | 309 | | return; |
| | 310 | |
|
| 1 | 311 | | eventImage.SetImage(uri); |
| 1 | 312 | | } |
| | 313 | |
|
| | 314 | | public void SetEventAsLive(bool isLive) |
| | 315 | | { |
| 26 | 316 | | model.isLive = isLive; |
| | 317 | |
|
| 26 | 318 | | if (liveTag != null) |
| 26 | 319 | | liveTag.gameObject.SetActive(isLive); |
| | 320 | |
|
| 26 | 321 | | if (eventDateText != null) |
| 26 | 322 | | eventDateText.gameObject.SetActive(!isLive); |
| | 323 | |
|
| 26 | 324 | | if (jumpinButton != null) |
| 26 | 325 | | jumpinButton.gameObject.SetActive(isEventCardModal || isLive); |
| | 326 | |
|
| 26 | 327 | | if (jumpinButtonForNotLive) |
| 23 | 328 | | jumpinButtonForNotLive.gameObject.SetActive(!isEventCardModal && !isLive); |
| | 329 | |
|
| 26 | 330 | | if (subscribeEventButton != null) |
| 26 | 331 | | subscribeEventButton.gameObject.SetActive(!isLive && !model.isSubscribed); |
| | 332 | |
|
| 26 | 333 | | if (unsubscribeEventButton != null) |
| 26 | 334 | | unsubscribeEventButton.gameObject.SetActive(!isLive && model.isSubscribed); |
| | 335 | |
|
| 26 | 336 | | if (eventStartedInTitleForLive) |
| 23 | 337 | | eventStartedInTitleForLive.gameObject.SetActive(isLive); |
| | 338 | |
|
| 26 | 339 | | if (eventStartedInTitleForNotLive) |
| 23 | 340 | | eventStartedInTitleForNotLive.gameObject.SetActive(!isLive); |
| | 341 | |
|
| 26 | 342 | | if (subscribedUsersTitleForLive != null) |
| 23 | 343 | | subscribedUsersTitleForLive.gameObject.SetActive(isLive); |
| | 344 | |
|
| 26 | 345 | | if (subscribedUsersTitleForNotLive != null) |
| 23 | 346 | | subscribedUsersTitleForNotLive.gameObject.SetActive(!isLive); |
| 26 | 347 | | } |
| | 348 | |
|
| | 349 | | public void SetLiveTagText(string newText) |
| | 350 | | { |
| 19 | 351 | | model.liveTagText = newText; |
| | 352 | |
|
| 19 | 353 | | if (liveTag == null) |
| 0 | 354 | | return; |
| | 355 | |
|
| 19 | 356 | | liveTag.SetText(newText); |
| 19 | 357 | | } |
| | 358 | |
|
| | 359 | | public void SetEventDate(string newDate) |
| | 360 | | { |
| 19 | 361 | | model.eventDateText = newDate; |
| | 362 | |
|
| 19 | 363 | | if (eventDateText == null) |
| 0 | 364 | | return; |
| | 365 | |
|
| 19 | 366 | | eventDateText.text = newDate; |
| 19 | 367 | | } |
| | 368 | |
|
| | 369 | | public void SetEventName(string newText) |
| | 370 | | { |
| 19 | 371 | | model.eventName = newText; |
| | 372 | |
|
| 19 | 373 | | if (eventNameText == null) |
| 0 | 374 | | return; |
| | 375 | |
|
| 19 | 376 | | eventNameText.text = newText; |
| 19 | 377 | | } |
| | 378 | |
|
| | 379 | | public void SetEventDescription(string newText) |
| | 380 | | { |
| 19 | 381 | | model.eventDescription = newText; |
| | 382 | |
|
| 19 | 383 | | if (eventDescText == null) |
| 11 | 384 | | return; |
| | 385 | |
|
| 8 | 386 | | eventDescText.text = newText; |
| 8 | 387 | | } |
| | 388 | |
|
| | 389 | | public void SetEventStartedIn(string newText) |
| | 390 | | { |
| 19 | 391 | | model.eventStartedIn = newText; |
| | 392 | |
|
| 19 | 393 | | if (eventStartedInText == null) |
| 3 | 394 | | return; |
| | 395 | |
|
| 16 | 396 | | eventStartedInText.text = newText; |
| 16 | 397 | | } |
| | 398 | |
|
| | 399 | | public void SetEventStartsInFromTo(string newText) |
| | 400 | | { |
| 19 | 401 | | model.eventStartsInFromTo = newText; |
| | 402 | |
|
| 19 | 403 | | if (eventStartsInFromToText == null) |
| 15 | 404 | | return; |
| | 405 | |
|
| 4 | 406 | | eventStartsInFromToText.text = newText; |
| 4 | 407 | | } |
| | 408 | |
|
| | 409 | | public void SetEventOrganizer(string newText) |
| | 410 | | { |
| 19 | 411 | | model.eventOrganizer = newText; |
| | 412 | |
|
| 19 | 413 | | if (eventOrganizerText == null) |
| 15 | 414 | | return; |
| | 415 | |
|
| 4 | 416 | | eventOrganizerText.text = newText; |
| 4 | 417 | | } |
| | 418 | |
|
| | 419 | | public void SetEventPlace(string newText) |
| | 420 | | { |
| 19 | 421 | | model.eventPlace = newText; |
| | 422 | |
|
| 19 | 423 | | if (eventPlaceText == null) |
| 15 | 424 | | return; |
| | 425 | |
|
| 4 | 426 | | eventPlaceText.text = newText; |
| 4 | 427 | | } |
| | 428 | |
|
| | 429 | | public void SetSubscribersUsers(int newNumberOfUsers) |
| | 430 | | { |
| 22 | 431 | | model.subscribedUsers = newNumberOfUsers; |
| | 432 | |
|
| 22 | 433 | | if (subscribedUsersText == null) |
| 0 | 434 | | return; |
| | 435 | |
|
| 22 | 436 | | if (!isEventCardModal) |
| | 437 | | { |
| 17 | 438 | | subscribedUsersText.text = newNumberOfUsers.ToString(); |
| 17 | 439 | | } |
| | 440 | | else |
| | 441 | | { |
| 5 | 442 | | if (newNumberOfUsers > 0) |
| 4 | 443 | | subscribedUsersText.text = string.Format(USERS_CONFIRMED_MESSAGE, newNumberOfUsers); |
| | 444 | | else |
| 1 | 445 | | subscribedUsersText.text = NOBODY_CONFIRMED_MESSAGE; |
| | 446 | | } |
| 1 | 447 | | } |
| | 448 | |
|
| | 449 | | public void SetCoords(Vector2Int newCoords) |
| | 450 | | { |
| 19 | 451 | | model.coords = newCoords; |
| | 452 | |
|
| 19 | 453 | | if (jumpinButton == null || !isEventCardModal) |
| 15 | 454 | | return; |
| | 455 | |
|
| 4 | 456 | | jumpinButton.SetText($"{newCoords.x},{newCoords.y}"); |
| 4 | 457 | | } |
| | 458 | |
|
| | 459 | | public void SetLoadingIndicatorVisible(bool isVisible) |
| | 460 | | { |
| 2 | 461 | | imageContainer.SetActive(!isVisible); |
| 2 | 462 | | eventInfoContainer.SetActive(!isVisible); |
| 2 | 463 | | loadingSpinner.SetActive(isVisible); |
| 2 | 464 | | } |
| | 465 | |
|
| | 466 | | internal void RebuildCardLayouts() |
| | 467 | | { |
| 18 | 468 | | if (contentVerticalLayout != null) |
| 3 | 469 | | Utils.ForceRebuildLayoutImmediate(contentVerticalLayout.transform as RectTransform); |
| | 470 | |
|
| 18 | 471 | | if (infoVerticalLayout != null) |
| 3 | 472 | | Utils.ForceRebuildLayoutImmediate(infoVerticalLayout.transform as RectTransform); |
| | 473 | |
|
| 18 | 474 | | if (timeAndPlayersHorizontalLayout != null) |
| 15 | 475 | | Utils.ForceRebuildLayoutImmediate(timeAndPlayersHorizontalLayout.transform as RectTransform); |
| 18 | 476 | | } |
| | 477 | |
|
| 4 | 478 | | internal void CloseModal() { Hide(); } |
| | 479 | |
|
| 2 | 480 | | internal void OnCloseActionTriggered(DCLAction_Trigger action) { CloseModal(); } |
| | 481 | | } |