| | 1 | | using TMPro; |
| | 2 | | using UnityEngine; |
| | 3 | | using UnityEngine.UI; |
| | 4 | |
|
| | 5 | | namespace DCL |
| | 6 | | { |
| | 7 | |
|
| | 8 | | public class NavmapView : MonoBehaviour |
| | 9 | | { |
| | 10 | | [SerializeField] internal ScrollRect scrollRect; |
| | 11 | | [SerializeField] private Transform scrollRectContentTransform; |
| | 12 | |
|
| | 13 | | [Header("TEXT")] |
| | 14 | | [SerializeField] internal TextMeshProUGUI currentSceneNameText; |
| | 15 | | [SerializeField] internal TextMeshProUGUI currentSceneCoordsText; |
| | 16 | |
|
| | 17 | | [Space] |
| | 18 | | [SerializeField] internal NavmapToastView toastView; |
| | 19 | | [SerializeField] private NavmapZoom zoom; |
| | 20 | |
|
| | 21 | | internal NavmapVisibilityBehaviour navmapVisibilityBehaviour; |
| | 22 | |
|
| | 23 | | private RectTransform rectTransform; |
| | 24 | |
|
| | 25 | |
|
| 0 | 26 | | private RectTransform RectTransform => rectTransform ??= transform as RectTransform; |
| 0 | 27 | | private BaseVariable<bool> navmapVisible => DataStore.i.HUDs.navmapVisible; |
| 6 | 28 | | private BaseVariable<Transform> configureMapInFullscreenMenu => DataStore.i.exploreV2.configureMapInFullscreenMe |
| | 29 | |
|
| | 30 | | void Start() |
| | 31 | | { |
| 2 | 32 | | navmapVisibilityBehaviour = new NavmapVisibilityBehaviour(DataStore.i.HUDs.navmapVisible, scrollRect, scroll |
| | 33 | |
|
| 2 | 34 | | ConfigureMapInFullscreenMenuChanged(configureMapInFullscreenMenu.Get(), null); |
| | 35 | |
|
| 2 | 36 | | scrollRect.gameObject.SetActive(false); |
| 2 | 37 | | DataStore.i.HUDs.isNavMapInitialized.Set(true); |
| 2 | 38 | | } |
| | 39 | |
|
| | 40 | | private void OnEnable() |
| | 41 | | { |
| 2 | 42 | | configureMapInFullscreenMenu.OnChange += ConfigureMapInFullscreenMenuChanged; |
| | 43 | |
|
| 2 | 44 | | scrollRect.onValueChanged.AddListener(OnScrollValueChanged); |
| 2 | 45 | | CommonScriptableObjects.playerCoords.OnChange += UpdateCurrentSceneData; |
| 2 | 46 | | } |
| | 47 | |
|
| | 48 | | private void OnDisable() |
| | 49 | | { |
| 2 | 50 | | configureMapInFullscreenMenu.OnChange -= ConfigureMapInFullscreenMenuChanged; |
| | 51 | |
|
| 2 | 52 | | scrollRect.onValueChanged.RemoveListener(OnScrollValueChanged); |
| 2 | 53 | | CommonScriptableObjects.playerCoords.OnChange -= UpdateCurrentSceneData; |
| 2 | 54 | | } |
| | 55 | |
|
| | 56 | | private void OnDestroy() |
| | 57 | | { |
| 2 | 58 | | navmapVisibilityBehaviour.Dispose(); |
| 2 | 59 | | } |
| | 60 | |
|
| | 61 | | private void ConfigureMapInFullscreenMenuChanged(Transform currentParentTransform, Transform _) |
| | 62 | | { |
| 2 | 63 | | if (currentParentTransform == null || transform.parent == currentParentTransform) |
| 2 | 64 | | return; |
| | 65 | |
|
| 0 | 66 | | transform.SetParent(currentParentTransform); |
| 0 | 67 | | transform.localScale = Vector3.one; |
| | 68 | |
|
| 0 | 69 | | RectTransform.anchorMin = Vector2.zero; |
| 0 | 70 | | RectTransform.anchorMax = Vector2.one; |
| 0 | 71 | | RectTransform.pivot = new Vector2(0.5f, 0.5f); |
| 0 | 72 | | RectTransform.localPosition = Vector2.zero; |
| 0 | 73 | | RectTransform.offsetMax = Vector2.zero; |
| 0 | 74 | | RectTransform.offsetMin = Vector2.zero; |
| 0 | 75 | | } |
| | 76 | |
|
| | 77 | | private void OnScrollValueChanged(Vector2 _) |
| | 78 | | { |
| 0 | 79 | | if (!navmapVisible.Get()) |
| 0 | 80 | | return; |
| | 81 | |
|
| 0 | 82 | | MapRenderer.i.atlas.UpdateCulling(); |
| 0 | 83 | | toastView.Close(); |
| 0 | 84 | | } |
| | 85 | |
|
| | 86 | | private void UpdateCurrentSceneData(Vector2Int current, Vector2Int _) |
| | 87 | | { |
| | 88 | | const string format = "{0},{1}"; |
| 1 | 89 | | currentSceneCoordsText.text = string.Format(format, current.x, current.y); |
| 1 | 90 | | currentSceneNameText.text = MinimapMetadata.GetMetadata().GetSceneInfo(current.x, current.y)?.name ?? "Unnam |
| 1 | 91 | | } |
| | 92 | | } |
| | 93 | | } |