Remove MF dependency (#815)

## Improvements
- No longer required Menu Framework as popups are now supported in OWML

## Bug fixes
- Fixed sector stuff breaking in props loaded from asset bundles
This commit is contained in:
xen-42 2024-03-22 15:51:13 -04:00 committed by GitHub
commit 178318b80f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 65 additions and 92 deletions

View File

@ -101,6 +101,7 @@ namespace NewHorizons.Builder.Props
GameObject prop;
bool isItem;
bool invalidComponentFound = false;
bool isFromAssetBundle = !string.IsNullOrEmpty(detail.assetBundle);
// We save copies with all their components fixed, good if the user is placing the same detail more than once
if (detail?.path != null && _fixedPrefabCache.TryGetValue((sector, detail.path), out var storedPrefab))
@ -139,12 +140,21 @@ namespace NewHorizons.Builder.Props
}
else
{
FixSectoredComponent(component, sector, existingSectors, detail.keepLoaded);
FixSectoredComponent(component, sector, existingSectors);
}
// Fix cull groups only when not from an asset bundle (because then they're there on purpose!)
// keepLoaded should remove existing groups
// renderers/colliders get enabled later so we dont have to do that here
if (detail.keepLoaded && !isFromAssetBundle && component is SectorCullGroup or SectorCollisionGroup or SectorLightsCullGroup)
{
UnityEngine.Object.DestroyImmediate(component);
continue;
}
// Asset bundle is a real string -> Object loaded from unity
// If they're adding dialogue we have to manually register the xml text
if (!string.IsNullOrEmpty(detail.assetBundle) && component is CharacterDialogueTree dialogue)
if (isFromAssetBundle && component is CharacterDialogueTree dialogue)
{
DialogueBuilder.AddTranslation(dialogue._xmlCharacterDialogueAsset.text, null);
}
@ -278,16 +288,8 @@ namespace NewHorizons.Builder.Props
/// <summary>
/// Fix components that have sectors. Has a specific fix if there is a VisionTorchItem on the object.
/// </summary>
private static void FixSectoredComponent(Component component, Sector sector, HashSet<Sector> existingSectors, bool keepLoaded)
private static void FixSectoredComponent(Component component, Sector sector, HashSet<Sector> existingSectors)
{
// keepLoaded should remove existing groups
// renderers/colliders get enabled later so we dont have to do that here
if (keepLoaded && component is SectorCullGroup or SectorCollisionGroup or SectorLightsCullGroup)
{
UnityEngine.Object.DestroyImmediate(component);
return;
}
// fix Sector stuff, eg SectorCullGroup (without this, props that have a SectorCullGroup component will become invisible inappropriately)
if (component is ISectorGroup sectorGroup && !existingSectors.Contains(sectorGroup.GetSector()))
{
@ -295,15 +297,8 @@ namespace NewHorizons.Builder.Props
}
// Not doing else if here because idk if any of the classes below implement ISectorGroup
// Null check else shuttles controls break
// parent sector is always null before Awake so this code actually never runs lol
if (component is Sector s && s.GetParentSector() != null && !existingSectors.Contains(s.GetParentSector()))
{
s.SetParentSector(sector);
}
else if(component is SectoredMonoBehaviour behaviour && !existingSectors.Contains(behaviour._sector))
if(component is SectoredMonoBehaviour behaviour && !existingSectors.Contains(behaviour._sector))
{
// not using SetSector here because it registers the events twice
// perhaps this happens with ISectorGroup.SetSector or Sector.SetParentSector too? idk and nothing seems to break because of it yet

View File

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

View File

@ -16,7 +16,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="OuterWildsGameLibs" Version="1.1.14.768" />
<PackageReference Include="OWML" Version="2.9.8" />
<PackageReference Include="OWML" Version="2.11.1" />
<Reference Include="../Lib/System.ComponentModel.Annotations.dll" />
</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
{
private static IMenuAPI _menuApi;
private static List<(IModBehaviour mod, string message, bool repeat)> _registeredPopups = new();
private static List<string> _failedFiles = new();
public static void Init()
{
_menuApi = Main.Instance.ModHelper.Interaction.TryGetModApi<IMenuAPI>("_nebula.MenuFramework");
TextTranslation.Get().OnLanguageChanged += OnLanguageChanged;
}
@ -35,14 +31,14 @@ namespace NewHorizons.OtherMods.MenuFramework
Application.version);
NHLogger.LogError(warning);
_menuApi.RegisterStartupPopup(warning);
Main.Instance.ModHelper.MenuHelper.PopupMenuManager.RegisterStartupPopup(warning);
}
foreach(var (mod, message, repeat) in _registeredPopups)
{
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);
}
}
@ -52,7 +48,7 @@ namespace NewHorizons.OtherMods.MenuFramework
var message = TranslationHandler.GetTranslation("JSON_FAILED_TO_LOAD", TranslationHandler.TextType.UI);
var mods = string.Join(",", _failedFiles.Take(10));
if (_failedFiles.Count > 10) mods += "...";
_menuApi.RegisterStartupPopup(string.Format(message, mods));
Main.Instance.ModHelper.MenuHelper.PopupMenuManager.RegisterStartupPopup(string.Format(message, mods));
}
_registeredPopups.Clear();

View File

@ -3,6 +3,7 @@ using NewHorizons.Utility.Files;
using NewHorizons.Utility.OWML;
using OWML.Common;
using OWML.Common.Menus;
using OWML.Utils;
using System;
namespace NewHorizons.Utility.DebugTools
@ -10,22 +11,18 @@ namespace NewHorizons.Utility.DebugTools
public static class DebugReload
{
private static IModButton _reloadButton;
private static SubmitAction _reloadButton;
public static void InitializePauseMenu()
public static void InitializePauseMenu(IPauseMenuManager pauseMenu)
{
_reloadButton = Main.Instance.ModHelper.Menus.PauseMenu.OptionsButton.Duplicate(TranslationHandler.GetTranslation("Reload Configs", TranslationHandler.TextType.UI).ToUpper());
_reloadButton.OnClick += ReloadConfigs;
_reloadButton = pauseMenu.MakeSimpleButton(TranslationHandler.GetTranslation("Reload Configs", TranslationHandler.TextType.UI).ToUpper(), 3, true);
_reloadButton.OnSubmitAction += ReloadConfigs;
UpdateReloadButton();
}
public static void UpdateReloadButton()
{
if (_reloadButton != null)
{
if (Main.Debug) _reloadButton.Show();
else _reloadButton.Hide();
}
_reloadButton?.SetButtonVisible(Main.Debug);
}
private static void ReloadConfigs()

View File

@ -5,6 +5,7 @@ using NewHorizons.Utility.OWML;
using Newtonsoft.Json;
using OWML.Common;
using OWML.Common.Menus;
using OWML.Utils;
using System;
using System.Collections.Generic;
using System.IO;
@ -15,7 +16,7 @@ namespace NewHorizons.Utility.DebugTools.Menu
{
class DebugMenu : MonoBehaviour
{
private static IModButton pauseMenuButton;
private static SubmitAction pauseMenuButton;
public GUIStyle _editorMenuStyle;
public GUIStyle _tabBarStyle;
@ -23,7 +24,6 @@ namespace NewHorizons.Utility.DebugTools.Menu
internal Vector2 EditorMenuSize = new Vector2(600, 900);
bool menuOpen = false;
static bool openMenuOnPause;
static bool staticInitialized;
// Menu params
internal static IModBehaviour loadedMod = null;
@ -34,6 +34,8 @@ namespace NewHorizons.Utility.DebugTools.Menu
// Submenus
private List<DebugSubmenu> submenus;
private int activeSubmenu = 0;
private static DebugMenu _instance;
internal static JsonSerializerSettings jsonSettings = new JsonSerializerSettings
{
@ -55,28 +57,13 @@ namespace NewHorizons.Utility.DebugTools.Menu
private void Start()
{
if (!staticInitialized)
{
staticInitialized = true;
_instance = this;
Main.Instance.ModHelper.Menus.PauseMenu.OnInit += PauseMenuInitHook;
Main.Instance.ModHelper.Menus.PauseMenu.OnClosed += CloseMenu;
Main.Instance.ModHelper.Menus.PauseMenu.OnOpened += RestoreMenuOpennessState;
Main.Instance.ModHelper.MenuHelper.PauseMenuManager.PauseMenuOpened += OnOpenMenu;
Main.Instance.ModHelper.MenuHelper.PauseMenuManager.PauseMenuClosed += OnCloseMenu;
Main.Instance.OnChangeStarSystem.AddListener(OnChangeStarSystem);
PauseMenuInitHook();
Main.Instance.OnChangeStarSystem.AddListener((string s) => {
if (saveButtonUnlocked)
{
SaveLoadedConfigsForRecentSystem();
saveButtonUnlocked = false;
}
});
}
else
{
InitMenu();
}
InitMenu();
if (loadedMod != null)
{
@ -84,26 +71,38 @@ namespace NewHorizons.Utility.DebugTools.Menu
}
}
private void PauseMenuInitHook()
public void OnDestroy()
{
pauseMenuButton = Main.Instance.ModHelper.Menus.PauseMenu.OptionsButton.Duplicate(TranslationHandler.GetTranslation("Toggle Dev Tools Menu", TranslationHandler.TextType.UI).ToUpper());
InitMenu();
Main.Instance.ModHelper.MenuHelper.PauseMenuManager.PauseMenuOpened -= OnOpenMenu;
Main.Instance.ModHelper.MenuHelper.PauseMenuManager.PauseMenuClosed -= OnCloseMenu;
Main.Instance.OnChangeStarSystem.RemoveListener(OnChangeStarSystem);
}
private void OnChangeStarSystem(string _)
{
if (saveButtonUnlocked)
{
SaveLoadedConfigsForRecentSystem();
saveButtonUnlocked = false;
}
}
public static void InitializePauseMenu(IPauseMenuManager pauseMenu)
{
pauseMenuButton = pauseMenu.MakeSimpleButton(TranslationHandler.GetTranslation("Toggle Dev Tools Menu", TranslationHandler.TextType.UI).ToUpper(), 3, true);
_instance?.InitMenu();
}
public static void UpdatePauseMenuButton()
{
if (pauseMenuButton != null)
{
if (Main.Debug) pauseMenuButton.Show();
else pauseMenuButton.Hide();
}
pauseMenuButton?.SetButtonVisible(Main.Debug);
}
private void RestoreMenuOpennessState() { menuOpen = openMenuOnPause; }
private void OnOpenMenu() { menuOpen = openMenuOnPause; }
private void ToggleMenu() { menuOpen = !menuOpen; openMenuOnPause = !openMenuOnPause; }
private void CloseMenu() { menuOpen = false; }
private void OnCloseMenu() { menuOpen = false; }
private void OnGUI()
{
@ -284,7 +283,7 @@ namespace NewHorizons.Utility.DebugTools.Menu
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
pauseMenuButton.OnClick += ToggleMenu;
pauseMenuButton.OnSubmitAction += ToggleMenu;
submenus.ForEach(submenu => submenu.OnInit(this));

View File

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