| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | public interface IPlacesAndEventsSectionComponentView |
| | 4 | | { |
| | 5 | | /// <summary> |
| | 6 | | /// Highlights sub-section component. |
| | 7 | | /// </summary> |
| | 8 | | IHighlightsSubSectionComponentView HighlightsSubSectionView { get; } |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// Places sub-section component. |
| | 12 | | /// </summary> |
| | 13 | | IPlacesSubSectionComponentView PlacesSubSectionView { get; } |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// Events sub-section component. |
| | 17 | | /// </summary> |
| | 18 | | IEventsSubSectionComponentView EventsSubSectionView { get; } |
| | 19 | |
|
| | 20 | | /// <summary> |
| | 21 | | /// Open a sub-section. |
| | 22 | | /// </summary> |
| | 23 | | /// <param name="subSectionIndex">Sub-section index.</param> |
| | 24 | | void GoToSubsection(int subSectionIndex); |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Activates/deactivates the section. |
| | 28 | | /// </summary> |
| | 29 | | /// <param name="isActive"></param> |
| | 30 | | void SetActive(bool isActive); |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public class PlacesAndEventsSectionComponentView : BaseComponentView, IPlacesAndEventsSectionComponentView |
| | 34 | | { |
| | 35 | | internal const int HIGHLIGHTS_SUB_SECTION_INDEX = 0; |
| | 36 | | internal const int PLACES_SUB_SECTION_INDEX = 1; |
| | 37 | | internal const int EVENTS_SUB_SECTION_INDEX = 2; |
| | 38 | |
|
| | 39 | | [Header("Top Menu")] |
| | 40 | | [SerializeField] internal SectionSelectorComponentView subSectionSelector; |
| | 41 | |
|
| | 42 | | [Header("Sub-Sections")] |
| | 43 | | [SerializeField] internal HighlightsSubSectionComponentView highlightsSubSection; |
| | 44 | | [SerializeField] internal PlacesSubSectionComponentView placesSubSection; |
| | 45 | | [SerializeField] internal EventsSubSectionComponentView eventsSubSection; |
| | 46 | |
|
| | 47 | | private Canvas canvas; |
| 42 | 48 | | private int currentSelectedIndex = -1; |
| | 49 | |
|
| | 50 | | public override void Awake() |
| | 51 | | { |
| 40 | 52 | | base.Awake(); |
| 40 | 53 | | canvas = GetComponent<Canvas>(); |
| 40 | 54 | | } |
| | 55 | |
|
| | 56 | | public override void Start() |
| | 57 | | { |
| 39 | 58 | | CreateSubSectionSelectorMappings(); |
| 39 | 59 | | SetActive(false); |
| 39 | 60 | | } |
| | 61 | |
|
| 0 | 62 | | public IHighlightsSubSectionComponentView HighlightsSubSectionView => highlightsSubSection; |
| 0 | 63 | | public IPlacesSubSectionComponentView PlacesSubSectionView => placesSubSection; |
| 0 | 64 | | public IEventsSubSectionComponentView EventsSubSectionView => eventsSubSection; |
| | 65 | |
|
| | 66 | | public void GoToSubsection(int subSectionIndex) => |
| 3 | 67 | | subSectionSelector.GetSection(subSectionIndex)?.SelectToggle(reselectIfAlreadyOn: true); |
| | 68 | |
|
| | 69 | | public void SetActive(bool isActive) |
| | 70 | | { |
| 41 | 71 | | canvas.enabled = isActive; |
| | 72 | |
|
| 41 | 73 | | highlightsSubSection.SetActive(isActive && currentSelectedIndex == HIGHLIGHTS_SUB_SECTION_INDEX); |
| 41 | 74 | | placesSubSection.SetActive(isActive && currentSelectedIndex == PLACES_SUB_SECTION_INDEX); |
| 41 | 75 | | eventsSubSection.SetActive(isActive && currentSelectedIndex == EVENTS_SUB_SECTION_INDEX); |
| 41 | 76 | | } |
| | 77 | |
|
| | 78 | | public override void RefreshControl() |
| | 79 | | { |
| 0 | 80 | | highlightsSubSection.RefreshControl(); |
| 0 | 81 | | placesSubSection.RefreshControl(); |
| 0 | 82 | | eventsSubSection.RefreshControl(); |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | public override void Dispose() |
| | 86 | | { |
| 51 | 87 | | base.Dispose(); |
| | 88 | |
|
| 51 | 89 | | RemoveSectionSelectorMappings(); |
| 51 | 90 | | highlightsSubSection.Dispose(); |
| 51 | 91 | | placesSubSection.Dispose(); |
| 51 | 92 | | eventsSubSection.Dispose(); |
| 51 | 93 | | } |
| | 94 | |
|
| | 95 | | internal void CreateSubSectionSelectorMappings() |
| | 96 | | { |
| 45 | 97 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 98 | | { |
| 53 | 99 | | highlightsSubSection.SetActive(isActive); |
| 53 | 100 | | currentSelectedIndex = HIGHLIGHTS_SUB_SECTION_INDEX; |
| 53 | 101 | | }); |
| 45 | 102 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 103 | | { |
| 3 | 104 | | placesSubSection.SetActive(isActive); |
| 3 | 105 | | currentSelectedIndex = PLACES_SUB_SECTION_INDEX; |
| 3 | 106 | | }); |
| 45 | 107 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.AddListener((isActive) => |
| | 108 | | { |
| 3 | 109 | | eventsSubSection.SetActive(isActive); |
| 3 | 110 | | currentSelectedIndex = EVENTS_SUB_SECTION_INDEX; |
| 3 | 111 | | }); |
| | 112 | |
|
| 45 | 113 | | placesSubSection.SetActive(false); |
| 45 | 114 | | eventsSubSection.SetActive(false); |
| 45 | 115 | | highlightsSubSection.SetActive(false); |
| | 116 | |
|
| 45 | 117 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.SelectToggle(reselectIfAlreadyOn: true); |
| 45 | 118 | | } |
| | 119 | |
|
| | 120 | | internal void RemoveSectionSelectorMappings() |
| | 121 | | { |
| 54 | 122 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 54 | 123 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 54 | 124 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 54 | 125 | | } |
| | 126 | | } |