| | 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; |
| | 48 | |
|
| | 49 | | public override void Awake() |
| | 50 | | { |
| 45 | 51 | | base.Awake(); |
| 45 | 52 | | canvas = GetComponent<Canvas>(); |
| 45 | 53 | | } |
| | 54 | |
|
| | 55 | | public override void Start() |
| | 56 | | { |
| 44 | 57 | | CreateSubSectionSelectorMappings(); |
| 44 | 58 | | SetActive(false); |
| 44 | 59 | | } |
| | 60 | |
|
| 0 | 61 | | public IHighlightsSubSectionComponentView HighlightsSubSectionView => highlightsSubSection; |
| 0 | 62 | | public IPlacesSubSectionComponentView PlacesSubSectionView => placesSubSection; |
| 0 | 63 | | public IEventsSubSectionComponentView EventsSubSectionView => eventsSubSection; |
| | 64 | |
|
| | 65 | | public void GoToSubsection(int subSectionIndex) => |
| 3 | 66 | | subSectionSelector.GetSection(subSectionIndex)?.SelectToggle(reselectIfAlreadyOn: true); |
| | 67 | |
|
| | 68 | | public void SetActive(bool isActive) => |
| 46 | 69 | | canvas.enabled = isActive; |
| | 70 | |
|
| | 71 | | public override void RefreshControl() |
| | 72 | | { |
| 0 | 73 | | highlightsSubSection.RefreshControl(); |
| 0 | 74 | | placesSubSection.RefreshControl(); |
| 0 | 75 | | eventsSubSection.RefreshControl(); |
| 0 | 76 | | } |
| | 77 | |
|
| | 78 | | public override void Dispose() |
| | 79 | | { |
| 56 | 80 | | base.Dispose(); |
| | 81 | |
|
| 56 | 82 | | RemoveSectionSelectorMappings(); |
| 56 | 83 | | highlightsSubSection.Dispose(); |
| 56 | 84 | | placesSubSection.Dispose(); |
| 56 | 85 | | eventsSubSection.Dispose(); |
| 56 | 86 | | } |
| | 87 | |
|
| | 88 | | internal void CreateSubSectionSelectorMappings() |
| | 89 | | { |
| 50 | 90 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.AddListener(highlightsSubSection.SetActive |
| 50 | 91 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.AddListener(placesSubSection.SetActive); |
| 50 | 92 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.AddListener(eventsSubSection.SetActive); |
| | 93 | |
|
| 50 | 94 | | placesSubSection.SetActive(false); |
| 50 | 95 | | eventsSubSection.SetActive(false); |
| 50 | 96 | | highlightsSubSection.SetActive(false); |
| | 97 | |
|
| 50 | 98 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.SelectToggle(reselectIfAlreadyOn: true); |
| 50 | 99 | | } |
| | 100 | |
|
| | 101 | | internal void RemoveSectionSelectorMappings() |
| | 102 | | { |
| 59 | 103 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 59 | 104 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 59 | 105 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 59 | 106 | | } |
| | 107 | | } |