diff --git a/Explorer/Assets/DCL/MapRenderer/ConsumerUtils/MapRenderImage.cs b/Explorer/Assets/DCL/MapRenderer/ConsumerUtils/MapRenderImage.cs index b1d0ddd24c..fe4941ddb8 100644 --- a/Explorer/Assets/DCL/MapRenderer/ConsumerUtils/MapRenderImage.cs +++ b/Explorer/Assets/DCL/MapRenderer/ConsumerUtils/MapRenderImage.cs @@ -71,7 +71,7 @@ public void OnEndDrag(PointerEventData eventData) public void OnPointerClick(PointerEventData eventData) { Profiler.BeginSample(POINTER_CLICK_SAMPLE_NAME); - GameObject? hitObject = null; + Vector2Int? hitParcel = null; bool parcelUnderPoint = TryGetParcelUnderPointer(eventData, out Vector2Int parcel, out _, out _); if (isActive && !dragging) @@ -81,13 +81,11 @@ public void OnPointerClick(PointerEventData eventData) Vector2 rectSize = rectTransform.rect.size; Vector2 localPosition = rectTransform.InverseTransformPoint(worldPosition); Vector2 leftCornerRelativeLocalPosition = localPosition + (rectTransform.pivot * rectSize); - hitObject = interactivityController!.ProcessMouseClick(leftCornerRelativeLocalPosition / rectSize, parcel); + hitParcel = interactivityController!.ProcessMouseClick(leftCornerRelativeLocalPosition / rectSize, parcel); } - if(hitObject == null && parcelUnderPoint) - { - InvokeParcelClicked(parcel); - } + if (hitParcel != null && parcelUnderPoint) + InvokeParcelClicked(hitParcel.Value); } Profiler.EndSample(); diff --git a/Explorer/Assets/DCL/MapRenderer/MapCameraController/IMapInteractivityController.cs b/Explorer/Assets/DCL/MapRenderer/MapCameraController/IMapInteractivityController.cs index f95dfe2eed..215b002a99 100644 --- a/Explorer/Assets/DCL/MapRenderer/MapCameraController/IMapInteractivityController.cs +++ b/Explorer/Assets/DCL/MapRenderer/MapCameraController/IMapInteractivityController.cs @@ -25,6 +25,9 @@ public interface IMapInteractivityController GameObject? ProcessMousePosition(Vector2 worldPosition, Vector2 screenPosition); - GameObject? ProcessMouseClick(Vector2 worldPosition, Vector2Int parcel); + /// + /// Returns the parcel position clicked (if any) or null if it doesn't (this includes map markers) + /// + Vector2Int? ProcessMouseClick(Vector2 worldPosition, Vector2Int parcel); } } diff --git a/Explorer/Assets/DCL/MapRenderer/MapCameraController/MapCameraInteractivityController.cs b/Explorer/Assets/DCL/MapRenderer/MapCameraController/MapCameraInteractivityController.cs index 7c89fd2e51..3efdce3b4d 100644 --- a/Explorer/Assets/DCL/MapRenderer/MapCameraController/MapCameraInteractivityController.cs +++ b/Explorer/Assets/DCL/MapRenderer/MapCameraController/MapCameraInteractivityController.cs @@ -3,6 +3,7 @@ using DCL.MapRenderer.CoordsUtils; using DCL.MapRenderer.MapLayers; using DCL.MapRenderer.MapLayers.ParcelHighlight; +using DCL.MapRenderer.MapLayers.PointsOfInterest; using DCL.Navmap; using DCL.UI; using System; @@ -115,35 +116,34 @@ public void HighlightParcel(Vector2Int parcel) return hitObject; } - public GameObject? ProcessMouseClick(Vector2 normalizedCoordinates, Vector2Int parcel) + public Vector2Int? ProcessMouseClick(Vector2 normalizedCoordinates, Vector2Int parcel) { clickCt = clickCt.SafeRestart(); previouslyClickedMarker?.ToggleSelection(false); previouslyClickedMarker = null; - GameObject? hitObject = null; + Vector2Int? hitParcel = null; RaycastHit2D raycast = Physics2D.Raycast(GetLocalPosition(normalizedCoordinates), Vector2.zero, 10); UIAudioEventsBus.Instance.SendPlayAudioEvent(clickAudio); if (raycast.collider != null) { - hitObject = raycast.collider.gameObject; - foreach (IMapLayerController mapLayerController in interactableLayers) - if (mapLayerController.TryClickObject(hitObject, clickCt, out IMapRendererMarker? clickedMarker)) + if (mapLayerController.TryClickObject(raycast.collider.gameObject, clickCt, out IMapRendererMarker? clickedMarker)) { previouslyClickedMarker = clickedMarker; - return hitObject; + hitParcel = clickedMarker?.GetParcelPosition(); + return hitParcel; } } else { navmapBus.MoveCameraTo(parcel, CAMERA_MOVE_SPEED); - hitObject = null; + hitParcel = parcel; } - return hitObject; + return hitParcel; } public void Initialize(MapLayer layers) diff --git a/Explorer/Assets/DCL/MapRenderer/MapLayers/Categories/CategoryMarker/CategoryMarker.cs b/Explorer/Assets/DCL/MapRenderer/MapLayers/Categories/CategoryMarker/CategoryMarker.cs index ad5e319d6f..d9591caf68 100644 --- a/Explorer/Assets/DCL/MapRenderer/MapLayers/Categories/CategoryMarker/CategoryMarker.cs +++ b/Explorer/Assets/DCL/MapRenderer/MapLayers/Categories/CategoryMarker/CategoryMarker.cs @@ -137,5 +137,8 @@ public void ToggleSelection(bool isSelected) if (poolableBehavior.instance != null) poolableBehavior.instance.ToggleSelection(isSelected); } + + public Vector2Int? GetParcelPosition() => + placeInfo?.base_position_processed; } } diff --git a/Explorer/Assets/DCL/MapRenderer/MapLayers/IMapRendererMarker.cs b/Explorer/Assets/DCL/MapRenderer/MapLayers/IMapRendererMarker.cs index 0284e85980..15642985a7 100644 --- a/Explorer/Assets/DCL/MapRenderer/MapLayers/IMapRendererMarker.cs +++ b/Explorer/Assets/DCL/MapRenderer/MapLayers/IMapRendererMarker.cs @@ -17,5 +17,8 @@ UniTaskVoid AnimateSelectionAsync(CancellationToken ct) => UniTaskVoid AnimateDeSelectionAsync(CancellationToken ct) => new (); + + Vector2Int? GetParcelPosition() => + null; } } diff --git a/Explorer/Assets/DCL/MapRenderer/MapLayers/Pins/PinMarker.cs b/Explorer/Assets/DCL/MapRenderer/MapLayers/Pins/PinMarker.cs index 2b44415cc7..09eaea81aa 100644 --- a/Explorer/Assets/DCL/MapRenderer/MapLayers/Pins/PinMarker.cs +++ b/Explorer/Assets/DCL/MapRenderer/MapLayers/Pins/PinMarker.cs @@ -175,5 +175,8 @@ public void Hide(Action? onFinish) public GameObject? GetGameObject() => poolableBehavior.instance != null ? poolableBehavior.instance.gameObject : null; + + public Vector2Int? GetParcelPosition() => + ParcelPosition; } } diff --git a/Explorer/Assets/DCL/MapRenderer/MapLayers/PointsOfInterest/SceneOfInterestMarker.cs b/Explorer/Assets/DCL/MapRenderer/MapLayers/PointsOfInterest/SceneOfInterestMarker.cs index 74a3ce36d5..4e0d228ab7 100644 --- a/Explorer/Assets/DCL/MapRenderer/MapLayers/PointsOfInterest/SceneOfInterestMarker.cs +++ b/Explorer/Assets/DCL/MapRenderer/MapLayers/PointsOfInterest/SceneOfInterestMarker.cs @@ -110,5 +110,8 @@ public void ToggleSelection(bool isSelected) if (poolableBehavior.instance != null) poolableBehavior.instance.ToggleSelection(isSelected); } + + public Vector2Int? GetParcelPosition() => + placeInfo.base_position_processed; } } diff --git a/Explorer/Assets/DCL/MapRenderer/MapLayers/PointsOfInterest/ScenesOfInterestMarkersController.cs b/Explorer/Assets/DCL/MapRenderer/MapLayers/PointsOfInterest/ScenesOfInterestMarkersController.cs index f9fdcda2f5..bddaeac36f 100644 --- a/Explorer/Assets/DCL/MapRenderer/MapLayers/PointsOfInterest/ScenesOfInterestMarkersController.cs +++ b/Explorer/Assets/DCL/MapRenderer/MapLayers/PointsOfInterest/ScenesOfInterestMarkersController.cs @@ -241,7 +241,7 @@ public bool TryClickObject(GameObject gameObject, CancellationTokenSource cts, o if (visibleMarkers.TryGetValue(gameObject, out ISceneOfInterestMarker marker)) { marker.ToggleSelection(true); - navmapBus.SelectPlaceAsync(marker.PlaceInfo, cts.Token).Forget(); + navmapBus.SelectPlaceAsync(marker.PlaceInfo, cts.Token, true).Forget(); mapRenderMarker = marker; return true; } diff --git a/Explorer/Assets/DCL/MapRenderer/MapLayers/SearchResults/SearchResultMarker/SearchResultMarker.cs b/Explorer/Assets/DCL/MapRenderer/MapLayers/SearchResults/SearchResultMarker/SearchResultMarker.cs index 0b6335b341..28578f1ee1 100644 --- a/Explorer/Assets/DCL/MapRenderer/MapLayers/SearchResults/SearchResultMarker/SearchResultMarker.cs +++ b/Explorer/Assets/DCL/MapRenderer/MapLayers/SearchResults/SearchResultMarker/SearchResultMarker.cs @@ -117,5 +117,8 @@ public void ToggleSelection(bool isSelected) if (poolableBehavior.instance != null) poolableBehavior.instance.ToggleSelection(isSelected); } + + public Vector2Int? GetParcelPosition() => + placeInfo?.base_position_processed; } } diff --git a/Explorer/Assets/DCL/Navmap/NavmapController.cs b/Explorer/Assets/DCL/Navmap/NavmapController.cs index 8a9fdb7a8e..738c1d76d3 100644 --- a/Explorer/Assets/DCL/Navmap/NavmapController.cs +++ b/Explorer/Assets/DCL/Navmap/NavmapController.cs @@ -6,6 +6,7 @@ using DCL.MapRenderer.ConsumerUtils; using DCL.MapRenderer.MapCameraController; using DCL.MapRenderer.MapLayers; +using DCL.MapRenderer.MapLayers.Pins; using DCL.MapRenderer.MapLayers.PlayerMarker; using DCL.Navmap.FilterPanel; using DCL.PlacesAPIService; @@ -126,14 +127,24 @@ private void RemoveDestination() private void SetDestination(PlacesData.PlaceInfo? placeInfo) { - mapPathEventBus.SetDestination(lastParcelClicked.Parcel, lastParcelClicked.PinMarker); + Vector2Int destinationParcel = placeInfo switch + { + { Positions: { Length: 1 } } => placeInfo.Positions[0], + { Positions: { Length: > 1 } } => placeInfo.base_position_processed, + _ => Vector2Int.zero, + }; + + IPinMarker? destinationPinMarker = destinationParcel == lastParcelClicked.Parcel ? lastParcelClicked.PinMarker : null; + + mapPathEventBus.SetDestination(destinationParcel, destinationPinMarker); navmapView.DestinationInfoElement.gameObject.SetActive(true); - if (lastParcelClicked.PinMarker != null) { navmapView.DestinationInfoElement.Setup(lastParcelClicked.PinMarker.Title, true, lastParcelClicked.PinMarker.CurrentSprite); } + if (destinationPinMarker != null) + navmapView.DestinationInfoElement.Setup(destinationPinMarker.Title, true, destinationPinMarker.CurrentSprite); else { parcelTitleStringBuilder.Clear(); - var parcelDescription = parcelTitleStringBuilder.Append(placeInfo != null ? placeInfo.title : EMPTY_PARCEL_NAME).Append(" ").Append(lastParcelClicked.Parcel.ToString()).ToString(); + var parcelDescription = parcelTitleStringBuilder.Append(placeInfo != null ? placeInfo.title : EMPTY_PARCEL_NAME).Append(" ").Append(destinationParcel.ToString()).ToString(); navmapView.DestinationInfoElement.Setup(parcelDescription, false, null); } } @@ -156,7 +167,7 @@ async UniTaskVoid FetchPlaceAndShowAsync(CancellationToken ct) if (place == null) place = new PlacesData.PlaceInfo(clickedParcel.Parcel); - navmapBus.SelectPlaceAsync(place, fetchPlaceAndShowCancellationToken.Token).Forget(); + navmapBus.SelectPlaceAsync(place, fetchPlaceAndShowCancellationToken.Token, true).Forget(); } fetchPlaceAndShowCancellationToken = fetchPlaceAndShowCancellationToken.SafeRestart();