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