| | 1 | | using DCL.Browser; |
| | 2 | | using System; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using DCLServices.MapRendererV2; |
| | 5 | | using DCLServices.MapRendererV2.CommonBehavior; |
| | 6 | | using DCLServices.MapRendererV2.ConsumerUtils; |
| | 7 | | using DCLServices.MapRendererV2.MapCameraController; |
| | 8 | | using DCLServices.MapRendererV2.MapLayers; |
| | 9 | | using DCLServices.MapRendererV2.MapLayers.PlayerMarker; |
| | 10 | | using DCLServices.PlacesAPIService; |
| | 11 | | using ExploreV2Analytics; |
| | 12 | | using System.Collections.Generic; |
| | 13 | | using UnityEngine; |
| | 14 | |
|
| | 15 | | namespace DCL |
| | 16 | | { |
| | 17 | | public class NavmapVisibilityBehaviour : IDisposable, IMapActivityOwner |
| | 18 | | { |
| | 19 | | private const MapLayer ACTIVE_MAP_LAYERS = |
| | 20 | | MapLayer.SatelliteAtlas | MapLayer.ParcelsAtlas | MapLayer.HomePoint | MapLayer.ScenesOfInterest | MapLayer. |
| | 21 | |
|
| | 22 | | private Vector3 atlasOriginalPosition; |
| | 23 | |
|
| | 24 | | private bool waitingForFullscreenHUDOpen; |
| | 25 | |
|
| | 26 | | private readonly BaseVariable<bool> navmapVisible; |
| | 27 | |
|
| | 28 | | private readonly NavmapZoomView zoomView; |
| | 29 | | private readonly NavmapRendererConfiguration rendererConfiguration; |
| | 30 | |
|
| | 31 | | private readonly NavmapToastViewController navmapToastViewController; |
| | 32 | | private readonly NavmapZoomViewController navmapZoomViewController; |
| | 33 | | private readonly NavMapLocationControlsController locationControlsController; |
| | 34 | |
|
| | 35 | | private readonly NavmapSearchController navmapSearchController; |
| | 36 | | private readonly IPlaceCardComponentView placeCardModal; |
| | 37 | | private readonly NavMapChunksLayersController chunksLayerController; |
| | 38 | | private readonly MapCameraDragBehavior mapCameraDragBehavior; |
| | 39 | | private readonly NavMapChunksLayersView chunksLayersView; |
| | 40 | | private readonly IExploreV2Analytics exploreV2Analytics; |
| | 41 | | private readonly IBrowserBridge browserBridge; |
| | 42 | |
|
| | 43 | | private Service<IMapRenderer> mapRenderer; |
| | 44 | |
|
| 1 | 45 | | private readonly BaseVariable<bool> navmapIsRendered = DataStore.i.HUDs.navmapIsRendered; |
| | 46 | |
|
| | 47 | | private IMapCameraController cameraController; |
| | 48 | | private readonly BaseVariable<FeatureFlag> featureFlagsFlags; |
| 1 | 49 | | public IReadOnlyDictionary<MapLayer, IMapLayerParameter> LayersParameters { get; } = new Dictionary<MapLayer, I |
| | 50 | | { { MapLayer.PlayerMarker, new PlayerMarkerParameter {BackgroundIsActive = true} } }; |
| | 51 | |
|
| 1 | 52 | | private Camera hudCamera => DataStore.i.camera.hudsCamera.Get(); |
| | 53 | |
|
| 1 | 54 | | public NavmapVisibilityBehaviour( |
| | 55 | | BaseVariable<FeatureFlag> featureFlagsFlags, |
| | 56 | | BaseVariable<bool> navmapVisible, |
| | 57 | | NavmapZoomView zoomView, |
| | 58 | | NavmapToastView toastView, |
| | 59 | | NavmapSearchComponentView searchView, |
| | 60 | | NavMapLocationControlsView locationControlsView, |
| | 61 | | NavMapChunksLayersView chunksLayersView, |
| | 62 | | NavmapRendererConfiguration rendererConfiguration, |
| | 63 | | IPlacesAPIService placesAPIService, |
| | 64 | | IPlacesAnalytics placesAnalytics, |
| | 65 | | IPlaceCardComponentView placeCardModal, |
| | 66 | | IExploreV2Analytics exploreV2Analytics, |
| | 67 | | IBrowserBridge browserBridge) |
| | 68 | | { |
| 1 | 69 | | this.featureFlagsFlags = featureFlagsFlags; |
| | 70 | |
|
| 1 | 71 | | this.navmapVisible = navmapVisible; |
| | 72 | |
|
| 1 | 73 | | this.zoomView = zoomView; |
| 1 | 74 | | this.rendererConfiguration = rendererConfiguration; |
| 1 | 75 | | this.placeCardModal = placeCardModal; |
| 1 | 76 | | this.exploreV2Analytics = exploreV2Analytics; |
| 1 | 77 | | this.browserBridge = browserBridge; |
| | 78 | |
|
| 1 | 79 | | DataStore.i.exploreV2.isOpen.OnChange += OnExploreOpenChanged; |
| 1 | 80 | | navmapVisible.OnChange += OnNavmapVisibilityChanged; |
| | 81 | |
|
| 1 | 82 | | navmapToastViewController = new NavmapToastViewController(MinimapMetadata.GetMetadata(), toastView, renderer |
| 1 | 83 | | navmapZoomViewController = new NavmapZoomViewController(zoomView, featureFlagsFlags); |
| 1 | 84 | | locationControlsController = new NavMapLocationControlsController(locationControlsView, exploreV2Analytics, |
| | 85 | |
|
| 1 | 86 | | navmapSearchController = new NavmapSearchController(searchView, Environment.i.platform.serviceLocator.Get<IP |
| 1 | 87 | | chunksLayerController = new NavMapChunksLayersController(chunksLayersView, exploreV2Analytics); |
| | 88 | |
|
| | 89 | | { // Needed for feature flag. Remove when feature flag is removed |
| 1 | 90 | | this.chunksLayersView = chunksLayersView; |
| | 91 | | } |
| | 92 | |
|
| 1 | 93 | | this.rendererConfiguration.RenderImage.EmbedMapCameraDragBehavior(rendererConfiguration.MapCameraDragBehavio |
| | 94 | |
|
| 1 | 95 | | SetRenderImageTransparency(true); |
| | 96 | |
|
| 1 | 97 | | rendererConfiguration.PixelPerfectMapRendererTextureProvider.SetHudCamera(hudCamera); |
| 1 | 98 | | } |
| | 99 | |
|
| | 100 | | public void Dispose() |
| | 101 | | { |
| 1 | 102 | | ReleaseCameraController(); |
| | 103 | |
|
| 1 | 104 | | DataStore.i.exploreV2.isOpen.OnChange -= OnExploreOpenChanged; |
| 1 | 105 | | navmapVisible.OnChange -= OnNavmapVisibilityChanged; |
| | 106 | |
|
| 1 | 107 | | if (waitingForFullscreenHUDOpen == false) |
| 0 | 108 | | CommonScriptableObjects.isFullscreenHUDOpen.OnChange -= OnFullScreenOpened; |
| | 109 | |
|
| 1 | 110 | | navmapToastViewController.Dispose(); |
| 1 | 111 | | navmapZoomViewController.Dispose(); |
| 1 | 112 | | chunksLayerController.Dispose(); |
| 1 | 113 | | } |
| | 114 | |
|
| | 115 | | private void ReleaseCameraController() |
| | 116 | | { |
| 1 | 117 | | if (cameraController != null) |
| | 118 | | { |
| 0 | 119 | | cameraController.Release(this); |
| 0 | 120 | | cameraController = null; |
| | 121 | | } |
| 1 | 122 | | } |
| | 123 | |
|
| | 124 | | private void SetRenderImageTransparency(bool isTransparent) |
| | 125 | | { |
| | 126 | | // Make Render Image transparent before activation |
| 1 | 127 | | var renderImageColor = this.rendererConfiguration.RenderImage.color; |
| 1 | 128 | | renderImageColor.a = isTransparent ? 0 : 1; |
| 1 | 129 | | this.rendererConfiguration.RenderImage.color = renderImageColor; |
| 1 | 130 | | } |
| | 131 | |
|
| | 132 | | private void OnNavmapVisibilityChanged(bool isVisible, bool _) => |
| 0 | 133 | | SetVisible(isVisible); |
| | 134 | |
|
| | 135 | | private void OnExploreOpenChanged(bool isOpen, bool _) |
| | 136 | | { |
| 0 | 137 | | if (!isOpen) |
| 0 | 138 | | SetVisible(false); |
| 0 | 139 | | } |
| | 140 | |
|
| | 141 | | internal void SetVisible(bool visible) |
| | 142 | | { |
| 1 | 143 | | if (waitingForFullscreenHUDOpen) |
| 0 | 144 | | return; |
| | 145 | |
|
| 1 | 146 | | if (visible) |
| | 147 | | { |
| 1 | 148 | | if (CommonScriptableObjects.isFullscreenHUDOpen.Get()) |
| 0 | 149 | | SetVisibility_Internal(true); |
| | 150 | | else |
| | 151 | | { |
| 1 | 152 | | waitingForFullscreenHUDOpen = true; |
| 1 | 153 | | CommonScriptableObjects.isFullscreenHUDOpen.OnChange += OnFullScreenOpened; |
| | 154 | | } |
| | 155 | | } |
| | 156 | | else |
| 0 | 157 | | SetVisibility_Internal(false); |
| 0 | 158 | | } |
| | 159 | |
|
| | 160 | | private void OnFullScreenOpened(bool isFullScreen, bool _) |
| | 161 | | { |
| 0 | 162 | | CommonScriptableObjects.isFullscreenHUDOpen.OnChange -= OnFullScreenOpened; |
| | 163 | |
|
| 0 | 164 | | if (!isFullScreen) |
| 0 | 165 | | return; |
| | 166 | |
|
| 0 | 167 | | SetVisibility_Internal(true); |
| 0 | 168 | | waitingForFullscreenHUDOpen = false; |
| 0 | 169 | | } |
| | 170 | |
|
| | 171 | | private void SetVisibility_Internal(bool visible) |
| | 172 | | { |
| 0 | 173 | | if (visible) |
| | 174 | | { |
| 0 | 175 | | if (!DataStore.i.exploreV2.isInitialized.Get()) |
| 0 | 176 | | Utils.UnlockCursor(); |
| | 177 | |
|
| 0 | 178 | | cameraController = mapRenderer.Ref.RentCamera( |
| | 179 | | new MapCameraInput( |
| | 180 | | this, |
| | 181 | | ACTIVE_MAP_LAYERS, |
| | 182 | | Utils.WorldToGridPosition(DataStore.i.player.playerWorldPosition.Get()), |
| | 183 | | navmapZoomViewController.ResetZoomToMidValue(), |
| | 184 | | rendererConfiguration.PixelPerfectMapRendererTextureProvider.GetPixelPerfectTextureResolution(), |
| | 185 | | zoomView.zoomVerticalRange |
| | 186 | | )); |
| | 187 | |
|
| 0 | 188 | | SetRenderImageTransparency(false); |
| | 189 | |
|
| 0 | 190 | | navmapToastViewController.Activate(); |
| 0 | 191 | | navmapZoomViewController.Activate(cameraController); |
| | 192 | |
|
| 0 | 193 | | if (!featureFlagsFlags.Get().IsFeatureEnabled("navmap-satellite-view")) |
| 0 | 194 | | chunksLayersView.Hide(); |
| | 195 | |
|
| 0 | 196 | | if (featureFlagsFlags.Get().IsFeatureEnabled("map_focus_home_or_user")) |
| 0 | 197 | | locationControlsController.Activate(cameraController); |
| | 198 | | else |
| 0 | 199 | | locationControlsController.Hide(); |
| | 200 | |
|
| 0 | 201 | | navmapSearchController.Activate(cameraController); |
| | 202 | |
|
| 0 | 203 | | rendererConfiguration.RenderImage.Activate(hudCamera, cameraController.GetRenderTexture(), cameraControl |
| 0 | 204 | | rendererConfiguration.PixelPerfectMapRendererTextureProvider.Activate(cameraController); |
| | 205 | |
|
| 0 | 206 | | navmapIsRendered.Set(true); |
| | 207 | | } |
| 0 | 208 | | else if (cameraController != null) |
| | 209 | | { |
| 0 | 210 | | navmapToastViewController.Deactivate(); |
| 0 | 211 | | navmapZoomViewController.Deactivate(); |
| 0 | 212 | | locationControlsController.Deactivate(); |
| 0 | 213 | | navmapSearchController.Deactivate(); |
| | 214 | |
|
| 0 | 215 | | rendererConfiguration.PixelPerfectMapRendererTextureProvider.Deactivate(); |
| 0 | 216 | | rendererConfiguration.RenderImage.Deactivate(); |
| | 217 | |
|
| 0 | 218 | | SetRenderImageTransparency(true); |
| | 219 | |
|
| 0 | 220 | | cameraController.Release(this); |
| 0 | 221 | | cameraController = null; |
| | 222 | |
|
| 0 | 223 | | navmapIsRendered.Set(false); |
| | 224 | | } |
| 0 | 225 | | } |
| | 226 | | } |
| | 227 | | } |