| | 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 | |
|
| 12 | 12 | | private int START_MENU_HOVER_BOOL = Animator.StringToHash("hover"); |
| 12 | 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 | | [SerializeField] internal ToggleComponentView setHomeScene; |
| | 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 | | private MinimapHUDController controller; |
| | 38 | |
|
| 22 | 39 | | private void Awake() { hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), Dat |
| | 40 | |
|
| | 41 | | public void Initialize(MinimapHUDController controller) |
| | 42 | | { |
| 11 | 43 | | this.controller = controller; |
| 11 | 44 | | mouseCatcher = SceneReferences.i?.mouseCatcher; |
| 11 | 45 | | gameObject.name = VIEW_OBJECT_NAME; |
| 11 | 46 | | sceneOptionsPanel.SetActive(false); |
| | 47 | |
|
| 11 | 48 | | optionsButton.onClick.AddListener(controller.ToggleOptions); |
| 11 | 49 | | toggleSceneUI.OnSelectedChanged += (isOn, id, name) => controller.ToggleSceneUI(isOn); |
| 11 | 50 | | reportSceneButton.onClick.AddListener(ReportScene); |
| 11 | 51 | | setHomeScene.OnSelectedChanged += (isOn, id, name) => SetHomeScene(isOn); |
| 11 | 52 | | openNavmapButton.onClick.AddListener(toggleNavMapAction.RaiseOnTriggered); |
| | 53 | |
|
| 11 | 54 | | if (mouseCatcher != null) |
| 11 | 55 | | mouseCatcher.OnMouseLock += OnMouseLocked; |
| | 56 | |
|
| 11 | 57 | | var renderer = MapRenderer.i; |
| | 58 | |
|
| 11 | 59 | | if (renderer != null) |
| | 60 | | { |
| 11 | 61 | | renderer.atlas.viewport = mapViewport; |
| 11 | 62 | | renderer.transform.SetParent(mapRenderContainer); |
| 11 | 63 | | renderer.transform.SetAsFirstSibling(); |
| | 64 | | } |
| 11 | 65 | | usersAroundListHudButton.gameObject.SetActive(false); |
| 11 | 66 | | } |
| | 67 | |
|
| | 68 | | private void ReportScene() |
| | 69 | | { |
| 1 | 70 | | controller.ReportScene(); |
| 1 | 71 | | controller.ToggleOptions(); |
| 1 | 72 | | } |
| | 73 | |
|
| | 74 | | private void SetHomeScene(bool isOn) |
| | 75 | | { |
| 0 | 76 | | controller.SetHomeScene(isOn); |
| 0 | 77 | | } |
| | 78 | |
|
| | 79 | | internal void OnMouseLocked() |
| | 80 | | { |
| 0 | 81 | | sceneOptionsPanel.SetActive(false); |
| 0 | 82 | | } |
| | 83 | |
|
| | 84 | | internal static MinimapHUDView Create(MinimapHUDController controller) |
| | 85 | | { |
| 11 | 86 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<MinimapHUDView>(); |
| 11 | 87 | | view.Initialize(controller); |
| 11 | 88 | | return view; |
| | 89 | | } |
| | 90 | |
|
| | 91 | | internal void UpdateSetHomePanel(bool isHome) |
| | 92 | | { |
| 1 | 93 | | setHomeScene.SetIsOnWithoutNotify(isHome); |
| 1 | 94 | | } |
| | 95 | |
|
| | 96 | | internal void UpdateData(MinimapHUDModel model) |
| | 97 | | { |
| 16 | 98 | | sceneNameText.text = string.IsNullOrEmpty(model.sceneName) ? "Unnamed" : model.sceneName; |
| 16 | 99 | | playerPositionText.text = model.playerPosition; |
| 16 | 100 | | } |
| | 101 | |
|
| 4 | 102 | | public void ToggleOptions() { sceneOptionsPanel.SetActive(!sceneOptionsPanel.activeSelf); } |
| | 103 | |
|
| | 104 | | public void SetVisibility(bool visible) |
| | 105 | | { |
| 1 | 106 | | if (visible && !mainShowHideAnimator.isVisible) |
| 0 | 107 | | mainShowHideAnimator.Show(); |
| 1 | 108 | | else if (!visible && mainShowHideAnimator.isVisible) |
| 0 | 109 | | mainShowHideAnimator.Hide(); |
| 1 | 110 | | } |
| | 111 | |
|
| | 112 | | private void OnDestroy() |
| | 113 | | { |
| 11 | 114 | | if(mouseCatcher != null) |
| 11 | 115 | | mouseCatcher.OnMouseLock -= OnMouseLocked; |
| 11 | 116 | | hudCanvasCameraModeController?.Dispose(); |
| 11 | 117 | | } |
| | 118 | | } |