Skip to content

Commit

Permalink
Merge pull request #571 from ow-mods/dev
Browse files Browse the repository at this point in the history
2.11.0
  • Loading branch information
misternebula authored Mar 22, 2024
2 parents ec64b5c + d96a04d commit 5457e2a
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 37 deletions.
37 changes: 32 additions & 5 deletions src/OWML.Common/Interfaces/IModBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,38 @@ public interface IModBehaviour

object GetApi();

void SetupTitleMenu();

void SetupPauseMenu();

void SetupOptionsMenu();
/// <summary>
/// Called when the title screen has loaded in.
/// Put any code that edits the title menu here.
/// </summary>
void SetupTitleMenu(ITitleMenuManager titleManager);

/// <summary>
/// Called when leaving the title menu scene. Put any event unsubscriptions here.
/// </summary>
void CleanupTitleMenu();

/// <summary>
/// Called when the SolarSystem or EyeOfTheUniverse scene has loaded in.
/// Put any code that edits the pause menu here.
/// </summary>
void SetupPauseMenu(IPauseMenuManager pauseManager);

/// <summary>
/// Called when leaving either game scene. Put any event unsubscriptions here.
/// </summary>
void CleanupPauseMenu();

/// <summary>
/// Called when the main menu or game has loaded in.
/// Put any code that edits the options menu here.
/// </summary>
void SetupOptionsMenu(IOptionsMenuManager optionsManager);

/// <summary>
/// Called when leaving the title or either game scene. Put any event unsubscriptions here.
/// </summary>
void CleanupOptionsMenu();

void Init(IModHelper helper);
}
Expand Down
3 changes: 3 additions & 0 deletions src/OWML.Common/Interfaces/Menus/IOWMLFourChoicePopupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ public interface IOWMLFourChoicePopupMenu
event PopupCancelEvent OnPopupCancel;

void EnableMenu(bool value);

public event Menu.ActivateMenuEvent OnActivateMenu;
public event Menu.DeactivateMenuEvent OnDeactivateMenu;
}
}
4 changes: 4 additions & 0 deletions src/OWML.Common/Interfaces/Menus/IOWMLPopupInputMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public interface IOWMLPopupInputMenu

public InputField GetInputField();

public void SetInputFieldPlaceholderText(string text);

public event PopupMenu.PopupConfirmEvent OnPopupConfirm;
public event Menu.ActivateMenuEvent OnActivateMenu;
public event Menu.DeactivateMenuEvent OnDeactivateMenu;
}
}
3 changes: 3 additions & 0 deletions src/OWML.Common/Interfaces/Menus/IOWMLThreeChoicePopupMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@ public interface IOWMLThreeChoicePopupMenu
event PopupCancelEvent OnPopupCancel;

void EnableMenu(bool value);

public event Menu.ActivateMenuEvent OnActivateMenu;
public event Menu.DeactivateMenuEvent OnDeactivateMenu;
}
}
15 changes: 14 additions & 1 deletion src/OWML.Common/Interfaces/Menus/IPauseMenuManager.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
namespace OWML.Common
using System;
using UnityEngine;

namespace OWML.Common
{
public interface IPauseMenuManager
{
/// <summary>
/// Called when the pause menu is opened.
/// </summary>
event Action PauseMenuOpened;

/// <summary>
/// Called when the pause menu is closed.
/// </summary>
event Action PauseMenuClosed;

/// <summary>
/// Makes another list of buttons that can be seen in the pause menu.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/OWML.Launcher/OWML.Manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Alek",
"name": "OWML",
"uniqueName": "Alek.OWML",
"version": "2.10.3",
"version": "2.11.0",
"minGameVersion": "1.1.14.768",
"maxGameVersion": "1.1.14.768"
}
35 changes: 31 additions & 4 deletions src/OWML.ModHelper.Menus/NewMenuSystem/MenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ enum SettingType
internal static Menu OWMLSettingsMenu;
internal static List<(IModBehaviour behaviour, Menu modMenu)> ModSettingsMenus = new();

private bool _hasSetupMenusThisScene = false;

public MenuManager(
IModConsole console,
IHarmonyHelper harmony,
Expand All @@ -56,9 +58,27 @@ public MenuManager(
var harmonyInstance = harmony.GetValue<Harmony>("_harmony");
harmonyInstance.PatchAll(typeof(Patches));

LoadManager.OnStartSceneLoad += (oldScene, newScene) =>
{
foreach (var mod in ((IMenuManager)this).ModList)
{
if (oldScene == OWScene.TitleScreen)
{
mod.CleanupTitleMenu();
mod.CleanupOptionsMenu();
}
else if (oldScene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse)
{
mod.CleanupPauseMenu();
mod.CleanupOptionsMenu();
}
}
};

LoadManager.OnCompleteSceneLoad += (_, newScene) =>
{
if (newScene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse)
_hasSetupMenusThisScene = false;
if (newScene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse)
{
SetupMenus(((IMenuManager)this).ModList);
}
Expand All @@ -67,6 +87,13 @@ public MenuManager(

internal void SetupMenus(IList<IModBehaviour> modList)
{
if (_hasSetupMenusThisScene)
{
return;
}

_hasSetupMenusThisScene = true;

void SaveConfig()
{
JsonHelper.SaveJsonObject($"{_owmlConfig.OWMLPath}{Constants.OwmlConfigFileName}", _owmlConfig);
Expand Down Expand Up @@ -311,14 +338,14 @@ void SaveConfig()
{
if (LoadManager.GetCurrentScene() == OWScene.TitleScreen)
{
mod.SetupTitleMenu();
mod.SetupTitleMenu(mod.ModHelper.MenuHelper.TitleMenuManager);
}
else if (LoadManager.GetCurrentScene() is OWScene.SolarSystem or OWScene.EyeOfTheUniverse)
{
mod.SetupPauseMenu();
mod.SetupPauseMenu(mod.ModHelper.MenuHelper.PauseMenuManager);
}

mod.SetupOptionsMenu();
mod.SetupOptionsMenu(mod.ModHelper.MenuHelper.OptionsMenuManager);
}
catch (Exception ex)
{
Expand Down
41 changes: 40 additions & 1 deletion src/OWML.ModHelper.Menus/NewMenuSystem/PauseMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,50 @@ namespace OWML.ModHelper.Menus.NewMenuSystem
public class PauseMenuManager : IPauseMenuManager
{
private IModConsole _console;

private FontAndLanguageController _languageController;
private GameObject _pauseMenuItemsTemplate;
private GameObject _buttonPrefab;

public event Action PauseMenuOpened;
public event Action PauseMenuClosed;

public PauseMenuManager(IModConsole console)
{
_console = console;
LoadManager.OnCompleteSceneLoad += OnSceneLoadCompleted;
}

private void OnSceneLoadCompleted(OWScene old, OWScene newScene)
{
if (newScene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse)
{
var pauseMenuManager = Resources.FindObjectsOfTypeAll<global::PauseMenuManager>()[0];
pauseMenuManager._pauseMenu.OnActivateMenu += () =>
{
if (!pauseMenuManager.IsOpen())
{
PauseMenuOpened?.SafeInvoke();
}
};

pauseMenuManager._pauseMenu.OnDeactivateMenu += () =>
{
if (MenuStackManager.SharedInstance.GetMenuCount() == 0)
{
PauseMenuClosed?.SafeInvoke();
}
};
}
}

private void AddToLangController(Text textComponent)
{
if (_languageController == null)
{
_languageController = Resources.FindObjectsOfTypeAll<global::PauseMenuManager>()[0].transform.GetChild(0).GetComponent<FontAndLanguageController>();
}

_languageController.AddTextElement(textComponent, false);
}

private void MakePauseMenuItemsTemplate()
Expand Down Expand Up @@ -89,6 +126,7 @@ public SubmitAction MakeSimpleButton(string name, int index, bool fromTop, Menu

SetButtonText(submitAction, name);
SetButtonIndex(submitAction, index, fromTop);
AddToLangController(submitAction.GetComponentInChildren<Text>());

return submitAction;
}
Expand All @@ -108,6 +146,7 @@ public SubmitAction MakeMenuOpenButton(string name, Menu menuToOpen, int index,

SetButtonText(submitActionMenu, name);
SetButtonIndex(submitActionMenu, index, fromTop);
AddToLangController(submitActionMenu.GetComponentInChildren<Text>());

menuRootObject.SetActive(true);
return submitActionMenu;
Expand Down
13 changes: 13 additions & 0 deletions src/OWML.ModHelper.Menus/NewMenuSystem/TitleMenuManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ namespace OWML.ModHelper.Menus.NewMenuSystem
{
internal class TitleMenuManager : ITitleMenuManager
{
private FontAndLanguageController _languageController;

private void AddToLangController(Text textComponent)
{
if (_languageController == null)
{
_languageController = GameObject.Find("MainMenu").GetComponent<FontAndLanguageController>();
}

_languageController.AddTextElement(textComponent, false);
}

public SubmitAction CreateTitleButton(string text, int index, bool fromTop)
{
var titleScreenManager = Object.FindObjectOfType<TitleScreenManager>();
Expand All @@ -27,6 +39,7 @@ public SubmitAction CreateTitleButton(string text, int index, bool fromTop)

SetButtonIndex(submitAction, index, fromTop);
SetButtonText(submitAction, text);
AddToLangController(submitAction.GetComponentInChildren<Text>());

newButton.GetComponent<CanvasGroup>().alpha = 0;
var animController = GameObject.Find("TitleMenuManagers").GetComponent<TitleAnimationController>();
Expand Down
15 changes: 6 additions & 9 deletions src/OWML.ModHelper/ModBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,14 @@ public virtual void Configure(IModConfig config)

public virtual object GetApi() => null;

public virtual void SetupTitleMenu()
{
}
public virtual void SetupTitleMenu(ITitleMenuManager titleManager) { }
public virtual void CleanupTitleMenu() { }

public virtual void SetupPauseMenu()
{
}
public virtual void SetupPauseMenu(IPauseMenuManager pauseManager) { }
public virtual void CleanupPauseMenu() { }

public virtual void SetupOptionsMenu()
{
}
public virtual void SetupOptionsMenu(IOptionsMenuManager optionsManager) { }
public virtual void CleanupOptionsMenu() { }

public IList<IModBehaviour> GetDependants() =>
ModHelper.Interaction.GetDependants(ModHelper.Manifest.UniqueName);
Expand Down
27 changes: 27 additions & 0 deletions src/OWML.Utils/MenuExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using UnityEngine;

namespace OWML.Utils
{
public static class MenuExtensions
{
public static void SetMessage(this PopupMenu menu, string message) => menu._labelText.text = message;

public static void SetButtonVisible(this SubmitAction buttonAction, bool visible)
{
var activeAlpha = 1;

if (LoadManager.GetCurrentScene() == OWScene.TitleScreen)
{
var titleAnimationController = Resources.FindObjectsOfTypeAll<TitleScreenManager>()[0]._gfxController;
activeAlpha = titleAnimationController.IsTitleAnimationComplete() ? 1 : 0;
if (titleAnimationController.IsFadingInMenuOptions())
{
activeAlpha = 1;
}
}

buttonAction.gameObject.SetActive(visible);
buttonAction.GetComponent<CanvasGroup>().alpha = visible ? activeAlpha : 0;
}
}
}
Loading

0 comments on commit 5457e2a

Please sign in to comment.