| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL.Browser; |
| | 3 | | using DCL.Map; |
| | 4 | | using DCL.Tasks; |
| | 5 | | using DCLServices.PlacesAPIService; |
| | 6 | | using System.Threading; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace DCL |
| | 10 | | { |
| | 11 | | public class NavmapView : MonoBehaviour |
| | 12 | | { |
| | 13 | | [SerializeField] internal NavmapSearchComponentView searchView; |
| | 14 | | [SerializeField] internal NavmapFilterComponentView filterView; |
| | 15 | | [SerializeField] internal GameObject placeCardModalParent; |
| | 16 | |
|
| | 17 | | [Space] |
| | 18 | | [SerializeField] internal NavmapToastView toastView; |
| | 19 | | [SerializeField] private NavMapLocationControlsView locationControlsView; |
| | 20 | | [SerializeField] private NavmapZoomView zoomView; |
| | 21 | | [SerializeField] private NavMapChunksLayersView chunksLayersView; |
| | 22 | |
|
| | 23 | | [Space] |
| | 24 | | [SerializeField] private NavmapRendererConfiguration navmapRendererConfiguration; |
| | 25 | |
|
| | 26 | | private IPlaceCardComponentView placeCardModal; |
| | 27 | |
|
| | 28 | | internal NavmapVisibilityBehaviour navmapVisibilityBehaviour; |
| | 29 | |
|
| | 30 | | private RectTransform rectTransform; |
| 2 | 31 | | private CancellationTokenSource updateSceneNameCancellationToken = new (); |
| | 32 | |
|
| 0 | 33 | | private RectTransform RectTransform => rectTransform ??= transform as RectTransform; |
| 3 | 34 | | private BaseVariable<Transform> configureMapInFullscreenMenu => DataStore.i.exploreV2.configureMapInFullscreenMe |
| | 35 | | private NavmapFilterComponentController navmapFilterComponentController; |
| | 36 | |
|
| | 37 | | private void Start() |
| | 38 | | { |
| 1 | 39 | | placeCardModal = placeCardModalParent.GetComponent<IPlaceCardComponentView>(); |
| | 40 | |
|
| 1 | 41 | | var exploreV2Analytics = new ExploreV2Analytics.ExploreV2Analytics(); |
| | 42 | |
|
| 1 | 43 | | navmapVisibilityBehaviour = new NavmapVisibilityBehaviour( |
| | 44 | | DataStore.i.featureFlags.flags, |
| | 45 | | DataStore.i.HUDs.navmapVisible, |
| | 46 | | zoomView, |
| | 47 | | toastView, |
| | 48 | | searchView, |
| | 49 | | locationControlsView, |
| | 50 | | chunksLayersView, |
| | 51 | | navmapRendererConfiguration, |
| | 52 | | Environment.i.platform.serviceLocator.Get<IPlacesAPIService>(), |
| | 53 | | new PlacesAnalytics(), |
| | 54 | | placeCardModal, |
| | 55 | | exploreV2Analytics, |
| | 56 | | new WebInterfaceBrowserBridge()); |
| 1 | 57 | | navmapFilterComponentController = new NavmapFilterComponentController(filterView, new WebInterfaceBrowserBri |
| | 58 | |
|
| 1 | 59 | | ConfigureMapInFullscreenMenuChanged(configureMapInFullscreenMenu.Get(), null); |
| 1 | 60 | | DataStore.i.HUDs.isNavMapInitialized.Set(true); |
| 1 | 61 | | } |
| | 62 | |
|
| | 63 | | private void OnEnable() |
| | 64 | | { |
| 1 | 65 | | configureMapInFullscreenMenu.OnChange += ConfigureMapInFullscreenMenuChanged; |
| 1 | 66 | | updateSceneNameCancellationToken = updateSceneNameCancellationToken.SafeRestart(); |
| | 67 | |
|
| | 68 | | //Needed due to script execution order |
| 1 | 69 | | DataStore.i.featureFlags.flags.OnChange += OnFeatureFlagsChanged; |
| 1 | 70 | | } |
| | 71 | |
|
| | 72 | | private void OnFeatureFlagsChanged(FeatureFlag current, FeatureFlag previous) |
| | 73 | | { |
| | 74 | | //TODO Remove: Temporary to allow PR merging |
| 0 | 75 | | searchView.gameObject.SetActive(DataStore.i.featureFlags.flags.Get().IsFeatureEnabled("navmap_header")); |
| 0 | 76 | | } |
| | 77 | |
|
| | 78 | | private void OnDisable() |
| | 79 | | { |
| 1 | 80 | | configureMapInFullscreenMenu.OnChange -= ConfigureMapInFullscreenMenuChanged; |
| 1 | 81 | | DataStore.i.featureFlags.flags.OnChange -= OnFeatureFlagsChanged; |
| 1 | 82 | | } |
| | 83 | |
|
| | 84 | | private void OnDestroy() |
| | 85 | | { |
| 1 | 86 | | navmapVisibilityBehaviour.Dispose(); |
| 1 | 87 | | } |
| | 88 | |
|
| | 89 | | private void ConfigureMapInFullscreenMenuChanged(Transform currentParentTransform, Transform _) |
| | 90 | | { |
| 1 | 91 | | if (currentParentTransform == null || transform.parent == currentParentTransform) |
| 1 | 92 | | return; |
| | 93 | |
|
| 0 | 94 | | transform.SetParent(currentParentTransform); |
| 0 | 95 | | transform.localScale = Vector3.one; |
| | 96 | |
|
| 0 | 97 | | RectTransform.anchorMin = Vector2.zero; |
| 0 | 98 | | RectTransform.anchorMax = Vector2.one; |
| 0 | 99 | | RectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 100 | | RectTransform.localPosition = Vector2.zero; |
| 0 | 101 | | RectTransform.offsetMax = Vector2.zero; |
| 0 | 102 | | RectTransform.offsetMin = Vector2.zero; |
| 0 | 103 | | } |
| | 104 | | } |
| | 105 | | } |