| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCLServices.MapRendererV2.CoordsUtils; |
| | 3 | | using DCLServices.MapRendererV2.Culling; |
| | 4 | | using DCLServices.MapRendererV2.MapCameraController; |
| | 5 | | using System; |
| | 6 | | using System.Threading; |
| | 7 | | using UnityEngine; |
| | 8 | |
|
| | 9 | | namespace DCLServices.MapRendererV2.MapLayers.HomePoint |
| | 10 | | { |
| | 11 | | internal class HomePointMarkerController : MapLayerControllerBase, IMapLayerController, IZoomScalingLayer |
| | 12 | | { |
| | 13 | | internal delegate IHomePointMarker HomePointMarkerBuilder(Transform parent); |
| | 14 | |
|
| | 15 | | private readonly BaseVariable<Vector2Int> homePointCoordinates; |
| | 16 | | private readonly HomePointMarkerBuilder builder; |
| | 17 | |
|
| | 18 | | private IHomePointMarker marker; |
| | 19 | |
|
| | 20 | | public HomePointMarkerController( |
| | 21 | | BaseVariable<Vector2Int> homePointCoordinates, |
| | 22 | | HomePointMarkerBuilder builder, |
| | 23 | | Transform instantiationParent, |
| | 24 | | ICoordsUtils coordsUtils, |
| | 25 | | IMapCullingController cullingController) |
| 96 | 26 | | : base(instantiationParent, coordsUtils, cullingController) |
| | 27 | | { |
| 96 | 28 | | this.homePointCoordinates = homePointCoordinates; |
| 96 | 29 | | this.builder = builder; |
| 96 | 30 | | } |
| | 31 | |
|
| | 32 | | public void ApplyCameraZoom(float baseZoom, float zoom) |
| | 33 | | { |
| 0 | 34 | | marker.SetZoom(baseZoom, zoom); |
| 0 | 35 | | } |
| | 36 | |
|
| | 37 | | public void ResetToBaseScale() |
| | 38 | | { |
| 0 | 39 | | marker.ResetToBaseScale(); |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | public void Initialize() |
| | 43 | | { |
| 96 | 44 | | marker = builder(instantiationParent); |
| 96 | 45 | | marker.SetActive(false); |
| 96 | 46 | | } |
| | 47 | |
|
| | 48 | | private void SetMarkerPosition(Vector2Int position) |
| | 49 | | { |
| 0 | 50 | | marker.SetPosition(coordsUtils.CoordsToPosition(position)); |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | public UniTask Enable(CancellationToken cancellationToken) |
| | 54 | | { |
| 0 | 55 | | marker.SetActive(true); |
| 0 | 56 | | SetMarkerPosition(homePointCoordinates.Get()); |
| | 57 | |
|
| 0 | 58 | | homePointCoordinates.OnChange += OnHomePointCoordinatesChange; |
| | 59 | |
|
| 0 | 60 | | return UniTask.CompletedTask; |
| | 61 | | } |
| | 62 | |
|
| | 63 | | public UniTask Disable(CancellationToken cancellationToken) |
| | 64 | | { |
| 88 | 65 | | marker.SetActive(false); |
| | 66 | |
|
| 88 | 67 | | homePointCoordinates.OnChange -= OnHomePointCoordinatesChange; |
| | 68 | |
|
| 88 | 69 | | return UniTask.CompletedTask; |
| | 70 | | } |
| | 71 | |
|
| | 72 | | private void OnHomePointCoordinatesChange(Vector2Int current, Vector2Int previous) |
| | 73 | | { |
| 0 | 74 | | SetMarkerPosition(current); |
| 0 | 75 | | } |
| | 76 | | } |
| | 77 | | } |