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