| | 1 | | using DCL; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public interface IPlacesAndEventsSectionComponentView |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// Places sub-section component. |
| | 8 | | /// </summary> |
| | 9 | | IPlacesSubSectionComponentView PlacesSubSectionView { get; } |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// Places sub-section component. |
| | 13 | | /// </summary> |
| | 14 | | IWorldsSubSectionComponentView WorldsSubSectionView { get; } |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Events sub-section component. |
| | 18 | | /// </summary> |
| | 19 | | IEventsSubSectionComponentView EventsSubSectionView { get; } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Favorites sub-section component. |
| | 23 | | /// </summary> |
| | 24 | | IFavoriteSubSectionComponentView FavoritesSubSectionView { get; } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Favorites sub-section component. |
| | 28 | | /// </summary> |
| | 29 | | ISearchSubSectionComponentView SearchSubSectionView { get; } |
| | 30 | |
|
| | 31 | | SearchBarComponentView SearchBar { get; } |
| | 32 | |
|
| | 33 | | /// <summary> |
| | 34 | | /// Open a sub-section. |
| | 35 | | /// </summary> |
| | 36 | | /// <param name="subSectionIndex">Sub-section index.</param> |
| | 37 | | void GoToSubsection(int subSectionIndex); |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// Activates/deactivates the section. |
| | 41 | | /// </summary> |
| | 42 | | /// <param name="isActive"></param> |
| | 43 | | void SetActive(bool isActive); |
| | 44 | |
|
| | 45 | | void EnableSearchBar(bool isActive); |
| | 46 | | } |
| | 47 | |
|
| | 48 | | public class PlacesAndEventsSectionComponentView : BaseComponentView, IPlacesAndEventsSectionComponentView |
| | 49 | | { |
| | 50 | | internal const int PLACES_SUB_SECTION_INDEX = 0; |
| | 51 | | internal const int WORLDS_SUB_SECTION_INDEX = 1; |
| | 52 | | internal const int EVENTS_SUB_SECTION_INDEX = 2; |
| | 53 | | internal const int FAVORITES_SUB_SECTION_INDEX = 3; |
| | 54 | | internal const int SEARCH_SUB_SECTION_INDEX = 4; |
| | 55 | |
|
| | 56 | | internal const string WORLDS_SUBSECTION_FF = "worlds_subsection"; |
| | 57 | |
|
| | 58 | | [Header("Top Menu")] |
| | 59 | | [SerializeField] internal SectionSelectorComponentView subSectionSelector; |
| | 60 | |
|
| | 61 | | [Header("Sub-Sections")] |
| | 62 | | [SerializeField] internal PlacesSubSectionComponentView placesSubSection; |
| | 63 | | [SerializeField] internal WorldsSubSectionComponentView worldsSubSection; |
| | 64 | | [SerializeField] internal EventsSubSectionComponentView eventsSubSection; |
| | 65 | | [SerializeField] internal FavoriteSubSectionComponentView favoritesSubSection; |
| | 66 | | [SerializeField] internal SearchSubSectionComponentView searchSubSection; |
| | 67 | | [SerializeField] internal SearchBarComponentView searchBar; |
| | 68 | |
|
| | 69 | | private Canvas canvas; |
| 39 | 70 | | private int currentSelectedIndex = -1; |
| | 71 | |
|
| | 72 | | public override void Awake() |
| | 73 | | { |
| 37 | 74 | | base.Awake(); |
| 37 | 75 | | canvas = GetComponent<Canvas>(); |
| 37 | 76 | | } |
| | 77 | |
|
| | 78 | | public void Start() |
| | 79 | | { |
| 36 | 80 | | CreateSubSectionSelectorMappings(); |
| 36 | 81 | | SetActive(false); |
| 36 | 82 | | } |
| | 83 | |
|
| 0 | 84 | | public IPlacesSubSectionComponentView PlacesSubSectionView => placesSubSection; |
| 0 | 85 | | public IWorldsSubSectionComponentView WorldsSubSectionView => worldsSubSection; |
| 0 | 86 | | public IEventsSubSectionComponentView EventsSubSectionView => eventsSubSection; |
| 0 | 87 | | public IFavoriteSubSectionComponentView FavoritesSubSectionView => favoritesSubSection; |
| 0 | 88 | | public ISearchSubSectionComponentView SearchSubSectionView => searchSubSection; |
| 0 | 89 | | public SearchBarComponentView SearchBar => searchBar; |
| | 90 | |
|
| | 91 | | public void GoToSubsection(int subSectionIndex) => |
| 2 | 92 | | subSectionSelector.GetSection(subSectionIndex)?.SelectToggle(reselectIfAlreadyOn: true); |
| | 93 | |
|
| | 94 | | public void SetActive(bool isActive) |
| | 95 | | { |
| 38 | 96 | | canvas.enabled = isActive; |
| | 97 | |
|
| | 98 | | //Temporary untill the full feature is released |
| 38 | 99 | | if(DataStore.i.HUDs.enableFavoritePlaces.Get()) |
| 0 | 100 | | subSectionSelector.EnableSection(FAVORITES_SUB_SECTION_INDEX); |
| | 101 | | else |
| 38 | 102 | | subSectionSelector.DisableSection(FAVORITES_SUB_SECTION_INDEX); |
| | 103 | |
|
| | 104 | | //Temporary until the full feature is released |
| 38 | 105 | | if (DataStore.i.featureFlags.flags.Get().IsFeatureEnabled(WORLDS_SUBSECTION_FF)) |
| 0 | 106 | | subSectionSelector.EnableSection(WORLDS_SUB_SECTION_INDEX); |
| | 107 | | else |
| 38 | 108 | | subSectionSelector.DisableSection(WORLDS_SUB_SECTION_INDEX); |
| | 109 | |
|
| 38 | 110 | | placesSubSection.SetActive(isActive && currentSelectedIndex == PLACES_SUB_SECTION_INDEX); |
| 38 | 111 | | worldsSubSection.SetActive(isActive && currentSelectedIndex == WORLDS_SUB_SECTION_INDEX); |
| 38 | 112 | | eventsSubSection.SetActive(isActive && currentSelectedIndex == EVENTS_SUB_SECTION_INDEX); |
| 38 | 113 | | favoritesSubSection.SetActive(isActive && currentSelectedIndex == FAVORITES_SUB_SECTION_INDEX); |
| 38 | 114 | | searchSubSection.SetActive(isActive && currentSelectedIndex == SEARCH_SUB_SECTION_INDEX); |
| | 115 | |
|
| 38 | 116 | | if (!isActive) |
| | 117 | | { |
| 37 | 118 | | searchBar.ClearSearch(false); |
| 37 | 119 | | searchSubSection.SetHeaderEnabled(""); |
| | 120 | | } |
| 38 | 121 | | } |
| | 122 | |
|
| | 123 | | public void EnableSearchBar(bool isActive) |
| | 124 | | { |
| 0 | 125 | | searchBar.gameObject.SetActive(isActive); |
| 0 | 126 | | } |
| | 127 | |
|
| | 128 | | public override void RefreshControl() |
| | 129 | | { |
| 0 | 130 | | placesSubSection.RefreshControl(); |
| 0 | 131 | | worldsSubSection.RefreshControl(); |
| 0 | 132 | | eventsSubSection.RefreshControl(); |
| 0 | 133 | | favoritesSubSection.RefreshControl(); |
| 0 | 134 | | searchSubSection.RefreshControl(); |
| 0 | 135 | | } |
| | 136 | |
|
| | 137 | | public override void Dispose() |
| | 138 | | { |
| 45 | 139 | | base.Dispose(); |
| | 140 | |
|
| 45 | 141 | | RemoveSectionSelectorMappings(); |
| 45 | 142 | | placesSubSection.Dispose(); |
| 45 | 143 | | worldsSubSection.Dispose(); |
| 45 | 144 | | eventsSubSection.Dispose(); |
| 45 | 145 | | favoritesSubSection.Dispose(); |
| 45 | 146 | | searchSubSection.Dispose(); |
| 45 | 147 | | } |
| | 148 | |
|
| | 149 | | internal void CreateSubSectionSelectorMappings() |
| | 150 | | { |
| 40 | 151 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 152 | | { |
| 46 | 153 | | placesSubSection.SetActive(isActive); |
| 46 | 154 | | searchSubSection.SetActive(false); |
| 46 | 155 | | currentSelectedIndex = PLACES_SUB_SECTION_INDEX; |
| 46 | 156 | | }); |
| 40 | 157 | | subSectionSelector.GetSection(WORLDS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 158 | | { |
| 0 | 159 | | worldsSubSection.SetActive(isActive); |
| 0 | 160 | | searchSubSection.SetActive(false); |
| 0 | 161 | | currentSelectedIndex = WORLDS_SUB_SECTION_INDEX; |
| 0 | 162 | | }); |
| 40 | 163 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 164 | | { |
| 3 | 165 | | eventsSubSection.SetActive(isActive); |
| 3 | 166 | | searchSubSection.SetActive(false); |
| 3 | 167 | | currentSelectedIndex = EVENTS_SUB_SECTION_INDEX; |
| 3 | 168 | | }); |
| 40 | 169 | | subSectionSelector.GetSection(FAVORITES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 170 | | { |
| 0 | 171 | | favoritesSubSection.SetActive(isActive); |
| 0 | 172 | | searchSubSection.SetActive(false); |
| 0 | 173 | | currentSelectedIndex = FAVORITES_SUB_SECTION_INDEX; |
| 0 | 174 | | }); |
| 40 | 175 | | subSectionSelector.GetSection(SEARCH_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 176 | | { |
| 0 | 177 | | searchSubSection.SetActive(isActive); |
| 0 | 178 | | }); |
| | 179 | |
|
| 40 | 180 | | searchBar.OnSearchText += SearchTextChanged; |
| | 181 | |
|
| 40 | 182 | | placesSubSection.SetActive(false); |
| 40 | 183 | | worldsSubSection.SetActive(false); |
| 40 | 184 | | eventsSubSection.SetActive(false); |
| 40 | 185 | | favoritesSubSection.SetActive(false); |
| 40 | 186 | | searchSubSection.SetActive(false); |
| | 187 | |
|
| 40 | 188 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.SelectToggle(reselectIfAlreadyOn: true); |
| 40 | 189 | | } |
| | 190 | |
|
| | 191 | | private void SearchTextChanged(string searchText) |
| | 192 | | { |
| 0 | 193 | | if (string.IsNullOrEmpty(searchText)) |
| | 194 | | { |
| 0 | 195 | | subSectionSelector.GetSection(currentSelectedIndex)?.onSelect?.Invoke(true); |
| 0 | 196 | | subSectionSelector.GetSection(SEARCH_SUB_SECTION_INDEX)?.UnSelectToggle(true); |
| | 197 | | } |
| | 198 | | else |
| | 199 | | { |
| 0 | 200 | | subSectionSelector.GetSection(currentSelectedIndex)?.onSelect?.Invoke(false); |
| 0 | 201 | | subSectionSelector.GetSection(SEARCH_SUB_SECTION_INDEX)?.SelectToggle(true); |
| | 202 | | } |
| 0 | 203 | | } |
| | 204 | |
|
| | 205 | | internal void RemoveSectionSelectorMappings() |
| | 206 | | { |
| 47 | 207 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 47 | 208 | | subSectionSelector.GetSection(WORLDS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 47 | 209 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 47 | 210 | | subSectionSelector.GetSection(FAVORITES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 47 | 211 | | subSectionSelector.GetSection(SEARCH_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 47 | 212 | | } |
| | 213 | | } |