diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLogStarChartMode.cs index 2d568bd6..314985b3 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLogStarChartMode.cs @@ -241,7 +241,7 @@ namespace NewHorizons.Components } } - public string UniqueIDToName(string uniqueID) + public static string UniqueIDToName(string uniqueID) { var name = TranslationHandler.GetTranslation(uniqueID, TranslationHandler.TextType.UI); diff --git a/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs b/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs new file mode 100644 index 00000000..94f6d9f5 --- /dev/null +++ b/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs @@ -0,0 +1,90 @@ +using NewHorizons.Components; +using NewHorizons.Utility; +using System; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; +using static NewHorizons.External.Configs.StarSystemConfig; + +namespace NewHorizons.Handlers +{ + public class VesselCoordinatePromptHandler + { + private static List> _factPromptPair; + private static List _textureCache; + + public static void RegisterPrompts(List systems) + { + // Have to destroy the images we've created if this isn't the first time it has run + if (_textureCache != null) + { + foreach (var texture in _textureCache) + { + UnityEngine.Object.Destroy(texture); + } + } + + _textureCache = new List(); + _factPromptPair = new List>(); + + foreach (var system in systems) + { + var systemName = system.UniqueID; + var fact = system.Config.factRequiredForWarp; + var nomaiCoords = system.Config.coords; + + RegisterPrompt(systemName, fact, nomaiCoords); + } + } + + private static void RegisterPrompt(string system, string fact, NomaiCoordinates coords) + { + var texture = MakeTexture(coords.x, coords.y, coords.z); + + _textureCache.Add(texture); + + var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(texture.width / 2f, texture.height / 2f)); + + var name = ShipLogStarChartMode.UniqueIDToName(system); + + var prompt = new ScreenPrompt($"{name} ", sprite, 0); + + _factPromptPair.Add(new (fact, prompt)); + + var manager = Locator.GetPromptManager(); + manager.AddScreenPrompt(prompt, manager.GetScreenPromptList(PromptPosition.LowerLeft), manager.GetTextAnchor(PromptPosition.LowerLeft), -1, true); + } + + private static Texture2D MakeTexture(int[] x, int[] y, int[] z) + { + // Put thing here + return new Texture2D(1, 1); + } + + // Gets called from the patches + public static void SetPromptVisibility(bool visible) + { + foreach (var pair in _factPromptPair) + { + var fact = pair.Item1; + var prompt = pair.Item2; + + if (visible) + { + if (string.IsNullOrEmpty(fact) || Locator.GetShipLogManager().IsFactRevealed(fact)) + { + prompt.SetVisibility(true); + } + else + { + prompt.SetVisibility(false); + } + } + else + { + prompt.SetVisibility(false); + } + } + } + } +} diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 495f47ca..fd560863 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -331,6 +331,8 @@ namespace NewHorizons if (shouldWarpInFromShip) _shipWarpController.WarpIn(WearingSuit); else if (shouldWarpInFromVessel) VesselWarpHandler.TeleportToVessel(); else FindObjectOfType().DebugWarp(SystemDict[_currentStarSystem].SpawnPoint); + + VesselCoordinatePromptHandler.RegisterPrompts(SystemDict.Where(system => system.Value.Config.coords != null).Select(x => x.Value).ToList()); } public void EnableWarpDrive() diff --git a/NewHorizons/Patches/EyeCoordinatePromptTriggerPatches.cs b/NewHorizons/Patches/EyeCoordinatePromptTriggerPatches.cs new file mode 100644 index 00000000..68534262 --- /dev/null +++ b/NewHorizons/Patches/EyeCoordinatePromptTriggerPatches.cs @@ -0,0 +1,29 @@ +using HarmonyLib; +using NewHorizons.Handlers; +using UnityEngine; + +namespace NewHorizons.Patches +{ + [HarmonyPatch] + public static class EyeCoordinatePromptTriggerPatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(EyeCoordinatePromptTrigger), nameof(EyeCoordinatePromptTrigger.Update))] + public static void EyeCoordinatePromptTrigger_Update(EyeCoordinatePromptTrigger __instance) + { + var showPrompts = __instance._warpController.HasPower(); + + VesselCoordinatePromptHandler.SetPromptVisibility(showPrompts); + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(EyeCoordinatePromptTrigger), nameof(EyeCoordinatePromptTrigger.OnExit))] + public static void EyeCoordinatePromptTrigger_OnExit(GameObject __0) + { + if (__0.CompareTag("PlayerDetector")) + { + VesselCoordinatePromptHandler.SetPromptVisibility(false); + } + } + } +}