| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | public interface IExploreV2MenuComponentView : IDisposable |
| | 5 | | { |
| | 6 | | /// <summary> |
| | 7 | | /// It will be triggered when the view is fully initialized. |
| | 8 | | /// </summary> |
| | 9 | | event Action OnInitialized; |
| | 10 | |
|
| | 11 | | /// <summary> |
| | 12 | | /// It will be triggered when the close button is clicked. |
| | 13 | | /// </summary> |
| | 14 | | event Action OnCloseButtonPressed; |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Real viewer component. |
| | 18 | | /// </summary> |
| | 19 | | IRealmViewerComponentView currentRealmViewer { get; } |
| | 20 | |
|
| | 21 | | /// <summary> |
| | 22 | | /// Profile card component. |
| | 23 | | /// </summary> |
| | 24 | | IProfileCardComponentView currentProfileCard { get; } |
| | 25 | |
|
| | 26 | | /// <summary> |
| | 27 | | /// Places and Events section component. |
| | 28 | | /// </summary> |
| | 29 | | IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection { get; } |
| | 30 | |
|
| | 31 | | /// <summary> |
| | 32 | | /// Returns true if the game object is activated. |
| | 33 | | /// </summary> |
| | 34 | | bool isActive { get; } |
| | 35 | |
|
| | 36 | | /// <summary> |
| | 37 | | /// Activates/Deactivates the game object of the explore menu. |
| | 38 | | /// </summary> |
| | 39 | | /// <param name="isActive">True to activate it.</param> |
| | 40 | | void SetActive(bool isActive); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public class ExploreV2MenuComponentView : MonoBehaviour, IExploreV2MenuComponentView |
| | 44 | | { |
| | 45 | | [Header("Top Menu")] |
| | 46 | | [SerializeField] internal SectionSelectorComponentView sectionSelector; |
| | 47 | | [SerializeField] internal ProfileCardComponentView profileCard; |
| | 48 | | [SerializeField] internal RealmViewerComponentView realmViewer; |
| | 49 | | [SerializeField] internal ButtonComponentView closeMenuButton; |
| | 50 | | [SerializeField] internal InputAction_Trigger closeAction; |
| | 51 | |
|
| | 52 | | [Header("Sections")] |
| | 53 | | [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection; |
| | 54 | |
|
| 0 | 55 | | public bool isActive => gameObject.activeSelf; |
| | 56 | |
|
| 0 | 57 | | public GameObject go => this != null ? gameObject : null; |
| 0 | 58 | | public IRealmViewerComponentView currentRealmViewer => realmViewer; |
| 0 | 59 | | public IProfileCardComponentView currentProfileCard => profileCard; |
| 0 | 60 | | public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection; |
| | 61 | |
|
| | 62 | | public event Action OnInitialized; |
| | 63 | | public event Action OnCloseButtonPressed; |
| | 64 | |
|
| | 65 | | private void Start() |
| | 66 | | { |
| 0 | 67 | | if (sectionSelector.isFullyInitialized) |
| 0 | 68 | | CreateSectionSelectorMappings(); |
| | 69 | | else |
| 0 | 70 | | sectionSelector.OnFullyInitialized += CreateSectionSelectorMappings; |
| | 71 | |
|
| 0 | 72 | | if (closeMenuButton.isFullyInitialized) |
| 0 | 73 | | ConfigureCloseButton(); |
| | 74 | | else |
| 0 | 75 | | closeMenuButton.OnFullyInitialized += ConfigureCloseButton; |
| | 76 | |
|
| 0 | 77 | | OnInitialized?.Invoke(); |
| 0 | 78 | | } |
| | 79 | |
|
| | 80 | | private void OnDestroy() |
| | 81 | | { |
| 18 | 82 | | sectionSelector.OnFullyInitialized -= CreateSectionSelectorMappings; |
| 18 | 83 | | RemoveSectionSelectorMappings(); |
| 18 | 84 | | closeMenuButton.onClick.RemoveAllListeners(); |
| 18 | 85 | | } |
| | 86 | |
|
| 4 | 87 | | public void SetActive(bool isActive) { gameObject.SetActive(isActive); } |
| | 88 | |
|
| | 89 | | internal void CreateSectionSelectorMappings() |
| | 90 | | { |
| 15 | 91 | | sectionSelector.GetSection(0)?.onSelect.AddListener((isOn) => placesAndEventsSection.gameObject.SetActive(isOn)) |
| | 92 | |
|
| 14 | 93 | | ShowDefaultSection(); |
| 14 | 94 | | } |
| | 95 | |
|
| 49 | 96 | | internal void RemoveSectionSelectorMappings() { sectionSelector.GetSection(0)?.onSelect.RemoveAllListeners(); } |
| | 97 | |
|
| | 98 | | internal void ConfigureCloseButton() |
| | 99 | | { |
| 2 | 100 | | closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke()); |
| 1 | 101 | | closeAction.OnTriggered += (action) => OnCloseButtonPressed?.Invoke(); |
| 1 | 102 | | } |
| | 103 | |
|
| 30 | 104 | | internal void ShowDefaultSection() { placesAndEventsSection.gameObject.SetActive(true); } |
| | 105 | |
|
| | 106 | | internal static ExploreV2MenuComponentView Create() |
| | 107 | | { |
| 0 | 108 | | ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get |
| 0 | 109 | | exploreV2View.name = "_ExploreV2"; |
| | 110 | |
|
| 0 | 111 | | return exploreV2View; |
| | 112 | | } |
| | 113 | |
|
| 0 | 114 | | public void Dispose() { Destroy(gameObject); } |
| | 115 | | } |