| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public interface IPlacesAndEventsSectionComponentView |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// It will be triggered when any action is executed inside the places and events section. |
| | 8 | | /// </summary> |
| | 9 | | event Action OnAnyActionExecuted; |
| | 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 | |
|
| | 22 | | public class PlacesAndEventsSectionComponentView : BaseComponentView, IPlacesAndEventsSectionComponentView |
| | 23 | | { |
| | 24 | | internal const int PLACES_SUB_SECTION_INDEX = 0; |
| | 25 | | internal const int EVENTS_SUB_SECTION_INDEX = 1; |
| | 26 | |
|
| | 27 | | [Header("Top Menu")] |
| | 28 | | [SerializeField] internal SectionSelectorComponentView subSectionSelector; |
| | 29 | |
|
| | 30 | | [Header("Sections")] |
| | 31 | | [SerializeField] internal PlacesSubSectionComponentView placesSubSection; |
| | 32 | | [SerializeField] internal EventsSubSectionComponentView eventsSubSection; |
| | 33 | |
|
| | 34 | | internal bool isDefaultSubSectionLoadedByFirstTime = false; |
| | 35 | |
|
| 0 | 36 | | public IEventsSubSectionComponentView currentEventsSubSectionComponentView => eventsSubSection; |
| 0 | 37 | | public IPlacesSubSectionComponentView currentPlacesSubSectionComponentView => placesSubSection; |
| | 38 | |
|
| | 39 | | public event Action OnAnyActionExecuted; |
| | 40 | |
|
| 12 | 41 | | public override void Start() { CreateSubSectionSelectorMappings(); } |
| | 42 | |
|
| 0 | 43 | | public override void RefreshControl() { } |
| | 44 | |
|
| | 45 | | public override void Dispose() |
| | 46 | | { |
| 11 | 47 | | base.Dispose(); |
| | 48 | |
|
| 11 | 49 | | RemoveSectionSelectorMappings(); |
| 11 | 50 | | placesSubSection.Dispose(); |
| 11 | 51 | | eventsSubSection.Dispose(); |
| 11 | 52 | | } |
| | 53 | |
|
| | 54 | | internal void CreateSubSectionSelectorMappings() |
| | 55 | | { |
| 10 | 56 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX) |
| | 57 | | ?.onSelect.AddListener((isOn) => |
| | 58 | | { |
| 10 | 59 | | placesSubSection.gameObject.SetActive(isOn); |
| | 60 | |
|
| 10 | 61 | | if (isDefaultSubSectionLoadedByFirstTime) |
| 4 | 62 | | OnAnyActionExecuted?.Invoke(); |
| 6 | 63 | | }); |
| | 64 | |
|
| 10 | 65 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX) |
| | 66 | | ?.onSelect.AddListener((isOn) => |
| | 67 | | { |
| 14 | 68 | | eventsSubSection.gameObject.SetActive(isOn); |
| | 69 | |
|
| 14 | 70 | | if (isDefaultSubSectionLoadedByFirstTime) |
| 8 | 71 | | OnAnyActionExecuted?.Invoke(); |
| | 72 | |
|
| 14 | 73 | | isDefaultSubSectionLoadedByFirstTime = true; |
| 14 | 74 | | }); |
| | 75 | |
|
| 10 | 76 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.SelectToggle(true); |
| 10 | 77 | | } |
| | 78 | |
|
| | 79 | | internal void RemoveSectionSelectorMappings() |
| | 80 | | { |
| 13 | 81 | | subSectionSelector.GetSection(PLACES_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 13 | 82 | | subSectionSelector.GetSection(EVENTS_SUB_SECTION_INDEX)?.onSelect.RemoveAllListeners(); |
| 13 | 83 | | } |
| | 84 | | } |