diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 97bfa2ae..c2d635a3 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -43,6 +43,8 @@ namespace NewHorizons public bool IsWarping { get; private set; } = false; public bool WearingSuit { get; private set; } = false; + public static bool HasWarpDrive { get; private set; } = false; + private ShipWarpController _shipWarpController; public override object GetApi() @@ -59,6 +61,7 @@ namespace NewHorizons BodyDict["SolarSystem"] = new List(); Tools.Patches.Apply(); + Tools.WarpDrivePatches.Apply(); Tools.OWCameraFix.Apply(); Logger.Log("Begin load of config files...", Logger.LogType.Log); @@ -107,6 +110,8 @@ namespace NewHorizons // Make the warp controller if there are multiple star systems if (BodyDict.Keys.Count > 1) { + HasWarpDrive = true; + _shipWarpController = GameObject.Find("Ship_Body").AddComponent(); Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => ShipLogBuilder.Init()); diff --git a/NewHorizons/Tools/Patches.cs b/NewHorizons/Tools/Patches.cs index 4ee1062b..cc02fc79 100644 --- a/NewHorizons/Tools/Patches.cs +++ b/NewHorizons/Tools/Patches.cs @@ -50,13 +50,8 @@ namespace NewHorizons.Tools Main.Instance.ModHelper.HarmonyHelper.AddPrefix("UpdateOrbitalLaunchValues", typeof(Patches), nameof(Patches.OnProbeLauncherUpdateOrbitalLaunchValues)); Main.Instance.ModHelper.HarmonyHelper.AddPrefix("IsLaunched", typeof(Patches), nameof(Patches.OnSurveyorProbeIsLaunched)); - Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Update", typeof(Patches), nameof(Patches.OnShipLogControllerUpdate)); - - Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Update", typeof(Patches), nameof(Patches.OnShipCockpitControllerUpdate)); - // Postfixes Main.Instance.ModHelper.HarmonyHelper.AddPostfix("Awake", typeof(Patches), nameof(Patches.OnMapControllerAwake)); - Main.Instance.ModHelper.HarmonyHelper.AddPostfix("EnterMode", typeof(Patches), nameof(Patches.OnShipLogMapModeEnterMode)); } public static bool GetHUDDisplayName(ReferenceFrame __instance, ref string __result) @@ -340,38 +335,6 @@ namespace NewHorizons.Tools return (Locator.GetPlayerRulesetDetector()?.GetPlanetoidRuleset()?.GetGravityVolume() != null); } - public static bool OnShipLogControllerUpdate(ShipLogController __instance) - { - if (__instance._exiting - || OWInput.GetInputMode() != InputMode.ShipComputer - || __instance._currentMode.AllowCancelInput() && OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.All) - || ShipLogBuilder.ShipLogStarChartMode == null) - return true; - - __instance._exitPrompt.SetVisibility(__instance._currentMode.AllowCancelInput()); - __instance._currentMode.UpdateMode(); - if (__instance._currentMode.AllowModeSwap() && OWInput.IsNewlyPressed(InputLibrary.swapShipLogMode, InputMode.All)) - { - ShipLogMode currentMode = __instance._currentMode; - string focusedEntryID = currentMode.GetFocusedEntryID(); - if (!focusedEntryID.Equals("")) return true; - bool flag = currentMode.Equals(__instance._mapMode); - __instance._currentMode = (flag ? __instance._detectiveMode : __instance._mapMode); - - if (currentMode.Equals(__instance._mapMode)) - __instance._currentMode = ShipLogBuilder.ShipLogStarChartMode; - else if (currentMode.Equals(ShipLogBuilder.ShipLogStarChartMode)) - __instance._currentMode = __instance._detectiveMode; - else - __instance._currentMode = __instance._mapMode; - - currentMode.ExitMode(); - __instance._currentMode.EnterMode(focusedEntryID, null); - __instance._oneShotSource.PlayOneShot(flag ? global::AudioType.ShipLogEnterDetectiveMode : global::AudioType.ShipLogEnterMapMode, 1f); - } - return false; - } - public static bool OnSurveyorProbeIsLaunched(SurveyorProbe __instance, ref bool __result) { try @@ -384,27 +347,5 @@ namespace NewHorizons.Tools } return false; } - - public static bool OnShipCockpitControllerUpdate(ShipCockpitController __instance) - { - if(__instance._playerAtFlightConsole && OWInput.IsNewlyPressed(InputLibrary.autopilot, InputMode.ShipCockpit)) - { - var targetSystem = ShipLogBuilder.ShipLogStarChartMode.GetTargetStarSystem(); - if (targetSystem != null) - { - Main.Instance.ChangeCurrentStarSystem(targetSystem, true); - return false; - } - } - return true; - } - - public static void OnShipLogMapModeEnterMode(ShipLogMapMode __instance) - { - var newPrompt = "Interstellar Mode"; - __instance._detectiveModePrompt.SetText(newPrompt); - var text = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); - text.text = newPrompt; - } } } diff --git a/NewHorizons/Tools/WarpDrivePatches.cs b/NewHorizons/Tools/WarpDrivePatches.cs new file mode 100644 index 00000000..e84d0d71 --- /dev/null +++ b/NewHorizons/Tools/WarpDrivePatches.cs @@ -0,0 +1,82 @@ +using NewHorizons.Builder.General; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace NewHorizons.Tools +{ + public static class WarpDrivePatches + { + public static void Apply() + { + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Update", typeof(WarpDrivePatches), nameof(WarpDrivePatches.OnShipCockpitControllerUpdate)); + + Main.Instance.ModHelper.HarmonyHelper.AddPostfix("EnterMode", typeof(WarpDrivePatches), nameof(WarpDrivePatches.OnShipLogMapModeEnterMode)); + + Main.Instance.ModHelper.HarmonyHelper.AddPrefix("Update", typeof(WarpDrivePatches), nameof(WarpDrivePatches.OnShipLogControllerUpdate)); + } + + public static void OnShipLogMapModeEnterMode(ShipLogMapMode __instance) + { + if (!Main.HasWarpDrive) return; + + var newPrompt = "Interstellar Mode"; + __instance._detectiveModePrompt.SetText(newPrompt); + var text = GameObject.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/ScreenPromptListScaleRoot/ScreenPromptList_UpperRight/ScreenPrompt/Text").GetComponent(); + text.text = newPrompt; + } + + public static bool OnShipCockpitControllerUpdate(ShipCockpitController __instance) + { + if (!Main.HasWarpDrive) return true; + + if (__instance._playerAtFlightConsole && OWInput.IsNewlyPressed(InputLibrary.autopilot, InputMode.ShipCockpit)) + { + var targetSystem = ShipLogBuilder.ShipLogStarChartMode.GetTargetStarSystem(); + if (targetSystem != null) + { + Main.Instance.ChangeCurrentStarSystem(targetSystem, true); + return false; + } + } + return true; + } + + public static bool OnShipLogControllerUpdate(ShipLogController __instance) + { + if (!Main.HasWarpDrive) return true; + + if (__instance._exiting + || OWInput.GetInputMode() != InputMode.ShipComputer + || __instance._currentMode.AllowCancelInput() && OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.All) + || ShipLogBuilder.ShipLogStarChartMode == null) + return true; + + __instance._exitPrompt.SetVisibility(__instance._currentMode.AllowCancelInput()); + __instance._currentMode.UpdateMode(); + if (__instance._currentMode.AllowModeSwap() && OWInput.IsNewlyPressed(InputLibrary.swapShipLogMode, InputMode.All)) + { + ShipLogMode currentMode = __instance._currentMode; + string focusedEntryID = currentMode.GetFocusedEntryID(); + if (!focusedEntryID.Equals("")) return true; + bool flag = currentMode.Equals(__instance._mapMode); + __instance._currentMode = (flag ? __instance._detectiveMode : __instance._mapMode); + + if (currentMode.Equals(__instance._mapMode)) + __instance._currentMode = ShipLogBuilder.ShipLogStarChartMode; + else if (currentMode.Equals(ShipLogBuilder.ShipLogStarChartMode)) + __instance._currentMode = __instance._detectiveMode; + else + __instance._currentMode = __instance._mapMode; + + currentMode.ExitMode(); + __instance._currentMode.EnterMode(focusedEntryID, null); + __instance._oneShotSource.PlayOneShot(flag ? global::AudioType.ShipLogEnterDetectiveMode : global::AudioType.ShipLogEnterMapMode, 1f); + } + return false; + } + } +}