| | 1 | | using System; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using DCL; |
| | 5 | | using JetBrains.Annotations; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.Events; |
| | 8 | |
|
| | 9 | | public interface IExploreV2MenuComponentView : IDisposable |
| | 10 | | { |
| | 11 | |
|
| | 12 | | /// <summary> |
| | 13 | | /// Real viewer component. |
| | 14 | | /// </summary> |
| | 15 | | IRealmViewerComponentView currentRealmViewer { get; } |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Realm Selector component. |
| | 19 | | /// </summary> |
| | 20 | | IRealmSelectorComponentView currentRealmSelectorModal { get; } |
| | 21 | |
|
| | 22 | | /// <summary> |
| | 23 | | /// Profile card component. |
| | 24 | | /// </summary> |
| | 25 | | IProfileCardComponentView currentProfileCard { get; } |
| | 26 | |
|
| | 27 | | /// <summary> |
| | 28 | | /// Places and Events section component. |
| | 29 | | /// </summary> |
| | 30 | | IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection { get; } |
| | 31 | |
|
| | 32 | | /// <summary> |
| | 33 | | /// Transform used to positionate the top menu tooltips. |
| | 34 | | /// </summary> |
| | 35 | | RectTransform currentTopMenuTooltipReference { get; } |
| | 36 | |
|
| | 37 | | /// <summary> |
| | 38 | | /// Transform used to positionate the places and events section tooltips. |
| | 39 | | /// </summary> |
| | 40 | | RectTransform currentPlacesAndEventsTooltipReference { get; } |
| | 41 | |
|
| | 42 | | /// <summary> |
| | 43 | | /// Transform used to positionate the backpack section tooltips. |
| | 44 | | /// </summary> |
| | 45 | | RectTransform currentBackpackTooltipReference { get; } |
| | 46 | |
|
| | 47 | | /// <summary> |
| | 48 | | /// Transform used to positionate the map section tooltips. |
| | 49 | | /// </summary> |
| | 50 | | RectTransform currentMapTooltipReference { get; } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Transform used to positionate the builder section tooltips. |
| | 54 | | /// </summary> |
| | 55 | | RectTransform currentBuilderTooltipReference { get; } |
| | 56 | |
|
| | 57 | | /// <summary> |
| | 58 | | /// Transform used to positionate the quest section tooltips. |
| | 59 | | /// </summary> |
| | 60 | | RectTransform currentQuestTooltipReference { get; } |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// Transform used to positionate the settings section tooltips. |
| | 64 | | /// </summary> |
| | 65 | | RectTransform currentSettingsTooltipReference { get; } |
| | 66 | |
|
| | 67 | | /// <summary> |
| | 68 | | /// Transform used to positionate the profile section tooltips. |
| | 69 | | /// </summary> |
| | 70 | | RectTransform currentProfileCardTooltipReference { get; } |
| | 71 | | /// <summary> |
| | 72 | | /// It will be triggered when the close button is clicked. |
| | 73 | | /// </summary> |
| | 74 | | event Action<bool> OnCloseButtonPressed; |
| | 75 | |
|
| | 76 | | /// <summary> |
| | 77 | | /// It will be triggered when a section is open. |
| | 78 | | /// </summary> |
| | 79 | | event Action<ExploreSection> OnSectionOpen; |
| | 80 | |
|
| | 81 | | /// <summary> |
| | 82 | | /// It will be triggered after the show animation has finished. |
| | 83 | | /// </summary> |
| | 84 | | event Action OnAfterShowAnimation; |
| | 85 | |
|
| | 86 | | /// <summary> |
| | 87 | | /// Shows/Hides the game object of the explore menu. |
| | 88 | | /// </summary> |
| | 89 | | /// <param name="isActive">True to show it.</param> |
| | 90 | | void SetVisible(bool isActive); |
| | 91 | |
|
| | 92 | | /// <summary> |
| | 93 | | /// It is called after the show animation has finished. |
| | 94 | | /// </summary> |
| | 95 | | [UsedImplicitly] |
| | 96 | | void OnAfterShowAnimationCompleted(); |
| | 97 | |
|
| | 98 | | /// <summary> |
| | 99 | | /// Open a section. |
| | 100 | | /// </summary> |
| | 101 | | /// <param name="section">Section to go.</param> |
| | 102 | | void GoToSection(ExploreSection section); |
| | 103 | |
|
| | 104 | | /// <summary> |
| | 105 | | /// Activates/Deactivates a section in the selector. |
| | 106 | | /// </summary> |
| | 107 | | /// <param name="section">Section to activate/deactivate.</param> |
| | 108 | | /// <param name="isActive">True for activating.</param> |
| | 109 | | void SetSectionActive(ExploreSection section, bool isActive); |
| | 110 | |
|
| | 111 | | /// <summary> |
| | 112 | | /// Check if a section is actived or not. |
| | 113 | | /// </summary> |
| | 114 | | /// <param name="section">Section to check.</param> |
| | 115 | | /// <returns></returns> |
| | 116 | | bool IsSectionActive(ExploreSection section); |
| | 117 | |
|
| | 118 | | /// <summary> |
| | 119 | | /// Configures a encapsulated section. |
| | 120 | | /// </summary> |
| | 121 | | /// <param name="sectionId">Section to configure.</param> |
| | 122 | | /// <param name="featureConfiguratorFlag">Flag used to configurates the feature.</param> |
| | 123 | | void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag); |
| | 124 | |
|
| | 125 | | /// <summary> |
| | 126 | | /// Shows the Realm Selector modal. |
| | 127 | | /// </summary> |
| | 128 | | void ShowRealmSelectorModal(); |
| | 129 | | } |
| | 130 | |
|
| | 131 | | public class ExploreV2MenuComponentView : BaseComponentView, IExploreV2MenuComponentView |
| | 132 | | { |
| | 133 | | internal const string REALM_SELECTOR_MODAL_ID = "RealmSelector_Modal"; |
| | 134 | |
|
| | 135 | | [Header("Assets References")] |
| | 136 | | [SerializeField] internal RealmSelectorComponentView realmSelectorModalPrefab; |
| | 137 | |
|
| | 138 | | [Header("Top Menu")] |
| | 139 | | [SerializeField] internal SectionSelectorComponentView sectionSelector; |
| | 140 | | [SerializeField] internal ProfileCardComponentView profileCard; |
| | 141 | | [SerializeField] internal RealmViewerComponentView realmViewer; |
| | 142 | | [SerializeField] internal ButtonComponentView closeMenuButton; |
| | 143 | | [SerializeField] internal InputAction_Trigger closeAction; |
| | 144 | |
|
| | 145 | | [Header("Sections")] |
| | 146 | | [SerializeField] internal PlacesAndEventsSectionComponentView placesAndEventsSection; |
| | 147 | | [SerializeField] internal FeatureEncapsulatorComponentView backpackSection; |
| | 148 | | [SerializeField] internal FeatureEncapsulatorComponentView mapSection; |
| | 149 | | [SerializeField] internal FeatureEncapsulatorComponentView builderSection; |
| | 150 | | [SerializeField] internal FeatureEncapsulatorComponentView questSection; |
| | 151 | | [SerializeField] internal FeatureEncapsulatorComponentView settingsSection; |
| | 152 | |
|
| | 153 | | [Header("Tutorial References")] |
| | 154 | | [SerializeField] internal RectTransform profileCardTooltipReference; |
| | 155 | |
|
| | 156 | | private DataStore_Camera cameraDataStore; |
| | 157 | |
|
| | 158 | | private Dictionary<ExploreSection, FeatureEncapsulatorComponentView> exploreSectionsById; |
| | 159 | | private HUDCanvasCameraModeController hudCanvasCameraModeController; |
| | 160 | |
|
| | 161 | | private RectTransform profileCardRectTranform; |
| | 162 | | private RealmSelectorComponentView realmSelectorModal; |
| | 163 | |
|
| | 164 | | public override void Awake() |
| | 165 | | { |
| 34 | 166 | | base.Awake(); |
| | 167 | |
|
| 34 | 168 | | profileCardRectTranform = profileCard.GetComponent<RectTransform>(); |
| 34 | 169 | | realmSelectorModal = ConfigureRealmSelectorModal(); |
| 34 | 170 | | hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud |
| | 171 | |
|
| 34 | 172 | | exploreSectionsById = new Dictionary<ExploreSection, FeatureEncapsulatorComponentView>() |
| | 173 | | { |
| | 174 | | { ExploreSection.Explore, null }, |
| | 175 | | { ExploreSection.Backpack, backpackSection }, |
| | 176 | | { ExploreSection.Map, mapSection }, |
| | 177 | | { ExploreSection.Builder, builderSection }, |
| | 178 | | { ExploreSection.Quest, questSection }, |
| | 179 | | { ExploreSection.Settings, settingsSection }, |
| | 180 | | }; |
| 34 | 181 | | } |
| | 182 | |
|
| | 183 | | public override void Start() |
| | 184 | | { |
| 34 | 185 | | DataStore.i.exploreV2.isInitialized.OnChange += IsInitialized_OnChange; |
| 34 | 186 | | IsInitialized_OnChange(DataStore.i.exploreV2.isInitialized.Get(), false); |
| | 187 | |
|
| 34 | 188 | | ConfigureCloseButton(); |
| 34 | 189 | | } |
| | 190 | |
|
| | 191 | | public override void Update() => |
| 0 | 192 | | CheckIfProfileCardShouldBeClosed(); |
| | 193 | |
|
| | 194 | | public void OnDestroy() => |
| 34 | 195 | | hudCanvasCameraModeController?.Dispose(); |
| | 196 | |
|
| 0 | 197 | | public IRealmViewerComponentView currentRealmViewer => realmViewer; |
| 0 | 198 | | public IRealmSelectorComponentView currentRealmSelectorModal => realmSelectorModal; |
| 0 | 199 | | public IProfileCardComponentView currentProfileCard => profileCard; |
| 0 | 200 | | public IPlacesAndEventsSectionComponentView currentPlacesAndEventsSection => placesAndEventsSection; |
| 0 | 201 | | public RectTransform currentTopMenuTooltipReference => sectionSelector.GetSection((int) ExploreSection.Explore).pivo |
| 0 | 202 | | public RectTransform currentPlacesAndEventsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Explor |
| 0 | 203 | | public RectTransform currentBackpackTooltipReference => sectionSelector.GetSection((int)ExploreSection.Backpack).piv |
| 0 | 204 | | public RectTransform currentMapTooltipReference => sectionSelector.GetSection((int)ExploreSection.Map).pivot; |
| 0 | 205 | | public RectTransform currentBuilderTooltipReference => sectionSelector.GetSection((int)ExploreSection.Builder).pivot |
| 0 | 206 | | public RectTransform currentQuestTooltipReference => sectionSelector.GetSection((int)ExploreSection.Quest).pivot; |
| 0 | 207 | | public RectTransform currentSettingsTooltipReference => sectionSelector.GetSection((int)ExploreSection.Settings).piv |
| 0 | 208 | | public RectTransform currentProfileCardTooltipReference => profileCardTooltipReference; |
| | 209 | |
|
| | 210 | | public event Action<bool> OnCloseButtonPressed; |
| | 211 | | public event Action<ExploreSection> OnSectionOpen; |
| | 212 | | public event Action OnAfterShowAnimation; |
| | 213 | |
|
| | 214 | | public override void Dispose() |
| | 215 | | { |
| 34 | 216 | | base.Dispose(); |
| | 217 | |
|
| 34 | 218 | | RemoveSectionSelectorMappings(); |
| 34 | 219 | | closeMenuButton.onClick.RemoveAllListeners(); |
| 34 | 220 | | closeAction.OnTriggered -= OnCloseActionTriggered; |
| 34 | 221 | | DataStore.i.exploreV2.isSomeModalOpen.OnChange -= IsSomeModalOpen_OnChange; |
| 34 | 222 | | DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange; |
| | 223 | |
|
| 34 | 224 | | if (realmSelectorModal != null) |
| 34 | 225 | | realmSelectorModal.Dispose(); |
| 34 | 226 | | } |
| | 227 | |
|
| | 228 | | public void SetVisible(bool isActive) |
| | 229 | | { |
| 2 | 230 | | if (isActive) |
| | 231 | | { |
| 1 | 232 | | DataStore.i.exploreV2.isInShowAnimationTransiton.Set(true); |
| 1 | 233 | | Show(); |
| | 234 | |
|
| 1 | 235 | | ISectionToggle sectionToGo = sectionSelector.GetSection(DataStore.i.exploreV2.currentSectionIndex.Get()); |
| | 236 | |
|
| 1 | 237 | | if (sectionToGo != null && sectionToGo.IsActive()) |
| | 238 | | { |
| 1 | 239 | | GoToSection((ExploreSection)DataStore.i.exploreV2.currentSectionIndex.Get()); |
| 1 | 240 | | } |
| | 241 | | else |
| | 242 | | { |
| 0 | 243 | | List<ISectionToggle> allSections = sectionSelector.GetAllSections(); |
| 0 | 244 | | foreach (ISectionToggle section in allSections) |
| | 245 | | { |
| 0 | 246 | | if (section != null && section.IsActive()) |
| | 247 | | { |
| 0 | 248 | | section.SelectToggle(reselectIfAlreadyOn: true); |
| 0 | 249 | | break; |
| | 250 | | } |
| | 251 | | } |
| | 252 | | } |
| | 253 | | } |
| | 254 | | else |
| | 255 | | { |
| 1 | 256 | | Hide(); |
| 1 | 257 | | AudioScriptableObjects.dialogClose.Play(true); |
| | 258 | | } |
| 1 | 259 | | } |
| | 260 | |
|
| | 261 | | public void GoToSection(ExploreSection section) |
| | 262 | | { |
| 1 | 263 | | sectionSelector.GetSection((int)section)?.SelectToggle(reselectIfAlreadyOn: true); |
| | 264 | |
|
| 1 | 265 | | AudioScriptableObjects.dialogOpen.Play(true); |
| 1 | 266 | | AudioScriptableObjects.listItemAppear.ResetPitch(); |
| 1 | 267 | | } |
| | 268 | |
|
| | 269 | | public void OnAfterShowAnimationCompleted() |
| | 270 | | { |
| 0 | 271 | | if (!DataStore.i.exploreV2.isOpen.Get()) |
| 0 | 272 | | return; |
| | 273 | |
|
| 0 | 274 | | DataStore.i.exploreV2.isInShowAnimationTransiton.Set(false); |
| 0 | 275 | | OnAfterShowAnimation?.Invoke(); |
| 0 | 276 | | } |
| | 277 | |
|
| | 278 | | public void SetSectionActive(ExploreSection section, bool isActive) => |
| 12 | 279 | | sectionSelector.GetSection((int)section).SetActive(isActive); |
| | 280 | |
|
| | 281 | | public bool IsSectionActive(ExploreSection section) => |
| 0 | 282 | | sectionSelector.GetSection((int)section).IsActive(); |
| | 283 | |
|
| | 284 | | public void ConfigureEncapsulatedSection(ExploreSection sectionId, BaseVariable<Transform> featureConfiguratorFlag) |
| 5 | 285 | | exploreSectionsById[sectionId]?.EncapsulateFeature(featureConfiguratorFlag); |
| | 286 | |
|
| | 287 | | public void ShowRealmSelectorModal() => |
| 0 | 288 | | realmSelectorModal.Show(); |
| | 289 | |
|
| | 290 | | public override void RefreshControl() |
| | 291 | | { |
| 0 | 292 | | placesAndEventsSection.RefreshControl(); |
| | 293 | |
|
| 0 | 294 | | foreach (var section in exploreSectionsById.Keys) |
| 0 | 295 | | exploreSectionsById[section]?.RefreshControl(); |
| 0 | 296 | | } |
| | 297 | |
|
| | 298 | | internal void RemoveSectionSelectorMappings() |
| | 299 | | { |
| 560 | 300 | | foreach (int sectionId in Enum.GetValues(typeof(ExploreSection))) |
| 240 | 301 | | sectionSelector.GetSection(sectionId)?.onSelect.RemoveAllListeners(); |
| 40 | 302 | | } |
| | 303 | |
|
| | 304 | | internal void ConfigureCloseButton() |
| | 305 | | { |
| 38 | 306 | | closeMenuButton.onClick.AddListener(() => OnCloseButtonPressed?.Invoke(false)); |
| 36 | 307 | | closeAction.OnTriggered += OnCloseActionTriggered; |
| 36 | 308 | | DataStore.i.exploreV2.isSomeModalOpen.OnChange += IsSomeModalOpen_OnChange; |
| 36 | 309 | | } |
| | 310 | |
|
| | 311 | | /// <summary> |
| | 312 | | /// Instantiates (if does not already exists) a realm selector modal from the given prefab. |
| | 313 | | /// </summary> |
| | 314 | | /// <returns>An instance of a realm modal modal.</returns> |
| | 315 | | internal RealmSelectorComponentView ConfigureRealmSelectorModal() |
| | 316 | | { |
| 35 | 317 | | RealmSelectorComponentView realmSelectorModal = null; |
| | 318 | |
|
| 35 | 319 | | GameObject existingModal = GameObject.Find(REALM_SELECTOR_MODAL_ID); |
| | 320 | |
|
| 35 | 321 | | if (existingModal != null) |
| | 322 | | { |
| 29 | 323 | | realmSelectorModal = existingModal.GetComponent<RealmSelectorComponentView>(); |
| 29 | 324 | | } |
| | 325 | | else |
| | 326 | | { |
| 6 | 327 | | realmSelectorModal = GameObject.Instantiate(realmSelectorModalPrefab); |
| 6 | 328 | | realmSelectorModal.name = REALM_SELECTOR_MODAL_ID; |
| | 329 | | } |
| | 330 | |
|
| 35 | 331 | | realmSelectorModal.Hide(true); |
| | 332 | |
|
| 35 | 333 | | return realmSelectorModal; |
| | 334 | | } |
| | 335 | |
|
| | 336 | | internal static ExploreV2MenuComponentView Create() |
| | 337 | | { |
| 0 | 338 | | ExploreV2MenuComponentView exploreV2View = Instantiate(Resources.Load<GameObject>("MainMenu/ExploreV2Menu")).Get |
| 0 | 339 | | exploreV2View.name = "_ExploreV2"; |
| | 340 | |
|
| 0 | 341 | | return exploreV2View; |
| | 342 | | } |
| | 343 | |
|
| | 344 | | private void IsInitialized_OnChange(bool current, bool previous) |
| | 345 | | { |
| 34 | 346 | | if (!current) |
| 0 | 347 | | return; |
| | 348 | |
|
| 34 | 349 | | DataStore.i.exploreV2.isInitialized.OnChange -= IsInitialized_OnChange; |
| 34 | 350 | | StartCoroutine(CreateSectionSelectorMappingsAfterDelay()); |
| 34 | 351 | | } |
| | 352 | |
|
| | 353 | | private IEnumerator CreateSectionSelectorMappingsAfterDelay() |
| | 354 | | { |
| 34 | 355 | | yield return null; |
| 0 | 356 | | CreateSectionSelectorMappings(); |
| 0 | 357 | | } |
| | 358 | |
|
| | 359 | | internal void CreateSectionSelectorMappings() |
| | 360 | | { |
| 168 | 361 | | foreach (ExploreSection sectionId in Enum.GetValues(typeof(ExploreSection))) |
| 72 | 362 | | sectionSelector.GetSection((int)sectionId) |
| | 363 | | ?.onSelect.AddListener(OnSectionSelected(sectionId)); |
| 12 | 364 | | } |
| | 365 | |
|
| | 366 | | private UnityAction<bool> OnSectionSelected(ExploreSection sectionId) => |
| 72 | 367 | | isOn => |
| | 368 | | { |
| 6 | 369 | | FeatureEncapsulatorComponentView sectionView = exploreSectionsById[sectionId]; |
| | 370 | |
|
| 6 | 371 | | if (isOn) |
| | 372 | | { |
| | 373 | | // If not an explorer Section, because we do not Show/Hide it |
| 6 | 374 | | if (sectionView != null) |
| 5 | 375 | | sectionView.Show(); |
| | 376 | |
|
| 6 | 377 | | OnSectionOpen?.Invoke(sectionId); |
| 6 | 378 | | } |
| 0 | 379 | | else if (sectionView != null) // If not an explorer Section, because we do not Show/Hide it |
| | 380 | | { |
| 0 | 381 | | sectionView.Hide(); |
| | 382 | | } |
| 0 | 383 | | }; |
| | 384 | |
|
| | 385 | | private void IsSomeModalOpen_OnChange(bool current, bool previous) |
| | 386 | | { |
| 28 | 387 | | closeAction.OnTriggered -= OnCloseActionTriggered; |
| | 388 | |
|
| 28 | 389 | | if (!current) |
| 14 | 390 | | closeAction.OnTriggered += OnCloseActionTriggered; |
| 28 | 391 | | } |
| | 392 | |
|
| 3 | 393 | | private void OnCloseActionTriggered(DCLAction_Trigger action) => OnCloseButtonPressed?.Invoke(true); |
| | 394 | |
|
| | 395 | | private void CheckIfProfileCardShouldBeClosed() |
| | 396 | | { |
| 0 | 397 | | if (!DataStore.i.exploreV2.profileCardIsOpen.Get()) |
| 0 | 398 | | return; |
| | 399 | |
|
| 0 | 400 | | cameraDataStore ??= DataStore.i.camera; |
| | 401 | |
|
| 0 | 402 | | if (Input.GetMouseButton(0) && |
| | 403 | | !RectTransformUtility.RectangleContainsScreenPoint(profileCardRectTranform, Input.mousePosition, cameraDataS |
| | 404 | | !RectTransformUtility.RectangleContainsScreenPoint(HUDController.i.profileHud.view.expandedMenu, Input.mouse |
| | 405 | | { |
| 0 | 406 | | DataStore.i.exploreV2.profileCardIsOpen.Set(false); |
| | 407 | | } |
| 0 | 408 | | } |
| | 409 | | } |