diff --git a/Config/Settings.cs b/Config/Settings.cs index 2a64312..8275996 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 @@ -66,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) @@ -396,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/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..26f9276 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 != null) + { + 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 != null) + { + MapScreen.MiniMapComponent.BeginMiniMap(); + } + + MapScreen.WasMinimapActive = MapScreen.IsMinimapActive; } } } diff --git a/UI/Components/MapView.cs b/UI/Components/MapView.cs index 026ec7f..2a07163 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; @@ -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 b5dcaa0..61bf5aa 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,7 +235,7 @@ private void Update() _mapView.IncrementalZoomInto(zoomDelta, currentCenter, 0f); } - if (_centerPlayerShortcut.BetterIsDown()) + if (_centerPlayerShortcut.BetterIsDown() || IsMinimapActive) { var player = GameUtils.GetMainPlayer(); if (player != null) @@ -241,7 +261,18 @@ private void Update() internal void OnMapScreenShow() { - _peekComponent?.EndPeek(); + if(PeekComponent != null) + { + PeekComponent.EndPeek(); + } + + if (WasMinimapActive) + { + if(MiniMapComponent != null) + { + MiniMapComponent.EndMiniMap(); + } + } transform.parent.Find("MapBlock").gameObject.SetActive(false); transform.parent.Find("EmptyBlock").gameObject.SetActive(false); @@ -253,12 +284,21 @@ internal void OnMapScreenShow() internal void OnMapScreenClose() { Hide(); + if (WasMinimapActive) + { + if(MiniMapComponent != null) + { + MiniMapComponent.BeginMiniMap(); + } + } } internal void Show() { AdjustSizeAndPosition(); + _mainMapZoom = _mapView.ZoomCurrent; + _isShown = true; gameObject.SetActive(true); @@ -299,16 +339,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 +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; + } + + if (MiniMapComponent != null) + { + MiniMapComponent.EndMiniMap(); + Destroy(MiniMapComponent.gameObject); + MiniMapComponent = null; + } // unload map completely when raid ends, since we've removed markers _mapView.UnloadMap(); @@ -365,6 +431,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 +442,56 @@ 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(_mainMapZoom, .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(Settings.MiniMapZoom.Value, .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 +608,7 @@ private void OnHideOutOfRaid() private void OnScroll(float scrollAmount) { - if (_isPeeking) + if (IsPeeking || IsMinimapActive) { return; } @@ -565,10 +659,22 @@ 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; + } + + if (MiniMapComponent != null) { - _peekComponent.PeekShortcut = Settings.PeekShortcut.Value; - _peekComponent.HoldForPeek = Settings.HoldForPeek.Value; + 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);