| | 1 | | using DCL; |
| | 2 | | using DCL.ContentModeration; |
| | 3 | | using DCLServices.MapRendererV2.ConsumerUtils; |
| | 4 | | using System; |
| | 5 | | using TMPro; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.UI; |
| | 8 | |
|
| | 9 | | public class MinimapHUDView : MonoBehaviour |
| | 10 | | { |
| | 11 | | public const string VIEW_PATH = "MinimapHUD"; |
| | 12 | | public const string VIEW_OBJECT_NAME = "_MinimapHUD"; |
| | 13 | |
|
| | 14 | | public event Action<string, bool> OnFavoriteToggleClicked; |
| | 15 | |
|
| | 16 | | [Header("Information")] [SerializeField] |
| | 17 | | private TextMeshProUGUI sceneNameText; |
| | 18 | |
|
| | 19 | | [SerializeField] private TextMeshProUGUI playerPositionText; |
| | 20 | | [SerializeField] internal ShowHideAnimator mainShowHideAnimator; |
| | 21 | | [SerializeField] private Button openNavmapButton; |
| | 22 | |
|
| | 23 | | [Header("Options")] [SerializeField] private Button optionsButton; |
| | 24 | | [SerializeField] internal GameObject sceneOptionsPanel; |
| | 25 | | [SerializeField] private ToggleComponentView toggleSceneUI; |
| | 26 | | [SerializeField] internal Button reportSceneButton; |
| | 27 | | [SerializeField] internal ContentModerationReportingButtonComponentView contentModerationReportButton; |
| | 28 | | [SerializeField] internal ToggleComponentView setHomeScene; |
| | 29 | | [SerializeField] internal FavoriteButtonComponentView favoriteToggle; |
| | 30 | | [SerializeField] internal Image disableFavorite; |
| | 31 | | [SerializeField] internal Button copyLocationButton; |
| | 32 | | [SerializeField] internal ShowHideAnimator locationCopiedToast; |
| | 33 | |
|
| | 34 | | [Header("Map Renderer")] |
| | 35 | | public RectTransform mapRenderContainer; |
| | 36 | |
|
| | 37 | | [field: SerializeField] |
| 10 | 38 | | internal RawImage mapRendererTargetImage { get; private set; } |
| | 39 | |
|
| | 40 | | [field: SerializeField] |
| 40 | 41 | | internal PixelPerfectMapRendererTextureProvider pixelPerfectMapRendererTextureProvider { get; private set; } |
| | 42 | |
|
| | 43 | | [field: SerializeField] |
| 20 | 44 | | internal int mapRendererVisibleParcels { get; private set; } |
| | 45 | |
|
| 20 | 46 | | internal IContentModerationReportingButtonComponentView contentModerationButton => contentModerationReportButton; |
| | 47 | |
|
| | 48 | | public RectTransform mapViewport; |
| | 49 | |
|
| | 50 | | public InputAction_Trigger toggleNavMapAction; |
| | 51 | | private IMouseCatcher mouseCatcher; |
| | 52 | | private HUDCanvasCameraModeController hudCanvasCameraModeController; |
| | 53 | | private MinimapHUDController controller; |
| | 54 | |
|
| | 55 | | public event Action OnCopyLocationRequested; |
| | 56 | |
|
| | 57 | | private void Awake() |
| | 58 | | { |
| 10 | 59 | | hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera.hud |
| 10 | 60 | | favoriteToggle.OnFavoriteChange += (uuid, isFavorite) => OnFavoriteToggleClicked?.Invoke(uuid, isFavorite); |
| 10 | 61 | | } |
| | 62 | |
|
| | 63 | | public void Initialize(MinimapHUDController controller) |
| | 64 | | { |
| 10 | 65 | | this.controller = controller; |
| 10 | 66 | | mouseCatcher = SceneReferences.i?.mouseCatcher; |
| 10 | 67 | | gameObject.name = VIEW_OBJECT_NAME; |
| 10 | 68 | | sceneOptionsPanel.SetActive(false); |
| | 69 | |
|
| 10 | 70 | | optionsButton.onClick.AddListener(controller.ToggleOptions); |
| 10 | 71 | | toggleSceneUI.OnSelectedChanged += (isOn, id, name) => controller.ToggleSceneUI(isOn); |
| 10 | 72 | | reportSceneButton.onClick.AddListener(ReportScene); |
| 10 | 73 | | setHomeScene.OnSelectedChanged += (isOn, id, name) => SetHomeScene(isOn); |
| 10 | 74 | | openNavmapButton.onClick.AddListener(toggleNavMapAction.RaiseOnTriggered); |
| 11 | 75 | | copyLocationButton.onClick.AddListener(() => OnCopyLocationRequested?.Invoke()); |
| | 76 | |
|
| 10 | 77 | | if (mouseCatcher != null) |
| 0 | 78 | | mouseCatcher.OnMouseLock += OnMouseLocked; |
| | 79 | |
|
| | 80 | | /*var renderer = MapRenderer.i; |
| | 81 | |
|
| | 82 | | if (renderer != null) |
| | 83 | | { |
| | 84 | | renderer.atlas.viewport = mapViewport; |
| | 85 | | renderer.transform.SetParent(mapRenderContainer); |
| | 86 | | renderer.transform.SetAsFirstSibling(); |
| | 87 | | }*/ |
| 10 | 88 | | } |
| | 89 | |
|
| | 90 | | private void ReportScene() |
| | 91 | | { |
| 1 | 92 | | controller.ReportScene(); |
| 1 | 93 | | controller.ToggleOptions(); |
| 1 | 94 | | } |
| | 95 | |
|
| | 96 | | private void SetHomeScene(bool isOn) |
| | 97 | | { |
| 0 | 98 | | controller.SetHomeScene(isOn); |
| 0 | 99 | | } |
| | 100 | |
|
| | 101 | | internal void OnMouseLocked() |
| | 102 | | { |
| 0 | 103 | | sceneOptionsPanel.SetActive(false); |
| 0 | 104 | | } |
| | 105 | |
|
| | 106 | | internal static MinimapHUDView Create(MinimapHUDController controller) |
| | 107 | | { |
| 10 | 108 | | var view = Instantiate(Resources.Load<GameObject>(VIEW_PATH)).GetComponent<MinimapHUDView>(); |
| 10 | 109 | | view.Initialize(controller); |
| 10 | 110 | | return view; |
| | 111 | | } |
| | 112 | |
|
| | 113 | | internal void UpdateSetHomePanel(bool isHome) |
| | 114 | | { |
| 10 | 115 | | setHomeScene.SetIsOnWithoutNotify(isHome); |
| 10 | 116 | | } |
| | 117 | |
|
| | 118 | | internal void UpdateData(MinimapHUDModel model) |
| | 119 | | { |
| 15 | 120 | | sceneNameText.text = string.IsNullOrEmpty(model.sceneName) ? "Unnamed" : model.sceneName; |
| 15 | 121 | | playerPositionText.text = model.playerPosition; |
| 15 | 122 | | } |
| | 123 | |
|
| | 124 | | public void ToggleOptions() |
| | 125 | | { |
| 2 | 126 | | sceneOptionsPanel.SetActive(!sceneOptionsPanel.activeSelf); |
| 2 | 127 | | } |
| | 128 | |
|
| | 129 | | public void SetVisibility(bool visible) |
| | 130 | | { |
| 11 | 131 | | if (visible && !mainShowHideAnimator.isVisible) |
| 0 | 132 | | mainShowHideAnimator.Show(); |
| 11 | 133 | | else if (!visible && mainShowHideAnimator.isVisible) |
| 0 | 134 | | mainShowHideAnimator.Hide(); |
| 11 | 135 | | } |
| | 136 | |
|
| | 137 | | public void SetCurrentFavoriteStatus(string uuid, bool isFavorite) |
| | 138 | | { |
| 0 | 139 | | favoriteToggle.Configure(new FavoriteButtonComponentModel() |
| | 140 | | { |
| | 141 | | placeUUID = uuid, |
| | 142 | | isFavorite = isFavorite |
| | 143 | | }); |
| 0 | 144 | | } |
| | 145 | |
|
| | 146 | | public void SetIsAPlace(bool isAPlace) |
| | 147 | | { |
| 0 | 148 | | favoriteToggle.gameObject.SetActive(isAPlace); |
| 0 | 149 | | disableFavorite.gameObject.SetActive(!isAPlace); |
| 0 | 150 | | } |
| | 151 | |
|
| | 152 | | public void ShowLocationCopiedToast() |
| | 153 | | { |
| 1 | 154 | | locationCopiedToast.gameObject.SetActive(true); |
| 1 | 155 | | locationCopiedToast.ShowDelayHide(3); |
| 1 | 156 | | } |
| | 157 | |
|
| | 158 | | public void SetReportSceneButtonActive(bool isActive) => |
| 10 | 159 | | reportSceneButton.gameObject.SetActive(isActive); |
| | 160 | |
|
| | 161 | | private void OnDestroy() |
| | 162 | | { |
| 10 | 163 | | if (mouseCatcher != null) |
| 0 | 164 | | mouseCatcher.OnMouseLock -= OnMouseLocked; |
| | 165 | |
|
| 10 | 166 | | hudCanvasCameraModeController?.Dispose(); |
| 10 | 167 | | } |
| | 168 | | } |