Remove MF dependency (waiting on next owml update for missing hooks)

This commit is contained in:
Nick 2024-03-20 17:05:07 -04:00
parent 962a6f778b
commit 1930882a03
7 changed files with 28 additions and 46 deletions

View File

@ -263,7 +263,6 @@ namespace NewHorizons
// Call this from the menu since we hadn't hooked onto the event yet // Call this from the menu since we hadn't hooked onto the event yet
Delay.FireOnNextUpdate(() => OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single)); Delay.FireOnNextUpdate(() => OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single));
Delay.FireOnNextUpdate(() => _firstLoad = false); Delay.FireOnNextUpdate(() => _firstLoad = false);
Instance.ModHelper.Menus.PauseMenu.OnInit += DebugReload.InitializePauseMenu;
MenuHandler.Init(); MenuHandler.Init();
AchievementHandler.Init(); AchievementHandler.Init();
@ -275,6 +274,13 @@ namespace NewHorizons
LoadAddonManifest("Assets/addon-manifest.json", this); LoadAddonManifest("Assets/addon-manifest.json", this);
} }
public override void SetupPauseMenu()
{
base.SetupPauseMenu();
DebugReload.InitializePauseMenu();
DebugMenu.InitializePauseMenu();
}
public void OnDestroy() public void OnDestroy()
{ {
NHLogger.Log($"Destroying NewHorizons"); NHLogger.Log($"Destroying NewHorizons");

View File

@ -16,7 +16,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="OuterWildsGameLibs" Version="1.1.14.768" /> <PackageReference Include="OuterWildsGameLibs" Version="1.1.14.768" />
<PackageReference Include="OWML" Version="2.9.8" /> <PackageReference Include="OWML" Version="2.10.3" />
<Reference Include="../Lib/System.ComponentModel.Annotations.dll" /> <Reference Include="../Lib/System.ComponentModel.Annotations.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,20 +0,0 @@
using UnityEngine;
using UnityEngine.UI;
namespace NewHorizons.OtherMods.MenuFramework
{
public interface IMenuAPI
{
GameObject TitleScreen_MakeMenuOpenButton(string name, int index, Menu menuToOpen);
GameObject TitleScreen_MakeSceneLoadButton(string name, int index, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null);
Button TitleScreen_MakeSimpleButton(string name, int index);
GameObject PauseMenu_MakeMenuOpenButton(string name, Menu menuToOpen, Menu customMenu = null);
GameObject PauseMenu_MakeSceneLoadButton(string name, SubmitActionLoadScene.LoadableScenes sceneToLoad, PopupMenu confirmPopup = null, Menu customMenu = null);
Button PauseMenu_MakeSimpleButton(string name, Menu customMenu = null);
Menu PauseMenu_MakePauseListMenu(string title);
PopupMenu MakeTwoChoicePopup(string message, string confirmText, string cancelText);
PopupInputMenu MakeInputFieldPopup(string message, string placeholderMessage, string confirmText, string cancelText);
PopupMenu MakeInfoPopup(string message, string continueButtonText);
void RegisterStartupPopup(string message);
}
}

View File

@ -11,15 +11,11 @@ namespace NewHorizons.OtherMods.MenuFramework
{ {
public static class MenuHandler public static class MenuHandler
{ {
private static IMenuAPI _menuApi;
private static List<(IModBehaviour mod, string message, bool repeat)> _registeredPopups = new(); private static List<(IModBehaviour mod, string message, bool repeat)> _registeredPopups = new();
private static List<string> _failedFiles = new(); private static List<string> _failedFiles = new();
public static void Init() public static void Init()
{ {
_menuApi = Main.Instance.ModHelper.Interaction.TryGetModApi<IMenuAPI>("_nebula.MenuFramework");
TextTranslation.Get().OnLanguageChanged += OnLanguageChanged; TextTranslation.Get().OnLanguageChanged += OnLanguageChanged;
} }
@ -35,14 +31,14 @@ namespace NewHorizons.OtherMods.MenuFramework
Application.version); Application.version);
NHLogger.LogError(warning); NHLogger.LogError(warning);
_menuApi.RegisterStartupPopup(warning); Main.Instance.ModHelper.MenuHelper.PopupMenuManager.RegisterStartupPopup(warning);
} }
foreach(var (mod, message, repeat) in _registeredPopups) foreach(var (mod, message, repeat) in _registeredPopups)
{ {
if (repeat || !NewHorizonsData.HasReadOneTimePopup(mod.ModHelper.Manifest.UniqueName)) if (repeat || !NewHorizonsData.HasReadOneTimePopup(mod.ModHelper.Manifest.UniqueName))
{ {
_menuApi.RegisterStartupPopup(TranslationHandler.GetTranslation(message, TranslationHandler.TextType.UI)); Main.Instance.ModHelper.MenuHelper.PopupMenuManager.RegisterStartupPopup(TranslationHandler.GetTranslation(message, TranslationHandler.TextType.UI));
NewHorizonsData.ReadOneTimePopup(mod.ModHelper.Manifest.UniqueName); NewHorizonsData.ReadOneTimePopup(mod.ModHelper.Manifest.UniqueName);
} }
} }
@ -52,7 +48,7 @@ namespace NewHorizons.OtherMods.MenuFramework
var message = TranslationHandler.GetTranslation("JSON_FAILED_TO_LOAD", TranslationHandler.TextType.UI); var message = TranslationHandler.GetTranslation("JSON_FAILED_TO_LOAD", TranslationHandler.TextType.UI);
var mods = string.Join(",", _failedFiles.Take(10)); var mods = string.Join(",", _failedFiles.Take(10));
if (_failedFiles.Count > 10) mods += "..."; if (_failedFiles.Count > 10) mods += "...";
_menuApi.RegisterStartupPopup(string.Format(message, mods)); Main.Instance.ModHelper.MenuHelper.PopupMenuManager.RegisterStartupPopup(string.Format(message, mods));
} }
_registeredPopups.Clear(); _registeredPopups.Clear();

View File

@ -10,12 +10,12 @@ namespace NewHorizons.Utility.DebugTools
public static class DebugReload public static class DebugReload
{ {
private static IModButton _reloadButton; private static SubmitAction _reloadButton;
public static void InitializePauseMenu() public static void InitializePauseMenu()
{ {
_reloadButton = Main.Instance.ModHelper.Menus.PauseMenu.OptionsButton.Duplicate(TranslationHandler.GetTranslation("Reload Configs", TranslationHandler.TextType.UI).ToUpper()); _reloadButton = Main.Instance.ModHelper.MenuHelper.PauseMenuManager.MakeSimpleButton(TranslationHandler.GetTranslation("Reload Configs", TranslationHandler.TextType.UI).ToUpper(), 3, true);
_reloadButton.OnClick += ReloadConfigs; _reloadButton.OnSubmitAction += ReloadConfigs;
UpdateReloadButton(); UpdateReloadButton();
} }
@ -23,8 +23,7 @@ namespace NewHorizons.Utility.DebugTools
{ {
if (_reloadButton != null) if (_reloadButton != null)
{ {
if (Main.Debug) _reloadButton.Show(); _reloadButton.gameObject.SetActive(Main.Debug);
else _reloadButton.Hide();
} }
} }

View File

@ -15,7 +15,7 @@ namespace NewHorizons.Utility.DebugTools.Menu
{ {
class DebugMenu : MonoBehaviour class DebugMenu : MonoBehaviour
{ {
private static IModButton pauseMenuButton; private static SubmitAction pauseMenuButton;
public GUIStyle _editorMenuStyle; public GUIStyle _editorMenuStyle;
public GUIStyle _tabBarStyle; public GUIStyle _tabBarStyle;
@ -35,6 +35,8 @@ namespace NewHorizons.Utility.DebugTools.Menu
private List<DebugSubmenu> submenus; private List<DebugSubmenu> submenus;
private int activeSubmenu = 0; private int activeSubmenu = 0;
private static DebugMenu _instance;
internal static JsonSerializerSettings jsonSettings = new JsonSerializerSettings internal static JsonSerializerSettings jsonSettings = new JsonSerializerSettings
{ {
NullValueHandling = NullValueHandling.Ignore, NullValueHandling = NullValueHandling.Ignore,
@ -57,14 +59,14 @@ namespace NewHorizons.Utility.DebugTools.Menu
{ {
if (!staticInitialized) if (!staticInitialized)
{ {
_instance = this;
staticInitialized = true; staticInitialized = true;
Main.Instance.ModHelper.Menus.PauseMenu.OnInit += PauseMenuInitHook; // This is lying, these hooks dont exist in the new menu system
Main.Instance.ModHelper.Menus.PauseMenu.OnClosed += CloseMenu; Main.Instance.ModHelper.Menus.PauseMenu.OnClosed += CloseMenu;
Main.Instance.ModHelper.Menus.PauseMenu.OnOpened += RestoreMenuOpennessState; Main.Instance.ModHelper.Menus.PauseMenu.OnOpened += RestoreMenuOpennessState;
PauseMenuInitHook();
Main.Instance.OnChangeStarSystem.AddListener((string s) => { Main.Instance.OnChangeStarSystem.AddListener((string s) => {
if (saveButtonUnlocked) if (saveButtonUnlocked)
{ {
@ -84,18 +86,17 @@ namespace NewHorizons.Utility.DebugTools.Menu
} }
} }
private void PauseMenuInitHook() public static void InitializePauseMenu()
{ {
pauseMenuButton = Main.Instance.ModHelper.Menus.PauseMenu.OptionsButton.Duplicate(TranslationHandler.GetTranslation("Toggle Dev Tools Menu", TranslationHandler.TextType.UI).ToUpper()); pauseMenuButton = Main.Instance.ModHelper.MenuHelper.PauseMenuManager.MakeSimpleButton(TranslationHandler.GetTranslation("Toggle Dev Tools Menu", TranslationHandler.TextType.UI).ToUpper(), 3, true);
InitMenu(); _instance.InitMenu();
} }
public static void UpdatePauseMenuButton() public static void UpdatePauseMenuButton()
{ {
if (pauseMenuButton != null) if (pauseMenuButton != null)
{ {
if (Main.Debug) pauseMenuButton.Show(); pauseMenuButton.gameObject.SetActive(Main.Debug);
else pauseMenuButton.Hide();
} }
} }
@ -284,7 +285,7 @@ namespace NewHorizons.Utility.DebugTools.Menu
UpdatePauseMenuButton(); UpdatePauseMenuButton();
// TODO: figure out how to clear this event list so that we don't pile up useless instances of the DebugMenu that can't get garbage collected // TODO: figure out how to clear this event list so that we don't pile up useless instances of the DebugMenu that can't get garbage collected
pauseMenuButton.OnClick += ToggleMenu; pauseMenuButton.OnSubmitAction += ToggleMenu;
submenus.ForEach(submenu => submenu.OnInit(this)); submenus.ForEach(submenu => submenu.OnInit(this));

View File

@ -5,8 +5,8 @@
"name": "New Horizons", "name": "New Horizons",
"uniqueName": "xen.NewHorizons", "uniqueName": "xen.NewHorizons",
"version": "1.19.3", "version": "1.19.3",
"owmlVersion": "2.9.8", "owmlVersion": "2.10.3",
"dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "dependencies": [ "JohnCorby.VanillaFix", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ],
"conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ],
"pathsToPreserve": [ "planets", "systems", "translations" ], "pathsToPreserve": [ "planets", "systems", "translations" ],
"donateLink": "https://www.patreon.com/ownh" "donateLink": "https://www.patreon.com/ownh"