| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | public interface IPlacesAndEventsSectionComponentView |
| | 4 | | { |
| | 5 | | /// <summary> |
| | 6 | | /// Highlights sub-section component. |
| | 7 | | /// </summary> |
| | 8 | | IHighlightsSubSectionComponentView currentHighlightsSubSectionComponentView { get; } |
| | 9 | |
|
| | 10 | | /// <summary> |
| | 11 | | /// Places sub-section component. |
| | 12 | | /// </summary> |
| | 13 | | IPlacesSubSectionComponentView currentPlacesSubSectionComponentView { get; } |
| | 14 | |
|
| | 15 | | /// <summary> |
| | 16 | | /// Events sub-section component. |
| | 17 | | /// </summary> |
| | 18 | | IEventsSubSectionComponentView currentEventsSubSectionComponentView { 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 | | internal bool isDefaultSubSectionLoadedByFirstTime = false; |
| | 48 | |
|
| | 49 | | public override void Start() => |
| 12 | 50 | | CreateSubSectionSelectorMappings(); |
| | 51 | |
|
| 0 | 52 | | public IHighlightsSubSectionComponentView currentHighlightsSubSectionComponentView => highlightsSubSection; |
| 0 | 53 | | public IPlacesSubSectionComponentView currentPlacesSubSectionComponentView => placesSubSection; |
| 0 | 54 | | public IEventsSubSectionComponentView currentEventsSubSectionComponentView => eventsSubSection; |
| | 55 | |
|
| | 56 | | public void GoToSubsection(int subSectionIndex) => |
| 3 | 57 | | subSectionSelector.GetSection(subSectionIndex)?.SelectToggle(reselectIfAlreadyOn: true); |
| | 58 | |
|
| | 59 | | public void SetActive(bool isActive) => |
| 2 | 60 | | gameObject.SetActive(isActive); |
| | 61 | |
|
| | 62 | | public override void RefreshControl() |
| | 63 | | { |
| 0 | 64 | | highlightsSubSection.RefreshControl(); |
| 0 | 65 | | placesSubSection.RefreshControl(); |
| 0 | 66 | | eventsSubSection.RefreshControl(); |
| 0 | 67 | | } |
| | 68 | |
|
| | 69 | | public override void Dispose() |
| | 70 | | { |
| 23 | 71 | | base.Dispose(); |
| | 72 | |
|
| 23 | 73 | | RemoveSectionSelectorMappings(); |
| 23 | 74 | | highlightsSubSection.Dispose(); |
| 23 | 75 | | placesSubSection.Dispose(); |
| 23 | 76 | | eventsSubSection.Dispose(); |
| 23 | 77 | | } |
| | 78 | |
|
| | 79 | | internal void CreateSubSectionSelectorMappings() |
| | 80 | | { |
| 18 | 81 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX) |
| | 82 | | ?.onSelect.AddListener((isOn) => |
| | 83 | | { |
| 26 | 84 | | highlightsSubSection.gameObject.SetActive(isOn); |
| | 85 | |
|
| 26 | 86 | | isDefaultSubSectionLoadedByFirstTime = true; |
| 26 | 87 | | }); |
| | 88 | |
|
| 18 | 89 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX) |
| | 90 | | ?.onSelect.AddListener((isOn) => |
| | 91 | | { |
| 3 | 92 | | placesSubSection.gameObject.SetActive(isOn); |
| 3 | 93 | | }); |
| | 94 | |
|
| 18 | 95 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX) |
| | 96 | | ?.onSelect.AddListener((isOn) => |
| | 97 | | { |
| 3 | 98 | | eventsSubSection.gameObject.SetActive(isOn); |
| 3 | 99 | | }); |
| | 100 | |
|
| 18 | 101 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.SelectToggle(reselectIfAlreadyOn: true); |
| 18 | 102 | | } |
| | 103 | |
|
| | 104 | | internal void RemoveSectionSelectorMappings() |
| | 105 | | { |
| 26 | 106 | | subSectionSelector.GetSection(HIGHLIGHTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 26 | 107 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 26 | 108 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 26 | 109 | | } |
| | 110 | | } |