| | 1 | | using DCL; |
| | 2 | | using DCL.Wallet; |
| | 3 | | using System; |
| | 4 | | using System.Collections; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.Events; |
| | 8 | |
|
| | 9 | | public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView |
| | 10 | | { |
| | 11 | | internal const string REALM_SELECTOR_MODAL_ID = "RealmSelector_Modal"; |
| | 12 | |
|
| | 13 | | [Header("Assets References")] |
| | 14 | | [SerializeField] internal RealmSelectorComponentView realmSelectorModalPrefab; |
| | 15 | |
|
| | 16 | | [Header("Top Menu")] |
| | 17 | | [SerializeField] internal SectionSelectorComponentView sectionSelector; |
| | 18 | | [SerializeField] internal WalletCardHUDComponentView walletCard; |
| | 19 | | [SerializeField] internal ProfileCardComponentView profileCard; |
| | 20 | | [SerializeField] internal RealmViewerComponentView realmViewer; |
| | 21 | | [SerializeField] internal ButtonComponentView closeMenuButton; |
| | 22 | | [SerializeField] internal InputAction_Trigger closeAction; |
| | 23 | |
|
| | 24 | | [Header("Sections")] |
| | 25 | | [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection; |
| | 26 | | [SerializeField] internal FeatureEncapsulatorComponentView backpackSection; |
| | 27 | | [SerializeField] internal FeatureEncapsulatorComponentView cameraReelSection; |
| | 28 | | [SerializeField] internal FeatureEncapsulatorComponentView mapSection; |
| | 29 | | [SerializeField] internal FeatureEncapsulatorComponentView questSection; |
| | 30 | | [SerializeField] internal FeatureEncapsulatorComponentView settingsSection; |
| | 31 | | [SerializeField] internal FeatureEncapsulatorComponentView walletSection; |
| | 32 | | [SerializeField] internal FeatureEncapsulatorComponentView myAccountSection; |
| | 33 | |
|
| | 34 | | [Header("Tutorial References")] |
| | 35 | | [SerializeField] internal RectTransform profileCardTooltipReference; |
| | 36 | |
|
| | 37 | | private DataStore_Camera cameraDataStore; |
| | 38 | |
|
| | 39 | | private Dictionary<ExploreSection, FeatureEncapsulatorComponentView> exploreSectionsById; |
| | 40 | | private HUDCanvasCameraModeController hudCanvasCameraModeController; |
| | 41 | |
|
| | 42 | | private RectTransform profileCardRectTransform; |
| | 43 | | private RealmSelectorComponentView realmSelectorModal; |
| | 44 | | private bool isOpeningSectionThisFrame; |
| | 45 | |
|
| 0 | 46 | | public IRealmViewerComponentView currentRealmViewer => realmViewer; |
| 0 | 47 | | public IRealmSelectorComponentView currentRealmSelectorModal => realmSelectorModal; |
| 58 | 48 | | public IWalletCardHUDComponentView currentWalletCard => walletCard; |
| 0 | 49 | | public IProfileCardComponentView currentProfileCard => profileCard; |
| 0 | 50 | | public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection; |
| | 51 | |
|
| 0 | 52 | | public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explore).pivot |
| 0 | 53 | | public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor |
| 0 | 54 | | public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv |
| 0 | 55 | | public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot; |
| 0 | 56 | | public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot; |
| 0 | 57 | | public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv |
| 0 | 58 | | public RectTransform cameraReelTooltipReference => sectionSelector.GetSection((int)ExploreSection.CameraReel).pivot; |
| 0 | 59 | | public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference; |
| | 60 | |
|
| | 61 | | public event Action<bool> OnCloseButtonPressed; |
| | 62 | | public event Action<ExploreSection> OnSectionOpen; |
| | 63 | | public event Action OnAfterShowAnimation; |
| | 64 | |
|
| | 65 | | public override void Dispose() |
| | 66 | | { |
| 29 | 67 | | base.Dispose(); |
| | 68 | |
|
| 29 | 69 | | RemoveSectionSelectorMappings(); |
| 29 | 70 | | closeMenuButton.onClick.RemoveAllListeners(); |
| 29 | 71 | | currentWalletCard.OnWalletCardClicked -= OpenCurrentWalletSection; |
| 29 | 72 | | closeAction.OnTriggered -= OnCloseActionTriggered; |
| 29 | 73 | | DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange; |
| 29 | 74 | | DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange; |
| 29 | 75 | | DataStore.i.myAccount.myAccountSectionOpenFromProfileHUD.OnChange -= OpenMyAccountSection; |
| | 76 | |
|
| 29 | 77 | | if (realmSelectorModal != null) |
| 29 | 78 | | realmSelectorModal.Dispose(); |
| 29 | 79 | | } |
| | 80 | |
|
| | 81 | | public override void Awake() |
| | 82 | | { |
| 29 | 83 | | base.Awake(); |
| 29 | 84 | | showHideAnimator.OnWillFinishStart += OnAfterShowAnimationCompleted; |
| | 85 | |
|
| 29 | 86 | | profileCardRectTransform = profileCard.GetComponent<RectTransform>(); |
| 29 | 87 | | realmSelectorModal = ConfigureRealmSelectorModal(); |
| 29 | 88 | | hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud |
| | 89 | |
|
| 29 | 90 | | exploreSectionsById = new Dictionary<ExploreSection, FeatureEncapsulatorComponentView> |
| | 91 | | { |
| | 92 | | { ExploreSection.Explore, null }, |
| | 93 | | { ExploreSection.Quest, questSection }, |
| | 94 | | { ExploreSection.Backpack, backpackSection }, |
| | 95 | | { ExploreSection.CameraReel, cameraReelSection }, |
| | 96 | | { ExploreSection.Map, mapSection }, |
| | 97 | | { ExploreSection.Settings, settingsSection }, |
| | 98 | | { ExploreSection.Wallet, walletSection }, |
| | 99 | | { ExploreSection.MyAccount, myAccountSection }, |
| | 100 | | }; |
| 29 | 101 | | } |
| | 102 | |
|
| | 103 | | public void Start() |
| | 104 | | { |
| 29 | 105 | | DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange; |
| 29 | 106 | | DataStore.i.myAccount.myAccountSectionOpenFromProfileHUD.OnChange += OpenMyAccountSection; |
| 29 | 107 | | IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false); |
| | 108 | |
|
| 29 | 109 | | ConfigureCloseButton(); |
| | 110 | |
|
| 29 | 111 | | currentWalletCard.OnWalletCardClicked += OpenCurrentWalletSection; |
| 29 | 112 | | } |
| | 113 | |
|
| | 114 | | public void Update() => |
| 0 | 115 | | CheckIfProfileCardShouldBeClosed(); |
| | 116 | |
|
| | 117 | | public void OnDestroy() => |
| 29 | 118 | | hudCanvasCameraModeController?.Dispose(); |
| | 119 | |
|
| | 120 | | internal static ExploreV2MenuComponentView Create() |
| | 121 | | { |
| 0 | 122 | | ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get |
| 0 | 123 | | exploreV2View.name = "_ExploreV2"; |
| | 124 | |
|
| 0 | 125 | | return exploreV2View; |
| | 126 | | } |
| | 127 | |
|
| | 128 | | private void IsInitialized_OnChange(bool current, bool previous) |
| | 129 | | { |
| 29 | 130 | | if (!current) |
| 0 | 131 | | return; |
| | 132 | |
|
| 29 | 133 | | DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange; |
| 29 | 134 | | StartCoroutine(CreateSectionSelectorMappingsAfterDelay()); |
| 29 | 135 | | } |
| | 136 | |
|
| | 137 | | private IEnumerator CreateSectionSelectorMappingsAfterDelay() |
| | 138 | | { |
| 29 | 139 | | yield return null; |
| 0 | 140 | | CreateSectionSelectorMappings(); |
| 0 | 141 | | } |
| | 142 | |
|
| | 143 | | internal void CreateSectionSelectorMappings() |
| | 144 | | { |
| 180 | 145 | | foreach (ExploreSection sectionId in Enum.GetValues(typeof(ExploreSection))) |
| 80 | 146 | | sectionSelector.GetSection((int)sectionId) |
| | 147 | | ?.onSelect.AddListener(OnSectionSelected(sectionId)); |
| 10 | 148 | | } |
| | 149 | |
|
| | 150 | | private void OpenCurrentWalletSection() |
| | 151 | | { |
| 0 | 152 | | HideAllSections(); |
| | 153 | |
|
| 0 | 154 | | foreach (ISectionToggle section in sectionSelector.GetAllSections()) |
| 0 | 155 | | section?.SetUnselectedVisuals(); |
| | 156 | |
|
| 0 | 157 | | SelectSection(ExploreSection.Wallet, true); |
| 0 | 158 | | } |
| | 159 | |
|
| | 160 | | private void OpenMyAccountSection(bool current, bool previous) |
| | 161 | | { |
| 0 | 162 | | if (!current) |
| 0 | 163 | | return; |
| | 164 | |
|
| 0 | 165 | | HideAllSections(); |
| | 166 | |
|
| 0 | 167 | | foreach (ISectionToggle section in sectionSelector.GetAllSections()) |
| 0 | 168 | | section?.SetUnselectedVisuals(); |
| | 169 | |
|
| 0 | 170 | | SelectSection(ExploreSection.MyAccount, true); |
| 0 | 171 | | } |
| | 172 | |
|
| | 173 | | private UnityAction<bool> OnSectionSelected(ExploreSection sectionId) => |
| 60 | 174 | | isOn => |
| | 175 | | { |
| 5 | 176 | | if (exploreSectionsById[ExploreSection.Wallet].isVisible) |
| 0 | 177 | | exploreSectionsById[ExploreSection.Wallet].Hide(); |
| | 178 | |
|
| 5 | 179 | | if (exploreSectionsById[ExploreSection.MyAccount].isVisible) |
| 0 | 180 | | exploreSectionsById[ExploreSection.MyAccount].Hide(); |
| | 181 | |
|
| 5 | 182 | | SelectSection(sectionId, isOn); |
| 5 | 183 | | }; |
| | 184 | |
|
| | 185 | | private void SelectSection(ExploreSection sectionId, bool isOn) |
| | 186 | | { |
| 5 | 187 | | FeatureEncapsulatorComponentView sectionView = exploreSectionsById[sectionId]; |
| | 188 | |
|
| 5 | 189 | | if (isOn) |
| | 190 | | { |
| 5 | 191 | | if (isOpeningSectionThisFrame) |
| 0 | 192 | | return; |
| | 193 | |
|
| 5 | 194 | | isOpeningSectionThisFrame = true; |
| 5 | 195 | | StartCoroutine(ResetSectionOpenLock()); |
| | 196 | |
|
| | 197 | | // If not an explorer Section, because we do not Show/Hide it |
| 5 | 198 | | if (sectionView != null) |
| 4 | 199 | | sectionView.Show(); |
| | 200 | |
|
| 5 | 201 | | OnSectionOpen?.Invoke(sectionId); |
| | 202 | | } |
| 0 | 203 | | else if (sectionView != null) // If not an explorer Section, because we do not Show/Hide it |
| 0 | 204 | | sectionView.Hide(); |
| 0 | 205 | | } |
| | 206 | |
|
| | 207 | | private IEnumerator ResetSectionOpenLock() |
| | 208 | | { |
| 5 | 209 | | yield return null; |
| 0 | 210 | | isOpeningSectionThisFrame = false; |
| 0 | 211 | | } |
| | 212 | |
|
| | 213 | | public void SetVisible(bool visible) |
| | 214 | | { |
| 2 | 215 | | if (visible) |
| | 216 | | { |
| 1 | 217 | | DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true); |
| 1 | 218 | | Show(); |
| | 219 | |
|
| 1 | 220 | | ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get()); |
| | 221 | |
|
| 1 | 222 | | if (sectionToGo != null && sectionToGo.IsActive()) |
| 1 | 223 | | GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get()); |
| | 224 | | else |
| 0 | 225 | | GoToFirstActiveSection(); |
| | 226 | | } |
| | 227 | | else |
| | 228 | | { |
| 1 | 229 | | Hide(); |
| 1 | 230 | | AudioScriptableObjects.dialogClose.Play(true); |
| | 231 | | } |
| 1 | 232 | | } |
| | 233 | |
|
| | 234 | | private void GoToFirstActiveSection() |
| | 235 | | { |
| 0 | 236 | | foreach (ISectionToggle section in sectionSelector.GetAllSections()) |
| 0 | 237 | | if (section != null && section.IsActive()) |
| | 238 | | { |
| 0 | 239 | | section.SelectToggle(reselectIfAlreadyOn: true); |
| 0 | 240 | | break; |
| | 241 | | } |
| 0 | 242 | | } |
| | 243 | |
|
| | 244 | | public void GoToSection(ExploreSection section) |
| | 245 | | { |
| 1 | 246 | | sectionSelector.GetSection((int)section)?.SelectToggle(reselectIfAlreadyOn: true); |
| | 247 | |
|
| 1 | 248 | | AudioScriptableObjects.dialogOpen.Play(true); |
| 1 | 249 | | AudioScriptableObjects.listItemAppear.ResetPitch(); |
| 1 | 250 | | } |
| | 251 | |
|
| | 252 | | public void SetSectionActive(ExploreSection section, bool isActive) => |
| 10 | 253 | | sectionSelector.GetSection((int)section)?.SetActive(isActive); |
| | 254 | |
|
| | 255 | | public void SetSectionAsNew(ExploreSection section, bool isNew) => |
| 0 | 256 | | sectionSelector.GetSection((int)section)?.SetAsNew(isNew); |
| | 257 | |
|
| | 258 | | public bool IsSectionActive(ExploreSection section) |
| | 259 | | { |
| 0 | 260 | | var sectionToCheck = sectionSelector.GetSection((int)section); |
| 0 | 261 | | return sectionToCheck != null && sectionToCheck.IsActive(); |
| | 262 | | } |
| | 263 | |
|
| | 264 | | private void OnAfterShowAnimationCompleted(ShowHideAnimator _) |
| | 265 | | { |
| 0 | 266 | | if (!DataStore.i.exploreV2.isOpen.Get()) |
| 0 | 267 | | return; |
| | 268 | |
|
| 0 | 269 | | DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false); |
| 0 | 270 | | OnAfterShowAnimation?.Invoke(); |
| 0 | 271 | | } |
| | 272 | |
|
| | 273 | | public void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag) |
| 4 | 274 | | exploreSectionsById[sectionId]?.EncapsulateFeature(featureConfiguratorFlag); |
| | 275 | |
|
| | 276 | | public override void RefreshControl() |
| | 277 | | { |
| 0 | 278 | | placesAndEventsSection.RefreshControl(); |
| | 279 | |
|
| 0 | 280 | | foreach (ExploreSection section in exploreSectionsById.Keys) |
| 0 | 281 | | exploreSectionsById[section]?.RefreshControl(); |
| 0 | 282 | | } |
| | 283 | |
|
| | 284 | | internal void RemoveSectionSelectorMappings() |
| | 285 | | { |
| 612 | 286 | | foreach (int sectionId in Enum.GetValues(typeof(ExploreSection))) |
| 272 | 287 | | sectionSelector.GetSection(sectionId)?.onSelect.RemoveAllListeners(); |
| 34 | 288 | | } |
| | 289 | |
|
| | 290 | | private void IsSomeModalOpen_OnChange(bool current, bool previous) |
| | 291 | | { |
| 20 | 292 | | closeAction.OnTriggered -= OnCloseActionTriggered; |
| | 293 | |
|
| 20 | 294 | | if (!current) |
| 10 | 295 | | closeAction.OnTriggered += OnCloseActionTriggered; |
| 20 | 296 | | } |
| | 297 | |
|
| | 298 | | private void CheckIfProfileCardShouldBeClosed() |
| | 299 | | { |
| 0 | 300 | | if (!DataStore.i.exploreV2.profileCardIsOpen.Get()) |
| 0 | 301 | | return; |
| | 302 | |
|
| 0 | 303 | | cameraDataStore ??= DataStore.i.camera; |
| | 304 | |
|
| 0 | 305 | | if (Input.GetMouseButton(0) && |
| | 306 | | !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTransform, Input.mousePosition, cameraData |
| | 307 | | !RectTransformUtility.RectangleContainsScreenPoint(DataStore.i.myAccount.isInitialized.Get() ? HUDController |
| | 308 | | Input.mousePosition, cameraDataStore.hudsCamera.Get()) && |
| | 309 | | !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.MyAccountCardMenu, Input. |
| 0 | 310 | | DataStore.i.exploreV2.profileCardIsOpen.Set(false); |
| 0 | 311 | | } |
| | 312 | |
|
| | 313 | | internal void ConfigureCloseButton() |
| | 314 | | { |
| 33 | 315 | | closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false)); |
| 31 | 316 | | closeAction.OnTriggered += OnCloseActionTriggered; |
| 31 | 317 | | DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange; |
| 31 | 318 | | } |
| | 319 | |
|
| | 320 | | private void OnCloseActionTriggered(DCLAction_Trigger action) => |
| 3 | 321 | | OnCloseButtonPressed?.Invoke(true); |
| | 322 | |
|
| | 323 | | public void ShowRealmSelectorModal() => |
| 0 | 324 | | realmSelectorModal.Show(); |
| | 325 | |
|
| | 326 | | /// <summary> |
| | 327 | | /// Instantiates (if does not already exists) a realm selector modal from the given prefab. |
| | 328 | | /// </summary> |
| | 329 | | /// <returns>An instance of a realm modal modal.</returns> |
| | 330 | | internal RealmSelectorComponentView ConfigureRealmSelectorModal() |
| | 331 | | { |
| | 332 | | RealmSelectorComponentView realmSelectorView; |
| | 333 | |
|
| 30 | 334 | | var existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID); |
| | 335 | |
|
| 30 | 336 | | if (existingModal != null) |
| 24 | 337 | | realmSelectorView = existingModal.GetComponent<RealmSelectorComponentView>(); |
| | 338 | | else |
| | 339 | | { |
| 6 | 340 | | realmSelectorView = Instantiate(realmSelectorModalPrefab); |
| 6 | 341 | | realmSelectorView.name = REALM_SELECTOR_MODAL_ID; |
| | 342 | | } |
| | 343 | |
|
| 30 | 344 | | realmSelectorView.Hide(true); |
| | 345 | |
|
| 30 | 346 | | return realmSelectorView; |
| | 347 | | } |
| | 348 | |
|
| | 349 | | public void HideMapOnEnteringWorld() |
| | 350 | | { |
| 0 | 351 | | placesAndEventsSection.Show(); |
| 0 | 352 | | mapSection.Hide(); |
| 0 | 353 | | } |
| | 354 | |
|
| | 355 | | public void SetWalletActive(bool isActive, bool isGuest) |
| | 356 | | { |
| 0 | 357 | | currentWalletCard.SetWalletCardActive(isActive); |
| 0 | 358 | | currentWalletCard.SetWalletCardAsGuest(isGuest); |
| 0 | 359 | | } |
| | 360 | |
|
| | 361 | | private void HideAllSections() |
| | 362 | | { |
| 0 | 363 | | foreach (var section in exploreSectionsById) |
| 0 | 364 | | if (section.Value != null && section.Value.isVisible) |
| 0 | 365 | | section.Value.Hide(); |
| 0 | 366 | | } |
| | 367 | | } |