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