From 4e1386b3c42f549fffa7db2fd1d1a627651530e8 Mon Sep 17 00:00:00 2001 From: geuks Date: Thu, 19 Sep 2024 13:17:46 +0200 Subject: [PATCH 1/2] First push minimap Adding minimap --- Config/Settings.cs | 105 +++++++++++++++++++++- Plugin.cs | 1 + UI/Components/MapMiniComponent.cs | 65 ++++++++++++++ UI/Components/MapPeekComponent.cs | 15 ++++ UI/Components/MapView.cs | 2 +- UI/ModdedMapScreen.cs | 139 ++++++++++++++++++++++++++---- 6 files changed, 306 insertions(+), 21 deletions(-) create mode 100644 UI/Components/MapMiniComponent.cs diff --git a/Config/Settings.cs b/Config/Settings.cs index 2a64312..5de888f 100644 --- a/Config/Settings.cs +++ b/Config/Settings.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using BepInEx.Configuration; +using DynamicMaps.UI.Controls; using UnityEngine; // THIS IS HEAVILY BASED ON DRAKIAXYZ'S SPT-QuickMoveToContainer @@ -25,6 +26,17 @@ internal class Settings public static ConfigEntry ChangeMapLevelUpHotkey; public static ConfigEntry ChangeMapLevelDownHotkey; + public static ConfigEntry MiniMapKey; + public static ConfigEntry MiniMapZoomIn; + public static ConfigEntry MiniMapZoomOut; + public static ConfigEntry MiniMapZoom; + public static ConfigEntry MiniMapAnchoredPosition; + public static ConfigEntry MiniMapSizeDelta; + public static ConfigEntry MiniMapAnchorMin; + public static ConfigEntry MiniMapAnchorMax; + public static ConfigEntry MiniMapPivot; + public static ConfigEntry MiniMapLevelSliderPositionOffset; + public static ConfigEntry ZoomMapInHotkey; public static ConfigEntry ZoomMapOutHotkey; public static ConfigEntry ZoomMapHotkeySpeed; @@ -162,10 +174,101 @@ public static void Init(ConfigFile Config) null, new ConfigurationManagerAttributes { }))); + ConfigEntries.Add(MiniMapSizeDelta = Config.Bind( + GeneralTitle, + "Zoom Map size", + new Vector2(200f, 200f), + new ConfigDescription( + "The size of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapAnchoredPosition = Config.Bind( + GeneralTitle, + "Mini Map position", + new Vector2(-10f, -10f), + new ConfigDescription( + "The position of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapAnchorMin = Config.Bind( + GeneralTitle, + "Mini Map anchor min", + new Vector2(1f, 1f), + new ConfigDescription( + "The min anchor of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapAnchorMax = Config.Bind( + GeneralTitle, + "Mini Map anchor max", + new Vector2(1f, 1f), + new ConfigDescription( + "The max anchor of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapPivot = Config.Bind( + GeneralTitle, + "Mini Map Pivot", + new Vector2(1f, 1f), + new ConfigDescription( + "The pivot of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + + ConfigEntries.Add(MiniMapZoom = Config.Bind( + GeneralTitle, + "Mini Map Zoom", + 10f, + new ConfigDescription( + "The zoom of the mini map", + new AcceptableValueRange(1f, 15f), + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapKey = Config.Bind( + GeneralTitle, + "Mini Map Hotkey", + new KeyboardShortcut(KeyCode.End), + new ConfigDescription( + "Active/disable the mini-map.", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapZoomIn = Config.Bind( + GeneralTitle, + "Mini Map Zoom In Hotkey", + new KeyboardShortcut(KeyCode.Keypad8), + new ConfigDescription( + "Zoom in the mini-map.", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapZoomOut = Config.Bind( + GeneralTitle, + "Mini Map Zoom Out Hotkey", + new KeyboardShortcut(KeyCode.Keypad5), + new ConfigDescription( + "Zoom out the mini-map.", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapLevelSliderPositionOffset = Config.Bind( + GeneralTitle, + "Mini Map Level Slider Position Offset", + new Vector2(-10f, 0f), + new ConfigDescription( + "Move the position of level slider of the mini map", + null, + new ConfigurationManagerAttributes { }))); + ConfigEntries.Add(ZoomMapOutHotkey = Config.Bind( GeneralTitle, "Zoom Map Out Hotkey", - new KeyboardShortcut(KeyCode.Minus), + new KeyboardShortcut(KeyCode.KeypadMinus), new ConfigDescription( "Hotkey to zoom the map out (scroll-down also does this in map screen)", null, diff --git a/Plugin.cs b/Plugin.cs index 029d29d..16322f1 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -78,6 +78,7 @@ internal void TryAttachToBattleUIScreen(EftBattleUIScreen battleUI) } Map.TryAddPeekComponent(battleUI); + Map.TryAddMiniMapComponent(battleUI); } } } diff --git a/UI/Components/MapMiniComponent.cs b/UI/Components/MapMiniComponent.cs new file mode 100644 index 0000000..9b94b62 --- /dev/null +++ b/UI/Components/MapMiniComponent.cs @@ -0,0 +1,65 @@ +using BepInEx.Configuration; +using DynamicMaps.Utils; +using UnityEngine; + +namespace DynamicMaps.UI.Components +{ + internal class MapMiniComponent : MonoBehaviour + { + public ModdedMapScreen MapScreen { get; set; } + public RectTransform MapScreenTrueParent { get; set; } + public RectTransform RectTransform { get; private set; } + public KeyboardShortcut ActivateMiniMap { get; set; } + public bool IsActive { get; private set; } + + internal static MapMiniComponent Create(GameObject parent) + { + var go = UIUtils.CreateUIGameObject(parent, "MiniMap"); + go.GetRectTransform().sizeDelta = parent.GetRectTransform().sizeDelta; + var component = go.AddComponent(); + return component; + } + + private void Awake() + { + RectTransform = gameObject.GetRectTransform(); + } + + private void Start() + { + BeginMiniMap(); + } + + private void Update() + { + if (ActivateMiniMap.BetterIsDown()) + { + if (!IsActive) + { + BeginMiniMap(); + } + else + { + EndMiniMap(); + } + } + } + + internal void BeginMiniMap() + { + IsActive = true; + + MapScreen.transform.SetParent(RectTransform); + MapScreen.Show(); + } + + internal void EndMiniMap() + { + MapScreen.WasMinimapActive = MapScreen.IsMinimapActive; + + IsActive = false; + MapScreen.Hide(); + MapScreen.transform.SetParent(MapScreenTrueParent); + } + } +} diff --git a/UI/Components/MapPeekComponent.cs b/UI/Components/MapPeekComponent.cs index fcc14f5..b63b25c 100644 --- a/UI/Components/MapPeekComponent.cs +++ b/UI/Components/MapPeekComponent.cs @@ -1,5 +1,6 @@ using BepInEx.Configuration; using DynamicMaps.Utils; +using EFT.UI.Map; using UnityEngine; namespace DynamicMaps.UI.Components @@ -27,6 +28,7 @@ internal static MapPeekComponent Create(GameObject parent) private void Awake() { RectTransform = gameObject.GetRectTransform(); + IsPeeking = false; } private void Update() @@ -63,6 +65,12 @@ internal void BeginPeek() { return; } + MapScreen.WasMinimapActive = MapScreen.IsMinimapActive; + + if (MapScreen.IsMinimapActive) + { + MapScreen.MiniMapComponent.EndMiniMap(); + } // just in case something else is attached and tries to be in front transform.SetAsLastSibling(); @@ -86,6 +94,13 @@ internal void EndPeek() // un-attach map screen and re-attach to true parent MapScreen.Hide(); MapScreen.transform.SetParent(MapScreenTrueParent); + + if (MapScreen.WasMinimapActive) + { + MapScreen.MiniMapComponent.BeginMiniMap(); + } + + MapScreen.WasMinimapActive = MapScreen.IsMinimapActive; } } } diff --git a/UI/Components/MapView.cs b/UI/Components/MapView.cs index 026ec7f..ecd24b5 100644 --- a/UI/Components/MapView.cs +++ b/UI/Components/MapView.cs @@ -14,7 +14,7 @@ public class MapView : MonoBehaviour { private static Vector2 _markerSize = new Vector2(30, 30); private static float _zoomMaxScaler = 10f; // multiplier against zoomMin - private static float _zoomMinScaler = 1.1f; // divider against ratio of a provided rect + private static float _zoomMinScaler = .9f; // divider against ratio of a provided rect public event Action OnLevelSelected; diff --git a/UI/ModdedMapScreen.cs b/UI/ModdedMapScreen.cs index b5dcaa0..ac65927 100644 --- a/UI/ModdedMapScreen.cs +++ b/UI/ModdedMapScreen.cs @@ -11,6 +11,7 @@ using DynamicMaps.UI.Controls; using DynamicMaps.Utils; using EFT.UI; +using EFT.UI.Map; using UnityEngine; using UnityEngine.UI; @@ -55,8 +56,12 @@ public class ModdedMapScreen : MonoBehaviour private PlayerPositionText _playerPositionText; // peek - private MapPeekComponent _peekComponent; - private bool _isPeeking => _peekComponent != null && _peekComponent.IsPeeking; + internal MapPeekComponent PeekComponent; + internal MapMiniComponent MiniMapComponent; + public bool IsPeeking => PeekComponent != null && PeekComponent.IsPeeking; + public bool IsMinimapActive => MiniMapComponent != null && MiniMapComponent.IsActive; + private float _mainMapZoom; + public bool WasMinimapActive = false; // dynamic map marker providers private Dictionary _dynamicMarkerProviders = new Dictionary(); @@ -157,6 +162,21 @@ private void Update() } } + if (Settings.MiniMapZoomIn.Value.BetterIsDown()) + { + var currentZoom = _mapView.ZoomCurrent + 1f; + _mapView.SetMapZoom(currentZoom, .5f); + Settings.MiniMapZoom.Value = currentZoom; + Settings.Config.Save(); + } + else if (Settings.MiniMapZoomOut.Value.BetterIsDown()) + { + var currentZoom = _mapView.ZoomCurrent - 1f; + _mapView.SetMapZoom(currentZoom, .5f); + Settings.MiniMapZoom.Value = currentZoom; + Settings.Config.Save(); + } + // change level hotkeys if (_moveMapLevelUpShortcut.BetterIsDown()) { @@ -215,6 +235,16 @@ private void Update() _mapView.IncrementalZoomInto(zoomDelta, currentCenter, 0f); } + if (IsMinimapActive) + { + var player = GameUtils.GetMainPlayer(); + if (player != null) + { + var mapPosition = MathUtils.ConvertToMapPosition(player.Position); + _mapView.ShiftMapToCoordinate(mapPosition, _positionTweenTime); + } + } + if (_centerPlayerShortcut.BetterIsDown()) { var player = GameUtils.GetMainPlayer(); @@ -241,7 +271,12 @@ private void Update() internal void OnMapScreenShow() { - _peekComponent?.EndPeek(); + PeekComponent?.EndPeek(); + + if (WasMinimapActive) + { + MiniMapComponent.EndMiniMap(); + } transform.parent.Find("MapBlock").gameObject.SetActive(false); transform.parent.Find("EmptyBlock").gameObject.SetActive(false); @@ -253,12 +288,18 @@ internal void OnMapScreenShow() internal void OnMapScreenClose() { Hide(); + if (WasMinimapActive) + { + MiniMapComponent.BeginMiniMap(); + } } internal void Show() { AdjustSizeAndPosition(); + _mainMapZoom = _mapView.ZoomCurrent; + _isShown = true; gameObject.SetActive(true); @@ -299,16 +340,32 @@ internal void Hide() internal void TryAddPeekComponent(EftBattleUIScreen battleUI) { - if (_peekComponent != null) + if (PeekComponent != null) { return; } Plugin.Log.LogInfo("Trying to attach peek component to BattleUI"); - _peekComponent = MapPeekComponent.Create(battleUI.gameObject); - _peekComponent.MapScreen = this; - _peekComponent.MapScreenTrueParent = _parentTransform; + PeekComponent = MapPeekComponent.Create(battleUI.gameObject); + PeekComponent.MapScreen = this; + PeekComponent.MapScreenTrueParent = _parentTransform; + + ReadConfig(); + } + + internal void TryAddMiniMapComponent(EftBattleUIScreen battleUI) + { + if (MiniMapComponent != null) + { + return; + } + + Plugin.Log.LogInfo("Trying to attach mini map component to BattleUI"); + + MiniMapComponent = MapMiniComponent.Create(battleUI.gameObject); + MiniMapComponent.MapScreen = this; + MiniMapComponent.MapScreenTrueParent = _parentTransform; ReadConfig(); } @@ -330,9 +387,13 @@ internal void OnRaidEnd() } // reset peek and remove reference, it will be destroyed very shortly with parent object - _peekComponent?.EndPeek(); - Destroy(_peekComponent.gameObject); - _peekComponent = null; + PeekComponent?.EndPeek(); + Destroy(PeekComponent.gameObject); + PeekComponent = null; + + MiniMapComponent?.EndMiniMap(); + Destroy(MiniMapComponent.gameObject); + MiniMapComponent = null; // unload map completely when raid ends, since we've removed markers _mapView.UnloadMap(); @@ -365,6 +426,10 @@ private void AdjustForOutOfRaid() _scrollMask.GetRectTransform().anchoredPosition = _maskPositionOutOfRaid; _scrollMask.GetRectTransform().sizeDelta = RectTransform.sizeDelta + _maskSizeModifierOutOfRaid; + _mapView.SetMapZoom(_mainMapZoom, .5f); + + _levelSelectSlider.RectTransform.anchoredPosition = _levelSliderPosition; + // turn on cursor and off player position texts _cursorPositionText.gameObject.SetActive(true); _playerPositionText.gameObject.SetActive(false); @@ -372,32 +437,57 @@ private void AdjustForOutOfRaid() private void AdjustForInRaid() { - // adjust mask _scrollMask.GetRectTransform().anchoredPosition = _maskPositionInRaid; _scrollMask.GetRectTransform().sizeDelta = RectTransform.sizeDelta + _maskSizeModifierInRaid; - // turn both cursor and player position texts on + _levelSelectSlider.gameObject.SetActive(true); _cursorPositionText.gameObject.SetActive(true); _playerPositionText.gameObject.SetActive(true); + + _mapView.SetMapZoom(_mainMapZoom, .5f); + + _cursorPositionText.RectTransform.anchoredPosition = _cursorPositionTextOffset; + _playerPositionText.RectTransform.anchoredPosition = _playerPositionTextOffset; } private void AdjustForPeek() { - // adjust mask _scrollMask.GetRectTransform().anchoredPosition = Vector2.zero; _scrollMask.GetRectTransform().sizeDelta = RectTransform.sizeDelta; - // turn both cursor and player position texts off + _mapView.SetMapZoom(Settings.MiniMapZoom.Value, .5f); + + _levelSelectSlider.gameObject.SetActive(true); + _cursorPositionText.gameObject.SetActive(false); + _playerPositionText.gameObject.SetActive(false); + } + + private void AdjustForMiniMap() + { + _scrollMask.GetRectTransform().anchoredPosition = Settings.MiniMapAnchoredPosition.Value; + _scrollMask.GetRectTransform().sizeDelta = Settings.MiniMapSizeDelta.Value; + _scrollMask.GetRectTransform().anchorMin = Settings.MiniMapAnchorMin.Value; + _scrollMask.GetRectTransform().anchorMax = Settings.MiniMapAnchorMax.Value; + _scrollMask.GetRectTransform().pivot = Settings.MiniMapPivot.Value; + + _mapView.SetMapZoom(_mainMapZoom, .5f); + + + _levelSelectSlider.gameObject.SetActive(false); _cursorPositionText.gameObject.SetActive(false); _playerPositionText.gameObject.SetActive(false); } private void OnShowInRaid() { - if (_isPeeking) + if (IsPeeking) { AdjustForPeek(); } + else if (IsMinimapActive) + { + AdjustForMiniMap(); + } else { AdjustForInRaid(); @@ -514,7 +604,7 @@ private void OnHideOutOfRaid() private void OnScroll(float scrollAmount) { - if (_isPeeking) + if (IsPeeking || IsMinimapActive) { return; } @@ -565,10 +655,21 @@ internal void ReadConfig() _resetZoomOnCenter = Settings.ResetZoomOnCenter.Value; _centeringZoomResetPoint = Settings.CenteringZoomResetPoint.Value; - if (_peekComponent != null) + if (PeekComponent != null) { - _peekComponent.PeekShortcut = Settings.PeekShortcut.Value; - _peekComponent.HoldForPeek = Settings.HoldForPeek.Value; + PeekComponent.PeekShortcut = Settings.PeekShortcut.Value; + PeekComponent.HoldForPeek = Settings.HoldForPeek.Value; + } + + if (MiniMapComponent != null) + { + MiniMapComponent.ActivateMiniMap = Settings.MiniMapKey.Value; + if (IsMinimapActive) + { + _scrollMask.GetRectTransform().anchoredPosition = Settings.MiniMapAnchoredPosition.Value; + _scrollMask.GetRectTransform().sizeDelta = Settings.MiniMapSizeDelta.Value; + _mapView.SetMapZoom(Settings.MiniMapZoom.Value, .5f); + } } AddRemoveMarkerProvider(Settings.ShowPlayerMarker.Value); From ac7eecda1be078d5b076022abbf98f2a1faf5fa1 Mon Sep 17 00:00:00 2001 From: geuks Date: Sat, 21 Sep 2024 13:21:51 +0200 Subject: [PATCH 2/2] polish Adding security to component when its called Adding default value for settings and category for minimap (f12) Fix auto map level Fix zoom in/out when press key Revert key for ZoomMapOut (mistake) --- Config/Settings.cs | 198 ++++++++++++++---------------- UI/Components/MapPeekComponent.cs | 4 +- UI/Components/MapView.cs | 6 +- UI/ModdedMapScreen.cs | 51 ++++---- 4 files changed, 129 insertions(+), 130 deletions(-) diff --git a/Config/Settings.cs b/Config/Settings.cs index 5de888f..8275996 100644 --- a/Config/Settings.cs +++ b/Config/Settings.cs @@ -26,17 +26,6 @@ internal class Settings public static ConfigEntry ChangeMapLevelUpHotkey; public static ConfigEntry ChangeMapLevelDownHotkey; - public static ConfigEntry MiniMapKey; - public static ConfigEntry MiniMapZoomIn; - public static ConfigEntry MiniMapZoomOut; - public static ConfigEntry MiniMapZoom; - public static ConfigEntry MiniMapAnchoredPosition; - public static ConfigEntry MiniMapSizeDelta; - public static ConfigEntry MiniMapAnchorMin; - public static ConfigEntry MiniMapAnchorMax; - public static ConfigEntry MiniMapPivot; - public static ConfigEntry MiniMapLevelSliderPositionOffset; - public static ConfigEntry ZoomMapInHotkey; public static ConfigEntry ZoomMapOutHotkey; public static ConfigEntry ZoomMapHotkeySpeed; @@ -78,6 +67,17 @@ internal class Settings public static ConfigEntry PeekShortcut; public static ConfigEntry HoldForPeek; + public const string MiniMapTitle = "4. Mini-Map"; + public static ConfigEntry MiniMapKey; + public static ConfigEntry MiniMapZoomIn; + public static ConfigEntry MiniMapZoomOut; + public static ConfigEntry MiniMapZoom; + public static ConfigEntry MiniMapAnchoredPosition; + public static ConfigEntry MiniMapSizeDelta; + public static ConfigEntry MiniMapAnchorMin; + public static ConfigEntry MiniMapAnchorMax; + public static ConfigEntry MiniMapPivot; + // public static ConfigEntry KeyboardShortcut; public static void Init(ConfigFile Config) @@ -174,101 +174,10 @@ public static void Init(ConfigFile Config) null, new ConfigurationManagerAttributes { }))); - ConfigEntries.Add(MiniMapSizeDelta = Config.Bind( - GeneralTitle, - "Zoom Map size", - new Vector2(200f, 200f), - new ConfigDescription( - "The size of the mini map", - null, - new ConfigurationManagerAttributes { }))); - - ConfigEntries.Add(MiniMapAnchoredPosition = Config.Bind( - GeneralTitle, - "Mini Map position", - new Vector2(-10f, -10f), - new ConfigDescription( - "The position of the mini map", - null, - new ConfigurationManagerAttributes { }))); - - ConfigEntries.Add(MiniMapAnchorMin = Config.Bind( - GeneralTitle, - "Mini Map anchor min", - new Vector2(1f, 1f), - new ConfigDescription( - "The min anchor of the mini map", - null, - new ConfigurationManagerAttributes { }))); - - ConfigEntries.Add(MiniMapAnchorMax = Config.Bind( - GeneralTitle, - "Mini Map anchor max", - new Vector2(1f, 1f), - new ConfigDescription( - "The max anchor of the mini map", - null, - new ConfigurationManagerAttributes { }))); - - ConfigEntries.Add(MiniMapPivot = Config.Bind( - GeneralTitle, - "Mini Map Pivot", - new Vector2(1f, 1f), - new ConfigDescription( - "The pivot of the mini map", - null, - new ConfigurationManagerAttributes { }))); - - - ConfigEntries.Add(MiniMapZoom = Config.Bind( - GeneralTitle, - "Mini Map Zoom", - 10f, - new ConfigDescription( - "The zoom of the mini map", - new AcceptableValueRange(1f, 15f), - new ConfigurationManagerAttributes { }))); - - ConfigEntries.Add(MiniMapKey = Config.Bind( - GeneralTitle, - "Mini Map Hotkey", - new KeyboardShortcut(KeyCode.End), - new ConfigDescription( - "Active/disable the mini-map.", - null, - new ConfigurationManagerAttributes { }))); - - ConfigEntries.Add(MiniMapZoomIn = Config.Bind( - GeneralTitle, - "Mini Map Zoom In Hotkey", - new KeyboardShortcut(KeyCode.Keypad8), - new ConfigDescription( - "Zoom in the mini-map.", - null, - new ConfigurationManagerAttributes { }))); - - ConfigEntries.Add(MiniMapZoomOut = Config.Bind( - GeneralTitle, - "Mini Map Zoom Out Hotkey", - new KeyboardShortcut(KeyCode.Keypad5), - new ConfigDescription( - "Zoom out the mini-map.", - null, - new ConfigurationManagerAttributes { }))); - - ConfigEntries.Add(MiniMapLevelSliderPositionOffset = Config.Bind( - GeneralTitle, - "Mini Map Level Slider Position Offset", - new Vector2(-10f, 0f), - new ConfigDescription( - "Move the position of level slider of the mini map", - null, - new ConfigurationManagerAttributes { }))); - ConfigEntries.Add(ZoomMapOutHotkey = Config.Bind( GeneralTitle, "Zoom Map Out Hotkey", - new KeyboardShortcut(KeyCode.KeypadMinus), + new KeyboardShortcut(KeyCode.Minus), new ConfigDescription( "Hotkey to zoom the map out (scroll-down also does this in map screen)", null, @@ -499,6 +408,89 @@ public static void Init(ConfigFile Config) null, new ConfigurationManagerAttributes { }))); + //4. Mini-Map START + ConfigEntries.Add(MiniMapSizeDelta = Config.Bind( + MiniMapTitle, + "Zoom Map size", + new Vector2(275f, 275f), + new ConfigDescription( + "The size of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapAnchoredPosition = Config.Bind( + MiniMapTitle, + "Mini Map position", + new Vector2(-10f, -10f), + new ConfigDescription( + "The position of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapAnchorMin = Config.Bind( + MiniMapTitle, + "Mini Map anchor min", + new Vector2(1f, 1f), + new ConfigDescription( + "The min anchor of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapAnchorMax = Config.Bind( + MiniMapTitle, + "Mini Map anchor max", + new Vector2(1f, 1f), + new ConfigDescription( + "The max anchor of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapPivot = Config.Bind( + MiniMapTitle, + "Mini Map Pivot", + new Vector2(1f, 1f), + new ConfigDescription( + "The pivot of the mini map", + null, + new ConfigurationManagerAttributes { }))); + + + ConfigEntries.Add(MiniMapZoom = Config.Bind( + MiniMapTitle, + "Mini Map Zoom", + 10f, + new ConfigDescription( + "The zoom of the mini map", + new AcceptableValueRange(.9f, 15f), + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapKey = Config.Bind( + MiniMapTitle, + "Mini Map Hotkey", + new KeyboardShortcut(KeyCode.End), + new ConfigDescription( + "Active/disable the mini-map.", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapZoomIn = Config.Bind( + MiniMapTitle, + "Mini Map Zoom In Hotkey", + new KeyboardShortcut(KeyCode.Keypad8), + new ConfigDescription( + "Zoom in the mini-map.", + null, + new ConfigurationManagerAttributes { }))); + + ConfigEntries.Add(MiniMapZoomOut = Config.Bind( + MiniMapTitle, + "Mini Map Zoom Out Hotkey", + new KeyboardShortcut(KeyCode.Keypad5), + new ConfigDescription( + "Zoom out the mini-map.", + null, + new ConfigurationManagerAttributes { }))); + //4.Mini-Map END RecalcOrder(); } diff --git a/UI/Components/MapPeekComponent.cs b/UI/Components/MapPeekComponent.cs index b63b25c..26f9276 100644 --- a/UI/Components/MapPeekComponent.cs +++ b/UI/Components/MapPeekComponent.cs @@ -67,7 +67,7 @@ internal void BeginPeek() } MapScreen.WasMinimapActive = MapScreen.IsMinimapActive; - if (MapScreen.IsMinimapActive) + if (MapScreen.IsMinimapActive && MapScreen.MiniMapComponent != null) { MapScreen.MiniMapComponent.EndMiniMap(); } @@ -95,7 +95,7 @@ internal void EndPeek() MapScreen.Hide(); MapScreen.transform.SetParent(MapScreenTrueParent); - if (MapScreen.WasMinimapActive) + if (MapScreen.WasMinimapActive && MapScreen.MiniMapComponent != null) { MapScreen.MiniMapComponent.BeginMiniMap(); } diff --git a/UI/Components/MapView.cs b/UI/Components/MapView.cs index ecd24b5..2a07163 100644 --- a/UI/Components/MapView.cs +++ b/UI/Components/MapView.cs @@ -286,8 +286,10 @@ public void SetMinMaxZoom(RectTransform parentTransform) { // set zoom min and max based on size of map and size of mask var mapSize = RectTransform.sizeDelta; - ZoomMin = Mathf.Min(parentTransform.sizeDelta.x / mapSize.x, parentTransform.sizeDelta.y / mapSize.y) / _zoomMinScaler; - ZoomMax = _zoomMaxScaler * ZoomMin; + var parentSize = parentTransform.sizeDelta; + + ZoomMin = Mathf.Min(parentSize.x / mapSize.x, parentSize.y / mapSize.y) / _zoomMinScaler; + ZoomMax = Mathf.Max(_zoomMaxScaler * ZoomMin, 1.0f); // this will set everything up for initial zoom SetMapZoom(ZoomMin, 0); diff --git a/UI/ModdedMapScreen.cs b/UI/ModdedMapScreen.cs index ac65927..61bf5aa 100644 --- a/UI/ModdedMapScreen.cs +++ b/UI/ModdedMapScreen.cs @@ -235,17 +235,7 @@ private void Update() _mapView.IncrementalZoomInto(zoomDelta, currentCenter, 0f); } - if (IsMinimapActive) - { - var player = GameUtils.GetMainPlayer(); - if (player != null) - { - var mapPosition = MathUtils.ConvertToMapPosition(player.Position); - _mapView.ShiftMapToCoordinate(mapPosition, _positionTweenTime); - } - } - - if (_centerPlayerShortcut.BetterIsDown()) + if (_centerPlayerShortcut.BetterIsDown() || IsMinimapActive) { var player = GameUtils.GetMainPlayer(); if (player != null) @@ -271,11 +261,17 @@ private void Update() internal void OnMapScreenShow() { - PeekComponent?.EndPeek(); + if(PeekComponent != null) + { + PeekComponent.EndPeek(); + } if (WasMinimapActive) { - MiniMapComponent.EndMiniMap(); + if(MiniMapComponent != null) + { + MiniMapComponent.EndMiniMap(); + } } transform.parent.Find("MapBlock").gameObject.SetActive(false); @@ -290,7 +286,10 @@ internal void OnMapScreenClose() Hide(); if (WasMinimapActive) { - MiniMapComponent.BeginMiniMap(); + if(MiniMapComponent != null) + { + MiniMapComponent.BeginMiniMap(); + } } } @@ -387,13 +386,19 @@ internal void OnRaidEnd() } // reset peek and remove reference, it will be destroyed very shortly with parent object - PeekComponent?.EndPeek(); - Destroy(PeekComponent.gameObject); - PeekComponent = null; + if(PeekComponent != null) + { + PeekComponent.EndPeek(); + Destroy(PeekComponent.gameObject); + PeekComponent = null; + } - MiniMapComponent?.EndMiniMap(); - Destroy(MiniMapComponent.gameObject); - MiniMapComponent = null; + if (MiniMapComponent != null) + { + MiniMapComponent.EndMiniMap(); + Destroy(MiniMapComponent.gameObject); + MiniMapComponent = null; + } // unload map completely when raid ends, since we've removed markers _mapView.UnloadMap(); @@ -455,7 +460,7 @@ private void AdjustForPeek() _scrollMask.GetRectTransform().anchoredPosition = Vector2.zero; _scrollMask.GetRectTransform().sizeDelta = RectTransform.sizeDelta; - _mapView.SetMapZoom(Settings.MiniMapZoom.Value, .5f); + _mapView.SetMapZoom(_mainMapZoom, .5f); _levelSelectSlider.gameObject.SetActive(true); _cursorPositionText.gameObject.SetActive(false); @@ -470,8 +475,7 @@ private void AdjustForMiniMap() _scrollMask.GetRectTransform().anchorMax = Settings.MiniMapAnchorMax.Value; _scrollMask.GetRectTransform().pivot = Settings.MiniMapPivot.Value; - _mapView.SetMapZoom(_mainMapZoom, .5f); - + _mapView.SetMapZoom(Settings.MiniMapZoom.Value, .5f); _levelSelectSlider.gameObject.SetActive(false); _cursorPositionText.gameObject.SetActive(false); @@ -668,6 +672,7 @@ internal void ReadConfig() { _scrollMask.GetRectTransform().anchoredPosition = Settings.MiniMapAnchoredPosition.Value; _scrollMask.GetRectTransform().sizeDelta = Settings.MiniMapSizeDelta.Value; + _mapView.SetMapZoom(Settings.MiniMapZoom.Value, .5f); } }