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