diff --git a/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs index a7b972ed..85aa5870 100644 --- a/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs @@ -21,10 +21,8 @@ namespace NewHorizons.Components.ShipLog private Vector2 _panRootPos = Vector2.zero; private Vector2 _startPanPos; - private ScreenPromptList _upperRightPromptList; private ScreenPromptList _centerPromptList; - private ScreenPrompt _detectiveModePrompt; private ScreenPrompt _targetSystemPrompt; private ScreenPrompt _warpPrompt = new ScreenPrompt(InputLibrary.autopilot, " Warp to system"); @@ -45,9 +43,7 @@ namespace NewHorizons.Components.ShipLog _oneShotSource = oneShotSource; _centerPromptList = centerPromptList; - _upperRightPromptList = upperRightPromptList; - _detectiveModePrompt = new ScreenPrompt(InputLibrary.swapShipLogMode, UITextLibrary.GetString(UITextType.LogRumorModePrompt), 0, ScreenPrompt.DisplayState.Normal, false); _targetSystemPrompt = new ScreenPrompt(InputLibrary.markEntryOnHUD, TranslationHandler.GetTranslation("LOCK_AUTOPILOT_WARP", TranslationHandler.TextType.UI), 0, ScreenPrompt.DisplayState.Normal, false); GlobalMessenger.AddListener("TargetReferenceFrame", new Callback(OnTargetReferenceFrame)); @@ -166,7 +162,7 @@ namespace NewHorizons.Components.ShipLog { gameObject.SetActive(true); - Locator.GetPromptManager().AddScreenPrompt(_detectiveModePrompt, _upperRightPromptList, TextAnchor.MiddleRight, -1, true); + _oneShotSource.PlayOneShot(AudioType.ShipLogEnterMapMode); Locator.GetPromptManager().AddScreenPrompt(_targetSystemPrompt, _centerPromptList, TextAnchor.MiddleCenter, -1, true); } @@ -174,7 +170,6 @@ namespace NewHorizons.Components.ShipLog { gameObject.SetActive(false); - Locator.GetPromptManager().RemoveScreenPrompt(_detectiveModePrompt); Locator.GetPromptManager().RemoveScreenPrompt(_targetSystemPrompt); } diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs index 4ddec030..f9195a3f 100644 --- a/NewHorizons/Handlers/StarChartHandler.cs +++ b/NewHorizons/Handlers/StarChartHandler.cs @@ -1,6 +1,7 @@ using NewHorizons.Components.ShipLog; using NewHorizons.Utility; using System.Collections.Generic; +using NewHorizons.OtherMods.CustomShipLogModes; using UnityEngine; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Handlers @@ -45,14 +46,7 @@ namespace NewHorizons.Handlers panRoot.transform.localPosition = Vector3.zero; panRoot.transform.localRotation = Quaternion.Euler(0, 0, 0); - var centerPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_Center")?.GetComponent(); - var upperRightPromptList = shipLogRoot.transform.Find("ScreenPromptListScaleRoot/ScreenPromptList_UpperRight")?.GetComponent(); - var oneShotSource = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/OneShotAudio_ShipLog")?.GetComponent(); - - ShipLogStarChartMode.Initialize( - centerPromptList, - upperRightPromptList, - oneShotSource); + CustomShipLogModesHandler.AddInterstellarMode(); } _starSystemToFactID = new Dictionary(); diff --git a/NewHorizons/OtherMods/CustomShipLogModes/CustomShipLogModesHandler.cs b/NewHorizons/OtherMods/CustomShipLogModes/CustomShipLogModesHandler.cs new file mode 100644 index 00000000..1ceed1eb --- /dev/null +++ b/NewHorizons/OtherMods/CustomShipLogModes/CustomShipLogModesHandler.cs @@ -0,0 +1,20 @@ +using NewHorizons.Handlers; + +namespace NewHorizons.OtherMods.CustomShipLogModes; + +public static class CustomShipLogModesHandler +{ + private static readonly ICustomShipLogModesAPI API; + + static CustomShipLogModesHandler() + { + API = Main.Instance.ModHelper.Interaction.TryGetModApi("dgarro.CustomShipLogModes"); + } + + public static void AddInterstellarMode() + { + API.AddMode(StarChartHandler.ShipLogStarChartMode, + () => Main.HasWarpDrive, + () => TranslationHandler.GetTranslation("INTERSTELLAR_MODE", TranslationHandler.TextType.UI)); + } +} diff --git a/NewHorizons/OtherMods/CustomShipLogModes/ICustomShipLogModes.cs b/NewHorizons/OtherMods/CustomShipLogModes/ICustomShipLogModes.cs new file mode 100644 index 00000000..9ada5f3f --- /dev/null +++ b/NewHorizons/OtherMods/CustomShipLogModes/ICustomShipLogModes.cs @@ -0,0 +1,8 @@ +using System; + +namespace NewHorizons.OtherMods.CustomShipLogModes; + +public interface ICustomShipLogModesAPI +{ + public void AddMode(ShipLogMode mode, Func isEnabledSupplier, Func nameSupplier); +} diff --git a/NewHorizons/Patches/WarpDrivePatches.cs b/NewHorizons/Patches/WarpDrivePatches.cs index 610cfbdd..4520fa97 100644 --- a/NewHorizons/Patches/WarpDrivePatches.cs +++ b/NewHorizons/Patches/WarpDrivePatches.cs @@ -7,18 +7,6 @@ namespace NewHorizons.Patches [HarmonyPatch] public static class WarpDrivePatches { - [HarmonyPostfix] - [HarmonyPatch(typeof(ShipLogMapMode), nameof(ShipLogMapMode.EnterMode))] - public static void ShipLogMapMode_EnterMode(ShipLogMapMode __instance) - { - if (!Main.HasWarpDrive) return; - - var newPrompt = TranslationHandler.GetTranslation("INTERSTELLAR_MODE", TranslationHandler.TextType.UI); - __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; - } - [HarmonyPrefix] [HarmonyPatch(typeof(ShipCockpitController), nameof(ShipCockpitController.Update))] public static bool ShipCockpitController_Update(ShipCockpitController __instance) @@ -37,42 +25,5 @@ namespace NewHorizons.Patches } return true; } - - [HarmonyPrefix] - [HarmonyPatch(typeof(ShipLogController), nameof(ShipLogController.Update))] - public static bool ShipLogController_Update(ShipLogController __instance) - { - if (!Main.HasWarpDrive) return true; - - if (__instance._exiting - || OWInput.GetInputMode() != InputMode.ShipComputer - || __instance._currentMode.AllowCancelInput() && OWInput.IsNewlyPressed(InputLibrary.cancel, InputMode.All) - || StarChartHandler.ShipLogStarChartMode == null) - return true; - - // Mostly copied from the base method but we're trying to fit in our new mode - __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 = StarChartHandler.ShipLogStarChartMode; - else if (currentMode.Equals(StarChartHandler.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; - } } } diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index ae3d41c3..4a8968b9 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -6,7 +6,7 @@ "uniqueName": "xen.NewHorizons", "version": "1.6.2", "owmlVersion": "2.7.2", - "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility" ], + "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_Randomizer" ], "pathsToPreserve": [ "planets", "systems", "translations" ] }