| | 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 IPlacesSubSectionComponentView |
| | 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 info button is clicked. |
| | 17 | | /// </summary> |
| | 18 | | event Action<PlaceCardComponentModel> OnInfoClicked; |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// It will be triggered when the JumpIn button is clicked. |
| | 22 | | /// </summary> |
| | 23 | | event Action<HotScenesController.HotSceneInfo> OnJumpInClicked; |
| | 24 | |
|
| | 25 | | /// <summary> |
| | 26 | | /// It will be triggered when a new friend handler is added by a place card. |
| | 27 | | /// </summary> |
| | 28 | | event Action<FriendsHandler> OnFriendHandlerAdded; |
| | 29 | |
|
| | 30 | | /// <summary> |
| | 31 | | /// It will be triggered each time the view is enabled. |
| | 32 | | /// </summary> |
| | 33 | | event Action OnPlacesSubSectionEnable; |
| | 34 | |
|
| | 35 | | /// <summary> |
| | 36 | | /// It will be triggered when the "Show More" button is clicked. |
| | 37 | | /// </summary> |
| | 38 | | event Action OnShowMorePlacesClicked; |
| | 39 | |
|
| | 40 | | /// <summary> |
| | 41 | | /// Colors used for the background of the friends heads. |
| | 42 | | /// </summary> |
| | 43 | | Color[] currentFriendColors { get; } |
| | 44 | |
|
| | 45 | | /// <summary> |
| | 46 | | /// Number of places per row that fit with the current places grid configuration. |
| | 47 | | /// </summary> |
| | 48 | | int currentPlacesPerRow { get; } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Set the places component with a list of places. |
| | 52 | | /// </summary> |
| | 53 | | /// <param name="places">List of places (model) to be loaded.</param> |
| | 54 | | void SetPlaces(List<PlaceCardComponentModel> places); |
| | 55 | |
|
| | 56 | | /// <summary> |
| | 57 | | /// Add a list of places in the places component. |
| | 58 | | /// </summary> |
| | 59 | | /// <param name="places">List of places (model) to be added.</param> |
| | 60 | | void AddPlaces(List<PlaceCardComponentModel> places); |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Set the places component in loading mode. |
| | 64 | | /// </summary> |
| | 65 | | /// <param name="isVisible">True for activating the loading mode.</param> |
| | 66 | | void SetPlacesAsLoading(bool isVisible); |
| | 67 | |
|
| | 68 | | /// <summary> |
| | 69 | | /// Activates/Deactivates the "Show More" button. |
| | 70 | | /// </summary> |
| | 71 | | /// <param name="isActive">True for activating it.</param> |
| | 72 | | void SetShowMorePlacesButtonActive(bool isActive); |
| | 73 | |
|
| | 74 | | /// <summary> |
| | 75 | | /// Shows the Place Card modal with the provided information. |
| | 76 | | /// </summary> |
| | 77 | | /// <param name="placeInfo">Place (model) to be loaded in the card.</param> |
| | 78 | | void ShowPlaceModal(PlaceCardComponentModel placeInfo); |
| | 79 | |
|
| | 80 | | /// <summary> |
| | 81 | | /// Hides the Place Card modal. |
| | 82 | | /// </summary> |
| | 83 | | void HidePlaceModal(); |
| | 84 | |
|
| | 85 | | /// <summary> |
| | 86 | | /// Set the current scroll view position to 1. |
| | 87 | | /// </summary> |
| | 88 | | void RestartScrollViewPosition(); |
| | 89 | | } |
| | 90 | |
|
| | 91 | | public class PlacesSubSectionComponentView : BaseComponentView, IPlacesSubSectionComponentView |
| | 92 | | { |
| | 93 | | internal const string PLACE_CARDS_POOL_NAME = "Places_PlaceCardsPool"; |
| | 94 | |
|
| | 95 | | [Header("Assets References")] |
| | 96 | | [SerializeField] internal PlaceCardComponentView placeCardPrefab; |
| | 97 | | [SerializeField] internal PlaceCardComponentView placeCardModalPrefab; |
| | 98 | |
|
| | 99 | | [Header("Prefab References")] |
| | 100 | | [SerializeField] internal ScrollRect scrollView; |
| | 101 | | [SerializeField] internal GridContainerComponentView places; |
| | 102 | | [SerializeField] internal GameObject placesLoading; |
| | 103 | | [SerializeField] internal TMP_Text placesNoDataText; |
| | 104 | | [SerializeField] internal Color[] friendColors = null; |
| | 105 | | [SerializeField] internal GameObject showMorePlacesButtonContainer; |
| | 106 | | [SerializeField] internal ButtonComponentView showMorePlacesButton; |
| | 107 | |
|
| | 108 | | public event Action OnReady; |
| | 109 | | public event Action<PlaceCardComponentModel> OnInfoClicked; |
| | 110 | | public event Action<HotScenesController.HotSceneInfo> OnJumpInClicked; |
| | 111 | | public event Action<FriendsHandler> OnFriendHandlerAdded; |
| | 112 | | public event Action OnPlacesSubSectionEnable; |
| | 113 | | public event Action OnShowMorePlacesClicked; |
| | 114 | |
|
| | 115 | | internal PlaceCardComponentView placeModal; |
| | 116 | | internal Pool placeCardsPool; |
| | 117 | |
|
| 0 | 118 | | public Color[] currentFriendColors => friendColors; |
| | 119 | |
|
| 0 | 120 | | public int currentPlacesPerRow => places.currentItemsPerRow; |
| | 121 | |
|
| 13 | 122 | | public override void OnEnable() { OnPlacesSubSectionEnable?.Invoke(); } |
| | 123 | |
|
| | 124 | | public override void Start() |
| | 125 | | { |
| 11 | 126 | | placeModal = ExplorePlacesHelpers.ConfigurePlaceCardModal(placeCardModalPrefab); |
| 11 | 127 | | ExplorePlacesHelpers.ConfigurePlaceCardsPool(out placeCardsPool, PLACE_CARDS_POOL_NAME, placeCardPrefab, 200); |
| | 128 | |
|
| 11 | 129 | | places.RemoveItems(); |
| | 130 | |
|
| 11 | 131 | | showMorePlacesButton.onClick.RemoveAllListeners(); |
| 11 | 132 | | showMorePlacesButton.onClick.AddListener(() => OnShowMorePlacesClicked?.Invoke()); |
| | 133 | |
|
| 11 | 134 | | OnReady?.Invoke(); |
| 0 | 135 | | } |
| | 136 | |
|
| 0 | 137 | | public override void RefreshControl() { places.RefreshControl(); } |
| | 138 | |
|
| | 139 | | public override void Dispose() |
| | 140 | | { |
| 85 | 141 | | base.Dispose(); |
| | 142 | |
|
| 85 | 143 | | showMorePlacesButton.onClick.RemoveAllListeners(); |
| | 144 | |
|
| 85 | 145 | | places.Dispose(); |
| | 146 | |
|
| 85 | 147 | | if (placeModal != null) |
| | 148 | | { |
| 15 | 149 | | placeModal.Dispose(); |
| 15 | 150 | | Destroy(placeModal.gameObject); |
| | 151 | | } |
| 85 | 152 | | } |
| | 153 | |
|
| | 154 | | public void SetPlaces(List<PlaceCardComponentModel> places) |
| | 155 | | { |
| 1 | 156 | | this.places.ExtractItems(); |
| 1 | 157 | | placeCardsPool.ReleaseAll(); |
| | 158 | |
|
| 1 | 159 | | List<BaseComponentView> placeComponentsToAdd = ExplorePlacesHelpers.InstantiateAndConfigurePlaceCards( |
| | 160 | | places, |
| | 161 | | placeCardsPool, |
| | 162 | | OnFriendHandlerAdded, |
| | 163 | | OnInfoClicked, |
| | 164 | | OnJumpInClicked); |
| | 165 | |
|
| 1 | 166 | | this.places.SetItems(placeComponentsToAdd); |
| 1 | 167 | | placesNoDataText.gameObject.SetActive(places.Count == 0); |
| 1 | 168 | | } |
| | 169 | |
|
| | 170 | | public void AddPlaces(List<PlaceCardComponentModel> places) |
| | 171 | | { |
| 1 | 172 | | List<BaseComponentView> placeComponentsToAdd = ExplorePlacesHelpers.InstantiateAndConfigurePlaceCards( |
| | 173 | | places, |
| | 174 | | placeCardsPool, |
| | 175 | | OnFriendHandlerAdded, |
| | 176 | | OnInfoClicked, |
| | 177 | | OnJumpInClicked); |
| | 178 | |
|
| 6 | 179 | | foreach (var place in placeComponentsToAdd) |
| | 180 | | { |
| 2 | 181 | | this.places.AddItem(place); |
| | 182 | | } |
| 1 | 183 | | } |
| | 184 | |
|
| | 185 | | public void SetPlacesAsLoading(bool isVisible) |
| | 186 | | { |
| 2 | 187 | | places.gameObject.SetActive(!isVisible); |
| 2 | 188 | | placesLoading.SetActive(isVisible); |
| | 189 | |
|
| 2 | 190 | | if (isVisible) |
| 1 | 191 | | placesNoDataText.gameObject.SetActive(false); |
| 2 | 192 | | } |
| | 193 | |
|
| 4 | 194 | | public void SetShowMorePlacesButtonActive(bool isActive) { showMorePlacesButtonContainer.gameObject.SetActive(isActi |
| | 195 | |
|
| | 196 | | public void ShowPlaceModal(PlaceCardComponentModel placeInfo) |
| | 197 | | { |
| 1 | 198 | | placeModal.Show(); |
| 1 | 199 | | ExplorePlacesHelpers.ConfigurePlaceCard(placeModal, placeInfo, OnInfoClicked, OnJumpInClicked); |
| 1 | 200 | | } |
| | 201 | |
|
| 2 | 202 | | public void HidePlaceModal() { placeModal.Hide(); } |
| | 203 | |
|
| 0 | 204 | | public void RestartScrollViewPosition() { scrollView.verticalNormalizedPosition = 1; } |
| | 205 | | } |