| | 1 | | using DCL; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public interface IPlacesAndEventsSectionComponentView |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// Highlights sub-section component. |
| | 8 | | /// </summary> |
| | 9 | | IHighlightsSubSectionComponentView HighlightsSubSectionView { get; } |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// Places sub-section component. |
| | 13 | | /// </summary> |
| | 14 | | IPlacesSubSectionComponentView PlacesSubSectionView { 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 | | IFavoritesSubSectionComponentView FavoritesSubSectionView { get; } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Open a sub-section. |
| | 28 | | /// </summary> |
| | 29 | | /// <param name="subSectionIndex">Sub-section index.</param> |
| | 30 | | void GoToSubsection(int subSectionIndex); |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Activates/deactivates the section. |
| | 34 | | /// </summary> |
| | 35 | | /// <param name="isActive"></param> |
| | 36 | | void SetActive(bool isActive); |
| | 37 | | } |
| | 38 | |
|
| | 39 | | public class PlacesAndEventsSectionComponentView : BaseComponentView, IPlacesAndEventsSectionComponentView |
| | 40 | | { |
| | 41 | | internal const int HIGHLIGHTS_SUB_SECTION_INDEX = 0; |
| | 42 | | internal const int PLACES_SUB_SECTION_INDEX = 1; |
| | 43 | | internal const int EVENTS_SUB_SECTION_INDEX = 2; |
| | 44 | | internal const int FAVORITES_SUB_SECTION_INDEX = 3; |
| | 45 | |
|
| | 46 | | [Header("Top Menu")] |
| | 47 | | [SerializeField] internal SectionSelectorComponentView subSectionSelector; |
| | 48 | |
|
| | 49 | | [Header("Sub-Sections")] |
| | 50 | | [SerializeField] internal HighlightsSubSectionComponentView highlightsSubSection; |
| | 51 | | [SerializeField] internal PlacesSubSectionComponentView placesSubSection; |
| | 52 | | [SerializeField] internal EventsSubSectionComponentView eventsSubSection; |
| | 53 | | [SerializeField] internal FavoritesSubSectionComponentView favoritesSubSection; |
| | 54 | |
|
| | 55 | | private Canvas canvas; |
| 42 | 56 | | private int currentSelectedIndex = -1; |
| | 57 | |
|
| | 58 | | public override void Awake() |
| | 59 | | { |
| 40 | 60 | | base.Awake(); |
| 40 | 61 | | canvas = GetComponent<Canvas>(); |
| 40 | 62 | | } |
| | 63 | |
|
| | 64 | | public override void Start() |
| | 65 | | { |
| 39 | 66 | | CreateSubSectionSelectorMappings(); |
| 39 | 67 | | SetActive(false); |
| 39 | 68 | | } |
| | 69 | |
|
| 0 | 70 | | public IHighlightsSubSectionComponentView HighlightsSubSectionView => highlightsSubSection; |
| 0 | 71 | | public IPlacesSubSectionComponentView PlacesSubSectionView => placesSubSection; |
| 0 | 72 | | public IEventsSubSectionComponentView EventsSubSectionView => eventsSubSection; |
| 0 | 73 | | public IFavoritesSubSectionComponentView FavoritesSubSectionView => favoritesSubSection; |
| | 74 | |
|
| | 75 | | public void GoToSubsection(int subSectionIndex) => |
| 3 | 76 | | subSectionSelector.GetSection(subSectionIndex)?.SelectToggle(reselectIfAlreadyOn: true); |
| | 77 | |
|
| | 78 | | public void SetActive(bool isActive) |
| | 79 | | { |
| 41 | 80 | | canvas.enabled = isActive; |
| | 81 | |
|
| | 82 | | //Temporary untill the full feature is released |
| 41 | 83 | | if(DataStore.i.HUDs.enableFavoritePlaces.Get()) |
| 0 | 84 | | subSectionSelector.EnableSection(FAVORITES_SUB_SECTION_INDEX); |
| | 85 | | else |
| 41 | 86 | | subSectionSelector.DisableSection(FAVORITES_SUB_SECTION_INDEX); |
| | 87 | |
|
| 41 | 88 | | highlightsSubSection.SetActive(isActive && currentSelectedIndex == HIGHLIGHTS_SUB_SECTION_INDEX); |
| 41 | 89 | | placesSubSection.SetActive(isActive && currentSelectedIndex == PLACES_SUB_SECTION_INDEX); |
| 41 | 90 | | eventsSubSection.SetActive(isActive && currentSelectedIndex == EVENTS_SUB_SECTION_INDEX); |
| 41 | 91 | | favoritesSubSection.SetActive(isActive && currentSelectedIndex == FAVORITES_SUB_SECTION_INDEX); |
| 41 | 92 | | } |
| | 93 | |
|
| | 94 | | public override void RefreshControl() |
| | 95 | | { |
| 0 | 96 | | highlightsSubSection.RefreshControl(); |
| 0 | 97 | | placesSubSection.RefreshControl(); |
| 0 | 98 | | eventsSubSection.RefreshControl(); |
| 0 | 99 | | favoritesSubSection.RefreshControl(); |
| 0 | 100 | | } |
| | 101 | |
|
| | 102 | | public override void Dispose() |
| | 103 | | { |
| 51 | 104 | | base.Dispose(); |
| | 105 | |
|
| 51 | 106 | | RemoveSectionSelectorMappings(); |
| 51 | 107 | | highlightsSubSection.Dispose(); |
| 51 | 108 | | placesSubSection.Dispose(); |
| 51 | 109 | | eventsSubSection.Dispose(); |
| 51 | 110 | | favoritesSubSection.Dispose(); |
| 51 | 111 | | } |
| | 112 | |
|
| | 113 | | internal void CreateSubSectionSelectorMappings() |
| | 114 | | { |
| 45 | 115 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 116 | | { |
| 53 | 117 | | highlightsSubSection.SetActive(isActive); |
| 53 | 118 | | currentSelectedIndex = HIGHLIGHTS_SUB_SECTION_INDEX; |
| 53 | 119 | | }); |
| 45 | 120 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 121 | | { |
| 3 | 122 | | placesSubSection.SetActive(isActive); |
| 3 | 123 | | currentSelectedIndex = PLACES_SUB_SECTION_INDEX; |
| 3 | 124 | | }); |
| 45 | 125 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 126 | | { |
| 3 | 127 | | eventsSubSection.SetActive(isActive); |
| 3 | 128 | | currentSelectedIndex = EVENTS_SUB_SECTION_INDEX; |
| 3 | 129 | | }); |
| 45 | 130 | | subSectionSelector.GetSection(FAVORITES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 131 | | { |
| 0 | 132 | | favoritesSubSection.SetActive(isActive); |
| 0 | 133 | | currentSelectedIndex = FAVORITES_SUB_SECTION_INDEX; |
| 0 | 134 | | }); |
| | 135 | |
|
| 45 | 136 | | placesSubSection.SetActive(false); |
| 45 | 137 | | eventsSubSection.SetActive(false); |
| 45 | 138 | | highlightsSubSection.SetActive(false); |
| 45 | 139 | | favoritesSubSection.SetActive(false); |
| | 140 | |
|
| 45 | 141 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.SelectToggle(reselectIfAlreadyOn: true); |
| 45 | 142 | | } |
| | 143 | |
|
| | 144 | | internal void RemoveSectionSelectorMappings() |
| | 145 | | { |
| 54 | 146 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 54 | 147 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 54 | 148 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 54 | 149 | | subSectionSelector.GetSection(FAVORITES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 54 | 150 | | } |
| | 151 | | } |