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

feat: align map with sidebar status #2876

Merged
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 @@ -4,6 +4,7 @@
using DCL.MapRenderer.Culling;
using DCL.MapRenderer.MapLayers;
using DCL.MapRenderer.MapLayers.Categories;
using DCL.Navmap;
using DCL.PlacesAPIService;
using System.Collections.Generic;
using System.Threading;
Expand All @@ -17,7 +18,6 @@ internal struct CategoryScenesMarkersInstaller
private const int PREWARM_COUNT = 60;

private Dictionary<MapLayer, IMapLayerController> writer;
private IAssetsProvisioner assetsProvisioner;
private IMapRendererSettings mapSettings;
private IPlacesAPIService placesAPIService;

Expand All @@ -27,16 +27,15 @@ public async UniTask InstallAsync(
MapRendererConfiguration configuration,
ICoordsUtils coordsUtils,
IMapCullingController cullingController,
IAssetsProvisioner assetsProv,
IMapRendererSettings settings,
IPlacesAPIService placesAPI,
ObjectPool<ClusterMarkerObject> clusterObjectsPool,
CategoryMarkerObject prefab,
INavmapBus navmapBus,
CancellationToken cancellationToken
)
{
mapSettings = settings;
assetsProvisioner = assetsProv;
placesAPIService = placesAPI;
this.writer = layerWriter;

Expand All @@ -46,17 +45,17 @@ CancellationToken cancellationToken
actionOnGet: obj => obj.gameObject.SetActive(true),
actionOnRelease: obj => obj.gameObject.SetActive(false));

var artController = CreateCategoryController(MapLayer.Art, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var gameController = CreateCategoryController(MapLayer.Game, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var cryptoController = CreateCategoryController(MapLayer.Crypto, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var educationController = CreateCategoryController(MapLayer.Education, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var socialController = CreateCategoryController(MapLayer.Social, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var businessController = CreateCategoryController(MapLayer.Business, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var casinoController = CreateCategoryController(MapLayer.Casino, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var fashionController = CreateCategoryController(MapLayer.Fashion, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var musicController = CreateCategoryController(MapLayer.Music, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var shopController = CreateCategoryController(MapLayer.Shop, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var sportsController = CreateCategoryController(MapLayer.Sports, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController);
var artController = CreateCategoryController(MapLayer.Art, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var gameController = CreateCategoryController(MapLayer.Game, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var cryptoController = CreateCategoryController(MapLayer.Crypto, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var educationController = CreateCategoryController(MapLayer.Education, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var socialController = CreateCategoryController(MapLayer.Social, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var businessController = CreateCategoryController(MapLayer.Business, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var casinoController = CreateCategoryController(MapLayer.Casino, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var fashionController = CreateCategoryController(MapLayer.Fashion, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var musicController = CreateCategoryController(MapLayer.Music, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var shopController = CreateCategoryController(MapLayer.Shop, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);
var sportsController = CreateCategoryController(MapLayer.Sports, objectsPool, clusterObjectsPool, configuration, coordsUtils, cullingController, navmapBus);

await InitializeControllerAsync(artController, MapLayer.Art, cancellationToken);
zoomScalingWriter.Add(artController);
Expand All @@ -82,7 +81,7 @@ CancellationToken cancellationToken
zoomScalingWriter.Add(sportsController);
}

private CategoryMarkersController CreateCategoryController(MapLayer layer, ObjectPool<CategoryMarkerObject> objectsPool, ObjectPool<ClusterMarkerObject> clusterObjectsPool, MapRendererConfiguration configuration, ICoordsUtils coordsUtils, IMapCullingController cullingController)
private CategoryMarkersController CreateCategoryController(MapLayer layer, ObjectPool<CategoryMarkerObject> objectsPool, ObjectPool<ClusterMarkerObject> clusterObjectsPool, MapRendererConfiguration configuration, ICoordsUtils coordsUtils, IMapCullingController cullingController, INavmapBus navmapBus)
{
return new CategoryMarkersController(
placesAPIService,
Expand All @@ -93,7 +92,8 @@ private CategoryMarkersController CreateCategoryController(MapLayer layer, Objec
cullingController,
mapSettings.CategoryIconMappings,
layer,
new ClusterController(cullingController, clusterObjectsPool, CreateClusterMarker, coordsUtils, layer, mapSettings.CategoryIconMappings)
new ClusterController(cullingController, clusterObjectsPool, CreateClusterMarker, coordsUtils, layer, mapSettings.CategoryIconMappings),
navmapBus
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ await UniTask.WhenAll(
CreateSatelliteAtlasAsync(layers, configuration, coordsUtils, cullingController, cancellationToken),
playerMarkerInstaller.InstallAsync(layers, zoomScalingLayers, configuration, coordsUtils, cullingController, mapSettings, assetsProvisioner, mapPathEventBus, cancellationToken),
sceneOfInterestMarkerInstaller.InstallAsync(layers, zoomScalingLayers, configuration, coordsUtils, cullingController, assetsProvisioner, mapSettings, placesAPIService, clusterObjectsPool, cancellationToken),
categoriesMarkerInstaller.InstallAsync(layers, zoomScalingLayers, configuration, coordsUtils, cullingController, assetsProvisioner, mapSettings, placesAPIService, clusterObjectsPool, categoryMarkerPrefab, cancellationToken),
categoriesMarkerInstaller.InstallAsync(layers, zoomScalingLayers, configuration, coordsUtils, cullingController, mapSettings, placesAPIService, clusterObjectsPool, categoryMarkerPrefab, navmapBus, cancellationToken),
liveEventsMarkersInstaller.InstallAsync(layers, zoomScalingLayers, configuration, coordsUtils, cullingController, assetsProvisioner, mapSettings, eventsApiService, clusterObjectsPool, categoryMarkerPrefab, cancellationToken),
favoritesMarkersInstaller.InstallAsync(layers, zoomScalingLayers, configuration, coordsUtils, cullingController, placesAPIService, assetsProvisioner, mapSettings, clusterObjectsPool, cancellationToken),
hotUsersMarkersInstaller.InstallAsync(layers, configuration, coordsUtils, cullingController, assetsProvisioner, mapSettings, teleportBusController, remoteUsersRequestController, cancellationToken),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using Cysharp.Threading.Tasks;
using DCL.MapRenderer.Culling;
using DCL.Navmap;
using DCL.PlacesAPIService;
using System;
using System.Collections.Generic;
using System.Threading;
using UnityEngine;
using UnityEngine.Pool;
using ICoordsUtils = DCL.MapRenderer.CoordsUtils.ICoordsUtils;
using IPlacesAPIService = DCL.PlacesAPIService.IPlacesAPIService;
using PlacesData = DCL.PlacesAPIService.PlacesData;

namespace DCL.MapRenderer.MapLayers.Categories
{
Expand All @@ -30,6 +33,7 @@ internal delegate IClusterMarker ClusterMarkerBuilder(
private readonly CategoryIconMappingsSO categoryIconMappings;
private readonly IPlacesAPIService placesAPIService;
private readonly ClusterController clusterController;
private readonly INavmapBus navmapBus;

private readonly Dictionary<Vector2Int, IClusterableMarker> markers = new();

Expand All @@ -49,7 +53,8 @@ public CategoryMarkersController(
IMapCullingController cullingController,
CategoryIconMappingsSO categoryIconMappings,
MapLayer mapLayer,
ClusterController clusterController)
ClusterController clusterController,
INavmapBus navmapBus)
: base(instantiationParent, coordsUtils, cullingController)
{
this.placesAPIService = placesAPIService;
Expand All @@ -58,31 +63,44 @@ public CategoryMarkersController(
this.categoryIconMappings = categoryIconMappings;
this.mapLayer = mapLayer;
this.clusterController = clusterController;
this.navmapBus = navmapBus;
this.navmapBus.OnPlaceSearched += OnPlaceSearched;
}

public async UniTask InitializeAsync(CancellationToken cancellationToken)
private void OnPlaceSearched(INavmapBus.SearchPlaceParams searchparams, IReadOnlyList<PlacesData.PlaceInfo> places, int totalresultcount)
{
ReleaseMarkers();

if (string.IsNullOrEmpty(searchparams.category) || !string.IsNullOrEmpty(searchparams.text))
return;

if (!string.IsNullOrEmpty(searchparams.category) && searchparams.category == mapLayer.ToString())
ShowPlaces(places);
}

private async UniTask LoadPlaces(CancellationToken cancellationToken)
public async UniTask InitializeAsync(CancellationToken cancellationToken)
{
IReadOnlyList<OptimizedPlaceInMapResponse> placesOfCategory = await placesAPIService.GetOptimizedPlacesFromTheMap(MapLayerUtils.MapLayerToCategory[mapLayer], cancellationToken);

foreach (OptimizedPlaceInMapResponse placeInfo in placesOfCategory)
}

private void ShowPlaces(IReadOnlyList<PlacesData.PlaceInfo> places)
{
ReleaseMarkers();
foreach (PlacesData.PlaceInfo placeInfo in places)
{
if (markers.ContainsKey(placeInfo.base_position))
if (markers.ContainsKey(MapLayerUtils.GetParcelsCenter(placeInfo)))
continue;

if (IsEmptyParcel(placeInfo))
continue;

var marker = builder(objectsPool, mapCullingController, coordsUtils);
var position = coordsUtils.CoordsToPosition(placeInfo.base_position);
var position = coordsUtils.CoordsToPosition(MapLayerUtils.GetParcelsCenter(placeInfo));

marker.SetData(placeInfo.name, position);
marker.SetData(placeInfo.title, position);
marker.SetCategorySprite(categoryIconMappings.GetCategoryImage(mapLayer));
markers.Add(placeInfo.base_position, marker);
markers.Add(MapLayerUtils.GetParcelsCenter(placeInfo), marker);
marker.SetZoom(coordsUtils.ParcelSize, baseZoom, zoom);

if (isEnabled)
mapCullingController.StartTracking(marker, this);
Expand All @@ -91,8 +109,8 @@ private async UniTask LoadPlaces(CancellationToken cancellationToken)
arePlacesLoaded = true;
}

private static bool IsEmptyParcel(OptimizedPlaceInMapResponse sceneInfo) =>
sceneInfo.name == EMPTY_PARCEL_NAME;
private static bool IsEmptyParcel(PlacesData.PlaceInfo sceneInfo) =>
sceneInfo.title == EMPTY_PARCEL_NAME;

public void ApplyCameraZoom(float baseZoom, float zoom, int zoomLevel)
{
Expand Down Expand Up @@ -125,9 +143,6 @@ public UniTask Disable(CancellationToken cancellationToken)

public async UniTask Enable(CancellationToken cancellationToken)
{
if(!arePlacesLoaded)
await LoadPlaces(cancellationToken);

foreach (ICategoryMarker marker in markers.Values)
mapCullingController.StartTracking(marker, this);

Expand Down Expand Up @@ -160,5 +175,17 @@ public void OnMapObjectCulled(ICategoryMarker marker)
{
marker.OnBecameInvisible();
}

private void ReleaseMarkers()
{
foreach (ICategoryMarker marker in markers.Values)
{
mapCullingController.StopTracking(marker);
marker.OnBecameInvisible();
}

markers.Clear();
clusterController.Disable();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ private void OnPlaceSearched(INavmapBus.SearchPlaceParams searchParams,

markers.Clear();

if (!string.IsNullOrEmpty(searchParams.category))
return;

foreach (PlacesData.PlaceInfo placeInfo in places)
{
if (markers.ContainsKey(MapLayerUtils.GetParcelsCenter(placeInfo)))
Expand Down
20 changes: 10 additions & 10 deletions Explorer/Assets/DCL/Navmap/Assets/Navmap.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,12 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 5006867210413875372}
- {fileID: 3220452891105341307}
- {fileID: 2167939991251870145}
- {fileID: 2126946985619970895}
- {fileID: 4310957910290201615}
- {fileID: 5836288190526832026}
- {fileID: 8644166709826704606}
- {fileID: 3220452891105341307}
- {fileID: 7741478239688773542}
- {fileID: 4523520423438625598}
- {fileID: 6416530793525408042}
Expand Down Expand Up @@ -374,7 +374,7 @@ MonoBehaviour:
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
m_PresetInfoIsWorld: 1
--- !u!114 &8235211841819826033
MonoBehaviour:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -2752,27 +2752,27 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_Pivot.x
value: 0.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_Pivot.y
value: 0.5
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_AnchorMax.x
value: 0.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_AnchorMax.y
value: 0.5
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_AnchorMin.x
value: 0.5
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_AnchorMin.y
value: 0.5
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_SizeDelta.x
Expand Down Expand Up @@ -2812,11 +2812,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_AnchoredPosition.x
value: -320
value: 17
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_AnchoredPosition.y
value: 404
value: -25
objectReference: {fileID: 0}
- target: {fileID: 4811734723808749645, guid: 60404242bfbb74ee0b0c50ee1f90ee88, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
Expand Down
19 changes: 17 additions & 2 deletions Explorer/Assets/DCL/Navmap/CategoryFilterController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using DCL.MapRenderer;
using DCL.MapRenderer.MapLayers;
using DCL.PlacesAPIService;
using System;
using System.Collections.Generic;
using UnityEngine;

namespace DCL.Navmap
{
Expand All @@ -11,6 +11,7 @@ public class CategoryFilterController : IDisposable
private readonly List<CategoryToggleView> categoryToggles;
private readonly IMapRenderer mapRenderer;
private readonly INavmapBus navmapBus;
private CategoryToggleView currentActiveToggle;

public CategoryFilterController(List<CategoryToggleView> categoryToggles, IMapRenderer mapRenderer, INavmapBus navmapBus)
{
Expand All @@ -23,10 +24,24 @@ public CategoryFilterController(List<CategoryToggleView> categoryToggles, IMapRe
mapRenderer.SetSharedLayer(categoryToggleView.Layer, false);
categoryToggleView.ToggleChanged += OnCategoryToggleChanged;
}

navmapBus.OnPlaceSearched += OnPlaceSearched;
}

private void OnCategoryToggleChanged(MapLayer mapLayer, bool isOn)
private void OnPlaceSearched(INavmapBus.SearchPlaceParams searchparams, IReadOnlyList<PlacesData.PlaceInfo> places, int totalresultcount)
{
if (string.IsNullOrEmpty(searchparams.category) && currentActiveToggle != null)
{
currentActiveToggle.SetVisualStatus(false);
currentActiveToggle.Toggle.SetIsOnWithoutNotify(false);
}
}

private void OnCategoryToggleChanged(MapLayer mapLayer, bool isOn, CategoryToggleView toggleView)
{
if (isOn)
currentActiveToggle = toggleView;

navmapBus.FilterByCategory(isOn ? mapLayer.ToString() : null);
mapRenderer.SetSharedLayer(mapLayer, isOn);
}
Expand Down
11 changes: 8 additions & 3 deletions Explorer/Assets/DCL/Navmap/CategoryToggleView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace DCL.Navmap
{
public class CategoryToggleView : MonoBehaviour
{
public event Action<MapLayer, bool> ToggleChanged;
public event Action<MapLayer, bool, CategoryToggleView> ToggleChanged;

[field: SerializeField]
public MapLayer Layer { get; private set; }
Expand All @@ -33,11 +33,16 @@ private void Start()
Toggle.onValueChanged.AddListener(OnToggleValueChanged);
}

private void OnToggleValueChanged(bool isOn)
public void SetVisualStatus(bool isOn)
{
Label.color = isOn ? OffColor : OnColor;
Background.color = isOn ? OnColor : OffColor;
ToggleChanged?.Invoke(Layer, isOn);
}

private void OnToggleValueChanged(bool isOn)
{
SetVisualStatus(isOn);
ToggleChanged?.Invoke(Layer, isOn, this);
}
}
}
4 changes: 4 additions & 0 deletions Explorer/Assets/DCL/Navmap/NavmapSearchBarController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ public void ClearInput()
view.inputField.SetTextWithoutNotify(string.Empty);

view.clearSearchButton.gameObject.SetActive(false);

searchCancellationToken = searchCancellationToken.SafeRestart();
DoDefaultSearch(searchCancellationToken.Token).Forget();
}

public void EnableBack()
Expand Down Expand Up @@ -140,6 +143,7 @@ private void OnInputValueChanged(string searchText)
if (string.IsNullOrEmpty(searchText))
{
historyRecordPanelView.gameObject.SetActive(true);
DoDefaultSearch(searchCancellationToken.Token).Forget();
return;
}

Expand Down
Loading