diff --git a/NewHorizons/Assets/DefaultMapModeStar.png b/NewHorizons/Assets/DefaultMapModeStar.png index 7bc0ac1b..bdcedc5b 100644 Binary files a/NewHorizons/Assets/DefaultMapModeStar.png and b/NewHorizons/Assets/DefaultMapModeStar.png differ diff --git a/NewHorizons/Builder/Props/Audio/SignalBuilder.cs b/NewHorizons/Builder/Props/Audio/SignalBuilder.cs index 66a86061..b5fbfaf0 100644 --- a/NewHorizons/Builder/Props/Audio/SignalBuilder.cs +++ b/NewHorizons/Builder/Props/Audio/SignalBuilder.cs @@ -1,9 +1,11 @@ using HarmonyLib; +using NewHorizons.External; using NewHorizons.External.Modules.Props.Audio; using NewHorizons.Utility; using NewHorizons.Utility.OWML; using OWML.Common; using OWML.Utils; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -36,27 +38,16 @@ namespace NewHorizons.Builder.Props.Audio }; NumberOfFrequencies = EnumUtils.GetValues().Length; - _qmSignals = new (){ SearchUtilities.Find("QuantumMoon_Body/Signal_Quantum").GetComponent() }; + _qmSignals = new () { SearchUtilities.Find("QuantumMoon_Body/Signal_Quantum").GetComponent() }; _cloakedSignals = new(); Initialized = true; SceneManager.sceneUnloaded -= OnSceneUnloaded; SceneManager.sceneUnloaded += OnSceneUnloaded; - Main.Instance.OnStarSystemLoaded.RemoveListener(OnStarSystemLoaded); - Main.Instance.OnStarSystemLoaded.AddListener(OnStarSystemLoaded); - } - private static HashSet _frequenciesInUse = new(); - - private static void OnSceneUnloaded(Scene _) - { - _frequenciesInUse.Clear(); - } - - private static void OnStarSystemLoaded(string starSystem) - { // If its the base game solar system or eye we get all the main frequencies + var starSystem = Main.Instance.CurrentStarSystem; if (starSystem == "SolarSystem" || starSystem == "EyeOfTheUniverse") { _frequenciesInUse.Add(SignalFrequency.Quantum); @@ -69,19 +60,43 @@ namespace NewHorizons.Builder.Props.Audio // We don't want a scenario where the player knows no frequencies _frequenciesInUse.Add(SignalFrequency.Traveler); + // Make sure the NH save file has all the right frequencies + // Skip "default" + for (int i = 1; i < PlayerData._currentGameSave.knownFrequencies.Length; i++) + { + if (PlayerData._currentGameSave.knownFrequencies[i]) + { + NewHorizonsData.LearnFrequency(AudioSignal.IndexToFrequency(i).ToString()); + } + } + NHLogger.LogVerbose($"Frequencies in use in {starSystem}: {_frequenciesInUse.Join(x => x.ToString())}"); } + private static HashSet _frequenciesInUse = new(); + + private static void OnSceneUnloaded(Scene _) + { + _frequenciesInUse.Clear(); + } + public static bool IsFrequencyInUse(SignalFrequency freq) => _frequenciesInUse.Contains(freq); + public static bool IsFrequencyInUse(string freqString) + { + if (Enum.TryParse(freqString, out var freq)) + { + return IsFrequencyInUse(freq); + } + return false; + } + public static bool IsCloaked(this AudioSignal signal) => _cloakedSignals.Contains(signal); public static bool IsOnQuantumMoon(this AudioSignal signal) => _qmSignals.Contains(signal); public static SignalFrequency AddFrequency(string str) { - if (_customFrequencyNames == null) Init(); - var freq = CollectionUtilities.KeyByValue(_customFrequencyNames, str); if (freq != default) return freq; @@ -99,23 +114,19 @@ namespace NewHorizons.Builder.Props.Audio NumberOfFrequencies = EnumUtils.GetValues().Length; // This stuff happens after the signalscope is Awake so we have to change the number of frequencies now - Object.FindObjectOfType()._strongestSignals = new AudioSignal[NumberOfFrequencies + 1]; + GameObject.FindObjectOfType()._strongestSignals = new AudioSignal[NumberOfFrequencies + 1]; return freq; } public static string GetCustomFrequencyName(SignalFrequency frequencyName) { - if (_customFrequencyNames == null) Init(); - _customFrequencyNames.TryGetValue(frequencyName, out string name); return name; } public static SignalName AddSignalName(string str) { - if (_customSignalNames == null) Init(); - var name = CollectionUtilities.KeyByValue(_customSignalNames, str); if (name != default) return name; @@ -129,8 +140,6 @@ namespace NewHorizons.Builder.Props.Audio public static string GetCustomSignalName(SignalName signalName) { - if (_customSignalNames == null) Init(); - _customSignalNames.TryGetValue(signalName, out string name); return name; } diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 15e34490..60e0e879 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -148,6 +148,7 @@ namespace NewHorizons.Builder.ShipLog astroObject._imageObj = CreateImage(gameObject, image, body.Config.name + " Revealed", layer); astroObject._outlineObj = CreateImage(gameObject, outline, body.Config.name + " Outline", layer); + if (ShipLogHandler.BodyHasEntries(body)) { Image revealedImage = astroObject._imageObj.GetComponent(); @@ -162,6 +163,12 @@ namespace NewHorizons.Builder.ShipLog Rect imageRect = astroObject._imageObj.GetComponent().rect; astroObject._unviewedObj.transform.localPosition = new Vector3(imageRect.width / 2 + unviewedIconOffset, imageRect.height / 2 + unviewedIconOffset, 0); + + // Set all icons inactive, they will be conditionally activated when the map mode is opened for the first time + astroObject._unviewedObj.SetActive(false); + astroObject._imageObj.SetActive(false); + astroObject._outlineObj.SetActive(false); + return astroObject; } #endregion diff --git a/NewHorizons/External/NewHorizonsData.cs b/NewHorizons/External/NewHorizonsData.cs index b691b622..63a62392 100644 --- a/NewHorizons/External/NewHorizonsData.cs +++ b/NewHorizons/External/NewHorizonsData.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.Linq; +using NewHorizons.Builder.Props.Audio; using NewHorizons.Utility.OWML; namespace NewHorizons.External @@ -124,7 +126,6 @@ namespace NewHorizons.External if (!KnowsFrequency(frequency)) { _activeProfile.KnownFrequencies.Add(frequency); - Save(); } } @@ -134,13 +135,12 @@ namespace NewHorizons.External if (KnowsFrequency(frequency)) { _activeProfile.KnownFrequencies.Remove(frequency); - Save(); } } public static bool KnowsMultipleFrequencies() { - return _activeProfile != null && _activeProfile.KnownFrequencies.Count > 0; + return _activeProfile?.KnownFrequencies != null && _activeProfile.KnownFrequencies.Count(SignalBuilder.IsFrequencyInUse) > 1; } #endregion @@ -159,7 +159,6 @@ namespace NewHorizons.External if (!KnowsSignal(signal)) { _activeProfile.KnownSignals.Add(signal); - Save(); } } @@ -170,7 +169,6 @@ namespace NewHorizons.External public static void AddNewlyRevealedFactID(string id) { _activeProfile?.NewlyRevealedFactIDs.Add(id); - Save(); } public static List GetNewlyRevealedFactIDs() @@ -181,7 +179,6 @@ namespace NewHorizons.External public static void ClearNewlyRevealedFactIDs() { _activeProfile?.NewlyRevealedFactIDs.Clear(); - Save(); } #endregion @@ -191,7 +188,6 @@ namespace NewHorizons.External public static void ReadOneTimePopup(string id) { _activeProfile?.PopupsRead.Add(id); - Save(); } public static bool HasReadOneTimePopup(string id) @@ -208,7 +204,6 @@ namespace NewHorizons.External { if (name == CharacterDialogueTree.RECORDING_NAME || name == CharacterDialogueTree.SIGN_NAME) return; _activeProfile?.CharactersTalkedTo.SafeAdd(name); - Save(); } public static bool HasTalkedToFiveCharacters() diff --git a/NewHorizons/Handlers/PlayerSpawnHandler.cs b/NewHorizons/Handlers/PlayerSpawnHandler.cs index 22380665..40670ad8 100644 --- a/NewHorizons/Handlers/PlayerSpawnHandler.cs +++ b/NewHorizons/Handlers/PlayerSpawnHandler.cs @@ -115,6 +115,17 @@ namespace NewHorizons.Handlers } // For some reason none of this seems to apply to the Player. // If somebody ever makes a sound volume thats somehow always applying to the player tho then itd probably be this + + // Sometimes the ship isn't added to the volumes it's meant to now be in + foreach (var volume in SpawnPointBuilder.ShipSpawn.GetAttachedOWRigidbody().GetComponentsInChildren()) + { + if (volume.GetOWTriggerVolume().GetPenetrationDistance(ship.transform.position) > 0) + { + // Add ship to volume + // If it's already tracking it it will complain here but thats fine + volume.GetOWTriggerVolume().AddObjectToVolume(Locator.GetShipDetector()); + } + } } } else if (Main.Instance.CurrentStarSystem != "SolarSystem" && !Main.Instance.IsWarpingFromShip) diff --git a/NewHorizons/Patches/PlayerPatches/PlayerDataPatches.cs b/NewHorizons/Patches/PlayerPatches/PlayerDataPatches.cs index 16056c7b..6785a8a2 100644 --- a/NewHorizons/Patches/PlayerPatches/PlayerDataPatches.cs +++ b/NewHorizons/Patches/PlayerPatches/PlayerDataPatches.cs @@ -85,12 +85,8 @@ namespace NewHorizons.Patches.PlayerPatches [HarmonyPatch(nameof(PlayerData.KnowsMultipleFrequencies))] public static bool PlayerData_KnowsMultipleFrequencies(ref bool __result) { - if (NewHorizonsData.KnowsMultipleFrequencies()) - { - __result = true; - return false; - } - return true; + __result = NewHorizonsData.KnowsMultipleFrequencies(); + return false; } [HarmonyPrefix] @@ -140,5 +136,12 @@ namespace NewHorizons.Patches.PlayerPatches { NewHorizonsData.Reset(); } + + [HarmonyPostfix] + [HarmonyPatch(nameof(PlayerData.SaveCurrentGame))] + public static void PlayerData_SaveCurrentGame() + { + NewHorizonsData.Save(); + } } } diff --git a/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs b/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs index ba3c0e33..abfc67a8 100644 --- a/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs +++ b/NewHorizons/Patches/ShipLogPatches/ShipLogAstroObjectPatches.cs @@ -25,9 +25,32 @@ namespace NewHorizons.Patches.ShipLogPatches } } + [HarmonyPrefix] + [HarmonyPatch(nameof(ShipLogAstroObject.UpdateState))] + public static bool ShipLogAstroObject_UpdateState_Pre(ShipLogAstroObject __instance) + { + // Custom astro objects might have no entries, in this case they will be permanently hidden + // Just treat it as if it were revealed + if (__instance._entries.Count == 0) + { + __instance._state = ShipLogEntry.State.Explored; + __instance._imageObj.SetActive(true); + __instance._outlineObj?.SetActive(false); + if (__instance._image != null) + { + __instance.SetMaterialGreyscale(false); + __instance._image.color = Color.white; + } + + return false; + } + + return true; + } + [HarmonyPostfix] [HarmonyPatch(nameof(ShipLogAstroObject.UpdateState))] - public static void ShipLogAstroObject_UpdateState(ShipLogAstroObject __instance) + public static void ShipLogAstroObject_UpdateState_Post(ShipLogAstroObject __instance) { Transform detailsParent = __instance.transform.Find("Details"); if (detailsParent != null) diff --git a/NewHorizons/Patches/SignalPatches/SignalscopePatches.cs b/NewHorizons/Patches/SignalPatches/SignalscopePatches.cs index 12c54db5..232b2d98 100644 --- a/NewHorizons/Patches/SignalPatches/SignalscopePatches.cs +++ b/NewHorizons/Patches/SignalPatches/SignalscopePatches.cs @@ -1,5 +1,6 @@ using HarmonyLib; using NewHorizons.Builder.Props.Audio; +using NewHorizons.Utility.OWML; namespace NewHorizons.Patches.SignalPatches { @@ -19,13 +20,17 @@ namespace NewHorizons.Patches.SignalPatches { var count = SignalBuilder.NumberOfFrequencies; __instance._frequencyFilterIndex += increment; - __instance._frequencyFilterIndex = __instance._frequencyFilterIndex >= count ? 0 : __instance._frequencyFilterIndex; - __instance._frequencyFilterIndex = __instance._frequencyFilterIndex < 0 ? count - 1 : __instance._frequencyFilterIndex; + __instance._frequencyFilterIndex = __instance._frequencyFilterIndex >= count ? 1 : __instance._frequencyFilterIndex; + __instance._frequencyFilterIndex = __instance._frequencyFilterIndex < 1 ? count - 1 : __instance._frequencyFilterIndex; var signalFrequency = AudioSignal.IndexToFrequency(__instance._frequencyFilterIndex); + NHLogger.Log($"Changed freq to {signalFrequency} at {__instance._frequencyFilterIndex}"); + // Skip over this frequency - var isUnknown = !PlayerData.KnowsFrequency(signalFrequency) && !(__instance._isUnknownFreqNearby && __instance._unknownFrequency == signalFrequency); - if (isUnknown || !SignalBuilder.IsFrequencyInUse(signalFrequency)) + // Never skip traveler (always known) + var isTraveler = __instance._frequencyFilterIndex == 1; + var isUnknown = !PlayerData.KnowsFrequency(signalFrequency) && (!__instance._isUnknownFreqNearby || __instance._unknownFrequency != signalFrequency); + if (!isTraveler && (isUnknown || !SignalBuilder.IsFrequencyInUse(signalFrequency))) { __instance.SwitchFrequencyFilter(increment); }