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