| | 1 | | using System; |
| | 2 | | using DCL; |
| | 3 | | using TMPro; |
| | 4 | | using UnityEngine; |
| | 5 | | using UnityEngine.UI; |
| | 6 | |
|
| | 7 | | public class MinimapHUDView : MonoBehaviour |
| | 8 | | { |
| | 9 | | public const string VIEW_PATH = "MinimapHUD"; |
| | 10 | | public const string VIEW_OBJECT_NAME = "_MinimapHUD"; |
| | 11 | |
|
| 10 | 12 | | private int START_MENU_HOVER_BOOL = Animator.StringToHash("hover"); |
| 10 | 13 | | private int START_MENU_PRESSED_TRIGGER = Animator.StringToHash("pressed"); |
| | 14 | |
|
| | 15 | | [Header("Information")] [SerializeField] |
| | 16 | | private TextMeshProUGUI sceneNameText; |
| | 17 | |
|
| | 18 | | [SerializeField] private TextMeshProUGUI playerPositionText; |
| | 19 | | [SerializeField] internal ShowHideAnimator mainShowHideAnimator; |
| | 20 | | [SerializeField] private Button openNavmapButton; |
| | 21 | |
|
| | 22 | | [Header("Options")] [SerializeField] private Button optionsButton; |
| | 23 | | [SerializeField] private GameObject sceneOptionsPanel; |
| | 24 | | [SerializeField] private ToggleComponentView toggleSceneUI; |
| | 25 | | [SerializeField] private Button addBookmarkButton; |
| | 26 | | [SerializeField] private Button reportSceneButton; |
| | 27 | | [SerializeField] internal UsersAroundListHUDButtonView usersAroundListHudButton; |
| | 28 | |
|
| | 29 | | [Header("Map Renderer")] public RectTransform mapRenderContainer; |
| | 30 | | public RectTransform mapViewport; |
| | 31 | |
|
| | 32 | | public static System.Action<MinimapHUDModel> OnUpdateData; |
| | 33 | | public static System.Action OnOpenNavmapClicked; |
| | 34 | | public InputAction_Trigger toggleNavMapAction; |
| | 35 | | private IMouseCatcher mouseCatcher; |
| | 36 | | private HUDCanvasCameraModeController hudCanvasCameraModeController; |
| | 37 | |
|
| 18 | 38 | | private void Awake() { hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), Dat |
| | 39 | |
|
| | 40 | | public void Initialize(MinimapHUDController controller) |
| | 41 | | { |
| 9 | 42 | | mouseCatcher = SceneReferences.i?.mouseCatcher; |
| 9 | 43 | | gameObject.name = VIEW_OBJECT_NAME; |
| 9 | 44 | | sceneOptionsPanel.SetActive(false); |
| | 45 | |
|
| 9 | 46 | | optionsButton.onClick.AddListener(controller.ToggleOptions); |
| 9 | 47 | | toggleSceneUI.OnSelectedChanged += (isOn, id, name) => controller.ToggleSceneUI(isOn); |
| 9 | 48 | | addBookmarkButton.onClick.AddListener(controller.AddBookmark); |
| 9 | 49 | | reportSceneButton.onClick.AddListener(controller.ReportScene); |
| 9 | 50 | | openNavmapButton.onClick.AddListener(toggleNavMapAction.RaiseOnTriggered); |
| | 51 | |
|
| 9 | 52 | | if (mouseCatcher != null) |
| 9 | 53 | | mouseCatcher.OnMouseLock += OnMouseLocked; |
| | 54 | |
|
| 9 | 55 | | var renderer = MapRenderer.i; |
| | 56 | |
|
| 9 | 57 | | if (renderer != null) |
| | 58 | | { |
| 9 | 59 | | renderer.atlas.viewport = mapViewport; |
| 9 | 60 | | renderer.transform.SetParent(mapRenderContainer); |
| 9 | 61 | | renderer.transform.SetAsFirstSibling(); |
| | 62 | | } |
| 9 | 63 | | usersAroundListHudButton.gameObject.SetActive(false); |
| 9 | 64 | | } |
| | 65 | |
|
| | 66 | | internal void OnMouseLocked() |
| | 67 | | { |
| 0 | 68 | | sceneOptionsPanel.SetActive(false); |
| 0 | 69 | | } |
| | 70 | |
|
| | 71 | | internal static MinimapHUDView Create(MinimapHUDController controller) |
| | 72 | | { |
| 9 | 73 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<MinimapHUDView>(); |
| 9 | 74 | | view.Initialize(controller); |
| 9 | 75 | | return view; |
| | 76 | | } |
| | 77 | |
|
| | 78 | | internal void UpdateData(MinimapHUDModel model) |
| | 79 | | { |
| 12 | 80 | | sceneNameText.text = string.IsNullOrEmpty(model.sceneName) ? "Unnamed" : model.sceneName; |
| 12 | 81 | | playerPositionText.text = model.playerPosition; |
| 12 | 82 | | } |
| | 83 | |
|
| 0 | 84 | | public void ToggleOptions() { sceneOptionsPanel.SetActive(!sceneOptionsPanel.activeSelf); } |
| | 85 | |
|
| | 86 | | public void SetVisibility(bool visible) |
| | 87 | | { |
| 1 | 88 | | if (visible && !mainShowHideAnimator.isVisible) |
| 0 | 89 | | mainShowHideAnimator.Show(); |
| 1 | 90 | | else if (!visible && mainShowHideAnimator.isVisible) |
| 0 | 91 | | mainShowHideAnimator.Hide(); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | private void OnDestroy() |
| | 95 | | { |
| 9 | 96 | | if(mouseCatcher != null) |
| 9 | 97 | | mouseCatcher.OnMouseLock -= OnMouseLocked; |
| 9 | 98 | | hudCanvasCameraModeController?.Dispose(); |
| 9 | 99 | | } |
| | 100 | | } |