Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Wrong navigation when we click on map markers #3230

Merged
merged 5 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public interface IMapInteractivityController

GameObject? ProcessMousePosition(Vector2 worldPosition, Vector2 screenPosition);

GameObject? ProcessMouseClick(Vector2 worldPosition, Vector2Int parcel);
/// <summary>
/// Returns the parcel position clicked (if any) or null if it doesn't (this includes map markers)
/// </summary>
Vector2Int? ProcessMouseClick(Vector2 worldPosition, Vector2Int parcel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,8 @@ public void ToggleSelection(bool isSelected)
if (poolableBehavior.instance != null)
poolableBehavior.instance.ToggleSelection(isSelected);
}

public Vector2Int? GetParcelPosition() =>
placeInfo?.base_position_processed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@ UniTaskVoid AnimateSelectionAsync(CancellationToken ct) =>

UniTaskVoid AnimateDeSelectionAsync(CancellationToken ct) =>
new ();

Vector2Int? GetParcelPosition() =>
null;
}
}
3 changes: 3 additions & 0 deletions Explorer/Assets/DCL/MapRenderer/MapLayers/Pins/PinMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,8 @@ public void Hide(Action? onFinish)

public GameObject? GetGameObject() =>
poolableBehavior.instance != null ? poolableBehavior.instance.gameObject : null;

public Vector2Int? GetParcelPosition() =>
ParcelPosition;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,8 @@ public void ToggleSelection(bool isSelected)
if (poolableBehavior.instance != null)
poolableBehavior.instance.ToggleSelection(isSelected);
}

public Vector2Int? GetParcelPosition() =>
placeInfo.base_position_processed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,8 @@ public void ToggleSelection(bool isSelected)
if (poolableBehavior.instance != null)
poolableBehavior.instance.ToggleSelection(isSelected);
}

public Vector2Int? GetParcelPosition() =>
placeInfo?.base_position_processed;
}
}
19 changes: 15 additions & 4 deletions Explorer/Assets/DCL/Navmap/NavmapController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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();
Expand Down
Loading